From 646ea20decc87530f871e5c56e96980c93fcf391 Mon Sep 17 00:00:00 2001 From: des Date: Sat, 13 Dec 2008 22:45:22 +0000 Subject: Flatten and clean up. --- lib/Makefile.am | 76 +++ lib/Makefile.in | 892 ++++++++++++++++++++++++++++++++++++ lib/openpam_borrow_cred.c | 121 +++++ lib/openpam_configure.c | 340 ++++++++++++++ lib/openpam_dispatch.c | 240 ++++++++++ lib/openpam_dynamic.c | 110 +++++ lib/openpam_findenv.c | 69 +++ lib/openpam_free_data.c | 72 +++ lib/openpam_free_envlist.c | 66 +++ lib/openpam_get_option.c | 83 ++++ lib/openpam_impl.h | 200 ++++++++ lib/openpam_load.c | 153 +++++++ lib/openpam_log.c | 158 +++++++ lib/openpam_nullconv.c | 86 ++++ lib/openpam_readline.c | 155 +++++++ lib/openpam_restore_cred.c | 94 ++++ lib/openpam_set_option.c | 119 +++++ lib/openpam_static.c | 70 +++ lib/openpam_ttyconv.c | 248 ++++++++++ lib/pam_acct_mgmt.c | 84 ++++ lib/pam_authenticate.c | 92 ++++ lib/pam_authenticate_secondary.c | 63 +++ lib/pam_chauthtok.c | 93 ++++ lib/pam_close_session.c | 85 ++++ lib/pam_end.c | 102 +++++ lib/pam_error.c | 85 ++++ lib/pam_get_authtok.c | 171 +++++++ lib/pam_get_data.c | 86 ++++ lib/pam_get_item.c | 142 ++++++ lib/pam_get_mapped_authtok.c | 62 +++ lib/pam_get_mapped_username.c | 63 +++ lib/pam_get_user.c | 113 +++++ lib/pam_getenv.c | 83 ++++ lib/pam_getenvlist.c | 106 +++++ lib/pam_info.c | 85 ++++ lib/pam_open_session.c | 86 ++++ lib/pam_prompt.c | 90 ++++ lib/pam_putenv.c | 108 +++++ lib/pam_set_data.c | 104 +++++ lib/pam_set_item.c | 120 +++++ lib/pam_set_mapped_authtok.c | 62 +++ lib/pam_set_mapped_username.c | 63 +++ lib/pam_setcred.c | 95 ++++ lib/pam_setenv.c | 98 ++++ lib/pam_sm_acct_mgmt.c | 81 ++++ lib/pam_sm_authenticate.c | 82 ++++ lib/pam_sm_authenticate_secondary.c | 68 +++ lib/pam_sm_chauthtok.c | 83 ++++ lib/pam_sm_close_session.c | 78 ++++ lib/pam_sm_get_mapped_authtok.c | 67 +++ lib/pam_sm_get_mapped_username.c | 68 +++ lib/pam_sm_open_session.c | 78 ++++ lib/pam_sm_set_mapped_authtok.c | 67 +++ lib/pam_sm_set_mapped_username.c | 65 +++ lib/pam_sm_setcred.c | 82 ++++ lib/pam_start.c | 108 +++++ lib/pam_strerror.c | 164 +++++++ lib/pam_verror.c | 80 ++++ lib/pam_vinfo.c | 80 ++++ lib/pam_vprompt.c | 129 ++++++ 60 files changed, 7073 insertions(+) create mode 100644 lib/Makefile.am create mode 100644 lib/Makefile.in create mode 100644 lib/openpam_borrow_cred.c create mode 100644 lib/openpam_configure.c create mode 100644 lib/openpam_dispatch.c create mode 100644 lib/openpam_dynamic.c create mode 100644 lib/openpam_findenv.c create mode 100644 lib/openpam_free_data.c create mode 100644 lib/openpam_free_envlist.c create mode 100644 lib/openpam_get_option.c create mode 100644 lib/openpam_impl.h create mode 100644 lib/openpam_load.c create mode 100644 lib/openpam_log.c create mode 100644 lib/openpam_nullconv.c create mode 100644 lib/openpam_readline.c create mode 100644 lib/openpam_restore_cred.c create mode 100644 lib/openpam_set_option.c create mode 100644 lib/openpam_static.c create mode 100644 lib/openpam_ttyconv.c create mode 100644 lib/pam_acct_mgmt.c create mode 100644 lib/pam_authenticate.c create mode 100644 lib/pam_authenticate_secondary.c create mode 100644 lib/pam_chauthtok.c create mode 100644 lib/pam_close_session.c create mode 100644 lib/pam_end.c create mode 100644 lib/pam_error.c create mode 100644 lib/pam_get_authtok.c create mode 100644 lib/pam_get_data.c create mode 100644 lib/pam_get_item.c create mode 100644 lib/pam_get_mapped_authtok.c create mode 100644 lib/pam_get_mapped_username.c create mode 100644 lib/pam_get_user.c create mode 100644 lib/pam_getenv.c create mode 100644 lib/pam_getenvlist.c create mode 100644 lib/pam_info.c create mode 100644 lib/pam_open_session.c create mode 100644 lib/pam_prompt.c create mode 100644 lib/pam_putenv.c create mode 100644 lib/pam_set_data.c create mode 100644 lib/pam_set_item.c create mode 100644 lib/pam_set_mapped_authtok.c create mode 100644 lib/pam_set_mapped_username.c create mode 100644 lib/pam_setcred.c create mode 100644 lib/pam_setenv.c create mode 100644 lib/pam_sm_acct_mgmt.c create mode 100644 lib/pam_sm_authenticate.c create mode 100644 lib/pam_sm_authenticate_secondary.c create mode 100644 lib/pam_sm_chauthtok.c create mode 100644 lib/pam_sm_close_session.c create mode 100644 lib/pam_sm_get_mapped_authtok.c create mode 100644 lib/pam_sm_get_mapped_username.c create mode 100644 lib/pam_sm_open_session.c create mode 100644 lib/pam_sm_set_mapped_authtok.c create mode 100644 lib/pam_sm_set_mapped_username.c create mode 100644 lib/pam_sm_setcred.c create mode 100644 lib/pam_start.c create mode 100644 lib/pam_strerror.c create mode 100644 lib/pam_verror.c create mode 100644 lib/pam_vinfo.c create mode 100644 lib/pam_vprompt.c (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000..c748079 --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,76 @@ +# $Id: Makefile.am 395 2007-06-03 20:26:18Z des $ + +NULL = + +INCLUDES = -I$(top_srcdir)/include + +lib_LTLIBRARIES = libpam.la + +noinst_HEADERS = openpam_impl.h + +libpam_la_SOURCES = \ + openpam_borrow_cred.c \ + openpam_configure.c \ + openpam_dispatch.c \ + openpam_dynamic.c \ + openpam_findenv.c \ + openpam_free_data.c \ + openpam_free_envlist.c \ + openpam_get_option.c \ + openpam_load.c \ + openpam_log.c \ + openpam_nullconv.c \ + openpam_readline.c \ + openpam_restore_cred.c \ + openpam_set_option.c \ + openpam_static.c \ + openpam_ttyconv.c \ + pam_acct_mgmt.c \ + pam_authenticate.c \ + pam_chauthtok.c \ + pam_close_session.c \ + pam_end.c \ + pam_error.c \ + pam_get_authtok.c \ + pam_get_data.c \ + pam_get_item.c \ + pam_get_user.c \ + pam_getenv.c \ + pam_getenvlist.c \ + pam_info.c \ + pam_open_session.c \ + pam_prompt.c \ + pam_putenv.c \ + pam_set_data.c \ + pam_set_item.c \ + pam_setcred.c \ + pam_setenv.c \ + pam_start.c \ + pam_strerror.c \ + pam_verror.c \ + pam_vinfo.c \ + pam_vprompt.c \ + $(NULL) + +libpam_la_CFLAGS = -DOPENPAM_MODULES_DIR='"@OPENPAM_MODULES_DIR@/"' + +libpam_la_LDFLAGS = -no-undefined -version-info @LIB_MAJ@ @DL_LIBS@ + +EXTRA_DIST = \ + pam_authenticate_secondary.c \ + pam_get_mapped_authtok.c \ + pam_get_mapped_username.c \ + pam_set_mapped_authtok.c \ + pam_set_mapped_username.c \ + \ + pam_sm_acct_mgmt.c \ + pam_sm_authenticate.c \ + pam_sm_authenticate_secondary.c \ + pam_sm_chauthtok.c \ + pam_sm_close_session.c \ + pam_sm_get_mapped_authtok.c \ + pam_sm_get_mapped_username.c \ + pam_sm_open_session.c \ + pam_sm_set_mapped_authtok.c \ + pam_sm_set_mapped_username.c \ + pam_sm_setcred.c diff --git a/lib/Makefile.in b/lib/Makefile.in new file mode 100644 index 0000000..f1ab0ad --- /dev/null +++ b/lib/Makefile.in @@ -0,0 +1,892 @@ +# Makefile.in generated by automake 1.9.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# $Id: Makefile.am 395 2007-06-03 20:26:18Z des $ + + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = lib +DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libdir)" +libLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(lib_LTLIBRARIES) +libpam_la_LIBADD = +am__objects_1 = +am_libpam_la_OBJECTS = libpam_la-openpam_borrow_cred.lo \ + libpam_la-openpam_configure.lo libpam_la-openpam_dispatch.lo \ + libpam_la-openpam_dynamic.lo libpam_la-openpam_findenv.lo \ + libpam_la-openpam_free_data.lo \ + libpam_la-openpam_free_envlist.lo \ + libpam_la-openpam_get_option.lo libpam_la-openpam_load.lo \ + libpam_la-openpam_log.lo libpam_la-openpam_nullconv.lo \ + libpam_la-openpam_readline.lo \ + libpam_la-openpam_restore_cred.lo \ + libpam_la-openpam_set_option.lo libpam_la-openpam_static.lo \ + libpam_la-openpam_ttyconv.lo libpam_la-pam_acct_mgmt.lo \ + libpam_la-pam_authenticate.lo libpam_la-pam_chauthtok.lo \ + libpam_la-pam_close_session.lo libpam_la-pam_end.lo \ + libpam_la-pam_error.lo libpam_la-pam_get_authtok.lo \ + libpam_la-pam_get_data.lo libpam_la-pam_get_item.lo \ + libpam_la-pam_get_user.lo libpam_la-pam_getenv.lo \ + libpam_la-pam_getenvlist.lo libpam_la-pam_info.lo \ + libpam_la-pam_open_session.lo libpam_la-pam_prompt.lo \ + libpam_la-pam_putenv.lo libpam_la-pam_set_data.lo \ + libpam_la-pam_set_item.lo libpam_la-pam_setcred.lo \ + libpam_la-pam_setenv.lo libpam_la-pam_start.lo \ + libpam_la-pam_strerror.lo libpam_la-pam_verror.lo \ + libpam_la-pam_vinfo.lo libpam_la-pam_vprompt.lo \ + $(am__objects_1) +libpam_la_OBJECTS = $(am_libpam_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libpam_la_SOURCES) +DIST_SOURCES = $(libpam_la_SOURCES) +HEADERS = $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPT_LIBS = @CRYPT_LIBS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DL_LIBS = @DL_LIBS@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIB_MAJ = @LIB_MAJ@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +OBJEXT = @OBJEXT@ +OPENPAM_MODULES_DIR = @OPENPAM_MODULES_DIR@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +WITH_DOC_FALSE = @WITH_DOC_FALSE@ +WITH_DOC_TRUE = @WITH_DOC_TRUE@ +WITH_PAM_UNIX_FALSE = @WITH_PAM_UNIX_FALSE@ +WITH_PAM_UNIX_TRUE = @WITH_PAM_UNIX_TRUE@ +WITH_SU_FALSE = @WITH_SU_FALSE@ +WITH_SU_TRUE = @WITH_SU_TRUE@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +NULL = +INCLUDES = -I$(top_srcdir)/include +lib_LTLIBRARIES = libpam.la +noinst_HEADERS = openpam_impl.h +libpam_la_SOURCES = \ + openpam_borrow_cred.c \ + openpam_configure.c \ + openpam_dispatch.c \ + openpam_dynamic.c \ + openpam_findenv.c \ + openpam_free_data.c \ + openpam_free_envlist.c \ + openpam_get_option.c \ + openpam_load.c \ + openpam_log.c \ + openpam_nullconv.c \ + openpam_readline.c \ + openpam_restore_cred.c \ + openpam_set_option.c \ + openpam_static.c \ + openpam_ttyconv.c \ + pam_acct_mgmt.c \ + pam_authenticate.c \ + pam_chauthtok.c \ + pam_close_session.c \ + pam_end.c \ + pam_error.c \ + pam_get_authtok.c \ + pam_get_data.c \ + pam_get_item.c \ + pam_get_user.c \ + pam_getenv.c \ + pam_getenvlist.c \ + pam_info.c \ + pam_open_session.c \ + pam_prompt.c \ + pam_putenv.c \ + pam_set_data.c \ + pam_set_item.c \ + pam_setcred.c \ + pam_setenv.c \ + pam_start.c \ + pam_strerror.c \ + pam_verror.c \ + pam_vinfo.c \ + pam_vprompt.c \ + $(NULL) + +libpam_la_CFLAGS = -DOPENPAM_MODULES_DIR='"@OPENPAM_MODULES_DIR@/"' +libpam_la_LDFLAGS = -no-undefined -version-info @LIB_MAJ@ @DL_LIBS@ +EXTRA_DIST = \ + pam_authenticate_secondary.c \ + pam_get_mapped_authtok.c \ + pam_get_mapped_username.c \ + pam_set_mapped_authtok.c \ + pam_set_mapped_username.c \ + \ + pam_sm_acct_mgmt.c \ + pam_sm_authenticate.c \ + pam_sm_authenticate_secondary.c \ + pam_sm_chauthtok.c \ + pam_sm_close_session.c \ + pam_sm_get_mapped_authtok.c \ + pam_sm_get_mapped_username.c \ + pam_sm_open_session.c \ + pam_sm_set_mapped_authtok.c \ + pam_sm_set_mapped_username.c \ + pam_sm_setcred.c + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign lib/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --foreign lib/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libpam.la: $(libpam_la_OBJECTS) $(libpam_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libpam_la_LDFLAGS) $(libpam_la_OBJECTS) $(libpam_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_borrow_cred.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_configure.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_dispatch.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_dynamic.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_findenv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_free_data.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_free_envlist.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_get_option.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_load.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_log.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_nullconv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_readline.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_restore_cred.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_set_option.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_static.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_ttyconv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_acct_mgmt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_authenticate.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_chauthtok.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_close_session.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_end.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_error.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_get_authtok.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_get_data.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_get_item.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_get_user.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_getenv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_getenvlist.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_info.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_open_session.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_prompt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_putenv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_set_data.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_set_item.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_setcred.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_setenv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_start.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_strerror.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_verror.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_vinfo.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_vprompt.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +libpam_la-openpam_borrow_cred.lo: openpam_borrow_cred.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_borrow_cred.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_borrow_cred.Tpo" -c -o libpam_la-openpam_borrow_cred.lo `test -f 'openpam_borrow_cred.c' || echo '$(srcdir)/'`openpam_borrow_cred.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_borrow_cred.Tpo" "$(DEPDIR)/libpam_la-openpam_borrow_cred.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_borrow_cred.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_borrow_cred.c' object='libpam_la-openpam_borrow_cred.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_borrow_cred.lo `test -f 'openpam_borrow_cred.c' || echo '$(srcdir)/'`openpam_borrow_cred.c + +libpam_la-openpam_configure.lo: openpam_configure.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_configure.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_configure.Tpo" -c -o libpam_la-openpam_configure.lo `test -f 'openpam_configure.c' || echo '$(srcdir)/'`openpam_configure.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_configure.Tpo" "$(DEPDIR)/libpam_la-openpam_configure.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_configure.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_configure.c' object='libpam_la-openpam_configure.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_configure.lo `test -f 'openpam_configure.c' || echo '$(srcdir)/'`openpam_configure.c + +libpam_la-openpam_dispatch.lo: openpam_dispatch.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_dispatch.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_dispatch.Tpo" -c -o libpam_la-openpam_dispatch.lo `test -f 'openpam_dispatch.c' || echo '$(srcdir)/'`openpam_dispatch.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_dispatch.Tpo" "$(DEPDIR)/libpam_la-openpam_dispatch.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_dispatch.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_dispatch.c' object='libpam_la-openpam_dispatch.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_dispatch.lo `test -f 'openpam_dispatch.c' || echo '$(srcdir)/'`openpam_dispatch.c + +libpam_la-openpam_dynamic.lo: openpam_dynamic.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_dynamic.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_dynamic.Tpo" -c -o libpam_la-openpam_dynamic.lo `test -f 'openpam_dynamic.c' || echo '$(srcdir)/'`openpam_dynamic.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_dynamic.Tpo" "$(DEPDIR)/libpam_la-openpam_dynamic.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_dynamic.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_dynamic.c' object='libpam_la-openpam_dynamic.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_dynamic.lo `test -f 'openpam_dynamic.c' || echo '$(srcdir)/'`openpam_dynamic.c + +libpam_la-openpam_findenv.lo: openpam_findenv.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_findenv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_findenv.Tpo" -c -o libpam_la-openpam_findenv.lo `test -f 'openpam_findenv.c' || echo '$(srcdir)/'`openpam_findenv.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_findenv.Tpo" "$(DEPDIR)/libpam_la-openpam_findenv.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_findenv.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_findenv.c' object='libpam_la-openpam_findenv.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_findenv.lo `test -f 'openpam_findenv.c' || echo '$(srcdir)/'`openpam_findenv.c + +libpam_la-openpam_free_data.lo: openpam_free_data.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_free_data.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_free_data.Tpo" -c -o libpam_la-openpam_free_data.lo `test -f 'openpam_free_data.c' || echo '$(srcdir)/'`openpam_free_data.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_free_data.Tpo" "$(DEPDIR)/libpam_la-openpam_free_data.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_free_data.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_free_data.c' object='libpam_la-openpam_free_data.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_free_data.lo `test -f 'openpam_free_data.c' || echo '$(srcdir)/'`openpam_free_data.c + +libpam_la-openpam_free_envlist.lo: openpam_free_envlist.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_free_envlist.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_free_envlist.Tpo" -c -o libpam_la-openpam_free_envlist.lo `test -f 'openpam_free_envlist.c' || echo '$(srcdir)/'`openpam_free_envlist.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_free_envlist.Tpo" "$(DEPDIR)/libpam_la-openpam_free_envlist.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_free_envlist.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_free_envlist.c' object='libpam_la-openpam_free_envlist.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_free_envlist.lo `test -f 'openpam_free_envlist.c' || echo '$(srcdir)/'`openpam_free_envlist.c + +libpam_la-openpam_get_option.lo: openpam_get_option.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_get_option.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_get_option.Tpo" -c -o libpam_la-openpam_get_option.lo `test -f 'openpam_get_option.c' || echo '$(srcdir)/'`openpam_get_option.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_get_option.Tpo" "$(DEPDIR)/libpam_la-openpam_get_option.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_get_option.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_get_option.c' object='libpam_la-openpam_get_option.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_get_option.lo `test -f 'openpam_get_option.c' || echo '$(srcdir)/'`openpam_get_option.c + +libpam_la-openpam_load.lo: openpam_load.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_load.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_load.Tpo" -c -o libpam_la-openpam_load.lo `test -f 'openpam_load.c' || echo '$(srcdir)/'`openpam_load.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_load.Tpo" "$(DEPDIR)/libpam_la-openpam_load.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_load.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_load.c' object='libpam_la-openpam_load.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_load.lo `test -f 'openpam_load.c' || echo '$(srcdir)/'`openpam_load.c + +libpam_la-openpam_log.lo: openpam_log.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_log.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_log.Tpo" -c -o libpam_la-openpam_log.lo `test -f 'openpam_log.c' || echo '$(srcdir)/'`openpam_log.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_log.Tpo" "$(DEPDIR)/libpam_la-openpam_log.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_log.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_log.c' object='libpam_la-openpam_log.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_log.lo `test -f 'openpam_log.c' || echo '$(srcdir)/'`openpam_log.c + +libpam_la-openpam_nullconv.lo: openpam_nullconv.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_nullconv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_nullconv.Tpo" -c -o libpam_la-openpam_nullconv.lo `test -f 'openpam_nullconv.c' || echo '$(srcdir)/'`openpam_nullconv.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_nullconv.Tpo" "$(DEPDIR)/libpam_la-openpam_nullconv.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_nullconv.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_nullconv.c' object='libpam_la-openpam_nullconv.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_nullconv.lo `test -f 'openpam_nullconv.c' || echo '$(srcdir)/'`openpam_nullconv.c + +libpam_la-openpam_readline.lo: openpam_readline.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_readline.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_readline.Tpo" -c -o libpam_la-openpam_readline.lo `test -f 'openpam_readline.c' || echo '$(srcdir)/'`openpam_readline.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_readline.Tpo" "$(DEPDIR)/libpam_la-openpam_readline.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_readline.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_readline.c' object='libpam_la-openpam_readline.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_readline.lo `test -f 'openpam_readline.c' || echo '$(srcdir)/'`openpam_readline.c + +libpam_la-openpam_restore_cred.lo: openpam_restore_cred.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_restore_cred.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_restore_cred.Tpo" -c -o libpam_la-openpam_restore_cred.lo `test -f 'openpam_restore_cred.c' || echo '$(srcdir)/'`openpam_restore_cred.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_restore_cred.Tpo" "$(DEPDIR)/libpam_la-openpam_restore_cred.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_restore_cred.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_restore_cred.c' object='libpam_la-openpam_restore_cred.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_restore_cred.lo `test -f 'openpam_restore_cred.c' || echo '$(srcdir)/'`openpam_restore_cred.c + +libpam_la-openpam_set_option.lo: openpam_set_option.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_set_option.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_set_option.Tpo" -c -o libpam_la-openpam_set_option.lo `test -f 'openpam_set_option.c' || echo '$(srcdir)/'`openpam_set_option.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_set_option.Tpo" "$(DEPDIR)/libpam_la-openpam_set_option.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_set_option.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_set_option.c' object='libpam_la-openpam_set_option.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_set_option.lo `test -f 'openpam_set_option.c' || echo '$(srcdir)/'`openpam_set_option.c + +libpam_la-openpam_static.lo: openpam_static.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_static.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_static.Tpo" -c -o libpam_la-openpam_static.lo `test -f 'openpam_static.c' || echo '$(srcdir)/'`openpam_static.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_static.Tpo" "$(DEPDIR)/libpam_la-openpam_static.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_static.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_static.c' object='libpam_la-openpam_static.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_static.lo `test -f 'openpam_static.c' || echo '$(srcdir)/'`openpam_static.c + +libpam_la-openpam_ttyconv.lo: openpam_ttyconv.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_ttyconv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_ttyconv.Tpo" -c -o libpam_la-openpam_ttyconv.lo `test -f 'openpam_ttyconv.c' || echo '$(srcdir)/'`openpam_ttyconv.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_ttyconv.Tpo" "$(DEPDIR)/libpam_la-openpam_ttyconv.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_ttyconv.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_ttyconv.c' object='libpam_la-openpam_ttyconv.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_ttyconv.lo `test -f 'openpam_ttyconv.c' || echo '$(srcdir)/'`openpam_ttyconv.c + +libpam_la-pam_acct_mgmt.lo: pam_acct_mgmt.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_acct_mgmt.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_acct_mgmt.Tpo" -c -o libpam_la-pam_acct_mgmt.lo `test -f 'pam_acct_mgmt.c' || echo '$(srcdir)/'`pam_acct_mgmt.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_acct_mgmt.Tpo" "$(DEPDIR)/libpam_la-pam_acct_mgmt.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_acct_mgmt.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_acct_mgmt.c' object='libpam_la-pam_acct_mgmt.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_acct_mgmt.lo `test -f 'pam_acct_mgmt.c' || echo '$(srcdir)/'`pam_acct_mgmt.c + +libpam_la-pam_authenticate.lo: pam_authenticate.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_authenticate.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_authenticate.Tpo" -c -o libpam_la-pam_authenticate.lo `test -f 'pam_authenticate.c' || echo '$(srcdir)/'`pam_authenticate.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_authenticate.Tpo" "$(DEPDIR)/libpam_la-pam_authenticate.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_authenticate.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_authenticate.c' object='libpam_la-pam_authenticate.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_authenticate.lo `test -f 'pam_authenticate.c' || echo '$(srcdir)/'`pam_authenticate.c + +libpam_la-pam_chauthtok.lo: pam_chauthtok.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_chauthtok.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_chauthtok.Tpo" -c -o libpam_la-pam_chauthtok.lo `test -f 'pam_chauthtok.c' || echo '$(srcdir)/'`pam_chauthtok.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_chauthtok.Tpo" "$(DEPDIR)/libpam_la-pam_chauthtok.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_chauthtok.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_chauthtok.c' object='libpam_la-pam_chauthtok.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_chauthtok.lo `test -f 'pam_chauthtok.c' || echo '$(srcdir)/'`pam_chauthtok.c + +libpam_la-pam_close_session.lo: pam_close_session.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_close_session.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_close_session.Tpo" -c -o libpam_la-pam_close_session.lo `test -f 'pam_close_session.c' || echo '$(srcdir)/'`pam_close_session.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_close_session.Tpo" "$(DEPDIR)/libpam_la-pam_close_session.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_close_session.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_close_session.c' object='libpam_la-pam_close_session.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_close_session.lo `test -f 'pam_close_session.c' || echo '$(srcdir)/'`pam_close_session.c + +libpam_la-pam_end.lo: pam_end.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_end.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_end.Tpo" -c -o libpam_la-pam_end.lo `test -f 'pam_end.c' || echo '$(srcdir)/'`pam_end.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_end.Tpo" "$(DEPDIR)/libpam_la-pam_end.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_end.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_end.c' object='libpam_la-pam_end.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_end.lo `test -f 'pam_end.c' || echo '$(srcdir)/'`pam_end.c + +libpam_la-pam_error.lo: pam_error.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_error.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_error.Tpo" -c -o libpam_la-pam_error.lo `test -f 'pam_error.c' || echo '$(srcdir)/'`pam_error.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_error.Tpo" "$(DEPDIR)/libpam_la-pam_error.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_error.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_error.c' object='libpam_la-pam_error.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_error.lo `test -f 'pam_error.c' || echo '$(srcdir)/'`pam_error.c + +libpam_la-pam_get_authtok.lo: pam_get_authtok.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_get_authtok.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_get_authtok.Tpo" -c -o libpam_la-pam_get_authtok.lo `test -f 'pam_get_authtok.c' || echo '$(srcdir)/'`pam_get_authtok.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_get_authtok.Tpo" "$(DEPDIR)/libpam_la-pam_get_authtok.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_get_authtok.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_get_authtok.c' object='libpam_la-pam_get_authtok.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_get_authtok.lo `test -f 'pam_get_authtok.c' || echo '$(srcdir)/'`pam_get_authtok.c + +libpam_la-pam_get_data.lo: pam_get_data.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_get_data.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_get_data.Tpo" -c -o libpam_la-pam_get_data.lo `test -f 'pam_get_data.c' || echo '$(srcdir)/'`pam_get_data.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_get_data.Tpo" "$(DEPDIR)/libpam_la-pam_get_data.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_get_data.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_get_data.c' object='libpam_la-pam_get_data.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_get_data.lo `test -f 'pam_get_data.c' || echo '$(srcdir)/'`pam_get_data.c + +libpam_la-pam_get_item.lo: pam_get_item.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_get_item.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_get_item.Tpo" -c -o libpam_la-pam_get_item.lo `test -f 'pam_get_item.c' || echo '$(srcdir)/'`pam_get_item.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_get_item.Tpo" "$(DEPDIR)/libpam_la-pam_get_item.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_get_item.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_get_item.c' object='libpam_la-pam_get_item.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_get_item.lo `test -f 'pam_get_item.c' || echo '$(srcdir)/'`pam_get_item.c + +libpam_la-pam_get_user.lo: pam_get_user.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_get_user.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_get_user.Tpo" -c -o libpam_la-pam_get_user.lo `test -f 'pam_get_user.c' || echo '$(srcdir)/'`pam_get_user.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_get_user.Tpo" "$(DEPDIR)/libpam_la-pam_get_user.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_get_user.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_get_user.c' object='libpam_la-pam_get_user.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_get_user.lo `test -f 'pam_get_user.c' || echo '$(srcdir)/'`pam_get_user.c + +libpam_la-pam_getenv.lo: pam_getenv.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_getenv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_getenv.Tpo" -c -o libpam_la-pam_getenv.lo `test -f 'pam_getenv.c' || echo '$(srcdir)/'`pam_getenv.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_getenv.Tpo" "$(DEPDIR)/libpam_la-pam_getenv.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_getenv.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_getenv.c' object='libpam_la-pam_getenv.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_getenv.lo `test -f 'pam_getenv.c' || echo '$(srcdir)/'`pam_getenv.c + +libpam_la-pam_getenvlist.lo: pam_getenvlist.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_getenvlist.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_getenvlist.Tpo" -c -o libpam_la-pam_getenvlist.lo `test -f 'pam_getenvlist.c' || echo '$(srcdir)/'`pam_getenvlist.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_getenvlist.Tpo" "$(DEPDIR)/libpam_la-pam_getenvlist.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_getenvlist.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_getenvlist.c' object='libpam_la-pam_getenvlist.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_getenvlist.lo `test -f 'pam_getenvlist.c' || echo '$(srcdir)/'`pam_getenvlist.c + +libpam_la-pam_info.lo: pam_info.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_info.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_info.Tpo" -c -o libpam_la-pam_info.lo `test -f 'pam_info.c' || echo '$(srcdir)/'`pam_info.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_info.Tpo" "$(DEPDIR)/libpam_la-pam_info.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_info.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_info.c' object='libpam_la-pam_info.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_info.lo `test -f 'pam_info.c' || echo '$(srcdir)/'`pam_info.c + +libpam_la-pam_open_session.lo: pam_open_session.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_open_session.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_open_session.Tpo" -c -o libpam_la-pam_open_session.lo `test -f 'pam_open_session.c' || echo '$(srcdir)/'`pam_open_session.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_open_session.Tpo" "$(DEPDIR)/libpam_la-pam_open_session.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_open_session.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_open_session.c' object='libpam_la-pam_open_session.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_open_session.lo `test -f 'pam_open_session.c' || echo '$(srcdir)/'`pam_open_session.c + +libpam_la-pam_prompt.lo: pam_prompt.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_prompt.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_prompt.Tpo" -c -o libpam_la-pam_prompt.lo `test -f 'pam_prompt.c' || echo '$(srcdir)/'`pam_prompt.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_prompt.Tpo" "$(DEPDIR)/libpam_la-pam_prompt.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_prompt.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_prompt.c' object='libpam_la-pam_prompt.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_prompt.lo `test -f 'pam_prompt.c' || echo '$(srcdir)/'`pam_prompt.c + +libpam_la-pam_putenv.lo: pam_putenv.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_putenv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_putenv.Tpo" -c -o libpam_la-pam_putenv.lo `test -f 'pam_putenv.c' || echo '$(srcdir)/'`pam_putenv.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_putenv.Tpo" "$(DEPDIR)/libpam_la-pam_putenv.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_putenv.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_putenv.c' object='libpam_la-pam_putenv.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_putenv.lo `test -f 'pam_putenv.c' || echo '$(srcdir)/'`pam_putenv.c + +libpam_la-pam_set_data.lo: pam_set_data.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_set_data.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_set_data.Tpo" -c -o libpam_la-pam_set_data.lo `test -f 'pam_set_data.c' || echo '$(srcdir)/'`pam_set_data.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_set_data.Tpo" "$(DEPDIR)/libpam_la-pam_set_data.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_set_data.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_set_data.c' object='libpam_la-pam_set_data.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_set_data.lo `test -f 'pam_set_data.c' || echo '$(srcdir)/'`pam_set_data.c + +libpam_la-pam_set_item.lo: pam_set_item.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_set_item.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_set_item.Tpo" -c -o libpam_la-pam_set_item.lo `test -f 'pam_set_item.c' || echo '$(srcdir)/'`pam_set_item.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_set_item.Tpo" "$(DEPDIR)/libpam_la-pam_set_item.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_set_item.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_set_item.c' object='libpam_la-pam_set_item.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_set_item.lo `test -f 'pam_set_item.c' || echo '$(srcdir)/'`pam_set_item.c + +libpam_la-pam_setcred.lo: pam_setcred.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_setcred.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_setcred.Tpo" -c -o libpam_la-pam_setcred.lo `test -f 'pam_setcred.c' || echo '$(srcdir)/'`pam_setcred.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_setcred.Tpo" "$(DEPDIR)/libpam_la-pam_setcred.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_setcred.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_setcred.c' object='libpam_la-pam_setcred.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_setcred.lo `test -f 'pam_setcred.c' || echo '$(srcdir)/'`pam_setcred.c + +libpam_la-pam_setenv.lo: pam_setenv.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_setenv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_setenv.Tpo" -c -o libpam_la-pam_setenv.lo `test -f 'pam_setenv.c' || echo '$(srcdir)/'`pam_setenv.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_setenv.Tpo" "$(DEPDIR)/libpam_la-pam_setenv.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_setenv.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_setenv.c' object='libpam_la-pam_setenv.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_setenv.lo `test -f 'pam_setenv.c' || echo '$(srcdir)/'`pam_setenv.c + +libpam_la-pam_start.lo: pam_start.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_start.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_start.Tpo" -c -o libpam_la-pam_start.lo `test -f 'pam_start.c' || echo '$(srcdir)/'`pam_start.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_start.Tpo" "$(DEPDIR)/libpam_la-pam_start.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_start.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_start.c' object='libpam_la-pam_start.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_start.lo `test -f 'pam_start.c' || echo '$(srcdir)/'`pam_start.c + +libpam_la-pam_strerror.lo: pam_strerror.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_strerror.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_strerror.Tpo" -c -o libpam_la-pam_strerror.lo `test -f 'pam_strerror.c' || echo '$(srcdir)/'`pam_strerror.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_strerror.Tpo" "$(DEPDIR)/libpam_la-pam_strerror.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_strerror.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_strerror.c' object='libpam_la-pam_strerror.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_strerror.lo `test -f 'pam_strerror.c' || echo '$(srcdir)/'`pam_strerror.c + +libpam_la-pam_verror.lo: pam_verror.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_verror.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_verror.Tpo" -c -o libpam_la-pam_verror.lo `test -f 'pam_verror.c' || echo '$(srcdir)/'`pam_verror.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_verror.Tpo" "$(DEPDIR)/libpam_la-pam_verror.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_verror.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_verror.c' object='libpam_la-pam_verror.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_verror.lo `test -f 'pam_verror.c' || echo '$(srcdir)/'`pam_verror.c + +libpam_la-pam_vinfo.lo: pam_vinfo.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_vinfo.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_vinfo.Tpo" -c -o libpam_la-pam_vinfo.lo `test -f 'pam_vinfo.c' || echo '$(srcdir)/'`pam_vinfo.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_vinfo.Tpo" "$(DEPDIR)/libpam_la-pam_vinfo.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_vinfo.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_vinfo.c' object='libpam_la-pam_vinfo.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_vinfo.lo `test -f 'pam_vinfo.c' || echo '$(srcdir)/'`pam_vinfo.c + +libpam_la-pam_vprompt.lo: pam_vprompt.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_vprompt.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_vprompt.Tpo" -c -o libpam_la-pam_vprompt.lo `test -f 'pam_vprompt.c' || echo '$(srcdir)/'`pam_vprompt.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_vprompt.Tpo" "$(DEPDIR)/libpam_la-pam_vprompt.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_vprompt.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_vprompt.c' object='libpam_la-pam_vprompt.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_vprompt.lo `test -f 'pam_vprompt.c' || echo '$(srcdir)/'`pam_vprompt.c + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(libdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: install-libLTLIBRARIES + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-exec \ + install-exec-am install-info install-info-am \ + install-libLTLIBRARIES install-man install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-info-am \ + uninstall-libLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/lib/openpam_borrow_cred.c b/lib/openpam_borrow_cred.c new file mode 100644 index 0000000..79a349f --- /dev/null +++ b/lib/openpam_borrow_cred.c @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_borrow_cred.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include +#include +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Temporarily borrow user credentials + */ + +int +openpam_borrow_cred(pam_handle_t *pamh, + const struct passwd *pwd) +{ + struct pam_saved_cred *scred; + const void *scredp; + int r; + + ENTERI(pwd->pw_uid); + r = pam_get_data(pamh, PAM_SAVED_CRED, &scredp); + if (r == PAM_SUCCESS && scredp != NULL) { + openpam_log(PAM_LOG_DEBUG, + "already operating under borrowed credentials"); + RETURNC(PAM_SYSTEM_ERR); + } + if (geteuid() != 0 && geteuid() != pwd->pw_uid) { + openpam_log(PAM_LOG_DEBUG, "called with non-zero euid: %d", + (int)geteuid()); + RETURNC(PAM_PERM_DENIED); + } + scred = calloc(1, sizeof *scred); + if (scred == NULL) + RETURNC(PAM_BUF_ERR); + scred->euid = geteuid(); + scred->egid = getegid(); + r = getgroups(NGROUPS_MAX, scred->groups); + if (r < 0) { + FREE(scred); + RETURNC(PAM_SYSTEM_ERR); + } + scred->ngroups = r; + r = pam_set_data(pamh, PAM_SAVED_CRED, scred, &openpam_free_data); + if (r != PAM_SUCCESS) { + FREE(scred); + RETURNC(r); + } + if (geteuid() == pwd->pw_uid) + RETURNC(PAM_SUCCESS); + if (initgroups(pwd->pw_name, pwd->pw_gid) < 0 || + setegid(pwd->pw_gid) < 0 || seteuid(pwd->pw_uid) < 0) { + openpam_restore_cred(pamh); + RETURNC(PAM_SYSTEM_ERR); + } + RETURNC(PAM_SUCCESS); +} + +/* + * Error codes: + * + * =pam_set_data + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_PERM_DENIED + */ + +/** + * The =openpam_borrow_cred function saves the current credentials and + * switches to those of the user specified by its =pwd argument. + * The affected credentials are the effective UID, the effective GID, and + * the group access list. + * The original credentials can be restored using =openpam_restore_cred. + * + * >setegid 2 + * >seteuid 2 + * >setgroups 2 + */ diff --git a/lib/openpam_configure.c b/lib/openpam_configure.c new file mode 100644 index 0000000..f9197ad --- /dev/null +++ b/lib/openpam_configure.c @@ -0,0 +1,340 @@ +/*- + * Copyright (c) 2001-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_configure.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include +#include +#include +#include + +#include + +#include "openpam_impl.h" + +const char *_pam_facility_name[PAM_NUM_FACILITIES] = { + [PAM_ACCOUNT] = "account", + [PAM_AUTH] = "auth", + [PAM_PASSWORD] = "password", + [PAM_SESSION] = "session", +}; + +const char *_pam_control_flag_name[PAM_NUM_CONTROL_FLAGS] = { + [PAM_BINDING] = "binding", + [PAM_OPTIONAL] = "optional", + [PAM_REQUIRED] = "required", + [PAM_REQUISITE] = "requisite", + [PAM_SUFFICIENT] = "sufficient", +}; + +static int openpam_load_chain(pam_handle_t *, const char *, pam_facility_t); + +/* + * Matches a word against the first one in a string. + * Returns non-zero if they match. + */ +static int +match_word(const char *str, const char *word) +{ + + while (*str && tolower(*str) == tolower(*word)) + ++str, ++word; + return (*str == ' ' && *word == '\0'); +} + +/* + * Return a pointer to the next word (or the final NUL) in a string. + */ +static const char * +next_word(const char *str) +{ + + /* skip current word */ + while (*str && *str != ' ') + ++str; + /* skip whitespace */ + while (*str == ' ') + ++str; + return (str); +} + +/* + * Return a malloc()ed copy of the first word in a string. + */ +static char * +dup_word(const char *str) +{ + const char *end; + char *word; + + for (end = str; *end && *end != ' '; ++end) + /* nothing */ ; + if (asprintf(&word, "%.*s", (int)(end - str), str) < 0) + return (NULL); + return (word); +} + +/* + * Return the length of the first word in a string. + */ +static int +wordlen(const char *str) +{ + int i; + + for (i = 0; str[i] && str[i] != ' '; ++i) + /* nothing */ ; + return (i); +} + +typedef enum { pam_conf_style, pam_d_style } openpam_style_t; + +/* + * Extracts given chains from a policy file. + */ +static int +openpam_read_chain(pam_handle_t *pamh, + const char *service, + pam_facility_t facility, + const char *filename, + openpam_style_t style) +{ + pam_chain_t *this, **next; + const char *p, *q; + int count, i, lineno, ret; + pam_facility_t fclt; + pam_control_t ctlf; + char *line, *name; + FILE *f; + + if ((f = fopen(filename, "r")) == NULL) { + openpam_log(errno == ENOENT ? PAM_LOG_DEBUG : PAM_LOG_NOTICE, + "%s: %m", filename); + return (0); + } + this = NULL; + count = lineno = 0; + while ((line = openpam_readline(f, &lineno, NULL)) != NULL) { + p = line; + + /* match service name */ + if (style == pam_conf_style) { + if (!match_word(p, service)) { + FREE(line); + continue; + } + p = next_word(p); + } + + /* match facility name */ + for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt) + if (match_word(p, _pam_facility_name[fclt])) + break; + if (fclt == PAM_NUM_FACILITIES) { + openpam_log(PAM_LOG_NOTICE, + "%s(%d): invalid facility '%.*s' (ignored)", + filename, lineno, wordlen(p), p); + goto fail; + } + if (facility != fclt && facility != PAM_FACILITY_ANY) { + FREE(line); + continue; + } + p = next_word(p); + + /* include other chain */ + if (match_word(p, "include")) { + p = next_word(p); + if (*next_word(p) != '\0') + openpam_log(PAM_LOG_NOTICE, + "%s(%d): garbage at end of 'include' line", + filename, lineno); + if ((name = dup_word(p)) == NULL) + goto syserr; + ret = openpam_load_chain(pamh, name, fclt); + FREE(name); + if (ret < 0) + goto fail; + count += ret; + FREE(line); + continue; + } + + /* allocate new entry */ + if ((this = calloc(1, sizeof *this)) == NULL) + goto syserr; + + /* control flag */ + for (ctlf = 0; ctlf < PAM_NUM_CONTROL_FLAGS; ++ctlf) + if (match_word(p, _pam_control_flag_name[ctlf])) + break; + if (ctlf == PAM_NUM_CONTROL_FLAGS) { + openpam_log(PAM_LOG_ERROR, + "%s(%d): invalid control flag '%.*s'", + filename, lineno, wordlen(p), p); + goto fail; + } + this->flag = ctlf; + + /* module name */ + p = next_word(p); + if (*p == '\0') { + openpam_log(PAM_LOG_ERROR, + "%s(%d): missing module name", + filename, lineno); + goto fail; + } + if ((name = dup_word(p)) == NULL) + goto syserr; + this->module = openpam_load_module(name); + FREE(name); + if (this->module == NULL) + goto fail; + + /* module options */ + p = q = next_word(p); + while (*q != '\0') { + ++this->optc; + q = next_word(q); + } + this->optv = calloc(this->optc + 1, sizeof(char *)); + if (this->optv == NULL) + goto syserr; + for (i = 0; i < this->optc; ++i) { + if ((this->optv[i] = dup_word(p)) == NULL) + goto syserr; + p = next_word(p); + } + + /* hook it up */ + for (next = &pamh->chains[fclt]; *next != NULL; + next = &(*next)->next) + /* nothing */ ; + *next = this; + this = NULL; + ++count; + + /* next please... */ + FREE(line); + } + if (!feof(f)) + goto syserr; + fclose(f); + return (count); + syserr: + openpam_log(PAM_LOG_ERROR, "%s: %m", filename); + fail: + FREE(this); + FREE(line); + fclose(f); + return (-1); +} + +static const char *openpam_policy_path[] = { + "/etc/pam.d/", + "/etc/pam.conf", + "/usr/local/etc/pam.d/", + "/usr/local/etc/pam.conf", + NULL +}; + +/* + * Locates the policy file for a given service and reads the given chains + * from it. + */ +static int +openpam_load_chain(pam_handle_t *pamh, + const char *service, + pam_facility_t facility) +{ + const char **path; + char *filename; + size_t len; + int r; + + for (path = openpam_policy_path; *path != NULL; ++path) { + len = strlen(*path); + if ((*path)[len - 1] == '/') { + if (asprintf(&filename, "%s%s", *path, service) < 0) { + openpam_log(PAM_LOG_ERROR, "asprintf(): %m"); + return (-PAM_BUF_ERR); + } + r = openpam_read_chain(pamh, service, facility, + filename, pam_d_style); + FREE(filename); + } else { + r = openpam_read_chain(pamh, service, facility, + *path, pam_conf_style); + } + if (r != 0) + return (r); + } + return (0); +} + +/* + * OpenPAM internal + * + * Configure a service + */ + +int +openpam_configure(pam_handle_t *pamh, + const char *service) +{ + pam_facility_t fclt; + + if (openpam_load_chain(pamh, service, PAM_FACILITY_ANY) < 0) + goto load_err; + + for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt) { + if (pamh->chains[fclt] != NULL) + continue; + if (openpam_load_chain(pamh, PAM_OTHER, fclt) < 0) + goto load_err; + } + return (PAM_SUCCESS); + load_err: + openpam_clear_chains(pamh->chains); + return (PAM_SYSTEM_ERR); +} + +/* + * NODOC + * + * Error codes: + * PAM_SYSTEM_ERR + */ diff --git a/lib/openpam_dispatch.c b/lib/openpam_dispatch.c new file mode 100644 index 0000000..69fe472 --- /dev/null +++ b/lib/openpam_dispatch.c @@ -0,0 +1,240 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_dispatch.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +#if !defined(OPENPAM_RELAX_CHECKS) +static void _openpam_check_error_code(int, int); +#else +#define _openpam_check_error_code(a, b) +#endif /* !defined(OPENPAM_RELAX_CHECKS) */ + +/* + * OpenPAM internal + * + * Execute a module chain + */ + +int +openpam_dispatch(pam_handle_t *pamh, + int primitive, + int flags) +{ + pam_chain_t *chain; + int err, fail, r; +#ifdef DEBUG + int debug; +#endif + + ENTER(); + if (pamh == NULL) + RETURNC(PAM_SYSTEM_ERR); + + /* prevent recursion */ + if (pamh->current != NULL) { + openpam_log(PAM_LOG_ERROR, + "%s() called while %s::%s() is in progress", + _pam_func_name[primitive], + pamh->current->module->path, + _pam_sm_func_name[pamh->primitive]); + RETURNC(PAM_ABORT); + } + + /* pick a chain */ + switch (primitive) { + case PAM_SM_AUTHENTICATE: + case PAM_SM_SETCRED: + chain = pamh->chains[PAM_AUTH]; + break; + case PAM_SM_ACCT_MGMT: + chain = pamh->chains[PAM_ACCOUNT]; + break; + case PAM_SM_OPEN_SESSION: + case PAM_SM_CLOSE_SESSION: + chain = pamh->chains[PAM_SESSION]; + break; + case PAM_SM_CHAUTHTOK: + chain = pamh->chains[PAM_PASSWORD]; + break; + default: + RETURNC(PAM_SYSTEM_ERR); + } + + /* execute */ + for (err = fail = 0; chain != NULL; chain = chain->next) { + if (chain->module->func[primitive] == NULL) { + openpam_log(PAM_LOG_ERROR, "%s: no %s()", + chain->module->path, _pam_sm_func_name[primitive]); + continue; + } else { + pamh->primitive = primitive; + pamh->current = chain; +#ifdef DEBUG + debug = (openpam_get_option(pamh, "debug") != NULL); + if (debug) + ++_openpam_debug; + openpam_log(PAM_LOG_DEBUG, "calling %s() in %s", + _pam_sm_func_name[primitive], chain->module->path); +#endif + r = (chain->module->func[primitive])(pamh, flags, + chain->optc, (const char **)chain->optv); + pamh->current = NULL; +#ifdef DEBUG + openpam_log(PAM_LOG_DEBUG, "%s: %s(): %s", + chain->module->path, _pam_sm_func_name[primitive], + pam_strerror(pamh, r)); + if (debug) + --_openpam_debug; +#endif + } + + if (r == PAM_IGNORE) + continue; + if (r == PAM_SUCCESS) { + /* + * For pam_setcred() and pam_chauthtok() with the + * PAM_PRELIM_CHECK flag, treat "sufficient" as + * "optional". + */ + if ((chain->flag == PAM_SUFFICIENT || + chain->flag == PAM_BINDING) && !fail && + primitive != PAM_SM_SETCRED && + !(primitive == PAM_SM_CHAUTHTOK && + (flags & PAM_PRELIM_CHECK))) + break; + continue; + } + + _openpam_check_error_code(primitive, r); + + /* + * Record the return code from the first module to + * fail. If a required module fails, record the + * return code from the first required module to fail. + */ + if (err == 0) + err = r; + if ((chain->flag == PAM_REQUIRED || + chain->flag == PAM_BINDING) && !fail) { + openpam_log(PAM_LOG_DEBUG, "required module failed"); + fail = 1; + err = r; + } + + /* + * If a requisite module fails, terminate the chain + * immediately. + */ + if (chain->flag == PAM_REQUISITE) { + openpam_log(PAM_LOG_DEBUG, "requisite module failed"); + fail = 1; + break; + } + } + + if (!fail && err != PAM_NEW_AUTHTOK_REQD) + err = PAM_SUCCESS; + RETURNC(err); +} + +#if !defined(OPENPAM_RELAX_CHECKS) +static void +_openpam_check_error_code(int primitive, int r) +{ + /* common error codes */ + if (r == PAM_SUCCESS || + r == PAM_SERVICE_ERR || + r == PAM_BUF_ERR || + r == PAM_CONV_ERR || + r == PAM_PERM_DENIED || + r == PAM_ABORT) + return; + + /* specific error codes */ + switch (primitive) { + case PAM_SM_AUTHENTICATE: + if (r == PAM_AUTH_ERR || + r == PAM_CRED_INSUFFICIENT || + r == PAM_AUTHINFO_UNAVAIL || + r == PAM_USER_UNKNOWN || + r == PAM_MAXTRIES) + return; + break; + case PAM_SM_SETCRED: + if (r == PAM_CRED_UNAVAIL || + r == PAM_CRED_EXPIRED || + r == PAM_USER_UNKNOWN || + r == PAM_CRED_ERR) + return; + break; + case PAM_SM_ACCT_MGMT: + if (r == PAM_USER_UNKNOWN || + r == PAM_AUTH_ERR || + r == PAM_NEW_AUTHTOK_REQD || + r == PAM_ACCT_EXPIRED) + return; + break; + case PAM_SM_OPEN_SESSION: + case PAM_SM_CLOSE_SESSION: + if (r == PAM_SESSION_ERR) + return; + break; + case PAM_SM_CHAUTHTOK: + if (r == PAM_PERM_DENIED || + r == PAM_AUTHTOK_ERR || + r == PAM_AUTHTOK_RECOVERY_ERR || + r == PAM_AUTHTOK_LOCK_BUSY || + r == PAM_AUTHTOK_DISABLE_AGING || + r == PAM_TRY_AGAIN) + return; + break; + } + + openpam_log(PAM_LOG_ERROR, "%s(): unexpected return value %d", + _pam_sm_func_name[primitive], r); +} +#endif /* !defined(OPENPAM_RELAX_CHECKS) */ + +/* + * NODOC + * + * Error codes: + */ diff --git a/lib/openpam_dynamic.c b/lib/openpam_dynamic.c new file mode 100644 index 0000000..084408e --- /dev/null +++ b/lib/openpam_dynamic.c @@ -0,0 +1,110 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_dynamic.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include +#include +#include + +#include + +#include "openpam_impl.h" + +#ifndef RTLD_NOW +#define RTLD_NOW RTLD_LAZY +#endif + +/* + * OpenPAM internal + * + * Locate a dynamically linked module + */ + +pam_module_t * +openpam_dynamic(const char *path) +{ + pam_module_t *module; + const char *prefix; + char *vpath; + void *dlh; + int i; + + dlh = NULL; + if ((module = calloc(1, sizeof *module)) == NULL) + goto buf_err; + + /* Prepend the standard prefix if not an absolute pathname. */ + if (path[0] != '/') + prefix = OPENPAM_MODULES_DIR; + else + prefix = ""; + + /* try versioned module first, then unversioned module */ + if (asprintf(&vpath, "%s%s.%d", prefix, path, LIB_MAJ) < 0) + goto buf_err; + if ((dlh = dlopen(vpath, RTLD_NOW)) == NULL) { + openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror()); + *strrchr(vpath, '.') = '\0'; + if ((dlh = dlopen(vpath, RTLD_NOW)) == NULL) { + openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror()); + FREE(vpath); + FREE(module); + return (NULL); + } + } + FREE(vpath); + if ((module->path = strdup(path)) == NULL) + goto buf_err; + module->dlh = dlh; + for (i = 0; i < PAM_NUM_PRIMITIVES; ++i) { + module->func[i] = (pam_func_t)dlsym(dlh, _pam_sm_func_name[i]); + if (module->func[i] == NULL) + openpam_log(PAM_LOG_DEBUG, "%s: %s(): %s", + path, _pam_sm_func_name[i], dlerror()); + } + return (module); + buf_err: + openpam_log(PAM_LOG_ERROR, "%m"); + if (dlh != NULL) + dlclose(dlh); + FREE(module); + return (NULL); +} + +/* + * NOPARSE + */ diff --git a/lib/openpam_findenv.c b/lib/openpam_findenv.c new file mode 100644 index 0000000..d78e147 --- /dev/null +++ b/lib/openpam_findenv.c @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_findenv.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * OpenPAM internal + * + * Locate an environment variable + */ + +int +openpam_findenv(pam_handle_t *pamh, + const char *name, + size_t len) +{ + int i; + + ENTER(); + if (pamh == NULL) + RETURNN(-1); + for (i = 0; i < pamh->env_count; ++i) + if (strncmp(pamh->env[i], name, len) == 0 && + pamh->env[i][len] == '=') + RETURNN(i); + RETURNN(-1); +} + +/* + * NODOC + */ diff --git a/lib/openpam_free_data.c b/lib/openpam_free_data.c new file mode 100644 index 0000000..e071c0a --- /dev/null +++ b/lib/openpam_free_data.c @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_free_data.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Generic cleanup function + */ + +void +openpam_free_data(pam_handle_t *pamh, + void *data, + int status) +{ + + ENTER(); + (void)pamh; + (void)status; + FREE(data); + RETURNV(); +} + +/* + * Error codes: + */ + +/** + * The =openpam_free_data function is a cleanup function suitable for + * passing to =pam_set_data. + * It simply releases the data by passing its =data argument to =free. + */ diff --git a/lib/openpam_free_envlist.c b/lib/openpam_free_envlist.c new file mode 100644 index 0000000..346c2dd --- /dev/null +++ b/lib/openpam_free_envlist.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2005 Dag-Erling Coïdan Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: openpam_free_envlist.c 320 2006-02-16 20:33:19Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Free an environment list + */ + +void +openpam_free_envlist(char **envlist) +{ + char **env; + + ENTER(); + if (envlist == NULL) + RETURNV(); + for (env = envlist; *env != NULL; ++env) + FREE(*env); + FREE(envlist); + RETURNV(); +} + +/* + * Error codes: + */ + +/** + * The =openpam_free_envlist function is a convenience function which + * frees all the environment variables in an environment list, and the + * list itself. + * It is suitable for freeing the return value from =pam_getenvlist. + */ diff --git a/lib/openpam_get_option.c b/lib/openpam_get_option.c new file mode 100644 index 0000000..73bc070 --- /dev/null +++ b/lib/openpam_get_option.c @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_get_option.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Returns the value of a module option + */ + +const char * +openpam_get_option(pam_handle_t *pamh, + const char *option) +{ + pam_chain_t *cur; + size_t len; + int i; + + ENTERS(option); + if (pamh == NULL || pamh->current == NULL || option == NULL) + RETURNS(NULL); + cur = pamh->current; + len = strlen(option); + for (i = 0; i < cur->optc; ++i) { + if (strncmp(cur->optv[i], option, len) == 0) { + if (cur->optv[i][len] == '\0') + RETURNS(&cur->optv[i][len]); + else if (cur->optv[i][len] == '=') + RETURNS(&cur->optv[i][len + 1]); + } + } + RETURNS(NULL); +} + +/** + * The =openpam_get_option function returns the value of the specified + * option in the context of the currently executing service module, or + * =NULL if the option is not set or no module is currently executing. + * + * >openpam_set_option + */ diff --git a/lib/openpam_impl.h b/lib/openpam_impl.h new file mode 100644 index 0000000..7704d4e --- /dev/null +++ b/lib/openpam_impl.h @@ -0,0 +1,200 @@ +/*- + * Copyright (c) 2001-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_impl.h 408 2007-12-21 11:36:24Z des $ + */ + +#ifndef _OPENPAM_IMPL_H_INCLUDED +#define _OPENPAM_IMPL_H_INCLUDED + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +extern const char *_pam_func_name[PAM_NUM_PRIMITIVES]; +extern const char *_pam_sm_func_name[PAM_NUM_PRIMITIVES]; +extern const char *_pam_err_name[PAM_NUM_ERRORS]; +extern const char *_pam_item_name[PAM_NUM_ITEMS]; + +extern int _openpam_debug; + +/* + * Control flags + */ +typedef enum { + PAM_BINDING, + PAM_REQUIRED, + PAM_REQUISITE, + PAM_SUFFICIENT, + PAM_OPTIONAL, + PAM_NUM_CONTROL_FLAGS +} pam_control_t; + +/* + * Facilities + */ +typedef enum { + PAM_FACILITY_ANY = -1, + PAM_AUTH = 0, + PAM_ACCOUNT, + PAM_SESSION, + PAM_PASSWORD, + PAM_NUM_FACILITIES +} pam_facility_t; + +typedef struct pam_chain pam_chain_t; +struct pam_chain { + pam_module_t *module; + int flag; + int optc; + char **optv; + pam_chain_t *next; +}; + +typedef struct pam_data pam_data_t; +struct pam_data { + char *name; + void *data; + void (*cleanup)(pam_handle_t *, void *, int); + pam_data_t *next; +}; + +struct pam_handle { + char *service; + + /* chains */ + pam_chain_t *chains[PAM_NUM_FACILITIES]; + pam_chain_t *current; + int primitive; + + /* items and data */ + void *item[PAM_NUM_ITEMS]; + pam_data_t *module_data; + + /* environment list */ + char **env; + int env_count; + int env_size; +}; + +#ifdef NGROUPS_MAX +#define PAM_SAVED_CRED "pam_saved_cred" +struct pam_saved_cred { + uid_t euid; + gid_t egid; + gid_t groups[NGROUPS_MAX]; + int ngroups; +}; +#endif + +#define PAM_OTHER "other" + +int openpam_configure(pam_handle_t *, const char *); +int openpam_dispatch(pam_handle_t *, int, int); +int openpam_findenv(pam_handle_t *, const char *, size_t); +pam_module_t *openpam_load_module(const char *); +void openpam_clear_chains(pam_chain_t **); + +#ifdef OPENPAM_STATIC_MODULES +pam_module_t *openpam_static(const char *); +#endif +pam_module_t *openpam_dynamic(const char *); + +#define FREE(p) do { free((p)); (p) = NULL; } while (0) + +#ifdef DEBUG +#define ENTER() openpam_log(PAM_LOG_DEBUG, "entering") +#define ENTERI(i) do { \ + int _i = (i); \ + if (_i > 0 && _i < PAM_NUM_ITEMS) \ + openpam_log(PAM_LOG_DEBUG, "entering: %s", _pam_item_name[_i]); \ + else \ + openpam_log(PAM_LOG_DEBUG, "entering: %d", _i); \ +} while (0) +#define ENTERN(n) do { \ + int _n = (n); \ + openpam_log(PAM_LOG_DEBUG, "entering: %d", _n); \ +} while (0) +#define ENTERS(s) do { \ + const char *_s = (s); \ + if (_s == NULL) \ + openpam_log(PAM_LOG_DEBUG, "entering: NULL"); \ + else \ + openpam_log(PAM_LOG_DEBUG, "entering: '%s'", _s); \ +} while (0) +#define RETURNV() openpam_log(PAM_LOG_DEBUG, "returning") +#define RETURNC(c) do { \ + int _c = (c); \ + if (_c >= 0 && _c < PAM_NUM_ERRORS) \ + openpam_log(PAM_LOG_DEBUG, "returning %s", _pam_err_name[_c]); \ + else \ + openpam_log(PAM_LOG_DEBUG, "returning %d!", _c); \ + return (_c); \ +} while (0) +#define RETURNN(n) do { \ + int _n = (n); \ + openpam_log(PAM_LOG_DEBUG, "returning %d", _n); \ + return (_n); \ +} while (0) +#define RETURNP(p) do { \ + const void *_p = (p); \ + if (_p == NULL) \ + openpam_log(PAM_LOG_DEBUG, "returning NULL"); \ + else \ + openpam_log(PAM_LOG_DEBUG, "returning %p", _p); \ + return (p); \ +} while (0) +#define RETURNS(s) do { \ + const char *_s = (s); \ + if (_s == NULL) \ + openpam_log(PAM_LOG_DEBUG, "returning NULL"); \ + else \ + openpam_log(PAM_LOG_DEBUG, "returning '%s'", _s); \ + return (_s); \ +} while (0) +#else +#define ENTER() +#define ENTERI(i) +#define ENTERN(n) +#define ENTERS(s) +#define RETURNV() return +#define RETURNC(c) return (c) +#define RETURNN(n) return (n) +#define RETURNP(p) return (p) +#define RETURNS(s) return (s) +#endif + +#endif diff --git a/lib/openpam_load.c b/lib/openpam_load.c new file mode 100644 index 0000000..303f3f5 --- /dev/null +++ b/lib/openpam_load.c @@ -0,0 +1,153 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_load.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include +#include + +#include + +#include "openpam_impl.h" + +const char *_pam_func_name[PAM_NUM_PRIMITIVES] = { + "pam_authenticate", + "pam_setcred", + "pam_acct_mgmt", + "pam_open_session", + "pam_close_session", + "pam_chauthtok" +}; + +const char *_pam_sm_func_name[PAM_NUM_PRIMITIVES] = { + "pam_sm_authenticate", + "pam_sm_setcred", + "pam_sm_acct_mgmt", + "pam_sm_open_session", + "pam_sm_close_session", + "pam_sm_chauthtok" +}; + +/* + * Locate a matching dynamic or static module. + */ + +pam_module_t * +openpam_load_module(const char *path) +{ + pam_module_t *module; + + module = openpam_dynamic(path); + openpam_log(PAM_LOG_DEBUG, "%s dynamic %s", + (module == NULL) ? "no" : "using", path); + +#ifdef OPENPAM_STATIC_MODULES + /* look for a static module */ + if (module == NULL && strchr(path, '/') == NULL) { + module = openpam_static(path); + openpam_log(PAM_LOG_DEBUG, "%s static %s", + (module == NULL) ? "no" : "using", path); + } +#endif + if (module == NULL) { + openpam_log(PAM_LOG_ERROR, "no %s found", path); + return (NULL); + } + return (module); +} + + +/* + * Release a module. + * XXX highly thread-unsafe + */ + +static void +openpam_release_module(pam_module_t *module) +{ + if (module == NULL) + return; + if (module->dlh == NULL) + /* static module */ + return; + dlclose(module->dlh); + openpam_log(PAM_LOG_DEBUG, "releasing %s", module->path); + FREE(module->path); + FREE(module); +} + + +/* + * Destroy a chain, freeing all its links and releasing the modules + * they point to. + */ + +static void +openpam_destroy_chain(pam_chain_t *chain) +{ + if (chain == NULL) + return; + openpam_destroy_chain(chain->next); + chain->next = NULL; + while (chain->optc) { + --chain->optc; + FREE(chain->optv[chain->optc]); + } + FREE(chain->optv); + openpam_release_module(chain->module); + chain->module = NULL; + FREE(chain); +} + + +/* + * Clear the chains and release the modules + */ + +void +openpam_clear_chains(pam_chain_t *policy[]) +{ + int i; + + for (i = 0; i < PAM_NUM_FACILITIES; ++i) { + openpam_destroy_chain(policy[i]); + policy[i] = NULL; + } +} + +/* + * NOPARSE + */ diff --git a/lib/openpam_log.c b/lib/openpam_log.c new file mode 100644 index 0000000..e492294 --- /dev/null +++ b/lib/openpam_log.c @@ -0,0 +1,158 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_log.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "openpam_impl.h" + +#ifdef OPENPAM_DEBUG +int _openpam_debug = 1; +#else +int _openpam_debug = 0; +#endif + +#if !defined(openpam_log) + +/* + * OpenPAM extension + * + * Log a message through syslog + */ + +void +openpam_log(int level, const char *fmt, ...) +{ + va_list ap; + int priority; + + switch (level) { + case PAM_LOG_DEBUG: + if (!_openpam_debug) + return; + priority = LOG_DEBUG; + break; + case PAM_LOG_VERBOSE: + priority = LOG_INFO; + break; + case PAM_LOG_NOTICE: + priority = LOG_NOTICE; + break; + case PAM_LOG_ERROR: + default: + priority = LOG_ERR; + break; + } + va_start(ap, fmt); + vsyslog(priority, fmt, ap); + va_end(ap); +} + +#else + +void +_openpam_log(int level, const char *func, const char *fmt, ...) +{ + va_list ap; + char *format; + int priority; + + switch (level) { + case PAM_LOG_DEBUG: + if (!_openpam_debug) + return; + priority = LOG_DEBUG; + break; + case PAM_LOG_VERBOSE: + priority = LOG_INFO; + break; + case PAM_LOG_NOTICE: + priority = LOG_NOTICE; + break; + case PAM_LOG_ERROR: + default: + priority = LOG_ERR; + break; + } + va_start(ap, fmt); + if (asprintf(&format, "in %s(): %s", func, fmt) > 0) { + vsyslog(priority, format, ap); + FREE(format); + } else { + vsyslog(priority, fmt, ap); + } + va_end(ap); +} + +#endif + +/** + * The =openpam_log function logs messages using =syslog. + * It is primarily intended for internal use by the library and modules. + * + * The =level argument indicates the importance of the message. + * The following levels are defined: + * + * =PAM_LOG_DEBUG: + * Debugging messages. + * These messages are normally not logged unless the global + * integer variable :_openpam_debug is set to a non-zero + * value, in which case they are logged with a =syslog + * priority of =LOG_DEBUG. + * =PAM_LOG_VERBOSE: + * Information about the progress of the authentication + * process, or other non-essential messages. + * These messages are logged with a =syslog priority of + * =LOG_INFO. + * =PAM_LOG_NOTICE: + * Messages relating to non-fatal errors. + * These messages are logged with a =syslog priority of + * =LOG_NOTICE. + * =PAM_LOG_ERROR: + * Messages relating to serious errors. + * These messages are logged with a =syslog priority of + * =LOG_ERR. + * + * The remaining arguments are a =printf format string and the + * corresponding arguments. + */ diff --git a/lib/openpam_nullconv.c b/lib/openpam_nullconv.c new file mode 100644 index 0000000..3294dcf --- /dev/null +++ b/lib/openpam_nullconv.c @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_nullconv.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Null conversation function + */ + +int +openpam_nullconv(int n, + const struct pam_message **msg, + struct pam_response **resp, + void *data) +{ + + ENTER(); + (void)n; + (void)msg; + (void)resp; + (void)data; + RETURNC(PAM_CONV_ERR); +} + +/* + * Error codes: + * + * PAM_CONV_ERR + */ + +/** + * The =openpam_nullconv function is a null conversation function suitable + * for applications that want to use PAM but don't support interactive + * dialog with the user. + * Such applications should set =PAM_AUTHTOK to whatever authentication + * token they've obtained on their own before calling =pam_authenticate + * and / or =pam_chauthtok, and their PAM configuration should specify the + * ;use_first_pass option for all modules that require access to the + * authentication token, to make sure they use =PAM_AUTHTOK rather than + * try to query the user. + * + * >openpam_ttyconv + * >pam_prompt + * >pam_set_item + * >pam_vprompt + */ diff --git a/lib/openpam_readline.c b/lib/openpam_readline.c new file mode 100644 index 0000000..17f03f3 --- /dev/null +++ b/lib/openpam_readline.c @@ -0,0 +1,155 @@ +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_readline.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include +#include + +#include +#include "openpam_impl.h" + +#define MIN_LINE_LENGTH 128 + +/* + * OpenPAM extension + * + * Read a line from a file. + */ + +char * +openpam_readline(FILE *f, int *lineno, size_t *lenp) +{ + char *line; + size_t len, size; + int ch; + + if ((line = malloc(MIN_LINE_LENGTH)) == NULL) + return (NULL); + size = MIN_LINE_LENGTH; + len = 0; + +#define line_putch(ch) do { \ + if (len >= size - 1) { \ + char *tmp = realloc(line, size *= 2); \ + if (tmp == NULL) \ + goto fail; \ + line = tmp; \ + } \ + line[len++] = ch; \ + line[len] = '\0'; \ +} while (0) + + for (;;) { + ch = fgetc(f); + /* strip comment */ + if (ch == '#') { + do { + ch = fgetc(f); + } while (ch != EOF && ch != '\n'); + } + /* eof */ + if (ch == EOF) { + /* remove trailing whitespace */ + while (len > 0 && isspace((int)line[len - 1])) + --len; + line[len] = '\0'; + if (len == 0) + goto fail; + break; + } + /* eol */ + if (ch == '\n') { + if (lineno != NULL) + ++*lineno; + + /* remove trailing whitespace */ + while (len > 0 && isspace((int)line[len - 1])) + --len; + line[len] = '\0'; + /* skip blank lines */ + if (len == 0) + continue; + /* continuation */ + if (line[len - 1] == '\\') { + line[--len] = '\0'; + /* fall through to whitespace case */ + } else { + break; + } + } + /* whitespace */ + if (isspace(ch)) { + /* ignore leading whitespace */ + /* collapse linear whitespace */ + if (len > 0 && line[len - 1] != ' ') + line_putch(' '); + continue; + } + /* anything else */ + line_putch(ch); + } + + if (lenp != NULL) + *lenp = len; + return (line); + fail: + FREE(line); + return (NULL); +} + +/** + * The =openpam_readline function reads a line from a file, and returns it + * in a NUL-terminated buffer allocated with =malloc. + * + * The =openpam_readline function performs a certain amount of processing + * on the data it reads. + * Comments (introduced by a hash sign) are stripped, as is leading and + * trailing whitespace. + * Any amount of linear whitespace is collapsed to a single space. + * Blank lines are ignored. + * If a line ends in a backslash, the backslash is stripped and the next + * line is appended. + * + * If =lineno is not =NULL, the integer variable it points to is + * incremented every time a newline character is read. + * + * If =lenp is not =NULL, the length of the line (not including the + * terminating NUL character) is stored in the variable it points to. + * + * The caller is responsible for releasing the returned buffer by passing + * it to =free. + */ diff --git a/lib/openpam_restore_cred.c b/lib/openpam_restore_cred.c new file mode 100644 index 0000000..20e80d4 --- /dev/null +++ b/lib/openpam_restore_cred.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_restore_cred.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include +#include +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Restore credentials + */ + +int +openpam_restore_cred(pam_handle_t *pamh) +{ + const struct pam_saved_cred *scred; + const void *scredp; + int r; + + ENTER(); + r = pam_get_data(pamh, PAM_SAVED_CRED, &scredp); + if (r != PAM_SUCCESS) + RETURNC(r); + if (scredp == NULL) + RETURNC(PAM_SYSTEM_ERR); + scred = scredp; + if (scred->euid != geteuid()) { + if (seteuid(scred->euid) < 0 || + setgroups(scred->ngroups, scred->groups) < 0 || + setegid(scred->egid) < 0) + RETURNC(PAM_SYSTEM_ERR); + } + pam_set_data(pamh, PAM_SAVED_CRED, NULL, NULL); + RETURNC(PAM_SUCCESS); +} + +/* + * Error codes: + * + * =pam_get_data + * PAM_SYSTEM_ERR + */ + +/** + * The =openpam_restore_cred function restores the credentials saved by + * =openpam_borrow_cred. + * + * >setegid 2 + * >seteuid 2 + * >setgroups 2 + */ diff --git a/lib/openpam_set_option.c b/lib/openpam_set_option.c new file mode 100644 index 0000000..57161d3 --- /dev/null +++ b/lib/openpam_set_option.c @@ -0,0 +1,119 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_set_option.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include +#include + +#include +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Sets the value of a module option + */ + +int +openpam_set_option(pam_handle_t *pamh, + const char *option, + const char *value) +{ + pam_chain_t *cur; + char *opt, **optv; + size_t len; + int i; + + ENTERS(option); + if (pamh == NULL || pamh->current == NULL || option == NULL) + RETURNC(PAM_SYSTEM_ERR); + cur = pamh->current; + for (len = 0; option[len] != '\0'; ++len) + if (option[len] == '=') + break; + for (i = 0; i < cur->optc; ++i) { + if (strncmp(cur->optv[i], option, len) == 0 && + (cur->optv[i][len] == '\0' || cur->optv[i][len] == '=')) + break; + } + if (value == NULL) { + /* remove */ + if (i == cur->optc) + RETURNC(PAM_SUCCESS); + for (free(cur->optv[i]); i < cur->optc; ++i) + cur->optv[i] = cur->optv[i + 1]; + cur->optv[i] = NULL; + RETURNC(PAM_SUCCESS); + } + if (asprintf(&opt, "%.*s=%s", (int)len, option, value) < 0) + RETURNC(PAM_BUF_ERR); + if (i == cur->optc) { + /* add */ + optv = realloc(cur->optv, sizeof(char *) * (cur->optc + 2)); + if (optv == NULL) { + FREE(opt); + RETURNC(PAM_BUF_ERR); + } + optv[i] = opt; + optv[i + 1] = NULL; + cur->optv = optv; + ++cur->optc; + } else { + /* replace */ + FREE(cur->optv[i]); + cur->optv[i] = opt; + } + RETURNC(PAM_SUCCESS); +} + +/* + * Error codes: + * + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + */ + +/** + * The =openpam_set_option function sets the specified option in the + * context of the currently executing service module. + * + * >openpam_get_option + */ diff --git a/lib/openpam_static.c b/lib/openpam_static.c new file mode 100644 index 0000000..c06ceed --- /dev/null +++ b/lib/openpam_static.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_static.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +#ifdef OPENPAM_STATIC_MODULES + +SET_DECLARE(_openpam_static_modules, pam_module_t); + +/* + * OpenPAM internal + * + * Locate a statically linked module + */ + +pam_module_t * +openpam_static(const char *path) +{ + pam_module_t **module; + + SET_FOREACH(module, _openpam_static_modules) { + if (strcmp((*module)->path, path) == 0) + return (*module); + } + return (NULL); +} + +#endif + +/* + * NOPARSE + */ diff --git a/lib/openpam_ttyconv.c b/lib/openpam_ttyconv.c new file mode 100644 index 0000000..a6820b9 --- /dev/null +++ b/lib/openpam_ttyconv.c @@ -0,0 +1,248 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_ttyconv.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "openpam_impl.h" + +int openpam_ttyconv_timeout = 0; + +static void +timeout(int sig) +{ + + (void)sig; +} + +static char * +prompt(const char *msg) +{ + char buf[PAM_MAX_RESP_SIZE]; + struct sigaction action, saved_action; + sigset_t saved_sigset, sigset; + unsigned int saved_alarm; + int eof, error, fd; + size_t len; + char *retval; + char ch; + + sigemptyset(&sigset); + sigaddset(&sigset, SIGINT); + sigaddset(&sigset, SIGTSTP); + sigprocmask(SIG_SETMASK, &sigset, &saved_sigset); + action.sa_handler = &timeout; + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + sigaction(SIGALRM, &action, &saved_action); + fputs(msg, stdout); + fflush(stdout); +#ifdef HAVE_FPURGE + fpurge(stdin); +#endif + fd = fileno(stdin); + buf[0] = '\0'; + eof = error = 0; + saved_alarm = 0; + if (openpam_ttyconv_timeout >= 0) + saved_alarm = alarm(openpam_ttyconv_timeout); + ch = '\0'; + for (len = 0; ch != '\n' && !eof && !error; ++len) { + switch (read(fd, &ch, 1)) { + case 1: + if (len < PAM_MAX_RESP_SIZE - 1) { + buf[len + 1] = '\0'; + buf[len] = ch; + } + break; + case 0: + eof = 1; + break; + default: + error = errno; + break; + } + } + if (openpam_ttyconv_timeout >= 0) + alarm(0); + sigaction(SIGALRM, &saved_action, NULL); + sigprocmask(SIG_SETMASK, &saved_sigset, NULL); + if (saved_alarm > 0) + alarm(saved_alarm); + if (error == EINTR) + fputs(" timeout!", stderr); + if (error || eof) { + fputs("\n", stderr); + memset(buf, 0, sizeof(buf)); + return (NULL); + } + /* trim trailing whitespace */ + for (len = strlen(buf); len > 0; --len) + if (buf[len - 1] != '\r' && buf[len - 1] != '\n') + break; + buf[len] = '\0'; + retval = strdup(buf); + memset(buf, 0, sizeof(buf)); + return (retval); +} + +static char * +prompt_echo_off(const char *msg) +{ + struct termios tattr; + tcflag_t lflag; + char *ret; + int fd; + + fd = fileno(stdin); + if (tcgetattr(fd, &tattr) != 0) { + openpam_log(PAM_LOG_ERROR, "tcgetattr(): %m"); + return (NULL); + } + lflag = tattr.c_lflag; + tattr.c_lflag &= ~ECHO; + if (tcsetattr(fd, TCSAFLUSH, &tattr) != 0) { + openpam_log(PAM_LOG_ERROR, "tcsetattr(): %m"); + return (NULL); + } + ret = prompt(msg); + tattr.c_lflag = lflag; + (void)tcsetattr(fd, TCSANOW, &tattr); + if (ret != NULL) + fputs("\n", stdout); + return (ret); +} + +/* + * OpenPAM extension + * + * Simple tty-based conversation function + */ + +int +openpam_ttyconv(int n, + const struct pam_message **msg, + struct pam_response **resp, + void *data) +{ + struct pam_response *aresp; + int i; + + ENTER(); + (void)data; + if (n <= 0 || n > PAM_MAX_NUM_MSG) + RETURNC(PAM_CONV_ERR); + if ((aresp = calloc(n, sizeof *aresp)) == NULL) + RETURNC(PAM_BUF_ERR); + for (i = 0; i < n; ++i) { + aresp[i].resp_retcode = 0; + aresp[i].resp = NULL; + switch (msg[i]->msg_style) { + case PAM_PROMPT_ECHO_OFF: + aresp[i].resp = prompt_echo_off(msg[i]->msg); + if (aresp[i].resp == NULL) + goto fail; + break; + case PAM_PROMPT_ECHO_ON: + aresp[i].resp = prompt(msg[i]->msg); + if (aresp[i].resp == NULL) + goto fail; + break; + case PAM_ERROR_MSG: + fputs(msg[i]->msg, stderr); + if (strlen(msg[i]->msg) > 0 && + msg[i]->msg[strlen(msg[i]->msg) - 1] != '\n') + fputc('\n', stderr); + break; + case PAM_TEXT_INFO: + fputs(msg[i]->msg, stdout); + if (strlen(msg[i]->msg) > 0 && + msg[i]->msg[strlen(msg[i]->msg) - 1] != '\n') + fputc('\n', stdout); + break; + default: + goto fail; + } + } + *resp = aresp; + RETURNC(PAM_SUCCESS); + fail: + for (i = 0; i < n; ++i) { + if (aresp[i].resp != NULL) { + memset(aresp[i].resp, 0, strlen(aresp[i].resp)); + FREE(aresp[i].resp); + } + } + memset(aresp, 0, n * sizeof *aresp); + FREE(aresp); + *resp = NULL; + RETURNC(PAM_CONV_ERR); +} + +/* + * Error codes: + * + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + */ + +/** + * The =openpam_ttyconv function is a standard conversation function + * suitable for use on TTY devices. + * It should be adequate for the needs of most text-based interactive + * programs. + * + * The =openpam_ttyconv function allows the application to specify a + * timeout for user input by setting the global integer variable + * :openpam_ttyconv_timeout to the length of the timeout in seconds. + * + * >openpam_nullconv + * >pam_prompt + * >pam_vprompt + */ diff --git a/lib/pam_acct_mgmt.c b/lib/pam_acct_mgmt.c new file mode 100644 index 0000000..0088ecf --- /dev/null +++ b/lib/pam_acct_mgmt.c @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_acct_mgmt.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 32 + * + * Perform PAM account validation procedures + */ + +int +pam_acct_mgmt(pam_handle_t *pamh, + int flags) +{ + int r; + + ENTER(); + r = openpam_dispatch(pamh, PAM_SM_ACCT_MGMT, flags); + RETURNC(r); +} + +/* + * Error codes: + * + * =openpam_dispatch + * =pam_sm_acct_mgmt + * !PAM_IGNORE + */ + +/** + * The =pam_acct_mgmt function verifies and enforces account restrictions + * after the user has been authenticated. + * + * The =flags argument is the binary or of zero or more of the following + * values: + * + * =PAM_SILENT: + * Do not emit any messages. + * =PAM_DISALLOW_NULL_AUTHTOK: + * Fail if the user's authentication token is null. + * + * If any other bits are set, =pam_acct_mgmt will return + * =PAM_SYMBOL_ERR. + */ diff --git a/lib/pam_authenticate.c b/lib/pam_authenticate.c new file mode 100644 index 0000000..3b5a78d --- /dev/null +++ b/lib/pam_authenticate.c @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_authenticate.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 34 + * + * Perform authentication within the PAM framework + */ + +int +pam_authenticate(pam_handle_t *pamh, + int flags) +{ + int r; + + ENTER(); + if (flags & ~(PAM_SILENT|PAM_DISALLOW_NULL_AUTHTOK)) + RETURNC(PAM_SYMBOL_ERR); + r = openpam_dispatch(pamh, PAM_SM_AUTHENTICATE, flags); + pam_set_item(pamh, PAM_AUTHTOK, NULL); + RETURNC(r); +} + +/* + * Error codes: + * + * =openpam_dispatch + * =pam_sm_authenticate + * !PAM_IGNORE + * PAM_SYMBOL_ERR + */ + +/** + * The =pam_authenticate function attempts to authenticate the user + * associated with the pam context specified by the =pamh argument. + * + * The application is free to call =pam_authenticate as many times as it + * wishes, but some modules may maintain an internal retry counter and + * return =PAM_MAXTRIES when it exceeds some preset or hardcoded limit. + * + * The =flags argument is the binary or of zero or more of the following + * values: + * + * =PAM_SILENT: + * Do not emit any messages. + * =PAM_DISALLOW_NULL_AUTHTOK: + * Fail if the user's authentication token is null. + * + * If any other bits are set, =pam_authenticate will return + * =PAM_SYMBOL_ERR. + */ diff --git a/lib/pam_authenticate_secondary.c b/lib/pam_authenticate_secondary.c new file mode 100644 index 0000000..27e3ce7 --- /dev/null +++ b/lib/pam_authenticate_secondary.c @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_authenticate_secondary.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +/* + * XSSO 4.2.1 + * XSSO 6 page 36 + * + * Perform authentication to a secondary domain within the PAM framework + */ + +int +pam_authenticate_secondary(pam_handle_t *pamh, + char *target_username, + char *target_module_type, + char *target_authn_domain, + char *target_supp_data, + char *target_module_authtok, + int flags) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_chauthtok.c b/lib/pam_chauthtok.c new file mode 100644 index 0000000..ecf1063 --- /dev/null +++ b/lib/pam_chauthtok.c @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_chauthtok.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 38 + * + * Perform password related functions within the PAM framework + */ + +int +pam_chauthtok(pam_handle_t *pamh, + int flags) +{ + int r; + + ENTER(); + if (flags & ~(PAM_SILENT|PAM_CHANGE_EXPIRED_AUTHTOK)) + RETURNC(PAM_SYMBOL_ERR); + r = openpam_dispatch(pamh, PAM_SM_CHAUTHTOK, + flags | PAM_PRELIM_CHECK); + if (r == PAM_SUCCESS) + r = openpam_dispatch(pamh, PAM_SM_CHAUTHTOK, + flags | PAM_UPDATE_AUTHTOK); + pam_set_item(pamh, PAM_OLDAUTHTOK, NULL); + pam_set_item(pamh, PAM_AUTHTOK, NULL); + RETURNC(r); +} + +/* + * Error codes: + * + * =openpam_dispatch + * =pam_sm_chauthtok + * !PAM_IGNORE + * PAM_SYMBOL_ERR + */ + +/** + * The =pam_chauthtok function attempts to change the authentication token + * for the user associated with the pam context specified by the =pamh + * argument. + * + * The =flags argument is the binary or of zero or more of the following + * values: + * + * =PAM_SILENT: + * Do not emit any messages. + * =PAM_CHANGE_EXPIRED_AUTHTOK: + * Change only those authentication tokens that have expired. + * + * If any other bits are set, =pam_chauthtok will return =PAM_SYMBOL_ERR. + */ diff --git a/lib/pam_close_session.c b/lib/pam_close_session.c new file mode 100644 index 0000000..ab50e35 --- /dev/null +++ b/lib/pam_close_session.c @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_close_session.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 40 + * + * Close an existing user session + */ + +int +pam_close_session(pam_handle_t *pamh, + int flags) +{ + int r; + + ENTER(); + if (flags & ~(PAM_SILENT)) + RETURNC(PAM_SYMBOL_ERR); + r = openpam_dispatch(pamh, PAM_SM_CLOSE_SESSION, flags); + RETURNC(r); +} + +/* + * Error codes: + * + * =openpam_dispatch + * =pam_sm_close_session + * !PAM_IGNORE + * PAM_SYMBOL_ERR + */ + +/** + * The =pam_close_session function tears down the user session previously + * set up by =pam_open_session. + * + * The =flags argument is the binary or of zero or more of the following + * values: + * + * =PAM_SILENT: + * Do not emit any messages. + * + * If any other bits are set, =pam_close_session will return + * =PAM_SYMBOL_ERR. + */ diff --git a/lib/pam_end.c b/lib/pam_end.c new file mode 100644 index 0000000..80baf8a --- /dev/null +++ b/lib/pam_end.c @@ -0,0 +1,102 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_end.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 42 + * + * Terminate the PAM transaction + */ + +int +pam_end(pam_handle_t *pamh, + int status) +{ + pam_data_t *dp; + int i; + + ENTER(); + if (pamh == NULL) + RETURNC(PAM_SYSTEM_ERR); + + /* clear module data */ + while ((dp = pamh->module_data) != NULL) { + if (dp->cleanup) + (dp->cleanup)(pamh, dp->data, status); + pamh->module_data = dp->next; + FREE(dp->name); + FREE(dp); + } + + /* clear environment */ + while (pamh->env_count) { + --pamh->env_count; + FREE(pamh->env[pamh->env_count]); + } + FREE(pamh->env); + + /* clear chains */ + openpam_clear_chains(pamh->chains); + + /* clear items */ + for (i = 0; i < PAM_NUM_ITEMS; ++i) + pam_set_item(pamh, i, NULL); + + FREE(pamh); + + RETURNC(PAM_SUCCESS); +} + +/* + * Error codes: + * + * PAM_SYSTEM_ERR + */ + +/** + * The =pam_end function terminates a PAM transaction and destroys the + * corresponding PAM context, releasing all resources allocated to it. + * + * The =status argument should be set to the error code returned by the + * last API call before the call to =pam_end. + */ diff --git a/lib/pam_error.c b/lib/pam_error.c new file mode 100644 index 0000000..f42a6b5 --- /dev/null +++ b/lib/pam_error.c @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_error.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include +#include + +#include +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Display an error message + */ + +int +pam_error(const pam_handle_t *pamh, + const char *fmt, + ...) +{ + va_list ap; + char *rsp; + int r; + + va_start(ap, fmt); + r = pam_vprompt(pamh, PAM_ERROR_MSG, &rsp, fmt, ap); + va_end(ap); + FREE(rsp); /* ignore response */ + return (r); +} + +/* + * Error codes: + * + * !PAM_SYMBOL_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + */ + +/** + * The =pam_error function displays an error message through the + * intermediary of the given PAM context's conversation function. + * + * >pam_info + * >pam_prompt + * >pam_verror + */ diff --git a/lib/pam_get_authtok.c b/lib/pam_get_authtok.c new file mode 100644 index 0000000..2a974c9 --- /dev/null +++ b/lib/pam_get_authtok.c @@ -0,0 +1,171 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_get_authtok.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +#include +#include + +#include "openpam_impl.h" + +static const char authtok_prompt[] = "Password:"; +static const char oldauthtok_prompt[] = "Old Password:"; +static const char newauthtok_prompt[] = "New Password:"; + +/* + * OpenPAM extension + * + * Retrieve authentication token + */ + +int +pam_get_authtok(pam_handle_t *pamh, + int item, + const char **authtok, + const char *prompt) +{ + const void *oldauthtok, *prevauthtok, *promptp; + const char *default_prompt; + char *resp, *resp2; + int pitem, r, style, twice; + + ENTER(); + if (pamh == NULL || authtok == NULL) + RETURNC(PAM_SYSTEM_ERR); + *authtok = NULL; + twice = 0; + switch (item) { + case PAM_AUTHTOK: + pitem = PAM_AUTHTOK_PROMPT; + default_prompt = authtok_prompt; + r = pam_get_item(pamh, PAM_OLDAUTHTOK, &oldauthtok); + if (r == PAM_SUCCESS && oldauthtok != NULL) { + default_prompt = newauthtok_prompt; + twice = 1; + } + break; + case PAM_OLDAUTHTOK: + pitem = PAM_OLDAUTHTOK_PROMPT; + default_prompt = oldauthtok_prompt; + twice = 0; + break; + default: + RETURNC(PAM_SYMBOL_ERR); + } + if (openpam_get_option(pamh, "try_first_pass") || + openpam_get_option(pamh, "use_first_pass")) { + r = pam_get_item(pamh, item, &prevauthtok); + if (r == PAM_SUCCESS && prevauthtok != NULL) { + *authtok = prevauthtok; + RETURNC(PAM_SUCCESS); + } + else if (openpam_get_option(pamh, "use_first_pass")) + RETURNC(r == PAM_SUCCESS ? PAM_AUTH_ERR : r); + } + if (prompt == NULL) { + r = pam_get_item(pamh, pitem, &promptp); + if (r != PAM_SUCCESS || promptp == NULL) + prompt = default_prompt; + else + prompt = promptp; + } + style = openpam_get_option(pamh, "echo_pass") ? + PAM_PROMPT_ECHO_ON : PAM_PROMPT_ECHO_OFF; + r = pam_prompt(pamh, style, &resp, "%s", prompt); + if (r != PAM_SUCCESS) + RETURNC(r); + if (twice) { + r = pam_prompt(pamh, style, &resp2, "Retype %s", prompt); + if (r != PAM_SUCCESS) { + FREE(resp); + RETURNC(r); + } + if (strcmp(resp, resp2) != 0) + FREE(resp); + FREE(resp2); + } + if (resp == NULL) + RETURNC(PAM_TRY_AGAIN); + r = pam_set_item(pamh, item, resp); + FREE(resp); + if (r != PAM_SUCCESS) + RETURNC(r); + r = pam_get_item(pamh, item, (const void **)authtok); + RETURNC(r); +} + +/* + * Error codes: + * + * =pam_get_item + * =pam_prompt + * =pam_set_item + * !PAM_SYMBOL_ERR + * PAM_TRY_AGAIN + */ + +/** + * The =pam_get_authtok function returns the cached authentication token, + * or prompts the user if no token is currently cached. + * Either way, a pointer to the authentication token is stored in the + * location pointed to by the =authtok argument. + * + * The =item argument must have one of the following values: + * + * =PAM_AUTHTOK: + * Returns the current authentication token, or the new token + * when changing authentication tokens. + * =PAM_OLDAUTHTOK: + * Returns the previous authentication token when changing + * authentication tokens. + * + * The =prompt argument specifies a prompt to use if no token is cached. + * If it is =NULL, the =PAM_AUTHTOK_PROMPT or =PAM_OLDAUTHTOK_PROMPT item, + * as appropriate, will be used. + * If that item is also =NULL, a hardcoded default prompt will be used. + * + * If =item is set to =PAM_AUTHTOK and there is a non-null =PAM_OLDAUTHTOK + * item, =pam_get_authtok will ask the user to confirm the new token by + * retyping it. + * If there is a mismatch, =pam_get_authtok will return =PAM_TRY_AGAIN. + * + * >pam_get_item + * >pam_get_user + */ diff --git a/lib/pam_get_data.c b/lib/pam_get_data.c new file mode 100644 index 0000000..0cceef0 --- /dev/null +++ b/lib/pam_get_data.c @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_get_data.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 43 + * + * Get module information + */ + +int +pam_get_data(const pam_handle_t *pamh, + const char *module_data_name, + const void **data) +{ + pam_data_t *dp; + + ENTERS(module_data_name); + if (pamh == NULL) + RETURNC(PAM_SYSTEM_ERR); + for (dp = pamh->module_data; dp != NULL; dp = dp->next) { + if (strcmp(dp->name, module_data_name) == 0) { + *data = (void *)dp->data; + RETURNC(PAM_SUCCESS); + } + } + RETURNC(PAM_NO_MODULE_DATA); +} + +/* + * Error codes: + * + * PAM_SYSTEM_ERR + * PAM_NO_MODULE_DATA + */ + +/** + * The =pam_get_data function looks up the opaque object associated with + * the string specified by the =module_data_name argument, in the PAM + * context specified by the =pamh argument. + * A pointer to the object is stored in the location pointed to by the + * =data argument. + * + * This function and its counterpart =pam_set_data are useful for managing + * data that are meaningful only to a particular service module. + */ diff --git a/lib/pam_get_item.c b/lib/pam_get_item.c new file mode 100644 index 0000000..9f127be --- /dev/null +++ b/lib/pam_get_item.c @@ -0,0 +1,142 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_get_item.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +const char *_pam_item_name[PAM_NUM_ITEMS] = { + "(NO ITEM)", + "PAM_SERVICE", + "PAM_USER", + "PAM_TTY", + "PAM_RHOST", + "PAM_CONV", + "PAM_AUTHTOK", + "PAM_OLDAUTHTOK", + "PAM_RUSER", + "PAM_USER_PROMPT", + "PAM_REPOSITORY", + "PAM_AUTHTOK_PROMPT", + "PAM_OLDAUTHTOK_PROMPT" +}; + +/* + * XSSO 4.2.1 + * XSSO 6 page 46 + * + * Get PAM information + */ + +int +pam_get_item(const pam_handle_t *pamh, + int item_type, + const void **item) +{ + + ENTERI(item_type); + if (pamh == NULL) + RETURNC(PAM_SYSTEM_ERR); + switch (item_type) { + case PAM_SERVICE: + case PAM_USER: + case PAM_AUTHTOK: + case PAM_OLDAUTHTOK: + case PAM_TTY: + case PAM_RHOST: + case PAM_RUSER: + case PAM_CONV: + case PAM_USER_PROMPT: + case PAM_AUTHTOK_PROMPT: + case PAM_OLDAUTHTOK_PROMPT: + case PAM_REPOSITORY: + *item = pamh->item[item_type]; + RETURNC(PAM_SUCCESS); + default: + RETURNC(PAM_SYMBOL_ERR); + } +} + +/* + * Error codes: + * + * PAM_SYMBOL_ERR + * PAM_SYSTEM_ERR + */ + +/** + * The =pam_get_item function stores a pointer to the item specified by + * the =item_type argument in the location specified by the =item + * argument. + * The item is retrieved from the PAM context specified by the =pamh + * argument. + * The following item types are recognized: + * + * =PAM_SERVICE: + * The name of the requesting service. + * =PAM_USER: + * The name of the user the application is trying to + * authenticate. + * =PAM_TTY: + * The name of the current terminal. + * =PAM_RHOST: + * The name of the applicant's host. + * =PAM_CONV: + * A =struct pam_conv describing the current conversation + * function. + * =PAM_AUTHTOK: + * The current authentication token. + * =PAM_OLDAUTHTOK: + * The expired authentication token. + * =PAM_RUSER: + * The name of the applicant. + * =PAM_USER_PROMPT: + * The prompt to use when asking the applicant for a user + * name to authenticate as. + * =PAM_AUTHTOK_PROMPT: + * The prompt to use when asking the applicant for an + * authentication token. + * =PAM_OLDAUTHTOK_PROMPT: + * The prompt to use when asking the applicant for an + * expired authentication token prior to changing it. + * + * See =pam_start for a description of =struct pam_conv. + * + * >pam_set_item + */ diff --git a/lib/pam_get_mapped_authtok.c b/lib/pam_get_mapped_authtok.c new file mode 100644 index 0000000..c49a918 --- /dev/null +++ b/lib/pam_get_mapped_authtok.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_get_mapped_authtok.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +/* + * XSSO 4.2.1 + * XSSO 6 page 48 + * + * Get mapped password for the user + */ + +int +pam_get_mapped_authtok(pam_handle_t *pamh, + const char *target_module_username, + const char *target_module_type, + const char *target_authn_domain, + size_t *target_authtok_len, + unsigned char **target_module_authtok) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_get_mapped_username.c b/lib/pam_get_mapped_username.c new file mode 100644 index 0000000..359baee --- /dev/null +++ b/lib/pam_get_mapped_username.c @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_get_mapped_username.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +/* + * XSSO 4.2.1 + * XSSO 6 page 50 + * + * Get valid matched identity in new domain + */ + +int +pam_get_mapped_username(pam_handle_t *pamh, + const char *src_username, + const char *src_module_type, + const char *src_authn_domain, + const char *target_module_type, + const char *target_authn_domain, + char **target_module_username) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_get_user.c b/lib/pam_get_user.c new file mode 100644 index 0000000..115a3ea --- /dev/null +++ b/lib/pam_get_user.c @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_get_user.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include +#include + +#include "openpam_impl.h" + +static const char user_prompt[] = "Login:"; + +/* + * XSSO 4.2.1 + * XSSO 6 page 52 + * + * Retrieve user name + */ + +int +pam_get_user(pam_handle_t *pamh, + const char **user, + const char *prompt) +{ + const void *promptp; + char *resp; + int r; + + ENTER(); + if (pamh == NULL || user == NULL) + RETURNC(PAM_SYSTEM_ERR); + r = pam_get_item(pamh, PAM_USER, (const void **)user); + if (r == PAM_SUCCESS && *user != NULL) + RETURNC(PAM_SUCCESS); + if (prompt == NULL) { + r = pam_get_item(pamh, PAM_USER_PROMPT, &promptp); + if (r != PAM_SUCCESS || promptp == NULL) + prompt = user_prompt; + else + prompt = promptp; + } + r = pam_prompt(pamh, PAM_PROMPT_ECHO_ON, &resp, "%s", prompt); + if (r != PAM_SUCCESS) + RETURNC(r); + r = pam_set_item(pamh, PAM_USER, resp); + FREE(resp); + if (r != PAM_SUCCESS) + RETURNC(r); + r = pam_get_item(pamh, PAM_USER, (const void **)user); + RETURNC(r); +} + +/* + * Error codes: + * + * =pam_get_item + * =pam_prompt + * =pam_set_item + * !PAM_SYMBOL_ERR + */ + +/** + * The =pam_get_user function returns the name of the target user, as + * specified to =pam_start. + * If no user was specified, nor set using =pam_set_item, =pam_get_user + * will prompt for a user name. + * Either way, a pointer to the user name is stored in the location + * pointed to by the =user argument. + * + * The =prompt argument specifies a prompt to use if no user name is + * cached. + * If it is =NULL, the =PAM_USER_PROMPT will be used. + * If that item is also =NULL, a hardcoded default prompt will be used. + * + * >pam_get_item + * >pam_get_authtok + */ diff --git a/lib/pam_getenv.c b/lib/pam_getenv.c new file mode 100644 index 0000000..f2d7910 --- /dev/null +++ b/lib/pam_getenv.c @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_getenv.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 44 + * + * Retrieve the value of a PAM environment variable + */ + +const char * +pam_getenv(pam_handle_t *pamh, + const char *name) +{ + char *str; + int i; + + ENTERS(name); + if (pamh == NULL) + RETURNS(NULL); + if (name == NULL || strchr(name, '=') != NULL) + RETURNS(NULL); + if ((i = openpam_findenv(pamh, name, strlen(name))) < 0) + RETURNS(NULL); + for (str = pamh->env[i]; *str != '\0'; ++str) { + if (*str == '=') { + ++str; + break; + } + } + RETURNS(str); +} + +/** + * The =pam_getenv function returns the value of an environment variable. + * Its semantics are similar to those of =getenv, but it accesses the PAM + * context's environment list instead of the application's. + * + * >pam_getenvlist + * >pam_putenv + * >pam_setenv + */ diff --git a/lib/pam_getenvlist.c b/lib/pam_getenvlist.c new file mode 100644 index 0000000..c0e128a --- /dev/null +++ b/lib/pam_getenvlist.c @@ -0,0 +1,106 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_getenvlist.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 45 + * + * Returns a list of all the PAM environment variables + */ + +char ** +pam_getenvlist(pam_handle_t *pamh) +{ + char **envlist; + int i; + + ENTER(); + if (pamh == NULL) + RETURNP(NULL); + envlist = malloc(sizeof(char *) * (pamh->env_count + 1)); + if (envlist == NULL) { + openpam_log(PAM_LOG_ERROR, "%s", + pam_strerror(pamh, PAM_BUF_ERR)); + RETURNP(NULL); + } + for (i = 0; i < pamh->env_count; ++i) { + if ((envlist[i] = strdup(pamh->env[i])) == NULL) { + while (i) { + --i; + FREE(envlist[i]); + } + FREE(envlist); + openpam_log(PAM_LOG_ERROR, "%s", + pam_strerror(pamh, PAM_BUF_ERR)); + RETURNP(NULL); + } + } + envlist[i] = NULL; + RETURNP(envlist); +} + +/** + * The =pam_getenvlist function returns a copy of the given PAM context's + * environment list as a pointer to an array of strings. + * The last element in the array is =NULL. + * The pointer is suitable for assignment to {Va environ}. + * + * The array and the strings it lists are allocated using =malloc, and + * should be released using =free after use: + * + * char **envlist, **env; + * + * envlist = environ; + * environ = pam_getenvlist(pamh); + * \/\* do something nifty \*\/ + * for (env = environ; *env != NULL; env++) + * free(*env); + * free(environ); + * environ = envlist; + * + * >environ 7 + * >pam_getenv + * >pam_putenv + * >pam_setenv + */ diff --git a/lib/pam_info.c b/lib/pam_info.c new file mode 100644 index 0000000..2e4dbc7 --- /dev/null +++ b/lib/pam_info.c @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_info.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include +#include + +#include +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Display an information message + */ + +int +pam_info(const pam_handle_t *pamh, + const char *fmt, + ...) +{ + va_list ap; + char *rsp; + int r; + + va_start(ap, fmt); + r = pam_vprompt(pamh, PAM_TEXT_INFO, &rsp, fmt, ap); + va_end(ap); + FREE(rsp); /* ignore response */ + return (r); +} + +/* + * Error codes: + * + * !PAM_SYMBOL_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + */ + +/** + * The =pam_info function displays an informational message through the + * intermediary of the given PAM context's conversation function. + * + * >pam_error + * >pam_prompt + * >pam_vinfo + */ diff --git a/lib/pam_open_session.c b/lib/pam_open_session.c new file mode 100644 index 0000000..f8d6eca --- /dev/null +++ b/lib/pam_open_session.c @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_open_session.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 54 + * + * Open a user session + */ + +int +pam_open_session(pam_handle_t *pamh, + int flags) +{ + int r; + + ENTER(); + if (flags & ~(PAM_SILENT)) + RETURNC(PAM_SYMBOL_ERR); + r = openpam_dispatch(pamh, PAM_SM_OPEN_SESSION, flags); + RETURNC(r); +} + +/* + * Error codes: + * + * =openpam_dispatch + * =pam_sm_open_session + * !PAM_IGNORE + * PAM_SYMBOL_ERR + */ + +/** + * The =pam_open_session sets up a user session for a previously + * authenticated user. + * The session should later be torn down by a call to =pam_close_session. + * + * The =flags argument is the binary or of zero or more of the following + * values: + * + * =PAM_SILENT: + * Do not emit any messages. + * + * If any other bits are set, =pam_open_session will return + * =PAM_SYMBOL_ERR. + */ diff --git a/lib/pam_prompt.c b/lib/pam_prompt.c new file mode 100644 index 0000000..76da55f --- /dev/null +++ b/lib/pam_prompt.c @@ -0,0 +1,90 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_prompt.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include +#include + +/* + * OpenPAM extension + * + * Call the conversation function + */ + +int +pam_prompt(const pam_handle_t *pamh, + int style, + char **resp, + const char *fmt, + ...) +{ + va_list ap; + int r; + + va_start(ap, fmt); + r = pam_vprompt(pamh, style, resp, fmt, ap); + va_end(ap); + return (r); +} + +/* + * Error codes: + * + * !PAM_SYMBOL_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + */ + +/** + * The =pam_prompt function constructs a message from the specified format + * string and arguments and passes it to the given PAM context's + * conversation function. + * + * A pointer to the response, or =NULL if the conversation function did + * not return one, is stored in the location pointed to by the =resp + * argument. + * + * See =pam_vprompt for further details. + * + * >pam_error + * >pam_info + * >pam_vprompt + */ diff --git a/lib/pam_putenv.c b/lib/pam_putenv.c new file mode 100644 index 0000000..79d6228 --- /dev/null +++ b/lib/pam_putenv.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_putenv.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 56 + * + * Set the value of an environment variable + */ + +int +pam_putenv(pam_handle_t *pamh, + const char *namevalue) +{ + char **env, *p; + int i; + + ENTER(); + if (pamh == NULL) + RETURNC(PAM_SYSTEM_ERR); + + /* sanity checks */ + if (namevalue == NULL || (p = strchr(namevalue, '=')) == NULL) + RETURNC(PAM_SYSTEM_ERR); + + /* see if the variable is already in the environment */ + if ((i = openpam_findenv(pamh, namevalue, p - namevalue)) >= 0) { + if ((p = strdup(namevalue)) == NULL) + RETURNC(PAM_BUF_ERR); + FREE(pamh->env[i]); + pamh->env[i] = p; + RETURNC(PAM_SUCCESS); + } + + /* grow the environment list if necessary */ + if (pamh->env_count == pamh->env_size) { + env = realloc(pamh->env, + sizeof(char *) * (pamh->env_size * 2 + 1)); + if (env == NULL) + RETURNC(PAM_BUF_ERR); + pamh->env = env; + pamh->env_size = pamh->env_size * 2 + 1; + } + + /* add the variable at the end */ + if ((pamh->env[pamh->env_count] = strdup(namevalue)) == NULL) + RETURNC(PAM_BUF_ERR); + ++pamh->env_count; + RETURNC(PAM_SUCCESS); +} + +/* + * Error codes: + * + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + */ + +/** + * The =pam_putenv function sets a environment variable. + * Its semantics are similar to those of =putenv, but it modifies the PAM + * context's environment list instead of the application's. + * + * >pam_getenv + * >pam_getenvlist + * >pam_setenv + */ diff --git a/lib/pam_set_data.c b/lib/pam_set_data.c new file mode 100644 index 0000000..963de92 --- /dev/null +++ b/lib/pam_set_data.c @@ -0,0 +1,104 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_set_data.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 59 + * + * Set module information + */ + +int +pam_set_data(pam_handle_t *pamh, + const char *module_data_name, + void *data, + void (*cleanup)(pam_handle_t *pamh, + void *data, + int pam_end_status)) +{ + pam_data_t *dp; + + ENTERS(module_data_name); + if (pamh == NULL) + RETURNC(PAM_SYSTEM_ERR); + for (dp = pamh->module_data; dp != NULL; dp = dp->next) { + if (strcmp(dp->name, module_data_name) == 0) { + if (dp->cleanup) + (dp->cleanup)(pamh, dp->data, PAM_SUCCESS); + dp->data = data; + dp->cleanup = cleanup; + RETURNC(PAM_SUCCESS); + } + } + if ((dp = malloc(sizeof *dp)) == NULL) + RETURNC(PAM_BUF_ERR); + if ((dp->name = strdup(module_data_name)) == NULL) { + FREE(dp); + RETURNC(PAM_BUF_ERR); + } + dp->data = data; + dp->cleanup = cleanup; + dp->next = pamh->module_data; + pamh->module_data = dp; + RETURNC(PAM_SUCCESS); +} + +/* + * Error codes: + * + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + */ + +/** + * The =pam_set_data function associates a pointer to an opaque object + * with an arbitrary string specified by the =module_data_name argument, + * in the PAM context specified by the =pamh argument. + * + * If not =NULL, the =cleanup argument should point to a function + * responsible for releasing the resources associated with the object. + * + * This function and its counterpart =pam_get_data are useful for managing + * data that are meaningful only to a particular service module. + */ diff --git a/lib/pam_set_item.c b/lib/pam_set_item.c new file mode 100644 index 0000000..9b60618 --- /dev/null +++ b/lib/pam_set_item.c @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_set_item.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 60 + * + * Set authentication information + */ + +int +pam_set_item(pam_handle_t *pamh, + int item_type, + const void *item) +{ + void **slot, *tmp; + size_t nsize, osize; + + ENTERI(item_type); + if (pamh == NULL) + RETURNC(PAM_SYSTEM_ERR); + slot = &pamh->item[item_type]; + osize = nsize = 0; + switch (item_type) { + case PAM_SERVICE: + case PAM_USER: + case PAM_AUTHTOK: + case PAM_OLDAUTHTOK: + case PAM_TTY: + case PAM_RHOST: + case PAM_RUSER: + case PAM_USER_PROMPT: + case PAM_AUTHTOK_PROMPT: + case PAM_OLDAUTHTOK_PROMPT: + if (*slot != NULL) + osize = strlen(*slot) + 1; + if (item != NULL) + nsize = strlen(item) + 1; + break; + case PAM_REPOSITORY: + osize = nsize = sizeof(struct pam_repository); + break; + case PAM_CONV: + osize = nsize = sizeof(struct pam_conv); + break; + default: + RETURNC(PAM_SYMBOL_ERR); + } + if (*slot != NULL) { + memset(*slot, 0xd0, osize); + FREE(*slot); + } + if (item != NULL) { + if ((tmp = malloc(nsize)) == NULL) + RETURNC(PAM_BUF_ERR); + memcpy(tmp, item, nsize); + } else { + tmp = NULL; + } + *slot = tmp; + RETURNC(PAM_SUCCESS); +} + +/* + * Error codes: + * + * PAM_SYMBOL_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + */ + +/** + * The =pam_set_item function sets the item specified by the =item_type + * argument to a copy of the object pointed to by the =item argument. + * The item is stored in the PAM context specified by the =pamh argument. + * See =pam_get_item for a list of recognized item types. + */ diff --git a/lib/pam_set_mapped_authtok.c b/lib/pam_set_mapped_authtok.c new file mode 100644 index 0000000..01ad255 --- /dev/null +++ b/lib/pam_set_mapped_authtok.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_set_mapped_authtok.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +/* + * XSSO 4.2.1 + * XSSO 6 page 62 + * + * Store the password for the username supplied + */ + +int +pam_set_mapped_authtok(pam_handle_t *pamh, + const char *target_module_username, + size_t target_authtok_len, + unsigned char *target_module_authtok, + const char *target_module_type, + const char *target_authn_domain) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_set_mapped_username.c b/lib/pam_set_mapped_username.c new file mode 100644 index 0000000..ae3619b --- /dev/null +++ b/lib/pam_set_mapped_username.c @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_set_mapped_username.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +/* + * XSSO 4.2.1 + * XSSO 6 page 64 + * + * Set a username + */ + +int +pam_set_mapped_username(pam_handle_t *pamh, + char *src_username, + char *src_module_type, + char *src_authn_domain, + char *target_module_username, + char *target_module_type, + char *target_authn_domain) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_setcred.c b/lib/pam_setcred.c new file mode 100644 index 0000000..80eb468 --- /dev/null +++ b/lib/pam_setcred.c @@ -0,0 +1,95 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_setcred.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 57 + * + * Modify / delete user credentials for an authentication service + */ + +int +pam_setcred(pam_handle_t *pamh, + int flags) +{ + int r; + + ENTER(); + if (flags & ~(PAM_SILENT|PAM_ESTABLISH_CRED|PAM_DELETE_CRED| + PAM_REINITIALIZE_CRED|PAM_REFRESH_CRED)) + RETURNC(PAM_SYMBOL_ERR); + /* XXX enforce exclusivity */ + r = openpam_dispatch(pamh, PAM_SM_SETCRED, flags); + RETURNC(r); +} + +/* + * Error codes: + * + * =openpam_dispatch + * =pam_sm_setcred + * !PAM_IGNORE + * PAM_SYMBOL_ERR + */ + +/** + * The =pam_setcred function manages the application's credentials. + * + * The =flags argument is the binary or of zero or more of the following + * values: + * + * =PAM_SILENT: + * Do not emit any messages. + * =PAM_ESTABLISH_CRED: + * Establish the credentials of the target user. + * =PAM_DELETE_CRED: + * Revoke all established credentials. + * =PAM_REINITIALIZE_CRED: + * Fully reinitialise credentials. + * =PAM_REFRESH_CRED: + * Refresh credentials. + * + * The latter four are mutually exclusive. + * + * If any other bits are set, =pam_setcred will return =PAM_SYMBOL_ERR. + */ diff --git a/lib/pam_setenv.c b/lib/pam_setenv.c new file mode 100644 index 0000000..e73f6b5 --- /dev/null +++ b/lib/pam_setenv.c @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_setenv.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Set the value of an environment variable + * Mirrors setenv(3) + */ + +int +pam_setenv(pam_handle_t *pamh, + const char *name, + const char *value, + int overwrite) +{ + char *env; + int r; + + ENTER(); + if (pamh == NULL) + RETURNC(PAM_SYSTEM_ERR); + + /* sanity checks */ + if (name == NULL || value == NULL || strchr(name, '=') != NULL) + RETURNC(PAM_SYSTEM_ERR); + + /* is it already there? */ + if (!overwrite && openpam_findenv(pamh, name, strlen(name)) >= 0) + RETURNC(PAM_SUCCESS); + + /* set it... */ + if (asprintf(&env, "%s=%s", name, value) < 0) + RETURNC(PAM_BUF_ERR); + r = pam_putenv(pamh, env); + FREE(env); + RETURNC(r); +} + +/* + * Error codes: + * + * =pam_putenv + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + */ + +/** + * The =pam_setenv function sets a environment variable. + * Its semantics are similar to those of =setenv, but it modifies the PAM + * context's environment list instead of the application's. + * + * >pam_getenv + * >pam_getenvlist + * >pam_putenv + */ diff --git a/lib/pam_sm_acct_mgmt.c b/lib/pam_sm_acct_mgmt.c new file mode 100644 index 0000000..a57e86a --- /dev/null +++ b/lib/pam_sm_acct_mgmt.c @@ -0,0 +1,81 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_acct_mgmt.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 66 + * + * Service module implementation for pam_acct_mgmt + */ + +int +pam_sm_acct_mgmt(pam_handle_t *pamh, + int flags, + int argc, + const char **argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * Error codes: + * + * PAM_SERVICE_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + * PAM_PERM_DENIED + * PAM_IGNORE + * PAM_ABORT + * + * PAM_USER_UNKNOWN + * PAM_AUTH_ERR + * PAM_NEW_AUTHTOK_REQD + * PAM_ACCT_EXPIRED + */ + +/** + * The =pam_sm_acct_mgmt function is the service module's implementation + * of the =pam_acct_mgmt API function. + */ diff --git a/lib/pam_sm_authenticate.c b/lib/pam_sm_authenticate.c new file mode 100644 index 0000000..7f4bb1c --- /dev/null +++ b/lib/pam_sm_authenticate.c @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_authenticate.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 68 + * + * Service module implementation for pam_authenticate + */ + +int +pam_sm_authenticate(pam_handle_t *pamh, + int flags, + int argc, + const char **argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * Error codes: + * + * PAM_SERVICE_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + * PAM_PERM_DENIED + * PAM_IGNORE + * PAM_ABORT + * + * PAM_AUTH_ERR + * PAM_CRED_INSUFFICIENT + * PAM_AUTHINFO_UNAVAIL + * PAM_USER_UNKNOWN + * PAM_MAXTRIES + */ + +/** + * The =pam_sm_authenticate function is the service module's + * implementation of the =pam_authenticate API function. + */ diff --git a/lib/pam_sm_authenticate_secondary.c b/lib/pam_sm_authenticate_secondary.c new file mode 100644 index 0000000..bde0366 --- /dev/null +++ b/lib/pam_sm_authenticate_secondary.c @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_authenticate_secondary.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 70 + * + * Service module implementation for pam_authenticate_secondary + */ + +int +pam_sm_authenticate_secondary(pam_handle_t *pamh, + char *target_username, + char *target_module_type, + char *target_authn_domain, + char *target_supp_data, + unsigned char *target_module_authtok, + int flags, + int argc, + const char **argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_sm_chauthtok.c b/lib/pam_sm_chauthtok.c new file mode 100644 index 0000000..2c41d6d --- /dev/null +++ b/lib/pam_sm_chauthtok.c @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_chauthtok.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 72 + * + * Service module implementation for pam_chauthtok + */ + +int +pam_sm_chauthtok(pam_handle_t *pamh, + int flags, + int argc, + const char **argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * Error codes: + * + * PAM_SERVICE_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + * PAM_PERM_DENIED + * PAM_IGNORE + * PAM_ABORT + * + * PAM_PERM_DENIED + * PAM_AUTHTOK_ERR + * PAM_AUTHTOK_RECOVERY_ERR + * PAM_AUTHTOK_LOCK_BUSY + * PAM_AUTHTOK_DISABLE_AGING + * PAM_TRY_AGAIN + */ + +/** + * The =pam_sm_chauthtok function is the service module's implementation + * of the =pam_chauthtok API function. + */ diff --git a/lib/pam_sm_close_session.c b/lib/pam_sm_close_session.c new file mode 100644 index 0000000..25cee92 --- /dev/null +++ b/lib/pam_sm_close_session.c @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_close_session.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 75 + * + * Service module implementation for pam_close_session + */ + +int +pam_sm_close_session(pam_handle_t *pamh, + int flags, + int args, + const char **argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * Error codes: + * + * PAM_SERVICE_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + * PAM_PERM_DENIED + * PAM_IGNORE + * PAM_ABORT + * + * PAM_SESSION_ERR + */ + +/** + * The =pam_sm_close_session function is the service module's + * implementation of the =pam_close_session API function. + */ diff --git a/lib/pam_sm_get_mapped_authtok.c b/lib/pam_sm_get_mapped_authtok.c new file mode 100644 index 0000000..9d85d5f --- /dev/null +++ b/lib/pam_sm_get_mapped_authtok.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_get_mapped_authtok.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 77 + * + * Service module implementation for pam_get_mapped_authtok + */ + +int +pam_sm_get_mapped_authtok(pam_handle_t *pamh, + char *target_module_username, + char *target_module_type, + char *target_authn_domain, + size_t *target_authtok_len, + unsigned char **target_module_authtok, + int argc, + char *argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_sm_get_mapped_username.c b/lib/pam_sm_get_mapped_username.c new file mode 100644 index 0000000..ee4d250 --- /dev/null +++ b/lib/pam_sm_get_mapped_username.c @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_get_mapped_username.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 79 + * + * Service module implementation for pam_get_mapped_username + */ + +int +pam_sm_get_mapped_username(pam_handle_t *pamh, + char *src_username, + char *src_module_type, + char *src_authn_domain, + char *target_module_type, + char *target_authn_domain, + char **target_module_username, + int argc, + const char **argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_sm_open_session.c b/lib/pam_sm_open_session.c new file mode 100644 index 0000000..bfe0794 --- /dev/null +++ b/lib/pam_sm_open_session.c @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_open_session.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 81 + * + * Service module implementation for pam_open_session + */ + +int +pam_sm_open_session(pam_handle_t *pamh, + int flags, + int argc, + const char **argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * Error codes: + * + * PAM_SERVICE_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + * PAM_PERM_DENIED + * PAM_IGNORE + * PAM_ABORT + * + * PAM_SESSION_ERR + */ + +/** + * The =pam_sm_open_session function is the service module's + * implementation of the =pam_open_session API function. + */ diff --git a/lib/pam_sm_set_mapped_authtok.c b/lib/pam_sm_set_mapped_authtok.c new file mode 100644 index 0000000..54fd370 --- /dev/null +++ b/lib/pam_sm_set_mapped_authtok.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_set_mapped_authtok.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 83 + * + * Service module implementation for pam_set_mapped_authtok + */ + +int +pam_sm_set_mapped_authtok(pam_handle_t *pamh, + char *target_module_username, + size_t target_authtok_len, + unsigned char *target_module_authtok, + char *target_module_type, + char *target_authn_domain, + int argc, + const char *argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_sm_set_mapped_username.c b/lib/pam_sm_set_mapped_username.c new file mode 100644 index 0000000..0239dbb --- /dev/null +++ b/lib/pam_sm_set_mapped_username.c @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_set_mapped_username.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 85 + * + * Service module implementation for pam_set_mapped_username + */ + +int +pam_sm_set_mapped_username(pam_handle_t *pamh, + char *target_module_username, + char *target_module_type, + char *target_authn_domain, + int argc, + const char **argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + +/* + * NODOC + */ diff --git a/lib/pam_sm_setcred.c b/lib/pam_sm_setcred.c new file mode 100644 index 0000000..4d472b3 --- /dev/null +++ b/lib/pam_sm_setcred.c @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_sm_setcred.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include +#include + +/* + * XSSO 4.2.2 + * XSSO 6 page 87 + * + * Service module implementation for pam_setcred + */ + +int +pam_sm_setcred(pam_handle_t *pamh, + int flags, + int argc, + const char **argv) +{ + + ENTER(); + RETURNC(PAM_SYSTEM_ERR); +} + + +/* + * Error codes: + * + * PAM_SERVICE_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + * PAM_PERM_DENIED + * PAM_IGNORE + * PAM_ABORT + * + * PAM_CRED_UNAVAIL + * PAM_CRED_EXPIRED + * PAM_USER_UNKNOWN + * PAM_CRED_ERR + */ + +/** + * The =pam_sm_setcred function is the service module's implementation of + * the =pam_setcred API function. + */ diff --git a/lib/pam_start.c b/lib/pam_start.c new file mode 100644 index 0000000..ee6468b --- /dev/null +++ b/lib/pam_start.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_start.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +/* + * XSSO 4.2.1 + * XSSO 6 page 89 + * + * Initiate a PAM transaction + */ + +int +pam_start(const char *service, + const char *user, + const struct pam_conv *pam_conv, + pam_handle_t **pamh) +{ + struct pam_handle *ph; + int r; + + ENTER(); + if ((ph = calloc(1, sizeof *ph)) == NULL) + RETURNC(PAM_BUF_ERR); + if ((r = pam_set_item(ph, PAM_SERVICE, service)) != PAM_SUCCESS) + goto fail; + if ((r = pam_set_item(ph, PAM_USER, user)) != PAM_SUCCESS) + goto fail; + if ((r = pam_set_item(ph, PAM_CONV, pam_conv)) != PAM_SUCCESS) + goto fail; + + r = openpam_configure(ph, service); + if (r != PAM_SUCCESS) + goto fail; + + *pamh = ph; + openpam_log(PAM_LOG_DEBUG, "pam_start(\"%s\") succeeded", service); + RETURNC(PAM_SUCCESS); + + fail: + pam_end(ph, r); + RETURNC(r); +} + +/* + * Error codes: + * + * =openpam_configure + * =pam_set_item + * !PAM_SYMBOL_ERR + * PAM_BUF_ERR + */ + +/** + * The =pam_start function creates and initializes a PAM context. + * + * The =service argument specifies the name of the policy to apply, and is + * stored in the =PAM_SERVICE item in the created context. + * + * The =user argument specifies the name of the target user - the user the + * created context will serve to authenticate. + * It is stored in the =PAM_USER item in the created context. + * + * The =pam_conv argument points to a =struct pam_conv describing the + * conversation function to use; see =pam_conv for details. + * + * >pam_get_item + * >pam_set_item + * >pam_end + */ diff --git a/lib/pam_strerror.c b/lib/pam_strerror.c new file mode 100644 index 0000000..24498c4 --- /dev/null +++ b/lib/pam_strerror.c @@ -0,0 +1,164 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_strerror.c 408 2007-12-21 11:36:24Z des $ + */ + +#include + +#include + +#include "openpam_impl.h" + +const char *_pam_err_name[PAM_NUM_ERRORS] = { + "PAM_SUCCESS", + "PAM_OPEN_ERR", + "PAM_SYMBOL_ERR", + "PAM_SERVICE_ERR", + "PAM_SYSTEM_ERR", + "PAM_BUF_ERR", + "PAM_CONV_ERR", + "PAM_PERM_DENIED", + "PAM_MAXTRIES", + "PAM_AUTH_ERR", + "PAM_NEW_AUTHTOK_REQD", + "PAM_CRED_INSUFFICIENT", + "PAM_AUTHINFO_UNAVAIL", + "PAM_USER_UNKNOWN", + "PAM_CRED_UNAVAIL", + "PAM_CRED_EXPIRED", + "PAM_CRED_ERR", + "PAM_ACCT_EXPIRED", + "PAM_AUTHTOK_EXPIRED", + "PAM_SESSION_ERR", + "PAM_AUTHTOK_ERR", + "PAM_AUTHTOK_RECOVERY_ERR", + "PAM_AUTHTOK_LOCK_BUSY", + "PAM_AUTHTOK_DISABLE_AGING", + "PAM_NO_MODULE_DATA", + "PAM_IGNORE", + "PAM_ABORT", + "PAM_TRY_AGAIN", + "PAM_MODULE_UNKNOWN", + "PAM_DOMAIN_UNKNOWN" +}; + +/* + * XSSO 4.2.1 + * XSSO 6 page 92 + * + * Get PAM standard error message string + */ + +const char * +pam_strerror(const pam_handle_t *pamh, + int error_number) +{ + static char unknown[16]; + + (void)pamh; + + switch (error_number) { + case PAM_SUCCESS: + return ("success"); + case PAM_OPEN_ERR: + return ("failed to load module"); + case PAM_SYMBOL_ERR: + return ("invalid symbol"); + case PAM_SERVICE_ERR: + return ("error in service module"); + case PAM_SYSTEM_ERR: + return ("system error"); + case PAM_BUF_ERR: + return ("memory buffer error"); + case PAM_CONV_ERR: + return ("conversation failure"); + case PAM_PERM_DENIED: + return ("permission denied"); + case PAM_MAXTRIES: + return ("maximum number of tries exceeded"); + case PAM_AUTH_ERR: + return ("authentication error"); + case PAM_NEW_AUTHTOK_REQD: + return ("new authentication token required"); + case PAM_CRED_INSUFFICIENT: + return ("insufficient credentials"); + case PAM_AUTHINFO_UNAVAIL: + return ("authentication information is unavailable"); + case PAM_USER_UNKNOWN: + return ("unknown user"); + case PAM_CRED_UNAVAIL: + return ("failed to retrieve user credentials"); + case PAM_CRED_EXPIRED: + return ("user credentials have expired"); + case PAM_CRED_ERR: + return ("failed to set user credentials"); + case PAM_ACCT_EXPIRED: + return ("user account has expired"); + case PAM_AUTHTOK_EXPIRED: + return ("password has expired"); + case PAM_SESSION_ERR: + return ("session failure"); + case PAM_AUTHTOK_ERR: + return ("authentication token failure"); + case PAM_AUTHTOK_RECOVERY_ERR: + return ("failed to recover old authentication token"); + case PAM_AUTHTOK_LOCK_BUSY: + return ("authentication token lock busy"); + case PAM_AUTHTOK_DISABLE_AGING: + return ("authentication token aging disabled"); + case PAM_NO_MODULE_DATA: + return ("module data not found"); + case PAM_IGNORE: + return ("ignore this module"); + case PAM_ABORT: + return ("general failure"); + case PAM_TRY_AGAIN: + return ("try again"); + case PAM_MODULE_UNKNOWN: + return ("unknown module type"); + case PAM_DOMAIN_UNKNOWN: + return ("unknown authentication domain"); + default: + snprintf(unknown, sizeof unknown, "#%d", error_number); + return (unknown); + } +} + +/** + * The =pam_strerror function returns a pointer to a string containing a + * textual description of the error indicated by the =error_number + * argument, in the context of the PAM transaction described by the =pamh + * argument. + */ diff --git a/lib/pam_verror.c b/lib/pam_verror.c new file mode 100644 index 0000000..0b128d1 --- /dev/null +++ b/lib/pam_verror.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_verror.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include + +#include +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Display an error message + */ + +int +pam_verror(const pam_handle_t *pamh, + const char *fmt, + va_list ap) +{ + char *rsp; + int r; + + r = pam_vprompt(pamh, PAM_ERROR_MSG, &rsp, fmt, ap); + FREE(rsp); /* ignore response */ + return (r); +} + +/* + * Error codes: + * + * !PAM_SYMBOL_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + */ + +/** + * The =pam_verror function passes its arguments to =pam_vprompt with a + * style argument of =PAM_ERROR_MSG, and discards the response. + * + * >pam_error + * >pam_vinfo + */ diff --git a/lib/pam_vinfo.c b/lib/pam_vinfo.c new file mode 100644 index 0000000..5282714 --- /dev/null +++ b/lib/pam_vinfo.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_vinfo.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include + +#include +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Display an information message + */ + +int +pam_vinfo(const pam_handle_t *pamh, + const char *fmt, + va_list ap) +{ + char *rsp; + int r; + + r = pam_vprompt(pamh, PAM_TEXT_INFO, &rsp, fmt, ap); + FREE(rsp); /* ignore response */ + return (r); +} + +/* + * Error codes: + * + * !PAM_SYMBOL_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + */ + +/** + * The =pam_vinfo function passes its arguments to =pam_vprompt with a + * style argument of =PAM_TEXT_INFO, and discards the response. + * + * >pam_info + * >pam_verror + */ diff --git a/lib/pam_vprompt.c b/lib/pam_vprompt.c new file mode 100644 index 0000000..e1215c3 --- /dev/null +++ b/lib/pam_vprompt.c @@ -0,0 +1,129 @@ +/*- + * Copyright (c) 2002-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: pam_vprompt.c 408 2007-12-21 11:36:24Z des $ + */ + +#include +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * OpenPAM extension + * + * Call the conversation function + */ + +int +pam_vprompt(const pam_handle_t *pamh, + int style, + char **resp, + const char *fmt, + va_list ap) +{ + char msgbuf[PAM_MAX_MSG_SIZE]; + struct pam_message msg; + const struct pam_message *msgp; + struct pam_response *rsp; + const struct pam_conv *conv; + const void *convp; + int r; + + ENTER(); + r = pam_get_item(pamh, PAM_CONV, &convp); + if (r != PAM_SUCCESS) + RETURNC(r); + conv = convp; + if (conv == NULL || conv->conv == NULL) { + openpam_log(PAM_LOG_ERROR, "no conversation function"); + RETURNC(PAM_SYSTEM_ERR); + } + vsnprintf(msgbuf, PAM_MAX_MSG_SIZE, fmt, ap); + msg.msg_style = style; + msg.msg = msgbuf; + msgp = &msg; + rsp = NULL; + r = (conv->conv)(1, &msgp, &rsp, conv->appdata_ptr); + *resp = rsp == NULL ? NULL : rsp->resp; + FREE(rsp); + RETURNC(r); +} + +/* + * Error codes: + * + * !PAM_SYMBOL_ERR + * PAM_SYSTEM_ERR + * PAM_BUF_ERR + * PAM_CONV_ERR + */ + +/** + * The =pam_vprompt function constructs a string from the =fmt and =ap + * arguments using =vsnprintf, and passes it to the given PAM context's + * conversation function. + * + * The =style argument specifies the type of interaction requested, and + * must be one of the following: + * + * =PAM_PROMPT_ECHO_OFF: + * Display the message and obtain the user's response without + * displaying it. + * =PAM_PROMPT_ECHO_ON: + * Display the message and obtain the user's response. + * =PAM_ERROR_MSG: + * Display the message as an error message, and do not wait + * for a response. + * =PAM_TEXT_INFO: + * Display the message as an informational message, and do + * not wait for a response. + * + * A pointer to the response, or =NULL if the conversation function did + * not return one, is stored in the location pointed to by the =resp + * argument. + * + * The message and response should not exceed =PAM_MAX_MSG_SIZE or + * =PAM_MAX_RESP_SIZE, respectively. + * If they do, they may be truncated. + * + * >pam_error + * >pam_info + * >pam_prompt + * >pam_verror + * >pam_vinfo + */ -- cgit v1.1 From 0a8d9e83286f1e0207031442c8c9b143758a0a75 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 9 Dec 2011 22:23:45 +0000 Subject: Upgrade our copy of llvm/clang to 3.0 release. Release notes can be found at: http://llvm.org/releases/3.0/docs/ReleaseNotes.html MFC after: 1 week --- lib/clang/include/MipsGenCodeEmitter.inc | 2 ++ lib/clang/include/clang/Basic/Version.inc | 4 ++-- lib/clang/libllvmmipscodegen/Makefile | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 lib/clang/include/MipsGenCodeEmitter.inc (limited to 'lib') diff --git a/lib/clang/include/MipsGenCodeEmitter.inc b/lib/clang/include/MipsGenCodeEmitter.inc new file mode 100644 index 0000000..1e2223d --- /dev/null +++ b/lib/clang/include/MipsGenCodeEmitter.inc @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +#include "MipsGenCodeEmitter.inc.h" diff --git a/lib/clang/include/clang/Basic/Version.inc b/lib/clang/include/clang/Basic/Version.inc index 1ab3e3e..18a7c8c 100644 --- a/lib/clang/include/clang/Basic/Version.inc +++ b/lib/clang/include/clang/Basic/Version.inc @@ -5,6 +5,6 @@ #define CLANG_VERSION_MINOR 0 #define CLANG_VENDOR "FreeBSD " -#define CLANG_VENDOR_SUFFIX " 20111021" +#define CLANG_VENDOR_SUFFIX " 20111209" -#define SVN_REVISION "142614" +#define SVN_REVISION "145546" diff --git a/lib/clang/libllvmmipscodegen/Makefile b/lib/clang/libllvmmipscodegen/Makefile index a70c072..f0b0180 100644 --- a/lib/clang/libllvmmipscodegen/Makefile +++ b/lib/clang/libllvmmipscodegen/Makefile @@ -24,6 +24,7 @@ SRCS= MipsAsmPrinter.cpp \ TGHDRS= Intrinsics \ MipsGenAsmWriter \ MipsGenCallingConv \ + MipsGenCodeEmitter \ MipsGenDAGISel \ MipsGenInstrInfo \ MipsGenRegisterInfo \ -- cgit v1.1 From 339827a68844d90e04afce4a7094daeff19acef4 Mon Sep 17 00:00:00 2001 From: dim Date: Sat, 10 Dec 2011 01:01:44 +0000 Subject: Use the correct upstream revision number for llvm/clang 3.0 release. The r145546 revision is from branches/release_30, the r145349 revision is from tags/RELEASE_30/final. MFC after: 1 week --- lib/clang/include/clang/Basic/Version.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/clang/include/clang/Basic/Version.inc b/lib/clang/include/clang/Basic/Version.inc index 18a7c8c..9842584 100644 --- a/lib/clang/include/clang/Basic/Version.inc +++ b/lib/clang/include/clang/Basic/Version.inc @@ -5,6 +5,6 @@ #define CLANG_VERSION_MINOR 0 #define CLANG_VENDOR "FreeBSD " -#define CLANG_VENDOR_SUFFIX " 20111209" +#define CLANG_VENDOR_SUFFIX " 20111210" -#define SVN_REVISION "145546" +#define SVN_REVISION "145349" -- cgit v1.1 From a105507a173a0d7935d40c66792b20bdb1f9f77d Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 13 Dec 2011 14:53:26 +0000 Subject: Don't use __P(). The rest of the file doesn't use it either and according to style(9), it should not be used. --- lib/libedit/histedit.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h index f245748..8417bb3 100644 --- a/lib/libedit/histedit.h +++ b/lib/libedit/histedit.h @@ -158,8 +158,8 @@ void el_resize(EditLine *); /* * Set user private data. */ -void el_data_set __P((EditLine *, void *)); -void * el_data_get __P((EditLine *)); +void el_data_set(EditLine *, void *); +void * el_data_get(EditLine *); /* * User-defined function interface. -- cgit v1.1 From eea2081b7ba5657f5262626acb93e1b0a7a08696 Mon Sep 17 00:00:00 2001 From: ru Date: Wed, 14 Dec 2011 08:35:08 +0000 Subject: Clean up includes; the prototype for getosreldate() has moved to in r183390. --- lib/libc/gen/getosreldate.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/libc/gen/getosreldate.c b/lib/libc/gen/getosreldate.c index 83bdc85..b4bf545 100644 --- a/lib/libc/gen/getosreldate.c +++ b/lib/libc/gen/getosreldate.c @@ -33,12 +33,11 @@ static char sccsid[] = "@(#)gethostid.c 8.1 (Berkeley) 6/2/93"; #include __FBSDID("$FreeBSD$"); -#include +#include #include -#include -#include -#include +#include +#include int getosreldate(void) -- cgit v1.1 From 09e4cb3bed3452f23085cd67bb9b8eff73657bb1 Mon Sep 17 00:00:00 2001 From: theraven Date: Thu, 15 Dec 2011 11:16:41 +0000 Subject: Small style(9) improvements. Approved by: dim (mentor) --- lib/libc/stdlib/quick_exit.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libc/stdlib/quick_exit.c b/lib/libc/stdlib/quick_exit.c index 33f9348..ef8cdb1 100644 --- a/lib/libc/stdlib/quick_exit.c +++ b/lib/libc/stdlib/quick_exit.c @@ -51,10 +51,12 @@ static struct quick_exit_handler *handlers; int at_quick_exit(void (*func)(void)) { - struct quick_exit_handler *h = malloc(sizeof(struct quick_exit_handler)); + struct quick_exit_handler *h; + + h = malloc(sizeof(*h)); if (NULL == h) - return 1; + return (1); h->cleanup = func; pthread_mutex_lock(&atexit_mutex); h->next = handlers; -- cgit v1.1 From 540bfb3294cc04aef78144ababcafcce86f6eaaa Mon Sep 17 00:00:00 2001 From: tuexen Date: Thu, 15 Dec 2011 12:35:03 +0000 Subject: Fix a bug where sctp_sendmdg() uses uninitialized memory. MFC after: 3 days. --- lib/libc/net/sctp_sys_calls.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/libc/net/sctp_sys_calls.c b/lib/libc/net/sctp_sys_calls.c index 72e9883..2e9c77a 100644 --- a/lib/libc/net/sctp_sys_calls.c +++ b/lib/libc/net/sctp_sys_calls.c @@ -563,6 +563,7 @@ sctp_sendmsg(int s, #ifdef SYS_sctp_generic_sendmsg struct sctp_sndrcvinfo sinfo; + memset(&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); sinfo.sinfo_ppid = ppid; sinfo.sinfo_flags = flags; sinfo.sinfo_stream = stream_no; -- cgit v1.1 From 366d0e5e6bc8a4c9a663a8cfb196b8010dc2f5f6 Mon Sep 17 00:00:00 2001 From: dim Date: Thu, 15 Dec 2011 19:42:25 +0000 Subject: The TCB_GET32() and TCB_GET64() macros in the i386 and amd64-specific versions of pthread_md.h have a special case of dereferencing a null pointer. Clang warns about this with: In file included from lib/libthr/arch/i386/i386/pthread_md.c:36: lib/libthr/arch/i386/include/pthread_md.h:96:10: error: indirection of non-volatile null pointer will be deleted, not trap [-Werror,-Wnull-dereference] return (TCB_GET32(tcb_self)); ^~~~~~~~~~~~~~~~~~~ lib/libthr/arch/i386/include/pthread_md.h:73:13: note: expanded from: : "m" (*(u_int *)(__tcb_offset(name)))); \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lib/libthr/arch/i386/include/pthread_md.h:96:10: note: consider using __builtin_trap() or qualifying pointer with 'volatile' Since this indirection is done relative to the fs or gs segment, to retrieve thread-specific data, it is an exception to the rule. Therefore, add a volatile qualifier to tell the compiler we really want to dereference a zero address. MFC after: 1 week --- lib/libthr/arch/amd64/include/pthread_md.h | 2 +- lib/libthr/arch/i386/include/pthread_md.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libthr/arch/amd64/include/pthread_md.h b/lib/libthr/arch/amd64/include/pthread_md.h index 9f6d3a1..0ebea2e 100644 --- a/lib/libthr/arch/amd64/include/pthread_md.h +++ b/lib/libthr/arch/amd64/include/pthread_md.h @@ -71,7 +71,7 @@ struct tcb { u_long __i; \ __asm __volatile("movq %%fs:%1, %0" \ : "=r" (__i) \ - : "m" (*(u_long *)(__tcb_offset(name)))); \ + : "m" (*(volatile u_long *)(__tcb_offset(name)))); \ __result = (__tcb_type(name))__i; \ \ __result; \ diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h index 5c00cf6..c160aa4 100644 --- a/lib/libthr/arch/i386/include/pthread_md.h +++ b/lib/libthr/arch/i386/include/pthread_md.h @@ -70,7 +70,7 @@ struct tcb { u_int __i; \ __asm __volatile("movl %%gs:%1, %0" \ : "=r" (__i) \ - : "m" (*(u_int *)(__tcb_offset(name)))); \ + : "m" (*(volatile u_int *)(__tcb_offset(name)))); \ __result = (__tcb_type(name))__i; \ \ __result; \ -- cgit v1.1 From eff6973ad8659f6856d467e550bbf642aac2eaac Mon Sep 17 00:00:00 2001 From: dim Date: Thu, 15 Dec 2011 20:10:12 +0000 Subject: Remove meaningless self-assignment in res_send.c, otherwise clang will warn about it. I guess this was originally done to silence a bogus warning by an older version of gcc, but I could not reproduce it with any version of gcc that I have access to. MFC after: 1 week --- lib/libc/resolv/res_send.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib') diff --git a/lib/libc/resolv/res_send.c b/lib/libc/resolv/res_send.c index d4f0c33..716ae32 100644 --- a/lib/libc/resolv/res_send.c +++ b/lib/libc/resolv/res_send.c @@ -1102,8 +1102,6 @@ Aerror(const res_state statp, FILE *file, const char *string, int error, char hbuf[NI_MAXHOST]; char sbuf[NI_MAXSERV]; - alen = alen; - if ((statp->options & RES_DEBUG) != 0U) { if (getnameinfo(address, alen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), niflags)) { -- cgit v1.1 From 1551a9d47765ddb3229399b4bb3fbacf4faaf66b Mon Sep 17 00:00:00 2001 From: dim Date: Thu, 15 Dec 2011 20:27:36 +0000 Subject: In lib/libc/rpc/crypt_client.c, fix a clang warning about an implicit conversion between enum desdir/desmode from include/rpc/des.h, and enum desdir/desmode from include/rpcsvc/crypt.x. These are actually different enums, with different value names, but by accident the integer representation of the enum values happened to be the same. MFC after: 1 week --- lib/libc/rpc/crypt_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libc/rpc/crypt_client.c b/lib/libc/rpc/crypt_client.c index 255b266..4e5c793 100644 --- a/lib/libc/rpc/crypt_client.c +++ b/lib/libc/rpc/crypt_client.c @@ -75,8 +75,8 @@ _des_crypt_call(buf, len, dparms) des_crypt_1_arg.desbuf.desbuf_len = len; des_crypt_1_arg.desbuf.desbuf_val = buf; - des_crypt_1_arg.des_dir = dparms->des_dir; - des_crypt_1_arg.des_mode = dparms->des_mode; + des_crypt_1_arg.des_dir = (dparms->des_dir == ENCRYPT) ? ENCRYPT_DES : DECRYPT_DES; + des_crypt_1_arg.des_mode = (dparms->des_mode == CBC) ? CBC_DES : ECB_DES; bcopy(dparms->des_ivec, des_crypt_1_arg.des_ivec, 8); bcopy(dparms->des_key, des_crypt_1_arg.des_key, 8); -- cgit v1.1 From b94ddd938bb1b86c6794c344a33ea3472829372b Mon Sep 17 00:00:00 2001 From: dim Date: Thu, 15 Dec 2011 20:40:11 +0000 Subject: Since clang does not support the tls_model attribute used in malloc.c yet (see LLVM PR 9788), and warns about it, rub it out for now. When clang grows support for this attribute, I will revert this again. MFC after: 1 week --- lib/libc/stdlib/malloc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 5290512..7ef59e4 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -219,7 +219,11 @@ __FBSDID("$FreeBSD$"); # define LG_QUANTUM 4 # define LG_SIZEOF_PTR 2 # define CPU_SPINWAIT __asm__ volatile("pause") -# define TLS_MODEL __attribute__((tls_model("initial-exec"))) +# ifdef __clang__ +# define TLS_MODEL /* clang does not support tls_model yet */ +# else +# define TLS_MODEL __attribute__((tls_model("initial-exec"))) +# endif #endif #ifdef __ia64__ # define LG_QUANTUM 4 @@ -240,7 +244,11 @@ __FBSDID("$FreeBSD$"); # define LG_QUANTUM 4 # define LG_SIZEOF_PTR 3 # define CPU_SPINWAIT __asm__ volatile("pause") -# define TLS_MODEL __attribute__((tls_model("initial-exec"))) +# ifdef __clang__ +# define TLS_MODEL /* clang does not support tls_model yet */ +# else +# define TLS_MODEL __attribute__((tls_model("initial-exec"))) +# endif #endif #ifdef __arm__ # define LG_QUANTUM 3 -- cgit v1.1 From b5cd6ab67fdbb336e943f41df3595dcfa1394853 Mon Sep 17 00:00:00 2001 From: bapt Date: Thu, 15 Dec 2011 22:07:36 +0000 Subject: Modify pw_copy: - if pw is NULL and oldpw is not NULL then the oldpw is deleted - if pw->pw_name != oldpw->pw_name but pw->pw_uid == oldpw->pw_uid then it renames the user add new gr_* functions so now gr_util API is similar to pw_util API, this allow to manipulate groups in a safe way. Reviewed by: des Approved by: des MFC after: 1 month --- lib/libutil/gr_util.c | 296 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/libutil/libutil.h | 8 +- lib/libutil/pw_util.c | 41 +++++-- 3 files changed, 332 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c index 633f435..0173595 100644 --- a/lib/libutil/gr_util.c +++ b/lib/libutil/gr_util.c @@ -28,23 +28,319 @@ __FBSDID("$FreeBSD$"); #include +#include +#include +#include +#include +#include #include #include #include +#include #include #include #include #include +#include struct group_storage { struct group gr; char *members[]; }; +static int lockfd = -1; +static char group_dir[PATH_MAX]; +static char group_file[PATH_MAX]; +static char tempname[PATH_MAX]; +static int initialized; + static const char group_line_format[] = "%s:%s:%ju:"; /* + * Initialize statics + */ +int +gr_init(const char *dir, const char *group) +{ + if (dir == NULL) { + strcpy(group_dir, _PATH_ETC); + } else { + if (strlen(dir) >= sizeof(group_dir)) { + errno = ENAMETOOLONG; + return (-1); + } + strcpy(group_dir, dir); + } + + if (group == NULL) { + if (dir == NULL) { + strcpy(group_file, _PATH_GROUP); + } else if (snprintf(group_file, sizeof(group_file), "%s/group", + group_dir) > (int)sizeof(group_file)) { + errno = ENAMETOOLONG; + return (-1); + } + } else { + if (strlen(group) >= sizeof(group_file)) { + errno = ENAMETOOLONG; + return (-1); + } + strcpy(group_file, group); + } + initialized = 1; + return (0); +} + +/* + * Lock the group file + */ +int +gr_lock(void) +{ + if (*group_file == '\0') + return (-1); + + for (;;) { + struct stat st; + + lockfd = open(group_file, O_RDONLY, 0); + if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1) + err(1, "%s", group_file); + if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) { + if (errno == EWOULDBLOCK) { + errx(1, "the group file is busy"); + } else { + err(1, "could not lock the group file: "); + } + } + if (fstat(lockfd, &st) == -1) + err(1, "fstat() failed: "); + if (st.st_nlink != 0) + break; + close(lockfd); + lockfd = -1; + } + return (lockfd); +} + +/* + * Create and open a presmuably safe temp file for editing group data + */ +int +gr_tmp(int mfd) +{ + char buf[8192]; + ssize_t nr; + const char *p; + int tfd; + + if (*group_file == '\0') + return (-1); + if ((p = strrchr(group_file, '/'))) + ++p; + else + p = group_file; + if (snprintf(tempname, sizeof(tempname), "%.*sgroup.XXXXXX", + (int)(p - group_file), group_file) >= (int)sizeof(tempname)) { + errno = ENAMETOOLONG; + return (-1); + } + if ((tfd = mkstemp(tempname)) == -1) + return (-1); + if (mfd != -1) { + while ((nr = read(mfd, buf, sizeof(buf))) > 0) + if (write(tfd, buf, (size_t)nr) != nr) + break; + if (nr != 0) { + unlink(tempname); + *tempname = '\0'; + close(tfd); + return (-1); + } + } + return (tfd); +} + +/* + * Copy the group file from one descriptor to another, replacing, deleting + * or adding a single record on the way. + */ +int +gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr) +{ + char buf[8192], *end, *line, *p, *q, *r, t; + struct group *fgr; + const struct group *sgr; + size_t len; + int eof, readlen; + + sgr = gr; + if (gr == NULL) { + line = NULL; + if (old_gr == NULL) + return (-1); + sgr = old_gr; + } else if ((line = gr_make(gr)) == NULL) + return (-1); + + eof = 0; + len = 0; + p = q = end = buf; + for (;;) { + /* find the end of the current line */ + for (p = q; q < end && *q != '\0'; ++q) + if (*q == '\n') + break; + + /* if we don't have a complete line, fill up the buffer */ + if (q >= end) { + if (eof) + break; + if ((size_t)(q - p) >= sizeof(buf)) { + warnx("group line too long"); + errno = EINVAL; /* hack */ + goto err; + } + if (p < end) { + q = memmove(buf, p, end -p); + end -= p - buf; + } else { + p = q = end = buf; + } + readlen = read(ffd, end, sizeof(buf) - (end -buf)); + if (readlen == -1) + goto err; + else + len = (size_t)readlen; + if (len == 0 && p == buf) + break; + end += len; + len = end - buf; + if (len < (ssize_t)sizeof(buf)) { + eof = 1; + if (len > 0 && buf[len -1] != '\n') + ++len, *end++ = '\n'; + } + continue; + } + + /* is it a blank line or a comment? */ + for (r = p; r < q && isspace(*r); ++r) + /* nothing */; + if (r == q || *r == '#') { + /* yep */ + if (write(tfd, p, q -p + 1) != q - p + 1) + goto err; + ++q; + continue; + } + + /* is it the one we're looking for? */ + + t = *q; + *q = '\0'; + + fgr = gr_scan(r); + + /* fgr is either a struct group for the current line, + * or NULL if the line is malformed. + */ + + *q = t; + if (fgr == NULL || fgr->gr_gid != sgr->gr_gid) { + /* nope */ + if (fgr != NULL) + free(fgr); + if (write(tfd, p, q - p + 1) != q - p + 1) + goto err; + ++q; + continue; + } + if (old_gr && !gr_equal(fgr, old_gr)) { + warnx("entry inconsistent"); + free(fgr); + errno = EINVAL; /* hack */ + goto err; + } + free(fgr); + + /* it is, replace or remove it */ + if (line != NULL) { + len = strlen(line); + if (write(tfd, line, len) != (int) len) + goto err; + } else { + /* when removed, avoid the \n */ + q++; + } + /* we're done, just copy the rest over */ + for (;;) { + if (write(tfd, q, end - q) != end - q) + goto err; + q = buf; + readlen = read(ffd, buf, sizeof(buf)); + if (readlen == 0) + break; + else + len = (size_t)readlen; + if (readlen == -1) + goto err; + end = buf + len; + } + goto done; + } + + /* if we got here, we didn't find the old entry */ + if (line == NULL) { + errno = ENOENT; + goto err; + } + len = strlen(line); + if ((size_t)write(tfd, line, len) != len || + write(tfd, "\n", 1) != 1) + goto err; + done: + if (line != NULL) + free(line); + return (0); + err: + if (line != NULL) + free(line); + return (-1); +} + +/* + * Regenerate the group file + */ +int +gr_mkdb(void) +{ + return (rename(tempname, group_file)); +} + +/* + * Clean up. Preserver errno for the caller's convenience. + */ +void +gr_fini(void) +{ + int serrno; + + if (!initialized) + return; + initialized = 0; + serrno = errno; + if (*tempname != '\0') { + unlink(tempname); + *tempname = '\0'; + } + if (lockfd != -1) + close(lockfd); + errno = serrno; +} + +/* * Compares two struct group's. */ int diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h index fc6d3bb..dea14cf 100644 --- a/lib/libutil/libutil.h +++ b/lib/libutil/libutil.h @@ -152,9 +152,15 @@ int pw_tmp(int _mfd); #endif #ifdef _GRP_H_ +int gr_copy(int __ffd, int _tfd, const struct group *_gr, struct group *_old_gr); +struct group *gr_dup(const struct group *gr); int gr_equal(const struct group *gr1, const struct group *gr2); +void gr_fini(void); +int gr_init(const char *_dir, const char *_master); +int gr_lock(void); char *gr_make(const struct group *gr); -struct group *gr_dup(const struct group *gr); +int gr_mkdb(void); +int gr_tmp(int _mdf); struct group *gr_scan(const char *line); #endif diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c index 5eae280..1068eff 100644 --- a/lib/libutil/pw_util.c +++ b/lib/libutil/pw_util.c @@ -410,18 +410,25 @@ pw_make(const struct passwd *pw) } /* - * Copy password file from one descriptor to another, replacing or adding - * a single record on the way. + * Copy password file from one descriptor to another, replacing, deleting + * or adding a single record on the way. */ int pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw) { char buf[8192], *end, *line, *p, *q, *r, t; struct passwd *fpw; + const struct passwd *spw; size_t len; int eof, readlen; - if ((line = pw_make(pw)) == NULL) + spw = pw; + if (pw == NULL) { + line = NULL; + if (old_pw == NULL) + return (-1); + spw = old_pw; + } else if ((line = pw_make(pw)) == NULL) return (-1); eof = 0; @@ -489,7 +496,7 @@ pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw) */ *q = t; - if (fpw == NULL || strcmp(fpw->pw_name, pw->pw_name) != 0) { + if (fpw == NULL || fpw->pw_uid != spw->pw_uid) { /* nope */ if (fpw != NULL) free(fpw); @@ -506,11 +513,15 @@ pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw) } free(fpw); - /* it is, replace it */ - len = strlen(line); - if (write(tfd, line, len) != (int)len) - goto err; - + /* it is, replace or remove it */ + if (line != NULL) { + len = strlen(line); + if (write(tfd, line, len) != (int)len) + goto err; + } else { + /* when removed, avoid the \n */ + q++; + } /* we're done, just copy the rest over */ for (;;) { if (write(tfd, q, end - q) != end - q) @@ -528,16 +539,22 @@ pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw) goto done; } - /* if we got here, we have a new entry */ + /* if we got here, we didn't find the old entry */ + if (line == NULL) { + errno = ENOENT; + goto err; + } len = strlen(line); if ((size_t)write(tfd, line, len) != len || write(tfd, "\n", 1) != 1) goto err; done: - free(line); + if (line != NULL) + free(line); return (0); err: - free(line); + if (line != NULL) + free(line); return (-1); } -- cgit v1.1 From 1288130bd13319920e34b68f23b20efc6ed070a6 Mon Sep 17 00:00:00 2001 From: dim Date: Thu, 15 Dec 2011 23:22:24 +0000 Subject: Define YY_NO_INPUT in lib/libipsec/policy_token.l, so lex's input() function does not get defined needlessly. MFC after: 1 week --- lib/libipsec/policy_token.l | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/libipsec/policy_token.l b/lib/libipsec/policy_token.l index d648702..d04720d 100644 --- a/lib/libipsec/policy_token.l +++ b/lib/libipsec/policy_token.l @@ -48,6 +48,7 @@ #include "y.tab.h" #define yylval __libipsecyylval /* XXX */ +#define YY_NO_INPUT int yylex(void); %} -- cgit v1.1 From 8961209ca3de731aab12c5aa523e15e6b448c45c Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 16 Dec 2011 00:01:19 +0000 Subject: In lib/libipsec/policy_token.l, use lex's standard "%option noinput" instead of hand-defining the YY_NO_INPUT macro. MFC after: 1 week --- lib/libipsec/policy_token.l | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libipsec/policy_token.l b/lib/libipsec/policy_token.l index d04720d..2a79d5e 100644 --- a/lib/libipsec/policy_token.l +++ b/lib/libipsec/policy_token.l @@ -48,13 +48,13 @@ #include "y.tab.h" #define yylval __libipsecyylval /* XXX */ -#define YY_NO_INPUT int yylex(void); %} %option noyywrap %option nounput +%option noinput /* common section */ nl \n -- cgit v1.1 From 3531846fa5f4b77d760e99879743fc445888caa9 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 16 Dec 2011 00:13:43 +0000 Subject: In lib/libpmc/libpmc.c, struct pmc_cputype_map's pm_cputype field should be of type 'enum pmc_cputype', not 'enum pmc_class'. MFC after: 1 week --- lib/libpmc/libpmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c index f0d5b0c..efdabc8 100644 --- a/lib/libpmc/libpmc.c +++ b/lib/libpmc/libpmc.c @@ -289,7 +289,7 @@ static const char * pmc_class_names[] = { }; struct pmc_cputype_map { - enum pmc_class pm_cputype; + enum pmc_cputype pm_cputype; const char *pm_name; }; -- cgit v1.1 From f5af6108d0c7f3fefb26388aa0bf848fc61482d8 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 16 Dec 2011 00:39:44 +0000 Subject: Unfortunately, clang gives a warning about sendmail code that cannot be turned off yet. Since this is contrib code, and we don't really care about the warnings, just turn make them non-fatal for now. MFC after: 1 week --- lib/libsm/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/libsm/Makefile b/lib/libsm/Makefile index ce590d7..f2c93b9 100644 --- a/lib/libsm/Makefile +++ b/lib/libsm/Makefile @@ -18,6 +18,13 @@ CFLAGS+=${SENDMAIL_CFLAGS} WARNS?= 2 +.if ${CC:T:Mclang} == "clang" +# Unfortunately, clang gives a warning about sendmail code that cannot +# be turned off yet. Since this is contrib code, and we don't really +# care about the warnings, just turn make them non-fatal for now. +NO_WERROR= +.endif + LIB= sm SRCS+= sm_os.h -- cgit v1.1 From 27a36f6ac8242750daa092abd7180b10d16f4508 Mon Sep 17 00:00:00 2001 From: glebius Date: Fri, 16 Dec 2011 12:16:56 +0000 Subject: A major overhaul of the CARP implementation. The ip_carp.c was started from scratch, copying needed functionality from the old implemenation on demand, with a thorough review of all code. The main change is that interface layer has been removed from the CARP. Now redundant addresses are configured exactly on the interfaces, they run on. The CARP configuration itself is, as before, configured and read via SIOCSVH/SIOCGVH ioctls. A new prefix created with SIOCAIFADDR or SIOCAIFADDR_IN6 may now be configured to a particular virtual host id, which makes the prefix redundant. ifconfig(8) semantics has been changed too: now one doesn't need to clone carpXX interface, he/she should directly configure a vhid on a Ethernet interface. To supply vhid data from the kernel to an application the getifaddrs(8) function had been changed to pass ifam_data with each address. [1] The new implementation definitely closes all PRs related to carp(4) being an interface, and may close several others. It also allows to run a single redundant IP per interface. Big thanks to Bjoern Zeeb for his help with inet6 part of patch, for idea on using ifam_data and for several rounds of reviewing! PR: kern/117000, kern/126945, kern/126714, kern/120130, kern/117448 Reviewed by: bz Submitted by: bz [1] --- lib/libc/net/getifaddrs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libc/net/getifaddrs.c b/lib/libc/net/getifaddrs.c index 41ef3f4..aada929 100644 --- a/lib/libc/net/getifaddrs.c +++ b/lib/libc/net/getifaddrs.c @@ -76,7 +76,7 @@ __FBSDID("$FreeBSD$"); #define HAVE_IFM_DATA #endif -#if _BSDI_VERSION >= 199802 +#if (_BSDI_VERSION >= 199802) || (__FreeBSD_version >= 1000003) /* ifam_data is very specific to recent versions of bsdi */ #define HAVE_IFAM_DATA #endif -- cgit v1.1 From 5780802b6cec44c8398568043c1dbf8bd3d4c241 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 16 Dec 2011 15:00:56 +0000 Subject: In lib/libthread_db/arch/i386/libpthread_md.c, clang gives two incorrect warnings about alignment, so turn -Wcast-align off for now. MFC after: 1 week --- lib/libthread_db/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/libthread_db/Makefile b/lib/libthread_db/Makefile index 047bbe6..a66f25d 100644 --- a/lib/libthread_db/Makefile +++ b/lib/libthread_db/Makefile @@ -16,4 +16,10 @@ SYM_MAPS+=${.CURDIR}/Symbol.map SYMBOL_MAPS=${SYM_MAPS} VERSION_DEF=${.CURDIR}/../libc/Versions.def +.if ${CC:T:Mclang} == "clang" +# Unfortunately, clang gives an incorrect warning about alignment in +# arch/i386/libpthread_md.c, so turn that off for now. +NO_WCAST_ALIGN= +.endif + .include -- cgit v1.1 From 838b9f84ea6a2b70f53b6c7b09c42bc108e028f7 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 16 Dec 2011 17:02:25 +0000 Subject: Fix typos in the comments about clang warnings in several sendmail-related Makefiles. Spotted by: arundel MFC after: 1 week --- lib/libsm/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libsm/Makefile b/lib/libsm/Makefile index f2c93b9..661e87a 100644 --- a/lib/libsm/Makefile +++ b/lib/libsm/Makefile @@ -19,9 +19,9 @@ CFLAGS+=${SENDMAIL_CFLAGS} WARNS?= 2 .if ${CC:T:Mclang} == "clang" -# Unfortunately, clang gives a warning about sendmail code that cannot +# Unfortunately, clang gives warnings about sendmail code that cannot # be turned off yet. Since this is contrib code, and we don't really -# care about the warnings, just turn make them non-fatal for now. +# care about the warnings, just make them non-fatal for now. NO_WERROR= .endif -- cgit v1.1 From 04ff721cff67dd3e641289f950656b9dbd02d09f Mon Sep 17 00:00:00 2001 From: tuexen Date: Sat, 17 Dec 2011 14:55:19 +0000 Subject: Address warnings found by clang. MFC after: 3 months. --- lib/libc/net/sctp_sys_calls.c | 64 +++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 36 deletions(-) (limited to 'lib') diff --git a/lib/libc/net/sctp_sys_calls.c b/lib/libc/net/sctp_sys_calls.c index 2e9c77a..e9c9d64 100644 --- a/lib/libc/net/sctp_sys_calls.c +++ b/lib/libc/net/sctp_sys_calls.c @@ -245,7 +245,8 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags) struct sockaddr *sa; struct sockaddr_in *sin; struct sockaddr_in6 *sin6; - int i, sz, argsz; + int i; + size_t argsz; uint16_t sport = 0; /* validate the flags */ @@ -269,7 +270,6 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags) /* First pre-screen the addresses */ sa = addrs; for (i = 0; i < addrcnt; i++) { - sz = sa->sa_len; if (sa->sa_family == AF_INET) { if (sa->sa_len != sizeof(struct sockaddr_in)) goto out_error; @@ -307,7 +307,7 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags) goto out_error; } - sa = (struct sockaddr *)((caddr_t)sa + sz); + sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); } sa = addrs; /* @@ -319,7 +319,6 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags) sin->sin_port = sport; } for (i = 0; i < addrcnt; i++) { - sz = sa->sa_len; if (sa->sa_family == AF_INET) { if (sa->sa_len != sizeof(struct sockaddr_in)) goto out_error; @@ -335,13 +334,13 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags) } memset(gaddrs, 0, argsz); gaddrs->sget_assoc_id = 0; - memcpy(gaddrs->addr, sa, sz); + memcpy(gaddrs->addr, sa, sa->sa_len); if (setsockopt(sd, IPPROTO_SCTP, flags, gaddrs, (socklen_t) argsz) != 0) { free(gaddrs); return (-1); } - sa = (struct sockaddr *)((caddr_t)sa + sz); + sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); } free(gaddrs); return (0); @@ -430,10 +429,9 @@ sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs) { struct sctp_getaddresses *addrs; struct sockaddr *sa; - struct sockaddr *re; sctp_assoc_t asoc; caddr_t lim; - socklen_t siz; + socklen_t opt_len; int cnt; if (raddrs == NULL) { @@ -441,30 +439,28 @@ sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs) return (-1); } asoc = id; - siz = sizeof(sctp_assoc_t); + opt_len = (socklen_t) sizeof(sctp_assoc_t); if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_REMOTE_ADDR_SIZE, - &asoc, &siz) != 0) { + &asoc, &opt_len) != 0) { return (-1); } /* size required is returned in 'asoc' */ - siz = (size_t)asoc; - siz += sizeof(struct sctp_getaddresses); - addrs = calloc(1, siz); + opt_len = (socklen_t) ((size_t)asoc + sizeof(struct sctp_getaddresses)); + addrs = calloc(1, (size_t)opt_len); if (addrs == NULL) { return (-1); } addrs->sget_assoc_id = id; /* Now lets get the array of addresses */ if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_PEER_ADDRESSES, - addrs, &siz) != 0) { + addrs, &opt_len) != 0) { free(addrs); return (-1); } - re = (struct sockaddr *)&addrs->addr[0]; - *raddrs = re; + *raddrs = (struct sockaddr *)&addrs->addr[0]; cnt = 0; sa = (struct sockaddr *)&addrs->addr[0]; - lim = (caddr_t)addrs + siz; + lim = (caddr_t)addrs + opt_len; while (((caddr_t)sa < lim) && (sa->sa_len > 0)) { sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); cnt++; @@ -487,11 +483,10 @@ int sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs) { struct sctp_getaddresses *addrs; - struct sockaddr *re; caddr_t lim; struct sockaddr *sa; - int size_of_addresses; - socklen_t siz; + size_t size_of_addresses; + socklen_t opt_len; int cnt; if (raddrs == NULL) { @@ -499,9 +494,9 @@ sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs) return (-1); } size_of_addresses = 0; - siz = sizeof(int); + opt_len = (socklen_t) sizeof(int); if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_LOCAL_ADDR_SIZE, - &size_of_addresses, &siz) != 0) { + &size_of_addresses, &opt_len) != 0) { errno = ENOMEM; return (-1); } @@ -509,9 +504,10 @@ sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs) errno = ENOTCONN; return (-1); } - siz = size_of_addresses + sizeof(struct sockaddr_storage); - siz += sizeof(struct sctp_getaddresses); - addrs = calloc(1, siz); + opt_len = (socklen_t) (size_of_addresses + + sizeof(struct sockaddr_storage) + + sizeof(struct sctp_getaddresses)); + addrs = calloc(1, (size_t)opt_len); if (addrs == NULL) { errno = ENOMEM; return (-1); @@ -519,16 +515,15 @@ sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs) addrs->sget_assoc_id = id; /* Now lets get the array of addresses */ if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_LOCAL_ADDRESSES, addrs, - &siz) != 0) { + &opt_len) != 0) { free(addrs); errno = ENOMEM; return (-1); } - re = (struct sockaddr *)&addrs->addr[0]; - *raddrs = re; + *raddrs = (struct sockaddr *)&addrs->addr[0]; cnt = 0; sa = (struct sockaddr *)&addrs->addr[0]; - lim = (caddr_t)addrs + siz; + lim = (caddr_t)addrs + opt_len; while (((caddr_t)sa < lim) && (sa->sa_len > 0)) { sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); cnt++; @@ -735,7 +730,8 @@ sctp_sendx(int sd, const void *msg, size_t msg_len, ssize_t ret; int i, cnt, *aa, saved_errno; char *buf; - int add_len, len, no_end_cx = 0; + int no_end_cx = 0; + size_t len, add_len; struct sockaddr *at; if (addrs == NULL) { @@ -785,7 +781,7 @@ sctp_sendx(int sd, const void *msg, size_t msg_len, aa = (int *)buf; *aa = cnt; aa++; - memcpy((caddr_t)aa, addrs, (len - sizeof(int))); + memcpy((caddr_t)aa, addrs, (size_t)(len - sizeof(int))); ret = setsockopt(sd, IPPROTO_SCTP, SCTP_CONNECT_X_DELAYED, (void *)buf, (socklen_t) len); @@ -862,7 +858,6 @@ sctp_recvmsg(int s, #else struct sctp_sndrcvinfo *s_info; ssize_t sz; - int sinfo_found = 0; struct msghdr msg; struct iovec iov; char controlVector[SCTP_CONTROL_VEC_SIZE_RCV]; @@ -891,7 +886,6 @@ sctp_recvmsg(int s, return (sz); } s_info = NULL; - len = sz; if (sinfo) { sinfo->sinfo_assoc_id = 0; } @@ -912,7 +906,6 @@ sctp_recvmsg(int s, /* Copy it to the user */ if (sinfo) *sinfo = *s_info; - sinfo_found = 1; break; } else if (cmsg->cmsg_type == SCTP_EXTRCV) { /* @@ -925,7 +918,6 @@ sctp_recvmsg(int s, if (sinfo) { memcpy(sinfo, s_info, sizeof(struct sctp_extrcvinfo)); } - sinfo_found = 1; break; } @@ -1058,7 +1050,7 @@ sctp_sendv(int sd, cmsgbuf = malloc(CMSG_SPACE(sizeof(struct sctp_sndinfo)) + CMSG_SPACE(sizeof(struct sctp_prinfo)) + CMSG_SPACE(sizeof(struct sctp_authinfo)) + - addrcnt * CMSG_SPACE(sizeof(struct in6_addr))); + (size_t)addrcnt * CMSG_SPACE(sizeof(struct in6_addr))); if (cmsgbuf == NULL) { errno = ENOBUFS; return (-1); -- cgit v1.1 From 9a25ed673db408d79135934ee39ea88142f9ed4d Mon Sep 17 00:00:00 2001 From: des Date: Sun, 18 Dec 2011 17:08:40 +0000 Subject: Vendor import of OpenPAM Lycopsida. --- lib/Makefile.am | 17 +- lib/Makefile.in | 700 ++++++++++++------------------------ lib/openpam_borrow_cred.c | 8 +- lib/openpam_check_owner_perms.c | 127 +++++++ lib/openpam_configure.c | 487 +++++++++++++++++++------ lib/openpam_constants.c | 127 +++++++ lib/openpam_constants.h | 40 +++ lib/openpam_debug.h | 103 ++++++ lib/openpam_dispatch.c | 40 +-- lib/openpam_dynamic.c | 59 ++- lib/openpam_findenv.c | 8 +- lib/openpam_free_data.c | 8 +- lib/openpam_free_envlist.c | 10 +- lib/openpam_get_option.c | 8 +- lib/openpam_impl.h | 115 +++--- lib/openpam_load.c | 30 +- lib/openpam_log.c | 18 +- lib/openpam_nullconv.c | 8 +- lib/openpam_readline.c | 49 +-- lib/openpam_restore_cred.c | 8 +- lib/openpam_set_option.c | 8 +- lib/openpam_static.c | 12 +- lib/openpam_strlcmp.h | 46 +++ lib/openpam_strlcpy.h | 49 +++ lib/openpam_subst.c | 168 +++++++++ lib/openpam_ttyconv.c | 10 +- lib/pam_acct_mgmt.c | 8 +- lib/pam_authenticate.c | 8 +- lib/pam_authenticate_secondary.c | 8 +- lib/pam_chauthtok.c | 8 +- lib/pam_close_session.c | 8 +- lib/pam_end.c | 8 +- lib/pam_error.c | 8 +- lib/pam_get_authtok.c | 42 ++- lib/pam_get_data.c | 9 +- lib/pam_get_item.c | 33 +- lib/pam_get_mapped_authtok.c | 8 +- lib/pam_get_mapped_username.c | 8 +- lib/pam_get_user.c | 40 ++- lib/pam_getenv.c | 8 +- lib/pam_getenvlist.c | 8 +- lib/pam_info.c | 8 +- lib/pam_open_session.c | 8 +- lib/pam_prompt.c | 8 +- lib/pam_putenv.c | 8 +- lib/pam_set_data.c | 8 +- lib/pam_set_item.c | 13 +- lib/pam_set_mapped_authtok.c | 8 +- lib/pam_set_mapped_username.c | 8 +- lib/pam_setcred.c | 8 +- lib/pam_setenv.c | 8 +- lib/pam_sm_acct_mgmt.c | 8 +- lib/pam_sm_authenticate.c | 8 +- lib/pam_sm_authenticate_secondary.c | 8 +- lib/pam_sm_chauthtok.c | 12 +- lib/pam_sm_close_session.c | 8 +- lib/pam_sm_get_mapped_authtok.c | 8 +- lib/pam_sm_get_mapped_username.c | 8 +- lib/pam_sm_open_session.c | 8 +- lib/pam_sm_set_mapped_authtok.c | 8 +- lib/pam_sm_set_mapped_username.c | 8 +- lib/pam_sm_setcred.c | 8 +- lib/pam_start.c | 30 +- lib/pam_strerror.c | 45 +-- lib/pam_verror.c | 8 +- lib/pam_vinfo.c | 8 +- lib/pam_vprompt.c | 8 +- 67 files changed, 1816 insertions(+), 935 deletions(-) create mode 100644 lib/openpam_check_owner_perms.c create mode 100644 lib/openpam_constants.c create mode 100644 lib/openpam_constants.h create mode 100644 lib/openpam_debug.h create mode 100644 lib/openpam_strlcmp.h create mode 100644 lib/openpam_strlcpy.h create mode 100644 lib/openpam_subst.c (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am index c748079..3a2e60e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am 395 2007-06-03 20:26:18Z des $ +# $Id: Makefile.am 499 2011-11-22 11:51:50Z des $ NULL = @@ -6,11 +6,18 @@ INCLUDES = -I$(top_srcdir)/include lib_LTLIBRARIES = libpam.la -noinst_HEADERS = openpam_impl.h +noinst_HEADERS = \ + openpam_constants.h \ + openpam_debug.h \ + openpam_impl.h \ + openpam_strlcmp.h \ + openpam_strlcpy.h libpam_la_SOURCES = \ openpam_borrow_cred.c \ + openpam_check_owner_perms.c \ openpam_configure.c \ + openpam_constants.c \ openpam_dispatch.c \ openpam_dynamic.c \ openpam_findenv.c \ @@ -24,6 +31,7 @@ libpam_la_SOURCES = \ openpam_restore_cred.c \ openpam_set_option.c \ openpam_static.c \ + openpam_subst.c \ openpam_ttyconv.c \ pam_acct_mgmt.c \ pam_authenticate.c \ @@ -52,9 +60,8 @@ libpam_la_SOURCES = \ pam_vprompt.c \ $(NULL) -libpam_la_CFLAGS = -DOPENPAM_MODULES_DIR='"@OPENPAM_MODULES_DIR@/"' - -libpam_la_LDFLAGS = -no-undefined -version-info @LIB_MAJ@ @DL_LIBS@ +libpam_la_LDFLAGS = -no-undefined -version-info @LIB_MAJ@ +libpam_la_LIBADD = @DL_LIBS@ EXTRA_DIST = \ pam_authenticate_secondary.c \ diff --git a/lib/Makefile.in b/lib/Makefile.in index f1ab0ad..0052ce2 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -1,8 +1,9 @@ -# Makefile.in generated by automake 1.9.6 from Makefile.am. +# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005 Free Software Foundation, Inc. +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -14,18 +15,15 @@ @SET_MAKE@ -# $Id: Makefile.am 395 2007-06-03 20:26:18Z des $ +# $Id: Makefile.am 499 2011-11-22 11:51:50Z des $ -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ -top_builddir = .. +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = @INSTALL@ install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c @@ -39,7 +37,6 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -target_triplet = @target@ subdir = lib DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in @@ -50,53 +47,65 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; -am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__installdirs = "$(DESTDIR)$(libdir)" -libLTLIBRARIES_INSTALL = $(INSTALL) LTLIBRARIES = $(lib_LTLIBRARIES) -libpam_la_LIBADD = +libpam_la_DEPENDENCIES = am__objects_1 = -am_libpam_la_OBJECTS = libpam_la-openpam_borrow_cred.lo \ - libpam_la-openpam_configure.lo libpam_la-openpam_dispatch.lo \ - libpam_la-openpam_dynamic.lo libpam_la-openpam_findenv.lo \ - libpam_la-openpam_free_data.lo \ - libpam_la-openpam_free_envlist.lo \ - libpam_la-openpam_get_option.lo libpam_la-openpam_load.lo \ - libpam_la-openpam_log.lo libpam_la-openpam_nullconv.lo \ - libpam_la-openpam_readline.lo \ - libpam_la-openpam_restore_cred.lo \ - libpam_la-openpam_set_option.lo libpam_la-openpam_static.lo \ - libpam_la-openpam_ttyconv.lo libpam_la-pam_acct_mgmt.lo \ - libpam_la-pam_authenticate.lo libpam_la-pam_chauthtok.lo \ - libpam_la-pam_close_session.lo libpam_la-pam_end.lo \ - libpam_la-pam_error.lo libpam_la-pam_get_authtok.lo \ - libpam_la-pam_get_data.lo libpam_la-pam_get_item.lo \ - libpam_la-pam_get_user.lo libpam_la-pam_getenv.lo \ - libpam_la-pam_getenvlist.lo libpam_la-pam_info.lo \ - libpam_la-pam_open_session.lo libpam_la-pam_prompt.lo \ - libpam_la-pam_putenv.lo libpam_la-pam_set_data.lo \ - libpam_la-pam_set_item.lo libpam_la-pam_setcred.lo \ - libpam_la-pam_setenv.lo libpam_la-pam_start.lo \ - libpam_la-pam_strerror.lo libpam_la-pam_verror.lo \ - libpam_la-pam_vinfo.lo libpam_la-pam_vprompt.lo \ - $(am__objects_1) +am_libpam_la_OBJECTS = openpam_borrow_cred.lo \ + openpam_check_owner_perms.lo openpam_configure.lo \ + openpam_constants.lo openpam_dispatch.lo openpam_dynamic.lo \ + openpam_findenv.lo openpam_free_data.lo \ + openpam_free_envlist.lo openpam_get_option.lo openpam_load.lo \ + openpam_log.lo openpam_nullconv.lo openpam_readline.lo \ + openpam_restore_cred.lo openpam_set_option.lo \ + openpam_static.lo openpam_subst.lo openpam_ttyconv.lo \ + pam_acct_mgmt.lo pam_authenticate.lo pam_chauthtok.lo \ + pam_close_session.lo pam_end.lo pam_error.lo \ + pam_get_authtok.lo pam_get_data.lo pam_get_item.lo \ + pam_get_user.lo pam_getenv.lo pam_getenvlist.lo pam_info.lo \ + pam_open_session.lo pam_prompt.lo pam_putenv.lo \ + pam_set_data.lo pam_set_item.lo pam_setcred.lo pam_setenv.lo \ + pam_start.lo pam_strerror.lo pam_verror.lo pam_vinfo.lo \ + pam_vprompt.lo $(am__objects_1) libpam_la_OBJECTS = $(am_libpam_la_OBJECTS) -DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +libpam_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libpam_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles +am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) -LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(AM_LDFLAGS) $(LDFLAGS) -o $@ +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ SOURCES = $(libpam_la_SOURCES) DIST_SOURCES = $(libpam_la_SOURCES) HEADERS = $(noinst_HEADERS) @@ -104,8 +113,6 @@ ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ -AMDEP_FALSE = @AMDEP_FALSE@ -AMDEP_TRUE = @AMDEP_TRUE@ AMTAR = @AMTAR@ AR = @AR@ AUTOCONF = @AUTOCONF@ @@ -118,42 +125,50 @@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CRYPT_LIBS = @CRYPT_LIBS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DL_LIBS = @DL_LIBS@ -ECHO = @ECHO@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ -F77 = @F77@ -FFLAGS = @FFLAGS@ +FGREP = @FGREP@ GREP = @GREP@ +INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIB_MAJ = @LIB_MAJ@ +LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OPENPAM_MODULES_DIR = @OPENPAM_MODULES_DIR@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ @@ -162,19 +177,13 @@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ -WITH_DOC_FALSE = @WITH_DOC_FALSE@ -WITH_DOC_TRUE = @WITH_DOC_TRUE@ -WITH_PAM_UNIX_FALSE = @WITH_PAM_UNIX_FALSE@ -WITH_PAM_UNIX_TRUE = @WITH_PAM_UNIX_TRUE@ -WITH_SU_FALSE = @WITH_SU_FALSE@ -WITH_SU_TRUE = @WITH_SU_TRUE@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_F77 = @ac_ct_F77@ -am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ -am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ -am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ -am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ @@ -186,6 +195,7 @@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ +builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ @@ -213,19 +223,27 @@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ sysconfdir = @sysconfdir@ -target = @target@ target_alias = @target_alias@ -target_cpu = @target_cpu@ -target_os = @target_os@ -target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ NULL = INCLUDES = -I$(top_srcdir)/include lib_LTLIBRARIES = libpam.la -noinst_HEADERS = openpam_impl.h +noinst_HEADERS = \ + openpam_constants.h \ + openpam_debug.h \ + openpam_impl.h \ + openpam_strlcmp.h \ + openpam_strlcpy.h + libpam_la_SOURCES = \ openpam_borrow_cred.c \ + openpam_check_owner_perms.c \ openpam_configure.c \ + openpam_constants.c \ openpam_dispatch.c \ openpam_dynamic.c \ openpam_findenv.c \ @@ -239,6 +257,7 @@ libpam_la_SOURCES = \ openpam_restore_cred.c \ openpam_set_option.c \ openpam_static.c \ + openpam_subst.c \ openpam_ttyconv.c \ pam_acct_mgmt.c \ pam_authenticate.c \ @@ -267,8 +286,8 @@ libpam_la_SOURCES = \ pam_vprompt.c \ $(NULL) -libpam_la_CFLAGS = -DOPENPAM_MODULES_DIR='"@OPENPAM_MODULES_DIR@/"' -libpam_la_LDFLAGS = -no-undefined -version-info @LIB_MAJ@ @DL_LIBS@ +libpam_la_LDFLAGS = -no-undefined -version-info @LIB_MAJ@ +libpam_la_LIBADD = @DL_LIBS@ EXTRA_DIST = \ pam_authenticate_secondary.c \ pam_get_mapped_authtok.c \ @@ -296,14 +315,14 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign lib/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --foreign lib/Makefile + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign lib/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign lib/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ @@ -321,23 +340,28 @@ $(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): install-libLTLIBRARIES: $(lib_LTLIBRARIES) @$(NORMAL_INSTALL) - test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)" - @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + list2=; for p in $$list; do \ if test -f $$p; then \ - f=$(am__strip_dir) \ - echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ - $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + list2="$$list2 $$p"; \ else :; fi; \ - done + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ + } uninstall-libLTLIBRARIES: @$(NORMAL_UNINSTALL) - @set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \ - p=$(am__strip_dir) \ - echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ - $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ done clean-libLTLIBRARIES: @@ -349,7 +373,7 @@ clean-libLTLIBRARIES: rm -f "$${dir}/so_locations"; \ done libpam.la: $(libpam_la_OBJECTS) $(libpam_la_DEPENDENCIES) - $(LINK) -rpath $(libdir) $(libpam_la_LDFLAGS) $(libpam_la_OBJECTS) $(libpam_la_LIBADD) $(LIBS) + $(libpam_la_LINK) -rpath $(libdir) $(libpam_la_OBJECTS) $(libpam_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -357,438 +381,157 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_borrow_cred.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_configure.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_dispatch.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_dynamic.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_findenv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_free_data.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_free_envlist.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_get_option.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_load.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_log.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_nullconv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_readline.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_restore_cred.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_set_option.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_static.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-openpam_ttyconv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_acct_mgmt.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_authenticate.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_chauthtok.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_close_session.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_end.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_error.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_get_authtok.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_get_data.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_get_item.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_get_user.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_getenv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_getenvlist.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_info.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_open_session.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_prompt.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_putenv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_set_data.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_set_item.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_setcred.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_setenv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_start.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_strerror.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_verror.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_vinfo.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpam_la-pam_vprompt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_borrow_cred.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_check_owner_perms.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_configure.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_constants.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_dispatch.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_dynamic.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_findenv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_free_data.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_free_envlist.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_get_option.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_load.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_log.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_nullconv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_readline.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_restore_cred.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_set_option.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_static.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_subst.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openpam_ttyconv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_acct_mgmt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_authenticate.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_chauthtok.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_close_session.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_end.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_error.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_get_authtok.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_get_data.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_get_item.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_get_user.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_getenv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_getenvlist.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_info.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_open_session.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_prompt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_putenv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_set_data.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_set_item.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_setcred.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_setenv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_start.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_strerror.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_verror.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_vinfo.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_vprompt.Plo@am__quote@ .c.o: -@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: -@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: -@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< -libpam_la-openpam_borrow_cred.lo: openpam_borrow_cred.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_borrow_cred.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_borrow_cred.Tpo" -c -o libpam_la-openpam_borrow_cred.lo `test -f 'openpam_borrow_cred.c' || echo '$(srcdir)/'`openpam_borrow_cred.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_borrow_cred.Tpo" "$(DEPDIR)/libpam_la-openpam_borrow_cred.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_borrow_cred.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_borrow_cred.c' object='libpam_la-openpam_borrow_cred.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_borrow_cred.lo `test -f 'openpam_borrow_cred.c' || echo '$(srcdir)/'`openpam_borrow_cred.c - -libpam_la-openpam_configure.lo: openpam_configure.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_configure.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_configure.Tpo" -c -o libpam_la-openpam_configure.lo `test -f 'openpam_configure.c' || echo '$(srcdir)/'`openpam_configure.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_configure.Tpo" "$(DEPDIR)/libpam_la-openpam_configure.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_configure.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_configure.c' object='libpam_la-openpam_configure.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_configure.lo `test -f 'openpam_configure.c' || echo '$(srcdir)/'`openpam_configure.c - -libpam_la-openpam_dispatch.lo: openpam_dispatch.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_dispatch.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_dispatch.Tpo" -c -o libpam_la-openpam_dispatch.lo `test -f 'openpam_dispatch.c' || echo '$(srcdir)/'`openpam_dispatch.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_dispatch.Tpo" "$(DEPDIR)/libpam_la-openpam_dispatch.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_dispatch.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_dispatch.c' object='libpam_la-openpam_dispatch.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_dispatch.lo `test -f 'openpam_dispatch.c' || echo '$(srcdir)/'`openpam_dispatch.c - -libpam_la-openpam_dynamic.lo: openpam_dynamic.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_dynamic.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_dynamic.Tpo" -c -o libpam_la-openpam_dynamic.lo `test -f 'openpam_dynamic.c' || echo '$(srcdir)/'`openpam_dynamic.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_dynamic.Tpo" "$(DEPDIR)/libpam_la-openpam_dynamic.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_dynamic.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_dynamic.c' object='libpam_la-openpam_dynamic.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_dynamic.lo `test -f 'openpam_dynamic.c' || echo '$(srcdir)/'`openpam_dynamic.c - -libpam_la-openpam_findenv.lo: openpam_findenv.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_findenv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_findenv.Tpo" -c -o libpam_la-openpam_findenv.lo `test -f 'openpam_findenv.c' || echo '$(srcdir)/'`openpam_findenv.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_findenv.Tpo" "$(DEPDIR)/libpam_la-openpam_findenv.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_findenv.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_findenv.c' object='libpam_la-openpam_findenv.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_findenv.lo `test -f 'openpam_findenv.c' || echo '$(srcdir)/'`openpam_findenv.c - -libpam_la-openpam_free_data.lo: openpam_free_data.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_free_data.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_free_data.Tpo" -c -o libpam_la-openpam_free_data.lo `test -f 'openpam_free_data.c' || echo '$(srcdir)/'`openpam_free_data.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_free_data.Tpo" "$(DEPDIR)/libpam_la-openpam_free_data.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_free_data.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_free_data.c' object='libpam_la-openpam_free_data.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_free_data.lo `test -f 'openpam_free_data.c' || echo '$(srcdir)/'`openpam_free_data.c - -libpam_la-openpam_free_envlist.lo: openpam_free_envlist.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_free_envlist.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_free_envlist.Tpo" -c -o libpam_la-openpam_free_envlist.lo `test -f 'openpam_free_envlist.c' || echo '$(srcdir)/'`openpam_free_envlist.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_free_envlist.Tpo" "$(DEPDIR)/libpam_la-openpam_free_envlist.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_free_envlist.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_free_envlist.c' object='libpam_la-openpam_free_envlist.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_free_envlist.lo `test -f 'openpam_free_envlist.c' || echo '$(srcdir)/'`openpam_free_envlist.c - -libpam_la-openpam_get_option.lo: openpam_get_option.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_get_option.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_get_option.Tpo" -c -o libpam_la-openpam_get_option.lo `test -f 'openpam_get_option.c' || echo '$(srcdir)/'`openpam_get_option.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_get_option.Tpo" "$(DEPDIR)/libpam_la-openpam_get_option.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_get_option.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_get_option.c' object='libpam_la-openpam_get_option.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_get_option.lo `test -f 'openpam_get_option.c' || echo '$(srcdir)/'`openpam_get_option.c - -libpam_la-openpam_load.lo: openpam_load.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_load.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_load.Tpo" -c -o libpam_la-openpam_load.lo `test -f 'openpam_load.c' || echo '$(srcdir)/'`openpam_load.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_load.Tpo" "$(DEPDIR)/libpam_la-openpam_load.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_load.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_load.c' object='libpam_la-openpam_load.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_load.lo `test -f 'openpam_load.c' || echo '$(srcdir)/'`openpam_load.c - -libpam_la-openpam_log.lo: openpam_log.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_log.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_log.Tpo" -c -o libpam_la-openpam_log.lo `test -f 'openpam_log.c' || echo '$(srcdir)/'`openpam_log.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_log.Tpo" "$(DEPDIR)/libpam_la-openpam_log.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_log.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_log.c' object='libpam_la-openpam_log.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_log.lo `test -f 'openpam_log.c' || echo '$(srcdir)/'`openpam_log.c - -libpam_la-openpam_nullconv.lo: openpam_nullconv.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_nullconv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_nullconv.Tpo" -c -o libpam_la-openpam_nullconv.lo `test -f 'openpam_nullconv.c' || echo '$(srcdir)/'`openpam_nullconv.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_nullconv.Tpo" "$(DEPDIR)/libpam_la-openpam_nullconv.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_nullconv.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_nullconv.c' object='libpam_la-openpam_nullconv.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_nullconv.lo `test -f 'openpam_nullconv.c' || echo '$(srcdir)/'`openpam_nullconv.c - -libpam_la-openpam_readline.lo: openpam_readline.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_readline.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_readline.Tpo" -c -o libpam_la-openpam_readline.lo `test -f 'openpam_readline.c' || echo '$(srcdir)/'`openpam_readline.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_readline.Tpo" "$(DEPDIR)/libpam_la-openpam_readline.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_readline.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_readline.c' object='libpam_la-openpam_readline.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_readline.lo `test -f 'openpam_readline.c' || echo '$(srcdir)/'`openpam_readline.c - -libpam_la-openpam_restore_cred.lo: openpam_restore_cred.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_restore_cred.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_restore_cred.Tpo" -c -o libpam_la-openpam_restore_cred.lo `test -f 'openpam_restore_cred.c' || echo '$(srcdir)/'`openpam_restore_cred.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_restore_cred.Tpo" "$(DEPDIR)/libpam_la-openpam_restore_cred.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_restore_cred.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_restore_cred.c' object='libpam_la-openpam_restore_cred.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_restore_cred.lo `test -f 'openpam_restore_cred.c' || echo '$(srcdir)/'`openpam_restore_cred.c - -libpam_la-openpam_set_option.lo: openpam_set_option.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_set_option.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_set_option.Tpo" -c -o libpam_la-openpam_set_option.lo `test -f 'openpam_set_option.c' || echo '$(srcdir)/'`openpam_set_option.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_set_option.Tpo" "$(DEPDIR)/libpam_la-openpam_set_option.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_set_option.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_set_option.c' object='libpam_la-openpam_set_option.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_set_option.lo `test -f 'openpam_set_option.c' || echo '$(srcdir)/'`openpam_set_option.c - -libpam_la-openpam_static.lo: openpam_static.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_static.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_static.Tpo" -c -o libpam_la-openpam_static.lo `test -f 'openpam_static.c' || echo '$(srcdir)/'`openpam_static.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_static.Tpo" "$(DEPDIR)/libpam_la-openpam_static.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_static.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_static.c' object='libpam_la-openpam_static.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_static.lo `test -f 'openpam_static.c' || echo '$(srcdir)/'`openpam_static.c - -libpam_la-openpam_ttyconv.lo: openpam_ttyconv.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-openpam_ttyconv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-openpam_ttyconv.Tpo" -c -o libpam_la-openpam_ttyconv.lo `test -f 'openpam_ttyconv.c' || echo '$(srcdir)/'`openpam_ttyconv.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-openpam_ttyconv.Tpo" "$(DEPDIR)/libpam_la-openpam_ttyconv.Plo"; else rm -f "$(DEPDIR)/libpam_la-openpam_ttyconv.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='openpam_ttyconv.c' object='libpam_la-openpam_ttyconv.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-openpam_ttyconv.lo `test -f 'openpam_ttyconv.c' || echo '$(srcdir)/'`openpam_ttyconv.c - -libpam_la-pam_acct_mgmt.lo: pam_acct_mgmt.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_acct_mgmt.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_acct_mgmt.Tpo" -c -o libpam_la-pam_acct_mgmt.lo `test -f 'pam_acct_mgmt.c' || echo '$(srcdir)/'`pam_acct_mgmt.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_acct_mgmt.Tpo" "$(DEPDIR)/libpam_la-pam_acct_mgmt.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_acct_mgmt.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_acct_mgmt.c' object='libpam_la-pam_acct_mgmt.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_acct_mgmt.lo `test -f 'pam_acct_mgmt.c' || echo '$(srcdir)/'`pam_acct_mgmt.c - -libpam_la-pam_authenticate.lo: pam_authenticate.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_authenticate.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_authenticate.Tpo" -c -o libpam_la-pam_authenticate.lo `test -f 'pam_authenticate.c' || echo '$(srcdir)/'`pam_authenticate.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_authenticate.Tpo" "$(DEPDIR)/libpam_la-pam_authenticate.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_authenticate.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_authenticate.c' object='libpam_la-pam_authenticate.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_authenticate.lo `test -f 'pam_authenticate.c' || echo '$(srcdir)/'`pam_authenticate.c - -libpam_la-pam_chauthtok.lo: pam_chauthtok.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_chauthtok.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_chauthtok.Tpo" -c -o libpam_la-pam_chauthtok.lo `test -f 'pam_chauthtok.c' || echo '$(srcdir)/'`pam_chauthtok.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_chauthtok.Tpo" "$(DEPDIR)/libpam_la-pam_chauthtok.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_chauthtok.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_chauthtok.c' object='libpam_la-pam_chauthtok.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_chauthtok.lo `test -f 'pam_chauthtok.c' || echo '$(srcdir)/'`pam_chauthtok.c - -libpam_la-pam_close_session.lo: pam_close_session.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_close_session.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_close_session.Tpo" -c -o libpam_la-pam_close_session.lo `test -f 'pam_close_session.c' || echo '$(srcdir)/'`pam_close_session.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_close_session.Tpo" "$(DEPDIR)/libpam_la-pam_close_session.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_close_session.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_close_session.c' object='libpam_la-pam_close_session.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_close_session.lo `test -f 'pam_close_session.c' || echo '$(srcdir)/'`pam_close_session.c - -libpam_la-pam_end.lo: pam_end.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_end.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_end.Tpo" -c -o libpam_la-pam_end.lo `test -f 'pam_end.c' || echo '$(srcdir)/'`pam_end.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_end.Tpo" "$(DEPDIR)/libpam_la-pam_end.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_end.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_end.c' object='libpam_la-pam_end.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_end.lo `test -f 'pam_end.c' || echo '$(srcdir)/'`pam_end.c - -libpam_la-pam_error.lo: pam_error.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_error.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_error.Tpo" -c -o libpam_la-pam_error.lo `test -f 'pam_error.c' || echo '$(srcdir)/'`pam_error.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_error.Tpo" "$(DEPDIR)/libpam_la-pam_error.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_error.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_error.c' object='libpam_la-pam_error.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_error.lo `test -f 'pam_error.c' || echo '$(srcdir)/'`pam_error.c - -libpam_la-pam_get_authtok.lo: pam_get_authtok.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_get_authtok.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_get_authtok.Tpo" -c -o libpam_la-pam_get_authtok.lo `test -f 'pam_get_authtok.c' || echo '$(srcdir)/'`pam_get_authtok.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_get_authtok.Tpo" "$(DEPDIR)/libpam_la-pam_get_authtok.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_get_authtok.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_get_authtok.c' object='libpam_la-pam_get_authtok.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_get_authtok.lo `test -f 'pam_get_authtok.c' || echo '$(srcdir)/'`pam_get_authtok.c - -libpam_la-pam_get_data.lo: pam_get_data.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_get_data.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_get_data.Tpo" -c -o libpam_la-pam_get_data.lo `test -f 'pam_get_data.c' || echo '$(srcdir)/'`pam_get_data.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_get_data.Tpo" "$(DEPDIR)/libpam_la-pam_get_data.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_get_data.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_get_data.c' object='libpam_la-pam_get_data.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_get_data.lo `test -f 'pam_get_data.c' || echo '$(srcdir)/'`pam_get_data.c - -libpam_la-pam_get_item.lo: pam_get_item.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_get_item.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_get_item.Tpo" -c -o libpam_la-pam_get_item.lo `test -f 'pam_get_item.c' || echo '$(srcdir)/'`pam_get_item.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_get_item.Tpo" "$(DEPDIR)/libpam_la-pam_get_item.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_get_item.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_get_item.c' object='libpam_la-pam_get_item.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_get_item.lo `test -f 'pam_get_item.c' || echo '$(srcdir)/'`pam_get_item.c - -libpam_la-pam_get_user.lo: pam_get_user.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_get_user.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_get_user.Tpo" -c -o libpam_la-pam_get_user.lo `test -f 'pam_get_user.c' || echo '$(srcdir)/'`pam_get_user.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_get_user.Tpo" "$(DEPDIR)/libpam_la-pam_get_user.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_get_user.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_get_user.c' object='libpam_la-pam_get_user.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_get_user.lo `test -f 'pam_get_user.c' || echo '$(srcdir)/'`pam_get_user.c - -libpam_la-pam_getenv.lo: pam_getenv.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_getenv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_getenv.Tpo" -c -o libpam_la-pam_getenv.lo `test -f 'pam_getenv.c' || echo '$(srcdir)/'`pam_getenv.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_getenv.Tpo" "$(DEPDIR)/libpam_la-pam_getenv.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_getenv.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_getenv.c' object='libpam_la-pam_getenv.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_getenv.lo `test -f 'pam_getenv.c' || echo '$(srcdir)/'`pam_getenv.c - -libpam_la-pam_getenvlist.lo: pam_getenvlist.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_getenvlist.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_getenvlist.Tpo" -c -o libpam_la-pam_getenvlist.lo `test -f 'pam_getenvlist.c' || echo '$(srcdir)/'`pam_getenvlist.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_getenvlist.Tpo" "$(DEPDIR)/libpam_la-pam_getenvlist.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_getenvlist.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_getenvlist.c' object='libpam_la-pam_getenvlist.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_getenvlist.lo `test -f 'pam_getenvlist.c' || echo '$(srcdir)/'`pam_getenvlist.c - -libpam_la-pam_info.lo: pam_info.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_info.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_info.Tpo" -c -o libpam_la-pam_info.lo `test -f 'pam_info.c' || echo '$(srcdir)/'`pam_info.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_info.Tpo" "$(DEPDIR)/libpam_la-pam_info.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_info.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_info.c' object='libpam_la-pam_info.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_info.lo `test -f 'pam_info.c' || echo '$(srcdir)/'`pam_info.c - -libpam_la-pam_open_session.lo: pam_open_session.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_open_session.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_open_session.Tpo" -c -o libpam_la-pam_open_session.lo `test -f 'pam_open_session.c' || echo '$(srcdir)/'`pam_open_session.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_open_session.Tpo" "$(DEPDIR)/libpam_la-pam_open_session.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_open_session.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_open_session.c' object='libpam_la-pam_open_session.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_open_session.lo `test -f 'pam_open_session.c' || echo '$(srcdir)/'`pam_open_session.c - -libpam_la-pam_prompt.lo: pam_prompt.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_prompt.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_prompt.Tpo" -c -o libpam_la-pam_prompt.lo `test -f 'pam_prompt.c' || echo '$(srcdir)/'`pam_prompt.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_prompt.Tpo" "$(DEPDIR)/libpam_la-pam_prompt.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_prompt.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_prompt.c' object='libpam_la-pam_prompt.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_prompt.lo `test -f 'pam_prompt.c' || echo '$(srcdir)/'`pam_prompt.c - -libpam_la-pam_putenv.lo: pam_putenv.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_putenv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_putenv.Tpo" -c -o libpam_la-pam_putenv.lo `test -f 'pam_putenv.c' || echo '$(srcdir)/'`pam_putenv.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_putenv.Tpo" "$(DEPDIR)/libpam_la-pam_putenv.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_putenv.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_putenv.c' object='libpam_la-pam_putenv.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_putenv.lo `test -f 'pam_putenv.c' || echo '$(srcdir)/'`pam_putenv.c - -libpam_la-pam_set_data.lo: pam_set_data.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_set_data.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_set_data.Tpo" -c -o libpam_la-pam_set_data.lo `test -f 'pam_set_data.c' || echo '$(srcdir)/'`pam_set_data.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_set_data.Tpo" "$(DEPDIR)/libpam_la-pam_set_data.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_set_data.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_set_data.c' object='libpam_la-pam_set_data.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_set_data.lo `test -f 'pam_set_data.c' || echo '$(srcdir)/'`pam_set_data.c - -libpam_la-pam_set_item.lo: pam_set_item.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_set_item.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_set_item.Tpo" -c -o libpam_la-pam_set_item.lo `test -f 'pam_set_item.c' || echo '$(srcdir)/'`pam_set_item.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_set_item.Tpo" "$(DEPDIR)/libpam_la-pam_set_item.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_set_item.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_set_item.c' object='libpam_la-pam_set_item.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_set_item.lo `test -f 'pam_set_item.c' || echo '$(srcdir)/'`pam_set_item.c - -libpam_la-pam_setcred.lo: pam_setcred.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_setcred.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_setcred.Tpo" -c -o libpam_la-pam_setcred.lo `test -f 'pam_setcred.c' || echo '$(srcdir)/'`pam_setcred.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_setcred.Tpo" "$(DEPDIR)/libpam_la-pam_setcred.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_setcred.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_setcred.c' object='libpam_la-pam_setcred.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_setcred.lo `test -f 'pam_setcred.c' || echo '$(srcdir)/'`pam_setcred.c - -libpam_la-pam_setenv.lo: pam_setenv.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_setenv.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_setenv.Tpo" -c -o libpam_la-pam_setenv.lo `test -f 'pam_setenv.c' || echo '$(srcdir)/'`pam_setenv.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_setenv.Tpo" "$(DEPDIR)/libpam_la-pam_setenv.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_setenv.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_setenv.c' object='libpam_la-pam_setenv.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_setenv.lo `test -f 'pam_setenv.c' || echo '$(srcdir)/'`pam_setenv.c - -libpam_la-pam_start.lo: pam_start.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_start.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_start.Tpo" -c -o libpam_la-pam_start.lo `test -f 'pam_start.c' || echo '$(srcdir)/'`pam_start.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_start.Tpo" "$(DEPDIR)/libpam_la-pam_start.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_start.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_start.c' object='libpam_la-pam_start.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_start.lo `test -f 'pam_start.c' || echo '$(srcdir)/'`pam_start.c - -libpam_la-pam_strerror.lo: pam_strerror.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_strerror.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_strerror.Tpo" -c -o libpam_la-pam_strerror.lo `test -f 'pam_strerror.c' || echo '$(srcdir)/'`pam_strerror.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_strerror.Tpo" "$(DEPDIR)/libpam_la-pam_strerror.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_strerror.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_strerror.c' object='libpam_la-pam_strerror.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_strerror.lo `test -f 'pam_strerror.c' || echo '$(srcdir)/'`pam_strerror.c - -libpam_la-pam_verror.lo: pam_verror.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_verror.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_verror.Tpo" -c -o libpam_la-pam_verror.lo `test -f 'pam_verror.c' || echo '$(srcdir)/'`pam_verror.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_verror.Tpo" "$(DEPDIR)/libpam_la-pam_verror.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_verror.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_verror.c' object='libpam_la-pam_verror.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_verror.lo `test -f 'pam_verror.c' || echo '$(srcdir)/'`pam_verror.c - -libpam_la-pam_vinfo.lo: pam_vinfo.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_vinfo.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_vinfo.Tpo" -c -o libpam_la-pam_vinfo.lo `test -f 'pam_vinfo.c' || echo '$(srcdir)/'`pam_vinfo.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_vinfo.Tpo" "$(DEPDIR)/libpam_la-pam_vinfo.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_vinfo.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_vinfo.c' object='libpam_la-pam_vinfo.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_vinfo.lo `test -f 'pam_vinfo.c' || echo '$(srcdir)/'`pam_vinfo.c - -libpam_la-pam_vprompt.lo: pam_vprompt.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -MT libpam_la-pam_vprompt.lo -MD -MP -MF "$(DEPDIR)/libpam_la-pam_vprompt.Tpo" -c -o libpam_la-pam_vprompt.lo `test -f 'pam_vprompt.c' || echo '$(srcdir)/'`pam_vprompt.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libpam_la-pam_vprompt.Tpo" "$(DEPDIR)/libpam_la-pam_vprompt.Plo"; else rm -f "$(DEPDIR)/libpam_la-pam_vprompt.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pam_vprompt.c' object='libpam_la-pam_vprompt.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpam_la_CFLAGS) $(CFLAGS) -c -o libpam_la-pam_vprompt.lo `test -f 'pam_vprompt.c' || echo '$(srcdir)/'`pam_vprompt.c - mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs -distclean-libtool: - -rm -f libtool -uninstall-info-am: - ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) - tags=; \ + set x; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique + $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ - list='$(DISTFILES)'; for file in $$list; do \ - case $$file in \ - $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ - $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ - esac; \ + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test "$$dir" != "$$file" && test "$$dir" != "."; then \ - dir="/$$dir"; \ - $(mkdir_p) "$(distdir)$$dir"; \ - else \ - dir=''; \ - fi; \ if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done @@ -797,7 +540,7 @@ check: check-am all-am: Makefile $(LTLIBRARIES) $(HEADERS) installdirs: for dir in "$(DESTDIR)$(libdir)"; do \ - test -z "$$dir" || $(mkdir_p) "$$dir"; \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am @@ -819,6 +562,7 @@ clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @@ -832,7 +576,7 @@ distclean: distclean-am -rm -rf ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ - distclean-libtool distclean-tags + distclean-tags dvi: dvi-am @@ -840,18 +584,38 @@ dvi-am: html: html-am +html-am: + info: info-am info-am: install-data-am: +install-dvi: install-dvi-am + +install-dvi-am: + install-exec-am: install-libLTLIBRARIES +install-html: install-html-am + +install-html-am: + install-info: install-info-am +install-info-am: + install-man: +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + installcheck-am: maintainer-clean: maintainer-clean-am @@ -872,20 +636,24 @@ ps: ps-am ps-am: -uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES +uninstall-am: uninstall-libLTLIBRARIES + +.MAKE: install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ clean-libLTLIBRARIES clean-libtool ctags distclean \ distclean-compile distclean-generic distclean-libtool \ distclean-tags distdir dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am install-exec \ - install-exec-am install-info install-info-am \ - install-libLTLIBRARIES install-man install-strip installcheck \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am \ + install-libLTLIBRARIES install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags uninstall uninstall-am uninstall-info-am \ - uninstall-libLTLIBRARIES + tags uninstall uninstall-am uninstall-libLTLIBRARIES + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/lib/openpam_borrow_cred.c b/lib/openpam_borrow_cred.c index 79a349f..e0dfc55 100644 --- a/lib/openpam_borrow_cred.c +++ b/lib/openpam_borrow_cred.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_borrow_cred.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_borrow_cred.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/openpam_check_owner_perms.c b/lib/openpam_check_owner_perms.c new file mode 100644 index 0000000..67cedc0 --- /dev/null +++ b/lib/openpam_check_owner_perms.c @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 2011 Dag-Erling Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_check_owner_perms.c 499 2011-11-22 11:51:50Z des $ + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "openpam_impl.h" + +/* + * OpenPAM internal + * + * Verify that the file or directory referenced by the given descriptor is + * owned by either root or the arbitrator and that it is not writable by + * group or other. + */ + +int +openpam_check_desc_owner_perms(const char *name, int fd) +{ + uid_t root, arbitrator; + struct stat sb; + int serrno; + + root = 0; + arbitrator = geteuid(); + if (fstat(fd, &sb) != 0) { + serrno = errno; + openpam_log(PAM_LOG_ERROR, "%s: %m", name); + errno = serrno; + return (-1); + } + if ((sb.st_uid != root && sb.st_uid != arbitrator) || + (sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) { + openpam_log(PAM_LOG_ERROR, + "%s: insecure ownership or permissions", name); + errno = EPERM; + return (-1); + } + return (0); +} + +/* + * OpenPAM internal + * + * Verify that a file or directory and all components of the path leading + * up to it are owned by either root or the arbitrator and that they are + * not writable by group or other. + * + * Note that openpam_check_file_owner_perms() should be used instead if + * possible to avoid a race between the ownership / permission check and + * the actual open(). + */ + +int +openpam_check_path_owner_perms(const char *path) +{ + uid_t root, arbitrator; + char pathbuf[PATH_MAX]; + struct stat sb; + int len, serrno; + + root = 0; + arbitrator = geteuid(); + if (realpath(path, pathbuf) == NULL) + return (-1); + len = strlen(pathbuf); + while (len > 0) { + if (stat(pathbuf, &sb) != 0) { + serrno = errno; + openpam_log(PAM_LOG_ERROR, "%s: %m", pathbuf); + errno = serrno; + return (-1); + } + if ((sb.st_uid != root && sb.st_uid != arbitrator) || + (sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) { + openpam_log(PAM_LOG_ERROR, + "%s: insecure ownership or permissions", pathbuf); + errno = EPERM; + return (-1); + } + while (--len > 0 && pathbuf[len] != '/') + pathbuf[len] = '\0'; + } + return (0); +} + +/* + * NOPARSE + */ diff --git a/lib/openpam_configure.c b/lib/openpam_configure.c index f9197ad..d395565 100644 --- a/lib/openpam_configure.c +++ b/lib/openpam_configure.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2001-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_configure.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_configure.c 500 2011-11-22 12:07:03Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -44,80 +48,301 @@ #include #include "openpam_impl.h" +#include "openpam_strlcmp.h" -const char *_pam_facility_name[PAM_NUM_FACILITIES] = { - [PAM_ACCOUNT] = "account", - [PAM_AUTH] = "auth", - [PAM_PASSWORD] = "password", - [PAM_SESSION] = "session", -}; +static int openpam_load_chain(pam_handle_t *, const char *, pam_facility_t); -const char *_pam_control_flag_name[PAM_NUM_CONTROL_FLAGS] = { - [PAM_BINDING] = "binding", - [PAM_OPTIONAL] = "optional", - [PAM_REQUIRED] = "required", - [PAM_REQUISITE] = "requisite", - [PAM_SUFFICIENT] = "sufficient", -}; +/* + * Evaluates to non-zero if the argument is a linear whitespace character. + */ +#define is_lws(ch) \ + (ch == ' ' || ch == '\t') -static int openpam_load_chain(pam_handle_t *, const char *, pam_facility_t); +/* + * Evaluates to non-zero if the argument is a printable ASCII character. + * Assumes that the execution character set is a superset of ASCII. + */ +#define is_p(ch) \ + (ch >= '!' && ch <= '~') + +/* + * Returns non-zero if the argument belongs to the POSIX Portable Filename + * Character Set. Assumes that the execution character set is a superset + * of ASCII. + */ +#define is_pfcs(ch) \ + ((ch >= '0' && ch <= '9') || \ + (ch >= 'A' && ch <= 'Z') || \ + (ch >= 'a' && ch <= 'z') || \ + ch == '.' || ch == '_' || ch == '-') /* - * Matches a word against the first one in a string. - * Returns non-zero if they match. + * Parse the service name. + * + * Returns the length of the service name, or 0 if the end of the string + * was reached or a disallowed non-whitespace character was encountered. + * + * If parse_service_name() is successful, it updates *service to point to + * the first character of the service name and *line to point one + * character past the end. If it reaches the end of the string, it + * updates *line to point to the terminating NUL character and leaves + * *service unmodified. In all other cases, it leaves both *line and + * *service unmodified. + * + * Allowed characters are all characters in the POSIX portable filename + * character set. */ static int -match_word(const char *str, const char *word) +parse_service_name(char **line, char **service) { + char *b, *e; - while (*str && tolower(*str) == tolower(*word)) - ++str, ++word; - return (*str == ' ' && *word == '\0'); + for (b = *line; *b && is_lws(*b); ++b) + /* nothing */ ; + if (!*b) { + *line = b; + return (0); + } + for (e = b; *e && !is_lws(*e); ++e) + if (!is_pfcs(*e)) + return (0); + if (e == b) + return (0); + *line = e; + *service = b; + return (e - b); } /* - * Return a pointer to the next word (or the final NUL) in a string. + * Parse the facility name. + * + * Returns the corresponding pam_facility_t value, or -1 if the end of the + * string was reached, a disallowed non-whitespace character was + * encountered, or the first word was not a recognized facility name. + * + * If parse_facility_name() is successful, it updates *line to point one + * character past the end of the facility name. If it reaches the end of + * the string, it updates *line to point to the terminating NUL character. + * In all other cases, it leaves *line unmodified. */ -static const char * -next_word(const char *str) +static pam_facility_t +parse_facility_name(char **line) { + char *b, *e; + int i; - /* skip current word */ - while (*str && *str != ' ') - ++str; - /* skip whitespace */ - while (*str == ' ') - ++str; - return (str); + for (b = *line; *b && is_lws(*b); ++b) + /* nothing */ ; + if (!*b) { + *line = b; + return ((pam_facility_t)-1); + } + for (e = b; *e && !is_lws(*e); ++e) + /* nothing */ ; + if (e == b) + return ((pam_facility_t)-1); + for (i = 0; i < PAM_NUM_FACILITIES; ++i) + if (strlcmp(pam_facility_name[i], b, e - b) == 0) + break; + if (i == PAM_NUM_FACILITIES) + return ((pam_facility_t)-1); + *line = e; + return (i); } /* - * Return a malloc()ed copy of the first word in a string. + * Parse the word "include". + * + * If the next word on the line is "include", parse_include() updates + * *line to point one character past "include" and returns 1. Otherwise, + * it leaves *line unmodified and returns 0. + */ +static int +parse_include(char **line) +{ + char *b, *e; + + for (b = *line; *b && is_lws(*b); ++b) + /* nothing */ ; + if (!*b) { + *line = b; + return (-1); + } + for (e = b; *e && !is_lws(*e); ++e) + /* nothing */ ; + if (e == b) + return (0); + if (strlcmp("include", b, e - b) != 0) + return (0); + *line = e; + return (1); +} + +/* + * Parse the control flag. + * + * Returns the corresponding pam_control_t value, or -1 if the end of the + * string was reached, a disallowed non-whitespace character was + * encountered, or the first word was not a recognized control flag. + * + * If parse_control_flag() is successful, it updates *line to point one + * character past the end of the control flag. If it reaches the end of + * the string, it updates *line to point to the terminating NUL character. + * In all other cases, it leaves *line unmodified. + */ +static pam_control_t +parse_control_flag(char **line) +{ + char *b, *e; + int i; + + for (b = *line; *b && is_lws(*b); ++b) + /* nothing */ ; + if (!*b) { + *line = b; + return ((pam_control_t)-1); + } + for (e = b; *e && !is_lws(*e); ++e) + /* nothing */ ; + if (e == b) + return ((pam_control_t)-1); + for (i = 0; i < PAM_NUM_CONTROL_FLAGS; ++i) + if (strlcmp(pam_control_flag_name[i], b, e - b) == 0) + break; + if (i == PAM_NUM_CONTROL_FLAGS) + return ((pam_control_t)-1); + *line = e; + return (i); +} + +/* + * Parse a file name. + * + * Returns the length of the file name, or 0 if the end of the string was + * reached or a disallowed non-whitespace character was encountered. + * + * If parse_filename() is successful, it updates *filename to point to the + * first character of the filename and *line to point one character past + * the end. If it reaches the end of the string, it updates *line to + * point to the terminating NUL character and leaves *filename unmodified. + * In all other cases, it leaves both *line and *filename unmodified. + * + * Allowed characters are all characters in the POSIX portable filename + * character set, plus the path separator (forward slash). + */ +static int +parse_filename(char **line, char **filename) +{ + char *b, *e; + + for (b = *line; *b && is_lws(*b); ++b) + /* nothing */ ; + if (!*b) { + *line = b; + return (0); + } + for (e = b; *e && !is_lws(*e); ++e) + if (!is_pfcs(*e) && *e != '/') + return (0); + if (e == b) + return (0); + *line = e; + *filename = b; + return (e - b); +} + +/* + * Parse an option. + * + * Returns a dynamically allocated string containing the next module + * option, or NULL if the end of the string was reached or a disallowed + * non-whitespace character was encountered. + * + * If parse_option() is successful, it updates *line to point one + * character past the end of the option. If it reaches the end of the + * string, it updates *line to point to the terminating NUL character. In + * all other cases, it leaves *line unmodified. + * + * If parse_option() fails to allocate memory, it will return NULL and set + * errno to a non-zero value. + * + * Allowed characters for option names are all characters in the POSIX + * portable filename character set. Allowed characters for option values + * are any printable non-whitespace characters. The option value may be + * quoted in either single or double quotes, in which case space + * characters and whichever quote character was not used are allowed. + * Note that the entire value must be quoted, not just part of it. */ static char * -dup_word(const char *str) +parse_option(char **line) { - const char *end; - char *word; + char *nb, *ne, *vb, *ve; + unsigned char q = 0; + char *option; + size_t size; - for (end = str; *end && *end != ' '; ++end) + errno = 0; + for (nb = *line; *nb && is_lws(*nb); ++nb) /* nothing */ ; - if (asprintf(&word, "%.*s", (int)(end - str), str) < 0) + if (!*nb) { + *line = nb; + return (NULL); + } + for (ne = nb; *ne && !is_lws(*ne) && *ne != '='; ++ne) + if (!is_pfcs(*ne)) + return (NULL); + if (ne == nb) + return (NULL); + if (*ne == '=') { + vb = ne + 1; + if (*vb == '"' || *vb == '\'') + q = *vb++; + for (ve = vb; + *ve && *ve != q && (is_p(*ve) || (q && is_lws(*ve))); + ++ve) + /* nothing */ ; + if (q && *ve != q) + /* non-printable character or missing endquote */ + return (NULL); + if (q && *(ve + 1) && !is_lws(*(ve + 1))) + /* garbage after value */ + return (NULL); + } else { + vb = ve = ne; + } + size = (ne - nb) + 1; + if (ve > vb) + size += (ve - vb) + 1; + if ((option = malloc(size)) == NULL) return (NULL); - return (word); + strncpy(option, nb, ne - nb); + if (ve > vb) { + option[ne - nb] = '='; + strncpy(option + (ne - nb) + 1, vb, ve - vb); + } + option[size - 1] = '\0'; + *line = q ? ve + 1 : ve; + return (option); } /* - * Return the length of the first word in a string. + * Consume trailing whitespace. + * + * If there are no non-whitespace characters left on the line, parse_eol() + * updates *line to point at the terminating NUL character and returns 0. + * Otherwise, it leaves *line unmodified and returns a non-zero value. */ static int -wordlen(const char *str) +parse_eol(char **line) { - int i; + char *p; - for (i = 0; str[i] && str[i] != ' '; ++i) + for (p = *line; *p && is_lws(*p); ++p) /* nothing */ ; - return (i); + if (*p) + return ((unsigned char)*p); + *line = p; + return (0); } typedef enum { pam_conf_style, pam_d_style } openpam_style_t; @@ -126,126 +351,139 @@ typedef enum { pam_conf_style, pam_d_style } openpam_style_t; * Extracts given chains from a policy file. */ static int -openpam_read_chain(pam_handle_t *pamh, +openpam_parse_chain(pam_handle_t *pamh, const char *service, pam_facility_t facility, const char *filename, openpam_style_t style) { pam_chain_t *this, **next; - const char *p, *q; - int count, i, lineno, ret; pam_facility_t fclt; pam_control_t ctlf; - char *line, *name; + char *line, *str, *name; + char *option, **optv; + int len, lineno, ret; FILE *f; if ((f = fopen(filename, "r")) == NULL) { openpam_log(errno == ENOENT ? PAM_LOG_DEBUG : PAM_LOG_NOTICE, "%s: %m", filename); - return (0); + return (PAM_SUCCESS); + } + if (openpam_check_desc_owner_perms(filename, fileno(f)) != 0) { + fclose(f); + return (PAM_SYSTEM_ERR); } this = NULL; - count = lineno = 0; + name = NULL; + lineno = 0; while ((line = openpam_readline(f, &lineno, NULL)) != NULL) { - p = line; - - /* match service name */ + /* get service name if necessary */ if (style == pam_conf_style) { - if (!match_word(p, service)) { + if ((len = parse_service_name(&line, &str)) == 0) { + openpam_log(PAM_LOG_NOTICE, + "%s(%d): invalid service name (ignored)", + filename, lineno); + FREE(line); + continue; + } + if (strlcmp(service, str, len) != 0) { FREE(line); continue; } - p = next_word(p); } - /* match facility name */ - for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt) - if (match_word(p, _pam_facility_name[fclt])) - break; - if (fclt == PAM_NUM_FACILITIES) { - openpam_log(PAM_LOG_NOTICE, - "%s(%d): invalid facility '%.*s' (ignored)", - filename, lineno, wordlen(p), p); + /* get facility name */ + if ((fclt = parse_facility_name(&line)) == (pam_facility_t)-1) { + openpam_log(PAM_LOG_ERROR, + "%s(%d): missing or invalid facility", + filename, lineno); goto fail; } if (facility != fclt && facility != PAM_FACILITY_ANY) { FREE(line); continue; } - p = next_word(p); - /* include other chain */ - if (match_word(p, "include")) { - p = next_word(p); - if (*next_word(p) != '\0') - openpam_log(PAM_LOG_NOTICE, - "%s(%d): garbage at end of 'include' line", + /* check for "include" */ + if (parse_include(&line)) { + if ((len = parse_service_name(&line, &str)) == 0) { + openpam_log(PAM_LOG_ERROR, + "%s(%d): missing or invalid filename", filename, lineno); - if ((name = dup_word(p)) == NULL) + goto fail; + } + if ((name = strndup(str, len)) == NULL) goto syserr; + if (parse_eol(&line) != 0) { + openpam_log(PAM_LOG_ERROR, + "%s(%d): garbage at end of line", + filename, lineno); + goto fail; + } ret = openpam_load_chain(pamh, name, fclt); FREE(name); - if (ret < 0) + if (ret != PAM_SUCCESS) goto fail; - count += ret; FREE(line); continue; } - /* allocate new entry */ - if ((this = calloc(1, sizeof *this)) == NULL) - goto syserr; + /* get control flag */ + if ((ctlf = parse_control_flag(&line)) == (pam_control_t)-1) { + openpam_log(PAM_LOG_ERROR, + "%s(%d): missing or invalid control flag", + filename, lineno); + goto fail; + } - /* control flag */ - for (ctlf = 0; ctlf < PAM_NUM_CONTROL_FLAGS; ++ctlf) - if (match_word(p, _pam_control_flag_name[ctlf])) - break; - if (ctlf == PAM_NUM_CONTROL_FLAGS) { + /* get module name */ + if ((len = parse_filename(&line, &str)) == 0) { openpam_log(PAM_LOG_ERROR, - "%s(%d): invalid control flag '%.*s'", - filename, lineno, wordlen(p), p); + "%s(%d): missing or invalid module name", + filename, lineno); goto fail; } + if ((name = strndup(str, len)) == NULL) + goto syserr; + + /* allocate new entry */ + if ((this = calloc(1, sizeof *this)) == NULL) + goto syserr; this->flag = ctlf; - /* module name */ - p = next_word(p); - if (*p == '\0') { + /* get module options */ + if ((this->optv = malloc(sizeof *optv)) == NULL) + goto syserr; + this->optc = 0; + while ((option = parse_option(&line)) != NULL) { + optv = realloc(this->optv, + (this->optc + 2) * sizeof *optv); + if (optv == NULL) + goto syserr; + this->optv = optv; + this->optv[this->optc++] = option; + } + this->optv[this->optc] = NULL; + if (*line != '\0') { openpam_log(PAM_LOG_ERROR, - "%s(%d): missing module name", + "%s(%d): syntax error in module options", filename, lineno); goto fail; } - if ((name = dup_word(p)) == NULL) - goto syserr; + + /* load module */ this->module = openpam_load_module(name); FREE(name); if (this->module == NULL) goto fail; - /* module options */ - p = q = next_word(p); - while (*q != '\0') { - ++this->optc; - q = next_word(q); - } - this->optv = calloc(this->optc + 1, sizeof(char *)); - if (this->optv == NULL) - goto syserr; - for (i = 0; i < this->optc; ++i) { - if ((this->optv[i] = dup_word(p)) == NULL) - goto syserr; - p = next_word(p); - } - /* hook it up */ for (next = &pamh->chains[fclt]; *next != NULL; next = &(*next)->next) /* nothing */ ; *next = this; this = NULL; - ++count; /* next please... */ FREE(line); @@ -253,14 +491,20 @@ openpam_read_chain(pam_handle_t *pamh, if (!feof(f)) goto syserr; fclose(f); - return (count); - syserr: + return (PAM_SUCCESS); +syserr: openpam_log(PAM_LOG_ERROR, "%s: %m", filename); - fail: +fail: + if (this && this->optc) { + while (this->optc--) + FREE(this->optv[this->optc]); + FREE(this->optv); + } FREE(this); FREE(line); + FREE(name); fclose(f); - return (-1); + return (PAM_SYSTEM_ERR); } static const char *openpam_policy_path[] = { @@ -283,26 +527,26 @@ openpam_load_chain(pam_handle_t *pamh, const char **path; char *filename; size_t len; - int r; + int ret; for (path = openpam_policy_path; *path != NULL; ++path) { len = strlen(*path); if ((*path)[len - 1] == '/') { if (asprintf(&filename, "%s%s", *path, service) < 0) { openpam_log(PAM_LOG_ERROR, "asprintf(): %m"); - return (-PAM_BUF_ERR); + return (PAM_BUF_ERR); } - r = openpam_read_chain(pamh, service, facility, + ret = openpam_parse_chain(pamh, service, facility, filename, pam_d_style); FREE(filename); } else { - r = openpam_read_chain(pamh, service, facility, + ret = openpam_parse_chain(pamh, service, facility, *path, pam_conf_style); } - if (r != 0) - return (r); + if (ret != PAM_SUCCESS) + return (ret); } - return (0); + return (PAM_SUCCESS); } /* @@ -316,18 +560,23 @@ openpam_configure(pam_handle_t *pamh, const char *service) { pam_facility_t fclt; + const char *p; + + for (p = service; *p; ++p) + if (!is_pfcs(*p)) + return (PAM_SYSTEM_ERR); - if (openpam_load_chain(pamh, service, PAM_FACILITY_ANY) < 0) + if (openpam_load_chain(pamh, service, PAM_FACILITY_ANY) != PAM_SUCCESS) goto load_err; for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt) { if (pamh->chains[fclt] != NULL) continue; - if (openpam_load_chain(pamh, PAM_OTHER, fclt) < 0) + if (openpam_load_chain(pamh, PAM_OTHER, fclt) != PAM_SUCCESS) goto load_err; } return (PAM_SUCCESS); - load_err: +load_err: openpam_clear_chains(pamh->chains); return (PAM_SYSTEM_ERR); } diff --git a/lib/openpam_constants.c b/lib/openpam_constants.c new file mode 100644 index 0000000..833e81f --- /dev/null +++ b/lib/openpam_constants.c @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 2001-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2011 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_constants.c 491 2011-11-12 00:12:32Z des $ + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "openpam_impl.h" + +const char *pam_err_name[PAM_NUM_ERRORS] = { + "PAM_SUCCESS", + "PAM_OPEN_ERR", + "PAM_SYMBOL_ERR", + "PAM_SERVICE_ERR", + "PAM_SYSTEM_ERR", + "PAM_BUF_ERR", + "PAM_CONV_ERR", + "PAM_PERM_DENIED", + "PAM_MAXTRIES", + "PAM_AUTH_ERR", + "PAM_NEW_AUTHTOK_REQD", + "PAM_CRED_INSUFFICIENT", + "PAM_AUTHINFO_UNAVAIL", + "PAM_USER_UNKNOWN", + "PAM_CRED_UNAVAIL", + "PAM_CRED_EXPIRED", + "PAM_CRED_ERR", + "PAM_ACCT_EXPIRED", + "PAM_AUTHTOK_EXPIRED", + "PAM_SESSION_ERR", + "PAM_AUTHTOK_ERR", + "PAM_AUTHTOK_RECOVERY_ERR", + "PAM_AUTHTOK_LOCK_BUSY", + "PAM_AUTHTOK_DISABLE_AGING", + "PAM_NO_MODULE_DATA", + "PAM_IGNORE", + "PAM_ABORT", + "PAM_TRY_AGAIN", + "PAM_MODULE_UNKNOWN", + "PAM_DOMAIN_UNKNOWN" +}; + +const char *pam_item_name[PAM_NUM_ITEMS] = { + "(NO ITEM)", + "PAM_SERVICE", + "PAM_USER", + "PAM_TTY", + "PAM_RHOST", + "PAM_CONV", + "PAM_AUTHTOK", + "PAM_OLDAUTHTOK", + "PAM_RUSER", + "PAM_USER_PROMPT", + "PAM_REPOSITORY", + "PAM_AUTHTOK_PROMPT", + "PAM_OLDAUTHTOK_PROMPT", + "PAM_HOST", +}; + +const char *pam_facility_name[PAM_NUM_FACILITIES] = { + [PAM_ACCOUNT] = "account", + [PAM_AUTH] = "auth", + [PAM_PASSWORD] = "password", + [PAM_SESSION] = "session", +}; + +const char *pam_control_flag_name[PAM_NUM_CONTROL_FLAGS] = { + [PAM_BINDING] = "binding", + [PAM_OPTIONAL] = "optional", + [PAM_REQUIRED] = "required", + [PAM_REQUISITE] = "requisite", + [PAM_SUFFICIENT] = "sufficient", +}; + +const char *pam_func_name[PAM_NUM_PRIMITIVES] = { + "pam_authenticate", + "pam_setcred", + "pam_acct_mgmt", + "pam_open_session", + "pam_close_session", + "pam_chauthtok" +}; + +const char *pam_sm_func_name[PAM_NUM_PRIMITIVES] = { + "pam_sm_authenticate", + "pam_sm_setcred", + "pam_sm_acct_mgmt", + "pam_sm_open_session", + "pam_sm_close_session", + "pam_sm_chauthtok" +}; diff --git a/lib/openpam_constants.h b/lib/openpam_constants.h new file mode 100644 index 0000000..b923179 --- /dev/null +++ b/lib/openpam_constants.h @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2011 Dag-Erling Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_constants.h 491 2011-11-12 00:12:32Z des $ + */ + +#ifndef OPENPAM_CONSTANTS_INCLUDED +#define OPENPAM_CONSTANTS_INCLUDED + +extern const char *pam_err_name[PAM_NUM_ERRORS]; +extern const char *pam_item_name[PAM_NUM_ITEMS]; +extern const char *pam_facility_name[PAM_NUM_FACILITIES]; +extern const char *pam_control_flag_name[PAM_NUM_CONTROL_FLAGS]; +extern const char *pam_func_name[PAM_NUM_PRIMITIVES]; +extern const char *pam_sm_func_name[PAM_NUM_PRIMITIVES]; + +#endif diff --git a/lib/openpam_debug.h b/lib/openpam_debug.h new file mode 100644 index 0000000..ef2884d --- /dev/null +++ b/lib/openpam_debug.h @@ -0,0 +1,103 @@ +/*- + * Copyright (c) 2001-2003 Networks Associates Technology, Inc. + * Copyright (c) 2004-2011 Dag-Erling Smørgrav + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * Network Associates Laboratories, the Security Research Division of + * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_debug.h 491 2011-11-12 00:12:32Z des $ + */ + +#ifndef OPENPAM_DEBUG_INCLUDED +#define OPENPAM_DEBUG_INCLUDED + +#ifdef OPENPAM_DEBUG +#define ENTER() openpam_log(PAM_LOG_DEBUG, "entering") +#define ENTERI(i) do { \ + int i_ = (i); \ + if (i_ > 0 && i_ < PAM_NUM_ITEMS) \ + openpam_log(PAM_LOG_DEBUG, "entering: %s", pam_item_name[i_]); \ + else \ + openpam_log(PAM_LOG_DEBUG, "entering: %d", i_); \ +} while (0) +#define ENTERN(n) do { \ + int n_ = (n); \ + openpam_log(PAM_LOG_DEBUG, "entering: %d", n_); \ +} while (0) +#define ENTERS(s) do { \ + const char *s_ = (s); \ + if (s_ == NULL) \ + openpam_log(PAM_LOG_DEBUG, "entering: NULL"); \ + else \ + openpam_log(PAM_LOG_DEBUG, "entering: '%s'", s_); \ +} while (0) +#define RETURNV() openpam_log(PAM_LOG_DEBUG, "returning") +#define RETURNC(c) do { \ + int c_ = (c); \ + if (c_ >= 0 && c_ < PAM_NUM_ERRORS) \ + openpam_log(PAM_LOG_DEBUG, "returning %s", pam_err_name[c_]); \ + else \ + openpam_log(PAM_LOG_DEBUG, "returning %d!", c_); \ + return (c_); \ +} while (0) +#define RETURNN(n) do { \ + int n_ = (n); \ + openpam_log(PAM_LOG_DEBUG, "returning %d", n_); \ + return (n_); \ +} while (0) +#define RETURNP(p) do { \ + const void *p_ = (p); \ + if (p_ == NULL) \ + openpam_log(PAM_LOG_DEBUG, "returning NULL"); \ + else \ + openpam_log(PAM_LOG_DEBUG, "returning %p", p_); \ + return (p_); \ +} while (0) +#define RETURNS(s) do { \ + const char *s_ = (s); \ + if (s_ == NULL) \ + openpam_log(PAM_LOG_DEBUG, "returning NULL"); \ + else \ + openpam_log(PAM_LOG_DEBUG, "returning '%s'", s_); \ + return (s_); \ +} while (0) +#else +#define ENTER() +#define ENTERI(i) +#define ENTERN(n) +#define ENTERS(s) +#define RETURNV() return +#define RETURNC(c) return (c) +#define RETURNN(n) return (n) +#define RETURNP(p) return (p) +#define RETURNS(s) return (s) +#endif + +#endif diff --git a/lib/openpam_dispatch.c b/lib/openpam_dispatch.c index 69fe472..54dfd3b 100644 --- a/lib/openpam_dispatch.c +++ b/lib/openpam_dispatch.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_dispatch.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_dispatch.c 501 2011-12-07 01:28:05Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include @@ -42,9 +46,9 @@ #include "openpam_impl.h" #if !defined(OPENPAM_RELAX_CHECKS) -static void _openpam_check_error_code(int, int); +static void openpam_check_error_code(int, int); #else -#define _openpam_check_error_code(a, b) +#define openpam_check_error_code(a, b) #endif /* !defined(OPENPAM_RELAX_CHECKS) */ /* @@ -60,9 +64,7 @@ openpam_dispatch(pam_handle_t *pamh, { pam_chain_t *chain; int err, fail, r; -#ifdef DEBUG int debug; -#endif ENTER(); if (pamh == NULL) @@ -72,9 +74,9 @@ openpam_dispatch(pam_handle_t *pamh, if (pamh->current != NULL) { openpam_log(PAM_LOG_ERROR, "%s() called while %s::%s() is in progress", - _pam_func_name[primitive], + pam_func_name[primitive], pamh->current->module->path, - _pam_sm_func_name[pamh->primitive]); + pam_sm_func_name[pamh->primitive]); RETURNC(PAM_ABORT); } @@ -102,28 +104,24 @@ openpam_dispatch(pam_handle_t *pamh, for (err = fail = 0; chain != NULL; chain = chain->next) { if (chain->module->func[primitive] == NULL) { openpam_log(PAM_LOG_ERROR, "%s: no %s()", - chain->module->path, _pam_sm_func_name[primitive]); - continue; + chain->module->path, pam_sm_func_name[primitive]); + r = PAM_SYSTEM_ERR; } else { pamh->primitive = primitive; pamh->current = chain; -#ifdef DEBUG debug = (openpam_get_option(pamh, "debug") != NULL); if (debug) - ++_openpam_debug; + ++openpam_debug; openpam_log(PAM_LOG_DEBUG, "calling %s() in %s", - _pam_sm_func_name[primitive], chain->module->path); -#endif + pam_sm_func_name[primitive], chain->module->path); r = (chain->module->func[primitive])(pamh, flags, chain->optc, (const char **)chain->optv); pamh->current = NULL; -#ifdef DEBUG openpam_log(PAM_LOG_DEBUG, "%s: %s(): %s", - chain->module->path, _pam_sm_func_name[primitive], + chain->module->path, pam_sm_func_name[primitive], pam_strerror(pamh, r)); if (debug) - --_openpam_debug; -#endif + --openpam_debug; } if (r == PAM_IGNORE) @@ -143,7 +141,7 @@ openpam_dispatch(pam_handle_t *pamh, continue; } - _openpam_check_error_code(primitive, r); + openpam_check_error_code(primitive, r); /* * Record the return code from the first module to @@ -177,7 +175,7 @@ openpam_dispatch(pam_handle_t *pamh, #if !defined(OPENPAM_RELAX_CHECKS) static void -_openpam_check_error_code(int primitive, int r) +openpam_check_error_code(int primitive, int r) { /* common error codes */ if (r == PAM_SUCCESS || @@ -229,7 +227,7 @@ _openpam_check_error_code(int primitive, int r) } openpam_log(PAM_LOG_ERROR, "%s(): unexpected return value %d", - _pam_sm_func_name[primitive], r); + pam_sm_func_name[primitive], r); } #endif /* !defined(OPENPAM_RELAX_CHECKS) */ diff --git a/lib/openpam_dynamic.c b/lib/openpam_dynamic.c index 084408e..d44174f 100644 --- a/lib/openpam_dynamic.c +++ b/lib/openpam_dynamic.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,13 +32,19 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_dynamic.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_dynamic.c 502 2011-12-18 13:59:22Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include +#include #include #include #include +#include #include @@ -51,21 +57,35 @@ /* * OpenPAM internal * + * Perform sanity checks and attempt to load a module + */ + +static void * +try_dlopen(const char *modfn) +{ + + if (openpam_check_path_owner_perms(modfn) != 0) + return (NULL); + return (dlopen(modfn, RTLD_NOW)); +} + +/* + * OpenPAM internal + * * Locate a dynamically linked module */ pam_module_t * openpam_dynamic(const char *path) { + const pam_module_t *dlmodule; pam_module_t *module; const char *prefix; char *vpath; void *dlh; - int i; + int i, serrno; dlh = NULL; - if ((module = calloc(1, sizeof *module)) == NULL) - goto buf_err; /* Prepend the standard prefix if not an absolute pathname. */ if (path[0] != '/') @@ -75,33 +95,36 @@ openpam_dynamic(const char *path) /* try versioned module first, then unversioned module */ if (asprintf(&vpath, "%s%s.%d", prefix, path, LIB_MAJ) < 0) - goto buf_err; - if ((dlh = dlopen(vpath, RTLD_NOW)) == NULL) { - openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror()); + goto err; + if ((dlh = try_dlopen(vpath)) == NULL && errno == ENOENT) { *strrchr(vpath, '.') = '\0'; - if ((dlh = dlopen(vpath, RTLD_NOW)) == NULL) { - openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror()); - FREE(vpath); - FREE(module); - return (NULL); - } + dlh = try_dlopen(vpath); } + serrno = errno; FREE(vpath); + errno = serrno; + if (dlh == NULL) + goto err; + if ((module = calloc(1, sizeof *module)) == NULL) + goto buf_err; if ((module->path = strdup(path)) == NULL) goto buf_err; module->dlh = dlh; + dlmodule = dlsym(dlh, "_pam_module"); for (i = 0; i < PAM_NUM_PRIMITIVES; ++i) { - module->func[i] = (pam_func_t)dlsym(dlh, _pam_sm_func_name[i]); + module->func[i] = dlmodule ? dlmodule->func[i] : + (pam_func_t)dlsym(dlh, pam_sm_func_name[i]); if (module->func[i] == NULL) openpam_log(PAM_LOG_DEBUG, "%s: %s(): %s", - path, _pam_sm_func_name[i], dlerror()); + path, pam_sm_func_name[i], dlerror()); } return (module); - buf_err: - openpam_log(PAM_LOG_ERROR, "%m"); +buf_err: if (dlh != NULL) dlclose(dlh); FREE(module); +err: + openpam_log(PAM_LOG_ERROR, "%m"); return (NULL); } diff --git a/lib/openpam_findenv.c b/lib/openpam_findenv.c index d78e147..b833ec9 100644 --- a/lib/openpam_findenv.c +++ b/lib/openpam_findenv.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_findenv.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_findenv.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/openpam_free_data.c b/lib/openpam_free_data.c index e071c0a..561687c 100644 --- a/lib/openpam_free_data.c +++ b/lib/openpam_free_data.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_free_data.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_free_data.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/openpam_free_envlist.c b/lib/openpam_free_envlist.c index 346c2dd..14754dc 100644 --- a/lib/openpam_free_envlist.c +++ b/lib/openpam_free_envlist.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005 Dag-Erling Coïdan Smørgrav + * Copyright (c) 2005-2011 Dag-Erling Smørgrav * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,9 +25,13 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: openpam_free_envlist.c 320 2006-02-16 20:33:19Z des $ + * $Id: openpam_free_envlist.c 447 2011-10-22 02:47:36Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include @@ -63,4 +67,6 @@ openpam_free_envlist(char **envlist) * frees all the environment variables in an environment list, and the * list itself. * It is suitable for freeing the return value from =pam_getenvlist. + * + * AUTHOR DES */ diff --git a/lib/openpam_get_option.c b/lib/openpam_get_option.c index 73bc070..b5faa87 100644 --- a/lib/openpam_get_option.c +++ b/lib/openpam_get_option.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_get_option.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_get_option.c 482 2011-11-03 16:33:02Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/openpam_impl.h b/lib/openpam_impl.h index 7704d4e..ba4d455 100644 --- a/lib/openpam_impl.h +++ b/lib/openpam_impl.h @@ -1,6 +1,6 @@ /*- * Copyright (c) 2001-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,24 +32,15 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_impl.h 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_impl.h 499 2011-11-22 11:51:50Z des $ */ -#ifndef _OPENPAM_IMPL_H_INCLUDED -#define _OPENPAM_IMPL_H_INCLUDED - -#ifdef HAVE_CONFIG_H -# include -#endif +#ifndef OPENPAM_IMPL_H_INCLUDED +#define OPENPAM_IMPL_H_INCLUDED #include -extern const char *_pam_func_name[PAM_NUM_PRIMITIVES]; -extern const char *_pam_sm_func_name[PAM_NUM_PRIMITIVES]; -extern const char *_pam_err_name[PAM_NUM_ERRORS]; -extern const char *_pam_item_name[PAM_NUM_ITEMS]; - -extern int _openpam_debug; +extern int openpam_debug; /* * Control flags @@ -75,6 +66,9 @@ typedef enum { PAM_NUM_FACILITIES } pam_facility_t; +/* + * Module chains + */ typedef struct pam_chain pam_chain_t; struct pam_chain { pam_module_t *module; @@ -84,6 +78,21 @@ struct pam_chain { pam_chain_t *next; }; +/* + * Service policies + */ +#if defined(OPENPAM_EMBEDDED) +typedef struct pam_policy pam_policy_t; +struct pam_policy { + const char *service; + pam_chain_t *chains[PAM_NUM_FACILITIES]; +}; +extern pam_policy_t *pam_embedded_policies[]; +#endif + +/* + * Module-specific data + */ typedef struct pam_data pam_data_t; struct pam_data { char *name; @@ -92,6 +101,9 @@ struct pam_data { pam_data_t *next; }; +/* + * PAM context + */ struct pam_handle { char *service; @@ -111,6 +123,9 @@ struct pam_handle { }; #ifdef NGROUPS_MAX +/* + * Saved credentials + */ #define PAM_SAVED_CRED "pam_saved_cred" struct pam_saved_cred { uid_t euid; @@ -120,14 +135,23 @@ struct pam_saved_cred { }; #endif +/* + * Default policy + */ #define PAM_OTHER "other" +/* + * Internal functions + */ int openpam_configure(pam_handle_t *, const char *); int openpam_dispatch(pam_handle_t *, int, int); int openpam_findenv(pam_handle_t *, const char *, size_t); pam_module_t *openpam_load_module(const char *); void openpam_clear_chains(pam_chain_t **); +int openpam_check_desc_owner_perms(const char *, int); +int openpam_check_path_owner_perms(const char *); + #ifdef OPENPAM_STATIC_MODULES pam_module_t *openpam_static(const char *); #endif @@ -135,66 +159,7 @@ pam_module_t *openpam_dynamic(const char *); #define FREE(p) do { free((p)); (p) = NULL; } while (0) -#ifdef DEBUG -#define ENTER() openpam_log(PAM_LOG_DEBUG, "entering") -#define ENTERI(i) do { \ - int _i = (i); \ - if (_i > 0 && _i < PAM_NUM_ITEMS) \ - openpam_log(PAM_LOG_DEBUG, "entering: %s", _pam_item_name[_i]); \ - else \ - openpam_log(PAM_LOG_DEBUG, "entering: %d", _i); \ -} while (0) -#define ENTERN(n) do { \ - int _n = (n); \ - openpam_log(PAM_LOG_DEBUG, "entering: %d", _n); \ -} while (0) -#define ENTERS(s) do { \ - const char *_s = (s); \ - if (_s == NULL) \ - openpam_log(PAM_LOG_DEBUG, "entering: NULL"); \ - else \ - openpam_log(PAM_LOG_DEBUG, "entering: '%s'", _s); \ -} while (0) -#define RETURNV() openpam_log(PAM_LOG_DEBUG, "returning") -#define RETURNC(c) do { \ - int _c = (c); \ - if (_c >= 0 && _c < PAM_NUM_ERRORS) \ - openpam_log(PAM_LOG_DEBUG, "returning %s", _pam_err_name[_c]); \ - else \ - openpam_log(PAM_LOG_DEBUG, "returning %d!", _c); \ - return (_c); \ -} while (0) -#define RETURNN(n) do { \ - int _n = (n); \ - openpam_log(PAM_LOG_DEBUG, "returning %d", _n); \ - return (_n); \ -} while (0) -#define RETURNP(p) do { \ - const void *_p = (p); \ - if (_p == NULL) \ - openpam_log(PAM_LOG_DEBUG, "returning NULL"); \ - else \ - openpam_log(PAM_LOG_DEBUG, "returning %p", _p); \ - return (p); \ -} while (0) -#define RETURNS(s) do { \ - const char *_s = (s); \ - if (_s == NULL) \ - openpam_log(PAM_LOG_DEBUG, "returning NULL"); \ - else \ - openpam_log(PAM_LOG_DEBUG, "returning '%s'", _s); \ - return (_s); \ -} while (0) -#else -#define ENTER() -#define ENTERI(i) -#define ENTERN(n) -#define ENTERS(s) -#define RETURNV() return -#define RETURNC(c) return (c) -#define RETURNN(n) return (n) -#define RETURNP(p) return (p) -#define RETURNS(s) return (s) -#endif +#include "openpam_constants.h" +#include "openpam_debug.h" #endif diff --git a/lib/openpam_load.c b/lib/openpam_load.c index 303f3f5..0eb8ea7 100644 --- a/lib/openpam_load.c +++ b/lib/openpam_load.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_load.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_load.c 491 2011-11-12 00:12:32Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -43,24 +47,6 @@ #include "openpam_impl.h" -const char *_pam_func_name[PAM_NUM_PRIMITIVES] = { - "pam_authenticate", - "pam_setcred", - "pam_acct_mgmt", - "pam_open_session", - "pam_close_session", - "pam_chauthtok" -}; - -const char *_pam_sm_func_name[PAM_NUM_PRIMITIVES] = { - "pam_sm_authenticate", - "pam_sm_setcred", - "pam_sm_acct_mgmt", - "pam_sm_open_session", - "pam_sm_close_session", - "pam_sm_chauthtok" -}; - /* * Locate a matching dynamic or static module. */ @@ -122,10 +108,8 @@ openpam_destroy_chain(pam_chain_t *chain) return; openpam_destroy_chain(chain->next); chain->next = NULL; - while (chain->optc) { - --chain->optc; + while (chain->optc--) FREE(chain->optv[chain->optc]); - } FREE(chain->optv); openpam_release_module(chain->module); chain->module = NULL; diff --git a/lib/openpam_log.c b/lib/openpam_log.c index e492294..9e3d28b 100644 --- a/lib/openpam_log.c +++ b/lib/openpam_log.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_log.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_log.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -47,9 +51,9 @@ #include "openpam_impl.h" #ifdef OPENPAM_DEBUG -int _openpam_debug = 1; +int openpam_debug = 1; #else -int _openpam_debug = 0; +int openpam_debug = 0; #endif #if !defined(openpam_log) @@ -68,7 +72,7 @@ openpam_log(int level, const char *fmt, ...) switch (level) { case PAM_LOG_DEBUG: - if (!_openpam_debug) + if (!openpam_debug) return; priority = LOG_DEBUG; break; @@ -99,7 +103,7 @@ _openpam_log(int level, const char *func, const char *fmt, ...) switch (level) { case PAM_LOG_DEBUG: - if (!_openpam_debug) + if (!openpam_debug) return; priority = LOG_DEBUG; break; @@ -136,7 +140,7 @@ _openpam_log(int level, const char *func, const char *fmt, ...) * =PAM_LOG_DEBUG: * Debugging messages. * These messages are normally not logged unless the global - * integer variable :_openpam_debug is set to a non-zero + * integer variable :openpam_debug is set to a non-zero * value, in which case they are logged with a =syslog * priority of =LOG_DEBUG. * =PAM_LOG_VERBOSE: diff --git a/lib/openpam_nullconv.c b/lib/openpam_nullconv.c index 3294dcf..a95b1e0 100644 --- a/lib/openpam_nullconv.c +++ b/lib/openpam_nullconv.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_nullconv.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_nullconv.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/openpam_readline.c b/lib/openpam_readline.c index 17f03f3..9cc8cc1 100644 --- a/lib/openpam_readline.c +++ b/lib/openpam_readline.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_readline.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_readline.c 473 2011-11-03 10:48:25Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -83,33 +87,23 @@ openpam_readline(FILE *f, int *lineno, size_t *lenp) } /* eof */ if (ch == EOF) { - /* remove trailing whitespace */ - while (len > 0 && isspace((int)line[len - 1])) - --len; - line[len] = '\0'; - if (len == 0) - goto fail; + /* done */ break; } /* eol */ if (ch == '\n') { if (lineno != NULL) ++*lineno; - - /* remove trailing whitespace */ - while (len > 0 && isspace((int)line[len - 1])) - --len; - line[len] = '\0'; /* skip blank lines */ if (len == 0) continue; /* continuation */ if (line[len - 1] == '\\') { line[--len] = '\0'; - /* fall through to whitespace case */ - } else { - break; + continue; } + /* done */ + break; } /* whitespace */ if (isspace(ch)) { @@ -123,10 +117,16 @@ openpam_readline(FILE *f, int *lineno, size_t *lenp) line_putch(ch); } + /* remove trailing whitespace */ + while (len > 0 && isspace((unsigned char)line[len - 1])) + --len; + line[len] = '\0'; + if (len == 0) + goto fail; if (lenp != NULL) *lenp = len; return (line); - fail: +fail: FREE(line); return (NULL); } @@ -136,13 +136,14 @@ openpam_readline(FILE *f, int *lineno, size_t *lenp) * in a NUL-terminated buffer allocated with =malloc. * * The =openpam_readline function performs a certain amount of processing - * on the data it reads. - * Comments (introduced by a hash sign) are stripped, as is leading and - * trailing whitespace. - * Any amount of linear whitespace is collapsed to a single space. - * Blank lines are ignored. - * If a line ends in a backslash, the backslash is stripped and the next - * line is appended. + * on the data it reads: + * + * - Comments (introduced by a hash sign) are stripped, as is leading and + * trailing whitespace. + * - Any amount of linear whitespace is collapsed to a single space. + * - Blank lines are ignored. + * - If a line ends in a backslash, the backslash is stripped and the + * next line is appended. * * If =lineno is not =NULL, the integer variable it points to is * incremented every time a newline character is read. diff --git a/lib/openpam_restore_cred.c b/lib/openpam_restore_cred.c index 20e80d4..41d44d0 100644 --- a/lib/openpam_restore_cred.c +++ b/lib/openpam_restore_cred.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_restore_cred.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_restore_cred.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/openpam_set_option.c b/lib/openpam_set_option.c index 57161d3..c7cb1c7 100644 --- a/lib/openpam_set_option.c +++ b/lib/openpam_set_option.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_set_option.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_set_option.c 482 2011-11-03 16:33:02Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/openpam_static.c b/lib/openpam_static.c index c06ceed..40b807c 100644 --- a/lib/openpam_static.c +++ b/lib/openpam_static.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_static.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_static.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include @@ -43,7 +47,7 @@ #ifdef OPENPAM_STATIC_MODULES -SET_DECLARE(_openpam_static_modules, pam_module_t); +SET_DECLARE(openpam_static_modules, pam_module_t); /* * OpenPAM internal @@ -56,7 +60,7 @@ openpam_static(const char *path) { pam_module_t **module; - SET_FOREACH(module, _openpam_static_modules) { + SET_FOREACH(module, openpam_static_modules) { if (strcmp((*module)->path, path) == 0) return (*module); } diff --git a/lib/openpam_strlcmp.h b/lib/openpam_strlcmp.h new file mode 100644 index 0000000..c692225 --- /dev/null +++ b/lib/openpam_strlcmp.h @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 2011 Dag-Erling Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_strlcmp.h 475 2011-11-03 15:29:24Z des $ + */ + +#ifndef OPENPAM_STRLCMP_H_INCLUDED +#define OPENPAM_STRLCMP_H_INCLUDED + +#ifndef HAVE_STRLCMP +/* like strcmp(3), but verifies that the entirety of s1 was matched */ +static int +strlcmp(const char *s1, const char *s2, size_t len) +{ + + for (; len && *s1 && *s2; --len, ++s1, ++s2) + if (*s1 != *s2) + return ((unsigned char)*s1 - (unsigned char)*s2); + return ((unsigned char)*s1); +} +#endif + +#endif diff --git a/lib/openpam_strlcpy.h b/lib/openpam_strlcpy.h new file mode 100644 index 0000000..921653b --- /dev/null +++ b/lib/openpam_strlcpy.h @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2011 Dag-Erling Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_strlcpy.h 492 2011-11-20 02:04:17Z des $ + */ + +#ifndef OPENPAM_STRLCPY_H_INCLUDED +#define OPENPAM_STRLCPY_H_INCLUDED + +#ifndef HAVE_STRLCPY +/* like strcpy(3), but always NUL-terminates; returns strlen(src) */ +size_t +strlcpy(char *dst, const char *src, size_t size) +{ + size_t len; + + for (len = 0; *src && size > 1; ++len, --size) + *dst++ = *src++; + *dst = '\0'; + while (*src) + ++len, ++src; + return (len); +} +#endif + +#endif diff --git a/lib/openpam_subst.c b/lib/openpam_subst.c new file mode 100644 index 0000000..d54b827 --- /dev/null +++ b/lib/openpam_subst.c @@ -0,0 +1,168 @@ +/*- + * Copyright (c) 2011 Dag-Erling Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: openpam_subst.c 461 2011-11-02 14:00:38Z des $ + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "openpam_impl.h" + +#define subst_char(ch) do { \ + int ch_ = (ch); \ + if (buf && len < *bufsize) \ + *buf++ = ch_; \ + ++len; \ +} while (0) + +#define subst_string(s) do { \ + const char *s_ = (s); \ + while (*s_) \ + subst_char(*s_++); \ +} while (0) + +#define subst_item(i) do { \ + int i_ = (i); \ + const void *p_; \ + ret = pam_get_item(pamh, i_, &p_); \ + if (ret == PAM_SUCCESS && p_ != NULL) \ + subst_string(p_); \ +} while (0) + +/* + * OpenPAM internal + * + * Substitute PAM item values in a string + */ + +int +openpam_subst(const pam_handle_t *pamh, + char *buf, size_t *bufsize, const char *template) +{ + size_t len; + int ret; + + ENTERS(template); + if (template == NULL) + template = "(null)"; + + len = 1; /* initialize to 1 for terminating NUL */ + ret = PAM_SUCCESS; + while (*template && ret == PAM_SUCCESS) { + if (template[0] == '%') { + ++template; + switch (*template) { + case 's': + subst_item(PAM_SERVICE); + break; + case 't': + subst_item(PAM_TTY); + break; + case 'h': + subst_item(PAM_HOST); + break; + case 'u': + subst_item(PAM_USER); + break; + case 'H': + subst_item(PAM_RHOST); + break; + case 'U': + subst_item(PAM_RUSER); + break; + case '\0': + subst_char('%'); + break; + default: + subst_char('%'); + subst_char(*template); + } + ++template; + } else { + subst_char(*template++); + } + } + if (buf) + *buf = '\0'; + if (ret == PAM_SUCCESS) { + if (len > *bufsize) + ret = PAM_TRY_AGAIN; + *bufsize = len; + } + RETURNC(ret); +} + +/* + * Error codes: + * + * =pam_get_item + * !PAM_SYMBOL_ERR + * PAM_TRY_AGAIN + */ + +/** + * The =openpam_subst function expands a string, substituting PAM item + * values for all occurrences of specific substitution codes. + * The =template argument points to the initial string. + * The result is stored in the buffer pointed to by the =buf argument; the + * =bufsize argument specifies the size of that buffer. + * The actual size of the resulting string, including the terminating NUL + * character, is stored in the location pointed to by the =bufsize + * argument. + * + * If =buf is NULL, or if the buffer is too small to hold the expanded + * string, =bufsize is updated to reflect the amount of space required to + * hold the entire string, and =openpam_subst returns =PAM_TRY_AGAIN. + * + * If =openpam_subst fails for any other reason, the =bufsize argument is + * untouched, but part of the buffer may still have been overwritten. + * + * Substitution codes are introduced by a percent character and correspond + * to PAM items: + * + * %H: + * Replaced by the current value of the =PAM_RHOST item. + * %h: + * Replaced by the current value of the =PAM_HOST item. + * %s: + * Replaced by the current value of the =PAM_SERVICE item. + * %t: + * Replaced by the current value of the =PAM_TTY item. + * %U: + * Replaced by the current value of the =PAM_RUSER item. + * %u: + * Replaced by the current value of the =PAM_USER item. + * + * >pam_get_authtok + * >pam_get_item + * >pam_get_user + * + * AUTHOR DES + */ diff --git a/lib/openpam_ttyconv.c b/lib/openpam_ttyconv.c index a6820b9..ec078f4 100644 --- a/lib/openpam_ttyconv.c +++ b/lib/openpam_ttyconv.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: openpam_ttyconv.c 408 2007-12-21 11:36:24Z des $ + * $Id: openpam_ttyconv.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include @@ -211,7 +215,7 @@ openpam_ttyconv(int n, } *resp = aresp; RETURNC(PAM_SUCCESS); - fail: +fail: for (i = 0; i < n; ++i) { if (aresp[i].resp != NULL) { memset(aresp[i].resp, 0, strlen(aresp[i].resp)); diff --git a/lib/pam_acct_mgmt.c b/lib/pam_acct_mgmt.c index 0088ecf..49c34ab 100644 --- a/lib/pam_acct_mgmt.c +++ b/lib/pam_acct_mgmt.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_acct_mgmt.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_acct_mgmt.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_authenticate.c b/lib/pam_authenticate.c index 3b5a78d..fc6c20f 100644 --- a/lib/pam_authenticate.c +++ b/lib/pam_authenticate.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_authenticate.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_authenticate.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_authenticate_secondary.c b/lib/pam_authenticate_secondary.c index 27e3ce7..1a57313 100644 --- a/lib/pam_authenticate_secondary.c +++ b/lib/pam_authenticate_secondary.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_authenticate_secondary.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_authenticate_secondary.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include /* diff --git a/lib/pam_chauthtok.c b/lib/pam_chauthtok.c index ecf1063..1750b0f 100644 --- a/lib/pam_chauthtok.c +++ b/lib/pam_chauthtok.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_chauthtok.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_chauthtok.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_close_session.c b/lib/pam_close_session.c index ab50e35..9e63a1d 100644 --- a/lib/pam_close_session.c +++ b/lib/pam_close_session.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_close_session.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_close_session.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_end.c b/lib/pam_end.c index 80baf8a..09cde35 100644 --- a/lib/pam_end.c +++ b/lib/pam_end.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_end.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_end.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_error.c b/lib/pam_error.c index f42a6b5..1e0de5b 100644 --- a/lib/pam_error.c +++ b/lib/pam_error.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_error.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_error.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include diff --git a/lib/pam_get_authtok.c b/lib/pam_get_authtok.c index 2a974c9..a0613ef 100644 --- a/lib/pam_get_authtok.c +++ b/lib/pam_get_authtok.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_get_authtok.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_get_authtok.c 455 2011-10-29 18:31:11Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include @@ -61,8 +65,10 @@ pam_get_authtok(pam_handle_t *pamh, const char **authtok, const char *prompt) { + char prompt_buf[1024]; + size_t prompt_size; const void *oldauthtok, *prevauthtok, *promptp; - const char *default_prompt; + const char *prompt_option, *default_prompt; char *resp, *resp2; int pitem, r, style, twice; @@ -74,6 +80,7 @@ pam_get_authtok(pam_handle_t *pamh, switch (item) { case PAM_AUTHTOK: pitem = PAM_AUTHTOK_PROMPT; + prompt_option = "authtok_prompt"; default_prompt = authtok_prompt; r = pam_get_item(pamh, PAM_OLDAUTHTOK, &oldauthtok); if (r == PAM_SUCCESS && oldauthtok != NULL) { @@ -83,6 +90,7 @@ pam_get_authtok(pam_handle_t *pamh, break; case PAM_OLDAUTHTOK: pitem = PAM_OLDAUTHTOK_PROMPT; + prompt_option = "oldauthtok_prompt"; default_prompt = oldauthtok_prompt; twice = 0; break; @@ -99,13 +107,21 @@ pam_get_authtok(pam_handle_t *pamh, else if (openpam_get_option(pamh, "use_first_pass")) RETURNC(r == PAM_SUCCESS ? PAM_AUTH_ERR : r); } - if (prompt == NULL) { - r = pam_get_item(pamh, pitem, &promptp); - if (r != PAM_SUCCESS || promptp == NULL) - prompt = default_prompt; - else + /* pam policy overrides the module's choice */ + if ((promptp = openpam_get_option(pamh, prompt_option)) != NULL) + prompt = promptp; + /* no prompt provided, see if there is one tucked away somewhere */ + if (prompt == NULL) + if (pam_get_item(pamh, pitem, &promptp) && promptp != NULL) prompt = promptp; - } + /* fall back to hardcoded default */ + if (prompt == NULL) + prompt = default_prompt; + /* expand */ + prompt_size = sizeof prompt_buf; + r = openpam_subst(pamh, prompt_buf, &prompt_size, prompt); + if (r == PAM_SUCCESS && prompt_size <= sizeof prompt_buf) + prompt = prompt_buf; style = openpam_get_option(pamh, "echo_pass") ? PAM_PROMPT_ECHO_ON : PAM_PROMPT_ECHO_OFF; r = pam_prompt(pamh, style, &resp, "%s", prompt); @@ -160,6 +176,13 @@ pam_get_authtok(pam_handle_t *pamh, * If it is =NULL, the =PAM_AUTHTOK_PROMPT or =PAM_OLDAUTHTOK_PROMPT item, * as appropriate, will be used. * If that item is also =NULL, a hardcoded default prompt will be used. + * Either way, the prompt is expanded using =openpam_subst before it is + * passed to the conversation function. + * + * If =pam_get_authtok is called from a module and the ;authtok_prompt / + * ;oldauthtok_prompt option is set in the policy file, the value of that + * option takes precedence over both the =prompt argument and the + * =PAM_AUTHTOK_PROMPT / =PAM_OLDAUTHTOK_PROMPT item. * * If =item is set to =PAM_AUTHTOK and there is a non-null =PAM_OLDAUTHTOK * item, =pam_get_authtok will ask the user to confirm the new token by @@ -168,4 +191,5 @@ pam_get_authtok(pam_handle_t *pamh, * * >pam_get_item * >pam_get_user + * >openpam_subst */ diff --git a/lib/pam_get_data.c b/lib/pam_get_data.c index 0cceef0..1a8ba1d 100644 --- a/lib/pam_get_data.c +++ b/lib/pam_get_data.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_get_data.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_get_data.c 444 2011-10-22 01:03:23Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include @@ -80,6 +84,7 @@ pam_get_data(const pam_handle_t *pamh, * context specified by the =pamh argument. * A pointer to the object is stored in the location pointed to by the * =data argument. + * If =pam_get_data fails, the =data argument is untouched. * * This function and its counterpart =pam_set_data are useful for managing * data that are meaningful only to a particular service module. diff --git a/lib/pam_get_item.c b/lib/pam_get_item.c index 9f127be..95b9df6 100644 --- a/lib/pam_get_item.c +++ b/lib/pam_get_item.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,31 +32,19 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_get_item.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_get_item.c 491 2011-11-12 00:12:32Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include "openpam_impl.h" -const char *_pam_item_name[PAM_NUM_ITEMS] = { - "(NO ITEM)", - "PAM_SERVICE", - "PAM_USER", - "PAM_TTY", - "PAM_RHOST", - "PAM_CONV", - "PAM_AUTHTOK", - "PAM_OLDAUTHTOK", - "PAM_RUSER", - "PAM_USER_PROMPT", - "PAM_REPOSITORY", - "PAM_AUTHTOK_PROMPT", - "PAM_OLDAUTHTOK_PROMPT" -}; - /* * XSSO 4.2.1 * XSSO 6 page 46 @@ -83,9 +71,10 @@ pam_get_item(const pam_handle_t *pamh, case PAM_RUSER: case PAM_CONV: case PAM_USER_PROMPT: + case PAM_REPOSITORY: case PAM_AUTHTOK_PROMPT: case PAM_OLDAUTHTOK_PROMPT: - case PAM_REPOSITORY: + case PAM_HOST: *item = pamh->item[item_type]; RETURNC(PAM_SUCCESS); default: @@ -102,10 +91,12 @@ pam_get_item(const pam_handle_t *pamh, /** * The =pam_get_item function stores a pointer to the item specified by - * the =item_type argument in the location specified by the =item + * the =item_type argument in the location pointed to by the =item * argument. * The item is retrieved from the PAM context specified by the =pamh * argument. + * If =pam_get_item fails, the =item argument is untouched. + * * The following item types are recognized: * * =PAM_SERVICE: @@ -135,6 +126,8 @@ pam_get_item(const pam_handle_t *pamh, * =PAM_OLDAUTHTOK_PROMPT: * The prompt to use when asking the applicant for an * expired authentication token prior to changing it. + * =PAM_HOST: + * The name of the host the application runs on. * * See =pam_start for a description of =struct pam_conv. * diff --git a/lib/pam_get_mapped_authtok.c b/lib/pam_get_mapped_authtok.c index c49a918..54ff6c3 100644 --- a/lib/pam_get_mapped_authtok.c +++ b/lib/pam_get_mapped_authtok.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_get_mapped_authtok.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_get_mapped_authtok.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include /* diff --git a/lib/pam_get_mapped_username.c b/lib/pam_get_mapped_username.c index 359baee..4f8ac17 100644 --- a/lib/pam_get_mapped_username.c +++ b/lib/pam_get_mapped_username.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_get_mapped_username.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_get_mapped_username.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include /* diff --git a/lib/pam_get_user.c b/lib/pam_get_user.c index 115a3ea..53245b9 100644 --- a/lib/pam_get_user.c +++ b/lib/pam_get_user.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_get_user.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_get_user.c 455 2011-10-29 18:31:11Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include @@ -58,6 +62,8 @@ pam_get_user(pam_handle_t *pamh, const char **user, const char *prompt) { + char prompt_buf[1024]; + size_t prompt_size; const void *promptp; char *resp; int r; @@ -68,13 +74,22 @@ pam_get_user(pam_handle_t *pamh, r = pam_get_item(pamh, PAM_USER, (const void **)user); if (r == PAM_SUCCESS && *user != NULL) RETURNC(PAM_SUCCESS); - if (prompt == NULL) { - r = pam_get_item(pamh, PAM_USER_PROMPT, &promptp); - if (r != PAM_SUCCESS || promptp == NULL) - prompt = user_prompt; - else + /* pam policy overrides the module's choice */ + if ((promptp = openpam_get_option(pamh, "user_prompt")) != NULL) + prompt = promptp; + /* no prompt provided, see if there is one tucked away somewhere */ + if (prompt == NULL) + if (pam_get_item(pamh, PAM_USER_PROMPT, &promptp) && + promptp != NULL) prompt = promptp; - } + /* fall back to hardcoded default */ + if (prompt == NULL) + prompt = user_prompt; + /* expand */ + prompt_size = sizeof prompt_buf; + r = openpam_subst(pamh, prompt_buf, &prompt_size, prompt); + if (r == PAM_SUCCESS && prompt_size <= sizeof prompt_buf) + prompt = prompt_buf; r = pam_prompt(pamh, PAM_PROMPT_ECHO_ON, &resp, "%s", prompt); if (r != PAM_SUCCESS) RETURNC(r); @@ -105,9 +120,16 @@ pam_get_user(pam_handle_t *pamh, * * The =prompt argument specifies a prompt to use if no user name is * cached. - * If it is =NULL, the =PAM_USER_PROMPT will be used. + * If it is =NULL, the =PAM_USER_PROMPT item will be used. * If that item is also =NULL, a hardcoded default prompt will be used. + * Either way, the prompt is expanded using =openpam_subst before it is + * passed to the conversation function. + * + * If =pam_get_user is called from a module and the ;user_prompt option is + * set in the policy file, the value of that option takes precedence over + * both the =prompt argument and the =PAM_USER_PROMPT item. * * >pam_get_item * >pam_get_authtok + * >openpam_subst */ diff --git a/lib/pam_getenv.c b/lib/pam_getenv.c index f2d7910..e2ebf57 100644 --- a/lib/pam_getenv.c +++ b/lib/pam_getenv.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_getenv.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_getenv.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_getenvlist.c b/lib/pam_getenvlist.c index c0e128a..06c003f 100644 --- a/lib/pam_getenvlist.c +++ b/lib/pam_getenvlist.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_getenvlist.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_getenvlist.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_info.c b/lib/pam_info.c index 2e4dbc7..7e51dbf 100644 --- a/lib/pam_info.c +++ b/lib/pam_info.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_info.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_info.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include diff --git a/lib/pam_open_session.c b/lib/pam_open_session.c index f8d6eca..36c59b0 100644 --- a/lib/pam_open_session.c +++ b/lib/pam_open_session.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_open_session.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_open_session.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_prompt.c b/lib/pam_prompt.c index 76da55f..194e765 100644 --- a/lib/pam_prompt.c +++ b/lib/pam_prompt.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_prompt.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_prompt.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_putenv.c b/lib/pam_putenv.c index 79d6228..369066d 100644 --- a/lib/pam_putenv.c +++ b/lib/pam_putenv.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_putenv.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_putenv.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_set_data.c b/lib/pam_set_data.c index 963de92..a8de632 100644 --- a/lib/pam_set_data.c +++ b/lib/pam_set_data.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_set_data.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_set_data.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_set_item.c b/lib/pam_set_item.c index 9b60618..05d538f 100644 --- a/lib/pam_set_item.c +++ b/lib/pam_set_item.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_set_item.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_set_item.c 496 2011-11-21 16:20:45Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include @@ -66,6 +70,10 @@ pam_set_item(pam_handle_t *pamh, osize = nsize = 0; switch (item_type) { case PAM_SERVICE: + /* set once only, by pam_start() */ + if (*slot != NULL) + RETURNC(PAM_SYSTEM_ERR); + /* fall through */ case PAM_USER: case PAM_AUTHTOK: case PAM_OLDAUTHTOK: @@ -75,6 +83,7 @@ pam_set_item(pam_handle_t *pamh, case PAM_USER_PROMPT: case PAM_AUTHTOK_PROMPT: case PAM_OLDAUTHTOK_PROMPT: + case PAM_HOST: if (*slot != NULL) osize = strlen(*slot) + 1; if (item != NULL) diff --git a/lib/pam_set_mapped_authtok.c b/lib/pam_set_mapped_authtok.c index 01ad255..d8db84f 100644 --- a/lib/pam_set_mapped_authtok.c +++ b/lib/pam_set_mapped_authtok.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_set_mapped_authtok.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_set_mapped_authtok.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include /* diff --git a/lib/pam_set_mapped_username.c b/lib/pam_set_mapped_username.c index ae3619b..4b8f815 100644 --- a/lib/pam_set_mapped_username.c +++ b/lib/pam_set_mapped_username.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_set_mapped_username.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_set_mapped_username.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include /* diff --git a/lib/pam_setcred.c b/lib/pam_setcred.c index 80eb468..51fb081 100644 --- a/lib/pam_setcred.c +++ b/lib/pam_setcred.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_setcred.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_setcred.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_setenv.c b/lib/pam_setenv.c index e73f6b5..fbe6a8f 100644 --- a/lib/pam_setenv.c +++ b/lib/pam_setenv.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_setenv.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_setenv.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include diff --git a/lib/pam_sm_acct_mgmt.c b/lib/pam_sm_acct_mgmt.c index a57e86a..f5c14cf 100644 --- a/lib/pam_sm_acct_mgmt.c +++ b/lib/pam_sm_acct_mgmt.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_acct_mgmt.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_acct_mgmt.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_sm_authenticate.c b/lib/pam_sm_authenticate.c index 7f4bb1c..97851af 100644 --- a/lib/pam_sm_authenticate.c +++ b/lib/pam_sm_authenticate.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_authenticate.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_authenticate.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_sm_authenticate_secondary.c b/lib/pam_sm_authenticate_secondary.c index bde0366..3f3f6bd 100644 --- a/lib/pam_sm_authenticate_secondary.c +++ b/lib/pam_sm_authenticate_secondary.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_authenticate_secondary.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_authenticate_secondary.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_sm_chauthtok.c b/lib/pam_sm_chauthtok.c index 2c41d6d..593344c 100644 --- a/lib/pam_sm_chauthtok.c +++ b/lib/pam_sm_chauthtok.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_chauthtok.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_chauthtok.c 466 2011-11-02 23:33:43Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include @@ -80,4 +84,8 @@ pam_sm_chauthtok(pam_handle_t *pamh, /** * The =pam_sm_chauthtok function is the service module's implementation * of the =pam_chauthtok API function. + * + * When the application calls =pam_chauthtok, the service function is + * called twice, first with the =PAM_PRELIM_CHECK flag set and then again + * with the =PAM_UPDATE_AUTHTOK flag set. */ diff --git a/lib/pam_sm_close_session.c b/lib/pam_sm_close_session.c index 25cee92..290f497 100644 --- a/lib/pam_sm_close_session.c +++ b/lib/pam_sm_close_session.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_close_session.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_close_session.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_sm_get_mapped_authtok.c b/lib/pam_sm_get_mapped_authtok.c index 9d85d5f..e86e6e5 100644 --- a/lib/pam_sm_get_mapped_authtok.c +++ b/lib/pam_sm_get_mapped_authtok.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_get_mapped_authtok.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_get_mapped_authtok.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_sm_get_mapped_username.c b/lib/pam_sm_get_mapped_username.c index ee4d250..596ca6c 100644 --- a/lib/pam_sm_get_mapped_username.c +++ b/lib/pam_sm_get_mapped_username.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_get_mapped_username.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_get_mapped_username.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_sm_open_session.c b/lib/pam_sm_open_session.c index bfe0794..acb401a 100644 --- a/lib/pam_sm_open_session.c +++ b/lib/pam_sm_open_session.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_open_session.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_open_session.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_sm_set_mapped_authtok.c b/lib/pam_sm_set_mapped_authtok.c index 54fd370..dab40fd 100644 --- a/lib/pam_sm_set_mapped_authtok.c +++ b/lib/pam_sm_set_mapped_authtok.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_set_mapped_authtok.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_set_mapped_authtok.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_sm_set_mapped_username.c b/lib/pam_sm_set_mapped_username.c index 0239dbb..3011016 100644 --- a/lib/pam_sm_set_mapped_username.c +++ b/lib/pam_sm_set_mapped_username.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_set_mapped_username.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_set_mapped_username.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_sm_setcred.c b/lib/pam_sm_setcred.c index 4d472b3..0d30683 100644 --- a/lib/pam_sm_setcred.c +++ b/lib/pam_sm_setcred.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_sm_setcred.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_sm_setcred.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_start.c b/lib/pam_start.c index ee6468b..84e0085 100644 --- a/lib/pam_start.c +++ b/lib/pam_start.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,14 +32,27 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_start.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_start.c 503 2011-12-18 14:00:33Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include +#include +#include #include #include "openpam_impl.h" +#include "openpam_strlcpy.h" + +#ifdef _SC_HOST_NAME_MAX +#define HOST_NAME_MAX sysconf(_SC_HOST_NAME_MAX) +#else +#define HOST_NAME_MAX 1024 +#endif /* * XSSO 4.2.1 @@ -54,6 +67,7 @@ pam_start(const char *service, const struct pam_conv *pam_conv, pam_handle_t **pamh) { + char hostname[HOST_NAME_MAX + 1]; struct pam_handle *ph; int r; @@ -62,20 +76,20 @@ pam_start(const char *service, RETURNC(PAM_BUF_ERR); if ((r = pam_set_item(ph, PAM_SERVICE, service)) != PAM_SUCCESS) goto fail; + if (gethostname(hostname, sizeof hostname) != 0) + strlcpy(hostname, "localhost", sizeof hostname); + if ((r = pam_set_item(ph, PAM_HOST, hostname)) != PAM_SUCCESS) + goto fail; if ((r = pam_set_item(ph, PAM_USER, user)) != PAM_SUCCESS) goto fail; if ((r = pam_set_item(ph, PAM_CONV, pam_conv)) != PAM_SUCCESS) goto fail; - - r = openpam_configure(ph, service); - if (r != PAM_SUCCESS) + if ((r = openpam_configure(ph, service)) != PAM_SUCCESS) goto fail; - *pamh = ph; openpam_log(PAM_LOG_DEBUG, "pam_start(\"%s\") succeeded", service); RETURNC(PAM_SUCCESS); - - fail: +fail: pam_end(ph, r); RETURNC(r); } diff --git a/lib/pam_strerror.c b/lib/pam_strerror.c index 24498c4..e29219d 100644 --- a/lib/pam_strerror.c +++ b/lib/pam_strerror.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,48 +32,19 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_strerror.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_strerror.c 491 2011-11-12 00:12:32Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include "openpam_impl.h" -const char *_pam_err_name[PAM_NUM_ERRORS] = { - "PAM_SUCCESS", - "PAM_OPEN_ERR", - "PAM_SYMBOL_ERR", - "PAM_SERVICE_ERR", - "PAM_SYSTEM_ERR", - "PAM_BUF_ERR", - "PAM_CONV_ERR", - "PAM_PERM_DENIED", - "PAM_MAXTRIES", - "PAM_AUTH_ERR", - "PAM_NEW_AUTHTOK_REQD", - "PAM_CRED_INSUFFICIENT", - "PAM_AUTHINFO_UNAVAIL", - "PAM_USER_UNKNOWN", - "PAM_CRED_UNAVAIL", - "PAM_CRED_EXPIRED", - "PAM_CRED_ERR", - "PAM_ACCT_EXPIRED", - "PAM_AUTHTOK_EXPIRED", - "PAM_SESSION_ERR", - "PAM_AUTHTOK_ERR", - "PAM_AUTHTOK_RECOVERY_ERR", - "PAM_AUTHTOK_LOCK_BUSY", - "PAM_AUTHTOK_DISABLE_AGING", - "PAM_NO_MODULE_DATA", - "PAM_IGNORE", - "PAM_ABORT", - "PAM_TRY_AGAIN", - "PAM_MODULE_UNKNOWN", - "PAM_DOMAIN_UNKNOWN" -}; - /* * XSSO 4.2.1 * XSSO 6 page 92 @@ -159,6 +130,8 @@ pam_strerror(const pam_handle_t *pamh, /** * The =pam_strerror function returns a pointer to a string containing a * textual description of the error indicated by the =error_number - * argument, in the context of the PAM transaction described by the =pamh * argument. + * The =pamh argument is ignored. + * For compatibility with other implementations, it should be either a + * valid PAM handle returned by a previous call to =pam_start, or =NULL. */ diff --git a/lib/pam_verror.c b/lib/pam_verror.c index 0b128d1..9ed85b6 100644 --- a/lib/pam_verror.c +++ b/lib/pam_verror.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_verror.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_verror.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_vinfo.c b/lib/pam_vinfo.c index 5282714..95f45f4 100644 --- a/lib/pam_vinfo.c +++ b/lib/pam_vinfo.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_vinfo.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_vinfo.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include diff --git a/lib/pam_vprompt.c b/lib/pam_vprompt.c index e1215c3..1e390e0 100644 --- a/lib/pam_vprompt.c +++ b/lib/pam_vprompt.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. - * Copyright (c) 2004-2007 Dag-Erling Smørgrav + * Copyright (c) 2004-2011 Dag-Erling Smørgrav * All rights reserved. * * This software was developed for the FreeBSD Project by ThinkSec AS and @@ -32,9 +32,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pam_vprompt.c 408 2007-12-21 11:36:24Z des $ + * $Id: pam_vprompt.c 437 2011-09-13 12:00:13Z des $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include -- cgit v1.1 From 01b1a8afd0f9dc565db2a74e83461c6705bd4373 Mon Sep 17 00:00:00 2001 From: melifaro Date: Tue, 20 Dec 2011 11:13:44 +0000 Subject: Add binding support to libradius(3). Submitted by: Sergey Matveychuk Approved by: ae (mentor) MFC after: 2 weeks --- lib/libradius/Makefile | 1 + lib/libradius/libradius.3 | 6 ++++++ lib/libradius/radlib.c | 9 ++++++++- lib/libradius/radlib.h | 1 + lib/libradius/radlib_private.h | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libradius/Makefile b/lib/libradius/Makefile index 5723bf1..d71d8f2 100644 --- a/lib/libradius/Makefile +++ b/lib/libradius/Makefile @@ -36,6 +36,7 @@ MAN= libradius.3 radius.conf.5 MLINKS+=libradius.3 rad_acct_open.3 \ libradius.3 rad_add_server.3 \ libradius.3 rad_auth_open.3 \ + libradius.3 rad_bind_to.3 \ libradius.3 rad_close.3 \ libradius.3 rad_config.3 \ libradius.3 rad_continue_send_request.3 \ diff --git a/lib/libradius/libradius.3 b/lib/libradius/libradius.3 index 7fc1162..dca38ca 100644 --- a/lib/libradius/libradius.3 +++ b/lib/libradius/libradius.3 @@ -91,6 +91,8 @@ .Fn rad_server_open "int fd" .Ft "const char *" .Fn rad_server_secret "struct rad_handle *h" +.Ft "void" +.Fn rad_bind_to "struct rad_handle *h" "in_addr_t addr" .Ft u_char * .Fn rad_demangle "struct rad_handle *h" "const void *mangled" "size_t mlen" .Ft u_char * @@ -431,6 +433,10 @@ returns the secret shared with the current RADIUS server according to the supplied rad_handle. .Pp The +.Fn rad_bind_to +assigns a source address for all requests to the current RADIUS server. +.Pp +The .Fn rad_demangle function demangles attributes containing passwords and MS-CHAPv1 MPPE-Keys. The return value is diff --git a/lib/libradius/radlib.c b/lib/libradius/radlib.c index e4e4a94..46a9b58 100644 --- a/lib/libradius/radlib.c +++ b/lib/libradius/radlib.c @@ -756,9 +756,16 @@ rad_create_request(struct rad_handle *h, int code) clear_password(h); h->authentic_pos = 0; h->out_created = 1; + h->bindto = INADDR_ANY; return 0; } +void +rad_bind_to(struct rad_handle *h, in_addr_t addr) +{ + h->bindto = addr; +} + int rad_create_response(struct rad_handle *h, int code) { @@ -857,7 +864,7 @@ rad_init_send_request(struct rad_handle *h, int *fd, struct timeval *tv) memset(&sin, 0, sizeof sin); sin.sin_len = sizeof sin; sin.sin_family = AF_INET; - sin.sin_addr.s_addr = INADDR_ANY; + sin.sin_addr.s_addr = h->bindto; sin.sin_port = htons(0); if (bind(h->fd, (const struct sockaddr *)&sin, sizeof sin) == -1) { diff --git a/lib/libradius/radlib.h b/lib/libradius/radlib.h index b26be41..f9e451b 100644 --- a/lib/libradius/radlib.h +++ b/lib/libradius/radlib.h @@ -195,6 +195,7 @@ struct rad_handle *rad_acct_open(void); int rad_add_server(struct rad_handle *, const char *, int, const char *, int, int); struct rad_handle *rad_auth_open(void); +void rad_bind_to(struct rad_handle *, in_addr_t); void rad_close(struct rad_handle *); int rad_config(struct rad_handle *, const char *); int rad_continue_send_request(struct rad_handle *, int, diff --git a/lib/libradius/radlib_private.h b/lib/libradius/radlib_private.h index d886c74..a76e594aa 100644 --- a/lib/libradius/radlib_private.h +++ b/lib/libradius/radlib_private.h @@ -92,6 +92,7 @@ struct rad_handle { int try; /* How many requests we've sent */ int srv; /* Server number we did last */ int type; /* Handle type */ + in_addr_t bindto; /* Bind to address */ }; struct vendor_attribute { -- cgit v1.1 From 3e7916ec1c37c8aabb4a4dcd644f98e38eff81f1 Mon Sep 17 00:00:00 2001 From: mm Date: Tue, 20 Dec 2011 20:02:07 +0000 Subject: Merge vendor revision 3723: Fixes extraction of Zip entries that use length-at-end without specifying either the compressed or uncompressed length. In particular, fixes bsdtar extraction of such files. Obtained from: http://code.google.com/p/libarchive Reported by: Patrick Lamaiziere (freebsd-stable@) MFC after: 1 week --- lib/libarchive/archive_read_extract.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libarchive/archive_read_extract.c b/lib/libarchive/archive_read_extract.c index 8ae5dec..5c69f59 100644 --- a/lib/libarchive/archive_read_extract.c +++ b/lib/libarchive/archive_read_extract.c @@ -108,7 +108,7 @@ archive_read_extract2(struct archive *_a, struct archive_entry *entry, if (r != ARCHIVE_OK) /* If _write_header failed, copy the error. */ archive_copy_error(&a->archive, ad); - else if (archive_entry_size(entry) > 0) + else if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) > 0) /* Otherwise, pour data into the entry. */ r = copy_data(_a, ad); r2 = archive_write_finish_entry(ad); -- cgit v1.1 From de78128d73d25a4377de7c74ce56bd3f3ee8abe7 Mon Sep 17 00:00:00 2001 From: mm Date: Tue, 20 Dec 2011 20:06:33 +0000 Subject: Update libarchive, tar and cpio to version 2.8.5 The following additional vendor revisions are applied: Revision 3740: Use archive_clear_error() to clear the error markers. Obtained from: http://code.google.com/p/libarchive MFC after: 2 weeks --- lib/libarchive/archive.h | 15 +++- lib/libarchive/archive_read.c | 2 +- .../archive_read_support_compression_bzip2.c | 2 +- .../archive_read_support_compression_uu.c | 4 +- lib/libarchive/archive_read_support_format_cpio.c | 6 +- .../archive_read_support_format_iso9660.c | 22 ++--- lib/libarchive/archive_read_support_format_tar.c | 2 +- lib/libarchive/archive_read_support_format_zip.c | 2 +- lib/libarchive/archive_string.h | 7 +- lib/libarchive/archive_write_disk.c | 2 +- lib/libarchive/archive_write_set_compression_xz.c | 3 +- lib/libarchive/archive_write_set_format_ar.c | 2 +- lib/libarchive/archive_write_set_format_shar.c | 3 +- lib/libarchive/archive_write_set_format_ustar.c | 2 +- lib/libarchive/config_freebsd.h | 1 + lib/libarchive/libarchive-formats.5 | 1 + lib/libarchive/libarchive.3 | 2 + lib/libarchive/test/Makefile | 2 +- lib/libarchive/test/test_compat_zip.c | 2 +- lib/libarchive/test/test_read_format_iso_Z.c | 99 ++++++++++++++++++++++ lib/libarchive/test/test_read_format_iso_gz.c | 99 ---------------------- 21 files changed, 147 insertions(+), 133 deletions(-) create mode 100644 lib/libarchive/test/test_read_format_iso_Z.c delete mode 100644 lib/libarchive/test/test_read_format_iso_gz.c (limited to 'lib') diff --git a/lib/libarchive/archive.h b/lib/libarchive/archive.h index 7075e26..bac93f0 100644 --- a/lib/libarchive/archive.h +++ b/lib/libarchive/archive.h @@ -52,7 +52,7 @@ /* These should match the types used in 'struct stat' */ #if defined(_WIN32) && !defined(__CYGWIN__) #define __LA_INT64_T __int64 -# if defined(_SSIZE_T_DEFINED) +# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_) # define __LA_SSIZE_T ssize_t # elif defined(_WIN64) # define __LA_SSIZE_T __int64 @@ -98,6 +98,13 @@ # define __LA_DECL #endif +#if defined(__GNUC__) && __GNUC__ >= 3 +#define __LA_PRINTF(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#else +#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */ +#endif + #ifdef __cplusplus extern "C" { #endif @@ -129,13 +136,13 @@ extern "C" { * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000) * #endif */ -#define ARCHIVE_VERSION_NUMBER 2008004 +#define ARCHIVE_VERSION_NUMBER 2008005 __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_STRING "libarchive 2.8.4" +#define ARCHIVE_VERSION_STRING "libarchive 2.8.5" __LA_DECL const char * archive_version_string(void); #if ARCHIVE_VERSION_NUMBER < 3000000 @@ -717,7 +724,7 @@ __LA_DECL const char *archive_format_name(struct archive *); __LA_DECL int archive_format(struct archive *); __LA_DECL void archive_clear_error(struct archive *); __LA_DECL void archive_set_error(struct archive *, int _err, - const char *fmt, ...); + const char *fmt, ...) __LA_PRINTF(3, 4); __LA_DECL void archive_copy_error(struct archive *dest, struct archive *src); __LA_DECL int archive_file_count(struct archive *); diff --git a/lib/libarchive/archive_read.c b/lib/libarchive/archive_read.c index 7873d45..fb72407 100644 --- a/lib/libarchive/archive_read.c +++ b/lib/libarchive/archive_read.c @@ -715,7 +715,7 @@ archive_read_data_block(struct archive *_a, /* * Close the file and release most resources. * - * Be careful: client might just call read_new and then read_finish. + * Be careful: client might just call read_new and then read_free. * Don't assume we actually read anything or performed any non-trivial * initialization. */ diff --git a/lib/libarchive/archive_read_support_compression_bzip2.c b/lib/libarchive/archive_read_support_compression_bzip2.c index fc419d4..891742f 100644 --- a/lib/libarchive/archive_read_support_compression_bzip2.c +++ b/lib/libarchive/archive_read_support_compression_bzip2.c @@ -350,4 +350,4 @@ bzip2_filter_close(struct archive_read_filter *self) return (ret); } -#endif /* HAVE_BZLIB_H */ +#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */ diff --git a/lib/libarchive/archive_read_support_compression_uu.c b/lib/libarchive/archive_read_support_compression_uu.c index cb1dae5..1b6a54c 100644 --- a/lib/libarchive/archive_read_support_compression_uu.c +++ b/lib/libarchive/archive_read_support_compression_uu.c @@ -488,9 +488,9 @@ read_more: switch (uudecode->state) { default: case ST_FIND_HEAD: - if (len - nl > 13 && memcmp(b, "begin ", 6) == 0) + if (len - nl >= 11 && memcmp(b, "begin ", 6) == 0) l = 6; - else if (len - nl > 18 && + else if (len - nl >= 18 && memcmp(b, "begin-base64 ", 13) == 0) l = 13; else diff --git a/lib/libarchive/archive_read_support_format_cpio.c b/lib/libarchive/archive_read_support_format_cpio.c index 24f3d35..790fa7a 100644 --- a/lib/libarchive/archive_read_support_format_cpio.c +++ b/lib/libarchive/archive_read_support_format_cpio.c @@ -264,9 +264,9 @@ archive_read_format_cpio_read_header(struct archive_read *a, /* Compare name to "TRAILER!!!" to test for end-of-archive. */ if (namelength == 11 && strcmp((const char *)h, "TRAILER!!!") == 0) { - /* TODO: Store file location of start of block. */ - archive_set_error(&a->archive, 0, NULL); - return (ARCHIVE_EOF); + /* TODO: Store file location of start of block. */ + archive_clear_error(&a->archive); + return (ARCHIVE_EOF); } /* Detect and record hardlinks to previously-extracted entries. */ diff --git a/lib/libarchive/archive_read_support_format_iso9660.c b/lib/libarchive/archive_read_support_format_iso9660.c index 0216461..6d8d304 100644 --- a/lib/libarchive/archive_read_support_format_iso9660.c +++ b/lib/libarchive/archive_read_support_format_iso9660.c @@ -934,14 +934,14 @@ read_children(struct archive_read *a, struct file_info *parent) archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Ignoring out-of-order directory (%s) %jd > %jd", parent->name.s, - iso9660->current_position, - parent->offset); + (intmax_t)iso9660->current_position, + (intmax_t)parent->offset); return (ARCHIVE_WARN); } if (parent->offset + parent->size > iso9660->volume_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Directory is beyond end-of-media: %s", - parent->name); + parent->name.s); return (ARCHIVE_WARN); } if (iso9660->current_position < parent->offset) { @@ -1139,7 +1139,7 @@ archive_read_format_iso9660_read_header(struct archive_read *a, if (file->offset + file->size > iso9660->volume_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "File is beyond end-of-media: %s", file->name); + "File is beyond end-of-media: %s", file->name.s); iso9660->entry_bytes_remaining = 0; iso9660->entry_sparse_offset = 0; return (ARCHIVE_WARN); @@ -1198,10 +1198,10 @@ archive_read_format_iso9660_read_header(struct archive_read *a, if ((file->mode & AE_IFMT) != AE_IFDIR && file->offset < iso9660->current_position) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring out-of-order file @%x (%s) %jd < %jd", - file, + "Ignoring out-of-order file (%s) %jd < %jd", iso9660->pathname.s, - file->offset, iso9660->current_position); + (intmax_t)file->offset, + (intmax_t)iso9660->current_position); iso9660->entry_bytes_remaining = 0; iso9660->entry_sparse_offset = 0; return (ARCHIVE_WARN); @@ -1524,8 +1524,8 @@ archive_read_format_iso9660_read_data(struct archive_read *a, archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Ignoring out-of-order file (%s) %jd < %jd", iso9660->pathname.s, - iso9660->entry_content->offset, - iso9660->current_position); + (intmax_t)iso9660->entry_content->offset, + (intmax_t)iso9660->current_position); *buff = NULL; *size = 0; *offset = iso9660->entry_sparse_offset; @@ -1626,8 +1626,8 @@ parse_file_info(struct archive_read *a, struct file_info *parent, */ if (location > 0 && (location + ((fsize + iso9660->logical_block_size -1) - / iso9660->logical_block_size)) > - (unsigned int)iso9660->volume_block) { + / iso9660->logical_block_size)) + > (uint32_t)iso9660->volume_block) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Invalid location of extent of file"); return (NULL); diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c index 20e1293..62be309 100644 --- a/lib/libarchive/archive_read_support_format_tar.c +++ b/lib/libarchive/archive_read_support_format_tar.c @@ -576,7 +576,7 @@ tar_read_header(struct archive_read *a, struct tar *tar, h = __archive_read_ahead(a, 512, NULL); if (h != NULL) __archive_read_consume(a, 512); - archive_set_error(&a->archive, 0, NULL); + archive_clear_error(&a->archive); if (a->archive.archive_format_name == NULL) { a->archive.archive_format = ARCHIVE_FORMAT_TAR; a->archive.archive_format_name = "tar"; diff --git a/lib/libarchive/archive_read_support_format_zip.c b/lib/libarchive/archive_read_support_format_zip.c index 0fa1fa3..a02a2c2 100644 --- a/lib/libarchive/archive_read_support_format_zip.c +++ b/lib/libarchive/archive_read_support_format_zip.c @@ -211,7 +211,7 @@ archive_read_format_zip_bid(struct archive_read *a) /* Get 4k of data beyond where we stopped. */ buff = __archive_read_ahead(a, offset + 4096, &bytes_avail); - if (bytes_avail < offset + 1) + if (buff == NULL) break; p = (const char *)buff + offset; while (p + 9 < (const char *)buff + bytes_avail) { diff --git a/lib/libarchive/archive_string.h b/lib/libarchive/archive_string.h index 68fbf16..f0655d1 100644 --- a/lib/libarchive/archive_string.h +++ b/lib/libarchive/archive_string.h @@ -44,6 +44,8 @@ #include #endif +#include "archive.h" + /* * Basic resizable/reusable string support a la Java's "StringBuffer." * @@ -134,10 +136,11 @@ void __archive_string_free(struct archive_string *); /* Like 'vsprintf', but resizes the underlying string as necessary. */ void __archive_string_vsprintf(struct archive_string *, const char *, - va_list); + va_list) __LA_PRINTF(2, 0); #define archive_string_vsprintf __archive_string_vsprintf -void __archive_string_sprintf(struct archive_string *, const char *, ...); +void __archive_string_sprintf(struct archive_string *, const char *, ...) + __LA_PRINTF(2, 3); #define archive_string_sprintf __archive_string_sprintf /* Allocates a fresh buffer and converts as (assumed to be UTF-8) into it. diff --git a/lib/libarchive/archive_write_disk.c b/lib/libarchive/archive_write_disk.c index 8a4fd04..2319220 100644 --- a/lib/libarchive/archive_write_disk.c +++ b/lib/libarchive/archive_write_disk.c @@ -1730,7 +1730,7 @@ create_dir(struct archive_write_disk *a, char *path) if (unlink(path) != 0) { archive_set_error(&a->archive, errno, "Can't create directory '%s': " - "Conflicting file cannot be removed"); + "Conflicting file cannot be removed", path); return (ARCHIVE_FAILED); } } else if (errno != ENOENT && errno != ENOTDIR) { diff --git a/lib/libarchive/archive_write_set_compression_xz.c b/lib/libarchive/archive_write_set_compression_xz.c index d97bca7..15b6cc2 100644 --- a/lib/libarchive/archive_write_set_compression_xz.c +++ b/lib/libarchive/archive_write_set_compression_xz.c @@ -132,9 +132,10 @@ static int archive_compressor_xz_init_stream(struct archive_write *a, struct private_data *state) { + static const lzma_stream lzma_stream_init_data = LZMA_STREAM_INIT; int ret; - state->stream = (lzma_stream)LZMA_STREAM_INIT; + state->stream = lzma_stream_init_data; state->stream.next_out = state->compressed; state->stream.avail_out = state->compressed_buffer_size; if (a->archive.compression_code == ARCHIVE_COMPRESSION_XZ) diff --git a/lib/libarchive/archive_write_set_format_ar.c b/lib/libarchive/archive_write_set_format_ar.c index bffe07c..cb8ddaa 100644 --- a/lib/libarchive/archive_write_set_format_ar.c +++ b/lib/libarchive/archive_write_set_format_ar.c @@ -440,7 +440,7 @@ archive_write_ar_finish_entry(struct archive_write *a) if (ar->entry_padding != 1) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Padding wrong size: %d should be 1 or 0", - ar->entry_padding); + (int)ar->entry_padding); return (ARCHIVE_WARN); } diff --git a/lib/libarchive/archive_write_set_format_shar.c b/lib/libarchive/archive_write_set_format_shar.c index 6cb58e8..bd62768 100644 --- a/lib/libarchive/archive_write_set_format_shar.c +++ b/lib/libarchive/archive_write_set_format_shar.c @@ -537,8 +537,7 @@ archive_write_shar_finish_entry(struct archive_write *a) } if ((p = archive_entry_fflags_text(shar->entry)) != NULL) { - archive_string_sprintf(&shar->work, "chflags %s ", - p, archive_entry_pathname(shar->entry)); + archive_string_sprintf(&shar->work, "chflags %s ", p); shar_quote(&shar->work, archive_entry_pathname(shar->entry), 1); archive_strcat(&shar->work, "\n"); diff --git a/lib/libarchive/archive_write_set_format_ustar.c b/lib/libarchive/archive_write_set_format_ustar.c index 2de0cf1..54893d4 100644 --- a/lib/libarchive/archive_write_set_format_ustar.c +++ b/lib/libarchive/archive_write_set_format_ustar.c @@ -168,7 +168,7 @@ archive_write_set_format_ustar(struct archive *_a) /* Basic internal sanity test. */ if (sizeof(template_header) != 512) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %d should be 512", sizeof(template_header)); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %d should be 512", (int)sizeof(template_header)); return (ARCHIVE_FATAL); } diff --git a/lib/libarchive/config_freebsd.h b/lib/libarchive/config_freebsd.h index a39a1fb..b4694ea1 100644 --- a/lib/libarchive/config_freebsd.h +++ b/lib/libarchive/config_freebsd.h @@ -68,6 +68,7 @@ #endif #define HAVE_BSDXML_H 1 +#define HAVE_BZLIB_H 1 #define HAVE_CHFLAGS 1 #define HAVE_CHOWN 1 #define HAVE_DECL_EXTATTR_NAMESPACE_USER 1 diff --git a/lib/libarchive/libarchive-formats.5 b/lib/libarchive/libarchive-formats.5 index ef4b6ca..e6849b9 100644 --- a/lib/libarchive/libarchive-formats.5 +++ b/lib/libarchive/libarchive-formats.5 @@ -65,6 +65,7 @@ Later variants have extended this by either appropriating undefined areas of the header record, extending the header to multiple records, or by storing special entries that modify the interpretation of subsequent entries. +.Pp .Bl -tag -width indent .It Cm gnutar The diff --git a/lib/libarchive/libarchive.3 b/lib/libarchive/libarchive.3 index 115a79c..70059dc 100644 --- a/lib/libarchive/libarchive.3 +++ b/lib/libarchive/libarchive.3 @@ -177,6 +177,8 @@ which provides a slightly more efficient interface. You may prefer to use the higher-level .Fn archive_read_data_skip , which reads and discards the data for this entry, +.Fn archive_read_data_to_buffer , +which reads the data into an in-memory buffer, .Fn archive_read_data_to_file , which copies the data to the provided file descriptor, or .Fn archive_read_extract , diff --git a/lib/libarchive/test/Makefile b/lib/libarchive/test/Makefile index ba72db7..e05ff1f 100644 --- a/lib/libarchive/test/Makefile +++ b/lib/libarchive/test/Makefile @@ -52,7 +52,7 @@ TESTS= \ test_read_format_gtar_gz.c \ test_read_format_gtar_lzma.c \ test_read_format_gtar_sparse.c \ - test_read_format_iso_gz.c \ + test_read_format_iso_Z.c \ test_read_format_iso_multi_extent.c \ test_read_format_isorr_rr_moved.c \ test_read_format_isojoliet_bz2.c \ diff --git a/lib/libarchive/test/test_compat_zip.c b/lib/libarchive/test/test_compat_zip.c index adb377c..7c1bde7 100644 --- a/lib/libarchive/test/test_compat_zip.c +++ b/lib/libarchive/test/test_compat_zip.c @@ -67,7 +67,7 @@ finish: #if ARCHIVE_VERSION_NUMBER < 2000000 archive_read_finish(a); #else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); #endif } diff --git a/lib/libarchive/test/test_read_format_iso_Z.c b/lib/libarchive/test/test_read_format_iso_Z.c new file mode 100644 index 0000000..2d60d41 --- /dev/null +++ b/lib/libarchive/test/test_read_format_iso_Z.c @@ -0,0 +1,99 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +static void +test1(void) +{ + struct archive_entry *ae; + struct archive *a; + const char *name = "test_read_format_iso.iso.Z"; + + extract_reference_file(name); + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, name, 512)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} + +static +void test2(void) +{ + struct archive_entry *ae; + struct archive *a; + const char *name = "test_read_format_iso_2.iso.Z"; + + extract_reference_file(name); + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, name, 512)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString(".", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString("A", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString("A/B", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString("C", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString("C/D", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} + +DEFINE_TEST(test_read_format_iso_Z) +{ + test1(); + test2(); +} + + diff --git a/lib/libarchive/test/test_read_format_iso_gz.c b/lib/libarchive/test/test_read_format_iso_gz.c deleted file mode 100644 index d0d6b3c..0000000 --- a/lib/libarchive/test/test_read_format_iso_gz.c +++ /dev/null @@ -1,99 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static void -test1(void) -{ - struct archive_entry *ae; - struct archive *a; - const char *name = "test_read_format_iso.iso.Z"; - - extract_reference_file(name); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_filename(a, name, 512)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - -static -void test2(void) -{ - struct archive_entry *ae; - struct archive *a; - const char *name = "test_read_format_iso_2.iso.Z"; - - extract_reference_file(name); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_filename(a, name, 512)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString(".", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString("A", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString("A/B", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString("C", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString("C/D", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - -DEFINE_TEST(test_read_format_iso_gz) -{ - test1(); - test2(); -} - - -- cgit v1.1 From f3adf4b52d600e699c5d826866cb5f4c520bb5a3 Mon Sep 17 00:00:00 2001 From: mm Date: Tue, 20 Dec 2011 20:34:02 +0000 Subject: Sync libarchive with vendor branch release/2.8: 3730: Fix issue 174 (Windows path names, not relevant for FreeBSD) 3734: Merge r1989: archive_clear_error should set errno to 0. 3735: Merge r3247 from trunk: Clear errors before returning from archive_read_support_format_all() 3799: Check the position before dereferencing the pointer. This avoids dereferencing one byte past the end of a string 3824: Merge r3823 from trunk for issue 199 (hang in iso9660 reading) Obtained from: http://code.google.com/p/libarchive MFC after: 2 weeks --- lib/libarchive/archive_read_support_format_all.c | 10 +- .../archive_read_support_format_iso9660.c | 10 +- lib/libarchive/archive_string.c | 2 +- lib/libarchive/archive_util.c | 1 + lib/libarchive/archive_write_disk.c | 104 +++++++++++++++++++-- 5 files changed, 114 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/libarchive/archive_read_support_format_all.c b/lib/libarchive/archive_read_support_format_all.c index 69d16fc..e57cd43 100644 --- a/lib/libarchive/archive_read_support_format_all.c +++ b/lib/libarchive/archive_read_support_format_all.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2011 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,5 +39,13 @@ archive_read_support_format_all(struct archive *a) archive_read_support_format_tar(a); archive_read_support_format_xar(a); archive_read_support_format_zip(a); + + /* Note: We always return ARCHIVE_OK here, even if some of the + * above return ARCHIVE_WARN. The intent here is to enable + * "as much as possible." Clients who need specific + * compression should enable those individually so they can + * verify the level of support. */ + /* Clear any warning messages set by the above functions. */ + archive_clear_error(a); return (ARCHIVE_OK); } diff --git a/lib/libarchive/archive_read_support_format_iso9660.c b/lib/libarchive/archive_read_support_format_iso9660.c index 6d8d304..f014eb3 100644 --- a/lib/libarchive/archive_read_support_format_iso9660.c +++ b/lib/libarchive/archive_read_support_format_iso9660.c @@ -302,6 +302,8 @@ struct file_info { struct file_info *first; struct file_info **last; } rede_files; + /* To check a ininity loop. */ + struct file_info *loop_by; }; struct heap_queue { @@ -2699,8 +2701,14 @@ rede_add_entry(struct file_info *file) struct file_info *re; re = file->parent; - while (re != NULL && !re->re) + while (re != NULL && !re->re) { + /* Sanity check to prevent a infinity loop + * cause by a currupted iso file. */ + if (re->loop_by == file) + return (-1); + re->loop_by = file; re = re->parent; + } if (re == NULL) return (-1); diff --git a/lib/libarchive/archive_string.c b/lib/libarchive/archive_string.c index d68ad58..c67182d 100644 --- a/lib/libarchive/archive_string.c +++ b/lib/libarchive/archive_string.c @@ -152,7 +152,7 @@ __archive_strncat(struct archive_string *as, const void *_p, size_t n) /* Like strlen(p), except won't examine positions beyond p[n]. */ s = 0; pp = p; - while (*pp && s < n) { + while (s < n && *pp) { pp++; s++; } diff --git a/lib/libarchive/archive_util.c b/lib/libarchive/archive_util.c index 4c0de02..8f2b4c6 100644 --- a/lib/libarchive/archive_util.c +++ b/lib/libarchive/archive_util.c @@ -155,6 +155,7 @@ archive_clear_error(struct archive *a) { archive_string_empty(&a->error_string); a->error = NULL; + a->archive_error_number = 0; } void diff --git a/lib/libarchive/archive_write_disk.c b/lib/libarchive/archive_write_disk.c index 2319220..49ced58 100644 --- a/lib/libarchive/archive_write_disk.c +++ b/lib/libarchive/archive_write_disk.c @@ -1513,6 +1513,22 @@ check_symlinks(struct archive_write_disk *a) } #if defined(_WIN32) || defined(__CYGWIN__) +static int +guidword(const char *p, int n) +{ + int i; + + for (i = 0; i < n; i++) { + if ((*p >= '0' && *p <= '9') || + (*p >= 'a' && *p <= 'f') || + (*p >= 'A' && *p <= 'F')) + p++; + else + return (-1); + } + return (0); +} + /* * 1. Convert a path separator from '\' to '/' . * We shouldn't check multi-byte character directly because some @@ -1521,26 +1537,92 @@ check_symlinks(struct archive_write_disk *a) * 2. Replace unusable characters in Windows with underscore('_'). * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx */ -static void +static int cleanup_pathname_win(struct archive_write_disk *a) { wchar_t wc; char *p; size_t alen, l; - alen = 0; - l = 0; - for (p = a->name; *p != '\0'; p++) { - ++alen; - if (*p == '\\') - l = 1; + p = a->name; + /* Skip leading "\\.\" or "\\?\" or "\\?\UNC\" or + * "\\?\Volume{GUID}\" + * (absolute path prefixes used by Windows API) */ + if ((p[0] == '\\' || p[0] == '/') && (p[1] == '\\' || p[1] == '/' ) && + (p[2] == '.' || p[2] == '?') && (p[3] == '\\' || p[3] == '/')) + { + /* A path begin with "\\?\UNC\" */ + if (p[2] == '?' && + (p[4] == 'U' || p[4] == 'u') && + (p[5] == 'N' || p[5] == 'n') && + (p[6] == 'C' || p[6] == 'c') && + (p[7] == '\\' || p[7] == '/')) + p += 8; + /* A path begin with "\\?\Volume{GUID}\" */ + else if (p[2] == '?' && + (p[4] == 'V' || p[4] == 'v') && + (p[5] == 'O' || p[5] == 'o') && + (p[6] == 'L' || p[6] == 'l') && + (p[7] == 'U' || p[7] == 'u') && + (p[8] == 'M' || p[8] == 'm') && + (p[9] == 'E' || p[9] == 'e') && + p[10] == '{') { + if (guidword(p+11, 8) == 0 && p[19] == '-' && + guidword(p+20, 4) == 0 && p[24] == '-' && + guidword(p+25, 4) == 0 && p[29] == '-' && + guidword(p+30, 4) == 0 && p[34] == '-' && + guidword(p+35, 12) == 0 && p[47] == '}' && + (p[48] == '\\' || p[48] == '/')) + p += 49; + else + p += 4; + /* A path begin with "\\.\PhysicalDriveX" */ + } else if (p[2] == '.' && + (p[4] == 'P' || p[4] == 'p') && + (p[5] == 'H' || p[5] == 'h') && + (p[6] == 'Y' || p[6] == 'y') && + (p[7] == 'S' || p[7] == 's') && + (p[8] == 'I' || p[8] == 'i') && + (p[9] == 'C' || p[9] == 'c') && + (p[9] == 'A' || p[9] == 'a') && + (p[9] == 'L' || p[9] == 'l') && + (p[9] == 'D' || p[9] == 'd') && + (p[9] == 'R' || p[9] == 'r') && + (p[9] == 'I' || p[9] == 'i') && + (p[9] == 'V' || p[9] == 'v') && + (p[9] == 'E' || p[9] == 'e') && + (p[10] >= '0' && p[10] <= '9') && + p[11] == '\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Path is a physical drive name"); + return (ARCHIVE_FAILED); + } else + p += 4; + } + + /* Skip leading drive letter from archives created + * on Windows. */ + if (((p[0] >= 'a' && p[0] <= 'z') || + (p[0] >= 'A' && p[0] <= 'Z')) && + p[1] == ':') { + if (p[2] == '\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Path is a drive name"); + return (ARCHIVE_FAILED); + } + if (p[2] == '\\' || p[2] == '/') + p += 3; + } + + for (; *p != '\0'; p++) { /* Rewrite the path name if its character is a unusable. */ if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || *p == '<' || *p == '>' || *p == '|') *p = '_'; } - if (alen == 0 || l == 0) - return; + alen = p - a->name; + if (alen == 0 || strchr(a->name, '\\') == NULL) + return (ARCHIVE_OK); /* * Convert path separator. */ @@ -1560,6 +1642,7 @@ cleanup_pathname_win(struct archive_write_disk *a) p += l; alen -= l; } + return (ARCHIVE_OK); } #endif @@ -1583,7 +1666,8 @@ cleanup_pathname(struct archive_write_disk *a) } #if defined(_WIN32) || defined(__CYGWIN__) - cleanup_pathname_win(a); + if (cleanup_pathname_win(a) != ARCHIVE_OK) + return (ARCHIVE_FAILED); #endif /* Skip leading '/'. */ if (*src == '/') -- cgit v1.1 From 2d67f772cb9e14a0ad6ac92f1eb072705aa1fb38 Mon Sep 17 00:00:00 2001 From: eadler Date: Tue, 20 Dec 2011 22:56:13 +0000 Subject: - Add restrict keyword to glob(3) PR: kern/161958 Submitted by: Henning Petersen Approved by: jilles MFC after: 3 days --- lib/libc/gen/glob.3 | 4 ++-- lib/libc/gen/glob.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/libc/gen/glob.3 b/lib/libc/gen/glob.3 index 7d6e43b..468a73b 100644 --- a/lib/libc/gen/glob.3 +++ b/lib/libc/gen/glob.3 @@ -30,7 +30,7 @@ .\" @(#)glob.3 8.3 (Berkeley) 4/16/94 .\" $FreeBSD$ .\" -.Dd February 15, 2011 +.Dd December 20, 2011 .Dt GLOB 3 .Os .Sh NAME @@ -42,7 +42,7 @@ .Sh SYNOPSIS .In glob.h .Ft int -.Fn glob "const char *pattern" "int flags" "int (*errfunc)(const char *, int)" "glob_t *pglob" +.Fn glob "const char * restrict pattern" "int flags" "int (*errfunc)(const char *, int)" "glob_t * restrict pglob" .Ft void .Fn globfree "glob_t *pglob" .Sh DESCRIPTION diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c index 59663d9..f3ae50f 100644 --- a/lib/libc/gen/glob.c +++ b/lib/libc/gen/glob.c @@ -168,7 +168,8 @@ static void qprintf(const char *, Char *); #endif int -glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) +glob(const char * __restrict pattern, int flags, + int (*errfunc)(const char *, int), glob_t * __restrict pglob) { const char *patnext; size_t limit; -- cgit v1.1 From c5305afb95d3257a16946735a6eafc1a34d5d17a Mon Sep 17 00:00:00 2001 From: eadler Date: Tue, 20 Dec 2011 22:56:44 +0000 Subject: - Fix style(9) bugs in glob.c Approved by: jilles --- lib/libc/gen/glob.c | 70 ++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c index f3ae50f..211b535 100644 --- a/lib/libc/gen/glob.c +++ b/lib/libc/gen/glob.c @@ -232,9 +232,9 @@ glob(const char * __restrict pattern, int flags, *bufnext = EOS; if (flags & GLOB_BRACE) - return globexp1(patbuf, pglob, &limit); + return (globexp1(patbuf, pglob, &limit)); else - return glob0(patbuf, pglob, &limit); + return (glob0(patbuf, pglob, &limit)); } /* @@ -304,7 +304,7 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, size_t *l /* Non matching braces; just glob the pattern */ if (i != 0 || *pe == EOS) { *rv = glob0(patbuf, pglob, limit); - return 0; + return (0); } for (i = 0, pl = pm = ptr; pm <= pe; pm++) @@ -361,7 +361,7 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, size_t *l break; } *rv = 0; - return 0; + return (0); } @@ -378,7 +378,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) Char *b, *eb; if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE)) - return pattern; + return (pattern); /* * Copy up to the end of the string or / @@ -403,7 +403,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) (pwd = getpwuid(getuid())) != NULL) h = pwd->pw_dir; else - return pattern; + return (pattern); } } else { @@ -411,7 +411,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) * Expand a ~user */ if ((pwd = getpwnam((char*) patbuf)) == NULL) - return pattern; + return (pattern); else h = pwd->pw_dir; } @@ -425,7 +425,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) continue; *b = EOS; - return patbuf; + return (patbuf); } @@ -512,20 +512,20 @@ glob0(const Char *pattern, glob_t *pglob, size_t *limit) if (((pglob->gl_flags & GLOB_NOCHECK) || ((pglob->gl_flags & GLOB_NOMAGIC) && !(pglob->gl_flags & GLOB_MAGCHAR)))) - return(globextend(pattern, pglob, limit)); + return (globextend(pattern, pglob, limit)); else - return(GLOB_NOMATCH); + return (GLOB_NOMATCH); } if (!(pglob->gl_flags & GLOB_NOSORT)) qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, pglob->gl_pathc - oldpathc, sizeof(char *), compare); - return(0); + return (0); } static int compare(const void *p, const void *q) { - return(strcmp(*(char **)p, *(char **)q)); + return (strcmp(*(char **)p, *(char **)q)); } static int @@ -535,8 +535,8 @@ glob1(Char *pattern, glob_t *pglob, size_t *limit) /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ if (*pattern == EOS) - return(0); - return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, + return (0); + return (glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, pattern, pglob, limit)); } @@ -561,7 +561,7 @@ glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern, if (*pattern == EOS) { /* End of pattern? */ *pathend = EOS; if (g_lstat(pathbuf, &sb, pglob)) - return(0); + return (0); if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) @@ -574,7 +574,7 @@ glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern, *pathend = EOS; } ++pglob->gl_matchc; - return(globextend(pathbuf, pglob, limit)); + return (globextend(pathbuf, pglob, limit)); } /* Find end of next segment, copy tentatively to pathend. */ @@ -597,8 +597,8 @@ glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern, *pathend++ = *pattern++; } } else /* Need expansion, recurse. */ - return(glob3(pathbuf, pathend, pathend_last, pattern, p, - pglob, limit)); + return (glob3(pathbuf, pathend, pathend_last, pattern, + p, pglob, limit)); } /* NOTREACHED */ } @@ -635,7 +635,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last, pglob->gl_flags & GLOB_ERR) return (GLOB_ABORTED); } - return(0); + return (0); } err = 0; @@ -683,7 +683,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last, (*pglob->gl_closedir)(dirp); else closedir(dirp); - return(err); + return (err); } @@ -723,7 +723,7 @@ globextend(const Char *path, glob_t *pglob, size_t *limit) free(pglob->gl_pathv); pglob->gl_pathv = NULL; } - return(GLOB_NOSPACE); + return (GLOB_NOSPACE); } if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { @@ -745,7 +745,7 @@ globextend(const Char *path, glob_t *pglob, size_t *limit) pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; } pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; - return(copy == NULL ? GLOB_NOSPACE : 0); + return (copy == NULL ? GLOB_NOSPACE : 0); } /* @@ -765,20 +765,20 @@ match(Char *name, Char *pat, Char *patend) switch (c & M_MASK) { case M_ALL: if (pat == patend) - return(1); + return (1); do if (match(name, pat, patend)) - return(1); + return (1); while (*name++ != EOS); - return(0); + return (0); case M_ONE: if (*name++ == EOS) - return(0); + return (0); break; case M_SET: ok = 0; if ((k = *name++) == EOS) - return(0); + return (0); if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) ++pat; while (((c = *pat++) & M_MASK) != M_END) @@ -793,15 +793,15 @@ match(Char *name, Char *pat, Char *patend) } else if (c == k) ok = 1; if (ok == negate_range) - return(0); + return (0); break; default: if (*name++ != c) - return(0); + return (0); break; } } - return(*name == EOS); + return (*name == EOS); } /* Free allocated data belonging to a glob_t structure. */ @@ -834,9 +834,9 @@ g_opendir(Char *str, glob_t *pglob) } if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_opendir)(buf)); + return ((*pglob->gl_opendir)(buf)); - return(opendir(buf)); + return (opendir(buf)); } static int @@ -850,7 +850,7 @@ g_lstat(Char *fn, struct stat *sb, glob_t *pglob) } if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_lstat)(buf, sb)); - return(lstat(buf, sb)); + return (lstat(buf, sb)); } static int @@ -863,8 +863,8 @@ g_stat(Char *fn, struct stat *sb, glob_t *pglob) return (-1); } if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_stat)(buf, sb)); - return(stat(buf, sb)); + return ((*pglob->gl_stat)(buf, sb)); + return (stat(buf, sb)); } static const Char * -- cgit v1.1 From 2942879b6ed0f413f59c085747271ea20b06e8f1 Mon Sep 17 00:00:00 2001 From: mm Date: Thu, 22 Dec 2011 08:42:07 +0000 Subject: Use contrib sources for building libarchive, tar and cpio. Make "make test" fully operational. MFC after: 2 weeks --- lib/libarchive/COPYING | 36 - lib/libarchive/Makefile | 13 +- lib/libarchive/README | 102 - lib/libarchive/archive.h | 746 ----- lib/libarchive/archive_check_magic.c | 134 - lib/libarchive/archive_crc32.h | 66 - lib/libarchive/archive_endian.h | 162 - lib/libarchive/archive_entry.3 | 433 --- lib/libarchive/archive_entry.c | 2202 -------------- lib/libarchive/archive_entry.h | 524 ---- lib/libarchive/archive_entry_copy_stat.c | 77 - lib/libarchive/archive_entry_link_resolver.c | 405 --- lib/libarchive/archive_entry_private.h | 184 -- lib/libarchive/archive_entry_stat.c | 118 - lib/libarchive/archive_entry_strmode.c | 87 - lib/libarchive/archive_entry_xattr.c | 158 - lib/libarchive/archive_hash.h | 309 -- lib/libarchive/archive_platform.h | 165 - lib/libarchive/archive_private.h | 124 - lib/libarchive/archive_read.3 | 714 ----- lib/libarchive/archive_read.c | 1249 -------- lib/libarchive/archive_read_data_into_fd.c | 93 - lib/libarchive/archive_read_disk.3 | 308 -- lib/libarchive/archive_read_disk.c | 198 -- lib/libarchive/archive_read_disk_entry_from_file.c | 570 ---- lib/libarchive/archive_read_disk_private.h | 62 - .../archive_read_disk_set_standard_lookup.c | 303 -- lib/libarchive/archive_read_extract.c | 180 -- lib/libarchive/archive_read_open_fd.c | 190 -- lib/libarchive/archive_read_open_file.c | 165 - lib/libarchive/archive_read_open_filename.c | 272 -- lib/libarchive/archive_read_open_memory.c | 156 - lib/libarchive/archive_read_private.h | 199 -- .../archive_read_support_compression_all.c | 60 - .../archive_read_support_compression_bzip2.c | 353 --- .../archive_read_support_compression_compress.c | 444 --- .../archive_read_support_compression_gzip.c | 465 --- .../archive_read_support_compression_none.c | 40 - .../archive_read_support_compression_program.c | 459 --- .../archive_read_support_compression_rpm.c | 288 -- .../archive_read_support_compression_uu.c | 637 ---- .../archive_read_support_compression_xz.c | 708 ----- lib/libarchive/archive_read_support_format_all.c | 51 - lib/libarchive/archive_read_support_format_ar.c | 584 ---- lib/libarchive/archive_read_support_format_cpio.c | 777 ----- lib/libarchive/archive_read_support_format_empty.c | 93 - .../archive_read_support_format_iso9660.c | 2964 ------------------ lib/libarchive/archive_read_support_format_mtree.c | 1309 -------- lib/libarchive/archive_read_support_format_raw.c | 185 -- lib/libarchive/archive_read_support_format_tar.c | 2418 --------------- lib/libarchive/archive_read_support_format_xar.c | 3151 -------------------- lib/libarchive/archive_read_support_format_zip.c | 950 ------ lib/libarchive/archive_string.c | 453 --- lib/libarchive/archive_string.h | 151 - lib/libarchive/archive_string_sprintf.c | 164 - lib/libarchive/archive_util.3 | 160 - lib/libarchive/archive_util.c | 392 --- lib/libarchive/archive_virtual.c | 98 - lib/libarchive/archive_write.3 | 629 ---- lib/libarchive/archive_write.c | 466 --- lib/libarchive/archive_write_disk.3 | 375 --- lib/libarchive/archive_write_disk.c | 2712 ----------------- lib/libarchive/archive_write_disk_private.h | 38 - .../archive_write_disk_set_standard_lookup.c | 262 -- lib/libarchive/archive_write_open_fd.c | 144 - lib/libarchive/archive_write_open_file.c | 109 - lib/libarchive/archive_write_open_filename.c | 166 -- lib/libarchive/archive_write_open_memory.c | 126 - lib/libarchive/archive_write_private.h | 122 - .../archive_write_set_compression_bzip2.c | 408 --- .../archive_write_set_compression_compress.c | 492 --- .../archive_write_set_compression_gzip.c | 477 --- .../archive_write_set_compression_none.c | 257 -- .../archive_write_set_compression_program.c | 347 --- lib/libarchive/archive_write_set_compression_xz.c | 439 --- lib/libarchive/archive_write_set_format.c | 72 - lib/libarchive/archive_write_set_format_ar.c | 550 ---- lib/libarchive/archive_write_set_format_by_name.c | 76 - lib/libarchive/archive_write_set_format_cpio.c | 344 --- .../archive_write_set_format_cpio_newc.c | 295 -- lib/libarchive/archive_write_set_format_mtree.c | 1050 ------- lib/libarchive/archive_write_set_format_pax.c | 1386 --------- lib/libarchive/archive_write_set_format_shar.c | 625 ---- lib/libarchive/archive_write_set_format_ustar.c | 587 ---- lib/libarchive/archive_write_set_format_zip.c | 670 ----- lib/libarchive/cpio.5 | 325 -- lib/libarchive/filter_fork.c | 161 - lib/libarchive/filter_fork.h | 41 - lib/libarchive/libarchive-formats.5 | 355 --- lib/libarchive/libarchive.3 | 371 --- lib/libarchive/libarchive_fe/err.c | 74 - lib/libarchive/libarchive_fe/err.h | 43 - lib/libarchive/libarchive_fe/lafe_platform.h | 55 - lib/libarchive/libarchive_fe/line_reader.c | 171 -- lib/libarchive/libarchive_fe/line_reader.h | 37 - lib/libarchive/libarchive_fe/matching.c | 281 -- lib/libarchive/libarchive_fe/matching.h | 46 - lib/libarchive/libarchive_fe/pathmatch.c | 255 -- lib/libarchive/libarchive_fe/pathmatch.h | 42 - lib/libarchive/libarchive_internals.3 | 365 --- lib/libarchive/tar.5 | 831 ------ lib/libarchive/test/.cvsignore | 10 - lib/libarchive/test/Makefile | 39 +- lib/libarchive/test/README | 63 - lib/libarchive/test/main.c | 2130 ------------- lib/libarchive/test/read_open_memory.c | 167 -- lib/libarchive/test/test.h | 302 -- lib/libarchive/test/test_acl_basic.c | 229 -- lib/libarchive/test/test_acl_freebsd.c | 260 -- lib/libarchive/test/test_acl_pax.c | 517 ---- lib/libarchive/test/test_archive_api_feature.c | 76 - lib/libarchive/test/test_bad_fd.c | 41 - lib/libarchive/test/test_compat_bzip2.c | 85 - lib/libarchive/test/test_compat_bzip2_1.tbz.uu | 24 - lib/libarchive/test/test_compat_bzip2_2.tbz.uu | 11 - lib/libarchive/test/test_compat_cpio.c | 106 - lib/libarchive/test/test_compat_cpio_1.cpio.uu | 19 - lib/libarchive/test/test_compat_gtar.c | 119 - lib/libarchive/test/test_compat_gtar_1.tar.uu | 232 -- lib/libarchive/test/test_compat_gzip.c | 97 - lib/libarchive/test/test_compat_gzip_1.tgz.uu | 24 - lib/libarchive/test/test_compat_gzip_2.tgz.uu | 11 - lib/libarchive/test/test_compat_lzma.c | 155 - lib/libarchive/test/test_compat_lzma_1.tlz.uu | 10 - lib/libarchive/test/test_compat_lzma_2.tlz.uu | 9 - lib/libarchive/test/test_compat_lzma_3.tlz.uu | 9 - lib/libarchive/test/test_compat_solaris_tar_acl.c | 128 - .../test/test_compat_solaris_tar_acl.tar.uu | 61 - lib/libarchive/test/test_compat_tar_hardlink.c | 108 - .../test/test_compat_tar_hardlink_1.tar.uu | 39 - lib/libarchive/test/test_compat_xz.c | 84 - lib/libarchive/test/test_compat_xz_1.txz.uu | 13 - lib/libarchive/test/test_compat_zip.c | 113 - lib/libarchive/test/test_compat_zip_1.zip.uu | 15 - lib/libarchive/test/test_compat_zip_2.zip.uu | 10 - lib/libarchive/test/test_empty_write.c | 120 - lib/libarchive/test/test_entry.c | 903 ------ lib/libarchive/test/test_entry_strmode.c | 71 - lib/libarchive/test/test_extattr_freebsd.c | 172 -- lib/libarchive/test/test_fuzz.c | 166 -- lib/libarchive/test/test_fuzz_1.iso.Z.uu | 495 --- lib/libarchive/test/test_link_resolver.c | 205 -- lib/libarchive/test/test_open_failure.c | 198 -- lib/libarchive/test/test_open_fd.c | 128 - lib/libarchive/test/test_open_file.c | 108 - lib/libarchive/test/test_open_filename.c | 109 - lib/libarchive/test/test_pax_filename_encoding.c | 333 --- .../test/test_pax_filename_encoding.tar.uu | 118 - lib/libarchive/test/test_read_compress_program.c | 84 - lib/libarchive/test/test_read_data_large.c | 125 - lib/libarchive/test/test_read_disk.c | 172 -- .../test/test_read_disk_entry_from_file.c | 80 - lib/libarchive/test/test_read_extract.c | 168 -- lib/libarchive/test/test_read_file_nonexistent.c | 37 - lib/libarchive/test/test_read_format_ar.ar.uu | 12 - lib/libarchive/test/test_read_format_ar.c | 87 - lib/libarchive/test/test_read_format_cpio_bin.c | 64 - lib/libarchive/test/test_read_format_cpio_bin_Z.c | 61 - lib/libarchive/test/test_read_format_cpio_bin_be.c | 55 - .../test/test_read_format_cpio_bin_be.cpio.uu | 8 - .../test/test_read_format_cpio_bin_bz2.c | 58 - lib/libarchive/test/test_read_format_cpio_bin_gz.c | 61 - .../test/test_read_format_cpio_bin_lzma.c | 60 - lib/libarchive/test/test_read_format_cpio_bin_xz.c | 70 - lib/libarchive/test/test_read_format_cpio_odc.c | 68 - .../test/test_read_format_cpio_svr4_bzip2_rpm.c | 128 - .../test_read_format_cpio_svr4_bzip2_rpm.rpm.uu | 49 - .../test/test_read_format_cpio_svr4_gzip.c | 61 - .../test/test_read_format_cpio_svr4_gzip_rpm.c | 128 - .../test_read_format_cpio_svr4_gzip_rpm.rpm.uu | 48 - .../test/test_read_format_cpio_svr4c_Z.c | 62 - lib/libarchive/test/test_read_format_empty.c | 47 - lib/libarchive/test/test_read_format_gtar_gz.c | 60 - lib/libarchive/test/test_read_format_gtar_lzma.c | 78 - lib/libarchive/test/test_read_format_gtar_sparse.c | 318 -- .../test/test_read_format_gtar_sparse_1_13.tar.uu | 1370 --------- .../test/test_read_format_gtar_sparse_1_17.tar.uu | 1370 --------- ...est_read_format_gtar_sparse_1_17_posix00.tar.uu | 1597 ---------- ...est_read_format_gtar_sparse_1_17_posix01.tar.uu | 1370 --------- ...est_read_format_gtar_sparse_1_17_posix10.tar.uu | 1370 --------- ...format_gtar_sparse_1_17_posix10_modified.tar.uu | 1370 --------- lib/libarchive/test/test_read_format_iso.iso.Z.uu | 26 - .../test/test_read_format_iso_2.iso.Z.uu | 37 - lib/libarchive/test/test_read_format_iso_Z.c | 99 - .../test/test_read_format_iso_joliet.iso.Z.uu | 66 - .../test/test_read_format_iso_joliet_long.iso.Z.uu | 71 - .../test_read_format_iso_joliet_rockridge.iso.Z.uu | 68 - .../test/test_read_format_iso_multi_extent.c | 94 - .../test_read_format_iso_multi_extent.iso.Z.uu | 67 - .../test/test_read_format_iso_rockridge.iso.Z.uu | 206 -- .../test_read_format_iso_rockridge_ce.iso.Z.uu | 63 - .../test_read_format_iso_rockridge_new.iso.Z.uu | 208 -- ...est_read_format_iso_rockridge_rr_moved.iso.Z.uu | 304 -- .../test/test_read_format_iso_zisofs.iso.Z.uu | 63 - .../test/test_read_format_isojoliet_bz2.c | 135 - .../test/test_read_format_isojoliet_long.c | 141 - .../test/test_read_format_isojoliet_rr.c | 160 - lib/libarchive/test/test_read_format_isorr_bz2.c | 203 -- lib/libarchive/test/test_read_format_isorr_ce.c | 223 -- .../test/test_read_format_isorr_new_bz2.c | 204 -- .../test/test_read_format_isorr_rr_moved.c | 270 -- .../test/test_read_format_isozisofs_bz2.c | 187 -- lib/libarchive/test/test_read_format_mtree.c | 186 -- .../test/test_read_format_mtree.mtree.uu | 13 - lib/libarchive/test/test_read_format_pax_bz2.c | 66 - lib/libarchive/test/test_read_format_raw.c | 89 - lib/libarchive/test/test_read_format_raw.data.Z.uu | 5 - lib/libarchive/test/test_read_format_raw.data.uu | 5 - lib/libarchive/test/test_read_format_tar.c | 480 --- .../test/test_read_format_tar_empty_filename.c | 66 - .../test_read_format_tar_empty_filename.tar.uu | 39 - lib/libarchive/test/test_read_format_tbz.c | 59 - lib/libarchive/test/test_read_format_tgz.c | 60 - lib/libarchive/test/test_read_format_tlz.c | 60 - lib/libarchive/test/test_read_format_txz.c | 63 - lib/libarchive/test/test_read_format_tz.c | 61 - lib/libarchive/test/test_read_format_xar.c | 697 ----- lib/libarchive/test/test_read_format_zip.c | 92 - lib/libarchive/test/test_read_format_zip.zip.uu | 14 - lib/libarchive/test/test_read_large.c | 93 - lib/libarchive/test/test_read_pax_truncated.c | 288 -- lib/libarchive/test/test_read_position.c | 94 - lib/libarchive/test/test_read_truncated.c | 149 - lib/libarchive/test/test_read_uu.c | 134 - lib/libarchive/test/test_tar_filenames.c | 186 -- lib/libarchive/test/test_tar_large.c | 312 -- lib/libarchive/test/test_ustar_filenames.c | 191 -- lib/libarchive/test/test_write_compress.c | 102 - lib/libarchive/test/test_write_compress_bzip2.c | 228 -- lib/libarchive/test/test_write_compress_gzip.c | 252 -- lib/libarchive/test/test_write_compress_lzma.c | 250 -- lib/libarchive/test/test_write_compress_program.c | 118 - lib/libarchive/test/test_write_compress_xz.c | 257 -- lib/libarchive/test/test_write_disk.c | 332 --- lib/libarchive/test/test_write_disk_failures.c | 72 - lib/libarchive/test/test_write_disk_hardlink.c | 219 -- lib/libarchive/test/test_write_disk_perms.c | 457 --- lib/libarchive/test/test_write_disk_secure.c | 215 -- lib/libarchive/test/test_write_disk_sparse.c | 280 -- lib/libarchive/test/test_write_disk_symlink.c | 117 - lib/libarchive/test/test_write_disk_times.c | 167 -- lib/libarchive/test/test_write_format_ar.c | 209 -- lib/libarchive/test/test_write_format_cpio.c | 194 -- lib/libarchive/test/test_write_format_cpio_empty.c | 75 - lib/libarchive/test/test_write_format_cpio_newc.c | 214 -- lib/libarchive/test/test_write_format_cpio_odc.c | 241 -- lib/libarchive/test/test_write_format_mtree.c | 155 - lib/libarchive/test/test_write_format_pax.c | 146 - lib/libarchive/test/test_write_format_shar_empty.c | 58 - lib/libarchive/test/test_write_format_tar.c | 114 - lib/libarchive/test/test_write_format_tar_empty.c | 92 - lib/libarchive/test/test_write_format_tar_ustar.c | 347 --- lib/libarchive/test/test_write_format_zip.c | 180 -- lib/libarchive/test/test_write_format_zip_empty.c | 56 - .../test/test_write_format_zip_no_compression.c | 304 -- lib/libarchive/test/test_write_open_memory.c | 76 - 256 files changed, 30 insertions(+), 75767 deletions(-) delete mode 100644 lib/libarchive/COPYING delete mode 100644 lib/libarchive/README delete mode 100644 lib/libarchive/archive.h delete mode 100644 lib/libarchive/archive_check_magic.c delete mode 100644 lib/libarchive/archive_crc32.h delete mode 100644 lib/libarchive/archive_endian.h delete mode 100644 lib/libarchive/archive_entry.3 delete mode 100644 lib/libarchive/archive_entry.c delete mode 100644 lib/libarchive/archive_entry.h delete mode 100644 lib/libarchive/archive_entry_copy_stat.c delete mode 100644 lib/libarchive/archive_entry_link_resolver.c delete mode 100644 lib/libarchive/archive_entry_private.h delete mode 100644 lib/libarchive/archive_entry_stat.c delete mode 100644 lib/libarchive/archive_entry_strmode.c delete mode 100644 lib/libarchive/archive_entry_xattr.c delete mode 100644 lib/libarchive/archive_hash.h delete mode 100644 lib/libarchive/archive_platform.h delete mode 100644 lib/libarchive/archive_private.h delete mode 100644 lib/libarchive/archive_read.3 delete mode 100644 lib/libarchive/archive_read.c delete mode 100644 lib/libarchive/archive_read_data_into_fd.c delete mode 100644 lib/libarchive/archive_read_disk.3 delete mode 100644 lib/libarchive/archive_read_disk.c delete mode 100644 lib/libarchive/archive_read_disk_entry_from_file.c delete mode 100644 lib/libarchive/archive_read_disk_private.h delete mode 100644 lib/libarchive/archive_read_disk_set_standard_lookup.c delete mode 100644 lib/libarchive/archive_read_extract.c delete mode 100644 lib/libarchive/archive_read_open_fd.c delete mode 100644 lib/libarchive/archive_read_open_file.c delete mode 100644 lib/libarchive/archive_read_open_filename.c delete mode 100644 lib/libarchive/archive_read_open_memory.c delete mode 100644 lib/libarchive/archive_read_private.h delete mode 100644 lib/libarchive/archive_read_support_compression_all.c delete mode 100644 lib/libarchive/archive_read_support_compression_bzip2.c delete mode 100644 lib/libarchive/archive_read_support_compression_compress.c delete mode 100644 lib/libarchive/archive_read_support_compression_gzip.c delete mode 100644 lib/libarchive/archive_read_support_compression_none.c delete mode 100644 lib/libarchive/archive_read_support_compression_program.c delete mode 100644 lib/libarchive/archive_read_support_compression_rpm.c delete mode 100644 lib/libarchive/archive_read_support_compression_uu.c delete mode 100644 lib/libarchive/archive_read_support_compression_xz.c delete mode 100644 lib/libarchive/archive_read_support_format_all.c delete mode 100644 lib/libarchive/archive_read_support_format_ar.c delete mode 100644 lib/libarchive/archive_read_support_format_cpio.c delete mode 100644 lib/libarchive/archive_read_support_format_empty.c delete mode 100644 lib/libarchive/archive_read_support_format_iso9660.c delete mode 100644 lib/libarchive/archive_read_support_format_mtree.c delete mode 100644 lib/libarchive/archive_read_support_format_raw.c delete mode 100644 lib/libarchive/archive_read_support_format_tar.c delete mode 100644 lib/libarchive/archive_read_support_format_xar.c delete mode 100644 lib/libarchive/archive_read_support_format_zip.c delete mode 100644 lib/libarchive/archive_string.c delete mode 100644 lib/libarchive/archive_string.h delete mode 100644 lib/libarchive/archive_string_sprintf.c delete mode 100644 lib/libarchive/archive_util.3 delete mode 100644 lib/libarchive/archive_util.c delete mode 100644 lib/libarchive/archive_virtual.c delete mode 100644 lib/libarchive/archive_write.3 delete mode 100644 lib/libarchive/archive_write.c delete mode 100644 lib/libarchive/archive_write_disk.3 delete mode 100644 lib/libarchive/archive_write_disk.c delete mode 100644 lib/libarchive/archive_write_disk_private.h delete mode 100644 lib/libarchive/archive_write_disk_set_standard_lookup.c delete mode 100644 lib/libarchive/archive_write_open_fd.c delete mode 100644 lib/libarchive/archive_write_open_file.c delete mode 100644 lib/libarchive/archive_write_open_filename.c delete mode 100644 lib/libarchive/archive_write_open_memory.c delete mode 100644 lib/libarchive/archive_write_private.h delete mode 100644 lib/libarchive/archive_write_set_compression_bzip2.c delete mode 100644 lib/libarchive/archive_write_set_compression_compress.c delete mode 100644 lib/libarchive/archive_write_set_compression_gzip.c delete mode 100644 lib/libarchive/archive_write_set_compression_none.c delete mode 100644 lib/libarchive/archive_write_set_compression_program.c delete mode 100644 lib/libarchive/archive_write_set_compression_xz.c delete mode 100644 lib/libarchive/archive_write_set_format.c delete mode 100644 lib/libarchive/archive_write_set_format_ar.c delete mode 100644 lib/libarchive/archive_write_set_format_by_name.c delete mode 100644 lib/libarchive/archive_write_set_format_cpio.c delete mode 100644 lib/libarchive/archive_write_set_format_cpio_newc.c delete mode 100644 lib/libarchive/archive_write_set_format_mtree.c delete mode 100644 lib/libarchive/archive_write_set_format_pax.c delete mode 100644 lib/libarchive/archive_write_set_format_shar.c delete mode 100644 lib/libarchive/archive_write_set_format_ustar.c delete mode 100644 lib/libarchive/archive_write_set_format_zip.c delete mode 100644 lib/libarchive/cpio.5 delete mode 100644 lib/libarchive/filter_fork.c delete mode 100644 lib/libarchive/filter_fork.h delete mode 100644 lib/libarchive/libarchive-formats.5 delete mode 100644 lib/libarchive/libarchive.3 delete mode 100644 lib/libarchive/libarchive_fe/err.c delete mode 100644 lib/libarchive/libarchive_fe/err.h delete mode 100644 lib/libarchive/libarchive_fe/lafe_platform.h delete mode 100644 lib/libarchive/libarchive_fe/line_reader.c delete mode 100644 lib/libarchive/libarchive_fe/line_reader.h delete mode 100644 lib/libarchive/libarchive_fe/matching.c delete mode 100644 lib/libarchive/libarchive_fe/matching.h delete mode 100644 lib/libarchive/libarchive_fe/pathmatch.c delete mode 100644 lib/libarchive/libarchive_fe/pathmatch.h delete mode 100644 lib/libarchive/libarchive_internals.3 delete mode 100644 lib/libarchive/tar.5 delete mode 100644 lib/libarchive/test/.cvsignore delete mode 100644 lib/libarchive/test/README delete mode 100644 lib/libarchive/test/main.c delete mode 100644 lib/libarchive/test/read_open_memory.c delete mode 100644 lib/libarchive/test/test.h delete mode 100644 lib/libarchive/test/test_acl_basic.c delete mode 100644 lib/libarchive/test/test_acl_freebsd.c delete mode 100644 lib/libarchive/test/test_acl_pax.c delete mode 100644 lib/libarchive/test/test_archive_api_feature.c delete mode 100644 lib/libarchive/test/test_bad_fd.c delete mode 100644 lib/libarchive/test/test_compat_bzip2.c delete mode 100644 lib/libarchive/test/test_compat_bzip2_1.tbz.uu delete mode 100644 lib/libarchive/test/test_compat_bzip2_2.tbz.uu delete mode 100644 lib/libarchive/test/test_compat_cpio.c delete mode 100644 lib/libarchive/test/test_compat_cpio_1.cpio.uu delete mode 100644 lib/libarchive/test/test_compat_gtar.c delete mode 100644 lib/libarchive/test/test_compat_gtar_1.tar.uu delete mode 100644 lib/libarchive/test/test_compat_gzip.c delete mode 100644 lib/libarchive/test/test_compat_gzip_1.tgz.uu delete mode 100644 lib/libarchive/test/test_compat_gzip_2.tgz.uu delete mode 100644 lib/libarchive/test/test_compat_lzma.c delete mode 100644 lib/libarchive/test/test_compat_lzma_1.tlz.uu delete mode 100644 lib/libarchive/test/test_compat_lzma_2.tlz.uu delete mode 100644 lib/libarchive/test/test_compat_lzma_3.tlz.uu delete mode 100644 lib/libarchive/test/test_compat_solaris_tar_acl.c delete mode 100644 lib/libarchive/test/test_compat_solaris_tar_acl.tar.uu delete mode 100644 lib/libarchive/test/test_compat_tar_hardlink.c delete mode 100644 lib/libarchive/test/test_compat_tar_hardlink_1.tar.uu delete mode 100644 lib/libarchive/test/test_compat_xz.c delete mode 100644 lib/libarchive/test/test_compat_xz_1.txz.uu delete mode 100644 lib/libarchive/test/test_compat_zip.c delete mode 100644 lib/libarchive/test/test_compat_zip_1.zip.uu delete mode 100644 lib/libarchive/test/test_compat_zip_2.zip.uu delete mode 100644 lib/libarchive/test/test_empty_write.c delete mode 100644 lib/libarchive/test/test_entry.c delete mode 100644 lib/libarchive/test/test_entry_strmode.c delete mode 100644 lib/libarchive/test/test_extattr_freebsd.c delete mode 100644 lib/libarchive/test/test_fuzz.c delete mode 100644 lib/libarchive/test/test_fuzz_1.iso.Z.uu delete mode 100644 lib/libarchive/test/test_link_resolver.c delete mode 100644 lib/libarchive/test/test_open_failure.c delete mode 100644 lib/libarchive/test/test_open_fd.c delete mode 100644 lib/libarchive/test/test_open_file.c delete mode 100644 lib/libarchive/test/test_open_filename.c delete mode 100644 lib/libarchive/test/test_pax_filename_encoding.c delete mode 100644 lib/libarchive/test/test_pax_filename_encoding.tar.uu delete mode 100644 lib/libarchive/test/test_read_compress_program.c delete mode 100644 lib/libarchive/test/test_read_data_large.c delete mode 100644 lib/libarchive/test/test_read_disk.c delete mode 100644 lib/libarchive/test/test_read_disk_entry_from_file.c delete mode 100644 lib/libarchive/test/test_read_extract.c delete mode 100644 lib/libarchive/test/test_read_file_nonexistent.c delete mode 100644 lib/libarchive/test/test_read_format_ar.ar.uu delete mode 100644 lib/libarchive/test/test_read_format_ar.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_bin.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_bin_Z.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_bin_be.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_bin_be.cpio.uu delete mode 100644 lib/libarchive/test/test_read_format_cpio_bin_bz2.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_bin_gz.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_bin_lzma.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_bin_xz.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_odc.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu delete mode 100644 lib/libarchive/test/test_read_format_cpio_svr4_gzip.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c delete mode 100644 lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu delete mode 100644 lib/libarchive/test/test_read_format_cpio_svr4c_Z.c delete mode 100644 lib/libarchive/test/test_read_format_empty.c delete mode 100644 lib/libarchive/test/test_read_format_gtar_gz.c delete mode 100644 lib/libarchive/test/test_read_format_gtar_lzma.c delete mode 100644 lib/libarchive/test/test_read_format_gtar_sparse.c delete mode 100644 lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu delete mode 100644 lib/libarchive/test/test_read_format_gtar_sparse_1_17.tar.uu delete mode 100644 lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix00.tar.uu delete mode 100644 lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix01.tar.uu delete mode 100644 lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix10.tar.uu delete mode 100644 lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix10_modified.tar.uu delete mode 100644 lib/libarchive/test/test_read_format_iso.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_2.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_Z.c delete mode 100644 lib/libarchive/test/test_read_format_iso_joliet.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_joliet_rockridge.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_multi_extent.c delete mode 100644 lib/libarchive/test/test_read_format_iso_multi_extent.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_rockridge.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_rockridge_ce.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_rockridge_new.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_rockridge_rr_moved.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_iso_zisofs.iso.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_isojoliet_bz2.c delete mode 100644 lib/libarchive/test/test_read_format_isojoliet_long.c delete mode 100644 lib/libarchive/test/test_read_format_isojoliet_rr.c delete mode 100644 lib/libarchive/test/test_read_format_isorr_bz2.c delete mode 100644 lib/libarchive/test/test_read_format_isorr_ce.c delete mode 100644 lib/libarchive/test/test_read_format_isorr_new_bz2.c delete mode 100644 lib/libarchive/test/test_read_format_isorr_rr_moved.c delete mode 100644 lib/libarchive/test/test_read_format_isozisofs_bz2.c delete mode 100644 lib/libarchive/test/test_read_format_mtree.c delete mode 100644 lib/libarchive/test/test_read_format_mtree.mtree.uu delete mode 100644 lib/libarchive/test/test_read_format_pax_bz2.c delete mode 100644 lib/libarchive/test/test_read_format_raw.c delete mode 100644 lib/libarchive/test/test_read_format_raw.data.Z.uu delete mode 100644 lib/libarchive/test/test_read_format_raw.data.uu delete mode 100644 lib/libarchive/test/test_read_format_tar.c delete mode 100644 lib/libarchive/test/test_read_format_tar_empty_filename.c delete mode 100644 lib/libarchive/test/test_read_format_tar_empty_filename.tar.uu delete mode 100644 lib/libarchive/test/test_read_format_tbz.c delete mode 100644 lib/libarchive/test/test_read_format_tgz.c delete mode 100644 lib/libarchive/test/test_read_format_tlz.c delete mode 100644 lib/libarchive/test/test_read_format_txz.c delete mode 100644 lib/libarchive/test/test_read_format_tz.c delete mode 100644 lib/libarchive/test/test_read_format_xar.c delete mode 100644 lib/libarchive/test/test_read_format_zip.c delete mode 100644 lib/libarchive/test/test_read_format_zip.zip.uu delete mode 100644 lib/libarchive/test/test_read_large.c delete mode 100644 lib/libarchive/test/test_read_pax_truncated.c delete mode 100644 lib/libarchive/test/test_read_position.c delete mode 100644 lib/libarchive/test/test_read_truncated.c delete mode 100644 lib/libarchive/test/test_read_uu.c delete mode 100644 lib/libarchive/test/test_tar_filenames.c delete mode 100644 lib/libarchive/test/test_tar_large.c delete mode 100644 lib/libarchive/test/test_ustar_filenames.c delete mode 100644 lib/libarchive/test/test_write_compress.c delete mode 100644 lib/libarchive/test/test_write_compress_bzip2.c delete mode 100644 lib/libarchive/test/test_write_compress_gzip.c delete mode 100644 lib/libarchive/test/test_write_compress_lzma.c delete mode 100644 lib/libarchive/test/test_write_compress_program.c delete mode 100644 lib/libarchive/test/test_write_compress_xz.c delete mode 100644 lib/libarchive/test/test_write_disk.c delete mode 100644 lib/libarchive/test/test_write_disk_failures.c delete mode 100644 lib/libarchive/test/test_write_disk_hardlink.c delete mode 100644 lib/libarchive/test/test_write_disk_perms.c delete mode 100644 lib/libarchive/test/test_write_disk_secure.c delete mode 100644 lib/libarchive/test/test_write_disk_sparse.c delete mode 100644 lib/libarchive/test/test_write_disk_symlink.c delete mode 100644 lib/libarchive/test/test_write_disk_times.c delete mode 100644 lib/libarchive/test/test_write_format_ar.c delete mode 100644 lib/libarchive/test/test_write_format_cpio.c delete mode 100644 lib/libarchive/test/test_write_format_cpio_empty.c delete mode 100644 lib/libarchive/test/test_write_format_cpio_newc.c delete mode 100644 lib/libarchive/test/test_write_format_cpio_odc.c delete mode 100644 lib/libarchive/test/test_write_format_mtree.c delete mode 100644 lib/libarchive/test/test_write_format_pax.c delete mode 100644 lib/libarchive/test/test_write_format_shar_empty.c delete mode 100644 lib/libarchive/test/test_write_format_tar.c delete mode 100644 lib/libarchive/test/test_write_format_tar_empty.c delete mode 100644 lib/libarchive/test/test_write_format_tar_ustar.c delete mode 100644 lib/libarchive/test/test_write_format_zip.c delete mode 100644 lib/libarchive/test/test_write_format_zip_empty.c delete mode 100644 lib/libarchive/test/test_write_format_zip_no_compression.c delete mode 100644 lib/libarchive/test/test_write_open_memory.c (limited to 'lib') diff --git a/lib/libarchive/COPYING b/lib/libarchive/COPYING deleted file mode 100644 index 5fea0f6..0000000 --- a/lib/libarchive/COPYING +++ /dev/null @@ -1,36 +0,0 @@ -All of the C source code, header files, and documentation in this -package are covered by the following: - -Copyright (c) 2003-2007 Tim Kientzle -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -=========================================================================== - -Shell scripts, makefiles, and certain other files may be covered by -other licenses. In particular, some distributions of this library -contain Makefiles and/or shell scripts that are generated -automatically by GNU autoconf and GNU automake. Those generated files -are controlled by the relevant licenses. - -$FreeBSD$ - diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile index 8d889c8..92ca954 100644 --- a/lib/libarchive/Makefile +++ b/lib/libarchive/Makefile @@ -1,6 +1,8 @@ # $FreeBSD$ .include +LIBARCHIVEDIR= ${.CURDIR}/../../contrib/libarchive + LIB= archive DPADD= ${LIBZ} LDADD= -lz @@ -20,7 +22,7 @@ LDADD+= -lbsdxml # It has no real relation to the libarchive version number. SHLIB_MAJOR= 5 -CFLAGS+= -DPLATFORM_CONFIG_H=\"config_freebsd.h\" +CFLAGS+= -DPLATFORM_CONFIG_H=\"${.CURDIR}/config_freebsd.h\" CFLAGS+= -I${.OBJDIR} .if ${MK_OPENSSL} != "no" @@ -32,6 +34,8 @@ DPADD+= ${LIBMD} LDADD+= -lmd .endif +.PATH: ${LIBARCHIVEDIR}/libarchive + # Headers to be installed in /usr/include INCS= archive.h archive_entry.h @@ -273,8 +277,11 @@ MLINKS+= archive_write_disk.3 archive_write_disk_set_standard_lookup.3 MLINKS+= archive_write_disk.3 archive_write_disk_set_user_lookup.3 MLINKS+= libarchive.3 archive.3 -.PHONY: check test +.PHONY: check test clean-test check test: - cd ${.CURDIR}/test && make test + cd ${.CURDIR}/test && make obj && make test + +clean-test: + cd ${.CURDIR}/test && make clean .include diff --git a/lib/libarchive/README b/lib/libarchive/README deleted file mode 100644 index 0c4758a..0000000 --- a/lib/libarchive/README +++ /dev/null @@ -1,102 +0,0 @@ -$FreeBSD$ - -libarchive: a library for reading and writing streaming archives - -This is all under a BSD license. Use, enjoy, but don't blame me if it breaks! - -Documentation: - * libarchive.3 gives an overview of the library as a whole - * archive_read.3, archive_write.3, and archive_write_disk.3 provide - detailed calling sequences for the read and write APIs - * archive_entry.3 details the "struct archive_entry" utility class - * libarchive-formats.5 documents the file formats supported by the library - * tar.5 provides some detailed information about a variety of different - "tar" formats. - -You should also read the copious comments in "archive.h" and the source -code for the sample "bsdtar" and "minitar" programs for more details. -Please let me know about any errors or omissions you find. - -Currently, the library automatically detects and reads the following: - * gzip compression - * bzip2 compression - * compress/LZW compression - * lzma and xz compression - * GNU tar format (including GNU long filenames, long link names, and - sparse files) - * Solaris 9 extended tar format (including ACLs) - * Old V7 tar archives - * POSIX ustar - * POSIX pax interchange format - * POSIX octet-oriented cpio - * SVR4 ASCII cpio - * Binary cpio (big-endian or little-endian) - * ISO9660 CD-ROM images (with optional Rockridge or Joliet extensions) - * ZIP archives (with uncompressed or "deflate" compressed entries) - * GNU and BSD 'ar' archives - * 'mtree' format - -The library can write: - * gzip compression - * bzip2 compression - * compress/LZW compression - * lzma and xz compression - * POSIX ustar - * POSIX pax interchange format - * "restricted" pax format, which will create ustar archives except for - entries that require pax extensions (for long filenames, ACLs, etc). - * POSIX octet-oriented cpio - * SVR4 "newc" cpio - * shar archives - * ZIP archives (with uncompressed or "deflate" compressed entries) - * GNU and BSD 'ar' archives - * 'mtree' format - -Notes: - * This is a heavily stream-oriented system. There is no direct - support for in-place modification or random access and no intention - of ever adding such support. Adding such support would require - sacrificing a lot of other features, so don't bother asking. - - * The library is designed to be extended with new compression and - archive formats. The only requirement is that the format be - readable or writable as a stream and that each archive entry be - independent. - - * On read, compression and format are always detected automatically. - - * I've attempted to minimize static link pollution. If you don't - explicitly invoke a particular feature (such as support for a - particular compression or format), it won't get pulled in. - In particular, if you don't explicitly enable a particular - compression or decompression support, you won't need to link - against the corresponding compression or decompression libraries. - This also reduces the size of statically-linked binaries in - environments where that matters. - - * On read, the library accepts whatever blocks you hand it. - Your read callback is free to pass the library a byte at a time - or mmap the entire archive and give it to the library at once. - On write, the library always produces correctly-blocked - output. - - * The object-style approach allows you to have multiple archive streams - open at once. bsdtar uses this in its "@archive" extension. - - * The archive itself is read/written using callback functions. - You can read an archive directly from an in-memory buffer or - write it to a socket, if you wish. There are some utility - functions to provide easy-to-use "open file," etc, capabilities. - - * The read/write APIs are designed to allow individual entries - to be read or written to any data source: You can create - a block of data in memory and add it to a tar archive without - first writing a temporary file. You can also read an entry from - an archive and write the data directly to a socket. If you want - to read/write entries to disk, the archive_write_disk interface - treats a directory as if it were an archive so you can copy - from archive->disk using the same code you use for archive->archive - transfers. - - * Note: "pax interchange format" is really an extended tar format, - despite what the name says. diff --git a/lib/libarchive/archive.h b/lib/libarchive/archive.h deleted file mode 100644 index bac93f0..0000000 --- a/lib/libarchive/archive.h +++ /dev/null @@ -1,746 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef ARCHIVE_H_INCLUDED -#define ARCHIVE_H_INCLUDED - -/* - * Note: archive.h is for use outside of libarchive; the configuration - * headers (config.h, archive_platform.h, etc.) are purely internal. - * Do NOT use HAVE_XXX configuration macros to control the behavior of - * this header! If you must conditionalize, use predefined compiler and/or - * platform macros. - */ -#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560 -# define __LA_STDINT_H -#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) -# define __LA_STDINT_H -#endif - -#include -#include /* Linux requires this for off_t */ -#ifdef __LA_STDINT_H -# include __LA_STDINT_H /* int64_t, etc. */ -#endif -#include /* For FILE * */ - -/* Get appropriate definitions of standard POSIX-style types. */ -/* These should match the types used in 'struct stat' */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#define __LA_INT64_T __int64 -# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_) -# define __LA_SSIZE_T ssize_t -# elif defined(_WIN64) -# define __LA_SSIZE_T __int64 -# else -# define __LA_SSIZE_T long -# endif -# if defined(__BORLANDC__) -# define __LA_UID_T uid_t -# define __LA_GID_T gid_t -# else -# define __LA_UID_T short -# define __LA_GID_T short -# endif -#else -#include /* ssize_t, uid_t, and gid_t */ -#define __LA_INT64_T int64_t -#define __LA_SSIZE_T ssize_t -#define __LA_UID_T uid_t -#define __LA_GID_T gid_t -#endif - -/* - * On Windows, define LIBARCHIVE_STATIC if you're building or using a - * .lib. The default here assumes you're building a DLL. Only - * libarchive source should ever define __LIBARCHIVE_BUILD. - */ -#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC) -# ifdef __LIBARCHIVE_BUILD -# ifdef __GNUC__ -# define __LA_DECL __attribute__((dllexport)) extern -# else -# define __LA_DECL __declspec(dllexport) -# endif -# else -# ifdef __GNUC__ -# define __LA_DECL __attribute__((dllimport)) extern -# else -# define __LA_DECL __declspec(dllimport) -# endif -# endif -#else -/* Static libraries or non-Windows needs no special declaration. */ -# define __LA_DECL -#endif - -#if defined(__GNUC__) && __GNUC__ >= 3 -#define __LA_PRINTF(fmtarg, firstvararg) \ - __attribute__((__format__ (__printf__, fmtarg, firstvararg))) -#else -#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */ -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * The version number is provided as both a macro and a function. - * The macro identifies the installed header; the function identifies - * the library version (which may not be the same if you're using a - * dynamically-linked version of the library). Of course, if the - * header and library are very different, you should expect some - * strangeness. Don't do that. - */ - -/* - * The version number is expressed as a single integer that makes it - * easy to compare versions at build time: for version a.b.c, the - * version number is printf("%d%03d%03d",a,b,c). For example, if you - * know your application requires version 2.12.108 or later, you can - * assert that ARCHIVE_VERSION >= 2012108. - * - * This single-number format was introduced with libarchive 1.9.0 in - * the libarchive 1.x family and libarchive 2.2.4 in the libarchive - * 2.x family. The following may be useful if you really want to do - * feature detection for earlier libarchive versions (which defined - * ARCHIVE_API_VERSION and ARCHIVE_API_FEATURE instead): - * - * #ifndef ARCHIVE_VERSION_NUMBER - * #define ARCHIVE_VERSION_NUMBER \ - * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000) - * #endif - */ -#define ARCHIVE_VERSION_NUMBER 2008005 -__LA_DECL int archive_version_number(void); - -/* - * Textual name/version of the library, useful for version displays. - */ -#define ARCHIVE_VERSION_STRING "libarchive 2.8.5" -__LA_DECL const char * archive_version_string(void); - -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* - * Deprecated; these are older names that will be removed in favor of - * the simpler definitions above. - */ -#define ARCHIVE_VERSION_STAMP ARCHIVE_VERSION_NUMBER -__LA_DECL int archive_version_stamp(void); -#define ARCHIVE_LIBRARY_VERSION ARCHIVE_VERSION_STRING -__LA_DECL const char * archive_version(void); -#define ARCHIVE_API_VERSION (ARCHIVE_VERSION_NUMBER / 1000000) -__LA_DECL int archive_api_version(void); -#define ARCHIVE_API_FEATURE ((ARCHIVE_VERSION_NUMBER / 1000) % 1000) -__LA_DECL int archive_api_feature(void); -#endif - -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* This should never have been here in the first place. */ -/* Legacy of old tar assumptions, will be removed in libarchive 3.0. */ -#define ARCHIVE_BYTES_PER_RECORD 512 -#define ARCHIVE_DEFAULT_BYTES_PER_BLOCK 10240 -#endif - -/* Declare our basic types. */ -struct archive; -struct archive_entry; - -/* - * Error codes: Use archive_errno() and archive_error_string() - * to retrieve details. Unless specified otherwise, all functions - * that return 'int' use these codes. - */ -#define ARCHIVE_EOF 1 /* Found end of archive. */ -#define ARCHIVE_OK 0 /* Operation was successful. */ -#define ARCHIVE_RETRY (-10) /* Retry might succeed. */ -#define ARCHIVE_WARN (-20) /* Partial success. */ -/* For example, if write_header "fails", then you can't push data. */ -#define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */ -/* But if write_header is "fatal," then this archive is dead and useless. */ -#define ARCHIVE_FATAL (-30) /* No more operations are possible. */ - -/* - * As far as possible, archive_errno returns standard platform errno codes. - * Of course, the details vary by platform, so the actual definitions - * here are stored in "archive_platform.h". The symbols are listed here - * for reference; as a rule, clients should not need to know the exact - * platform-dependent error code. - */ -/* Unrecognized or invalid file format. */ -/* #define ARCHIVE_ERRNO_FILE_FORMAT */ -/* Illegal usage of the library. */ -/* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */ -/* Unknown or unclassified error. */ -/* #define ARCHIVE_ERRNO_MISC */ - -/* - * Callbacks are invoked to automatically read/skip/write/open/close the - * archive. You can provide your own for complex tasks (like breaking - * archives across multiple tapes) or use standard ones built into the - * library. - */ - -/* Returns pointer and size of next block of data from archive. */ -typedef __LA_SSIZE_T archive_read_callback(struct archive *, - void *_client_data, const void **_buffer); - -/* Skips at most request bytes from archive and returns the skipped amount */ -#if ARCHIVE_VERSION_NUMBER < 2000000 -/* Libarchive 1.0 used ssize_t for the return, which is only 32 bits - * on most 32-bit platforms; not large enough. */ -typedef __LA_SSIZE_T archive_skip_callback(struct archive *, - void *_client_data, size_t request); -#elif ARCHIVE_VERSION_NUMBER < 3000000 -/* Libarchive 2.0 used off_t here, but that is a bad idea on Linux and a - * few other platforms where off_t varies with build settings. */ -typedef off_t archive_skip_callback(struct archive *, - void *_client_data, off_t request); -#else -/* Libarchive 3.0 uses int64_t here, which is actually guaranteed to be - * 64 bits on every platform. */ -typedef __LA_INT64_T archive_skip_callback(struct archive *, - void *_client_data, __LA_INT64_T request); -#endif - -/* Returns size actually written, zero on EOF, -1 on error. */ -typedef __LA_SSIZE_T archive_write_callback(struct archive *, - void *_client_data, - const void *_buffer, size_t _length); - -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* Open callback is actually never needed; remove it in libarchive 3.0. */ -typedef int archive_open_callback(struct archive *, void *_client_data); -#endif - -typedef int archive_close_callback(struct archive *, void *_client_data); - -/* - * Codes for archive_compression. - */ -#define ARCHIVE_COMPRESSION_NONE 0 -#define ARCHIVE_COMPRESSION_GZIP 1 -#define ARCHIVE_COMPRESSION_BZIP2 2 -#define ARCHIVE_COMPRESSION_COMPRESS 3 -#define ARCHIVE_COMPRESSION_PROGRAM 4 -#define ARCHIVE_COMPRESSION_LZMA 5 -#define ARCHIVE_COMPRESSION_XZ 6 -#define ARCHIVE_COMPRESSION_UU 7 -#define ARCHIVE_COMPRESSION_RPM 8 - -/* - * Codes returned by archive_format. - * - * Top 16 bits identifies the format family (e.g., "tar"); lower - * 16 bits indicate the variant. This is updated by read_next_header. - * Note that the lower 16 bits will often vary from entry to entry. - * In some cases, this variation occurs as libarchive learns more about - * the archive (for example, later entries might utilize extensions that - * weren't necessary earlier in the archive; in this case, libarchive - * will change the format code to indicate the extended format that - * was used). In other cases, it's because different tools have - * modified the archive and so different parts of the archive - * actually have slightly different formts. (Both tar and cpio store - * format codes in each entry, so it is quite possible for each - * entry to be in a different format.) - */ -#define ARCHIVE_FORMAT_BASE_MASK 0xff0000 -#define ARCHIVE_FORMAT_CPIO 0x10000 -#define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1) -#define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2) -#define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3) -#define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4) -#define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5) -#define ARCHIVE_FORMAT_SHAR 0x20000 -#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1) -#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2) -#define ARCHIVE_FORMAT_TAR 0x30000 -#define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1) -#define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2) -#define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3) -#define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4) -#define ARCHIVE_FORMAT_ISO9660 0x40000 -#define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1) -#define ARCHIVE_FORMAT_ZIP 0x50000 -#define ARCHIVE_FORMAT_EMPTY 0x60000 -#define ARCHIVE_FORMAT_AR 0x70000 -#define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1) -#define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2) -#define ARCHIVE_FORMAT_MTREE 0x80000 -#define ARCHIVE_FORMAT_RAW 0x90000 -#define ARCHIVE_FORMAT_XAR 0xA0000 - -/*- - * Basic outline for reading an archive: - * 1) Ask archive_read_new for an archive reader object. - * 2) Update any global properties as appropriate. - * In particular, you'll certainly want to call appropriate - * archive_read_support_XXX functions. - * 3) Call archive_read_open_XXX to open the archive - * 4) Repeatedly call archive_read_next_header to get information about - * successive archive entries. Call archive_read_data to extract - * data for entries of interest. - * 5) Call archive_read_finish to end processing. - */ -__LA_DECL struct archive *archive_read_new(void); - -/* - * The archive_read_support_XXX calls enable auto-detect for this - * archive handle. They also link in the necessary support code. - * For example, if you don't want bzlib linked in, don't invoke - * support_compression_bzip2(). The "all" functions provide the - * obvious shorthand. - */ -__LA_DECL int archive_read_support_compression_all(struct archive *); -__LA_DECL int archive_read_support_compression_bzip2(struct archive *); -__LA_DECL int archive_read_support_compression_compress(struct archive *); -__LA_DECL int archive_read_support_compression_gzip(struct archive *); -__LA_DECL int archive_read_support_compression_lzma(struct archive *); -__LA_DECL int archive_read_support_compression_none(struct archive *); -__LA_DECL int archive_read_support_compression_program(struct archive *, - const char *command); -__LA_DECL int archive_read_support_compression_program_signature - (struct archive *, const char *, - const void * /* match */, size_t); - -__LA_DECL int archive_read_support_compression_rpm(struct archive *); -__LA_DECL int archive_read_support_compression_uu(struct archive *); -__LA_DECL int archive_read_support_compression_xz(struct archive *); - -__LA_DECL int archive_read_support_format_all(struct archive *); -__LA_DECL int archive_read_support_format_ar(struct archive *); -__LA_DECL int archive_read_support_format_cpio(struct archive *); -__LA_DECL int archive_read_support_format_empty(struct archive *); -__LA_DECL int archive_read_support_format_gnutar(struct archive *); -__LA_DECL int archive_read_support_format_iso9660(struct archive *); -__LA_DECL int archive_read_support_format_mtree(struct archive *); -__LA_DECL int archive_read_support_format_raw(struct archive *); -__LA_DECL int archive_read_support_format_tar(struct archive *); -__LA_DECL int archive_read_support_format_xar(struct archive *); -__LA_DECL int archive_read_support_format_zip(struct archive *); - - -/* Open the archive using callbacks for archive I/O. */ -__LA_DECL int archive_read_open(struct archive *, void *_client_data, - archive_open_callback *, archive_read_callback *, - archive_close_callback *); -__LA_DECL int archive_read_open2(struct archive *, void *_client_data, - archive_open_callback *, archive_read_callback *, - archive_skip_callback *, archive_close_callback *); - -/* - * A variety of shortcuts that invoke archive_read_open() with - * canned callbacks suitable for common situations. The ones that - * accept a block size handle tape blocking correctly. - */ -/* Use this if you know the filename. Note: NULL indicates stdin. */ -__LA_DECL int archive_read_open_filename(struct archive *, - const char *_filename, size_t _block_size); -/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */ -__LA_DECL int archive_read_open_file(struct archive *, - const char *_filename, size_t _block_size); -/* Read an archive that's stored in memory. */ -__LA_DECL int archive_read_open_memory(struct archive *, - void * buff, size_t size); -/* A more involved version that is only used for internal testing. */ -__LA_DECL int archive_read_open_memory2(struct archive *a, void *buff, - size_t size, size_t read_size); -/* Read an archive that's already open, using the file descriptor. */ -__LA_DECL int archive_read_open_fd(struct archive *, int _fd, - size_t _block_size); -/* Read an archive that's already open, using a FILE *. */ -/* Note: DO NOT use this with tape drives. */ -__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file); - -/* Parses and returns next entry header. */ -__LA_DECL int archive_read_next_header(struct archive *, - struct archive_entry **); - -/* Parses and returns next entry header using the archive_entry passed in */ -__LA_DECL int archive_read_next_header2(struct archive *, - struct archive_entry *); - -/* - * Retrieve the byte offset in UNCOMPRESSED data where last-read - * header started. - */ -__LA_DECL __LA_INT64_T archive_read_header_position(struct archive *); - -/* Read data from the body of an entry. Similar to read(2). */ -__LA_DECL __LA_SSIZE_T archive_read_data(struct archive *, - void *, size_t); - -/* - * A zero-copy version of archive_read_data that also exposes the file offset - * of each returned block. Note that the client has no way to specify - * the desired size of the block. The API does guarantee that offsets will - * be strictly increasing and that returned blocks will not overlap. - */ -#if ARCHIVE_VERSION_NUMBER < 3000000 -__LA_DECL int archive_read_data_block(struct archive *a, - const void **buff, size_t *size, off_t *offset); -#else -__LA_DECL int archive_read_data_block(struct archive *a, - const void **buff, size_t *size, - __LA_INT64_T *offset); -#endif - -/*- - * Some convenience functions that are built on archive_read_data: - * 'skip': skips entire entry - * 'into_buffer': writes data into memory buffer that you provide - * 'into_fd': writes data to specified filedes - */ -__LA_DECL int archive_read_data_skip(struct archive *); -__LA_DECL int archive_read_data_into_buffer(struct archive *, - void *buffer, __LA_SSIZE_T len); -__LA_DECL int archive_read_data_into_fd(struct archive *, int fd); - -/* - * Set read options. - */ -/* Apply option string to the format only. */ -__LA_DECL int archive_read_set_format_options(struct archive *_a, - const char *s); -/* Apply option string to the filter only. */ -__LA_DECL int archive_read_set_filter_options(struct archive *_a, - const char *s); -/* Apply option string to both the format and the filter. */ -__LA_DECL int archive_read_set_options(struct archive *_a, - const char *s); - -/*- - * Convenience function to recreate the current entry (whose header - * has just been read) on disk. - * - * This does quite a bit more than just copy data to disk. It also: - * - Creates intermediate directories as required. - * - Manages directory permissions: non-writable directories will - * be initially created with write permission enabled; when the - * archive is closed, dir permissions are edited to the values specified - * in the archive. - * - Checks hardlinks: hardlinks will not be extracted unless the - * linked-to file was also extracted within the same session. (TODO) - */ - -/* The "flags" argument selects optional behavior, 'OR' the flags you want. */ - -/* Default: Do not try to set owner/group. */ -#define ARCHIVE_EXTRACT_OWNER (0x0001) -/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */ -#define ARCHIVE_EXTRACT_PERM (0x0002) -/* Default: Do not restore mtime/atime. */ -#define ARCHIVE_EXTRACT_TIME (0x0004) -/* Default: Replace existing files. */ -#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008) -/* Default: Try create first, unlink only if create fails with EEXIST. */ -#define ARCHIVE_EXTRACT_UNLINK (0x0010) -/* Default: Do not restore ACLs. */ -#define ARCHIVE_EXTRACT_ACL (0x0020) -/* Default: Do not restore fflags. */ -#define ARCHIVE_EXTRACT_FFLAGS (0x0040) -/* Default: Do not restore xattrs. */ -#define ARCHIVE_EXTRACT_XATTR (0x0080) -/* Default: Do not try to guard against extracts redirected by symlinks. */ -/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */ -#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100) -/* Default: Do not reject entries with '..' as path elements. */ -#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200) -/* Default: Create parent directories as needed. */ -#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400) -/* Default: Overwrite files, even if one on disk is newer. */ -#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800) -/* Detect blocks of 0 and write holes instead. */ -#define ARCHIVE_EXTRACT_SPARSE (0x1000) - -__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *, - int flags); -__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *, - struct archive * /* dest */); -__LA_DECL void archive_read_extract_set_progress_callback(struct archive *, - void (*_progress_func)(void *), void *_user_data); - -/* Record the dev/ino of a file that will not be written. This is - * generally set to the dev/ino of the archive being read. */ -__LA_DECL void archive_read_extract_set_skip_file(struct archive *, - dev_t, ino_t); - -/* Close the file and release most resources. */ -__LA_DECL int archive_read_close(struct archive *); -/* Release all resources and destroy the object. */ -/* Note that archive_read_free will call archive_read_close for you. */ -__LA_DECL int archive_read_free(struct archive *); -#if ARCHIVE_VERSION_NUMBER < 4000000 -/* Synonym for archive_read_free() for backwards compatibility. */ -__LA_DECL int archive_read_finish(struct archive *); -#endif - -/*- - * To create an archive: - * 1) Ask archive_write_new for a archive writer object. - * 2) Set any global properties. In particular, you should set - * the compression and format to use. - * 3) Call archive_write_open to open the file (most people - * will use archive_write_open_file or archive_write_open_fd, - * which provide convenient canned I/O callbacks for you). - * 4) For each entry: - * - construct an appropriate struct archive_entry structure - * - archive_write_header to write the header - * - archive_write_data to write the entry data - * 5) archive_write_close to close the output - * 6) archive_write_free to cleanup the writer and release resources - */ -__LA_DECL struct archive *archive_write_new(void); -__LA_DECL int archive_write_set_bytes_per_block(struct archive *, - int bytes_per_block); -__LA_DECL int archive_write_get_bytes_per_block(struct archive *); -/* XXX This is badly misnamed; suggestions appreciated. XXX */ -__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *, - int bytes_in_last_block); -__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *); - -/* The dev/ino of a file that won't be archived. This is used - * to avoid recursively adding an archive to itself. */ -__LA_DECL int archive_write_set_skip_file(struct archive *, dev_t, ino_t); - -__LA_DECL int archive_write_set_compression_bzip2(struct archive *); -__LA_DECL int archive_write_set_compression_compress(struct archive *); -__LA_DECL int archive_write_set_compression_gzip(struct archive *); -__LA_DECL int archive_write_set_compression_lzma(struct archive *); -__LA_DECL int archive_write_set_compression_none(struct archive *); -__LA_DECL int archive_write_set_compression_program(struct archive *, - const char *cmd); -__LA_DECL int archive_write_set_compression_xz(struct archive *); -/* A convenience function to set the format based on the code or name. */ -__LA_DECL int archive_write_set_format(struct archive *, int format_code); -__LA_DECL int archive_write_set_format_by_name(struct archive *, - const char *name); -/* To minimize link pollution, use one or more of the following. */ -__LA_DECL int archive_write_set_format_ar_bsd(struct archive *); -__LA_DECL int archive_write_set_format_ar_svr4(struct archive *); -__LA_DECL int archive_write_set_format_cpio(struct archive *); -__LA_DECL int archive_write_set_format_cpio_newc(struct archive *); -__LA_DECL int archive_write_set_format_mtree(struct archive *); -/* TODO: int archive_write_set_format_old_tar(struct archive *); */ -__LA_DECL int archive_write_set_format_pax(struct archive *); -__LA_DECL int archive_write_set_format_pax_restricted(struct archive *); -__LA_DECL int archive_write_set_format_shar(struct archive *); -__LA_DECL int archive_write_set_format_shar_dump(struct archive *); -__LA_DECL int archive_write_set_format_ustar(struct archive *); -__LA_DECL int archive_write_set_format_zip(struct archive *); -__LA_DECL int archive_write_open(struct archive *, void *, - archive_open_callback *, archive_write_callback *, - archive_close_callback *); -__LA_DECL int archive_write_open_fd(struct archive *, int _fd); -__LA_DECL int archive_write_open_filename(struct archive *, const char *_file); -/* A deprecated synonym for archive_write_open_filename() */ -__LA_DECL int archive_write_open_file(struct archive *, const char *_file); -__LA_DECL int archive_write_open_FILE(struct archive *, FILE *); -/* _buffSize is the size of the buffer, _used refers to a variable that - * will be updated after each write into the buffer. */ -__LA_DECL int archive_write_open_memory(struct archive *, - void *_buffer, size_t _buffSize, size_t *_used); - -/* - * Note that the library will truncate writes beyond the size provided - * to archive_write_header or pad if the provided data is short. - */ -__LA_DECL int archive_write_header(struct archive *, - struct archive_entry *); -#if ARCHIVE_VERSION_NUMBER < 2000000 -/* This was erroneously declared to return "int" in libarchive 1.x. */ -__LA_DECL int archive_write_data(struct archive *, - const void *, size_t); -#else -/* Libarchive 2.0 and later return ssize_t here. */ -__LA_DECL __LA_SSIZE_T archive_write_data(struct archive *, - const void *, size_t); -#endif - -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* Libarchive 1.x and 2.x use off_t for the argument, but that's not - * stable on Linux. */ -__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, - const void *, size_t, off_t); -#else -/* Libarchive 3.0 uses explicit int64_t to ensure consistent 64-bit support. */ -__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, - const void *, size_t, __LA_INT64_T); -#endif -__LA_DECL int archive_write_finish_entry(struct archive *); -__LA_DECL int archive_write_close(struct archive *); - -/* This can fail if the archive wasn't already closed, in which case - * archive_write_free() will implicitly call archive_write_close(). */ -__LA_DECL int archive_write_free(struct archive *); -#if ARCHIVE_VERSION_NUMBER < 4000000 -/* Synonym for archive_write_free() for backwards compatibility. */ -__LA_DECL int archive_write_finish(struct archive *); -#endif - -/* - * Set write options. - */ -/* Apply option string to the format only. */ -__LA_DECL int archive_write_set_format_options(struct archive *_a, - const char *s); -/* Apply option string to the compressor only. */ -__LA_DECL int archive_write_set_compressor_options(struct archive *_a, - const char *s); -/* Apply option string to both the format and the compressor. */ -__LA_DECL int archive_write_set_options(struct archive *_a, - const char *s); - - -/*- - * ARCHIVE_WRITE_DISK API - * - * To create objects on disk: - * 1) Ask archive_write_disk_new for a new archive_write_disk object. - * 2) Set any global properties. In particular, you probably - * want to set the options. - * 3) For each entry: - * - construct an appropriate struct archive_entry structure - * - archive_write_header to create the file/dir/etc on disk - * - archive_write_data to write the entry data - * 4) archive_write_free to cleanup the writer and release resources - * - * In particular, you can use this in conjunction with archive_read() - * to pull entries out of an archive and create them on disk. - */ -__LA_DECL struct archive *archive_write_disk_new(void); -/* This file will not be overwritten. */ -__LA_DECL int archive_write_disk_set_skip_file(struct archive *, - dev_t, ino_t); -/* Set flags to control how the next item gets created. - * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */ -__LA_DECL int archive_write_disk_set_options(struct archive *, - int flags); -/* - * The lookup functions are given uname/uid (or gname/gid) pairs and - * return a uid (gid) suitable for this system. These are used for - * restoring ownership and for setting ACLs. The default functions - * are naive, they just return the uid/gid. These are small, so reasonable - * for applications that don't need to preserve ownership; they - * are probably also appropriate for applications that are doing - * same-system backup and restore. - */ -/* - * The "standard" lookup functions use common system calls to lookup - * the uname/gname, falling back to the uid/gid if the names can't be - * found. They cache lookups and are reasonably fast, but can be very - * large, so they are not used unless you ask for them. In - * particular, these match the specifications of POSIX "pax" and old - * POSIX "tar". - */ -__LA_DECL int archive_write_disk_set_standard_lookup(struct archive *); -/* - * If neither the default (naive) nor the standard (big) functions suit - * your needs, you can write your own and register them. Be sure to - * include a cleanup function if you have allocated private data. - */ -__LA_DECL int archive_write_disk_set_group_lookup(struct archive *, - void * /* private_data */, - __LA_GID_T (*)(void *, const char *, __LA_GID_T), - void (* /* cleanup */)(void *)); -__LA_DECL int archive_write_disk_set_user_lookup(struct archive *, - void * /* private_data */, - __LA_UID_T (*)(void *, const char *, __LA_UID_T), - void (* /* cleanup */)(void *)); - -/* - * ARCHIVE_READ_DISK API - * - * This is still evolving and somewhat experimental. - */ -__LA_DECL struct archive *archive_read_disk_new(void); -/* The names for symlink modes here correspond to an old BSD - * command-line argument convention: -L, -P, -H */ -/* Follow all symlinks. */ -__LA_DECL int archive_read_disk_set_symlink_logical(struct archive *); -/* Follow no symlinks. */ -__LA_DECL int archive_read_disk_set_symlink_physical(struct archive *); -/* Follow symlink initially, then not. */ -__LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *); -/* TODO: Handle Linux stat32/stat64 ugliness. */ -__LA_DECL int archive_read_disk_entry_from_file(struct archive *, - struct archive_entry *, int /* fd */, const struct stat *); -/* Look up gname for gid or uname for uid. */ -/* Default implementations are very, very stupid. */ -__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_GID_T); -__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_UID_T); -/* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the - * results for performance. */ -__LA_DECL int archive_read_disk_set_standard_lookup(struct archive *); -/* You can install your own lookups if you like. */ -__LA_DECL int archive_read_disk_set_gname_lookup(struct archive *, - void * /* private_data */, - const char *(* /* lookup_fn */)(void *, __LA_GID_T), - void (* /* cleanup_fn */)(void *)); -__LA_DECL int archive_read_disk_set_uname_lookup(struct archive *, - void * /* private_data */, - const char *(* /* lookup_fn */)(void *, __LA_UID_T), - void (* /* cleanup_fn */)(void *)); - -/* - * Accessor functions to read/set various information in - * the struct archive object: - */ -/* Bytes written after compression or read before decompression. */ -__LA_DECL __LA_INT64_T archive_position_compressed(struct archive *); -/* Bytes written to compressor or read from decompressor. */ -__LA_DECL __LA_INT64_T archive_position_uncompressed(struct archive *); - -__LA_DECL const char *archive_compression_name(struct archive *); -__LA_DECL int archive_compression(struct archive *); -__LA_DECL int archive_errno(struct archive *); -__LA_DECL const char *archive_error_string(struct archive *); -__LA_DECL const char *archive_format_name(struct archive *); -__LA_DECL int archive_format(struct archive *); -__LA_DECL void archive_clear_error(struct archive *); -__LA_DECL void archive_set_error(struct archive *, int _err, - const char *fmt, ...) __LA_PRINTF(3, 4); -__LA_DECL void archive_copy_error(struct archive *dest, - struct archive *src); -__LA_DECL int archive_file_count(struct archive *); - -#ifdef __cplusplus -} -#endif - -/* These are meaningless outside of this header. */ -#undef __LA_DECL -#undef __LA_GID_T -#undef __LA_UID_T - -/* These need to remain defined because they're used in the - * callback type definitions. XXX Fix this. This is ugly. XXX */ -/* #undef __LA_INT64_T */ -/* #undef __LA_SSIZE_T */ - -#endif /* !ARCHIVE_H_INCLUDED */ diff --git a/lib/libarchive/archive_check_magic.c b/lib/libarchive/archive_check_magic.c deleted file mode 100644 index 1381a18..0000000 --- a/lib/libarchive/archive_check_magic.c +++ /dev/null @@ -1,134 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#if defined(_WIN32) && !defined(__CYGWIN__) -#include -#include -#endif - -#include "archive_private.h" - -static void -errmsg(const char *m) -{ - size_t s = strlen(m); - ssize_t written; - - while (s > 0) { - written = write(2, m, strlen(m)); - if (written <= 0) - return; - m += written; - s -= written; - } -} - -static void -diediedie(void) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) - /* Cause a breakpoint exception */ - DebugBreak(); -#endif - abort(); /* Terminate the program abnormally. */ -} - -static const char * -state_name(unsigned s) -{ - switch (s) { - case ARCHIVE_STATE_NEW: return ("new"); - case ARCHIVE_STATE_HEADER: return ("header"); - case ARCHIVE_STATE_DATA: return ("data"); - case ARCHIVE_STATE_EOF: return ("eof"); - case ARCHIVE_STATE_CLOSED: return ("closed"); - case ARCHIVE_STATE_FATAL: return ("fatal"); - default: return ("??"); - } -} - - -static void -write_all_states(unsigned int states) -{ - unsigned int lowbit; - - /* A trick for computing the lowest set bit. */ - while ((lowbit = states & (1 + ~states)) != 0) { - states &= ~lowbit; /* Clear the low bit. */ - errmsg(state_name(lowbit)); - if (states != 0) - errmsg("/"); - } -} - -/* - * Check magic value and current state; bail if it isn't valid. - * - * This is designed to catch serious programming errors that violate - * the libarchive API. - */ -void -__archive_check_magic(struct archive *a, unsigned int magic, - unsigned int state, const char *function) -{ - if (a->magic != magic) { - errmsg("INTERNAL ERROR: Function "); - errmsg(function); - errmsg(" invoked with invalid struct archive structure.\n"); - diediedie(); - } - - if (state == ARCHIVE_STATE_ANY) - return; - - if ((a->state & state) == 0) { - errmsg("INTERNAL ERROR: Function '"); - errmsg(function); - errmsg("' invoked with archive structure in state '"); - write_all_states(a->state); - errmsg("', should be in state '"); - write_all_states(state); - errmsg("'\n"); - diediedie(); - } -} diff --git a/lib/libarchive/archive_crc32.h b/lib/libarchive/archive_crc32.h deleted file mode 100644 index 7715754..0000000 --- a/lib/libarchive/archive_crc32.h +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 2009 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -/* - * When zlib is unavailable, we should still be able to validate - * uncompressed zip archives. That requires us to be able to compute - * the CRC32 check value. This is a drop-in compatible replacement - * for crc32() from zlib. It's slower than the zlib implementation, - * but still pretty fast: This runs about 300MB/s on my 3GHz P4 - * compared to about 800MB/s for the zlib implementation. - */ -static unsigned long -crc32(unsigned long crc, const void *_p, size_t len) -{ - unsigned long crc2, b, i; - const unsigned char *p = _p; - static volatile int crc_tbl_inited = 0; - static unsigned long crc_tbl[256]; - - if (!crc_tbl_inited) { - for (b = 0; b < 256; ++b) { - crc2 = b; - for (i = 8; i > 0; --i) { - if (crc2 & 1) - crc2 = (crc2 >> 1) ^ 0xedb88320UL; - else - crc2 = (crc2 >> 1); - } - crc_tbl[b] = crc2; - } - crc_tbl_inited = 1; - } - - crc = crc ^ 0xffffffffUL; - while (len--) - crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); - return (crc ^ 0xffffffffUL); -} diff --git a/lib/libarchive/archive_endian.h b/lib/libarchive/archive_endian.h deleted file mode 100644 index 9d01365..0000000 --- a/lib/libarchive/archive_endian.h +++ /dev/null @@ -1,162 +0,0 @@ -/*- - * Copyright (c) 2002 Thomas Moestl - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - * - * Borrowed from FreeBSD's - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -/* Note: This is a purely internal header! */ -/* Do not use this outside of libarchive internal code! */ - -#ifndef ARCHIVE_ENDIAN_H_INCLUDED -#define ARCHIVE_ENDIAN_H_INCLUDED - - -/* - * Disabling inline keyword for compilers known to choke on it: - * - Watcom C++ in C code. (For any version?) - * - SGI MIPSpro - * - Microsoft Visual C++ 6.0 (supposedly newer versions too) - */ -#if defined(__WATCOMC__) || defined(__sgi) || defined(__hpux) || defined(__BORLANDC__) -#define inline -#elif defined(_MSC_VER) -#define inline __inline -#endif - -/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ - -static inline uint16_t -archive_be16dec(const void *pp) -{ - unsigned char const *p = (unsigned char const *)pp; - - return ((p[0] << 8) | p[1]); -} - -static inline uint32_t -archive_be32dec(const void *pp) -{ - unsigned char const *p = (unsigned char const *)pp; - - return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); -} - -static inline uint64_t -archive_be64dec(const void *pp) -{ - unsigned char const *p = (unsigned char const *)pp; - - return (((uint64_t)archive_be32dec(p) << 32) | archive_be32dec(p + 4)); -} - -static inline uint16_t -archive_le16dec(const void *pp) -{ - unsigned char const *p = (unsigned char const *)pp; - - return ((p[1] << 8) | p[0]); -} - -static inline uint32_t -archive_le32dec(const void *pp) -{ - unsigned char const *p = (unsigned char const *)pp; - - return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); -} - -static inline uint64_t -archive_le64dec(const void *pp) -{ - unsigned char const *p = (unsigned char const *)pp; - - return (((uint64_t)archive_le32dec(p + 4) << 32) | archive_le32dec(p)); -} - -static inline void -archive_be16enc(void *pp, uint16_t u) -{ - unsigned char *p = (unsigned char *)pp; - - p[0] = (u >> 8) & 0xff; - p[1] = u & 0xff; -} - -static inline void -archive_be32enc(void *pp, uint32_t u) -{ - unsigned char *p = (unsigned char *)pp; - - p[0] = (u >> 24) & 0xff; - p[1] = (u >> 16) & 0xff; - p[2] = (u >> 8) & 0xff; - p[3] = u & 0xff; -} - -static inline void -archive_be64enc(void *pp, uint64_t u) -{ - unsigned char *p = (unsigned char *)pp; - - archive_be32enc(p, u >> 32); - archive_be32enc(p + 4, u & 0xffffffff); -} - -static inline void -archive_le16enc(void *pp, uint16_t u) -{ - unsigned char *p = (unsigned char *)pp; - - p[0] = u & 0xff; - p[1] = (u >> 8) & 0xff; -} - -static inline void -archive_le32enc(void *pp, uint32_t u) -{ - unsigned char *p = (unsigned char *)pp; - - p[0] = u & 0xff; - p[1] = (u >> 8) & 0xff; - p[2] = (u >> 16) & 0xff; - p[3] = (u >> 24) & 0xff; -} - -static inline void -archive_le64enc(void *pp, uint64_t u) -{ - unsigned char *p = (unsigned char *)pp; - - archive_le32enc(p, u & 0xffffffff); - archive_le32enc(p + 4, u >> 32); -} - -#endif diff --git a/lib/libarchive/archive_entry.3 b/lib/libarchive/archive_entry.3 deleted file mode 100644 index 35cb385..0000000 --- a/lib/libarchive/archive_entry.3 +++ /dev/null @@ -1,433 +0,0 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd May 12, 2008 -.Dt ARCHIVE_ENTRY 3 -.Os -.Sh NAME -.Nm archive_entry_acl_add_entry , -.Nm archive_entry_acl_add_entry_w , -.Nm archive_entry_acl_clear , -.Nm archive_entry_acl_count , -.Nm archive_entry_acl_next , -.Nm archive_entry_acl_next_w , -.Nm archive_entry_acl_reset , -.Nm archive_entry_acl_text_w , -.Nm archive_entry_atime , -.Nm archive_entry_atime_nsec , -.Nm archive_entry_clear , -.Nm archive_entry_clone , -.Nm archive_entry_copy_fflags_text , -.Nm archive_entry_copy_fflags_text_w , -.Nm archive_entry_copy_gname , -.Nm archive_entry_copy_gname_w , -.Nm archive_entry_copy_hardlink , -.Nm archive_entry_copy_hardlink_w , -.Nm archive_entry_copy_link , -.Nm archive_entry_copy_link_w , -.Nm archive_entry_copy_pathname_w , -.Nm archive_entry_copy_sourcepath , -.Nm archive_entry_copy_stat , -.Nm archive_entry_copy_symlink , -.Nm archive_entry_copy_symlink_w , -.Nm archive_entry_copy_uname , -.Nm archive_entry_copy_uname_w , -.Nm archive_entry_dev , -.Nm archive_entry_devmajor , -.Nm archive_entry_devminor , -.Nm archive_entry_filetype , -.Nm archive_entry_fflags , -.Nm archive_entry_fflags_text , -.Nm archive_entry_free , -.Nm archive_entry_gid , -.Nm archive_entry_gname , -.Nm archive_entry_hardlink , -.Nm archive_entry_ino , -.Nm archive_entry_mode , -.Nm archive_entry_mtime , -.Nm archive_entry_mtime_nsec , -.Nm archive_entry_nlink , -.Nm archive_entry_new , -.Nm archive_entry_pathname , -.Nm archive_entry_pathname_w , -.Nm archive_entry_rdev , -.Nm archive_entry_rdevmajor , -.Nm archive_entry_rdevminor , -.Nm archive_entry_set_atime , -.Nm archive_entry_set_ctime , -.Nm archive_entry_set_dev , -.Nm archive_entry_set_devmajor , -.Nm archive_entry_set_devminor , -.Nm archive_entry_set_filetype , -.Nm archive_entry_set_fflags , -.Nm archive_entry_set_gid , -.Nm archive_entry_set_gname , -.Nm archive_entry_set_hardlink , -.Nm archive_entry_set_link , -.Nm archive_entry_set_mode , -.Nm archive_entry_set_mtime , -.Nm archive_entry_set_pathname , -.Nm archive_entry_set_rdevmajor , -.Nm archive_entry_set_rdevminor , -.Nm archive_entry_set_size , -.Nm archive_entry_set_symlink , -.Nm archive_entry_set_uid , -.Nm archive_entry_set_uname , -.Nm archive_entry_size , -.Nm archive_entry_sourcepath , -.Nm archive_entry_stat , -.Nm archive_entry_symlink , -.Nm archive_entry_uid , -.Nm archive_entry_uname -.Nd functions for manipulating archive entry descriptions -.Sh SYNOPSIS -.In archive_entry.h -.Ft void -.Fo archive_entry_acl_add_entry -.Fa "struct archive_entry *" -.Fa "int type" -.Fa "int permset" -.Fa "int tag" -.Fa "int qual" -.Fa "const char *name" -.Fc -.Ft void -.Fo archive_entry_acl_add_entry_w -.Fa "struct archive_entry *" -.Fa "int type" -.Fa "int permset" -.Fa "int tag" -.Fa "int qual" -.Fa "const wchar_t *name" -.Fc -.Ft void -.Fn archive_entry_acl_clear "struct archive_entry *" -.Ft int -.Fn archive_entry_acl_count "struct archive_entry *" "int type" -.Ft int -.Fo archive_entry_acl_next -.Fa "struct archive_entry *" -.Fa "int want_type" -.Fa "int *type" -.Fa "int *permset" -.Fa "int *tag" -.Fa "int *qual" -.Fa "const char **name" -.Fc -.Ft int -.Fo archive_entry_acl_next_w -.Fa "struct archive_entry *" -.Fa "int want_type" -.Fa "int *type" -.Fa "int *permset" -.Fa "int *tag" -.Fa "int *qual" -.Fa "const wchar_t **name" -.Fc -.Ft int -.Fn archive_entry_acl_reset "struct archive_entry *" "int want_type" -.Ft const wchar_t * -.Fn archive_entry_acl_text_w "struct archive_entry *" "int flags" -.Ft time_t -.Fn archive_entry_atime "struct archive_entry *" -.Ft long -.Fn archive_entry_atime_nsec "struct archive_entry *" -.Ft "struct archive_entry *" -.Fn archive_entry_clear "struct archive_entry *" -.Ft struct archive_entry * -.Fn archive_entry_clone "struct archive_entry *" -.Ft const char * * -.Fn archive_entry_copy_fflags_text_w "struct archive_entry *" "const char *" -.Ft const wchar_t * -.Fn archive_entry_copy_fflags_text_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_gname "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_gname_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_hardlink "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_hardlink_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_sourcepath "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_pathname_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_stat "struct archive_entry *" "const struct stat *" -.Ft void -.Fn archive_entry_copy_symlink "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_symlink_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_uname "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_uname_w "struct archive_entry *" "const wchar_t *" -.Ft dev_t -.Fn archive_entry_dev "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_devmajor "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_devminor "struct archive_entry *" -.Ft mode_t -.Fn archive_entry_filetype "struct archive_entry *" -.Ft void -.Fo archive_entry_fflags -.Fa "struct archive_entry *" -.Fa "unsigned long *set" -.Fa "unsigned long *clear" -.Fc -.Ft const char * -.Fn archive_entry_fflags_text "struct archive_entry *" -.Ft void -.Fn archive_entry_free "struct archive_entry *" -.Ft const char * -.Fn archive_entry_gname "struct archive_entry *" -.Ft const char * -.Fn archive_entry_hardlink "struct archive_entry *" -.Ft ino_t -.Fn archive_entry_ino "struct archive_entry *" -.Ft mode_t -.Fn archive_entry_mode "struct archive_entry *" -.Ft time_t -.Fn archive_entry_mtime "struct archive_entry *" -.Ft long -.Fn archive_entry_mtime_nsec "struct archive_entry *" -.Ft unsigned int -.Fn archive_entry_nlink "struct archive_entry *" -.Ft struct archive_entry * -.Fn archive_entry_new "void" -.Ft const char * -.Fn archive_entry_pathname "struct archive_entry *" -.Ft const wchar_t * -.Fn archive_entry_pathname_w "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_rdev "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_rdevmajor "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_rdevminor "struct archive_entry *" -.Ft void -.Fn archive_entry_set_dev "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_devmajor "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_devminor "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_filetype "struct archive_entry *" "unsigned int" -.Ft void -.Fo archive_entry_set_fflags -.Fa "struct archive_entry *" -.Fa "unsigned long set" -.Fa "unsigned long clear" -.Fc -.Ft void -.Fn archive_entry_set_gid "struct archive_entry *" "gid_t" -.Ft void -.Fn archive_entry_set_gname "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_hardlink "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_ino "struct archive_entry *" "unsigned long" -.Ft void -.Fn archive_entry_set_link "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_mode "struct archive_entry *" "mode_t" -.Ft void -.Fn archive_entry_set_mtime "struct archive_entry *" "time_t" "long nanos" -.Ft void -.Fn archive_entry_set_nlink "struct archive_entry *" "unsigned int" -.Ft void -.Fn archive_entry_set_pathname "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_rdev "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_rdevmajor "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_rdevminor "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_size "struct archive_entry *" "int64_t" -.Ft void -.Fn archive_entry_set_symlink "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_uid "struct archive_entry *" "uid_t" -.Ft void -.Fn archive_entry_set_uname "struct archive_entry *" "const char *" -.Ft int64_t -.Fn archive_entry_size "struct archive_entry *" -.Ft const char * -.Fn archive_entry_sourcepath "struct archive_entry *" -.Ft const struct stat * -.Fn archive_entry_stat "struct archive_entry *" -.Ft const char * -.Fn archive_entry_symlink "struct archive_entry *" -.Ft const char * -.Fn archive_entry_uname "struct archive_entry *" -.Sh DESCRIPTION -These functions create and manipulate data objects that -represent entries within an archive. -You can think of a -.Tn struct archive_entry -as a heavy-duty version of -.Tn struct stat : -it includes everything from -.Tn struct stat -plus associated pathname, textual group and user names, etc. -These objects are used by -.Xr libarchive 3 -to represent the metadata associated with a particular -entry in an archive. -.Ss Create and Destroy -There are functions to allocate, destroy, clear, and copy -.Va archive_entry -objects: -.Bl -tag -compact -width indent -.It Fn archive_entry_clear -Erases the object, resetting all internal fields to the -same state as a newly-created object. -This is provided to allow you to quickly recycle objects -without thrashing the heap. -.It Fn archive_entry_clone -A deep copy operation; all text fields are duplicated. -.It Fn archive_entry_free -Releases the -.Tn struct archive_entry -object. -.It Fn archive_entry_new -Allocate and return a blank -.Tn struct archive_entry -object. -.El -.Ss Set and Get Functions -Most of the functions here set or read entries in an object. -Such functions have one of the following forms: -.Bl -tag -compact -width indent -.It Fn archive_entry_set_XXXX -Stores the provided data in the object. -In particular, for strings, the pointer is stored, -not the referenced string. -.It Fn archive_entry_copy_XXXX -As above, except that the referenced data is copied -into the object. -.It Fn archive_entry_XXXX -Returns the specified data. -In the case of strings, a const-qualified pointer to -the string is returned. -.El -String data can be set or accessed as wide character strings -or normal -.Va char -strings. -The functions that use wide character strings are suffixed with -.Cm _w . -Note that these are different representations of the same data: -For example, if you store a narrow string and read the corresponding -wide string, the object will transparently convert formats -using the current locale. -Similarly, if you store a wide string and then store a -narrow string for the same data, the previously-set wide string will -be discarded in favor of the new data. -.Pp -There are a few set/get functions that merit additional description: -.Bl -tag -compact -width indent -.It Fn archive_entry_set_link -This function sets the symlink field if it is already set. -Otherwise, it sets the hardlink field. -.El -.Ss File Flags -File flags are transparently converted between a bitmap -representation and a textual format. -For example, if you set the bitmap and ask for text, the library -will build a canonical text format. -However, if you set a text format and request a text format, -you will get back the same text, even if it is ill-formed. -If you need to canonicalize a textual flags string, you should first set the -text form, then request the bitmap form, then use that to set the bitmap form. -Setting the bitmap format will clear the internal text representation -and force it to be reconstructed when you next request the text form. -.Pp -The bitmap format consists of two integers, one containing bits -that should be set, the other specifying bits that should be -cleared. -Bits not mentioned in either bitmap will be ignored. -Usually, the bitmap of bits to be cleared will be set to zero. -In unusual circumstances, you can force a fully-specified set -of file flags by setting the bitmap of flags to clear to the complement -of the bitmap of flags to set. -(This differs from -.Xr fflagstostr 3 , -which only includes names for set bits.) -Converting a bitmap to a textual string is a platform-specific -operation; bits that are not meaningful on the current platform -will be ignored. -.Pp -The canonical text format is a comma-separated list of flag names. -The -.Fn archive_entry_copy_fflags_text -and -.Fn archive_entry_copy_fflags_text_w -functions parse the provided text and sets the internal bitmap values. -This is a platform-specific operation; names that are not meaningful -on the current platform will be ignored. -The function returns a pointer to the start of the first name that was not -recognized, or NULL if every name was recognized. -Note that every name--including names that follow an unrecognized name--will -be evaluated, and the bitmaps will be set to reflect every name that is -recognized. -(In particular, this differs from -.Xr strtofflags 3 , -which stops parsing at the first unrecognized name.) -.Ss ACL Handling -XXX This needs serious help. -XXX -.Pp -An -.Dq Access Control List -(ACL) is a list of permissions that grant access to particular users or -groups beyond what would normally be provided by standard POSIX mode bits. -The ACL handling here addresses some deficiencies in the POSIX.1e draft 17 ACL -specification. -In particular, POSIX.1e draft 17 specifies several different formats, but -none of those formats include both textual user/group names and numeric -UIDs/GIDs. -.Pp -XXX explain ACL stuff XXX -.\" .Sh EXAMPLE -.\" .Sh RETURN VALUES -.\" .Sh ERRORS -.Sh SEE ALSO -.Xr archive 3 -.Sh HISTORY -The -.Nm libarchive -library first appeared in -.Fx 5.3 . -.Sh AUTHORS -.An -nosplit -The -.Nm libarchive -library was written by -.An Tim Kientzle Aq kientzle@acm.org . -.\" .Sh BUGS diff --git a/lib/libarchive/archive_entry.c b/lib/libarchive/archive_entry.c deleted file mode 100644 index 1202a8a..0000000 --- a/lib/libarchive/archive_entry.c +++ /dev/null @@ -1,2202 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#if MAJOR_IN_MKDEV -#include -#define HAVE_MAJOR -#elif MAJOR_IN_SYSMACROS -#include -#define HAVE_MAJOR -#endif -#ifdef HAVE_LIMITS_H -#include -#endif -#ifdef HAVE_LINUX_FS_H -#include /* for Linux file flags */ -#endif -/* - * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. - * As the include guards don't agree, the order of include is important. - */ -#ifdef HAVE_LINUX_EXT2_FS_H -#include /* for Linux file flags */ -#endif -#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) -#include /* for Linux file flags */ -#endif -#include -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_WCHAR_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_entry_private.h" - -#undef max -#define max(a, b) ((a)>(b)?(a):(b)) - -#if !defined(HAVE_MAJOR) && !defined(major) -/* Replacement for major/minor/makedev. */ -#define major(x) ((int)(0x00ff & ((x) >> 8))) -#define minor(x) ((int)(0xffff00ff & (x))) -#define makedev(maj,min) ((0xff00 & ((maj)<<8)) | (0xffff00ff & (min))) -#endif - -/* Play games to come up with a suitable makedev() definition. */ -#ifdef __QNXNTO__ -/* QNX. */ -#include -#define ae_makedev(maj, min) makedev(ND_LOCAL_NODE, (maj), (min)) -#elif defined makedev -/* There's a "makedev" macro. */ -#define ae_makedev(maj, min) makedev((maj), (min)) -#elif defined mkdev || ((defined _WIN32 || defined __WIN32__) && !defined(__CYGWIN__)) -/* Windows. */ -#define ae_makedev(maj, min) mkdev((maj), (min)) -#else -/* There's a "makedev" function. */ -#define ae_makedev(maj, min) makedev((maj), (min)) -#endif - -static void aes_clean(struct aes *); -static void aes_copy(struct aes *dest, struct aes *src); -static const char * aes_get_mbs(struct aes *); -static const wchar_t * aes_get_wcs(struct aes *); -static int aes_set_mbs(struct aes *, const char *mbs); -static int aes_copy_mbs(struct aes *, const char *mbs); -/* static void aes_set_wcs(struct aes *, const wchar_t *wcs); */ -static int aes_copy_wcs(struct aes *, const wchar_t *wcs); -static int aes_copy_wcs_len(struct aes *, const wchar_t *wcs, size_t); - -static char * ae_fflagstostr(unsigned long bitset, unsigned long bitclear); -static const wchar_t *ae_wcstofflags(const wchar_t *stringp, - unsigned long *setp, unsigned long *clrp); -static const char *ae_strtofflags(const char *stringp, - unsigned long *setp, unsigned long *clrp); -static void append_entry_w(wchar_t **wp, const wchar_t *prefix, int tag, - const wchar_t *wname, int perm, int id); -static void append_id_w(wchar_t **wp, int id); - -static int acl_special(struct archive_entry *entry, - int type, int permset, int tag); -static struct ae_acl *acl_new_entry(struct archive_entry *entry, - int type, int permset, int tag, int id); -static int isint_w(const wchar_t *start, const wchar_t *end, int *result); -static int ismode_w(const wchar_t *start, const wchar_t *end, int *result); -static void next_field_w(const wchar_t **wp, const wchar_t **start, - const wchar_t **end, wchar_t *sep); -static int prefix_w(const wchar_t *start, const wchar_t *end, - const wchar_t *test); -static void -archive_entry_acl_add_entry_w_len(struct archive_entry *entry, int type, - int permset, int tag, int id, const wchar_t *name, size_t); - - -#ifndef HAVE_WCSCPY -static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2) -{ - wchar_t *dest = s1; - while ((*s1 = *s2) != L'\0') - ++s1, ++s2; - return dest; -} -#endif -#ifndef HAVE_WCSLEN -static size_t wcslen(const wchar_t *s) -{ - const wchar_t *p = s; - while (*p != L'\0') - ++p; - return p - s; -} -#endif -#ifndef HAVE_WMEMCMP -/* Good enough for simple equality testing, but not for sorting. */ -#define wmemcmp(a,b,i) memcmp((a), (b), (i) * sizeof(wchar_t)) -#endif -#ifndef HAVE_WMEMCPY -#define wmemcpy(a,b,i) (wchar_t *)memcpy((a), (b), (i) * sizeof(wchar_t)) -#endif - -static void -aes_clean(struct aes *aes) -{ - if (aes->aes_wcs) { - free((wchar_t *)(uintptr_t)aes->aes_wcs); - aes->aes_wcs = NULL; - } - archive_string_free(&(aes->aes_mbs)); - archive_string_free(&(aes->aes_utf8)); - aes->aes_set = 0; -} - -static void -aes_copy(struct aes *dest, struct aes *src) -{ - wchar_t *wp; - - dest->aes_set = src->aes_set; - archive_string_copy(&(dest->aes_mbs), &(src->aes_mbs)); - archive_string_copy(&(dest->aes_utf8), &(src->aes_utf8)); - - if (src->aes_wcs != NULL) { - wp = (wchar_t *)malloc((wcslen(src->aes_wcs) + 1) - * sizeof(wchar_t)); - if (wp == NULL) - __archive_errx(1, "No memory for aes_copy()"); - wcscpy(wp, src->aes_wcs); - dest->aes_wcs = wp; - } -} - -static const char * -aes_get_utf8(struct aes *aes) -{ - if (aes->aes_set & AES_SET_UTF8) - return (aes->aes_utf8.s); - if ((aes->aes_set & AES_SET_WCS) - && archive_strappend_w_utf8(&(aes->aes_utf8), aes->aes_wcs) != NULL) { - aes->aes_set |= AES_SET_UTF8; - return (aes->aes_utf8.s); - } - return (NULL); -} - -static const char * -aes_get_mbs(struct aes *aes) -{ - /* If we already have an MBS form, return that immediately. */ - if (aes->aes_set & AES_SET_MBS) - return (aes->aes_mbs.s); - /* If there's a WCS form, try converting with the native locale. */ - if ((aes->aes_set & AES_SET_WCS) - && archive_strappend_w_mbs(&(aes->aes_mbs), aes->aes_wcs) != NULL) { - aes->aes_set |= AES_SET_MBS; - return (aes->aes_mbs.s); - } - /* We'll use UTF-8 for MBS if all else fails. */ - return (aes_get_utf8(aes)); -} - -static const wchar_t * -aes_get_wcs(struct aes *aes) -{ - wchar_t *w; - size_t r; - - /* Return WCS form if we already have it. */ - if (aes->aes_set & AES_SET_WCS) - return (aes->aes_wcs); - - if (aes->aes_set & AES_SET_MBS) { - /* Try converting MBS to WCS using native locale. */ - /* - * No single byte will be more than one wide character, - * so this length estimate will always be big enough. - */ - size_t wcs_length = aes->aes_mbs.length; - - w = (wchar_t *)malloc((wcs_length + 1) * sizeof(wchar_t)); - if (w == NULL) - __archive_errx(1, "No memory for aes_get_wcs()"); - r = mbstowcs(w, aes->aes_mbs.s, wcs_length); - if (r != (size_t)-1 && r != 0) { - w[r] = 0; - aes->aes_set |= AES_SET_WCS; - return (aes->aes_wcs = w); - } - free(w); - } - - if (aes->aes_set & AES_SET_UTF8) { - /* Try converting UTF8 to WCS. */ - aes->aes_wcs = __archive_string_utf8_w(&(aes->aes_utf8)); - if (aes->aes_wcs != NULL) - aes->aes_set |= AES_SET_WCS; - return (aes->aes_wcs); - } - return (NULL); -} - -static int -aes_set_mbs(struct aes *aes, const char *mbs) -{ - return (aes_copy_mbs(aes, mbs)); -} - -static int -aes_copy_mbs(struct aes *aes, const char *mbs) -{ - if (mbs == NULL) { - aes->aes_set = 0; - return (0); - } - aes->aes_set = AES_SET_MBS; /* Only MBS form is set now. */ - archive_strcpy(&(aes->aes_mbs), mbs); - archive_string_empty(&(aes->aes_utf8)); - if (aes->aes_wcs) { - free((wchar_t *)(uintptr_t)aes->aes_wcs); - aes->aes_wcs = NULL; - } - return (0); -} - -/* - * The 'update' form tries to proactively update all forms of - * this string (WCS and MBS) and returns an error if any of - * them fail. This is used by the 'pax' handler, for instance, - * to detect and report character-conversion failures early while - * still allowing clients to get potentially useful values from - * the more tolerant lazy conversions. (get_mbs and get_wcs will - * strive to give the user something useful, so you can get hopefully - * usable values even if some of the character conversions are failing.) - */ -static int -aes_update_utf8(struct aes *aes, const char *utf8) -{ - if (utf8 == NULL) { - aes->aes_set = 0; - return (1); /* Succeeded in clearing everything. */ - } - - /* Save the UTF8 string. */ - archive_strcpy(&(aes->aes_utf8), utf8); - - /* Empty the mbs and wcs strings. */ - archive_string_empty(&(aes->aes_mbs)); - if (aes->aes_wcs) { - free((wchar_t *)(uintptr_t)aes->aes_wcs); - aes->aes_wcs = NULL; - } - - aes->aes_set = AES_SET_UTF8; /* Only UTF8 is set now. */ - - /* TODO: We should just do a direct UTF-8 to MBS conversion - * here. That would be faster, use less space, and give the - * same information. (If a UTF-8 to MBS conversion succeeds, - * then UTF-8->WCS and Unicode->MBS conversions will both - * succeed.) */ - - /* Try converting UTF8 to WCS, return false on failure. */ - aes->aes_wcs = __archive_string_utf8_w(&(aes->aes_utf8)); - if (aes->aes_wcs == NULL) - return (0); - aes->aes_set = AES_SET_UTF8 | AES_SET_WCS; /* Both UTF8 and WCS set. */ - - /* Try converting WCS to MBS, return false on failure. */ - if (archive_strappend_w_mbs(&(aes->aes_mbs), aes->aes_wcs) == NULL) - return (0); - aes->aes_set = AES_SET_UTF8 | AES_SET_WCS | AES_SET_MBS; - - /* All conversions succeeded. */ - return (1); -} - -static int -aes_copy_wcs(struct aes *aes, const wchar_t *wcs) -{ - return aes_copy_wcs_len(aes, wcs, wcs == NULL ? 0 : wcslen(wcs)); -} - -static int -aes_copy_wcs_len(struct aes *aes, const wchar_t *wcs, size_t len) -{ - wchar_t *w; - - if (wcs == NULL) { - aes->aes_set = 0; - return (0); - } - aes->aes_set = AES_SET_WCS; /* Only WCS form set. */ - archive_string_empty(&(aes->aes_mbs)); - archive_string_empty(&(aes->aes_utf8)); - if (aes->aes_wcs) { - free((wchar_t *)(uintptr_t)aes->aes_wcs); - aes->aes_wcs = NULL; - } - w = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); - if (w == NULL) - __archive_errx(1, "No memory for aes_copy_wcs()"); - wmemcpy(w, wcs, len); - w[len] = L'\0'; - aes->aes_wcs = w; - return (0); -} - -/**************************************************************************** - * - * Public Interface - * - ****************************************************************************/ - -struct archive_entry * -archive_entry_clear(struct archive_entry *entry) -{ - if (entry == NULL) - return (NULL); - aes_clean(&entry->ae_fflags_text); - aes_clean(&entry->ae_gname); - aes_clean(&entry->ae_hardlink); - aes_clean(&entry->ae_pathname); - aes_clean(&entry->ae_sourcepath); - aes_clean(&entry->ae_symlink); - aes_clean(&entry->ae_uname); - archive_entry_acl_clear(entry); - archive_entry_xattr_clear(entry); - free(entry->stat); - memset(entry, 0, sizeof(*entry)); - return entry; -} - -struct archive_entry * -archive_entry_clone(struct archive_entry *entry) -{ - struct archive_entry *entry2; - struct ae_acl *ap, *ap2; - struct ae_xattr *xp; - - /* Allocate new structure and copy over all of the fields. */ - entry2 = (struct archive_entry *)malloc(sizeof(*entry2)); - if (entry2 == NULL) - return (NULL); - memset(entry2, 0, sizeof(*entry2)); - entry2->ae_stat = entry->ae_stat; - entry2->ae_fflags_set = entry->ae_fflags_set; - entry2->ae_fflags_clear = entry->ae_fflags_clear; - - aes_copy(&entry2->ae_fflags_text, &entry->ae_fflags_text); - aes_copy(&entry2->ae_gname, &entry->ae_gname); - aes_copy(&entry2->ae_hardlink, &entry->ae_hardlink); - aes_copy(&entry2->ae_pathname, &entry->ae_pathname); - aes_copy(&entry2->ae_sourcepath, &entry->ae_sourcepath); - aes_copy(&entry2->ae_symlink, &entry->ae_symlink); - entry2->ae_set = entry->ae_set; - aes_copy(&entry2->ae_uname, &entry->ae_uname); - - /* Copy ACL data over. */ - ap = entry->acl_head; - while (ap != NULL) { - ap2 = acl_new_entry(entry2, - ap->type, ap->permset, ap->tag, ap->id); - if (ap2 != NULL) - aes_copy(&ap2->name, &ap->name); - ap = ap->next; - } - - /* Copy xattr data over. */ - xp = entry->xattr_head; - while (xp != NULL) { - archive_entry_xattr_add_entry(entry2, - xp->name, xp->value, xp->size); - xp = xp->next; - } - - return (entry2); -} - -void -archive_entry_free(struct archive_entry *entry) -{ - archive_entry_clear(entry); - free(entry); -} - -struct archive_entry * -archive_entry_new(void) -{ - struct archive_entry *entry; - - entry = (struct archive_entry *)malloc(sizeof(*entry)); - if (entry == NULL) - return (NULL); - memset(entry, 0, sizeof(*entry)); - return (entry); -} - -/* - * Functions for reading fields from an archive_entry. - */ - -time_t -archive_entry_atime(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_atime); -} - -long -archive_entry_atime_nsec(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_atime_nsec); -} - -int -archive_entry_atime_is_set(struct archive_entry *entry) -{ - return (entry->ae_set & AE_SET_ATIME); -} - -time_t -archive_entry_birthtime(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_birthtime); -} - -long -archive_entry_birthtime_nsec(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_birthtime_nsec); -} - -int -archive_entry_birthtime_is_set(struct archive_entry *entry) -{ - return (entry->ae_set & AE_SET_BIRTHTIME); -} - -time_t -archive_entry_ctime(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_ctime); -} - -int -archive_entry_ctime_is_set(struct archive_entry *entry) -{ - return (entry->ae_set & AE_SET_CTIME); -} - -long -archive_entry_ctime_nsec(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_ctime_nsec); -} - -dev_t -archive_entry_dev(struct archive_entry *entry) -{ - if (entry->ae_stat.aest_dev_is_broken_down) - return ae_makedev(entry->ae_stat.aest_devmajor, - entry->ae_stat.aest_devminor); - else - return (entry->ae_stat.aest_dev); -} - -dev_t -archive_entry_devmajor(struct archive_entry *entry) -{ - if (entry->ae_stat.aest_dev_is_broken_down) - return (entry->ae_stat.aest_devmajor); - else - return major(entry->ae_stat.aest_dev); -} - -dev_t -archive_entry_devminor(struct archive_entry *entry) -{ - if (entry->ae_stat.aest_dev_is_broken_down) - return (entry->ae_stat.aest_devminor); - else - return minor(entry->ae_stat.aest_dev); -} - -mode_t -archive_entry_filetype(struct archive_entry *entry) -{ - return (AE_IFMT & entry->ae_stat.aest_mode); -} - -void -archive_entry_fflags(struct archive_entry *entry, - unsigned long *set, unsigned long *clear) -{ - *set = entry->ae_fflags_set; - *clear = entry->ae_fflags_clear; -} - -/* - * Note: if text was provided, this just returns that text. If you - * really need the text to be rebuilt in a canonical form, set the - * text, ask for the bitmaps, then set the bitmaps. (Setting the - * bitmaps clears any stored text.) This design is deliberate: if - * we're editing archives, we don't want to discard flags just because - * they aren't supported on the current system. The bitmap<->text - * conversions are platform-specific (see below). - */ -const char * -archive_entry_fflags_text(struct archive_entry *entry) -{ - const char *f; - char *p; - - f = aes_get_mbs(&entry->ae_fflags_text); - if (f != NULL) - return (f); - - if (entry->ae_fflags_set == 0 && entry->ae_fflags_clear == 0) - return (NULL); - - p = ae_fflagstostr(entry->ae_fflags_set, entry->ae_fflags_clear); - if (p == NULL) - return (NULL); - - aes_copy_mbs(&entry->ae_fflags_text, p); - free(p); - f = aes_get_mbs(&entry->ae_fflags_text); - return (f); -} - -gid_t -archive_entry_gid(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_gid); -} - -const char * -archive_entry_gname(struct archive_entry *entry) -{ - return (aes_get_mbs(&entry->ae_gname)); -} - -const wchar_t * -archive_entry_gname_w(struct archive_entry *entry) -{ - return (aes_get_wcs(&entry->ae_gname)); -} - -const char * -archive_entry_hardlink(struct archive_entry *entry) -{ - if (entry->ae_set & AE_SET_HARDLINK) - return (aes_get_mbs(&entry->ae_hardlink)); - return (NULL); -} - -const wchar_t * -archive_entry_hardlink_w(struct archive_entry *entry) -{ - if (entry->ae_set & AE_SET_HARDLINK) - return (aes_get_wcs(&entry->ae_hardlink)); - return (NULL); -} - -ino_t -archive_entry_ino(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_ino); -} - -int64_t -archive_entry_ino64(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_ino); -} - -mode_t -archive_entry_mode(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_mode); -} - -time_t -archive_entry_mtime(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_mtime); -} - -long -archive_entry_mtime_nsec(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_mtime_nsec); -} - -int -archive_entry_mtime_is_set(struct archive_entry *entry) -{ - return (entry->ae_set & AE_SET_MTIME); -} - -unsigned int -archive_entry_nlink(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_nlink); -} - -const char * -archive_entry_pathname(struct archive_entry *entry) -{ - return (aes_get_mbs(&entry->ae_pathname)); -} - -const wchar_t * -archive_entry_pathname_w(struct archive_entry *entry) -{ - return (aes_get_wcs(&entry->ae_pathname)); -} - -dev_t -archive_entry_rdev(struct archive_entry *entry) -{ - if (entry->ae_stat.aest_rdev_is_broken_down) - return ae_makedev(entry->ae_stat.aest_rdevmajor, - entry->ae_stat.aest_rdevminor); - else - return (entry->ae_stat.aest_rdev); -} - -dev_t -archive_entry_rdevmajor(struct archive_entry *entry) -{ - if (entry->ae_stat.aest_rdev_is_broken_down) - return (entry->ae_stat.aest_rdevmajor); - else - return major(entry->ae_stat.aest_rdev); -} - -dev_t -archive_entry_rdevminor(struct archive_entry *entry) -{ - if (entry->ae_stat.aest_rdev_is_broken_down) - return (entry->ae_stat.aest_rdevminor); - else - return minor(entry->ae_stat.aest_rdev); -} - -int64_t -archive_entry_size(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_size); -} - -int -archive_entry_size_is_set(struct archive_entry *entry) -{ - return (entry->ae_set & AE_SET_SIZE); -} - -const char * -archive_entry_sourcepath(struct archive_entry *entry) -{ - return (aes_get_mbs(&entry->ae_sourcepath)); -} - -const char * -archive_entry_symlink(struct archive_entry *entry) -{ - if (entry->ae_set & AE_SET_SYMLINK) - return (aes_get_mbs(&entry->ae_symlink)); - return (NULL); -} - -const wchar_t * -archive_entry_symlink_w(struct archive_entry *entry) -{ - if (entry->ae_set & AE_SET_SYMLINK) - return (aes_get_wcs(&entry->ae_symlink)); - return (NULL); -} - -uid_t -archive_entry_uid(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_uid); -} - -const char * -archive_entry_uname(struct archive_entry *entry) -{ - return (aes_get_mbs(&entry->ae_uname)); -} - -const wchar_t * -archive_entry_uname_w(struct archive_entry *entry) -{ - return (aes_get_wcs(&entry->ae_uname)); -} - -/* - * Functions to set archive_entry properties. - */ - -void -archive_entry_set_filetype(struct archive_entry *entry, unsigned int type) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_mode &= ~AE_IFMT; - entry->ae_stat.aest_mode |= AE_IFMT & type; -} - -void -archive_entry_set_fflags(struct archive_entry *entry, - unsigned long set, unsigned long clear) -{ - aes_clean(&entry->ae_fflags_text); - entry->ae_fflags_set = set; - entry->ae_fflags_clear = clear; -} - -const char * -archive_entry_copy_fflags_text(struct archive_entry *entry, - const char *flags) -{ - aes_copy_mbs(&entry->ae_fflags_text, flags); - return (ae_strtofflags(flags, - &entry->ae_fflags_set, &entry->ae_fflags_clear)); -} - -const wchar_t * -archive_entry_copy_fflags_text_w(struct archive_entry *entry, - const wchar_t *flags) -{ - aes_copy_wcs(&entry->ae_fflags_text, flags); - return (ae_wcstofflags(flags, - &entry->ae_fflags_set, &entry->ae_fflags_clear)); -} - -void -archive_entry_set_gid(struct archive_entry *entry, gid_t g) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_gid = g; -} - -void -archive_entry_set_gname(struct archive_entry *entry, const char *name) -{ - aes_set_mbs(&entry->ae_gname, name); -} - -void -archive_entry_copy_gname(struct archive_entry *entry, const char *name) -{ - aes_copy_mbs(&entry->ae_gname, name); -} - -void -archive_entry_copy_gname_w(struct archive_entry *entry, const wchar_t *name) -{ - aes_copy_wcs(&entry->ae_gname, name); -} - -int -archive_entry_update_gname_utf8(struct archive_entry *entry, const char *name) -{ - return (aes_update_utf8(&entry->ae_gname, name)); -} - -void -archive_entry_set_ino(struct archive_entry *entry, unsigned long ino) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_ino = ino; -} - -void -archive_entry_set_ino64(struct archive_entry *entry, int64_t ino) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_ino = ino; -} - -void -archive_entry_set_hardlink(struct archive_entry *entry, const char *target) -{ - aes_set_mbs(&entry->ae_hardlink, target); - if (target != NULL) - entry->ae_set |= AE_SET_HARDLINK; - else - entry->ae_set &= ~AE_SET_HARDLINK; -} - -void -archive_entry_copy_hardlink(struct archive_entry *entry, const char *target) -{ - aes_copy_mbs(&entry->ae_hardlink, target); - if (target != NULL) - entry->ae_set |= AE_SET_HARDLINK; - else - entry->ae_set &= ~AE_SET_HARDLINK; -} - -void -archive_entry_copy_hardlink_w(struct archive_entry *entry, const wchar_t *target) -{ - aes_copy_wcs(&entry->ae_hardlink, target); - if (target != NULL) - entry->ae_set |= AE_SET_HARDLINK; - else - entry->ae_set &= ~AE_SET_HARDLINK; -} - -int -archive_entry_update_hardlink_utf8(struct archive_entry *entry, const char *target) -{ - if (target != NULL) - entry->ae_set |= AE_SET_HARDLINK; - else - entry->ae_set &= ~AE_SET_HARDLINK; - return (aes_update_utf8(&entry->ae_hardlink, target)); -} - -void -archive_entry_set_atime(struct archive_entry *entry, time_t t, long ns) -{ - entry->stat_valid = 0; - entry->ae_set |= AE_SET_ATIME; - entry->ae_stat.aest_atime = t; - entry->ae_stat.aest_atime_nsec = ns; -} - -void -archive_entry_unset_atime(struct archive_entry *entry) -{ - archive_entry_set_atime(entry, 0, 0); - entry->ae_set &= ~AE_SET_ATIME; -} - -void -archive_entry_set_birthtime(struct archive_entry *entry, time_t m, long ns) -{ - entry->stat_valid = 0; - entry->ae_set |= AE_SET_BIRTHTIME; - entry->ae_stat.aest_birthtime = m; - entry->ae_stat.aest_birthtime_nsec = ns; -} - -void -archive_entry_unset_birthtime(struct archive_entry *entry) -{ - archive_entry_set_birthtime(entry, 0, 0); - entry->ae_set &= ~AE_SET_BIRTHTIME; -} - -void -archive_entry_set_ctime(struct archive_entry *entry, time_t t, long ns) -{ - entry->stat_valid = 0; - entry->ae_set |= AE_SET_CTIME; - entry->ae_stat.aest_ctime = t; - entry->ae_stat.aest_ctime_nsec = ns; -} - -void -archive_entry_unset_ctime(struct archive_entry *entry) -{ - archive_entry_set_ctime(entry, 0, 0); - entry->ae_set &= ~AE_SET_CTIME; -} - -void -archive_entry_set_dev(struct archive_entry *entry, dev_t d) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_dev_is_broken_down = 0; - entry->ae_stat.aest_dev = d; -} - -void -archive_entry_set_devmajor(struct archive_entry *entry, dev_t m) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_dev_is_broken_down = 1; - entry->ae_stat.aest_devmajor = m; -} - -void -archive_entry_set_devminor(struct archive_entry *entry, dev_t m) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_dev_is_broken_down = 1; - entry->ae_stat.aest_devminor = m; -} - -/* Set symlink if symlink is already set, else set hardlink. */ -void -archive_entry_set_link(struct archive_entry *entry, const char *target) -{ - if (entry->ae_set & AE_SET_SYMLINK) - aes_set_mbs(&entry->ae_symlink, target); - else - aes_set_mbs(&entry->ae_hardlink, target); -} - -/* Set symlink if symlink is already set, else set hardlink. */ -void -archive_entry_copy_link(struct archive_entry *entry, const char *target) -{ - if (entry->ae_set & AE_SET_SYMLINK) - aes_copy_mbs(&entry->ae_symlink, target); - else - aes_copy_mbs(&entry->ae_hardlink, target); -} - -/* Set symlink if symlink is already set, else set hardlink. */ -void -archive_entry_copy_link_w(struct archive_entry *entry, const wchar_t *target) -{ - if (entry->ae_set & AE_SET_SYMLINK) - aes_copy_wcs(&entry->ae_symlink, target); - else - aes_copy_wcs(&entry->ae_hardlink, target); -} - -int -archive_entry_update_link_utf8(struct archive_entry *entry, const char *target) -{ - if (entry->ae_set & AE_SET_SYMLINK) - return (aes_update_utf8(&entry->ae_symlink, target)); - else - return (aes_update_utf8(&entry->ae_hardlink, target)); -} - -void -archive_entry_set_mode(struct archive_entry *entry, mode_t m) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_mode = m; -} - -void -archive_entry_set_mtime(struct archive_entry *entry, time_t m, long ns) -{ - entry->stat_valid = 0; - entry->ae_set |= AE_SET_MTIME; - entry->ae_stat.aest_mtime = m; - entry->ae_stat.aest_mtime_nsec = ns; -} - -void -archive_entry_unset_mtime(struct archive_entry *entry) -{ - archive_entry_set_mtime(entry, 0, 0); - entry->ae_set &= ~AE_SET_MTIME; -} - -void -archive_entry_set_nlink(struct archive_entry *entry, unsigned int nlink) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_nlink = nlink; -} - -void -archive_entry_set_pathname(struct archive_entry *entry, const char *name) -{ - aes_set_mbs(&entry->ae_pathname, name); -} - -void -archive_entry_copy_pathname(struct archive_entry *entry, const char *name) -{ - aes_copy_mbs(&entry->ae_pathname, name); -} - -void -archive_entry_copy_pathname_w(struct archive_entry *entry, const wchar_t *name) -{ - aes_copy_wcs(&entry->ae_pathname, name); -} - -int -archive_entry_update_pathname_utf8(struct archive_entry *entry, const char *name) -{ - return (aes_update_utf8(&entry->ae_pathname, name)); -} - -void -archive_entry_set_perm(struct archive_entry *entry, mode_t p) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_mode &= AE_IFMT; - entry->ae_stat.aest_mode |= ~AE_IFMT & p; -} - -void -archive_entry_set_rdev(struct archive_entry *entry, dev_t m) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_rdev = m; - entry->ae_stat.aest_rdev_is_broken_down = 0; -} - -void -archive_entry_set_rdevmajor(struct archive_entry *entry, dev_t m) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_rdev_is_broken_down = 1; - entry->ae_stat.aest_rdevmajor = m; -} - -void -archive_entry_set_rdevminor(struct archive_entry *entry, dev_t m) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_rdev_is_broken_down = 1; - entry->ae_stat.aest_rdevminor = m; -} - -void -archive_entry_set_size(struct archive_entry *entry, int64_t s) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_size = s; - entry->ae_set |= AE_SET_SIZE; -} - -void -archive_entry_unset_size(struct archive_entry *entry) -{ - archive_entry_set_size(entry, 0); - entry->ae_set &= ~AE_SET_SIZE; -} - -void -archive_entry_copy_sourcepath(struct archive_entry *entry, const char *path) -{ - aes_set_mbs(&entry->ae_sourcepath, path); -} - -void -archive_entry_set_symlink(struct archive_entry *entry, const char *linkname) -{ - aes_set_mbs(&entry->ae_symlink, linkname); - if (linkname != NULL) - entry->ae_set |= AE_SET_SYMLINK; - else - entry->ae_set &= ~AE_SET_SYMLINK; -} - -void -archive_entry_copy_symlink(struct archive_entry *entry, const char *linkname) -{ - aes_copy_mbs(&entry->ae_symlink, linkname); - if (linkname != NULL) - entry->ae_set |= AE_SET_SYMLINK; - else - entry->ae_set &= ~AE_SET_SYMLINK; -} - -void -archive_entry_copy_symlink_w(struct archive_entry *entry, const wchar_t *linkname) -{ - aes_copy_wcs(&entry->ae_symlink, linkname); - if (linkname != NULL) - entry->ae_set |= AE_SET_SYMLINK; - else - entry->ae_set &= ~AE_SET_SYMLINK; -} - -int -archive_entry_update_symlink_utf8(struct archive_entry *entry, const char *linkname) -{ - if (linkname != NULL) - entry->ae_set |= AE_SET_SYMLINK; - else - entry->ae_set &= ~AE_SET_SYMLINK; - return (aes_update_utf8(&entry->ae_symlink, linkname)); -} - -void -archive_entry_set_uid(struct archive_entry *entry, uid_t u) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_uid = u; -} - -void -archive_entry_set_uname(struct archive_entry *entry, const char *name) -{ - aes_set_mbs(&entry->ae_uname, name); -} - -void -archive_entry_copy_uname(struct archive_entry *entry, const char *name) -{ - aes_copy_mbs(&entry->ae_uname, name); -} - -void -archive_entry_copy_uname_w(struct archive_entry *entry, const wchar_t *name) -{ - aes_copy_wcs(&entry->ae_uname, name); -} - -int -archive_entry_update_uname_utf8(struct archive_entry *entry, const char *name) -{ - return (aes_update_utf8(&entry->ae_uname, name)); -} - -/* - * ACL management. The following would, of course, be a lot simpler - * if: 1) the last draft of POSIX.1e were a really thorough and - * complete standard that addressed the needs of ACL archiving and 2) - * everyone followed it faithfully. Alas, neither is true, so the - * following is a lot more complex than might seem necessary to the - * uninitiated. - */ - -void -archive_entry_acl_clear(struct archive_entry *entry) -{ - struct ae_acl *ap; - - while (entry->acl_head != NULL) { - ap = entry->acl_head->next; - aes_clean(&entry->acl_head->name); - free(entry->acl_head); - entry->acl_head = ap; - } - if (entry->acl_text_w != NULL) { - free(entry->acl_text_w); - entry->acl_text_w = NULL; - } - entry->acl_p = NULL; - entry->acl_state = 0; /* Not counting. */ -} - -/* - * Add a single ACL entry to the internal list of ACL data. - */ -void -archive_entry_acl_add_entry(struct archive_entry *entry, - int type, int permset, int tag, int id, const char *name) -{ - struct ae_acl *ap; - - if (acl_special(entry, type, permset, tag) == 0) - return; - ap = acl_new_entry(entry, type, permset, tag, id); - if (ap == NULL) { - /* XXX Error XXX */ - return; - } - if (name != NULL && *name != '\0') - aes_copy_mbs(&ap->name, name); - else - aes_clean(&ap->name); -} - -/* - * As above, but with a wide-character name. - */ -void -archive_entry_acl_add_entry_w(struct archive_entry *entry, - int type, int permset, int tag, int id, const wchar_t *name) -{ - archive_entry_acl_add_entry_w_len(entry, type, permset, tag, id, name, wcslen(name)); -} - -static void -archive_entry_acl_add_entry_w_len(struct archive_entry *entry, - int type, int permset, int tag, int id, const wchar_t *name, size_t len) -{ - struct ae_acl *ap; - - if (acl_special(entry, type, permset, tag) == 0) - return; - ap = acl_new_entry(entry, type, permset, tag, id); - if (ap == NULL) { - /* XXX Error XXX */ - return; - } - if (name != NULL && *name != L'\0' && len > 0) - aes_copy_wcs_len(&ap->name, name, len); - else - aes_clean(&ap->name); -} - -/* - * If this ACL entry is part of the standard POSIX permissions set, - * store the permissions in the stat structure and return zero. - */ -static int -acl_special(struct archive_entry *entry, int type, int permset, int tag) -{ - if (type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS) { - switch (tag) { - case ARCHIVE_ENTRY_ACL_USER_OBJ: - entry->ae_stat.aest_mode &= ~0700; - entry->ae_stat.aest_mode |= (permset & 7) << 6; - return (0); - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - entry->ae_stat.aest_mode &= ~0070; - entry->ae_stat.aest_mode |= (permset & 7) << 3; - return (0); - case ARCHIVE_ENTRY_ACL_OTHER: - entry->ae_stat.aest_mode &= ~0007; - entry->ae_stat.aest_mode |= permset & 7; - return (0); - } - } - return (1); -} - -/* - * Allocate and populate a new ACL entry with everything but the - * name. - */ -static struct ae_acl * -acl_new_entry(struct archive_entry *entry, - int type, int permset, int tag, int id) -{ - struct ae_acl *ap, *aq; - - if (type != ARCHIVE_ENTRY_ACL_TYPE_ACCESS && - type != ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) - return (NULL); - if (entry->acl_text_w != NULL) { - free(entry->acl_text_w); - entry->acl_text_w = NULL; - } - - /* XXX TODO: More sanity-checks on the arguments XXX */ - - /* If there's a matching entry already in the list, overwrite it. */ - ap = entry->acl_head; - aq = NULL; - while (ap != NULL) { - if (ap->type == type && ap->tag == tag && ap->id == id) { - ap->permset = permset; - return (ap); - } - aq = ap; - ap = ap->next; - } - - /* Add a new entry to the end of the list. */ - ap = (struct ae_acl *)malloc(sizeof(*ap)); - if (ap == NULL) - return (NULL); - memset(ap, 0, sizeof(*ap)); - if (aq == NULL) - entry->acl_head = ap; - else - aq->next = ap; - ap->type = type; - ap->tag = tag; - ap->id = id; - ap->permset = permset; - return (ap); -} - -/* - * Return a count of entries matching "want_type". - */ -int -archive_entry_acl_count(struct archive_entry *entry, int want_type) -{ - int count; - struct ae_acl *ap; - - count = 0; - ap = entry->acl_head; - while (ap != NULL) { - if ((ap->type & want_type) != 0) - count++; - ap = ap->next; - } - - if (count > 0 && ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)) - count += 3; - return (count); -} - -/* - * Prepare for reading entries from the ACL data. Returns a count - * of entries matching "want_type", or zero if there are no - * non-extended ACL entries of that type. - */ -int -archive_entry_acl_reset(struct archive_entry *entry, int want_type) -{ - int count, cutoff; - - count = archive_entry_acl_count(entry, want_type); - - /* - * If the only entries are the three standard ones, - * then don't return any ACL data. (In this case, - * client can just use chmod(2) to set permissions.) - */ - if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) - cutoff = 3; - else - cutoff = 0; - - if (count > cutoff) - entry->acl_state = ARCHIVE_ENTRY_ACL_USER_OBJ; - else - entry->acl_state = 0; - entry->acl_p = entry->acl_head; - return (count); -} - -/* - * Return the next ACL entry in the list. Fake entries for the - * standard permissions and include them in the returned list. - */ - -int -archive_entry_acl_next(struct archive_entry *entry, int want_type, int *type, - int *permset, int *tag, int *id, const char **name) -{ - *name = NULL; - *id = -1; - - /* - * The acl_state is either zero (no entries available), -1 - * (reading from list), or an entry type (retrieve that type - * from ae_stat.aest_mode). - */ - if (entry->acl_state == 0) - return (ARCHIVE_WARN); - - /* The first three access entries are special. */ - if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { - switch (entry->acl_state) { - case ARCHIVE_ENTRY_ACL_USER_OBJ: - *permset = (entry->ae_stat.aest_mode >> 6) & 7; - *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; - *tag = ARCHIVE_ENTRY_ACL_USER_OBJ; - entry->acl_state = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - return (ARCHIVE_OK); - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - *permset = (entry->ae_stat.aest_mode >> 3) & 7; - *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; - *tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - entry->acl_state = ARCHIVE_ENTRY_ACL_OTHER; - return (ARCHIVE_OK); - case ARCHIVE_ENTRY_ACL_OTHER: - *permset = entry->ae_stat.aest_mode & 7; - *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; - *tag = ARCHIVE_ENTRY_ACL_OTHER; - entry->acl_state = -1; - entry->acl_p = entry->acl_head; - return (ARCHIVE_OK); - default: - break; - } - } - - while (entry->acl_p != NULL && (entry->acl_p->type & want_type) == 0) - entry->acl_p = entry->acl_p->next; - if (entry->acl_p == NULL) { - entry->acl_state = 0; - *type = 0; - *permset = 0; - *tag = 0; - *id = -1; - *name = NULL; - return (ARCHIVE_EOF); /* End of ACL entries. */ - } - *type = entry->acl_p->type; - *permset = entry->acl_p->permset; - *tag = entry->acl_p->tag; - *id = entry->acl_p->id; - *name = aes_get_mbs(&entry->acl_p->name); - entry->acl_p = entry->acl_p->next; - return (ARCHIVE_OK); -} - -/* - * Generate a text version of the ACL. The flags parameter controls - * the style of the generated ACL. - */ -const wchar_t * -archive_entry_acl_text_w(struct archive_entry *entry, int flags) -{ - int count; - size_t length; - const wchar_t *wname; - const wchar_t *prefix; - wchar_t separator; - struct ae_acl *ap; - int id; - wchar_t *wp; - - if (entry->acl_text_w != NULL) { - free (entry->acl_text_w); - entry->acl_text_w = NULL; - } - - separator = L','; - count = 0; - length = 0; - ap = entry->acl_head; - while (ap != NULL) { - if ((ap->type & flags) != 0) { - count++; - if ((flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) && - (ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT)) - length += 8; /* "default:" */ - length += 5; /* tag name */ - length += 1; /* colon */ - wname = aes_get_wcs(&ap->name); - if (wname != NULL) - length += wcslen(wname); - else - length += sizeof(uid_t) * 3 + 1; - length ++; /* colon */ - length += 3; /* rwx */ - length += 1; /* colon */ - length += max(sizeof(uid_t), sizeof(gid_t)) * 3 + 1; - length ++; /* newline */ - } - ap = ap->next; - } - - if (count > 0 && ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)) { - length += 10; /* "user::rwx\n" */ - length += 11; /* "group::rwx\n" */ - length += 11; /* "other::rwx\n" */ - } - - if (count == 0) - return (NULL); - - /* Now, allocate the string and actually populate it. */ - wp = entry->acl_text_w = (wchar_t *)malloc(length * sizeof(wchar_t)); - if (wp == NULL) - __archive_errx(1, "No memory to generate the text version of the ACL"); - count = 0; - if ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { - append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_USER_OBJ, NULL, - entry->ae_stat.aest_mode & 0700, -1); - *wp++ = ','; - append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_GROUP_OBJ, NULL, - entry->ae_stat.aest_mode & 0070, -1); - *wp++ = ','; - append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_OTHER, NULL, - entry->ae_stat.aest_mode & 0007, -1); - count += 3; - - ap = entry->acl_head; - while (ap != NULL) { - if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { - wname = aes_get_wcs(&ap->name); - *wp++ = separator; - if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID) - id = ap->id; - else - id = -1; - append_entry_w(&wp, NULL, ap->tag, wname, - ap->permset, id); - count++; - } - ap = ap->next; - } - } - - - if ((flags & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) { - if (flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) - prefix = L"default:"; - else - prefix = NULL; - ap = entry->acl_head; - count = 0; - while (ap != NULL) { - if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) { - wname = aes_get_wcs(&ap->name); - if (count > 0) - *wp++ = separator; - if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID) - id = ap->id; - else - id = -1; - append_entry_w(&wp, prefix, ap->tag, - wname, ap->permset, id); - count ++; - } - ap = ap->next; - } - } - - return (entry->acl_text_w); -} - -static void -append_id_w(wchar_t **wp, int id) -{ - if (id < 0) - id = 0; - if (id > 9) - append_id_w(wp, id / 10); - *(*wp)++ = L"0123456789"[id % 10]; -} - -static void -append_entry_w(wchar_t **wp, const wchar_t *prefix, int tag, - const wchar_t *wname, int perm, int id) -{ - if (prefix != NULL) { - wcscpy(*wp, prefix); - *wp += wcslen(*wp); - } - switch (tag) { - case ARCHIVE_ENTRY_ACL_USER_OBJ: - wname = NULL; - id = -1; - /* FALLTHROUGH */ - case ARCHIVE_ENTRY_ACL_USER: - wcscpy(*wp, L"user"); - break; - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - wname = NULL; - id = -1; - /* FALLTHROUGH */ - case ARCHIVE_ENTRY_ACL_GROUP: - wcscpy(*wp, L"group"); - break; - case ARCHIVE_ENTRY_ACL_MASK: - wcscpy(*wp, L"mask"); - wname = NULL; - id = -1; - break; - case ARCHIVE_ENTRY_ACL_OTHER: - wcscpy(*wp, L"other"); - wname = NULL; - id = -1; - break; - } - *wp += wcslen(*wp); - *(*wp)++ = L':'; - if (wname != NULL) { - wcscpy(*wp, wname); - *wp += wcslen(*wp); - } else if (tag == ARCHIVE_ENTRY_ACL_USER - || tag == ARCHIVE_ENTRY_ACL_GROUP) { - append_id_w(wp, id); - id = -1; - } - *(*wp)++ = L':'; - *(*wp)++ = (perm & 0444) ? L'r' : L'-'; - *(*wp)++ = (perm & 0222) ? L'w' : L'-'; - *(*wp)++ = (perm & 0111) ? L'x' : L'-'; - if (id != -1) { - *(*wp)++ = L':'; - append_id_w(wp, id); - } - **wp = L'\0'; -} - -/* - * Parse a textual ACL. This automatically recognizes and supports - * extensions described above. The 'type' argument is used to - * indicate the type that should be used for any entries not - * explicitly marked as "default:". - */ -int -__archive_entry_acl_parse_w(struct archive_entry *entry, - const wchar_t *text, int default_type) -{ - struct { - const wchar_t *start; - const wchar_t *end; - } field[4], name; - - int fields, n; - int type, tag, permset, id; - wchar_t sep; - - while (text != NULL && *text != L'\0') { - /* - * Parse the fields out of the next entry, - * advance 'text' to start of next entry. - */ - fields = 0; - do { - const wchar_t *start, *end; - next_field_w(&text, &start, &end, &sep); - if (fields < 4) { - field[fields].start = start; - field[fields].end = end; - } - ++fields; - } while (sep == L':'); - - /* Set remaining fields to blank. */ - for (n = fields; n < 4; ++n) - field[n].start = field[n].end = NULL; - - /* Check for a numeric ID in field 1 or 3. */ - id = -1; - isint_w(field[1].start, field[1].end, &id); - /* Field 3 is optional. */ - if (id == -1 && fields > 3) - isint_w(field[3].start, field[3].end, &id); - - /* - * Solaris extension: "defaultuser::rwx" is the - * default ACL corresponding to "user::rwx", etc. - */ - if (field[0].end - field[0].start > 7 - && wmemcmp(field[0].start, L"default", 7) == 0) { - type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT; - field[0].start += 7; - } else - type = default_type; - - name.start = name.end = NULL; - if (prefix_w(field[0].start, field[0].end, L"user")) { - if (!ismode_w(field[2].start, field[2].end, &permset)) - return (ARCHIVE_WARN); - if (id != -1 || field[1].start < field[1].end) { - tag = ARCHIVE_ENTRY_ACL_USER; - name = field[1]; - } else - tag = ARCHIVE_ENTRY_ACL_USER_OBJ; - } else if (prefix_w(field[0].start, field[0].end, L"group")) { - if (!ismode_w(field[2].start, field[2].end, &permset)) - return (ARCHIVE_WARN); - if (id != -1 || field[1].start < field[1].end) { - tag = ARCHIVE_ENTRY_ACL_GROUP; - name = field[1]; - } else - tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - } else if (prefix_w(field[0].start, field[0].end, L"other")) { - if (fields == 2 - && field[1].start < field[1].end - && ismode_w(field[1].start, field[1].end, &permset)) { - /* This is Solaris-style "other:rwx" */ - } else if (fields == 3 - && field[1].start == field[1].end - && field[2].start < field[2].end - && ismode_w(field[2].start, field[2].end, &permset)) { - /* This is FreeBSD-style "other::rwx" */ - } else - return (ARCHIVE_WARN); - tag = ARCHIVE_ENTRY_ACL_OTHER; - } else if (prefix_w(field[0].start, field[0].end, L"mask")) { - if (fields == 2 - && field[1].start < field[1].end - && ismode_w(field[1].start, field[1].end, &permset)) { - /* This is Solaris-style "mask:rwx" */ - } else if (fields == 3 - && field[1].start == field[1].end - && field[2].start < field[2].end - && ismode_w(field[2].start, field[2].end, &permset)) { - /* This is FreeBSD-style "mask::rwx" */ - } else - return (ARCHIVE_WARN); - tag = ARCHIVE_ENTRY_ACL_MASK; - } else - return (ARCHIVE_WARN); - - /* Add entry to the internal list. */ - archive_entry_acl_add_entry_w_len(entry, type, permset, - tag, id, name.start, name.end - name.start); - } - return (ARCHIVE_OK); -} - -/* - * Parse a string to a positive decimal integer. Returns true if - * the string is non-empty and consists only of decimal digits, - * false otherwise. - */ -static int -isint_w(const wchar_t *start, const wchar_t *end, int *result) -{ - int n = 0; - if (start >= end) - return (0); - while (start < end) { - if (*start < '0' || *start > '9') - return (0); - if (n > (INT_MAX / 10)) - n = INT_MAX; - else { - n *= 10; - n += *start - '0'; - } - start++; - } - *result = n; - return (1); -} - -/* - * Parse a string as a mode field. Returns true if - * the string is non-empty and consists only of mode characters, - * false otherwise. - */ -static int -ismode_w(const wchar_t *start, const wchar_t *end, int *permset) -{ - const wchar_t *p; - - if (start >= end) - return (0); - p = start; - *permset = 0; - while (p < end) { - switch (*p++) { - case 'r': case 'R': - *permset |= ARCHIVE_ENTRY_ACL_READ; - break; - case 'w': case 'W': - *permset |= ARCHIVE_ENTRY_ACL_WRITE; - break; - case 'x': case 'X': - *permset |= ARCHIVE_ENTRY_ACL_EXECUTE; - break; - case '-': - break; - default: - return (0); - } - } - return (1); -} - -/* - * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *wp is updated - * to point to just after the separator. *start points to the first - * character of the matched text and *end just after the last - * character of the matched identifier. In particular *end - *start - * is the length of the field body, not including leading or trailing - * whitespace. - */ -static void -next_field_w(const wchar_t **wp, const wchar_t **start, - const wchar_t **end, wchar_t *sep) -{ - /* Skip leading whitespace to find start of field. */ - while (**wp == L' ' || **wp == L'\t' || **wp == L'\n') { - (*wp)++; - } - *start = *wp; - - /* Scan for the separator. */ - while (**wp != L'\0' && **wp != L',' && **wp != L':' && - **wp != L'\n') { - (*wp)++; - } - *sep = **wp; - - /* Trim trailing whitespace to locate end of field. */ - *end = *wp - 1; - while (**end == L' ' || **end == L'\t' || **end == L'\n') { - (*end)--; - } - (*end)++; - - /* Adjust scanner location. */ - if (**wp != L'\0') - (*wp)++; -} - -/* - * Return true if the characters [start...end) are a prefix of 'test'. - * This makes it easy to handle the obvious abbreviations: 'u' for 'user', etc. - */ -static int -prefix_w(const wchar_t *start, const wchar_t *end, const wchar_t *test) -{ - if (start == end) - return (0); - - if (*start++ != *test++) - return (0); - - while (start < end && *start++ == *test++) - ; - - if (start < end) - return (0); - - return (1); -} - - -/* - * Following code is modified from UC Berkeley sources, and - * is subject to the following copyright notice. - */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -static struct flag { - const char *name; - const wchar_t *wname; - unsigned long set; - unsigned long clear; -} flags[] = { - /* Preferred (shorter) names per flag first, all prefixed by "no" */ -#ifdef SF_APPEND - { "nosappnd", L"nosappnd", SF_APPEND, 0 }, - { "nosappend", L"nosappend", SF_APPEND, 0 }, -#endif -#ifdef EXT2_APPEND_FL /* 'a' */ - { "nosappnd", L"nosappnd", EXT2_APPEND_FL, 0 }, - { "nosappend", L"nosappend", EXT2_APPEND_FL, 0 }, -#endif -#ifdef SF_ARCHIVED - { "noarch", L"noarch", SF_ARCHIVED, 0 }, - { "noarchived", L"noarchived", SF_ARCHIVED, 0 }, -#endif -#ifdef SF_IMMUTABLE - { "noschg", L"noschg", SF_IMMUTABLE, 0 }, - { "noschange", L"noschange", SF_IMMUTABLE, 0 }, - { "nosimmutable", L"nosimmutable", SF_IMMUTABLE, 0 }, -#endif -#ifdef EXT2_IMMUTABLE_FL /* 'i' */ - { "noschg", L"noschg", EXT2_IMMUTABLE_FL, 0 }, - { "noschange", L"noschange", EXT2_IMMUTABLE_FL, 0 }, - { "nosimmutable", L"nosimmutable", EXT2_IMMUTABLE_FL, 0 }, -#endif -#ifdef SF_NOUNLINK - { "nosunlnk", L"nosunlnk", SF_NOUNLINK, 0 }, - { "nosunlink", L"nosunlink", SF_NOUNLINK, 0 }, -#endif -#ifdef SF_SNAPSHOT - { "nosnapshot", L"nosnapshot", SF_SNAPSHOT, 0 }, -#endif -#ifdef UF_APPEND - { "nouappnd", L"nouappnd", UF_APPEND, 0 }, - { "nouappend", L"nouappend", UF_APPEND, 0 }, -#endif -#ifdef UF_IMMUTABLE - { "nouchg", L"nouchg", UF_IMMUTABLE, 0 }, - { "nouchange", L"nouchange", UF_IMMUTABLE, 0 }, - { "nouimmutable", L"nouimmutable", UF_IMMUTABLE, 0 }, -#endif -#ifdef UF_NODUMP - { "nodump", L"nodump", 0, UF_NODUMP}, -#endif -#ifdef EXT2_NODUMP_FL /* 'd' */ - { "nodump", L"nodump", 0, EXT2_NODUMP_FL}, -#endif -#ifdef UF_OPAQUE - { "noopaque", L"noopaque", UF_OPAQUE, 0 }, -#endif -#ifdef UF_NOUNLINK - { "nouunlnk", L"nouunlnk", UF_NOUNLINK, 0 }, - { "nouunlink", L"nouunlink", UF_NOUNLINK, 0 }, -#endif -#ifdef EXT2_UNRM_FL - { "nouunlink", L"nouunlink", EXT2_UNRM_FL, 0}, -#endif - -#ifdef EXT2_BTREE_FL - { "nobtree", L"nobtree", EXT2_BTREE_FL, 0 }, -#endif - -#ifdef EXT2_ECOMPR_FL - { "nocomperr", L"nocomperr", EXT2_ECOMPR_FL, 0 }, -#endif - -#ifdef EXT2_COMPR_FL /* 'c' */ - { "nocompress", L"nocompress", EXT2_COMPR_FL, 0 }, -#endif - -#ifdef EXT2_NOATIME_FL /* 'A' */ - { "noatime", L"noatime", 0, EXT2_NOATIME_FL}, -#endif - -#ifdef EXT2_DIRTY_FL - { "nocompdirty",L"nocompdirty", EXT2_DIRTY_FL, 0}, -#endif - -#ifdef EXT2_COMPRBLK_FL -#ifdef EXT2_NOCOMPR_FL - { "nocomprblk", L"nocomprblk", EXT2_COMPRBLK_FL, EXT2_NOCOMPR_FL}, -#else - { "nocomprblk", L"nocomprblk", EXT2_COMPRBLK_FL, 0}, -#endif -#endif -#ifdef EXT2_DIRSYNC_FL - { "nodirsync", L"nodirsync", EXT2_DIRSYNC_FL, 0}, -#endif -#ifdef EXT2_INDEX_FL - { "nohashidx", L"nohashidx", EXT2_INDEX_FL, 0}, -#endif -#ifdef EXT2_IMAGIC_FL - { "noimagic", L"noimagic", EXT2_IMAGIC_FL, 0}, -#endif -#ifdef EXT3_JOURNAL_DATA_FL - { "nojournal", L"nojournal", EXT3_JOURNAL_DATA_FL, 0}, -#endif -#ifdef EXT2_SECRM_FL - { "nosecuredeletion",L"nosecuredeletion",EXT2_SECRM_FL, 0}, -#endif -#ifdef EXT2_SYNC_FL - { "nosync", L"nosync", EXT2_SYNC_FL, 0}, -#endif -#ifdef EXT2_NOTAIL_FL - { "notail", L"notail", 0, EXT2_NOTAIL_FL}, -#endif -#ifdef EXT2_TOPDIR_FL - { "notopdir", L"notopdir", EXT2_TOPDIR_FL, 0}, -#endif -#ifdef EXT2_RESERVED_FL - { "noreserved", L"noreserved", EXT2_RESERVED_FL, 0}, -#endif - - { NULL, NULL, 0, 0 } -}; - -/* - * fflagstostr -- - * Convert file flags to a comma-separated string. If no flags - * are set, return the empty string. - */ -static char * -ae_fflagstostr(unsigned long bitset, unsigned long bitclear) -{ - char *string, *dp; - const char *sp; - unsigned long bits; - struct flag *flag; - size_t length; - - bits = bitset | bitclear; - length = 0; - for (flag = flags; flag->name != NULL; flag++) - if (bits & (flag->set | flag->clear)) { - length += strlen(flag->name) + 1; - bits &= ~(flag->set | flag->clear); - } - - if (length == 0) - return (NULL); - string = (char *)malloc(length); - if (string == NULL) - return (NULL); - - dp = string; - for (flag = flags; flag->name != NULL; flag++) { - if (bitset & flag->set || bitclear & flag->clear) { - sp = flag->name + 2; - } else if (bitset & flag->clear || bitclear & flag->set) { - sp = flag->name; - } else - continue; - bitset &= ~(flag->set | flag->clear); - bitclear &= ~(flag->set | flag->clear); - if (dp > string) - *dp++ = ','; - while ((*dp++ = *sp++) != '\0') - ; - dp--; - } - - *dp = '\0'; - return (string); -} - -/* - * strtofflags -- - * Take string of arguments and return file flags. This - * version works a little differently than strtofflags(3). - * In particular, it always tests every token, skipping any - * unrecognized tokens. It returns a pointer to the first - * unrecognized token, or NULL if every token was recognized. - * This version is also const-correct and does not modify the - * provided string. - */ -static const char * -ae_strtofflags(const char *s, unsigned long *setp, unsigned long *clrp) -{ - const char *start, *end; - struct flag *flag; - unsigned long set, clear; - const char *failed; - - set = clear = 0; - start = s; - failed = NULL; - /* Find start of first token. */ - while (*start == '\t' || *start == ' ' || *start == ',') - start++; - while (*start != '\0') { - /* Locate end of token. */ - end = start; - while (*end != '\0' && *end != '\t' && - *end != ' ' && *end != ',') - end++; - for (flag = flags; flag->name != NULL; flag++) { - if (memcmp(start, flag->name, end - start) == 0) { - /* Matched "noXXXX", so reverse the sense. */ - clear |= flag->set; - set |= flag->clear; - break; - } else if (memcmp(start, flag->name + 2, end - start) - == 0) { - /* Matched "XXXX", so don't reverse. */ - set |= flag->set; - clear |= flag->clear; - break; - } - } - /* Ignore unknown flag names. */ - if (flag->name == NULL && failed == NULL) - failed = start; - - /* Find start of next token. */ - start = end; - while (*start == '\t' || *start == ' ' || *start == ',') - start++; - - } - - if (setp) - *setp = set; - if (clrp) - *clrp = clear; - - /* Return location of first failure. */ - return (failed); -} - -/* - * wcstofflags -- - * Take string of arguments and return file flags. This - * version works a little differently than strtofflags(3). - * In particular, it always tests every token, skipping any - * unrecognized tokens. It returns a pointer to the first - * unrecognized token, or NULL if every token was recognized. - * This version is also const-correct and does not modify the - * provided string. - */ -static const wchar_t * -ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp) -{ - const wchar_t *start, *end; - struct flag *flag; - unsigned long set, clear; - const wchar_t *failed; - - set = clear = 0; - start = s; - failed = NULL; - /* Find start of first token. */ - while (*start == L'\t' || *start == L' ' || *start == L',') - start++; - while (*start != L'\0') { - /* Locate end of token. */ - end = start; - while (*end != L'\0' && *end != L'\t' && - *end != L' ' && *end != L',') - end++; - for (flag = flags; flag->wname != NULL; flag++) { - if (wmemcmp(start, flag->wname, end - start) == 0) { - /* Matched "noXXXX", so reverse the sense. */ - clear |= flag->set; - set |= flag->clear; - break; - } else if (wmemcmp(start, flag->wname + 2, end - start) - == 0) { - /* Matched "XXXX", so don't reverse. */ - set |= flag->set; - clear |= flag->clear; - break; - } - } - /* Ignore unknown flag names. */ - if (flag->wname == NULL && failed == NULL) - failed = start; - - /* Find start of next token. */ - start = end; - while (*start == L'\t' || *start == L' ' || *start == L',') - start++; - - } - - if (setp) - *setp = set; - if (clrp) - *clrp = clear; - - /* Return location of first failure. */ - return (failed); -} - - -#ifdef TEST -#include -int -main(int argc, char **argv) -{ - struct archive_entry *entry = archive_entry_new(); - unsigned long set, clear; - const wchar_t *remainder; - - remainder = archive_entry_copy_fflags_text_w(entry, L"nosappnd dump archive,,,,,,,"); - archive_entry_fflags(entry, &set, &clear); - - wprintf(L"set=0x%lX clear=0x%lX remainder='%ls'\n", set, clear, remainder); - - wprintf(L"new flags='%s'\n", archive_entry_fflags_text(entry)); - return (0); -} -#endif diff --git a/lib/libarchive/archive_entry.h b/lib/libarchive/archive_entry.h deleted file mode 100644 index 7ed2dde..0000000 --- a/lib/libarchive/archive_entry.h +++ /dev/null @@ -1,524 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef ARCHIVE_ENTRY_H_INCLUDED -#define ARCHIVE_ENTRY_H_INCLUDED - -/* - * Note: archive_entry.h is for use outside of libarchive; the - * configuration headers (config.h, archive_platform.h, etc.) are - * purely internal. Do NOT use HAVE_XXX configuration macros to - * control the behavior of this header! If you must conditionalize, - * use predefined compiler and/or platform macros. - */ - -#include -#include /* for wchar_t */ -#include - -#if defined(_WIN32) && !defined(__CYGWIN__) -#include -#endif - -/* Get appropriate definitions of standard POSIX-style types. */ -/* These should match the types used in 'struct stat' */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#define __LA_INT64_T __int64 -# if defined(__BORLANDC__) -# define __LA_UID_T uid_t -# define __LA_GID_T gid_t -# define __LA_DEV_T dev_t -# define __LA_MODE_T mode_t -# else -# define __LA_UID_T short -# define __LA_GID_T short -# define __LA_DEV_T unsigned int -# define __LA_MODE_T unsigned short -# endif -#else -#include -#define __LA_INT64_T int64_t -#define __LA_UID_T uid_t -#define __LA_GID_T gid_t -#define __LA_DEV_T dev_t -#define __LA_MODE_T mode_t -#endif - -/* - * XXX Is this defined for all Windows compilers? If so, in what - * header? It would be nice to remove the __LA_INO_T indirection and - * just use plain ino_t everywhere. Likewise for the other types just - * above. - */ -#define __LA_INO_T ino_t - - -/* - * On Windows, define LIBARCHIVE_STATIC if you're building or using a - * .lib. The default here assumes you're building a DLL. Only - * libarchive source should ever define __LIBARCHIVE_BUILD. - */ -#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC) -# ifdef __LIBARCHIVE_BUILD -# ifdef __GNUC__ -# define __LA_DECL __attribute__((dllexport)) extern -# else -# define __LA_DECL __declspec(dllexport) -# endif -# else -# ifdef __GNUC__ -# define __LA_DECL __attribute__((dllimport)) extern -# else -# define __LA_DECL __declspec(dllimport) -# endif -# endif -#else -/* Static libraries on all platforms and shared libraries on non-Windows. */ -# define __LA_DECL -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Description of an archive entry. - * - * You can think of this as "struct stat" with some text fields added in. - * - * TODO: Add "comment", "charset", and possibly other entries that are - * supported by "pax interchange" format. However, GNU, ustar, cpio, - * and other variants don't support these features, so they're not an - * excruciatingly high priority right now. - * - * TODO: "pax interchange" format allows essentially arbitrary - * key/value attributes to be attached to any entry. Supporting - * such extensions may make this library useful for special - * applications (e.g., a package manager could attach special - * package-management attributes to each entry). - */ -struct archive_entry; - -/* - * File-type constants. These are returned from archive_entry_filetype() - * and passed to archive_entry_set_filetype(). - * - * These values match S_XXX defines on every platform I've checked, - * including Windows, AIX, Linux, Solaris, and BSD. They're - * (re)defined here because platforms generally don't define the ones - * they don't support. For example, Windows doesn't define S_IFLNK or - * S_IFBLK. Instead of having a mass of conditional logic and system - * checks to define any S_XXX values that aren't supported locally, - * I've just defined a new set of such constants so that - * libarchive-based applications can manipulate and identify archive - * entries properly even if the hosting platform can't store them on - * disk. - * - * These values are also used directly within some portable formats, - * such as cpio. If you find a platform that varies from these, the - * correct solution is to leave these alone and translate from these - * portable values to platform-native values when entries are read from - * or written to disk. - */ -#define AE_IFMT 0170000 -#define AE_IFREG 0100000 -#define AE_IFLNK 0120000 -#define AE_IFSOCK 0140000 -#define AE_IFCHR 0020000 -#define AE_IFBLK 0060000 -#define AE_IFDIR 0040000 -#define AE_IFIFO 0010000 - -/* - * Basic object manipulation - */ - -__LA_DECL struct archive_entry *archive_entry_clear(struct archive_entry *); -/* The 'clone' function does a deep copy; all of the strings are copied too. */ -__LA_DECL struct archive_entry *archive_entry_clone(struct archive_entry *); -__LA_DECL void archive_entry_free(struct archive_entry *); -__LA_DECL struct archive_entry *archive_entry_new(void); - -/* - * Retrieve fields from an archive_entry. - * - * There are a number of implicit conversions among these fields. For - * example, if a regular string field is set and you read the _w wide - * character field, the entry will implicitly convert narrow-to-wide - * using the current locale. Similarly, dev values are automatically - * updated when you write devmajor or devminor and vice versa. - * - * In addition, fields can be "set" or "unset." Unset string fields - * return NULL, non-string fields have _is_set() functions to test - * whether they've been set. You can "unset" a string field by - * assigning NULL; non-string fields have _unset() functions to - * unset them. - * - * Note: There is one ambiguity in the above; string fields will - * also return NULL when implicit character set conversions fail. - * This is usually what you want. - */ -__LA_DECL time_t archive_entry_atime(struct archive_entry *); -__LA_DECL long archive_entry_atime_nsec(struct archive_entry *); -__LA_DECL int archive_entry_atime_is_set(struct archive_entry *); -__LA_DECL time_t archive_entry_birthtime(struct archive_entry *); -__LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *); -__LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *); -__LA_DECL time_t archive_entry_ctime(struct archive_entry *); -__LA_DECL long archive_entry_ctime_nsec(struct archive_entry *); -__LA_DECL int archive_entry_ctime_is_set(struct archive_entry *); -__LA_DECL dev_t archive_entry_dev(struct archive_entry *); -__LA_DECL dev_t archive_entry_devmajor(struct archive_entry *); -__LA_DECL dev_t archive_entry_devminor(struct archive_entry *); -__LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *); -__LA_DECL void archive_entry_fflags(struct archive_entry *, - unsigned long * /* set */, - unsigned long * /* clear */); -__LA_DECL const char *archive_entry_fflags_text(struct archive_entry *); -__LA_DECL __LA_GID_T archive_entry_gid(struct archive_entry *); -__LA_DECL const char *archive_entry_gname(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *); -__LA_DECL const char *archive_entry_hardlink(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *); -__LA_DECL __LA_INO_T archive_entry_ino(struct archive_entry *); -__LA_DECL __LA_INT64_T archive_entry_ino64(struct archive_entry *); -__LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *); -__LA_DECL time_t archive_entry_mtime(struct archive_entry *); -__LA_DECL long archive_entry_mtime_nsec(struct archive_entry *); -__LA_DECL int archive_entry_mtime_is_set(struct archive_entry *); -__LA_DECL unsigned int archive_entry_nlink(struct archive_entry *); -__LA_DECL const char *archive_entry_pathname(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *); -__LA_DECL dev_t archive_entry_rdev(struct archive_entry *); -__LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *); -__LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *); -__LA_DECL const char *archive_entry_sourcepath(struct archive_entry *); -__LA_DECL __LA_INT64_T archive_entry_size(struct archive_entry *); -__LA_DECL int archive_entry_size_is_set(struct archive_entry *); -__LA_DECL const char *archive_entry_strmode(struct archive_entry *); -__LA_DECL const char *archive_entry_symlink(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *); -__LA_DECL __LA_UID_T archive_entry_uid(struct archive_entry *); -__LA_DECL const char *archive_entry_uname(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *); - -/* - * Set fields in an archive_entry. - * - * Note that string 'set' functions do not copy the string, only the pointer. - * In contrast, 'copy' functions do copy the object pointed to. - * - * Note: As of libarchive 2.4, 'set' functions do copy the string and - * are therefore exact synonyms for the 'copy' versions. The 'copy' - * names will be retired in libarchive 3.0. - */ - -__LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long); -__LA_DECL void archive_entry_unset_atime(struct archive_entry *); -#if defined(_WIN32) && !defined(__CYGWIN__) -__LA_DECL void archive_entry_copy_bhfi(struct archive_entry *, - BY_HANDLE_FILE_INFORMATION *); -#endif -__LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long); -__LA_DECL void archive_entry_unset_birthtime(struct archive_entry *); -__LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long); -__LA_DECL void archive_entry_unset_ctime(struct archive_entry *); -__LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_devmajor(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_devminor(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_filetype(struct archive_entry *, unsigned int); -__LA_DECL void archive_entry_set_fflags(struct archive_entry *, - unsigned long /* set */, unsigned long /* clear */); -/* Returns pointer to start of first invalid token, or NULL if none. */ -/* Note that all recognized tokens are processed, regardless. */ -__LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *, - const char *); -__LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *, - const wchar_t *); -__LA_DECL void archive_entry_set_gid(struct archive_entry *, __LA_GID_T); -__LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_hardlink_utf8(struct archive_entry *, const char *); -#if ARCHIVE_VERSION_NUMBER >= 3000000 -/* Starting with libarchive 3.0, this will be synonym for ino64. */ -__LA_DECL void archive_entry_set_ino(struct archive_entry *, __LA_INT64_T); -#else -__LA_DECL void archive_entry_set_ino(struct archive_entry *, unsigned long); -#endif -__LA_DECL void archive_entry_set_ino64(struct archive_entry *, __LA_INT64_T); -__LA_DECL void archive_entry_set_link(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_mode(struct archive_entry *, __LA_MODE_T); -__LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long); -__LA_DECL void archive_entry_unset_mtime(struct archive_entry *); -__LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int); -__LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T); -__LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_size(struct archive_entry *, __LA_INT64_T); -__LA_DECL void archive_entry_unset_size(struct archive_entry *); -__LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_symlink_utf8(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_uid(struct archive_entry *, __LA_UID_T); -__LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *); -/* - * Routines to bulk copy fields to/from a platform-native "struct - * stat." Libarchive used to just store a struct stat inside of each - * archive_entry object, but this created issues when trying to - * manipulate archives on systems different than the ones they were - * created on. - * - * TODO: On Linux, provide both stat32 and stat64 versions of these functions. - */ -__LA_DECL const struct stat *archive_entry_stat(struct archive_entry *); -__LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *); - - -/* - * ACL routines. This used to simply store and return text-format ACL - * strings, but that proved insufficient for a number of reasons: - * = clients need control over uname/uid and gname/gid mappings - * = there are many different ACL text formats - * = would like to be able to read/convert archives containing ACLs - * on platforms that lack ACL libraries - * - * This last point, in particular, forces me to implement a reasonably - * complete set of ACL support routines. - * - * TODO: Extend this to support NFSv4/NTFS permissions. That should - * allow full ACL support on Mac OS, in particular, which uses - * POSIX.1e-style interfaces to manipulate NFSv4/NTFS permissions. - */ - -/* - * Permission bits mimic POSIX.1e. Note that I've not followed POSIX.1e's - * "permset"/"perm" abstract type nonsense. A permset is just a simple - * bitmap, following long-standing Unix tradition. - */ -#define ARCHIVE_ENTRY_ACL_EXECUTE 1 -#define ARCHIVE_ENTRY_ACL_WRITE 2 -#define ARCHIVE_ENTRY_ACL_READ 4 - -/* We need to be able to specify either or both of these. */ -#define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256 -#define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512 - -/* Tag values mimic POSIX.1e */ -#define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */ -#define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */ -#define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */ -#define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */ -#define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access. */ -#define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public. */ - -/* - * Set the ACL by clearing it and adding entries one at a time. - * Unlike the POSIX.1e ACL routines, you must specify the type - * (access/default) for each entry. Internally, the ACL data is just - * a soup of entries. API calls here allow you to retrieve just the - * entries of interest. This design (which goes against the spirit of - * POSIX.1e) is useful for handling archive formats that combine - * default and access information in a single ACL list. - */ -__LA_DECL void archive_entry_acl_clear(struct archive_entry *); -__LA_DECL void archive_entry_acl_add_entry(struct archive_entry *, - int /* type */, int /* permset */, int /* tag */, - int /* qual */, const char * /* name */); -__LA_DECL void archive_entry_acl_add_entry_w(struct archive_entry *, - int /* type */, int /* permset */, int /* tag */, - int /* qual */, const wchar_t * /* name */); - -/* - * To retrieve the ACL, first "reset", then repeatedly ask for the - * "next" entry. The want_type parameter allows you to request only - * access entries or only default entries. - */ -__LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type */); -__LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */, - int * /* type */, int * /* permset */, int * /* tag */, - int * /* qual */, const char ** /* name */); -__LA_DECL int archive_entry_acl_next_w(struct archive_entry *, int /* want_type */, - int * /* type */, int * /* permset */, int * /* tag */, - int * /* qual */, const wchar_t ** /* name */); - -/* - * Construct a text-format ACL. The flags argument is a bitmask that - * can include any of the following: - * - * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include access entries. - * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include default entries. - * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in - * each ACL entry. (As used by 'star'.) - * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each - * default ACL entry. - */ -#define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024 -#define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048 -__LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *, - int /* flags */); - -/* Return a count of entries matching 'want_type' */ -__LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */); - -/* - * Private ACL parser. This is private because it handles some - * very weird formats that clients should not be messing with. - * Clients should only deal with their platform-native formats. - * Because of the need to support many formats cleanly, new arguments - * are likely to get added on a regular basis. Clients who try to use - * this interface are likely to be surprised when it changes. - * - * You were warned! - * - * TODO: Move this declaration out of the public header and into - * a private header. Warnings above are silly. - */ -__LA_DECL int __archive_entry_acl_parse_w(struct archive_entry *, - const wchar_t *, int /* type */); - -/* - * extended attributes - */ - -__LA_DECL void archive_entry_xattr_clear(struct archive_entry *); -__LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *, - const char * /* name */, const void * /* value */, - size_t /* size */); - -/* - * To retrieve the xattr list, first "reset", then repeatedly ask for the - * "next" entry. - */ - -__LA_DECL int archive_entry_xattr_count(struct archive_entry *); -__LA_DECL int archive_entry_xattr_reset(struct archive_entry *); -__LA_DECL int archive_entry_xattr_next(struct archive_entry *, - const char ** /* name */, const void ** /* value */, size_t *); - -/* - * Utility to match up hardlinks. - * - * The 'struct archive_entry_linkresolver' is a cache of archive entries - * for files with multiple links. Here's how to use it: - * 1. Create a lookup object with archive_entry_linkresolver_new() - * 2. Tell it the archive format you're using. - * 3. Hand each archive_entry to archive_entry_linkify(). - * That function will return 0, 1, or 2 entries that should - * be written. - * 4. Call archive_entry_linkify(resolver, NULL) until - * no more entries are returned. - * 5. Call archive_entry_link_resolver_free(resolver) to free resources. - * - * The entries returned have their hardlink and size fields updated - * appropriately. If an entry is passed in that does not refer to - * a file with multiple links, it is returned unchanged. The intention - * is that you should be able to simply filter all entries through - * this machine. - * - * To make things more efficient, be sure that each entry has a valid - * nlinks value. The hardlink cache uses this to track when all links - * have been found. If the nlinks value is zero, it will keep every - * name in the cache indefinitely, which can use a lot of memory. - * - * Note that archive_entry_size() is reset to zero if the file - * body should not be written to the archive. Pay attention! - */ -struct archive_entry_linkresolver; - -/* - * There are three different strategies for marking hardlinks. - * The descriptions below name them after the best-known - * formats that rely on each strategy: - * - * "Old cpio" is the simplest, it always returns any entry unmodified. - * As far as I know, only cpio formats use this. Old cpio archives - * store every link with the full body; the onus is on the dearchiver - * to detect and properly link the files as they are restored. - * "tar" is also pretty simple; it caches a copy the first time it sees - * any link. Subsequent appearances are modified to be hardlink - * references to the first one without any body. Used by all tar - * formats, although the newest tar formats permit the "old cpio" strategy - * as well. This strategy is very simple for the dearchiver, - * and reasonably straightforward for the archiver. - * "new cpio" is trickier. It stores the body only with the last - * occurrence. The complication is that we might not - * see every link to a particular file in a single session, so - * there's no easy way to know when we've seen the last occurrence. - * The solution here is to queue one link until we see the next. - * At the end of the session, you can enumerate any remaining - * entries by calling archive_entry_linkify(NULL) and store those - * bodies. If you have a file with three links l1, l2, and l3, - * you'll get the following behavior if you see all three links: - * linkify(l1) => NULL (the resolver stores l1 internally) - * linkify(l2) => l1 (resolver stores l2, you write l1) - * linkify(l3) => l2, l3 (all links seen, you can write both). - * If you only see l1 and l2, you'll get this behavior: - * linkify(l1) => NULL - * linkify(l2) => l1 - * linkify(NULL) => l2 (at end, you retrieve remaining links) - * As the name suggests, this strategy is used by newer cpio variants. - * It's noticably more complex for the archiver, slightly more complex - * for the dearchiver than the tar strategy, but makes it straightforward - * to restore a file using any link by simply continuing to scan until - * you see a link that is stored with a body. In contrast, the tar - * strategy requires you to rescan the archive from the beginning to - * correctly extract an arbitrary link. - */ - -__LA_DECL struct archive_entry_linkresolver *archive_entry_linkresolver_new(void); -__LA_DECL void archive_entry_linkresolver_set_strategy( - struct archive_entry_linkresolver *, int /* format_code */); -__LA_DECL void archive_entry_linkresolver_free(struct archive_entry_linkresolver *); -__LA_DECL void archive_entry_linkify(struct archive_entry_linkresolver *, - struct archive_entry **, struct archive_entry **); - -#ifdef __cplusplus -} -#endif - -/* This is meaningless outside of this header. */ -#undef __LA_DECL - -#endif /* !ARCHIVE_ENTRY_H_INCLUDED */ diff --git a/lib/libarchive/archive_entry_copy_stat.c b/lib/libarchive/archive_entry_copy_stat.c deleted file mode 100644 index 615d3b0..0000000 --- a/lib/libarchive/archive_entry_copy_stat.c +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif - -#include "archive_entry.h" - -void -archive_entry_copy_stat(struct archive_entry *entry, const struct stat *st) -{ -#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - archive_entry_set_atime(entry, st->st_atime, st->st_atimespec.tv_nsec); - archive_entry_set_ctime(entry, st->st_ctime, st->st_ctimespec.tv_nsec); - archive_entry_set_mtime(entry, st->st_mtime, st->st_mtimespec.tv_nsec); -#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - archive_entry_set_atime(entry, st->st_atime, st->st_atim.tv_nsec); - archive_entry_set_ctime(entry, st->st_ctime, st->st_ctim.tv_nsec); - archive_entry_set_mtime(entry, st->st_mtime, st->st_mtim.tv_nsec); -#elif HAVE_STRUCT_STAT_ST_MTIME_N - archive_entry_set_atime(entry, st->st_atime, st->st_atime_n); - archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_n); - archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_n); -#elif HAVE_STRUCT_STAT_ST_UMTIME - archive_entry_set_atime(entry, st->st_atime, st->st_uatime * 1000); - archive_entry_set_ctime(entry, st->st_ctime, st->st_uctime * 1000); - archive_entry_set_mtime(entry, st->st_mtime, st->st_umtime * 1000); -#elif HAVE_STRUCT_STAT_ST_MTIME_USEC - archive_entry_set_atime(entry, st->st_atime, st->st_atime_usec * 1000); - archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_usec * 1000); - archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_usec * 1000); -#else - archive_entry_set_atime(entry, st->st_atime, 0); - archive_entry_set_ctime(entry, st->st_ctime, 0); - archive_entry_set_mtime(entry, st->st_mtime, 0); -#if HAVE_STRUCT_STAT_ST_BIRTHTIME - archive_entry_set_birthtime(entry, st->st_birthtime, 0); -#endif -#endif -#if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC - archive_entry_set_birthtime(entry, st->st_birthtime, st->st_birthtimespec.tv_nsec); -#endif - archive_entry_set_dev(entry, st->st_dev); - archive_entry_set_gid(entry, st->st_gid); - archive_entry_set_uid(entry, st->st_uid); - archive_entry_set_ino(entry, st->st_ino); - archive_entry_set_nlink(entry, st->st_nlink); - archive_entry_set_rdev(entry, st->st_rdev); - archive_entry_set_size(entry, st->st_size); - archive_entry_set_mode(entry, st->st_mode); -} diff --git a/lib/libarchive/archive_entry_link_resolver.c b/lib/libarchive/archive_entry_link_resolver.c deleted file mode 100644 index a5eb624..0000000 --- a/lib/libarchive/archive_entry_link_resolver.c +++ /dev/null @@ -1,405 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" - -/* - * This is mostly a pretty straightforward hash table implementation. - * The only interesting bit is the different strategies used to - * match up links. These strategies match those used by various - * archiving formats: - * tar - content stored with first link, remainder refer back to it. - * This requires us to match each subsequent link up with the - * first appearance. - * cpio - Old cpio just stored body with each link, match-ups were - * implicit. This is trivial. - * new cpio - New cpio only stores body with last link, match-ups - * are implicit. This is actually quite tricky; see the notes - * below. - */ - -/* Users pass us a format code, we translate that into a strategy here. */ -#define ARCHIVE_ENTRY_LINKIFY_LIKE_TAR 0 -#define ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE 1 -#define ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO 2 -#define ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO 3 - -/* Initial size of link cache. */ -#define links_cache_initial_size 1024 - -struct links_entry { - struct links_entry *next; - struct links_entry *previous; - int links; /* # links not yet seen */ - int hash; - struct archive_entry *canonical; - struct archive_entry *entry; -}; - -struct archive_entry_linkresolver { - struct links_entry **buckets; - struct links_entry *spare; - unsigned long number_entries; - size_t number_buckets; - int strategy; -}; - -static struct links_entry *find_entry(struct archive_entry_linkresolver *, - struct archive_entry *); -static void grow_hash(struct archive_entry_linkresolver *); -static struct links_entry *insert_entry(struct archive_entry_linkresolver *, - struct archive_entry *); -static struct links_entry *next_entry(struct archive_entry_linkresolver *); - -struct archive_entry_linkresolver * -archive_entry_linkresolver_new(void) -{ - struct archive_entry_linkresolver *res; - size_t i; - - res = malloc(sizeof(struct archive_entry_linkresolver)); - if (res == NULL) - return (NULL); - memset(res, 0, sizeof(struct archive_entry_linkresolver)); - res->number_buckets = links_cache_initial_size; - res->buckets = malloc(res->number_buckets * - sizeof(res->buckets[0])); - if (res->buckets == NULL) { - free(res); - return (NULL); - } - for (i = 0; i < res->number_buckets; i++) - res->buckets[i] = NULL; - return (res); -} - -void -archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *res, - int fmt) -{ - int fmtbase = fmt & ARCHIVE_FORMAT_BASE_MASK; - - switch (fmtbase) { - case ARCHIVE_FORMAT_CPIO: - switch (fmt) { - case ARCHIVE_FORMAT_CPIO_SVR4_NOCRC: - case ARCHIVE_FORMAT_CPIO_SVR4_CRC: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO; - break; - default: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO; - break; - } - break; - case ARCHIVE_FORMAT_MTREE: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE; - break; - case ARCHIVE_FORMAT_TAR: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_TAR; - break; - default: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_TAR; - break; - } -} - -void -archive_entry_linkresolver_free(struct archive_entry_linkresolver *res) -{ - struct links_entry *le; - - if (res == NULL) - return; - - if (res->buckets != NULL) { - while ((le = next_entry(res)) != NULL) - archive_entry_free(le->entry); - free(res->buckets); - res->buckets = NULL; - } - free(res); -} - -void -archive_entry_linkify(struct archive_entry_linkresolver *res, - struct archive_entry **e, struct archive_entry **f) -{ - struct links_entry *le; - struct archive_entry *t; - - *f = NULL; /* Default: Don't return a second entry. */ - - if (*e == NULL) { - le = next_entry(res); - if (le != NULL) { - *e = le->entry; - le->entry = NULL; - } - return; - } - - /* If it has only one link, then we're done. */ - if (archive_entry_nlink(*e) == 1) - return; - /* Directories, devices never have hardlinks. */ - if (archive_entry_filetype(*e) == AE_IFDIR - || archive_entry_filetype(*e) == AE_IFBLK - || archive_entry_filetype(*e) == AE_IFCHR) - return; - - switch (res->strategy) { - case ARCHIVE_ENTRY_LINKIFY_LIKE_TAR: - le = find_entry(res, *e); - if (le != NULL) { - archive_entry_unset_size(*e); - archive_entry_copy_hardlink(*e, - archive_entry_pathname(le->canonical)); - } else - insert_entry(res, *e); - return; - case ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE: - le = find_entry(res, *e); - if (le != NULL) { - archive_entry_copy_hardlink(*e, - archive_entry_pathname(le->canonical)); - } else - insert_entry(res, *e); - return; - case ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO: - /* This one is trivial. */ - return; - case ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO: - le = find_entry(res, *e); - if (le != NULL) { - /* - * Put the new entry in le, return the - * old entry from le. - */ - t = *e; - *e = le->entry; - le->entry = t; - /* Make the old entry into a hardlink. */ - archive_entry_unset_size(*e); - archive_entry_copy_hardlink(*e, - archive_entry_pathname(le->canonical)); - /* If we ran out of links, return the - * final entry as well. */ - if (le->links == 0) { - *f = le->entry; - le->entry = NULL; - } - } else { - /* - * If we haven't seen it, tuck it away - * for future use. - */ - le = insert_entry(res, *e); - le->entry = *e; - *e = NULL; - } - return; - default: - break; - } - return; -} - -static struct links_entry * -find_entry(struct archive_entry_linkresolver *res, - struct archive_entry *entry) -{ - struct links_entry *le; - int hash, bucket; - dev_t dev; - int64_t ino; - - /* Free a held entry. */ - if (res->spare != NULL) { - archive_entry_free(res->spare->canonical); - archive_entry_free(res->spare->entry); - free(res->spare); - res->spare = NULL; - } - - /* If the links cache overflowed and got flushed, don't bother. */ - if (res->buckets == NULL) - return (NULL); - - dev = archive_entry_dev(entry); - ino = archive_entry_ino64(entry); - hash = (int)(dev ^ ino); - - /* Try to locate this entry in the links cache. */ - bucket = hash % res->number_buckets; - for (le = res->buckets[bucket]; le != NULL; le = le->next) { - if (le->hash == hash - && dev == archive_entry_dev(le->canonical) - && ino == archive_entry_ino64(le->canonical)) { - /* - * Decrement link count each time and release - * the entry if it hits zero. This saves - * memory and is necessary for detecting - * missed links. - */ - --le->links; - if (le->links > 0) - return (le); - /* Remove it from this hash bucket. */ - if (le->previous != NULL) - le->previous->next = le->next; - if (le->next != NULL) - le->next->previous = le->previous; - if (res->buckets[bucket] == le) - res->buckets[bucket] = le->next; - res->number_entries--; - /* Defer freeing this entry. */ - res->spare = le; - return (le); - } - } - return (NULL); -} - -static struct links_entry * -next_entry(struct archive_entry_linkresolver *res) -{ - struct links_entry *le; - size_t bucket; - - /* Free a held entry. */ - if (res->spare != NULL) { - archive_entry_free(res->spare->canonical); - free(res->spare); - res->spare = NULL; - } - - /* If the links cache overflowed and got flushed, don't bother. */ - if (res->buckets == NULL) - return (NULL); - - /* Look for next non-empty bucket in the links cache. */ - for (bucket = 0; bucket < res->number_buckets; bucket++) { - le = res->buckets[bucket]; - if (le != NULL) { - /* Remove it from this hash bucket. */ - if (le->next != NULL) - le->next->previous = le->previous; - res->buckets[bucket] = le->next; - res->number_entries--; - /* Defer freeing this entry. */ - res->spare = le; - return (le); - } - } - return (NULL); -} - -static struct links_entry * -insert_entry(struct archive_entry_linkresolver *res, - struct archive_entry *entry) -{ - struct links_entry *le; - int hash, bucket; - - /* Add this entry to the links cache. */ - le = malloc(sizeof(struct links_entry)); - if (le == NULL) - return (NULL); - memset(le, 0, sizeof(*le)); - le->canonical = archive_entry_clone(entry); - - /* If the links cache is getting too full, enlarge the hash table. */ - if (res->number_entries > res->number_buckets * 2) - grow_hash(res); - - hash = archive_entry_dev(entry) ^ archive_entry_ino64(entry); - bucket = hash % res->number_buckets; - - /* If we could allocate the entry, record it. */ - if (res->buckets[bucket] != NULL) - res->buckets[bucket]->previous = le; - res->number_entries++; - le->next = res->buckets[bucket]; - le->previous = NULL; - res->buckets[bucket] = le; - le->hash = hash; - le->links = archive_entry_nlink(entry) - 1; - return (le); -} - -static void -grow_hash(struct archive_entry_linkresolver *res) -{ - struct links_entry *le, **new_buckets; - size_t new_size; - size_t i, bucket; - - /* Try to enlarge the bucket list. */ - new_size = res->number_buckets * 2; - new_buckets = malloc(new_size * sizeof(struct links_entry *)); - - if (new_buckets != NULL) { - memset(new_buckets, 0, - new_size * sizeof(struct links_entry *)); - for (i = 0; i < res->number_buckets; i++) { - while (res->buckets[i] != NULL) { - /* Remove entry from old bucket. */ - le = res->buckets[i]; - res->buckets[i] = le->next; - - /* Add entry to new bucket. */ - bucket = le->hash % new_size; - - if (new_buckets[bucket] != NULL) - new_buckets[bucket]->previous = - le; - le->next = new_buckets[bucket]; - le->previous = NULL; - new_buckets[bucket] = le; - } - } - free(res->buckets); - res->buckets = new_buckets; - res->number_buckets = new_size; - } -} diff --git a/lib/libarchive/archive_entry_private.h b/lib/libarchive/archive_entry_private.h deleted file mode 100644 index d59021c..0000000 --- a/lib/libarchive/archive_entry_private.h +++ /dev/null @@ -1,184 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifndef ARCHIVE_ENTRY_PRIVATE_H_INCLUDED -#define ARCHIVE_ENTRY_PRIVATE_H_INCLUDED - -#include "archive_string.h" - -/* - * Handle wide character (i.e., Unicode) and non-wide character - * strings transparently. - */ - -struct aes { - struct archive_string aes_mbs; - struct archive_string aes_utf8; - const wchar_t *aes_wcs; - /* Bitmap of which of the above are valid. Because we're lazy - * about malloc-ing and reusing the underlying storage, we - * can't rely on NULL pointers to indicate whether a string - * has been set. */ - int aes_set; -#define AES_SET_MBS 1 -#define AES_SET_UTF8 2 -#define AES_SET_WCS 4 -}; - -struct ae_acl { - struct ae_acl *next; - int type; /* E.g., access or default */ - int tag; /* E.g., user/group/other/mask */ - int permset; /* r/w/x bits */ - int id; /* uid/gid for user/group */ - struct aes name; /* uname/gname */ -}; - -struct ae_xattr { - struct ae_xattr *next; - - char *name; - void *value; - size_t size; -}; - -/* - * Description of an archive entry. - * - * Basically, this is a "struct stat" with a few text fields added in. - * - * TODO: Add "comment", "charset", and possibly other entries - * that are supported by "pax interchange" format. However, GNU, ustar, - * cpio, and other variants don't support these features, so they're not an - * excruciatingly high priority right now. - * - * TODO: "pax interchange" format allows essentially arbitrary - * key/value attributes to be attached to any entry. Supporting - * such extensions may make this library useful for special - * applications (e.g., a package manager could attach special - * package-management attributes to each entry). There are tricky - * API issues involved, so this is not going to happen until - * there's a real demand for it. - * - * TODO: Design a good API for handling sparse files. - */ -struct archive_entry { - /* - * Note that ae_stat.st_mode & AE_IFMT can be 0! - * - * This occurs when the actual file type of the object is not - * in the archive. For example, 'tar' archives store - * hardlinks without marking the type of the underlying - * object. - */ - - /* - * Read archive_entry_copy_stat.c for an explanation of why I - * don't just use "struct stat" instead of "struct aest" here - * and why I have this odd pointer to a separately-allocated - * struct stat. - */ - void *stat; - int stat_valid; /* Set to 0 whenever a field in aest changes. */ - - struct aest { - int64_t aest_atime; - uint32_t aest_atime_nsec; - int64_t aest_ctime; - uint32_t aest_ctime_nsec; - int64_t aest_mtime; - uint32_t aest_mtime_nsec; - int64_t aest_birthtime; - uint32_t aest_birthtime_nsec; - gid_t aest_gid; - int64_t aest_ino; - mode_t aest_mode; - uint32_t aest_nlink; - uint64_t aest_size; - uid_t aest_uid; - /* - * Because converting between device codes and - * major/minor values is platform-specific and - * inherently a bit risky, we only do that conversion - * lazily. That way, we will do a better job of - * preserving information in those cases where no - * conversion is actually required. - */ - int aest_dev_is_broken_down; - dev_t aest_dev; - dev_t aest_devmajor; - dev_t aest_devminor; - int aest_rdev_is_broken_down; - dev_t aest_rdev; - dev_t aest_rdevmajor; - dev_t aest_rdevminor; - } ae_stat; - - int ae_set; /* bitmap of fields that are currently set */ -#define AE_SET_HARDLINK 1 -#define AE_SET_SYMLINK 2 -#define AE_SET_ATIME 4 -#define AE_SET_CTIME 8 -#define AE_SET_MTIME 16 -#define AE_SET_BIRTHTIME 32 -#define AE_SET_SIZE 64 - - /* - * Use aes here so that we get transparent mbs<->wcs conversions. - */ - struct aes ae_fflags_text; /* Text fflags per fflagstostr(3) */ - unsigned long ae_fflags_set; /* Bitmap fflags */ - unsigned long ae_fflags_clear; - struct aes ae_gname; /* Name of owning group */ - struct aes ae_hardlink; /* Name of target for hardlink */ - struct aes ae_pathname; /* Name of entry */ - struct aes ae_symlink; /* symlink contents */ - struct aes ae_uname; /* Name of owner */ - - /* Not used within libarchive; useful for some clients. */ - struct aes ae_sourcepath; /* Path this entry is sourced from. */ - - /* ACL support. */ - struct ae_acl *acl_head; - struct ae_acl *acl_p; - int acl_state; /* See acl_next for details. */ - wchar_t *acl_text_w; - - /* extattr support. */ - struct ae_xattr *xattr_head; - struct ae_xattr *xattr_p; - - /* Miscellaneous. */ - char strmode[12]; -}; - - -#endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */ diff --git a/lib/libarchive/archive_entry_stat.c b/lib/libarchive/archive_entry_stat.c deleted file mode 100644 index cdaeac3..0000000 --- a/lib/libarchive/archive_entry_stat.c +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif - -#include "archive_entry.h" -#include "archive_entry_private.h" - -const struct stat * -archive_entry_stat(struct archive_entry *entry) -{ - struct stat *st; - if (entry->stat == NULL) { - entry->stat = malloc(sizeof(*st)); - if (entry->stat == NULL) - return (NULL); - entry->stat_valid = 0; - } - - /* - * If none of the underlying fields have been changed, we - * don't need to regenerate. In theory, we could use a bitmap - * here to flag only those items that have changed, but the - * extra complexity probably isn't worth it. It will be very - * rare for anyone to change just one field then request a new - * stat structure. - */ - if (entry->stat_valid) - return (entry->stat); - - st = entry->stat; - /* - * Use the public interfaces to extract items, so that - * the appropriate conversions get invoked. - */ - st->st_atime = archive_entry_atime(entry); -#if HAVE_STRUCT_STAT_ST_BIRTHTIME - st->st_birthtime = archive_entry_birthtime(entry); -#endif - st->st_ctime = archive_entry_ctime(entry); - st->st_mtime = archive_entry_mtime(entry); - st->st_dev = archive_entry_dev(entry); - st->st_gid = archive_entry_gid(entry); - st->st_uid = archive_entry_uid(entry); - st->st_ino = archive_entry_ino64(entry); - st->st_nlink = archive_entry_nlink(entry); - st->st_rdev = archive_entry_rdev(entry); - st->st_size = archive_entry_size(entry); - st->st_mode = archive_entry_mode(entry); - - /* - * On systems that support high-res timestamps, copy that - * information into struct stat. - */ -#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - st->st_atimespec.tv_nsec = archive_entry_atime_nsec(entry); - st->st_ctimespec.tv_nsec = archive_entry_ctime_nsec(entry); - st->st_mtimespec.tv_nsec = archive_entry_mtime_nsec(entry); -#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - st->st_atim.tv_nsec = archive_entry_atime_nsec(entry); - st->st_ctim.tv_nsec = archive_entry_ctime_nsec(entry); - st->st_mtim.tv_nsec = archive_entry_mtime_nsec(entry); -#elif HAVE_STRUCT_STAT_ST_MTIME_N - st->st_atime_n = archive_entry_atime_nsec(entry); - st->st_ctime_n = archive_entry_ctime_nsec(entry); - st->st_mtime_n = archive_entry_mtime_nsec(entry); -#elif HAVE_STRUCT_STAT_ST_UMTIME - st->st_uatime = archive_entry_atime_nsec(entry) / 1000; - st->st_uctime = archive_entry_ctime_nsec(entry) / 1000; - st->st_umtime = archive_entry_mtime_nsec(entry) / 1000; -#elif HAVE_STRUCT_STAT_ST_MTIME_USEC - st->st_atime_usec = archive_entry_atime_nsec(entry) / 1000; - st->st_ctime_usec = archive_entry_ctime_nsec(entry) / 1000; - st->st_mtime_usec = archive_entry_mtime_nsec(entry) / 1000; -#endif -#if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC - st->st_birthtimespec.tv_nsec = archive_entry_birthtime_nsec(entry); -#endif - - /* - * TODO: On Linux, store 32 or 64 here depending on whether - * the cached stat structure is a stat32 or a stat64. This - * will allow us to support both variants interchangably. - */ - entry->stat_valid = 1; - - return (st); -} diff --git a/lib/libarchive/archive_entry_strmode.c b/lib/libarchive/archive_entry_strmode.c deleted file mode 100644 index 8d7006a..0000000 --- a/lib/libarchive/archive_entry_strmode.c +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive_entry.h" -#include "archive_entry_private.h" - -const char * -archive_entry_strmode(struct archive_entry *entry) -{ - static const mode_t permbits[] = - { 0400, 0200, 0100, 0040, 0020, 0010, 0004, 0002, 0001 }; - char *bp = entry->strmode; - mode_t mode; - int i; - - /* Fill in a default string, then selectively override. */ - strcpy(bp, "?rwxrwxrwx "); - - mode = archive_entry_mode(entry); - switch (archive_entry_filetype(entry)) { - case AE_IFREG: bp[0] = '-'; break; - case AE_IFBLK: bp[0] = 'b'; break; - case AE_IFCHR: bp[0] = 'c'; break; - case AE_IFDIR: bp[0] = 'd'; break; - case AE_IFLNK: bp[0] = 'l'; break; - case AE_IFSOCK: bp[0] = 's'; break; - case AE_IFIFO: bp[0] = 'p'; break; - default: - if (archive_entry_hardlink(entry) != NULL) { - bp[0] = 'h'; - break; - } - } - - for (i = 0; i < 9; i++) - if (!(mode & permbits[i])) - bp[i+1] = '-'; - - if (mode & S_ISUID) { - if (mode & 0100) bp[3] = 's'; - else bp[3] = 'S'; - } - if (mode & S_ISGID) { - if (mode & 0010) bp[6] = 's'; - else bp[6] = 'S'; - } - if (mode & S_ISVTX) { - if (mode & 0001) bp[9] = 't'; - else bp[9] = 'T'; - } - if (archive_entry_acl_count(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)) - bp[10] = '+'; - - return (bp); -} diff --git a/lib/libarchive/archive_entry_xattr.c b/lib/libarchive/archive_entry_xattr.c deleted file mode 100644 index b7e53e3..0000000 --- a/lib/libarchive/archive_entry_xattr.c +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_LIMITS_H -#include -#endif -#ifdef HAVE_LINUX_FS_H -#include /* for Linux file flags */ -#endif -/* - * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. - * As the include guards don't agree, the order of include is important. - */ -#ifdef HAVE_LINUX_EXT2_FS_H -#include /* for Linux file flags */ -#endif -#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) -#include /* for Linux file flags */ -#endif -#include -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_WCHAR_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_entry_private.h" - -/* - * extended attribute handling - */ - -void -archive_entry_xattr_clear(struct archive_entry *entry) -{ - struct ae_xattr *xp; - - while (entry->xattr_head != NULL) { - xp = entry->xattr_head->next; - free(entry->xattr_head->name); - free(entry->xattr_head->value); - free(entry->xattr_head); - entry->xattr_head = xp; - } - - entry->xattr_head = NULL; -} - -void -archive_entry_xattr_add_entry(struct archive_entry *entry, - const char *name, const void *value, size_t size) -{ - struct ae_xattr *xp; - - for (xp = entry->xattr_head; xp != NULL; xp = xp->next) - ; - - if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL) - /* XXX Error XXX */ - return; - - xp->name = strdup(name); - if ((xp->value = malloc(size)) != NULL) { - memcpy(xp->value, value, size); - xp->size = size; - } else - xp->size = 0; - - xp->next = entry->xattr_head; - entry->xattr_head = xp; -} - - -/* - * returns number of the extended attribute entries - */ -int -archive_entry_xattr_count(struct archive_entry *entry) -{ - struct ae_xattr *xp; - int count = 0; - - for (xp = entry->xattr_head; xp != NULL; xp = xp->next) - count++; - - return count; -} - -int -archive_entry_xattr_reset(struct archive_entry * entry) -{ - entry->xattr_p = entry->xattr_head; - - return archive_entry_xattr_count(entry); -} - -int -archive_entry_xattr_next(struct archive_entry * entry, - const char **name, const void **value, size_t *size) -{ - if (entry->xattr_p) { - *name = entry->xattr_p->name; - *value = entry->xattr_p->value; - *size = entry->xattr_p->size; - - entry->xattr_p = entry->xattr_p->next; - - return (ARCHIVE_OK); - } else { - *name = NULL; - *value = NULL; - *size = (size_t)0; - return (ARCHIVE_WARN); - } -} - -/* - * end of xattr handling - */ diff --git a/lib/libarchive/archive_hash.h b/lib/libarchive/archive_hash.h deleted file mode 100644 index 43f398c..0000000 --- a/lib/libarchive/archive_hash.h +++ /dev/null @@ -1,309 +0,0 @@ -/*- - * Copyright (c) 2009 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -/* - * Hash function support in various Operating Systems: - * - * NetBSD: - * - MD5 and SHA1 in libc: without _ after algorithm name - * - SHA2 in libc: with _ after algorithm name - * - * OpenBSD: - * - MD5, SHA1 and SHA2 in libc: without _ after algorithm name - * - OpenBSD 4.4 and earlier have SHA2 in libc with _ after algorithm name - * - * DragonFly and FreeBSD (XXX not used yet): - * - MD5 and SHA1 in libmd: without _ after algorithm name - * - SHA256: with _ after algorithm name - * - * Mac OS X (10.4 and later): - * - MD5, SHA1 and SHA2 in libSystem: with CC_ prefix and _ after algorithm name - * - * OpenSSL: - * - MD5, SHA1 and SHA2 in libcrypto: with _ after algorithm name - * - * Windows: - * - MD5, SHA1 and SHA2 in archive_windows.c: without algorithm name - * and with __la_ prefix. - */ -#if defined(ARCHIVE_HASH_MD5_WIN) ||\ - defined(ARCHIVE_HASH_SHA1_WIN) || defined(ARCHIVE_HASH_SHA256_WIN) ||\ - defined(ARCHIVE_HASH_SHA384_WIN) || defined(ARCHIVE_HASH_SHA512_WIN) -#include -typedef struct { - int valid; - HCRYPTPROV cryptProv; - HCRYPTHASH hash; -} Digest_CTX; -extern void __la_hash_Init(Digest_CTX *, ALG_ID); -extern void __la_hash_Final(unsigned char *, size_t, Digest_CTX *); -extern void __la_hash_Update(Digest_CTX *, const unsigned char *, size_t); -#endif - -#if defined(ARCHIVE_HASH_MD5_LIBC) -# include -# define ARCHIVE_HAS_MD5 -typedef MD5_CTX archive_md5_ctx; -# define archive_md5_init(ctx) MD5Init(ctx) -# define archive_md5_final(ctx, buf) MD5Final(buf, ctx) -# define archive_md5_update(ctx, buf, n) MD5Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_MD5_LIBMD) -# include -# define ARCHIVE_HAS_MD5 -typedef MD5_CTX archive_md5_ctx; -# define archive_md5_init(ctx) MD5Init(ctx) -# define archive_md5_final(ctx, buf) MD5Final(buf, ctx) -# define archive_md5_update(ctx, buf, n) MD5Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_MD5_LIBSYSTEM) -# include -# define ARCHIVE_HAS_MD5 -typedef CC_MD5_CTX archive_md5_ctx; -# define archive_md5_init(ctx) CC_MD5_Init(ctx) -# define archive_md5_final(ctx, buf) CC_MD5_Final(buf, ctx) -# define archive_md5_update(ctx, buf, n) CC_MD5_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_MD5_OPENSSL) -# include -# define ARCHIVE_HAS_MD5 -typedef MD5_CTX archive_md5_ctx; -# define archive_md5_init(ctx) MD5_Init(ctx) -# define archive_md5_final(ctx, buf) MD5_Final(buf, ctx) -# define archive_md5_update(ctx, buf, n) MD5_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_MD5_WIN) -# define ARCHIVE_HAS_MD5 -# define MD5_DIGEST_LENGTH 16 -typedef Digest_CTX archive_md5_ctx; -# define archive_md5_init(ctx) __la_hash_Init(ctx, CALG_MD5) -# define archive_md5_final(ctx, buf) __la_hash_Final(buf, MD5_DIGEST_LENGTH, ctx) -# define archive_md5_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) -#endif - -#if defined(ARCHIVE_HASH_RMD160_LIBC) -# include -# define ARCHIVE_HAS_RMD160 -typedef RMD160_CTX archive_rmd160_ctx; -# define archive_rmd160_init(ctx) RMD160Init(ctx) -# define archive_rmd160_final(ctx, buf) RMD160Final(buf, ctx) -# define archive_rmd160_update(ctx, buf, n) RMD160Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_RMD160_OPENSSL) -# include -# define ARCHIVE_HAS_RMD160 -typedef RIPEMD160_CTX archive_rmd160_ctx; -# define archive_rmd160_init(ctx) RIPEMD160_Init(ctx) -# define archive_rmd160_final(ctx, buf) RIPEMD160_Final(buf, ctx) -# define archive_rmd160_update(ctx, buf, n) RIPEMD160_Update(ctx, buf, n) -#endif - -#if defined(ARCHIVE_HASH_SHA1_LIBC) -# include -# define ARCHIVE_HAS_SHA1 -typedef SHA1_CTX archive_sha1_ctx; -# define archive_sha1_init(ctx) SHA1Init(ctx) -# define archive_sha1_final(ctx, buf) SHA1Final(buf, ctx) -# define archive_sha1_update(ctx, buf, n) SHA1Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA1_LIBMD) -# include -# define ARCHIVE_HAS_SHA1 -typedef SHA1_CTX archive_sha1_ctx; -# define archive_sha1_init(ctx) SHA1_Init(ctx) -# define archive_sha1_final(ctx, buf) SHA1_Final(buf, ctx) -# define archive_sha1_update(ctx, buf, n) SHA1_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA1_LIBSYSTEM) -# include -# define ARCHIVE_HAS_SHA1 -typedef CC_SHA1_CTX archive_sha1_ctx; -# define archive_sha1_init(ctx) CC_SHA1_Init(ctx) -# define archive_sha1_final(ctx, buf) CC_SHA1_Final(buf, ctx) -# define archive_sha1_update(ctx, buf, n) CC_SHA1_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA1_OPENSSL) -# include -# define ARCHIVE_HAS_SHA1 -typedef SHA_CTX archive_sha1_ctx; -# define archive_sha1_init(ctx) SHA1_Init(ctx) -# define archive_sha1_final(ctx, buf) SHA1_Final(buf, ctx) -# define archive_sha1_update(ctx, buf, n) SHA1_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA1_WIN) -# define ARCHIVE_HAS_SHA1 -# define SHA1_DIGEST_LENGTH 20 -typedef Digest_CTX archive_sha1_ctx; -# define archive_sha1_init(ctx) __la_hash_Init(ctx, CALG_SHA1) -# define archive_sha1_final(ctx, buf) __la_hash_Final(buf, SHA1_DIGEST_LENGTH, ctx) -# define archive_sha1_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) -#endif - -#if defined(ARCHIVE_HASH_SHA256_LIBC) -# include -# define ARCHIVE_HAS_SHA256 -typedef SHA256_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) SHA256_Init(ctx) -# define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx) -# define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA256_LIBC2) -# include -# define ARCHIVE_HAS_SHA256 -typedef SHA256_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) SHA256Init(ctx) -# define archive_sha256_final(ctx, buf) SHA256Final(buf, ctx) -# define archive_sha256_update(ctx, buf, n) SHA256Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA256_LIBC3) -# include -# define ARCHIVE_HAS_SHA256 -typedef SHA2_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) SHA256Init(ctx) -# define archive_sha256_final(ctx, buf) SHA256Final(buf, ctx) -# define archive_sha256_update(ctx, buf, n) SHA256Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA256_LIBMD) -# include -# define ARCHIVE_HAS_SHA256 -typedef SHA256_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) SHA256_Init(ctx) -# define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx) -# define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA256_LIBSYSTEM) -# include -# define ARCHIVE_HAS_SHA256 -typedef CC_SHA256_CTX archive_shs256_ctx; -# define archive_shs256_init(ctx) CC_SHA256_Init(ctx) -# define archive_shs256_final(ctx, buf) CC_SHA256_Final(buf, ctx) -# define archive_shs256_update(ctx, buf, n) CC_SHA256_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA256_OPENSSL) -# include -# define ARCHIVE_HAS_SHA256 -typedef SHA256_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) SHA256_Init(ctx) -# define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx) -# define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA256_WIN) -# define ARCHIVE_HAS_SHA256 -# define SHA256_DIGEST_LENGTH 32 -typedef Digest_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) __la_hash_Init(ctx, CALG_SHA_256) -# define archive_sha256_final(ctx, buf) __la_hash_Final(buf, SHA256_DIGEST_LENGTH, ctx) -# define archive_sha256_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) -#endif - -#if defined(ARCHIVE_HASH_SHA384_LIBC) -# include -# define ARCHIVE_HAS_SHA384 -typedef SHA384_CTX archive_sha384_ctx; -# define archive_sha384_init(ctx) SHA384_Init(ctx) -# define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx) -# define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA384_LIBC2) -# include -# define ARCHIVE_HAS_SHA384 -typedef SHA384_CTX archive_sha384_ctx; -# define archive_sha384_init(ctx) SHA384Init(ctx) -# define archive_sha384_final(ctx, buf) SHA384Final(buf, ctx) -# define archive_sha384_update(ctx, buf, n) SHA384Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA384_LIBC3) -# include -# define ARCHIVE_HAS_SHA384 -typedef SHA2_CTX archive_sha384_ctx; -# define archive_sha384_init(ctx) SHA384Init(ctx) -# define archive_sha384_final(ctx, buf) SHA384Final(buf, ctx) -# define archive_sha384_update(ctx, buf, n) SHA384Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA384_LIBSYSTEM) -# include -# define ARCHIVE_HAS_SHA384 -typedef CC_SHA512_CTX archive_shs384_ctx; -# define archive_shs384_init(ctx) CC_SHA384_Init(ctx) -# define archive_shs384_final(ctx, buf) CC_SHA384_Final(buf, ctx) -# define archive_shs384_update(ctx, buf, n) CC_SHA384_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA384_OPENSSL) -# include -# define ARCHIVE_HAS_SHA384 -typedef SHA512_CTX archive_sha384_ctx; -# define archive_sha384_init(ctx) SHA384_Init(ctx) -# define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx) -# define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA384_WIN) -# define ARCHIVE_HAS_SHA384 -# define SHA384_DIGEST_LENGTH 48 -typedef Digest_CTX archive_sha384_ctx; -# define archive_sha384_init(ctx) __la_hash_Init(ctx, CALG_SHA_384) -# define archive_sha384_final(ctx, buf) __la_hash_Final(buf, SHA384_DIGEST_LENGTH, ctx) -# define archive_sha384_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) -#endif - -#if defined(ARCHIVE_HASH_SHA512_LIBC) -# include -# define ARCHIVE_HAS_SHA512 -typedef SHA512_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) SHA512_Init(ctx) -# define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx) -# define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA512_LIBC2) -# include -# define ARCHIVE_HAS_SHA512 -typedef SHA512_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) SHA512Init(ctx) -# define archive_sha512_final(ctx, buf) SHA512Final(buf, ctx) -# define archive_sha512_update(ctx, buf, n) SHA512Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA512_LIBC3) -# include -# define ARCHIVE_HAS_SHA512 -typedef SHA2_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) SHA512Init(ctx) -# define archive_sha512_final(ctx, buf) SHA512Final(buf, ctx) -# define archive_sha512_update(ctx, buf, n) SHA512Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA512_LIBMD) -# include -# define ARCHIVE_HAS_SHA512 -typedef SHA512_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) SHA512_Init(ctx) -# define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx) -# define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA512_LIBSYSTEM) -# include -# define ARCHIVE_HAS_SHA512 -typedef CC_SHA512_CTX archive_shs512_ctx; -# define archive_shs512_init(ctx) CC_SHA512_Init(ctx) -# define archive_shs512_final(ctx, buf) CC_SHA512_Final(buf, ctx) -# define archive_shs512_update(ctx, buf, n) CC_SHA512_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA512_OPENSSL) -# include -# define ARCHIVE_HAS_SHA512 -typedef SHA512_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) SHA512_Init(ctx) -# define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx) -# define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n) -#elif defined(ARCHIVE_HASH_SHA512_WIN) -# define ARCHIVE_HAS_SHA512 -# define SHA512_DIGEST_LENGTH 64 -typedef Digest_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) __la_hash_Init(ctx, CALG_SHA_512) -# define archive_sha512_final(ctx, buf) __la_hash_Final(buf, SHA512_DIGEST_LENGTH, ctx) -# define archive_sha512_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) -#endif diff --git a/lib/libarchive/archive_platform.h b/lib/libarchive/archive_platform.h deleted file mode 100644 index 9dc4643..0000000 --- a/lib/libarchive/archive_platform.h +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ - -/* - * This header is the first thing included in any of the libarchive - * source files. As far as possible, platform-specific issues should - * be dealt with here and not within individual source files. I'm - * actively trying to minimize #if blocks within the main source, - * since they obfuscate the code. - */ - -#ifndef ARCHIVE_PLATFORM_H_INCLUDED -#define ARCHIVE_PLATFORM_H_INCLUDED - -/* archive.h and archive_entry.h require this. */ -#define __LIBARCHIVE_BUILD 1 - -#if defined(PLATFORM_CONFIG_H) -/* Use hand-built config.h in environments that need it. */ -#include PLATFORM_CONFIG_H -#elif defined(HAVE_CONFIG_H) -/* Most POSIX platforms use the 'configure' script to build config.h */ -#include "config.h" -#else -/* Warn if the library hasn't been (automatically or manually) configured. */ -#error Oops: No config.h and no pre-built configuration in archive_platform.h. -#endif - -/* It should be possible to get rid of this by extending the feature-test - * macros to cover Windows API functions, probably along with non-trivial - * refactoring of code to find structures that sit more cleanly on top of - * either Windows or Posix APIs. */ -#if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) -#include "archive_windows.h" -#endif - -/* - * The config files define a lot of feature macros. The following - * uses those macros to select/define replacements and include key - * headers as required. - */ - -/* Get a real definition for __FBSDID if we can */ -#if HAVE_SYS_CDEFS_H -#include -#endif - -/* If not, define it so as to avoid dangling semicolons. */ -#ifndef __FBSDID -#define __FBSDID(a) struct _undefined_hack -#endif - -/* Try to get standard C99-style integer type definitions. */ -#if HAVE_INTTYPES_H -#include -#endif -#if HAVE_STDINT_H -#include -#endif - -/* Borland warns about its own constants! */ -#if defined(__BORLANDC__) -# if HAVE_DECL_UINT64_MAX -# undef UINT64_MAX -# undef HAVE_DECL_UINT64_MAX -# endif -# if HAVE_DECL_UINT64_MIN -# undef UINT64_MIN -# undef HAVE_DECL_UINT64_MIN -# endif -# if HAVE_DECL_INT64_MAX -# undef INT64_MAX -# undef HAVE_DECL_INT64_MAX -# endif -# if HAVE_DECL_INT64_MIN -# undef INT64_MIN -# undef HAVE_DECL_INT64_MIN -# endif -#endif - -/* Some platforms lack the standard *_MAX definitions. */ -#if !HAVE_DECL_SIZE_MAX -#define SIZE_MAX (~(size_t)0) -#endif -#if !HAVE_DECL_SSIZE_MAX -#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) -#endif -#if !HAVE_DECL_UINT32_MAX -#define UINT32_MAX (~(uint32_t)0) -#endif -#if !HAVE_DECL_UINT64_MAX -#define UINT64_MAX (~(uint64_t)0) -#endif -#if !HAVE_DECL_INT64_MAX -#define INT64_MAX ((int64_t)(UINT64_MAX >> 1)) -#endif -#if !HAVE_DECL_INT64_MIN -#define INT64_MIN ((int64_t)(~INT64_MAX)) -#endif - -/* - * If this platform has , acl_create(), acl_init(), - * acl_set_file(), and ACL_USER, we assume it has the rest of the - * POSIX.1e draft functions used in archive_read_extract.c. - */ -#if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER -#define HAVE_POSIX_ACL 1 -#endif - -/* - * If we can't restore metadata using a file descriptor, then - * for compatibility's sake, close files before trying to restore metadata. - */ -#if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN) -#define CAN_RESTORE_METADATA_FD -#endif - -/* Set up defaults for internal error codes. */ -#ifndef ARCHIVE_ERRNO_FILE_FORMAT -#if HAVE_EFTYPE -#define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE -#else -#if HAVE_EILSEQ -#define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ -#else -#define ARCHIVE_ERRNO_FILE_FORMAT EINVAL -#endif -#endif -#endif - -#ifndef ARCHIVE_ERRNO_PROGRAMMER -#define ARCHIVE_ERRNO_PROGRAMMER EINVAL -#endif - -#ifndef ARCHIVE_ERRNO_MISC -#define ARCHIVE_ERRNO_MISC (-1) -#endif - -#endif /* !ARCHIVE_PLATFORM_H_INCLUDED */ diff --git a/lib/libarchive/archive_private.h b/lib/libarchive/archive_private.h deleted file mode 100644 index dc83048..0000000 --- a/lib/libarchive/archive_private.h +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifndef ARCHIVE_PRIVATE_H_INCLUDED -#define ARCHIVE_PRIVATE_H_INCLUDED - -#include "archive.h" -#include "archive_string.h" - -#if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) -#else -#define __LA_DEAD -#endif - -#define ARCHIVE_WRITE_MAGIC (0xb0c5c0deU) -#define ARCHIVE_READ_MAGIC (0xdeb0c5U) -#define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U) -#define ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U) - -#define ARCHIVE_STATE_ANY 0xFFFFU -#define ARCHIVE_STATE_NEW 1U -#define ARCHIVE_STATE_HEADER 2U -#define ARCHIVE_STATE_DATA 4U -#define ARCHIVE_STATE_DATA_END 8U -#define ARCHIVE_STATE_EOF 0x10U -#define ARCHIVE_STATE_CLOSED 0x20U -#define ARCHIVE_STATE_FATAL 0x8000U - -struct archive_vtable { - int (*archive_close)(struct archive *); - int (*archive_free)(struct archive *); - int (*archive_write_header)(struct archive *, - struct archive_entry *); - int (*archive_write_finish_entry)(struct archive *); - ssize_t (*archive_write_data)(struct archive *, - const void *, size_t); - ssize_t (*archive_write_data_block)(struct archive *, - const void *, size_t, off_t); -}; - -struct archive { - /* - * The magic/state values are used to sanity-check the - * client's usage. If an API function is called at a - * ridiculous time, or the client passes us an invalid - * pointer, these values allow me to catch that. - */ - unsigned int magic; - unsigned int state; - - /* - * Some public API functions depend on the "real" type of the - * archive object. - */ - struct archive_vtable *vtable; - - int archive_format; - const char *archive_format_name; - - int compression_code; /* Currently active compression. */ - const char *compression_name; - - /* Position in UNCOMPRESSED data stream. */ - int64_t file_position; - /* Position in COMPRESSED data stream. */ - int64_t raw_position; - /* Number of file entries processed. */ - int file_count; - - int archive_error_number; - const char *error; - struct archive_string error_string; -}; - -/* Check magic value and state; exit if it isn't valid. */ -void __archive_check_magic(struct archive *, unsigned int magic, - unsigned int state, const char *func); - -void __archive_errx(int retvalue, const char *msg) __LA_DEAD; - -int __archive_parse_options(const char *p, const char *fn, - int keysize, char *key, int valsize, char *val); - -#define err_combine(a,b) ((a) < (b) ? (a) : (b)) - -#if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER <= 1300) -# define ARCHIVE_LITERAL_LL(x) x##i64 -# define ARCHIVE_LITERAL_ULL(x) x##ui64 -#else -# define ARCHIVE_LITERAL_LL(x) x##ll -# define ARCHIVE_LITERAL_ULL(x) x##ull -#endif - -#endif diff --git a/lib/libarchive/archive_read.3 b/lib/libarchive/archive_read.3 deleted file mode 100644 index 4df0db6..0000000 --- a/lib/libarchive/archive_read.3 +++ /dev/null @@ -1,714 +0,0 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd April 13, 2009 -.Dt ARCHIVE_READ 3 -.Os -.Sh NAME -.Nm archive_read_new , -.Nm archive_read_set_filter_options , -.Nm archive_read_set_format_options , -.Nm archive_read_set_options , -.Nm archive_read_support_compression_all , -.Nm archive_read_support_compression_bzip2 , -.Nm archive_read_support_compression_compress , -.Nm archive_read_support_compression_gzip , -.Nm archive_read_support_compression_lzma , -.Nm archive_read_support_compression_none , -.Nm archive_read_support_compression_xz , -.Nm archive_read_support_compression_program , -.Nm archive_read_support_compression_program_signature , -.Nm archive_read_support_format_all , -.Nm archive_read_support_format_ar , -.Nm archive_read_support_format_cpio , -.Nm archive_read_support_format_empty , -.Nm archive_read_support_format_iso9660 , -.Nm archive_read_support_format_mtree, -.Nm archive_read_support_format_raw, -.Nm archive_read_support_format_tar , -.Nm archive_read_support_format_zip , -.Nm archive_read_open , -.Nm archive_read_open2 , -.Nm archive_read_open_fd , -.Nm archive_read_open_FILE , -.Nm archive_read_open_filename , -.Nm archive_read_open_memory , -.Nm archive_read_next_header , -.Nm archive_read_next_header2 , -.Nm archive_read_data , -.Nm archive_read_data_block , -.Nm archive_read_data_skip , -.\" #if ARCHIVE_API_VERSION < 3 -.Nm archive_read_data_into_buffer , -.\" #endif -.Nm archive_read_data_into_fd , -.Nm archive_read_extract , -.Nm archive_read_extract2 , -.Nm archive_read_extract_set_progress_callback , -.Nm archive_read_close , -.Nm archive_read_free -.Nd functions for reading streaming archives -.Sh SYNOPSIS -.In archive.h -.Ft struct archive * -.Fn archive_read_new "void" -.Ft int -.Fn archive_read_support_compression_all "struct archive *" -.Ft int -.Fn archive_read_support_compression_bzip2 "struct archive *" -.Ft int -.Fn archive_read_support_compression_compress "struct archive *" -.Ft int -.Fn archive_read_support_compression_gzip "struct archive *" -.Ft int -.Fn archive_read_support_compression_lzma "struct archive *" -.Ft int -.Fn archive_read_support_compression_none "struct archive *" -.Ft int -.Fn archive_read_support_compression_xz "struct archive *" -.Ft int -.Fo archive_read_support_compression_program -.Fa "struct archive *" -.Fa "const char *cmd" -.Fc -.Ft int -.Fo archive_read_support_compression_program_signature -.Fa "struct archive *" -.Fa "const char *cmd" -.Fa "const void *signature" -.Fa "size_t signature_length" -.Fc -.Ft int -.Fn archive_read_support_format_all "struct archive *" -.Ft int -.Fn archive_read_support_format_ar "struct archive *" -.Ft int -.Fn archive_read_support_format_cpio "struct archive *" -.Ft int -.Fn archive_read_support_format_empty "struct archive *" -.Ft int -.Fn archive_read_support_format_iso9660 "struct archive *" -.Ft int -.Fn archive_read_support_format_mtree "struct archive *" -.Ft int -.Fn archive_read_support_format_raw "struct archive *" -.Ft int -.Fn archive_read_support_format_tar "struct archive *" -.Ft int -.Fn archive_read_support_format_zip "struct archive *" -.Ft int -.Fn archive_read_set_filter_options "struct archive *" "const char *" -.Ft int -.Fn archive_read_set_format_options "struct archive *" "const char *" -.Ft int -.Fn archive_read_set_options "struct archive *" "const char *" -.Ft int -.Fo archive_read_open -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "archive_open_callback *" -.Fa "archive_read_callback *" -.Fa "archive_close_callback *" -.Fc -.Ft int -.Fo archive_read_open2 -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "archive_open_callback *" -.Fa "archive_read_callback *" -.Fa "archive_skip_callback *" -.Fa "archive_close_callback *" -.Fc -.Ft int -.Fn archive_read_open_FILE "struct archive *" "FILE *file" -.Ft int -.Fn archive_read_open_fd "struct archive *" "int fd" "size_t block_size" -.Ft int -.Fo archive_read_open_filename -.Fa "struct archive *" -.Fa "const char *filename" -.Fa "size_t block_size" -.Fc -.Ft int -.Fn archive_read_open_memory "struct archive *" "void *buff" "size_t size" -.Ft int -.Fn archive_read_next_header "struct archive *" "struct archive_entry **" -.Ft int -.Fn archive_read_next_header2 "struct archive *" "struct archive_entry *" -.Ft ssize_t -.Fn archive_read_data "struct archive *" "void *buff" "size_t len" -.Ft int -.Fo archive_read_data_block -.Fa "struct archive *" -.Fa "const void **buff" -.Fa "size_t *len" -.Fa "off_t *offset" -.Fc -.Ft int -.Fn archive_read_data_skip "struct archive *" -.\" #if ARCHIVE_API_VERSION < 3 -.Ft int -.Fn archive_read_data_into_buffer "struct archive *" "void *" "ssize_t len" -.\" #endif -.Ft int -.Fn archive_read_data_into_fd "struct archive *" "int fd" -.Ft int -.Fo archive_read_extract -.Fa "struct archive *" -.Fa "struct archive_entry *" -.Fa "int flags" -.Fc -.Ft int -.Fo archive_read_extract2 -.Fa "struct archive *src" -.Fa "struct archive_entry *" -.Fa "struct archive *dest" -.Fc -.Ft void -.Fo archive_read_extract_set_progress_callback -.Fa "struct archive *" -.Fa "void (*func)(void *)" -.Fa "void *user_data" -.Fc -.Ft int -.Fn archive_read_close "struct archive *" -.Ft int -.Fn archive_read_free "struct archive *" -.Sh DESCRIPTION -These functions provide a complete API for reading streaming archives. -The general process is to first create the -.Tn struct archive -object, set options, initialize the reader, iterate over the archive -headers and associated data, then close the archive and release all -resources. -The following summary describes the functions in approximately the -order they would be used: -.Bl -tag -compact -width indent -.It Fn archive_read_new -Allocates and initializes a -.Tn struct archive -object suitable for reading from an archive. -.It Xo -.Fn archive_read_support_compression_bzip2 , -.Fn archive_read_support_compression_compress , -.Fn archive_read_support_compression_gzip , -.Fn archive_read_support_compression_lzma , -.Fn archive_read_support_compression_none , -.Fn archive_read_support_compression_xz -.Xc -Enables auto-detection code and decompression support for the -specified compression. -Returns -.Cm ARCHIVE_OK -if the compression is fully supported, or -.Cm ARCHIVE_WARN -if the compression is supported only through an external program. -Note that decompression using an external program is usually slower than -decompression through built-in libraries. -Note that -.Dq none -is always enabled by default. -.It Fn archive_read_support_compression_all -Enables all available decompression filters. -.It Fn archive_read_support_compression_program -Data is fed through the specified external program before being dearchived. -Note that this disables automatic detection of the compression format, -so it makes no sense to specify this in conjunction with any other -decompression option. -.It Fn archive_read_support_compression_program_signature -This feeds data through the specified external program -but only if the initial bytes of the data match the specified -signature value. -.It Xo -.Fn archive_read_support_format_all , -.Fn archive_read_support_format_ar , -.Fn archive_read_support_format_cpio , -.Fn archive_read_support_format_empty , -.Fn archive_read_support_format_iso9660 , -.Fn archive_read_support_format_mtree , -.Fn archive_read_support_format_tar , -.Fn archive_read_support_format_zip -.Xc -Enables support---including auto-detection code---for the -specified archive format. -For example, -.Fn archive_read_support_format_tar -enables support for a variety of standard tar formats, old-style tar, -ustar, pax interchange format, and many common variants. -For convenience, -.Fn archive_read_support_format_all -enables support for all available formats. -Only empty archives are supported by default. -.It Fn archive_read_support_format_raw -The -.Dq raw -format handler allows libarchive to be used to read arbitrary data. -It treats any data stream as an archive with a single entry. -The pathname of this entry is -.Dq data ; -all other entry fields are unset. -This is not enabled by -.Fn archive_read_support_format_all -in order to avoid erroneous handling of damaged archives. -.It Xo -.Fn archive_read_set_filter_options , -.Fn archive_read_set_format_options , -.Fn archive_read_set_options -.Xc -Specifies options that will be passed to currently-registered -filters (including decompression filters) and/or format readers. -The argument is a comma-separated list of individual options. -Individual options have one of the following forms: -.Bl -tag -compact -width indent -.It Ar option=value -The option/value pair will be provided to every module. -Modules that do not accept an option with this name will ignore it. -.It Ar option -The option will be provided to every module with a value of -.Dq 1 . -.It Ar !option -The option will be provided to every module with a NULL value. -.It Ar module:option=value , Ar module:option , Ar module:!option -As above, but the corresponding option and value will be provided -only to modules whose name matches -.Ar module . -.El -The return value will be -.Cm ARCHIVE_OK -if any module accepts the option, or -.Cm ARCHIVE_WARN -if no module accepted the option, or -.Cm ARCHIVE_FATAL -if there was a fatal error while attempting to process the option. -.Pp -The currently supported options are: -.Bl -tag -compact -width indent -.It Format iso9660 -.Bl -tag -compact -width indent -.It Cm joliet -Support Joliet extensions. -Defaults to enabled, use -.Cm !joliet -to disable. -.El -.El -.It Fn archive_read_open -The same as -.Fn archive_read_open2 , -except that the skip callback is assumed to be -.Dv NULL . -.It Fn archive_read_open2 -Freeze the settings, open the archive, and prepare for reading entries. -This is the most generic version of this call, which accepts -four callback functions. -Most clients will want to use -.Fn archive_read_open_filename , -.Fn archive_read_open_FILE , -.Fn archive_read_open_fd , -or -.Fn archive_read_open_memory -instead. -The library invokes the client-provided functions to obtain -raw bytes from the archive. -.It Fn archive_read_open_FILE -Like -.Fn archive_read_open , -except that it accepts a -.Ft "FILE *" -pointer. -This function should not be used with tape drives or other devices -that require strict I/O blocking. -.It Fn archive_read_open_fd -Like -.Fn archive_read_open , -except that it accepts a file descriptor and block size rather than -a set of function pointers. -Note that the file descriptor will not be automatically closed at -end-of-archive. -This function is safe for use with tape drives or other blocked devices. -.It Fn archive_read_open_file -This is a deprecated synonym for -.Fn archive_read_open_filename . -.It Fn archive_read_open_filename -Like -.Fn archive_read_open , -except that it accepts a simple filename and a block size. -A NULL filename represents standard input. -This function is safe for use with tape drives or other blocked devices. -.It Fn archive_read_open_memory -Like -.Fn archive_read_open , -except that it accepts a pointer and size of a block of -memory containing the archive data. -.It Fn archive_read_next_header -Read the header for the next entry and return a pointer to -a -.Tn struct archive_entry . -This is a convenience wrapper around -.Fn archive_read_next_header2 -that reuses an internal -.Tn struct archive_entry -object for each request. -.It Fn archive_read_next_header2 -Read the header for the next entry and populate the provided -.Tn struct archive_entry . -.It Fn archive_read_data -Read data associated with the header just read. -Internally, this is a convenience function that calls -.Fn archive_read_data_block -and fills any gaps with nulls so that callers see a single -continuous stream of data. -.It Fn archive_read_data_block -Return the next available block of data for this entry. -Unlike -.Fn archive_read_data , -the -.Fn archive_read_data_block -function avoids copying data and allows you to correctly handle -sparse files, as supported by some archive formats. -The library guarantees that offsets will increase and that blocks -will not overlap. -Note that the blocks returned from this function can be much larger -than the block size read from disk, due to compression -and internal buffer optimizations. -.It Fn archive_read_data_skip -A convenience function that repeatedly calls -.Fn archive_read_data_block -to skip all of the data for this archive entry. -.\" #if ARCHIVE_API_VERSION < 3 -.It Fn archive_read_data_into_buffer -This function is deprecated and will be removed. -Use -.Fn archive_read_data -instead. -.\" #endif -.It Fn archive_read_data_into_fd -A convenience function that repeatedly calls -.Fn archive_read_data_block -to copy the entire entry to the provided file descriptor. -.It Fn archive_read_extract , Fn archive_read_extract_set_skip_file -A convenience function that wraps the corresponding -.Xr archive_write_disk 3 -interfaces. -The first call to -.Fn archive_read_extract -creates a restore object using -.Xr archive_write_disk_new 3 -and -.Xr archive_write_disk_set_standard_lookup 3 , -then transparently invokes -.Xr archive_write_disk_set_options 3 , -.Xr archive_write_header 3 , -.Xr archive_write_data 3 , -and -.Xr archive_write_finish_entry 3 -to create the entry on disk and copy data into it. -The -.Va flags -argument is passed unmodified to -.Xr archive_write_disk_set_options 3 . -.It Fn archive_read_extract2 -This is another version of -.Fn archive_read_extract -that allows you to provide your own restore object. -In particular, this allows you to override the standard lookup functions -using -.Xr archive_write_disk_set_group_lookup 3 , -and -.Xr archive_write_disk_set_user_lookup 3 . -Note that -.Fn archive_read_extract2 -does not accept a -.Va flags -argument; you should use -.Fn archive_write_disk_set_options -to set the restore options yourself. -.It Fn archive_read_extract_set_progress_callback -Sets a pointer to a user-defined callback that can be used -for updating progress displays during extraction. -The progress function will be invoked during the extraction of large -regular files. -The progress function will be invoked with the pointer provided to this call. -Generally, the data pointed to should include a reference to the archive -object and the archive_entry object so that various statistics -can be retrieved for the progress display. -.It Fn archive_read_close -Complete the archive and invoke the close callback. -.It Fn archive_read_free -Invokes -.Fn archive_read_close -if it was not invoked manually, then release all resources. -Note: In libarchive 1.x, this function was declared to return -.Ft void , -which made it impossible to detect certain errors when -.Fn archive_read_close -was invoked implicitly from this function. -The declaration is corrected beginning with libarchive 2.0. -.El -.Pp -Note that the library determines most of the relevant information about -the archive by inspection. -In particular, it automatically detects -.Xr gzip 1 -or -.Xr bzip2 1 -compression and transparently performs the appropriate decompression. -It also automatically detects the archive format. -.Pp -A complete description of the -.Tn struct archive -and -.Tn struct archive_entry -objects can be found in the overview manual page for -.Xr libarchive 3 . -.Sh CLIENT CALLBACKS -The callback functions must match the following prototypes: -.Bl -item -offset indent -.It -.Ft typedef ssize_t -.Fo archive_read_callback -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "const void **buffer" -.Fc -.It -.\" #if ARCHIVE_API_VERSION < 2 -.Ft typedef int -.Fo archive_skip_callback -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "size_t request" -.Fc -.\" #else -.\" .Ft typedef off_t -.\" .Fo archive_skip_callback -.\" .Fa "struct archive *" -.\" .Fa "void *client_data" -.\" .Fa "off_t request" -.\" .Fc -.\" #endif -.It -.Ft typedef int -.Fn archive_open_callback "struct archive *" "void *client_data" -.It -.Ft typedef int -.Fn archive_close_callback "struct archive *" "void *client_data" -.El -.Pp -The open callback is invoked by -.Fn archive_open . -It should return -.Cm ARCHIVE_OK -if the underlying file or data source is successfully -opened. -If the open fails, it should call -.Fn archive_set_error -to register an error code and message and return -.Cm ARCHIVE_FATAL . -.Pp -The read callback is invoked whenever the library -requires raw bytes from the archive. -The read callback should read data into a buffer, -set the -.Li const void **buffer -argument to point to the available data, and -return a count of the number of bytes available. -The library will invoke the read callback again -only after it has consumed this data. -The library imposes no constraints on the size -of the data blocks returned. -On end-of-file, the read callback should -return zero. -On error, the read callback should invoke -.Fn archive_set_error -to register an error code and message and -return -1. -.Pp -The skip callback is invoked when the -library wants to ignore a block of data. -The return value is the number of bytes actually -skipped, which may differ from the request. -If the callback cannot skip data, it should return -zero. -If the skip callback is not provided (the -function pointer is -.Dv NULL ), -the library will invoke the read function -instead and simply discard the result. -A skip callback can provide significant -performance gains when reading uncompressed -archives from slow disk drives or other media -that can skip quickly. -.Pp -The close callback is invoked by archive_close when -the archive processing is complete. -The callback should return -.Cm ARCHIVE_OK -on success. -On failure, the callback should invoke -.Fn archive_set_error -to register an error code and message and -return -.Cm ARCHIVE_FATAL. -.Sh EXAMPLE -The following illustrates basic usage of the library. -In this example, -the callback functions are simply wrappers around the standard -.Xr open 2 , -.Xr read 2 , -and -.Xr close 2 -system calls. -.Bd -literal -offset indent -void -list_archive(const char *name) -{ - struct mydata *mydata; - struct archive *a; - struct archive_entry *entry; - - mydata = malloc(sizeof(struct mydata)); - a = archive_read_new(); - mydata->name = name; - archive_read_support_compression_all(a); - archive_read_support_format_all(a); - archive_read_open(a, mydata, myopen, myread, myclose); - while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { - printf("%s\en",archive_entry_pathname(entry)); - archive_read_data_skip(a); - } - archive_read_free(a); - free(mydata); -} - -ssize_t -myread(struct archive *a, void *client_data, const void **buff) -{ - struct mydata *mydata = client_data; - - *buff = mydata->buff; - return (read(mydata->fd, mydata->buff, 10240)); -} - -int -myopen(struct archive *a, void *client_data) -{ - struct mydata *mydata = client_data; - - mydata->fd = open(mydata->name, O_RDONLY); - return (mydata->fd >= 0 ? ARCHIVE_OK : ARCHIVE_FATAL); -} - -int -myclose(struct archive *a, void *client_data) -{ - struct mydata *mydata = client_data; - - if (mydata->fd > 0) - close(mydata->fd); - return (ARCHIVE_OK); -} -.Ed -.Sh RETURN VALUES -Most functions return zero on success, non-zero on error. -The possible return codes include: -.Cm ARCHIVE_OK -(the operation succeeded), -.Cm ARCHIVE_WARN -(the operation succeeded but a non-critical error was encountered), -.Cm ARCHIVE_EOF -(end-of-archive was encountered), -.Cm ARCHIVE_RETRY -(the operation failed but can be retried), -and -.Cm ARCHIVE_FATAL -(there was a fatal error; the archive should be closed immediately). -Detailed error codes and textual descriptions are available from the -.Fn archive_errno -and -.Fn archive_error_string -functions. -.Pp -.Fn archive_read_new -returns a pointer to a freshly allocated -.Tn struct archive -object. -It returns -.Dv NULL -on error. -.Pp -.Fn archive_read_data -returns a count of bytes actually read or zero at the end of the entry. -On error, a value of -.Cm ARCHIVE_FATAL , -.Cm ARCHIVE_WARN , -or -.Cm ARCHIVE_RETRY -is returned and an error code and textual description can be retrieved from the -.Fn archive_errno -and -.Fn archive_error_string -functions. -.Pp -The library expects the client callbacks to behave similarly. -If there is an error, you can use -.Fn archive_set_error -to set an appropriate error code and description, -then return one of the non-zero values above. -(Note that the value eventually returned to the client may -not be the same; many errors that are not critical at the level -of basic I/O can prevent the archive from being properly read, -thus most I/O errors eventually cause -.Cm ARCHIVE_FATAL -to be returned.) -.\" .Sh ERRORS -.Sh SEE ALSO -.Xr tar 1 , -.Xr archive 3 , -.Xr archive_util 3 , -.Xr tar 5 -.Sh HISTORY -The -.Nm libarchive -library first appeared in -.Fx 5.3 . -.Sh AUTHORS -.An -nosplit -The -.Nm libarchive -library was written by -.An Tim Kientzle Aq kientzle@acm.org . -.Sh BUGS -Many traditional archiver programs treat -empty files as valid empty archives. -For example, many implementations of -.Xr tar 1 -allow you to append entries to an empty file. -Of course, it is impossible to determine the format of an empty file -by inspecting the contents, so this library treats empty files as -having a special -.Dq empty -format. diff --git a/lib/libarchive/archive_read.c b/lib/libarchive/archive_read.c deleted file mode 100644 index fb72407..0000000 --- a/lib/libarchive/archive_read.c +++ /dev/null @@ -1,1249 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This file contains the "essential" portions of the read API, that - * is, stuff that will probably always be used by any client that - * actually needs to read an archive. Optional pieces have been, as - * far as possible, separated out into separate files to avoid - * needlessly bloating statically-linked clients. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" - -#define minimum(a, b) (a < b ? a : b) - -static int build_stream(struct archive_read *); -static int choose_format(struct archive_read *); -static int cleanup_filters(struct archive_read *); -static struct archive_vtable *archive_read_vtable(void); -static int _archive_read_close(struct archive *); -static int _archive_read_free(struct archive *); - -static struct archive_vtable * -archive_read_vtable(void) -{ - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_free = _archive_read_free; - av.archive_close = _archive_read_close; - } - return (&av); -} - -/* - * Allocate, initialize and return a struct archive object. - */ -struct archive * -archive_read_new(void) -{ - struct archive_read *a; - - a = (struct archive_read *)malloc(sizeof(*a)); - if (a == NULL) - return (NULL); - memset(a, 0, sizeof(*a)); - a->archive.magic = ARCHIVE_READ_MAGIC; - - a->archive.state = ARCHIVE_STATE_NEW; - a->entry = archive_entry_new(); - a->archive.vtable = archive_read_vtable(); - - return (&a->archive); -} - -/* - * Record the do-not-extract-to file. This belongs in archive_read_extract.c. - */ -void -archive_read_extract_set_skip_file(struct archive *_a, dev_t d, ino_t i) -{ - struct archive_read *a = (struct archive_read *)_a; - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_ANY, - "archive_read_extract_set_skip_file"); - a->skip_file_dev = d; - a->skip_file_ino = i; -} - -/* - * Set read options for the format. - */ -int -archive_read_set_format_options(struct archive *_a, const char *s) -{ - struct archive_read *a; - struct archive_format_descriptor *format; - char key[64], val[64]; - char *valp; - size_t i; - int len, r; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "archive_read_set_format_options"); - - if (s == NULL || *s == '\0') - return (ARCHIVE_OK); - a = (struct archive_read *)_a; - __archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_NEW, "archive_read_set_format_options"); - len = 0; - for (i = 0; i < sizeof(a->formats)/sizeof(a->formats[0]); i++) { - format = &a->formats[i]; - if (format == NULL || format->options == NULL || - format->name == NULL) - /* This format does not support option. */ - continue; - - while ((len = __archive_parse_options(s, format->name, - sizeof(key), key, sizeof(val), val)) > 0) { - valp = val[0] == '\0' ? NULL : val; - a->format = format; - r = format->options(a, key, valp); - a->format = NULL; - if (r == ARCHIVE_FATAL) - return (r); - s += len; - } - } - if (len < 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Illegal format options."); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); -} - -/* - * Set read options for the filter. - */ -int -archive_read_set_filter_options(struct archive *_a, const char *s) -{ - struct archive_read *a; - struct archive_read_filter *filter; - struct archive_read_filter_bidder *bidder; - char key[64], val[64]; - int len, r; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "archive_read_set_filter_options"); - - if (s == NULL || *s == '\0') - return (ARCHIVE_OK); - a = (struct archive_read *)_a; - __archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_NEW, "archive_read_set_filter_options"); - len = 0; - for (filter = a->filter; filter != NULL; filter = filter->upstream) { - bidder = filter->bidder; - if (bidder == NULL) - continue; - if (bidder->options == NULL) - /* This bidder does not support option */ - continue; - while ((len = __archive_parse_options(s, filter->name, - sizeof(key), key, sizeof(val), val)) > 0) { - if (val[0] == '\0') - r = bidder->options(bidder, key, NULL); - else - r = bidder->options(bidder, key, val); - if (r == ARCHIVE_FATAL) - return (r); - s += len; - } - } - if (len < 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Illegal format options."); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); -} - -/* - * Set read options for the format and the filter. - */ -int -archive_read_set_options(struct archive *_a, const char *s) -{ - int r; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "archive_read_set_options"); - archive_clear_error(_a); - - r = archive_read_set_format_options(_a, s); - if (r != ARCHIVE_OK) - return (r); - r = archive_read_set_filter_options(_a, s); - if (r != ARCHIVE_OK) - return (r); - return (ARCHIVE_OK); -} - -/* - * Open the archive - */ -int -archive_read_open(struct archive *a, void *client_data, - archive_open_callback *client_opener, archive_read_callback *client_reader, - archive_close_callback *client_closer) -{ - /* Old archive_read_open() is just a thin shell around - * archive_read_open2. */ - return archive_read_open2(a, client_data, client_opener, - client_reader, NULL, client_closer); -} - -static ssize_t -client_read_proxy(struct archive_read_filter *self, const void **buff) -{ - ssize_t r; - r = (self->archive->client.reader)(&self->archive->archive, - self->data, buff); - self->archive->archive.raw_position += r; - return (r); -} - -static int64_t -client_skip_proxy(struct archive_read_filter *self, int64_t request) -{ - int64_t ask, get, total; - /* Limit our maximum seek request to 1GB on platforms - * with 32-bit off_t (such as Windows). */ - int64_t skip_limit = ((int64_t)1) << (sizeof(off_t) * 8 - 2); - - if (self->archive->client.skipper == NULL) - return (0); - total = 0; - for (;;) { - ask = request; - if (ask > skip_limit) - ask = skip_limit; - get = (self->archive->client.skipper)(&self->archive->archive, - self->data, ask); - if (get == 0) - return (total); - request -= get; - self->archive->archive.raw_position += get; - total += get; - } -} - -static int -client_close_proxy(struct archive_read_filter *self) -{ - int r = ARCHIVE_OK; - - if (self->archive->client.closer != NULL) - r = (self->archive->client.closer)((struct archive *)self->archive, - self->data); - self->data = NULL; - return (r); -} - - -int -archive_read_open2(struct archive *_a, void *client_data, - archive_open_callback *client_opener, - archive_read_callback *client_reader, - archive_skip_callback *client_skipper, - archive_close_callback *client_closer) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter *filter; - int e; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "archive_read_open"); - archive_clear_error(&a->archive); - - if (client_reader == NULL) - __archive_errx(1, - "No reader function provided to archive_read_open"); - - /* Open data source. */ - if (client_opener != NULL) { - e =(client_opener)(&a->archive, client_data); - if (e != 0) { - /* If the open failed, call the closer to clean up. */ - if (client_closer) - (client_closer)(&a->archive, client_data); - return (e); - } - } - - /* Save the client functions and mock up the initial source. */ - a->client.reader = client_reader; - a->client.skipper = client_skipper; - a->client.closer = client_closer; - - filter = calloc(1, sizeof(*filter)); - if (filter == NULL) - return (ARCHIVE_FATAL); - filter->bidder = NULL; - filter->upstream = NULL; - filter->archive = a; - filter->data = client_data; - filter->read = client_read_proxy; - filter->skip = client_skip_proxy; - filter->close = client_close_proxy; - filter->name = "none"; - filter->code = ARCHIVE_COMPRESSION_NONE; - a->filter = filter; - - /* Build out the input pipeline. */ - e = build_stream(a); - if (e == ARCHIVE_OK) - a->archive.state = ARCHIVE_STATE_HEADER; - - return (e); -} - -/* - * Allow each registered stream transform to bid on whether - * it wants to handle this stream. Repeat until we've finished - * building the pipeline. - */ -static int -build_stream(struct archive_read *a) -{ - int number_bidders, i, bid, best_bid; - struct archive_read_filter_bidder *bidder, *best_bidder; - struct archive_read_filter *filter; - ssize_t avail; - int r; - - for (;;) { - number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]); - - best_bid = 0; - best_bidder = NULL; - - bidder = a->bidders; - for (i = 0; i < number_bidders; i++, bidder++) { - if (bidder->bid != NULL) { - bid = (bidder->bid)(bidder, a->filter); - if (bid > best_bid) { - best_bid = bid; - best_bidder = bidder; - } - } - } - - /* If no bidder, we're done. */ - if (best_bidder == NULL) { - /* Verify the final pipelin by asking it for some data. */ - __archive_read_filter_ahead(a->filter, 1, &avail); - if (avail < 0) { - cleanup_filters(a); - return (ARCHIVE_FATAL); - } - a->archive.compression_name = a->filter->name; - a->archive.compression_code = a->filter->code; - return (ARCHIVE_OK); - } - - filter - = (struct archive_read_filter *)calloc(1, sizeof(*filter)); - if (filter == NULL) - return (ARCHIVE_FATAL); - filter->bidder = best_bidder; - filter->archive = a; - filter->upstream = a->filter; - a->filter = filter; - r = (best_bidder->init)(a->filter); - if (r != ARCHIVE_OK) { - cleanup_filters(a); - return (r); - } - } -} - -/* - * Read header of next entry. - */ -int -archive_read_next_header2(struct archive *_a, struct archive_entry *entry) -{ - struct archive_read *a = (struct archive_read *)_a; - int slot, ret; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_read_next_header"); - - ++_a->file_count; - archive_entry_clear(entry); - archive_clear_error(&a->archive); - - /* - * If no format has yet been chosen, choose one. - */ - if (a->format == NULL) { - slot = choose_format(a); - if (slot < 0) { - a->archive.state = ARCHIVE_STATE_FATAL; - return (ARCHIVE_FATAL); - } - a->format = &(a->formats[slot]); - } - - /* - * If client didn't consume entire data, skip any remainder - * (This is especially important for GNU incremental directories.) - */ - if (a->archive.state == ARCHIVE_STATE_DATA) { - ret = archive_read_data_skip(&a->archive); - if (ret == ARCHIVE_EOF) { - archive_set_error(&a->archive, EIO, "Premature end-of-file."); - a->archive.state = ARCHIVE_STATE_FATAL; - return (ARCHIVE_FATAL); - } - if (ret != ARCHIVE_OK) - return (ret); - } - - /* Record start-of-header. */ - a->header_position = a->archive.file_position; - - ret = (a->format->read_header)(a, entry); - - /* - * EOF and FATAL are persistent at this layer. By - * modifying the state, we guarantee that future calls to - * read a header or read data will fail. - */ - switch (ret) { - case ARCHIVE_EOF: - a->archive.state = ARCHIVE_STATE_EOF; - break; - case ARCHIVE_OK: - a->archive.state = ARCHIVE_STATE_DATA; - break; - case ARCHIVE_WARN: - a->archive.state = ARCHIVE_STATE_DATA; - break; - case ARCHIVE_RETRY: - break; - case ARCHIVE_FATAL: - a->archive.state = ARCHIVE_STATE_FATAL; - break; - } - - a->read_data_output_offset = 0; - a->read_data_remaining = 0; - return (ret); -} - -int -archive_read_next_header(struct archive *_a, struct archive_entry **entryp) -{ - int ret; - struct archive_read *a = (struct archive_read *)_a; - *entryp = NULL; - ret = archive_read_next_header2(_a, a->entry); - *entryp = a->entry; - return ret; -} - -/* - * Allow each registered format to bid on whether it wants to handle - * the next entry. Return index of winning bidder. - */ -static int -choose_format(struct archive_read *a) -{ - int slots; - int i; - int bid, best_bid; - int best_bid_slot; - - slots = sizeof(a->formats) / sizeof(a->formats[0]); - best_bid = -1; - best_bid_slot = -1; - - /* Set up a->format and a->pformat_data for convenience of bidders. */ - a->format = &(a->formats[0]); - for (i = 0; i < slots; i++, a->format++) { - if (a->format->bid) { - bid = (a->format->bid)(a); - if (bid == ARCHIVE_FATAL) - return (ARCHIVE_FATAL); - if ((bid > best_bid) || (best_bid_slot < 0)) { - best_bid = bid; - best_bid_slot = i; - } - } - } - - /* - * There were no bidders; this is a serious programmer error - * and demands a quick and definitive abort. - */ - if (best_bid_slot < 0) - __archive_errx(1, "No formats were registered; you must " - "invoke at least one archive_read_support_format_XXX " - "function in order to successfully read an archive."); - - /* - * There were bidders, but no non-zero bids; this means we - * can't support this stream. - */ - if (best_bid < 1) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Unrecognized archive format"); - return (ARCHIVE_FATAL); - } - - return (best_bid_slot); -} - -/* - * Return the file offset (within the uncompressed data stream) where - * the last header started. - */ -int64_t -archive_read_header_position(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_ANY, "archive_read_header_position"); - return (a->header_position); -} - -/* - * Read data from an archive entry, using a read(2)-style interface. - * This is a convenience routine that just calls - * archive_read_data_block and copies the results into the client - * buffer, filling any gaps with zero bytes. Clients using this - * API can be completely ignorant of sparse-file issues; sparse files - * will simply be padded with nulls. - * - * DO NOT intermingle calls to this function and archive_read_data_block - * to read a single entry body. - */ -ssize_t -archive_read_data(struct archive *_a, void *buff, size_t s) -{ - struct archive_read *a = (struct archive_read *)_a; - char *dest; - const void *read_buf; - size_t bytes_read; - size_t len; - int r; - - bytes_read = 0; - dest = (char *)buff; - - while (s > 0) { - if (a->read_data_remaining == 0) { - read_buf = a->read_data_block; - r = archive_read_data_block(&a->archive, &read_buf, - &a->read_data_remaining, &a->read_data_offset); - a->read_data_block = read_buf; - if (r == ARCHIVE_EOF) - return (bytes_read); - /* - * Error codes are all negative, so the status - * return here cannot be confused with a valid - * byte count. (ARCHIVE_OK is zero.) - */ - if (r < ARCHIVE_OK) - return (r); - } - - if (a->read_data_offset < a->read_data_output_offset) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Encountered out-of-order sparse blocks"); - return (ARCHIVE_RETRY); - } - - /* Compute the amount of zero padding needed. */ - if (a->read_data_output_offset + (off_t)s < - a->read_data_offset) { - len = s; - } else if (a->read_data_output_offset < - a->read_data_offset) { - len = a->read_data_offset - - a->read_data_output_offset; - } else - len = 0; - - /* Add zeroes. */ - memset(dest, 0, len); - s -= len; - a->read_data_output_offset += len; - dest += len; - bytes_read += len; - - /* Copy data if there is any space left. */ - if (s > 0) { - len = a->read_data_remaining; - if (len > s) - len = s; - memcpy(dest, a->read_data_block, len); - s -= len; - a->read_data_block += len; - a->read_data_remaining -= len; - a->read_data_output_offset += len; - a->read_data_offset += len; - dest += len; - bytes_read += len; - } - } - return (bytes_read); -} - -#if ARCHIVE_API_VERSION < 3 -/* - * Obsolete function provided for compatibility only. Note that the API - * of this function doesn't allow the caller to detect if the remaining - * data from the archive entry is shorter than the buffer provided, or - * even if an error occurred while reading data. - */ -int -archive_read_data_into_buffer(struct archive *a, void *d, ssize_t len) -{ - - archive_read_data(a, d, len); - return (ARCHIVE_OK); -} -#endif - -/* - * Skip over all remaining data in this entry. - */ -int -archive_read_data_skip(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - int r; - const void *buff; - size_t size; - off_t offset; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, - "archive_read_data_skip"); - - if (a->format->read_data_skip != NULL) - r = (a->format->read_data_skip)(a); - else { - while ((r = archive_read_data_block(&a->archive, - &buff, &size, &offset)) - == ARCHIVE_OK) - ; - } - - if (r == ARCHIVE_EOF) - r = ARCHIVE_OK; - - a->archive.state = ARCHIVE_STATE_HEADER; - return (r); -} - -/* - * Read the next block of entry data from the archive. - * This is a zero-copy interface; the client receives a pointer, - * size, and file offset of the next available block of data. - * - * Returns ARCHIVE_OK if the operation is successful, ARCHIVE_EOF if - * the end of entry is encountered. - */ -int -archive_read_data_block(struct archive *_a, - const void **buff, size_t *size, off_t *offset) -{ - struct archive_read *a = (struct archive_read *)_a; - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, - "archive_read_data_block"); - - if (a->format->read_data == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "Internal error: " - "No format_read_data_block function registered"); - return (ARCHIVE_FATAL); - } - - return (a->format->read_data)(a, buff, size, offset); -} - -/* - * Close the file and release most resources. - * - * Be careful: client might just call read_new and then read_free. - * Don't assume we actually read anything or performed any non-trivial - * initialization. - */ -static int -_archive_read_close(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - int r = ARCHIVE_OK, r1 = ARCHIVE_OK; - size_t i, n; - - __archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_ANY, "archive_read_close"); - archive_clear_error(&a->archive); - a->archive.state = ARCHIVE_STATE_CLOSED; - - - /* Call cleanup functions registered by optional components. */ - if (a->cleanup_archive_extract != NULL) - r = (a->cleanup_archive_extract)(a); - - /* TODO: Clean up the formatters. */ - - /* Release the filter objects. */ - r1 = cleanup_filters(a); - if (r1 < r) - r = r1; - - /* Release the bidder objects. */ - n = sizeof(a->bidders)/sizeof(a->bidders[0]); - for (i = 0; i < n; i++) { - if (a->bidders[i].free != NULL) { - r1 = (a->bidders[i].free)(&a->bidders[i]); - if (r1 < r) - r = r1; - } - } - - return (r); -} - -static int -cleanup_filters(struct archive_read *a) -{ - int r = ARCHIVE_OK; - /* Clean up the filter pipeline. */ - while (a->filter != NULL) { - struct archive_read_filter *t = a->filter->upstream; - if (a->filter->close != NULL) { - int r1 = (a->filter->close)(a->filter); - if (r1 < r) - r = r1; - } - free(a->filter->buffer); - free(a->filter); - a->filter = t; - } - return r; -} - -/* - * Release memory and other resources. - */ -static int -_archive_read_free(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - int i; - int slots; - int r = ARCHIVE_OK; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_ANY, - "archive_read_free"); - if (a->archive.state != ARCHIVE_STATE_CLOSED) - r = archive_read_close(&a->archive); - - /* Cleanup format-specific data. */ - slots = sizeof(a->formats) / sizeof(a->formats[0]); - for (i = 0; i < slots; i++) { - a->format = &(a->formats[i]); - if (a->formats[i].cleanup) - (a->formats[i].cleanup)(a); - } - - archive_string_free(&a->archive.error_string); - if (a->entry) - archive_entry_free(a->entry); - a->archive.magic = 0; - free(a); -#if ARCHIVE_API_VERSION > 1 - return (r); -#endif -} - -/* - * Used internally by read format handlers to register their bid and - * initialization functions. - */ -int -__archive_read_register_format(struct archive_read *a, - void *format_data, - const char *name, - int (*bid)(struct archive_read *), - int (*options)(struct archive_read *, const char *, const char *), - int (*read_header)(struct archive_read *, struct archive_entry *), - int (*read_data)(struct archive_read *, const void **, size_t *, off_t *), - int (*read_data_skip)(struct archive_read *), - int (*cleanup)(struct archive_read *)) -{ - int i, number_slots; - - __archive_check_magic(&a->archive, - ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "__archive_read_register_format"); - - number_slots = sizeof(a->formats) / sizeof(a->formats[0]); - - for (i = 0; i < number_slots; i++) { - if (a->formats[i].bid == bid) - return (ARCHIVE_WARN); /* We've already installed */ - if (a->formats[i].bid == NULL) { - a->formats[i].bid = bid; - a->formats[i].options = options; - a->formats[i].read_header = read_header; - a->formats[i].read_data = read_data; - a->formats[i].read_data_skip = read_data_skip; - a->formats[i].cleanup = cleanup; - a->formats[i].data = format_data; - a->formats[i].name = name; - return (ARCHIVE_OK); - } - } - - __archive_errx(1, "Not enough slots for format registration"); - return (ARCHIVE_FATAL); /* Never actually called. */ -} - -/* - * Used internally by decompression routines to register their bid and - * initialization functions. - */ -struct archive_read_filter_bidder * -__archive_read_get_bidder(struct archive_read *a) -{ - int i, number_slots; - - __archive_check_magic(&a->archive, - ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "__archive_read_get_bidder"); - - number_slots = sizeof(a->bidders) / sizeof(a->bidders[0]); - - for (i = 0; i < number_slots; i++) { - if (a->bidders[i].bid == NULL) { - memset(a->bidders + i, 0, sizeof(a->bidders[0])); - return (a->bidders + i); - } - } - - __archive_errx(1, "Not enough slots for compression registration"); - return (NULL); /* Never actually executed. */ -} - -/* - * The next three functions comprise the peek/consume internal I/O - * system used by archive format readers. This system allows fairly - * flexible read-ahead and allows the I/O code to operate in a - * zero-copy manner most of the time. - * - * In the ideal case, filters generate blocks of data - * and __archive_read_ahead() just returns pointers directly into - * those blocks. Then __archive_read_consume() just bumps those - * pointers. Only if your request would span blocks does the I/O - * layer use a copy buffer to provide you with a contiguous block of - * data. The __archive_read_skip() is an optimization; it scans ahead - * very quickly (it usually translates into a seek() operation if - * you're reading uncompressed disk files). - * - * A couple of useful idioms: - * * "I just want some data." Ask for 1 byte and pay attention to - * the "number of bytes available" from __archive_read_ahead(). - * You can consume more than you asked for; you just can't consume - * more than is available. If you consume everything that's - * immediately available, the next read_ahead() call will pull - * the next block. - * * "I want to output a large block of data." As above, ask for 1 byte, - * emit all that's available (up to whatever limit you have), then - * repeat until you're done. - * * "I want to peek ahead by a large amount." Ask for 4k or so, then - * double and repeat until you get an error or have enough. Note - * that the I/O layer will likely end up expanding its copy buffer - * to fit your request, so use this technique cautiously. This - * technique is used, for example, by some of the format tasting - * code that has uncertain look-ahead needs. - * - * TODO: Someday, provide a more generic __archive_read_seek() for - * those cases where it's useful. This is tricky because there are lots - * of cases where seek() is not available (reading gzip data from a - * network socket, for instance), so there needs to be a good way to - * communicate whether seek() is available and users of that interface - * need to use non-seeking strategies whenever seek() is not available. - */ - -/* - * Looks ahead in the input stream: - * * If 'avail' pointer is provided, that returns number of bytes available - * in the current buffer, which may be much larger than requested. - * * If end-of-file, *avail gets set to zero. - * * If error, *avail gets error code. - * * If request can be met, returns pointer to data, returns NULL - * if request is not met. - * - * Note: If you just want "some data", ask for 1 byte and pay attention - * to *avail, which will have the actual amount available. If you - * know exactly how many bytes you need, just ask for that and treat - * a NULL return as an error. - * - * Important: This does NOT move the file pointer. See - * __archive_read_consume() below. - */ - -/* - * This is tricky. We need to provide our clients with pointers to - * contiguous blocks of memory but we want to avoid copying whenever - * possible. - * - * Mostly, this code returns pointers directly into the block of data - * provided by the client_read routine. It can do this unless the - * request would split across blocks. In that case, we have to copy - * into an internal buffer to combine reads. - */ -const void * -__archive_read_ahead(struct archive_read *a, size_t min, ssize_t *avail) -{ - return (__archive_read_filter_ahead(a->filter, min, avail)); -} - -const void * -__archive_read_filter_ahead(struct archive_read_filter *filter, - size_t min, ssize_t *avail) -{ - ssize_t bytes_read; - size_t tocopy; - - if (filter->fatal) { - if (avail) - *avail = ARCHIVE_FATAL; - return (NULL); - } - - /* - * Keep pulling more data until we can satisfy the request. - */ - for (;;) { - - /* - * If we can satisfy from the copy buffer (and the - * copy buffer isn't empty), we're done. In particular, - * note that min == 0 is a perfectly well-defined - * request. - */ - if (filter->avail >= min && filter->avail > 0) { - if (avail != NULL) - *avail = filter->avail; - return (filter->next); - } - - /* - * We can satisfy directly from client buffer if everything - * currently in the copy buffer is still in the client buffer. - */ - if (filter->client_total >= filter->client_avail + filter->avail - && filter->client_avail + filter->avail >= min) { - /* "Roll back" to client buffer. */ - filter->client_avail += filter->avail; - filter->client_next -= filter->avail; - /* Copy buffer is now empty. */ - filter->avail = 0; - filter->next = filter->buffer; - /* Return data from client buffer. */ - if (avail != NULL) - *avail = filter->client_avail; - return (filter->client_next); - } - - /* Move data forward in copy buffer if necessary. */ - if (filter->next > filter->buffer && - filter->next + min > filter->buffer + filter->buffer_size) { - if (filter->avail > 0) - memmove(filter->buffer, filter->next, filter->avail); - filter->next = filter->buffer; - } - - /* If we've used up the client data, get more. */ - if (filter->client_avail <= 0) { - if (filter->end_of_file) { - if (avail != NULL) - *avail = 0; - return (NULL); - } - bytes_read = (filter->read)(filter, - &filter->client_buff); - if (bytes_read < 0) { /* Read error. */ - filter->client_total = filter->client_avail = 0; - filter->client_next = filter->client_buff = NULL; - filter->fatal = 1; - if (avail != NULL) - *avail = ARCHIVE_FATAL; - return (NULL); - } - if (bytes_read == 0) { /* Premature end-of-file. */ - filter->client_total = filter->client_avail = 0; - filter->client_next = filter->client_buff = NULL; - filter->end_of_file = 1; - /* Return whatever we do have. */ - if (avail != NULL) - *avail = filter->avail; - return (NULL); - } - filter->position += bytes_read; - filter->client_total = bytes_read; - filter->client_avail = filter->client_total; - filter->client_next = filter->client_buff; - } - else - { - /* - * We can't satisfy the request from the copy - * buffer or the existing client data, so we - * need to copy more client data over to the - * copy buffer. - */ - - /* Ensure the buffer is big enough. */ - if (min > filter->buffer_size) { - size_t s, t; - char *p; - - /* Double the buffer; watch for overflow. */ - s = t = filter->buffer_size; - if (s == 0) - s = min; - while (s < min) { - t *= 2; - if (t <= s) { /* Integer overflow! */ - archive_set_error( - &filter->archive->archive, - ENOMEM, - "Unable to allocate copy buffer"); - filter->fatal = 1; - if (avail != NULL) - *avail = ARCHIVE_FATAL; - return (NULL); - } - s = t; - } - /* Now s >= min, so allocate a new buffer. */ - p = (char *)malloc(s); - if (p == NULL) { - archive_set_error( - &filter->archive->archive, - ENOMEM, - "Unable to allocate copy buffer"); - filter->fatal = 1; - if (avail != NULL) - *avail = ARCHIVE_FATAL; - return (NULL); - } - /* Move data into newly-enlarged buffer. */ - if (filter->avail > 0) - memmove(p, filter->next, filter->avail); - free(filter->buffer); - filter->next = filter->buffer = p; - filter->buffer_size = s; - } - - /* We can add client data to copy buffer. */ - /* First estimate: copy to fill rest of buffer. */ - tocopy = (filter->buffer + filter->buffer_size) - - (filter->next + filter->avail); - /* Don't waste time buffering more than we need to. */ - if (tocopy + filter->avail > min) - tocopy = min - filter->avail; - /* Don't copy more than is available. */ - if (tocopy > filter->client_avail) - tocopy = filter->client_avail; - - memcpy(filter->next + filter->avail, filter->client_next, - tocopy); - /* Remove this data from client buffer. */ - filter->client_next += tocopy; - filter->client_avail -= tocopy; - /* add it to copy buffer. */ - filter->avail += tocopy; - } - } -} - -/* - * Move the file pointer forward. This should be called after - * __archive_read_ahead() returns data to you. Don't try to move - * ahead by more than the amount of data available according to - * __archive_read_ahead(). - */ -/* - * Mark the appropriate data as used. Note that the request here will - * often be much smaller than the size of the previous read_ahead - * request. - */ -ssize_t -__archive_read_consume(struct archive_read *a, size_t request) -{ - ssize_t r; - r = __archive_read_filter_consume(a->filter, request); - a->archive.file_position += r; - return (r); -} - -ssize_t -__archive_read_filter_consume(struct archive_read_filter * filter, - size_t request) -{ - if (filter->avail > 0) { - /* Read came from copy buffer. */ - filter->next += request; - filter->avail -= request; - } else { - /* Read came from client buffer. */ - filter->client_next += request; - filter->client_avail -= request; - } - return (request); -} - -/* - * Move the file pointer ahead by an arbitrary amount. If you're - * reading uncompressed data from a disk file, this will actually - * translate into a seek() operation. Even in cases where seek() - * isn't feasible, this at least pushes the read-and-discard loop - * down closer to the data source. - */ -int64_t -__archive_read_skip(struct archive_read *a, int64_t request) -{ - int64_t skipped = __archive_read_skip_lenient(a, request); - if (skipped == request) - return (skipped); - /* We hit EOF before we satisfied the skip request. */ - if (skipped < 0) // Map error code to 0 for error message below. - skipped = 0; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Truncated input file (needed %jd bytes, only %jd available)", - (intmax_t)request, (intmax_t)skipped); - return (ARCHIVE_FATAL); -} - -int64_t -__archive_read_skip_lenient(struct archive_read *a, int64_t request) -{ - int64_t skipped = __archive_read_filter_skip(a->filter, request); - if (skipped > 0) - a->archive.file_position += skipped; - return (skipped); -} - -int64_t -__archive_read_filter_skip(struct archive_read_filter *filter, int64_t request) -{ - int64_t bytes_skipped, total_bytes_skipped = 0; - size_t min; - - if (filter->fatal) - return (-1); - /* - * If there is data in the buffers already, use that first. - */ - if (filter->avail > 0) { - min = minimum(request, (off_t)filter->avail); - bytes_skipped = __archive_read_filter_consume(filter, min); - request -= bytes_skipped; - total_bytes_skipped += bytes_skipped; - } - if (filter->client_avail > 0) { - min = minimum(request, (int64_t)filter->client_avail); - bytes_skipped = __archive_read_filter_consume(filter, min); - request -= bytes_skipped; - total_bytes_skipped += bytes_skipped; - } - if (request == 0) - return (total_bytes_skipped); - /* - * If a client_skipper was provided, try that first. - */ -#if ARCHIVE_API_VERSION < 2 - if ((filter->skip != NULL) && (request < SSIZE_MAX)) { -#else - if (filter->skip != NULL) { -#endif - bytes_skipped = (filter->skip)(filter, request); - if (bytes_skipped < 0) { /* error */ - filter->client_total = filter->client_avail = 0; - filter->client_next = filter->client_buff = NULL; - filter->fatal = 1; - return (bytes_skipped); - } - total_bytes_skipped += bytes_skipped; - request -= bytes_skipped; - filter->client_next = filter->client_buff; - filter->client_avail = filter->client_total = 0; - } - /* - * Note that client_skipper will usually not satisfy the - * full request (due to low-level blocking concerns), - * so even if client_skipper is provided, we may still - * have to use ordinary reads to finish out the request. - */ - while (request > 0) { - ssize_t bytes_read; - (void)__archive_read_filter_ahead(filter, 1, &bytes_read); - if (bytes_read < 0) - return (bytes_read); - if (bytes_read == 0) { - return (total_bytes_skipped); - } - min = (size_t)(minimum(bytes_read, request)); - bytes_read = __archive_read_filter_consume(filter, min); - total_bytes_skipped += bytes_read; - request -= bytes_read; - } - return (total_bytes_skipped); -} diff --git a/lib/libarchive/archive_read_data_into_fd.c b/lib/libarchive/archive_read_data_into_fd.c deleted file mode 100644 index b2421bb..0000000 --- a/lib/libarchive/archive_read_data_into_fd.c +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" - -/* Maximum amount of data to write at one time. */ -#define MAX_WRITE (1024 * 1024) - -/* - * This implementation minimizes copying of data and is sparse-file aware. - */ -int -archive_read_data_into_fd(struct archive *a, int fd) -{ - int r; - const void *buff; - size_t size, bytes_to_write; - ssize_t bytes_written, total_written; - off_t offset; - off_t output_offset; - - __archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, "archive_read_data_into_fd"); - - total_written = 0; - output_offset = 0; - - while ((r = archive_read_data_block(a, &buff, &size, &offset)) == - ARCHIVE_OK) { - const char *p = buff; - if (offset > output_offset) { - output_offset = lseek(fd, - offset - output_offset, SEEK_CUR); - if (output_offset != offset) { - archive_set_error(a, errno, "Seek error"); - return (ARCHIVE_FATAL); - } - } - while (size > 0) { - bytes_to_write = size; - if (bytes_to_write > MAX_WRITE) - bytes_to_write = MAX_WRITE; - bytes_written = write(fd, p, bytes_to_write); - if (bytes_written < 0) { - archive_set_error(a, errno, "Write error"); - return (ARCHIVE_FATAL); - } - output_offset += bytes_written; - total_written += bytes_written; - p += bytes_written; - size -= bytes_written; - } - } - - if (r != ARCHIVE_EOF) - return (r); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_read_disk.3 b/lib/libarchive/archive_read_disk.3 deleted file mode 100644 index 638c158..0000000 --- a/lib/libarchive/archive_read_disk.3 +++ /dev/null @@ -1,308 +0,0 @@ -.\" Copyright (c) 2003-2009 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd March 10, 2009 -.Dt ARCHIVE_READ_DISK 3 -.Os -.Sh NAME -.Nm archive_read_disk_new , -.Nm archive_read_disk_set_symlink_logical , -.Nm archive_read_disk_set_symlink_physical , -.Nm archive_read_disk_set_symlink_hybrid , -.Nm archive_read_disk_entry_from_file , -.Nm archive_read_disk_gname , -.Nm archive_read_disk_uname , -.Nm archive_read_disk_set_uname_lookup , -.Nm archive_read_disk_set_gname_lookup , -.Nm archive_read_disk_set_standard_lookup , -.Nm archive_read_close , -.Nm archive_read_free -.Nd functions for reading objects from disk -.Sh SYNOPSIS -.In archive.h -.Ft struct archive * -.Fn archive_read_disk_new "void" -.Ft int -.Fn archive_read_disk_set_symlink_logical "struct archive *" -.Ft int -.Fn archive_read_disk_set_symlink_physical "struct archive *" -.Ft int -.Fn archive_read_disk_set_symlink_hybrid "struct archive *" -.Ft int -.Fn archive_read_disk_gname "struct archive *" "gid_t" -.Ft int -.Fn archive_read_disk_uname "struct archive *" "uid_t" -.Ft int -.Fo archive_read_disk_set_gname_lookup -.Fa "struct archive *" -.Fa "void *" -.Fa "const char *(*lookup)(void *, gid_t)" -.Fa "void (*cleanup)(void *)" -.Fc -.Ft int -.Fo archive_read_disk_set_uname_lookup -.Fa "struct archive *" -.Fa "void *" -.Fa "const char *(*lookup)(void *, uid_t)" -.Fa "void (*cleanup)(void *)" -.Fc -.Ft int -.Fn archive_read_disk_set_standard_lookup "struct archive *" -.Ft int -.Fo archive_read_disk_entry_from_file -.Fa "struct archive *" -.Fa "struct archive_entry *" -.Fa "int fd" -.Fa "const struct stat *" -.Fc -.Ft int -.Fn archive_read_close "struct archive *" -.Ft int -.Fn archive_read_free "struct archive *" -.Sh DESCRIPTION -These functions provide an API for reading information about -objects on disk. -In particular, they provide an interface for populating -.Tn struct archive_entry -objects. -.Bl -tag -width indent -.It Fn archive_read_disk_new -Allocates and initializes a -.Tn struct archive -object suitable for reading object information from disk. -.It Xo -.Fn archive_read_disk_set_symlink_logical , -.Fn archive_read_disk_set_symlink_physical , -.Fn archive_read_disk_set_symlink_hybrid -.Xc -This sets the mode used for handling symbolic links. -The -.Dq logical -mode follows all symbolic links. -The -.Dq physical -mode does not follow any symbolic links. -The -.Dq hybrid -mode currently behaves identically to the -.Dq logical -mode. -.It Xo -.Fn archive_read_disk_gname , -.Fn archive_read_disk_uname -.Xc -Returns a user or group name given a gid or uid value. -By default, these always return a NULL string. -.It Xo -.Fn archive_read_disk_set_gname_lookup , -.Fn archive_read_disk_set_uname_lookup -.Xc -These allow you to override the functions used for -user and group name lookups. -You may also provide a -.Tn void * -pointer to a private data structure and a cleanup function for -that data. -The cleanup function will be invoked when the -.Tn struct archive -object is destroyed or when new lookup functions are registered. -.It Fn archive_read_disk_set_standard_lookup -This convenience function installs a standard set of user -and group name lookup functions. -These functions use -.Xr getpwuid 3 -and -.Xr getgrgid 3 -to convert ids to names, defaulting to NULL if the names cannot -be looked up. -These functions also implement a simple memory cache to reduce -the number of calls to -.Xr getpwuid 3 -and -.Xr getgrgid 3 . -.It Fn archive_read_disk_entry_from_file -Populates a -.Tn struct archive_entry -object with information about a particular file. -The -.Tn archive_entry -object must have already been created with -.Xr archive_entry_new 3 -and at least one of the source path or path fields must already be set. -(If both are set, the source path will be used.) -.Pp -Information is read from disk using the path name from the -.Tn struct archive_entry -object. -If a file descriptor is provided, some information will be obtained using -that file descriptor, on platforms that support the appropriate -system calls. -.Pp -If a pointer to a -.Tn struct stat -is provided, information from that structure will be used instead -of reading from the disk where appropriate. -This can provide performance benefits in scenarios where -.Tn struct stat -information has already been read from the disk as a side effect -of some other operation. -(For example, directory traversal libraries often provide this information.) -.Pp -Where necessary, user and group ids are converted to user and group names -using the currently registered lookup functions above. -This affects the file ownership fields and ACL values in the -.Tn struct archive_entry -object. -.It Fn archive_read_close -This currently does nothing. -.It Fn archive_read_free -Invokes -.Fn archive_read_close -if it was not invoked manually, then releases all resources. -.El -More information about the -.Va struct archive -object and the overall design of the library can be found in the -.Xr libarchive 3 -overview. -.Sh EXAMPLE -The following illustrates basic usage of the library by -showing how to use it to copy an item on disk into an archive. -.Bd -literal -offset indent -void -file_to_archive(struct archive *a, const char *name) -{ - char buff[8192]; - size_t bytes_read; - struct archive *ard; - struct archive_entry *entry; - int fd; - - ard = archive_read_disk_new(); - archive_read_disk_set_standard_lookup(ard); - entry = archive_entry_new(); - fd = open(name, O_RDONLY); - if (fd < 0) - return; - archive_entry_copy_sourcepath(entry, name); - archive_read_disk_entry_from_file(ard, entry, fd, NULL); - archive_write_header(a, entry); - while ((bytes_read = read(fd, buff, sizeof(buff))) > 0) - archive_write_data(a, buff, bytes_read); - archive_write_finish_entry(a); - archive_read_free(ard); - archive_entry_free(entry); -} -.Ed -.Sh RETURN VALUES -Most functions return -.Cm ARCHIVE_OK -(zero) on success, or one of several negative -error codes for errors. -Specific error codes include: -.Cm ARCHIVE_RETRY -for operations that might succeed if retried, -.Cm ARCHIVE_WARN -for unusual conditions that do not prevent further operations, and -.Cm ARCHIVE_FATAL -for serious errors that make remaining operations impossible. -The -.Xr archive_errno 3 -and -.Xr archive_error_string 3 -functions can be used to retrieve an appropriate error code and a -textual error message. -(See -.Xr archive_util 3 -for details.) -.Pp -.Fn archive_read_disk_new -returns a pointer to a newly-allocated -.Tn struct archive -object or NULL if the allocation failed for any reason. -.Pp -.Fn archive_read_disk_gname -and -.Fn archive_read_disk_uname -return -.Tn const char * -pointers to the textual name or NULL if the lookup failed for any reason. -The returned pointer points to internal storage that -may be reused on the next call to either of these functions; -callers should copy the string if they need to continue accessing it. -.Pp -.Sh SEE ALSO -.Xr archive_read 3 , -.Xr archive_write 3 , -.Xr archive_write_disk 3 , -.Xr tar 1 , -.Xr libarchive 3 -.Sh HISTORY -The -.Nm libarchive -library first appeared in -.Fx 5.3 . -The -.Nm archive_read_disk -interface was added to -.Nm libarchive 2.6 -and first appeared in -.Fx 8.0 . -.Sh AUTHORS -.An -nosplit -The -.Nm libarchive -library was written by -.An Tim Kientzle Aq kientzle@FreeBSD.org . -.Sh BUGS -The -.Dq standard -user name and group name lookup functions are not the defaults because -.Xr getgrgid 3 -and -.Xr getpwuid 3 -are sometimes too large for particular applications. -The current design allows the application author to use a more -compact implementation when appropriate. -.Pp -The full list of metadata read from disk by -.Fn archive_read_disk_entry_from_file -is necessarily system-dependent. -.Pp -The -.Fn archive_read_disk_entry_from_file -function reads as much information as it can from disk. -Some method should be provided to limit this so that clients who -do not need ACLs, for instance, can avoid the extra work needed -to look up such information. -.Pp -This API should provide a set of methods for walking a directory tree. -That would make it a direct parallel of the -.Xr archive_read 3 -API. -When such methods are implemented, the -.Dq hybrid -symbolic link mode will make sense. diff --git a/lib/libarchive/archive_read_disk.c b/lib/libarchive/archive_read_disk.c deleted file mode 100644 index 3fd3133..0000000 --- a/lib/libarchive/archive_read_disk.c +++ /dev/null @@ -1,198 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#include "archive.h" -#include "archive_string.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_disk_private.h" - -static int _archive_read_free(struct archive *); -static int _archive_read_close(struct archive *); -static const char *trivial_lookup_gname(void *, gid_t gid); -static const char *trivial_lookup_uname(void *, uid_t uid); - -static struct archive_vtable * -archive_read_disk_vtable(void) -{ - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_free = _archive_read_free; - av.archive_close = _archive_read_close; - } - return (&av); -} - -const char * -archive_read_disk_gname(struct archive *_a, gid_t gid) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - if (a->lookup_gname != NULL) - return ((*a->lookup_gname)(a->lookup_gname_data, gid)); - return (NULL); -} - -const char * -archive_read_disk_uname(struct archive *_a, uid_t uid) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - if (a->lookup_uname != NULL) - return ((*a->lookup_uname)(a->lookup_uname_data, uid)); - return (NULL); -} - -int -archive_read_disk_set_gname_lookup(struct archive *_a, - void *private_data, - const char * (*lookup_gname)(void *private, gid_t gid), - void (*cleanup_gname)(void *private)) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_read_disk_set_gname_lookup"); - - if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL) - (a->cleanup_gname)(a->lookup_gname_data); - - a->lookup_gname = lookup_gname; - a->cleanup_gname = cleanup_gname; - a->lookup_gname_data = private_data; - return (ARCHIVE_OK); -} - -int -archive_read_disk_set_uname_lookup(struct archive *_a, - void *private_data, - const char * (*lookup_uname)(void *private, uid_t uid), - void (*cleanup_uname)(void *private)) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_read_disk_set_uname_lookup"); - - if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL) - (a->cleanup_uname)(a->lookup_uname_data); - - a->lookup_uname = lookup_uname; - a->cleanup_uname = cleanup_uname; - a->lookup_uname_data = private_data; - return (ARCHIVE_OK); -} - -/* - * Create a new archive_read_disk object and initialize it with global state. - */ -struct archive * -archive_read_disk_new(void) -{ - struct archive_read_disk *a; - - a = (struct archive_read_disk *)malloc(sizeof(*a)); - if (a == NULL) - return (NULL); - memset(a, 0, sizeof(*a)); - a->archive.magic = ARCHIVE_READ_DISK_MAGIC; - /* We're ready to write a header immediately. */ - a->archive.state = ARCHIVE_STATE_HEADER; - a->archive.vtable = archive_read_disk_vtable(); - a->lookup_uname = trivial_lookup_uname; - a->lookup_gname = trivial_lookup_gname; - return (&a->archive); -} - -static int -_archive_read_free(struct archive *_a) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - - if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL) - (a->cleanup_gname)(a->lookup_gname_data); - if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL) - (a->cleanup_uname)(a->lookup_uname_data); - archive_string_free(&a->archive.error_string); - free(a); - return (ARCHIVE_OK); -} - -static int -_archive_read_close(struct archive *_a) -{ - (void)_a; /* UNUSED */ - return (ARCHIVE_OK); -} - -int -archive_read_disk_set_symlink_logical(struct archive *_a) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - a->symlink_mode = 'L'; - a->follow_symlinks = 1; - return (ARCHIVE_OK); -} - -int -archive_read_disk_set_symlink_physical(struct archive *_a) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - a->symlink_mode = 'P'; - a->follow_symlinks = 0; - return (ARCHIVE_OK); -} - -int -archive_read_disk_set_symlink_hybrid(struct archive *_a) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - a->symlink_mode = 'H'; - a->follow_symlinks = 1; /* Follow symlinks initially. */ - return (ARCHIVE_OK); -} - -/* - * Trivial implementations of gname/uname lookup functions. - * These are normally overridden by the client, but these stub - * versions ensure that we always have something that works. - */ -static const char * -trivial_lookup_gname(void *private_data, gid_t gid) -{ - (void)private_data; /* UNUSED */ - (void)gid; /* UNUSED */ - return (NULL); -} - -static const char * -trivial_lookup_uname(void *private_data, uid_t uid) -{ - (void)private_data; /* UNUSED */ - (void)uid; /* UNUSED */ - return (NULL); -} diff --git a/lib/libarchive/archive_read_disk_entry_from_file.c b/lib/libarchive/archive_read_disk_entry_from_file.c deleted file mode 100644 index 957e4ee..0000000 --- a/lib/libarchive/archive_read_disk_entry_from_file.c +++ /dev/null @@ -1,570 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -/* Mac OSX requires sys/types.h before sys/acl.h. */ -#include -#endif -#ifdef HAVE_SYS_ACL_H -#include -#endif -#ifdef HAVE_SYS_EXTATTR_H -#include -#endif -#ifdef HAVE_SYS_PARAM_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_SYS_XATTR_H -#include -#endif -#ifdef HAVE_ACL_LIBACL_H -#include -#endif -#ifdef HAVE_ATTR_XATTR_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_LIMITS_H -#include -#endif -#ifdef HAVE_WINDOWS_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_disk_private.h" - -/* - * Linux and FreeBSD plug this obvious hole in POSIX.1e in - * different ways. - */ -#if HAVE_ACL_GET_PERM -#define ACL_GET_PERM acl_get_perm -#elif HAVE_ACL_GET_PERM_NP -#define ACL_GET_PERM acl_get_perm_np -#endif - -static int setup_acls_posix1e(struct archive_read_disk *, - struct archive_entry *, int fd); -static int setup_xattrs(struct archive_read_disk *, - struct archive_entry *, int fd); - -int -archive_read_disk_entry_from_file(struct archive *_a, - struct archive_entry *entry, - int fd, const struct stat *st) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - const char *path, *name; - struct stat s; - int initial_fd = fd; - int r, r1; - - archive_clear_error(_a); - path = archive_entry_sourcepath(entry); - if (path == NULL) - path = archive_entry_pathname(entry); - -#ifdef EXT2_IOC_GETFLAGS - /* Linux requires an extra ioctl to pull the flags. Although - * this is an extra step, it has a nice side-effect: We get an - * open file descriptor which we can use in the subsequent lookups. */ - if ((S_ISREG(st->st_mode) || S_ISDIR(st->st_mode))) { - if (fd < 0) - fd = open(pathname, O_RDONLY | O_NONBLOCK | O_BINARY); - if (fd >= 0) { - unsigned long stflags; - int r = ioctl(fd, EXT2_IOC_GETFLAGS, &stflags); - if (r == 0 && stflags != 0) - archive_entry_set_fflags(entry, stflags, 0); - } - } -#endif - - if (st == NULL) { - /* TODO: On Windows, use GetFileInfoByHandle() here. - * Using Windows stat() call is badly broken, but - * even the stat() wrapper has problems because - * 'struct stat' is broken on Windows. - */ -#if HAVE_FSTAT - if (fd >= 0) { - if (fstat(fd, &s) != 0) { - archive_set_error(&a->archive, errno, - "Can't fstat"); - return (ARCHIVE_FAILED); - } - } else -#endif -#if HAVE_LSTAT - if (!a->follow_symlinks) { - if (lstat(path, &s) != 0) { - archive_set_error(&a->archive, errno, - "Can't lstat %s", path); - return (ARCHIVE_FAILED); - } - } else -#endif - if (stat(path, &s) != 0) { - archive_set_error(&a->archive, errno, - "Can't stat %s", path); - return (ARCHIVE_FAILED); - } - st = &s; - } - archive_entry_copy_stat(entry, st); - - /* Lookup uname/gname */ - name = archive_read_disk_uname(_a, archive_entry_uid(entry)); - if (name != NULL) - archive_entry_copy_uname(entry, name); - name = archive_read_disk_gname(_a, archive_entry_gid(entry)); - if (name != NULL) - archive_entry_copy_gname(entry, name); - -#ifdef HAVE_STRUCT_STAT_ST_FLAGS - /* On FreeBSD, we get flags for free with the stat. */ - /* TODO: Does this belong in copy_stat()? */ - if (st->st_flags != 0) - archive_entry_set_fflags(entry, st->st_flags, 0); -#endif - -#ifdef HAVE_READLINK - if (S_ISLNK(st->st_mode)) { - char linkbuffer[PATH_MAX + 1]; - int lnklen = readlink(path, linkbuffer, PATH_MAX); - if (lnklen < 0) { - archive_set_error(&a->archive, errno, - "Couldn't read link data"); - return (ARCHIVE_FAILED); - } - linkbuffer[lnklen] = 0; - archive_entry_set_symlink(entry, linkbuffer); - } -#endif - - r = setup_acls_posix1e(a, entry, fd); - r1 = setup_xattrs(a, entry, fd); - if (r1 < r) - r = r1; - /* If we opened the file earlier in this function, close it. */ - if (initial_fd != fd) - close(fd); - return (r); -} - -#ifdef HAVE_POSIX_ACL -static void setup_acl_posix1e(struct archive_read_disk *a, - struct archive_entry *entry, acl_t acl, int archive_entry_acl_type); - -static int -setup_acls_posix1e(struct archive_read_disk *a, - struct archive_entry *entry, int fd) -{ - const char *accpath; - acl_t acl; - - accpath = archive_entry_sourcepath(entry); - if (accpath == NULL) - accpath = archive_entry_pathname(entry); - - archive_entry_acl_clear(entry); - - /* Retrieve access ACL from file. */ - if (fd >= 0) - acl = acl_get_fd(fd); -#if HAVE_ACL_GET_LINK_NP - else if (!a->follow_symlinks) - acl = acl_get_link_np(accpath, ACL_TYPE_ACCESS); -#else - else if ((!a->follow_symlinks) - && (archive_entry_filetype(entry) == AE_IFLNK)) - /* We can't get the ACL of a symlink, so we assume it can't - have one. */ - acl = NULL; -#endif - else - acl = acl_get_file(accpath, ACL_TYPE_ACCESS); - if (acl != NULL) { - setup_acl_posix1e(a, entry, acl, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - acl_free(acl); - } - - /* Only directories can have default ACLs. */ - if (S_ISDIR(archive_entry_mode(entry))) { - acl = acl_get_file(accpath, ACL_TYPE_DEFAULT); - if (acl != NULL) { - setup_acl_posix1e(a, entry, acl, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT); - acl_free(acl); - } - } - return (ARCHIVE_OK); -} - -/* - * Translate POSIX.1e ACL into libarchive internal structure. - */ -static void -setup_acl_posix1e(struct archive_read_disk *a, - struct archive_entry *entry, acl_t acl, int archive_entry_acl_type) -{ - acl_tag_t acl_tag; - acl_entry_t acl_entry; - acl_permset_t acl_permset; - int s, ae_id, ae_tag, ae_perm; - const char *ae_name; - - s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry); - while (s == 1) { - ae_id = -1; - ae_name = NULL; - - acl_get_tag_type(acl_entry, &acl_tag); - if (acl_tag == ACL_USER) { - ae_id = (int)*(uid_t *)acl_get_qualifier(acl_entry); - ae_name = archive_read_disk_uname(&a->archive, ae_id); - ae_tag = ARCHIVE_ENTRY_ACL_USER; - } else if (acl_tag == ACL_GROUP) { - ae_id = (int)*(gid_t *)acl_get_qualifier(acl_entry); - ae_name = archive_read_disk_gname(&a->archive, ae_id); - ae_tag = ARCHIVE_ENTRY_ACL_GROUP; - } else if (acl_tag == ACL_MASK) { - ae_tag = ARCHIVE_ENTRY_ACL_MASK; - } else if (acl_tag == ACL_USER_OBJ) { - ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; - } else if (acl_tag == ACL_GROUP_OBJ) { - ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - } else if (acl_tag == ACL_OTHER) { - ae_tag = ARCHIVE_ENTRY_ACL_OTHER; - } else { - /* Skip types that libarchive can't support. */ - continue; - } - - acl_get_permset(acl_entry, &acl_permset); - ae_perm = 0; - /* - * acl_get_perm() is spelled differently on different - * platforms; see above. - */ - if (ACL_GET_PERM(acl_permset, ACL_EXECUTE)) - ae_perm |= ARCHIVE_ENTRY_ACL_EXECUTE; - if (ACL_GET_PERM(acl_permset, ACL_READ)) - ae_perm |= ARCHIVE_ENTRY_ACL_READ; - if (ACL_GET_PERM(acl_permset, ACL_WRITE)) - ae_perm |= ARCHIVE_ENTRY_ACL_WRITE; - - archive_entry_acl_add_entry(entry, - archive_entry_acl_type, ae_perm, ae_tag, - ae_id, ae_name); - - s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); - } -} -#else -static int -setup_acls_posix1e(struct archive_read_disk *a, - struct archive_entry *entry, int fd) -{ - (void)a; /* UNUSED */ - (void)entry; /* UNUSED */ - (void)fd; /* UNUSED */ - return (ARCHIVE_OK); -} -#endif - -#if HAVE_LISTXATTR && HAVE_LLISTXATTR && HAVE_GETXATTR && HAVE_LGETXATTR - -/* - * Linux extended attribute support. - * - * TODO: By using a stack-allocated buffer for the first - * call to getxattr(), we might be able to avoid the second - * call entirely. We only need the second call if the - * stack-allocated buffer is too small. But a modest buffer - * of 1024 bytes or so will often be big enough. Same applies - * to listxattr(). - */ - - -static int -setup_xattr(struct archive_read_disk *a, - struct archive_entry *entry, const char *name, int fd) -{ - ssize_t size; - void *value = NULL; - const char *accpath; - - (void)fd; /* UNUSED */ - - accpath = archive_entry_sourcepath(entry); - if (accpath == NULL) - accpath = archive_entry_pathname(entry); - - if (!a->follow_symlinks) - size = lgetxattr(accpath, name, NULL, 0); - else - size = getxattr(accpath, name, NULL, 0); - - if (size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't query extended attribute"); - return (ARCHIVE_WARN); - } - - if (size > 0 && (value = malloc(size)) == NULL) { - archive_set_error(&a->archive, errno, "Out of memory"); - return (ARCHIVE_FATAL); - } - - if (!a->follow_symlinks) - size = lgetxattr(accpath, name, value, size); - else - size = getxattr(accpath, name, value, size); - - if (size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't read extended attribute"); - return (ARCHIVE_WARN); - } - - archive_entry_xattr_add_entry(entry, name, value, size); - - free(value); - return (ARCHIVE_OK); -} - -static int -setup_xattrs(struct archive_read_disk *a, - struct archive_entry *entry, int fd) -{ - char *list, *p; - const char *path; - ssize_t list_size; - - - path = archive_entry_sourcepath(entry); - if (path == NULL) - path = archive_entry_pathname(entry); - - if (!a->follow_symlinks) - list_size = llistxattr(path, NULL, 0); - else - list_size = listxattr(path, NULL, 0); - - if (list_size == -1) { - if (errno == ENOTSUP) - return (ARCHIVE_OK); - archive_set_error(&a->archive, errno, - "Couldn't list extended attributes"); - return (ARCHIVE_WARN); - } - - if (list_size == 0) - return (ARCHIVE_OK); - - if ((list = malloc(list_size)) == NULL) { - archive_set_error(&a->archive, errno, "Out of memory"); - return (ARCHIVE_FATAL); - } - - if (!a->follow_symlinks) - list_size = llistxattr(path, list, list_size); - else - list_size = listxattr(path, list, list_size); - - if (list_size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't retrieve extended attributes"); - free(list); - return (ARCHIVE_WARN); - } - - for (p = list; (p - list) < list_size; p += strlen(p) + 1) { - if (strncmp(p, "system.", 7) == 0 || - strncmp(p, "xfsroot.", 8) == 0) - continue; - setup_xattr(a, entry, p, fd); - } - - free(list); - return (ARCHIVE_OK); -} - -#elif HAVE_EXTATTR_GET_FILE && HAVE_EXTATTR_LIST_FILE && \ - HAVE_DECL_EXTATTR_NAMESPACE_USER - -/* - * FreeBSD extattr interface. - */ - -/* TODO: Implement this. Follow the Linux model above, but - * with FreeBSD-specific system calls, of course. Be careful - * to not include the system extattrs that hold ACLs; we handle - * those separately. - */ -static int -setup_xattr(struct archive_read_disk *a, struct archive_entry *entry, - int namespace, const char *name, const char *fullname, int fd); - -static int -setup_xattr(struct archive_read_disk *a, struct archive_entry *entry, - int namespace, const char *name, const char *fullname, int fd) -{ - ssize_t size; - void *value = NULL; - const char *accpath; - - (void)fd; /* UNUSED */ - - accpath = archive_entry_sourcepath(entry); - if (accpath == NULL) - accpath = archive_entry_pathname(entry); - - if (!a->follow_symlinks) - size = extattr_get_link(accpath, namespace, name, NULL, 0); - else - size = extattr_get_file(accpath, namespace, name, NULL, 0); - - if (size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't query extended attribute"); - return (ARCHIVE_WARN); - } - - if (size > 0 && (value = malloc(size)) == NULL) { - archive_set_error(&a->archive, errno, "Out of memory"); - return (ARCHIVE_FATAL); - } - - if (!a->follow_symlinks) - size = extattr_get_link(accpath, namespace, name, value, size); - else - size = extattr_get_file(accpath, namespace, name, value, size); - - if (size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't read extended attribute"); - return (ARCHIVE_WARN); - } - - archive_entry_xattr_add_entry(entry, fullname, value, size); - - free(value); - return (ARCHIVE_OK); -} - -static int -setup_xattrs(struct archive_read_disk *a, - struct archive_entry *entry, int fd) -{ - char buff[512]; - char *list, *p; - ssize_t list_size; - const char *path; - int namespace = EXTATTR_NAMESPACE_USER; - - path = archive_entry_sourcepath(entry); - if (path == NULL) - path = archive_entry_pathname(entry); - - if (!a->follow_symlinks) - list_size = extattr_list_link(path, namespace, NULL, 0); - else - list_size = extattr_list_file(path, namespace, NULL, 0); - - if (list_size == -1 && errno == EOPNOTSUPP) - return (ARCHIVE_OK); - if (list_size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't list extended attributes"); - return (ARCHIVE_WARN); - } - - if (list_size == 0) - return (ARCHIVE_OK); - - if ((list = malloc(list_size)) == NULL) { - archive_set_error(&a->archive, errno, "Out of memory"); - return (ARCHIVE_FATAL); - } - - if (!a->follow_symlinks) - list_size = extattr_list_link(path, namespace, list, list_size); - else - list_size = extattr_list_file(path, namespace, list, list_size); - - if (list_size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't retrieve extended attributes"); - free(list); - return (ARCHIVE_WARN); - } - - p = list; - while ((p - list) < list_size) { - size_t len = 255 & (int)*p; - char *name; - - strcpy(buff, "user."); - name = buff + strlen(buff); - memcpy(name, p + 1, len); - name[len] = '\0'; - setup_xattr(a, entry, namespace, name, buff, fd); - p += 1 + len; - } - - free(list); - return (ARCHIVE_OK); -} - -#else - -/* - * Generic (stub) extended attribute support. - */ -static int -setup_xattrs(struct archive_read_disk *a, - struct archive_entry *entry, int fd) -{ - (void)a; /* UNUSED */ - (void)entry; /* UNUSED */ - (void)fd; /* UNUSED */ - return (ARCHIVE_OK); -} - -#endif diff --git a/lib/libarchive/archive_read_disk_private.h b/lib/libarchive/archive_read_disk_private.h deleted file mode 100644 index 3e8884b..0000000 --- a/lib/libarchive/archive_read_disk_private.h +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifndef ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED -#define ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED - -struct archive_read_disk { - struct archive archive; - - /* - * Symlink mode is one of 'L'ogical, 'P'hysical, or 'H'ybrid, - * following an old BSD convention. 'L' follows all symlinks, - * 'P' follows none, 'H' follows symlinks only for the first - * item. - */ - char symlink_mode; - - /* - * Since symlink interaction changes, we need to track whether - * we're following symlinks for the current item. 'L' mode above - * sets this true, 'P' sets it false, 'H' changes it as we traverse. - */ - char follow_symlinks; /* Either 'L' or 'P'. */ - - const char * (*lookup_gname)(void *private, gid_t gid); - void (*cleanup_gname)(void *private); - void *lookup_gname_data; - const char * (*lookup_uname)(void *private, gid_t gid); - void (*cleanup_uname)(void *private); - void *lookup_uname_data; -}; - -#endif diff --git a/lib/libarchive/archive_read_disk_set_standard_lookup.c b/lib/libarchive/archive_read_disk_set_standard_lookup.c deleted file mode 100644 index 45f8b43..0000000 --- a/lib/libarchive/archive_read_disk_set_standard_lookup.c +++ /dev/null @@ -1,303 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_GRP_H -#include -#endif -#ifdef HAVE_PWD_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" - -#if defined(_WIN32) && !defined(__CYGWIN__) -int -archive_read_disk_set_standard_lookup(struct archive *a) -{ - archive_set_error(a, -1, "Standard lookups not available on Windows"); - return (ARCHIVE_FATAL); -} -#else /* ! (_WIN32 && !__CYGWIN__) */ -#define name_cache_size 127 - -static const char * const NO_NAME = "(noname)"; - -struct name_cache { - struct archive *archive; - char *buff; - size_t buff_size; - int probes; - int hits; - size_t size; - struct { - id_t id; - const char *name; - } cache[name_cache_size]; -}; - -static const char * lookup_gname(void *, gid_t); -static const char * lookup_uname(void *, uid_t); -static void cleanup(void *); -static const char * lookup_gname_helper(struct name_cache *, id_t gid); -static const char * lookup_uname_helper(struct name_cache *, id_t uid); - -/* - * Installs functions that use getpwuid()/getgrgid()---along with - * a simple cache to accelerate such lookups---into the archive_read_disk - * object. This is in a separate file because getpwuid()/getgrgid() - * can pull in a LOT of library code (including NIS/LDAP functions, which - * pull in DNS resolveers, etc). This can easily top 500kB, which makes - * it inappropriate for some space-constrained applications. - * - * Applications that are size-sensitive may want to just use the - * real default functions (defined in archive_read_disk.c) that just - * use the uid/gid without the lookup. Or define your own custom functions - * if you prefer. - */ -int -archive_read_disk_set_standard_lookup(struct archive *a) -{ - struct name_cache *ucache = malloc(sizeof(struct name_cache)); - struct name_cache *gcache = malloc(sizeof(struct name_cache)); - - if (ucache == NULL || gcache == NULL) { - archive_set_error(a, ENOMEM, - "Can't allocate uname/gname lookup cache"); - free(ucache); - free(gcache); - return (ARCHIVE_FATAL); - } - - memset(ucache, 0, sizeof(*ucache)); - ucache->archive = a; - ucache->size = name_cache_size; - memset(gcache, 0, sizeof(*gcache)); - gcache->archive = a; - gcache->size = name_cache_size; - - archive_read_disk_set_gname_lookup(a, gcache, lookup_gname, cleanup); - archive_read_disk_set_uname_lookup(a, ucache, lookup_uname, cleanup); - - return (ARCHIVE_OK); -} - -static void -cleanup(void *data) -{ - struct name_cache *cache = (struct name_cache *)data; - size_t i; - - if (cache != NULL) { - for (i = 0; i < cache->size; i++) { - if (cache->cache[i].name != NULL && - cache->cache[i].name != NO_NAME) - free((void *)(uintptr_t)cache->cache[i].name); - } - free(cache->buff); - free(cache); - } -} - -/* - * Lookup uid/gid from uname/gname, return NULL if no match. - */ -static const char * -lookup_name(struct name_cache *cache, - const char * (*lookup_fn)(struct name_cache *, id_t), id_t id) -{ - const char *name; - int slot; - - - cache->probes++; - - slot = id % cache->size; - if (cache->cache[slot].name != NULL) { - if (cache->cache[slot].id == id) { - cache->hits++; - if (cache->cache[slot].name == NO_NAME) - return (NULL); - return (cache->cache[slot].name); - } - if (cache->cache[slot].name != NO_NAME) - free((void *)(uintptr_t)cache->cache[slot].name); - cache->cache[slot].name = NULL; - } - - name = (lookup_fn)(cache, id); - if (name == NULL) { - /* Cache and return the negative response. */ - cache->cache[slot].name = NO_NAME; - cache->cache[slot].id = id; - return (NULL); - } - - cache->cache[slot].name = name; - cache->cache[slot].id = id; - return (cache->cache[slot].name); -} - -static const char * -lookup_uname(void *data, uid_t uid) -{ - struct name_cache *uname_cache = (struct name_cache *)data; - return (lookup_name(uname_cache, - &lookup_uname_helper, (id_t)uid)); -} - -#if HAVE_GETPWUID_R -static const char * -lookup_uname_helper(struct name_cache *cache, id_t id) -{ - struct passwd pwent, *result; - int r; - - if (cache->buff_size == 0) { - cache->buff_size = 256; - cache->buff = malloc(cache->buff_size); - } - if (cache->buff == NULL) - return (NULL); - for (;;) { - result = &pwent; /* Old getpwuid_r ignores last arg. */ - r = getpwuid_r((uid_t)id, &pwent, - cache->buff, cache->buff_size, &result); - if (r == 0) - break; - if (r != ERANGE) - break; - /* ERANGE means our buffer was too small, but POSIX - * doesn't tell us how big the buffer should be, so - * we just double it and try again. Because the buffer - * is kept around in the cache object, we shouldn't - * have to do this very often. */ - cache->buff_size *= 2; - cache->buff = realloc(cache->buff, cache->buff_size); - if (cache->buff == NULL) - break; - } - if (r != 0) { - archive_set_error(cache->archive, errno, - "Can't lookup user for id %d", (int)id); - return (NULL); - } - if (result == NULL) - return (NULL); - - return strdup(result->pw_name); -} -#else -static const char * -lookup_uname_helper(struct name_cache *cache, id_t id) -{ - struct passwd *result; - - result = getpwuid((uid_t)id); - - if (result == NULL) - return (NULL); - - return strdup(result->pw_name); -} -#endif - -static const char * -lookup_gname(void *data, gid_t gid) -{ - struct name_cache *gname_cache = (struct name_cache *)data; - return (lookup_name(gname_cache, - &lookup_gname_helper, (id_t)gid)); -} - -#if HAVE_GETGRGID_R -static const char * -lookup_gname_helper(struct name_cache *cache, id_t id) -{ - struct group grent, *result; - int r; - - if (cache->buff_size == 0) { - cache->buff_size = 256; - cache->buff = malloc(cache->buff_size); - } - if (cache->buff == NULL) - return (NULL); - for (;;) { - result = &grent; /* Old getgrgid_r ignores last arg. */ - r = getgrgid_r((gid_t)id, &grent, - cache->buff, cache->buff_size, &result); - if (r == 0) - break; - if (r != ERANGE) - break; - /* ERANGE means our buffer was too small, but POSIX - * doesn't tell us how big the buffer should be, so - * we just double it and try again. */ - cache->buff_size *= 2; - cache->buff = realloc(cache->buff, cache->buff_size); - if (cache->buff == NULL) - break; - } - if (r != 0) { - archive_set_error(cache->archive, errno, - "Can't lookup group for id %d", (int)id); - return (NULL); - } - if (result == NULL) - return (NULL); - - return strdup(result->gr_name); -} -#else -static const char * -lookup_gname_helper(struct name_cache *cache, id_t id) -{ - struct group *result; - - result = getgrgid((gid_t)id); - - if (result == NULL) - return (NULL); - - return strdup(result->gr_name); -} -#endif - -#endif /* ! (_WIN32 && !__CYGWIN__) */ diff --git a/lib/libarchive/archive_read_extract.c b/lib/libarchive/archive_read_extract.c deleted file mode 100644 index 5c69f59..0000000 --- a/lib/libarchive/archive_read_extract.c +++ /dev/null @@ -1,180 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" -#include "archive_write_disk_private.h" - -struct extract { - struct archive *ad; /* archive_write_disk object */ - - /* Progress function invoked during extract. */ - void (*extract_progress)(void *); - void *extract_progress_user_data; -}; - -static int archive_read_extract_cleanup(struct archive_read *); -static int copy_data(struct archive *ar, struct archive *aw); -static struct extract *get_extract(struct archive_read *); - -static struct extract * -get_extract(struct archive_read *a) -{ - /* If we haven't initialized, do it now. */ - /* This also sets up a lot of global state. */ - if (a->extract == NULL) { - a->extract = (struct extract *)malloc(sizeof(*a->extract)); - if (a->extract == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't extract"); - return (NULL); - } - memset(a->extract, 0, sizeof(*a->extract)); - a->extract->ad = archive_write_disk_new(); - if (a->extract->ad == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't extract"); - return (NULL); - } - archive_write_disk_set_standard_lookup(a->extract->ad); - a->cleanup_archive_extract = archive_read_extract_cleanup; - } - return (a->extract); -} - -int -archive_read_extract(struct archive *_a, struct archive_entry *entry, int flags) -{ - struct extract *extract; - - extract = get_extract((struct archive_read *)_a); - if (extract == NULL) - return (ARCHIVE_FATAL); - archive_write_disk_set_options(extract->ad, flags); - return (archive_read_extract2(_a, entry, extract->ad)); -} - -int -archive_read_extract2(struct archive *_a, struct archive_entry *entry, - struct archive *ad) -{ - struct archive_read *a = (struct archive_read *)_a; - int r, r2; - - /* Set up for this particular entry. */ - archive_write_disk_set_skip_file(ad, - a->skip_file_dev, a->skip_file_ino); - r = archive_write_header(ad, entry); - if (r < ARCHIVE_WARN) - r = ARCHIVE_WARN; - if (r != ARCHIVE_OK) - /* If _write_header failed, copy the error. */ - archive_copy_error(&a->archive, ad); - else if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) > 0) - /* Otherwise, pour data into the entry. */ - r = copy_data(_a, ad); - r2 = archive_write_finish_entry(ad); - if (r2 < ARCHIVE_WARN) - r2 = ARCHIVE_WARN; - /* Use the first message. */ - if (r2 != ARCHIVE_OK && r == ARCHIVE_OK) - archive_copy_error(&a->archive, ad); - /* Use the worst error return. */ - if (r2 < r) - r = r2; - return (r); -} - -void -archive_read_extract_set_progress_callback(struct archive *_a, - void (*progress_func)(void *), void *user_data) -{ - struct archive_read *a = (struct archive_read *)_a; - struct extract *extract = get_extract(a); - if (extract != NULL) { - extract->extract_progress = progress_func; - extract->extract_progress_user_data = user_data; - } -} - -static int -copy_data(struct archive *ar, struct archive *aw) -{ - off_t offset; - const void *buff; - struct extract *extract; - size_t size; - int r; - - extract = get_extract((struct archive_read *)ar); - for (;;) { - r = archive_read_data_block(ar, &buff, &size, &offset); - if (r == ARCHIVE_EOF) - return (ARCHIVE_OK); - if (r != ARCHIVE_OK) - return (r); - r = archive_write_data_block(aw, buff, size, offset); - if (r < ARCHIVE_WARN) - r = ARCHIVE_WARN; - if (r != ARCHIVE_OK) { - archive_set_error(ar, archive_errno(aw), - "%s", archive_error_string(aw)); - return (r); - } - if (extract->extract_progress) - (extract->extract_progress) - (extract->extract_progress_user_data); - } -} - -/* - * Cleanup function for archive_extract. - */ -static int -archive_read_extract_cleanup(struct archive_read *a) -{ - int ret = ARCHIVE_OK; - - ret = archive_write_free(a->extract->ad); - free(a->extract); - a->extract = NULL; - return (ret); -} diff --git a/lib/libarchive/archive_read_open_fd.c b/lib/libarchive/archive_read_open_fd.c deleted file mode 100644 index 90e764a..0000000 --- a/lib/libarchive/archive_read_open_fd.c +++ /dev/null @@ -1,190 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_IO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" - -struct read_fd_data { - int fd; - size_t block_size; - char can_skip; - void *buffer; -}; - -static int file_close(struct archive *, void *); -static ssize_t file_read(struct archive *, void *, const void **buff); -#if ARCHIVE_API_VERSION < 2 -static ssize_t file_skip(struct archive *, void *, size_t request); -#else -static off_t file_skip(struct archive *, void *, off_t request); -#endif - -int -archive_read_open_fd(struct archive *a, int fd, size_t block_size) -{ - struct stat st; - struct read_fd_data *mine; - void *b; - - archive_clear_error(a); - if (fstat(fd, &st) != 0) { - archive_set_error(a, errno, "Can't stat fd %d", fd); - return (ARCHIVE_FATAL); - } - - mine = (struct read_fd_data *)malloc(sizeof(*mine)); - b = malloc(block_size); - if (mine == NULL || b == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - free(mine); - free(b); - return (ARCHIVE_FATAL); - } - mine->block_size = block_size; - mine->buffer = b; - mine->fd = fd; - /* - * Skip support is a performance optimization for anything - * that supports lseek(). On FreeBSD, only regular files and - * raw disk devices support lseek() and there's no portable - * way to determine if a device is a raw disk device, so we - * only enable this optimization for regular files. - */ - if (S_ISREG(st.st_mode)) { - archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); - mine->can_skip = 1; - } else - mine->can_skip = 0; -#if defined(__CYGWIN__) || defined(_WIN32) - setmode(mine->fd, O_BINARY); -#endif - - return (archive_read_open2(a, mine, - NULL, file_read, file_skip, file_close)); -} - -static ssize_t -file_read(struct archive *a, void *client_data, const void **buff) -{ - struct read_fd_data *mine = (struct read_fd_data *)client_data; - ssize_t bytes_read; - - *buff = mine->buffer; - for (;;) { - bytes_read = read(mine->fd, mine->buffer, mine->block_size); - if (bytes_read < 0) { - if (errno == EINTR) - continue; - archive_set_error(a, errno, "Error reading fd %d", mine->fd); - } - return (bytes_read); - } -} - -#if ARCHIVE_API_VERSION < 2 -static ssize_t -file_skip(struct archive *a, void *client_data, size_t request) -#else -static off_t -file_skip(struct archive *a, void *client_data, off_t request) -#endif -{ - struct read_fd_data *mine = (struct read_fd_data *)client_data; - off_t old_offset, new_offset; - - if (!mine->can_skip) - return (0); - - /* Reduce request to the next smallest multiple of block_size */ - request = (request / mine->block_size) * mine->block_size; - if (request == 0) - return (0); - - /* - * Hurray for lazy evaluation: if the first lseek fails, the second - * one will not be executed. - */ - if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) < 0) || - ((new_offset = lseek(mine->fd, request, SEEK_CUR)) < 0)) - { - /* If seek failed once, it will probably fail again. */ - mine->can_skip = 0; - - if (errno == ESPIPE) - { - /* - * Failure to lseek() can be caused by the file - * descriptor pointing to a pipe, socket or FIFO. - * Return 0 here, so the compression layer will use - * read()s instead to advance the file descriptor. - * It's slower of course, but works as well. - */ - return (0); - } - /* - * There's been an error other than ESPIPE. This is most - * likely caused by a programmer error (too large request) - * or a corrupted archive file. - */ - archive_set_error(a, errno, "Error seeking"); - return (-1); - } - return (new_offset - old_offset); -} - -static int -file_close(struct archive *a, void *client_data) -{ - struct read_fd_data *mine = (struct read_fd_data *)client_data; - - (void)a; /* UNUSED */ - free(mine->buffer); - free(mine); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_read_open_file.c b/lib/libarchive/archive_read_open_file.c deleted file mode 100644 index 1575f94..0000000 --- a/lib/libarchive/archive_read_open_file.c +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_IO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" - -struct read_FILE_data { - FILE *f; - size_t block_size; - void *buffer; - char can_skip; -}; - -static int file_close(struct archive *, void *); -static ssize_t file_read(struct archive *, void *, const void **buff); -#if ARCHIVE_API_VERSION < 2 -static ssize_t file_skip(struct archive *, void *, size_t request); -#else -static off_t file_skip(struct archive *, void *, off_t request); -#endif - -int -archive_read_open_FILE(struct archive *a, FILE *f) -{ - struct stat st; - struct read_FILE_data *mine; - size_t block_size = 128 * 1024; - void *b; - - archive_clear_error(a); - mine = (struct read_FILE_data *)malloc(sizeof(*mine)); - b = malloc(block_size); - if (mine == NULL || b == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - free(mine); - free(b); - return (ARCHIVE_FATAL); - } - mine->block_size = block_size; - mine->buffer = b; - mine->f = f; - /* - * If we can't fstat() the file, it may just be that it's not - * a file. (FILE * objects can wrap many kinds of I/O - * streams, some of which don't support fileno()).) - */ - if (fstat(fileno(mine->f), &st) == 0 && S_ISREG(st.st_mode)) { - archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); - /* Enable the seek optimization only for regular files. */ - mine->can_skip = 1; - } else - mine->can_skip = 0; - -#if defined(__CYGWIN__) || defined(_WIN32) - setmode(fileno(mine->f), O_BINARY); -#endif - - return (archive_read_open2(a, mine, NULL, file_read, - file_skip, file_close)); -} - -static ssize_t -file_read(struct archive *a, void *client_data, const void **buff) -{ - struct read_FILE_data *mine = (struct read_FILE_data *)client_data; - ssize_t bytes_read; - - *buff = mine->buffer; - bytes_read = fread(mine->buffer, 1, mine->block_size, mine->f); - if (bytes_read < 0) { - archive_set_error(a, errno, "Error reading file"); - } - return (bytes_read); -} - -#if ARCHIVE_API_VERSION < 2 -static ssize_t -file_skip(struct archive *a, void *client_data, size_t request) -#else -static off_t -file_skip(struct archive *a, void *client_data, off_t request) -#endif -{ - struct read_FILE_data *mine = (struct read_FILE_data *)client_data; - - (void)a; /* UNUSED */ - - /* - * If we can't skip, return 0 as the amount we did step and - * the caller will work around by reading and discarding. - */ - if (!mine->can_skip) - return (0); - if (request == 0) - return (0); - -#if HAVE_FSEEKO - if (fseeko(mine->f, request, SEEK_CUR) != 0) -#else - if (fseek(mine->f, request, SEEK_CUR) != 0) -#endif - { - mine->can_skip = 0; - return (0); - } - return (request); -} - -static int -file_close(struct archive *a, void *client_data) -{ - struct read_FILE_data *mine = (struct read_FILE_data *)client_data; - - (void)a; /* UNUSED */ - if (mine->buffer != NULL) - free(mine->buffer); - free(mine); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_read_open_filename.c b/lib/libarchive/archive_read_open_filename.c deleted file mode 100644 index 3d6c5dc..0000000 --- a/lib/libarchive/archive_read_open_filename.c +++ /dev/null @@ -1,272 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_IO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -struct read_file_data { - int fd; - size_t block_size; - void *buffer; - mode_t st_mode; /* Mode bits for opened file. */ - char can_skip; /* This file supports skipping. */ - char filename[1]; /* Must be last! */ -}; - -static int file_close(struct archive *, void *); -static ssize_t file_read(struct archive *, void *, const void **buff); -#if ARCHIVE_API_VERSION < 2 -static ssize_t file_skip(struct archive *, void *, size_t request); -#else -static off_t file_skip(struct archive *, void *, off_t request); -#endif - -int -archive_read_open_file(struct archive *a, const char *filename, - size_t block_size) -{ - return (archive_read_open_filename(a, filename, block_size)); -} - -int -archive_read_open_filename(struct archive *a, const char *filename, - size_t block_size) -{ - struct stat st; - struct read_file_data *mine; - void *b; - int fd; - - archive_clear_error(a); - if (filename == NULL || filename[0] == '\0') { - /* We used to invoke archive_read_open_fd(a,0,block_size) - * here, but that doesn't (and shouldn't) handle the - * end-of-file flush when reading stdout from a pipe. - * Basically, read_open_fd() is intended for folks who - * are willing to handle such details themselves. This - * API is intended to be a little smarter for folks who - * want easy handling of the common case. - */ - filename = ""; /* Normalize NULL to "" */ - fd = 0; -#if defined(__CYGWIN__) || defined(_WIN32) - setmode(0, O_BINARY); -#endif - } else { - fd = open(filename, O_RDONLY | O_BINARY); - if (fd < 0) { - archive_set_error(a, errno, - "Failed to open '%s'", filename); - return (ARCHIVE_FATAL); - } - } - if (fstat(fd, &st) != 0) { - archive_set_error(a, errno, "Can't stat '%s'", filename); - return (ARCHIVE_FATAL); - } - - mine = (struct read_file_data *)calloc(1, - sizeof(*mine) + strlen(filename)); - b = malloc(block_size); - if (mine == NULL || b == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - free(mine); - free(b); - return (ARCHIVE_FATAL); - } - strcpy(mine->filename, filename); - mine->block_size = block_size; - mine->buffer = b; - mine->fd = fd; - /* Remember mode so close can decide whether to flush. */ - mine->st_mode = st.st_mode; - /* If we're reading a file from disk, ensure that we don't - overwrite it with an extracted file. */ - if (S_ISREG(st.st_mode)) { - archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); - /* - * Enabling skip here is a performance optimization - * for anything that supports lseek(). On FreeBSD - * (and probably many other systems), only regular - * files and raw disk devices support lseek() (on - * other input types, lseek() returns success but - * doesn't actually change the file pointer, which - * just completely screws up the position-tracking - * logic). In addition, I've yet to find a portable - * way to determine if a device is a raw disk device. - * So I don't see a way to do much better than to only - * enable this optimization for regular files. - */ - mine->can_skip = 1; - } - return (archive_read_open2(a, mine, - NULL, file_read, file_skip, file_close)); -} - -static ssize_t -file_read(struct archive *a, void *client_data, const void **buff) -{ - struct read_file_data *mine = (struct read_file_data *)client_data; - ssize_t bytes_read; - - *buff = mine->buffer; - for (;;) { - bytes_read = read(mine->fd, mine->buffer, mine->block_size); - if (bytes_read < 0) { - if (errno == EINTR) - continue; - else if (mine->filename[0] == '\0') - archive_set_error(a, errno, "Error reading stdin"); - else - archive_set_error(a, errno, "Error reading '%s'", - mine->filename); - } - return (bytes_read); - } -} - -#if ARCHIVE_API_VERSION < 2 -static ssize_t -file_skip(struct archive *a, void *client_data, size_t request) -#else -static off_t -file_skip(struct archive *a, void *client_data, off_t request) -#endif -{ - struct read_file_data *mine = (struct read_file_data *)client_data; - off_t old_offset, new_offset; - - if (!mine->can_skip) /* We can't skip, so ... */ - return (0); /* ... skip zero bytes. */ - - /* Reduce request to the next smallest multiple of block_size */ - request = (request / mine->block_size) * mine->block_size; - if (request == 0) - return (0); - - /* - * Hurray for lazy evaluation: if the first lseek fails, the second - * one will not be executed. - */ - if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) < 0) || - ((new_offset = lseek(mine->fd, request, SEEK_CUR)) < 0)) - { - /* If skip failed once, it will probably fail again. */ - mine->can_skip = 0; - - if (errno == ESPIPE) - { - /* - * Failure to lseek() can be caused by the file - * descriptor pointing to a pipe, socket or FIFO. - * Return 0 here, so the compression layer will use - * read()s instead to advance the file descriptor. - * It's slower of course, but works as well. - */ - return (0); - } - /* - * There's been an error other than ESPIPE. This is most - * likely caused by a programmer error (too large request) - * or a corrupted archive file. - */ - if (mine->filename[0] == '\0') - /* - * Should never get here, since lseek() on stdin ought - * to return an ESPIPE error. - */ - archive_set_error(a, errno, "Error seeking in stdin"); - else - archive_set_error(a, errno, "Error seeking in '%s'", - mine->filename); - return (-1); - } - return (new_offset - old_offset); -} - -static int -file_close(struct archive *a, void *client_data) -{ - struct read_file_data *mine = (struct read_file_data *)client_data; - - (void)a; /* UNUSED */ - - /* Only flush and close if open succeeded. */ - if (mine->fd >= 0) { - /* - * Sometimes, we should flush the input before closing. - * Regular files: faster to just close without flush. - * Devices: must not flush (user might need to - * read the "next" item on a non-rewind device). - * Pipes and sockets: must flush (otherwise, the - * program feeding the pipe or socket may complain). - * Here, I flush everything except for regular files and - * device nodes. - */ - if (!S_ISREG(mine->st_mode) - && !S_ISCHR(mine->st_mode) - && !S_ISBLK(mine->st_mode)) { - ssize_t bytesRead; - do { - bytesRead = read(mine->fd, mine->buffer, - mine->block_size); - } while (bytesRead > 0); - } - /* If a named file was opened, then it needs to be closed. */ - if (mine->filename[0] != '\0') - close(mine->fd); - } - free(mine->buffer); - free(mine); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_read_open_memory.c b/lib/libarchive/archive_read_open_memory.c deleted file mode 100644 index 7f52117..0000000 --- a/lib/libarchive/archive_read_open_memory.c +++ /dev/null @@ -1,156 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -#include "archive.h" - -/* - * Glue to read an archive from a block of memory. - * - * This is mostly a huge help in building test harnesses; - * test programs can build archives in memory and read them - * back again without having to mess with files on disk. - */ - -struct read_memory_data { - unsigned char *buffer; - unsigned char *end; - ssize_t read_size; -}; - -static int memory_read_close(struct archive *, void *); -static int memory_read_open(struct archive *, void *); -#if ARCHIVE_API_VERSION < 2 -static ssize_t memory_read_skip(struct archive *, void *, size_t request); -#else -static off_t memory_read_skip(struct archive *, void *, off_t request); -#endif -static ssize_t memory_read(struct archive *, void *, const void **buff); - -int -archive_read_open_memory(struct archive *a, void *buff, size_t size) -{ - return archive_read_open_memory2(a, buff, size, size); -} - -/* - * Don't use _open_memory2() in production code; the archive_read_open_memory() - * version is the one you really want. This is just here so that - * test harnesses can exercise block operations inside the library. - */ -int -archive_read_open_memory2(struct archive *a, void *buff, - size_t size, size_t read_size) -{ - struct read_memory_data *mine; - - mine = (struct read_memory_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - memset(mine, 0, sizeof(*mine)); - mine->buffer = (unsigned char *)buff; - mine->end = mine->buffer + size; - mine->read_size = read_size; - return (archive_read_open2(a, mine, memory_read_open, - memory_read, memory_read_skip, memory_read_close)); -} - -/* - * There's nothing to open. - */ -static int -memory_read_open(struct archive *a, void *client_data) -{ - (void)a; /* UNUSED */ - (void)client_data; /* UNUSED */ - return (ARCHIVE_OK); -} - -/* - * This is scary simple: Just advance a pointer. Limiting - * to read_size is not technically necessary, but it exercises - * more of the internal logic when used with a small block size - * in a test harness. Production use should not specify a block - * size; then this is much faster. - */ -static ssize_t -memory_read(struct archive *a, void *client_data, const void **buff) -{ - struct read_memory_data *mine = (struct read_memory_data *)client_data; - ssize_t size; - - (void)a; /* UNUSED */ - *buff = mine->buffer; - size = mine->end - mine->buffer; - if (size > mine->read_size) - size = mine->read_size; - mine->buffer += size; - return (size); -} - -/* - * Advancing is just as simple. Again, this is doing more than - * necessary in order to better exercise internal code when used - * as a test harness. - */ -#if ARCHIVE_API_VERSION < 2 -static ssize_t -memory_read_skip(struct archive *a, void *client_data, size_t skip) -#else -static off_t -memory_read_skip(struct archive *a, void *client_data, off_t skip) -#endif -{ - struct read_memory_data *mine = (struct read_memory_data *)client_data; - - (void)a; /* UNUSED */ - if ((off_t)skip > (off_t)(mine->end - mine->buffer)) - skip = mine->end - mine->buffer; - /* Round down to block size. */ - skip /= mine->read_size; - skip *= mine->read_size; - mine->buffer += skip; - return (skip); -} - -/* - * Close is just cleaning up our one small bit of data. - */ -static int -memory_read_close(struct archive *a, void *client_data) -{ - struct read_memory_data *mine = (struct read_memory_data *)client_data; - (void)a; /* UNUSED */ - free(mine); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_read_private.h b/lib/libarchive/archive_read_private.h deleted file mode 100644 index ed8a889..0000000 --- a/lib/libarchive/archive_read_private.h +++ /dev/null @@ -1,199 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifndef ARCHIVE_READ_PRIVATE_H_INCLUDED -#define ARCHIVE_READ_PRIVATE_H_INCLUDED - -#include "archive.h" -#include "archive_string.h" -#include "archive_private.h" - -struct archive_read; -struct archive_read_filter_bidder; -struct archive_read_filter; - -/* - * How bidding works for filters: - * * The bid manager reads the first block from the current source. - * * It shows that block to each registered bidder. - * * The bid manager creates a new filter structure for the winning - * bidder and gives the winning bidder a chance to initialize it. - * * The new filter becomes the top filter in the archive_read structure - * and we repeat the process. - * This ends only when no bidder provides a non-zero bid. - */ -struct archive_read_filter_bidder { - /* Configuration data for the bidder. */ - void *data; - /* Taste the upstream filter to see if we handle this. */ - int (*bid)(struct archive_read_filter_bidder *, - struct archive_read_filter *); - /* Initialize a newly-created filter. */ - int (*init)(struct archive_read_filter *); - /* Set an option for the filter bidder. */ - int (*options)(struct archive_read_filter_bidder *, - const char *key, const char *value); - /* Release the bidder's configuration data. */ - int (*free)(struct archive_read_filter_bidder *); -}; - -/* - * This structure is allocated within the archive_read core - * and initialized by archive_read and the init() method of the - * corresponding bidder above. - */ -struct archive_read_filter { - /* Essentially all filters will need these values, so - * just declare them here. */ - struct archive_read_filter_bidder *bidder; /* My bidder. */ - struct archive_read_filter *upstream; /* Who I read from. */ - struct archive_read *archive; /* Associated archive. */ - /* Return next block. */ - ssize_t (*read)(struct archive_read_filter *, const void **); - /* Skip forward this many bytes. */ - int64_t (*skip)(struct archive_read_filter *self, int64_t request); - /* Close (just this filter) and free(self). */ - int (*close)(struct archive_read_filter *self); - /* My private data. */ - void *data; - - const char *name; - int code; - - /* Used by reblocking logic. */ - char *buffer; - size_t buffer_size; - char *next; /* Current read location. */ - size_t avail; /* Bytes in my buffer. */ - const void *client_buff; /* Client buffer information. */ - size_t client_total; - const char *client_next; - size_t client_avail; - int64_t position; - char end_of_file; - char fatal; -}; - -/* - * The client looks a lot like a filter, so we just wrap it here. - * - * TODO: Make archive_read_filter and archive_read_client identical so - * that users of the library can easily register their own - * transformation filters. This will probably break the API/ABI and - * so should be deferred at least until libarchive 3.0. - */ -struct archive_read_client { - archive_read_callback *reader; - archive_skip_callback *skipper; - archive_close_callback *closer; -}; - -struct archive_read { - struct archive archive; - - struct archive_entry *entry; - - /* Dev/ino of the archive being read/written. */ - dev_t skip_file_dev; - ino_t skip_file_ino; - - /* - * Used by archive_read_data() to track blocks and copy - * data to client buffers, filling gaps with zero bytes. - */ - const char *read_data_block; - off_t read_data_offset; - off_t read_data_output_offset; - size_t read_data_remaining; - - /* Callbacks to open/read/write/close client archive stream. */ - struct archive_read_client client; - - /* Registered filter bidders. */ - struct archive_read_filter_bidder bidders[8]; - - /* Last filter in chain */ - struct archive_read_filter *filter; - - /* File offset of beginning of most recently-read header. */ - off_t header_position; - - /* - * Format detection is mostly the same as compression - * detection, with one significant difference: The bidders - * use the read_ahead calls above to examine the stream rather - * than having the supervisor hand them a block of data to - * examine. - */ - - struct archive_format_descriptor { - void *data; - const char *name; - int (*bid)(struct archive_read *); - int (*options)(struct archive_read *, const char *key, - const char *value); - int (*read_header)(struct archive_read *, struct archive_entry *); - int (*read_data)(struct archive_read *, const void **, size_t *, off_t *); - int (*read_data_skip)(struct archive_read *); - int (*cleanup)(struct archive_read *); - } formats[9]; - struct archive_format_descriptor *format; /* Active format. */ - - /* - * Various information needed by archive_extract. - */ - struct extract *extract; - int (*cleanup_archive_extract)(struct archive_read *); -}; - -int __archive_read_register_format(struct archive_read *a, - void *format_data, - const char *name, - int (*bid)(struct archive_read *), - int (*options)(struct archive_read *, const char *, const char *), - int (*read_header)(struct archive_read *, struct archive_entry *), - int (*read_data)(struct archive_read *, const void **, size_t *, off_t *), - int (*read_data_skip)(struct archive_read *), - int (*cleanup)(struct archive_read *)); - -struct archive_read_filter_bidder - *__archive_read_get_bidder(struct archive_read *a); - -const void *__archive_read_ahead(struct archive_read *, size_t, ssize_t *); -const void *__archive_read_filter_ahead(struct archive_read_filter *, - size_t, ssize_t *); -ssize_t __archive_read_consume(struct archive_read *, size_t); -ssize_t __archive_read_filter_consume(struct archive_read_filter *, size_t); -int64_t __archive_read_skip(struct archive_read *, int64_t); -int64_t __archive_read_skip_lenient(struct archive_read *, int64_t); -int64_t __archive_read_filter_skip(struct archive_read_filter *, int64_t); -int __archive_read_program(struct archive_read_filter *, const char *); -#endif diff --git a/lib/libarchive/archive_read_support_compression_all.c b/lib/libarchive/archive_read_support_compression_all.c deleted file mode 100644 index 484e557..0000000 --- a/lib/libarchive/archive_read_support_compression_all.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#include "archive.h" - -int -archive_read_support_compression_all(struct archive *a) -{ - /* Bzip falls back to "bunzip2" command-line */ - archive_read_support_compression_bzip2(a); - /* The decompress code doesn't use an outside library. */ - archive_read_support_compression_compress(a); - /* Gzip decompress falls back to "gunzip" command-line. */ - archive_read_support_compression_gzip(a); - /* The LZMA file format has a very weak signature, so it - * may not be feasible to keep this here, but we'll try. - * This will come back out if there are problems. */ - /* Lzma falls back to "unlzma" command-line program. */ - archive_read_support_compression_lzma(a); - /* Xz falls back to "unxz" command-line program. */ - archive_read_support_compression_xz(a); - /* The decode code doesn't use an outside library. */ - archive_read_support_compression_uu(a); - /* The decode code doesn't use an outside library. */ - archive_read_support_compression_rpm(a); - - /* Note: We always return ARCHIVE_OK here, even if some of the - * above return ARCHIVE_WARN. The intent here is to enable - * "as much as possible." Clients who need specific - * compression should enable those individually so they can - * verify the level of support. */ - /* Clear any warning messages set by the above functions. */ - archive_clear_error(a); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_read_support_compression_bzip2.c b/lib/libarchive/archive_read_support_compression_bzip2.c deleted file mode 100644 index 891742f..0000000 --- a/lib/libarchive/archive_read_support_compression_bzip2.c +++ /dev/null @@ -1,353 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" - -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_BZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) -struct private_data { - bz_stream stream; - char *out_block; - size_t out_block_size; - char valid; /* True = decompressor is initialized */ - char eof; /* True = found end of compressed data. */ -}; - -/* Bzip2 filter */ -static ssize_t bzip2_filter_read(struct archive_read_filter *, const void **); -static int bzip2_filter_close(struct archive_read_filter *); -#endif - -/* - * Note that we can detect bzip2 archives even if we can't decompress - * them. (In fact, we like detecting them because we can give better - * error messages.) So the bid framework here gets compiled even - * if bzlib is unavailable. - */ -static int bzip2_reader_bid(struct archive_read_filter_bidder *, struct archive_read_filter *); -static int bzip2_reader_init(struct archive_read_filter *); -static int bzip2_reader_free(struct archive_read_filter_bidder *); - -int -archive_read_support_compression_bzip2(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *reader = __archive_read_get_bidder(a); - - if (reader == NULL) - return (ARCHIVE_FATAL); - - reader->data = NULL; - reader->bid = bzip2_reader_bid; - reader->init = bzip2_reader_init; - reader->options = NULL; - reader->free = bzip2_reader_free; -#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) - return (ARCHIVE_OK); -#else - archive_set_error(_a, ARCHIVE_ERRNO_MISC, - "Using external bunzip2 program"); - return (ARCHIVE_WARN); -#endif -} - -static int -bzip2_reader_free(struct archive_read_filter_bidder *self){ - (void)self; /* UNUSED */ - return (ARCHIVE_OK); -} - -/* - * Test whether we can handle this data. - * - * This logic returns zero if any part of the signature fails. It - * also tries to Do The Right Thing if a very short buffer prevents us - * from verifying as much as we would like. - */ -static int -bzip2_reader_bid(struct archive_read_filter_bidder *self, struct archive_read_filter *filter) -{ - const unsigned char *buffer; - ssize_t avail; - int bits_checked; - - (void)self; /* UNUSED */ - - /* Minimal bzip2 archive is 14 bytes. */ - buffer = __archive_read_filter_ahead(filter, 14, &avail); - if (buffer == NULL) - return (0); - - /* First three bytes must be "BZh" */ - bits_checked = 0; - if (buffer[0] != 'B' || buffer[1] != 'Z' || buffer[2] != 'h') - return (0); - bits_checked += 24; - - /* Next follows a compression flag which must be an ASCII digit. */ - if (buffer[3] < '1' || buffer[3] > '9') - return (0); - bits_checked += 5; - - /* After BZh[1-9], there must be either a data block - * which begins with 0x314159265359 or an end-of-data - * marker of 0x177245385090. */ - if (memcmp(buffer + 4, "\x31\x41\x59\x26\x53\x59", 6) == 0) - bits_checked += 48; - else if (memcmp(buffer + 4, "\x17\x72\x45\x38\x50\x90", 6) == 0) - bits_checked += 48; - else - return (0); - - return (bits_checked); -} - -#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) - -/* - * If we don't have the library on this system, we can't actually do the - * decompression. We can, however, still detect compressed archives - * and emit a useful message. - */ -static int -bzip2_reader_init(struct archive_read_filter *self) -{ - int r; - - r = __archive_read_program(self, "bunzip2"); - /* Note: We set the format here even if __archive_read_program() - * above fails. We do, after all, know what the format is - * even if we weren't able to read it. */ - self->code = ARCHIVE_COMPRESSION_BZIP2; - self->name = "bzip2"; - return (r); -} - - -#else - -/* - * Setup the callbacks. - */ -static int -bzip2_reader_init(struct archive_read_filter *self) -{ - static const size_t out_block_size = 64 * 1024; - void *out_block; - struct private_data *state; - - self->code = ARCHIVE_COMPRESSION_BZIP2; - self->name = "bzip2"; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = (unsigned char *)malloc(out_block_size); - if (self == NULL || state == NULL || out_block == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for bzip2 decompression"); - free(out_block); - free(state); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = bzip2_filter_read; - self->skip = NULL; /* not supported */ - self->close = bzip2_filter_close; - - return (ARCHIVE_OK); -} - -/* - * Return the next block of decompressed data. - */ -static ssize_t -bzip2_filter_read(struct archive_read_filter *self, const void **p) -{ - struct private_data *state; - size_t decompressed; - const char *read_buf; - ssize_t ret; - - state = (struct private_data *)self->data; - - if (state->eof) { - *p = NULL; - return (0); - } - - /* Empty our output buffer. */ - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Try to fill the output buffer. */ - for (;;) { - if (!state->valid) { - if (bzip2_reader_bid(self->bidder, self->upstream) == 0) { - state->eof = 1; - *p = state->out_block; - decompressed = state->stream.next_out - - state->out_block; - return (decompressed); - } - /* Initialize compression library. */ - ret = BZ2_bzDecompressInit(&(state->stream), - 0 /* library verbosity */, - 0 /* don't use low-mem algorithm */); - - /* If init fails, try low-memory algorithm instead. */ - if (ret == BZ_MEM_ERROR) - ret = BZ2_bzDecompressInit(&(state->stream), - 0 /* library verbosity */, - 1 /* do use low-mem algo */); - - if (ret != BZ_OK) { - const char *detail = NULL; - int err = ARCHIVE_ERRNO_MISC; - switch (ret) { - case BZ_PARAM_ERROR: - detail = "invalid setup parameter"; - break; - case BZ_MEM_ERROR: - err = ENOMEM; - detail = "out of memory"; - break; - case BZ_CONFIG_ERROR: - detail = "mis-compiled library"; - break; - } - archive_set_error(&self->archive->archive, err, - "Internal error initializing decompressor%s%s", - detail == NULL ? "" : ": ", - detail); - return (ARCHIVE_FATAL); - } - state->valid = 1; - } - - /* stream.next_in is really const, but bzlib - * doesn't declare it so. */ - read_buf = - __archive_read_filter_ahead(self->upstream, 1, &ret); - if (read_buf == NULL) - return (ARCHIVE_FATAL); - state->stream.next_in = (char *)(uintptr_t)read_buf; - state->stream.avail_in = ret; - /* There is no more data, return whatever we have. */ - if (ret == 0) { - state->eof = 1; - *p = state->out_block; - decompressed = state->stream.next_out - - state->out_block; - return (decompressed); - } - - /* Decompress as much as we can in one pass. */ - ret = BZ2_bzDecompress(&(state->stream)); - __archive_read_filter_consume(self->upstream, - state->stream.next_in - read_buf); - - switch (ret) { - case BZ_STREAM_END: /* Found end of stream. */ - switch (BZ2_bzDecompressEnd(&(state->stream))) { - case BZ_OK: - break; - default: - archive_set_error(&(self->archive->archive), - ARCHIVE_ERRNO_MISC, - "Failed to clean up decompressor"); - return (ARCHIVE_FATAL); - } - state->valid = 0; - /* FALLTHROUGH */ - case BZ_OK: /* Decompressor made some progress. */ - /* If we filled our buffer, update stats and return. */ - if (state->stream.avail_out == 0) { - *p = state->out_block; - decompressed = state->stream.next_out - - state->out_block; - return (decompressed); - } - break; - default: /* Return an error. */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, "bzip decompression failed"); - return (ARCHIVE_FATAL); - } - } -} - -/* - * Clean up the decompressor. - */ -static int -bzip2_filter_close(struct archive_read_filter *self) -{ - struct private_data *state; - int ret = ARCHIVE_OK; - - state = (struct private_data *)self->data; - - if (state->valid) { - switch (BZ2_bzDecompressEnd(&state->stream)) { - case BZ_OK: - break; - default: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Failed to clean up decompressor"); - ret = ARCHIVE_FATAL; - } - } - - free(state->out_block); - free(state); - return (ret); -} - -#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */ diff --git a/lib/libarchive/archive_read_support_compression_compress.c b/lib/libarchive/archive_read_support_compression_compress.c deleted file mode 100644 index c6d4e85..0000000 --- a/lib/libarchive/archive_read_support_compression_compress.c +++ /dev/null @@ -1,444 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This code borrows heavily from "compress" source code, which is - * protected by the following copyright. (Clause 3 dropped by request - * of the Regents.) - */ - -/*- - * Copyright (c) 1985, 1986, 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Diomidis Spinellis and James A. Woods, derived from original - * work by Spencer Thomas and Joseph Orost. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -/* - * Because LZW decompression is pretty simple, I've just implemented - * the whole decompressor here (cribbing from "compress" source code, - * of course), rather than relying on an external library. I have - * made an effort to clarify and simplify the algorithm, so the - * names and structure here don't exactly match those used by compress. - */ - -struct private_data { - /* Input variables. */ - const unsigned char *next_in; - size_t avail_in; - int bit_buffer; - int bits_avail; - size_t bytes_in_section; - - /* Output variables. */ - size_t out_block_size; - void *out_block; - - /* Decompression status variables. */ - int use_reset_code; - int end_of_stream; /* EOF status. */ - int maxcode; /* Largest code. */ - int maxcode_bits; /* Length of largest code. */ - int section_end_code; /* When to increase bits. */ - int bits; /* Current code length. */ - int oldcode; /* Previous code. */ - int finbyte; /* Last byte of prev code. */ - - /* Dictionary. */ - int free_ent; /* Next dictionary entry. */ - unsigned char suffix[65536]; - uint16_t prefix[65536]; - - /* - * Scratch area for expanding dictionary entries. Note: - * "worst" case here comes from compressing /dev/zero: the - * last code in the dictionary will code a sequence of - * 65536-256 zero bytes. Thus, we need stack space to expand - * a 65280-byte dictionary entry. (Of course, 32640:1 - * compression could also be considered the "best" case. ;-) - */ - unsigned char *stackp; - unsigned char stack[65300]; -}; - -static int compress_bidder_bid(struct archive_read_filter_bidder *, struct archive_read_filter *); -static int compress_bidder_init(struct archive_read_filter *); -static int compress_bidder_free(struct archive_read_filter_bidder *); - -static ssize_t compress_filter_read(struct archive_read_filter *, const void **); -static int compress_filter_close(struct archive_read_filter *); - -static int getbits(struct archive_read_filter *, int n); -static int next_code(struct archive_read_filter *); - -int -archive_read_support_compression_compress(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a); - - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = compress_bidder_bid; - bidder->init = compress_bidder_init; - bidder->options = NULL; - bidder->free = compress_bidder_free; - return (ARCHIVE_OK); -} - -/* - * Test whether we can handle this data. - * - * This logic returns zero if any part of the signature fails. It - * also tries to Do The Right Thing if a very short buffer prevents us - * from verifying as much as we would like. - */ -static int -compress_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - const unsigned char *buffer; - ssize_t avail; - int bits_checked; - - (void)self; /* UNUSED */ - - buffer = __archive_read_filter_ahead(filter, 2, &avail); - - if (buffer == NULL) - return (0); - - bits_checked = 0; - if (buffer[0] != 037) /* Verify first ID byte. */ - return (0); - bits_checked += 8; - - if (buffer[1] != 0235) /* Verify second ID byte. */ - return (0); - bits_checked += 8; - - /* - * TODO: Verify more. - */ - - return (bits_checked); -} - -/* - * Setup the callbacks. - */ -static int -compress_bidder_init(struct archive_read_filter *self) -{ - struct private_data *state; - static const size_t out_block_size = 64 * 1024; - void *out_block; - int code; - - self->code = ARCHIVE_COMPRESSION_COMPRESS; - self->name = "compress (.Z)"; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = malloc(out_block_size); - if (state == NULL || out_block == NULL) { - free(out_block); - free(state); - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for %s decompression", - self->name); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = compress_filter_read; - self->skip = NULL; /* not supported */ - self->close = compress_filter_close; - - /* XXX MOVE THE FOLLOWING OUT OF INIT() XXX */ - - (void)getbits(self, 8); /* Skip first signature byte. */ - (void)getbits(self, 8); /* Skip second signature byte. */ - - code = getbits(self, 8); - state->maxcode_bits = code & 0x1f; - state->maxcode = (1 << state->maxcode_bits); - state->use_reset_code = code & 0x80; - - /* Initialize decompressor. */ - state->free_ent = 256; - state->stackp = state->stack; - if (state->use_reset_code) - state->free_ent++; - state->bits = 9; - state->section_end_code = (1<bits) - 1; - state->oldcode = -1; - for (code = 255; code >= 0; code--) { - state->prefix[code] = 0; - state->suffix[code] = code; - } - next_code(self); - - return (ARCHIVE_OK); -} - -/* - * Return a block of data from the decompression buffer. Decompress more - * as necessary. - */ -static ssize_t -compress_filter_read(struct archive_read_filter *self, const void **pblock) -{ - struct private_data *state; - unsigned char *p, *start, *end; - int ret; - - state = (struct private_data *)self->data; - if (state->end_of_stream) { - *pblock = NULL; - return (0); - } - p = start = (unsigned char *)state->out_block; - end = start + state->out_block_size; - - while (p < end && !state->end_of_stream) { - if (state->stackp > state->stack) { - *p++ = *--state->stackp; - } else { - ret = next_code(self); - if (ret == -1) - state->end_of_stream = ret; - else if (ret != ARCHIVE_OK) - return (ret); - } - } - - *pblock = start; - return (p - start); -} - -/* - * Clean up the reader. - */ -static int -compress_bidder_free(struct archive_read_filter_bidder *self) -{ - self->data = NULL; - return (ARCHIVE_OK); -} - -/* - * Close and release the filter. - */ -static int -compress_filter_close(struct archive_read_filter *self) -{ - struct private_data *state = (struct private_data *)self->data; - - free(state->out_block); - free(state); - return (ARCHIVE_OK); -} - -/* - * Process the next code and fill the stack with the expansion - * of the code. Returns ARCHIVE_FATAL if there is a fatal I/O or - * format error, ARCHIVE_EOF if we hit end of data, ARCHIVE_OK otherwise. - */ -static int -next_code(struct archive_read_filter *self) -{ - struct private_data *state = (struct private_data *)self->data; - int code, newcode; - - static int debug_buff[1024]; - static unsigned debug_index; - - code = newcode = getbits(self, state->bits); - if (code < 0) - return (code); - - debug_buff[debug_index++] = code; - if (debug_index >= sizeof(debug_buff)/sizeof(debug_buff[0])) - debug_index = 0; - - /* If it's a reset code, reset the dictionary. */ - if ((code == 256) && state->use_reset_code) { - /* - * The original 'compress' implementation blocked its - * I/O in a manner that resulted in junk bytes being - * inserted after every reset. The next section skips - * this junk. (Yes, the number of *bytes* to skip is - * a function of the current *bit* length.) - */ - int skip_bytes = state->bits - - (state->bytes_in_section % state->bits); - skip_bytes %= state->bits; - state->bits_avail = 0; /* Discard rest of this byte. */ - while (skip_bytes-- > 0) { - code = getbits(self, 8); - if (code < 0) - return (code); - } - /* Now, actually do the reset. */ - state->bytes_in_section = 0; - state->bits = 9; - state->section_end_code = (1 << state->bits) - 1; - state->free_ent = 257; - state->oldcode = -1; - return (next_code(self)); - } - - if (code > state->free_ent) { - /* An invalid code is a fatal error. */ - archive_set_error(&(self->archive->archive), -1, - "Invalid compressed data"); - return (ARCHIVE_FATAL); - } - - /* Special case for KwKwK string. */ - if (code >= state->free_ent) { - *state->stackp++ = state->finbyte; - code = state->oldcode; - } - - /* Generate output characters in reverse order. */ - while (code >= 256) { - *state->stackp++ = state->suffix[code]; - code = state->prefix[code]; - } - *state->stackp++ = state->finbyte = code; - - /* Generate the new entry. */ - code = state->free_ent; - if (code < state->maxcode && state->oldcode >= 0) { - state->prefix[code] = state->oldcode; - state->suffix[code] = state->finbyte; - ++state->free_ent; - } - if (state->free_ent > state->section_end_code) { - state->bits++; - state->bytes_in_section = 0; - if (state->bits == state->maxcode_bits) - state->section_end_code = state->maxcode; - else - state->section_end_code = (1 << state->bits) - 1; - } - - /* Remember previous code. */ - state->oldcode = newcode; - return (ARCHIVE_OK); -} - -/* - * Return next 'n' bits from stream. - * - * -1 indicates end of available data. - */ -static int -getbits(struct archive_read_filter *self, int n) -{ - struct private_data *state = (struct private_data *)self->data; - int code; - ssize_t ret; - static const int mask[] = { - 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, - 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff, 0xffff - }; - - while (state->bits_avail < n) { - if (state->avail_in <= 0) { - state->next_in - = __archive_read_filter_ahead(self->upstream, - 1, &ret); - if (ret == 0) - return (-1); - if (ret < 0 || state->next_in == NULL) - return (ARCHIVE_FATAL); - state->avail_in = ret; - __archive_read_filter_consume(self->upstream, ret); - } - state->bit_buffer |= *state->next_in++ << state->bits_avail; - state->avail_in--; - state->bits_avail += 8; - state->bytes_in_section++; - } - - code = state->bit_buffer; - state->bit_buffer >>= n; - state->bits_avail -= n; - - return (code & mask[n]); -} diff --git a/lib/libarchive/archive_read_support_compression_gzip.c b/lib/libarchive/archive_read_support_compression_gzip.c deleted file mode 100644 index bf6ee46..0000000 --- a/lib/libarchive/archive_read_support_compression_gzip.c +++ /dev/null @@ -1,465 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" - -__FBSDID("$FreeBSD$"); - - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_ZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -#ifdef HAVE_ZLIB_H -struct private_data { - z_stream stream; - char in_stream; - unsigned char *out_block; - size_t out_block_size; - int64_t total_out; - unsigned long crc; - char eof; /* True = found end of compressed data. */ -}; - -/* Gzip Filter. */ -static ssize_t gzip_filter_read(struct archive_read_filter *, const void **); -static int gzip_filter_close(struct archive_read_filter *); -#endif - -/* - * Note that we can detect gzip archives even if we can't decompress - * them. (In fact, we like detecting them because we can give better - * error messages.) So the bid framework here gets compiled even - * if zlib is unavailable. - * - * TODO: If zlib is unavailable, gzip_bidder_init() should - * use the compress_program framework to try to fire up an external - * gunzip program. - */ -static int gzip_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *); -static int gzip_bidder_init(struct archive_read_filter *); - -int -archive_read_support_compression_gzip(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a); - - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = gzip_bidder_bid; - bidder->init = gzip_bidder_init; - bidder->options = NULL; - bidder->free = NULL; /* No data, so no cleanup necessary. */ - /* Signal the extent of gzip support with the return value here. */ -#if HAVE_ZLIB_H - return (ARCHIVE_OK); -#else - archive_set_error(_a, ARCHIVE_ERRNO_MISC, - "Using external gunzip program"); - return (ARCHIVE_WARN); -#endif -} - -/* - * Read and verify the header. - * - * Returns zero if the header couldn't be validated, else returns - * number of bytes in header. If pbits is non-NULL, it receives a - * count of bits verified, suitable for use by bidder. - */ -static int -peek_at_header(struct archive_read_filter *filter, int *pbits) -{ - const unsigned char *p; - ssize_t avail, len; - int bits = 0; - int header_flags; - - /* Start by looking at the first ten bytes of the header, which - * is all fixed layout. */ - len = 10; - p = __archive_read_filter_ahead(filter, len, &avail); - if (p == NULL || avail == 0) - return (0); - if (p[0] != 037) - return (0); - bits += 8; - if (p[1] != 0213) - return (0); - bits += 8; - if (p[2] != 8) /* We only support deflation. */ - return (0); - bits += 8; - if ((p[3] & 0xE0)!= 0) /* No reserved flags set. */ - return (0); - bits += 3; - header_flags = p[3]; - /* Bytes 4-7 are mod time. */ - /* Byte 8 is deflate flags. */ - /* XXXX TODO: return deflate flags back to consume_header for use - in initializing the decompressor. */ - /* Byte 9 is OS. */ - - /* Optional extra data: 2 byte length plus variable body. */ - if (header_flags & 4) { - p = __archive_read_filter_ahead(filter, len + 2, &avail); - if (p == NULL) - return (0); - len += ((int)p[len + 1] << 8) | (int)p[len]; - len += 2; - } - - /* Null-terminated optional filename. */ - if (header_flags & 8) { - do { - ++len; - if (avail < len) - p = __archive_read_filter_ahead(filter, - len, &avail); - if (p == NULL) - return (0); - } while (p[len - 1] != 0); - } - - /* Null-terminated optional comment. */ - if (header_flags & 16) { - do { - ++len; - if (avail < len) - p = __archive_read_filter_ahead(filter, - len, &avail); - if (p == NULL) - return (0); - } while (p[len - 1] != 0); - } - - /* Optional header CRC */ - if ((header_flags & 2)) { - p = __archive_read_filter_ahead(filter, len + 2, &avail); - if (p == NULL) - return (0); -#if 0 - int hcrc = ((int)p[len + 1] << 8) | (int)p[len]; - int crc = /* XXX TODO: Compute header CRC. */; - if (crc != hcrc) - return (0); - bits += 16; -#endif - len += 2; - } - - if (pbits != NULL) - *pbits = bits; - return (len); -} - -/* - * Bidder just verifies the header and returns the number of verified bits. - */ -static int -gzip_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - int bits_checked; - - (void)self; /* UNUSED */ - - if (peek_at_header(filter, &bits_checked)) - return (bits_checked); - return (0); -} - - -#ifndef HAVE_ZLIB_H - -/* - * If we don't have the library on this system, we can't do the - * decompression directly. We can, however, try to run gunzip - * in case that's available. - */ -static int -gzip_bidder_init(struct archive_read_filter *self) -{ - int r; - - r = __archive_read_program(self, "gunzip"); - /* Note: We set the format here even if __archive_read_program() - * above fails. We do, after all, know what the format is - * even if we weren't able to read it. */ - self->code = ARCHIVE_COMPRESSION_GZIP; - self->name = "gzip"; - return (r); -} - -#else - -/* - * Initialize the filter object. - */ -static int -gzip_bidder_init(struct archive_read_filter *self) -{ - struct private_data *state; - static const size_t out_block_size = 64 * 1024; - void *out_block; - - self->code = ARCHIVE_COMPRESSION_GZIP; - self->name = "gzip"; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = (unsigned char *)malloc(out_block_size); - if (state == NULL || out_block == NULL) { - free(out_block); - free(state); - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for gzip decompression"); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = gzip_filter_read; - self->skip = NULL; /* not supported */ - self->close = gzip_filter_close; - - state->in_stream = 0; /* We're not actually within a stream yet. */ - - return (ARCHIVE_OK); -} - -static int -consume_header(struct archive_read_filter *self) -{ - struct private_data *state; - ssize_t avail; - size_t len; - int ret; - - state = (struct private_data *)self->data; - - /* If this is a real header, consume it. */ - len = peek_at_header(self->upstream, NULL); - if (len == 0) - return (ARCHIVE_EOF); - __archive_read_filter_consume(self->upstream, len); - - /* Initialize CRC accumulator. */ - state->crc = crc32(0L, NULL, 0); - - /* Initialize compression library. */ - state->stream.next_in = (unsigned char *)(uintptr_t) - __archive_read_filter_ahead(self->upstream, 1, &avail); - state->stream.avail_in = avail; - ret = inflateInit2(&(state->stream), - -15 /* Don't check for zlib header */); - - /* Decipher the error code. */ - switch (ret) { - case Z_OK: - state->in_stream = 1; - return (ARCHIVE_OK); - case Z_STREAM_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "invalid setup parameter"); - break; - case Z_MEM_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Internal error initializing compression library: " - "out of memory"); - break; - case Z_VERSION_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "invalid library version"); - break; - default: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - " Zlib error %d", ret); - break; - } - return (ARCHIVE_FATAL); -} - -static int -consume_trailer(struct archive_read_filter *self) -{ - struct private_data *state; - const unsigned char *p; - ssize_t avail; - - state = (struct private_data *)self->data; - - state->in_stream = 0; - switch (inflateEnd(&(state->stream))) { - case Z_OK: - break; - default: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Failed to clean up gzip decompressor"); - return (ARCHIVE_FATAL); - } - - /* GZip trailer is a fixed 8 byte structure. */ - p = __archive_read_filter_ahead(self->upstream, 8, &avail); - if (p == NULL || avail == 0) - return (ARCHIVE_FATAL); - - /* XXX TODO: Verify the length and CRC. */ - - /* We've verified the trailer, so consume it now. */ - __archive_read_filter_consume(self->upstream, 8); - - return (ARCHIVE_OK); -} - -static ssize_t -gzip_filter_read(struct archive_read_filter *self, const void **p) -{ - struct private_data *state; - size_t decompressed; - ssize_t avail_in; - int ret; - - state = (struct private_data *)self->data; - - /* Empty our output buffer. */ - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Try to fill the output buffer. */ - while (state->stream.avail_out > 0 && !state->eof) { - /* If we're not in a stream, read a header - * and initialize the decompression library. */ - if (!state->in_stream) { - ret = consume_header(self); - if (ret == ARCHIVE_EOF) { - state->eof = 1; - break; - } - if (ret < ARCHIVE_OK) - return (ret); - } - - /* Peek at the next available data. */ - /* ZLib treats stream.next_in as const but doesn't declare - * it so, hence this ugly cast. */ - state->stream.next_in = (unsigned char *)(uintptr_t) - __archive_read_filter_ahead(self->upstream, 1, &avail_in); - if (state->stream.next_in == NULL) - return (ARCHIVE_FATAL); - state->stream.avail_in = avail_in; - - /* Decompress and consume some of that data. */ - ret = inflate(&(state->stream), 0); - switch (ret) { - case Z_OK: /* Decompressor made some progress. */ - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - break; - case Z_STREAM_END: /* Found end of stream. */ - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - /* Consume the stream trailer; release the - * decompression library. */ - ret = consume_trailer(self); - if (ret < ARCHIVE_OK) - return (ret); - break; - default: - /* Return an error. */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "gzip decompression failed"); - return (ARCHIVE_FATAL); - } - } - - /* We've read as much as we can. */ - decompressed = state->stream.next_out - state->out_block; - state->total_out += decompressed; - if (decompressed == 0) - *p = NULL; - else - *p = state->out_block; - return (decompressed); -} - -/* - * Clean up the decompressor. - */ -static int -gzip_filter_close(struct archive_read_filter *self) -{ - struct private_data *state; - int ret; - - state = (struct private_data *)self->data; - ret = ARCHIVE_OK; - - if (state->in_stream) { - switch (inflateEnd(&(state->stream))) { - case Z_OK: - break; - default: - archive_set_error(&(self->archive->archive), - ARCHIVE_ERRNO_MISC, - "Failed to clean up gzip compressor"); - ret = ARCHIVE_FATAL; - } - } - - free(state->out_block); - free(state); - return (ret); -} - -#endif /* HAVE_ZLIB_H */ diff --git a/lib/libarchive/archive_read_support_compression_none.c b/lib/libarchive/archive_read_support_compression_none.c deleted file mode 100644 index e05614f..0000000 --- a/lib/libarchive/archive_read_support_compression_none.c +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#include "archive.h" - -/* - * Uncompressed streams are handled implicitly by the read core, - * so this is now a no-op. - */ -int -archive_read_support_compression_none(struct archive *a) -{ - (void)a; /* UNUSED */ - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_read_support_compression_program.c b/lib/libarchive/archive_read_support_compression_program.c deleted file mode 100644 index 01552ba..0000000 --- a/lib/libarchive/archive_read_support_compression_program.c +++ /dev/null @@ -1,459 +0,0 @@ -/*- - * Copyright (c) 2007 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_WAIT_H -# include -#endif -#ifdef HAVE_ERRNO_H -# include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -#ifdef HAVE_LIMITS_H -# include -#endif -#ifdef HAVE_SIGNAL_H -# include -#endif -#ifdef HAVE_STDLIB_H -# include -#endif -#ifdef HAVE_STRING_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -int -archive_read_support_compression_program(struct archive *a, const char *cmd) -{ - return (archive_read_support_compression_program_signature(a, cmd, NULL, 0)); -} - - -/* This capability is only available on POSIX systems. */ -#if (!defined(HAVE_PIPE) || !defined(HAVE_FCNTL) || \ - !(defined(HAVE_FORK) || defined(HAVE_VFORK))) && (!defined(_WIN32) || defined(__CYGWIN__)) - -/* - * On non-Posix systems, allow the program to build, but choke if - * this function is actually invoked. - */ -int -archive_read_support_compression_program_signature(struct archive *_a, - const char *cmd, void *signature, size_t signature_len) -{ - (void)_a; /* UNUSED */ - (void)cmd; /* UNUSED */ - (void)signature; /* UNUSED */ - (void)signature_len; /* UNUSED */ - - archive_set_error(_a, -1, - "External compression programs not supported on this platform"); - return (ARCHIVE_FATAL); -} - -int -__archive_read_program(struct archive_read_filter *self, const char *cmd) -{ - (void)self; /* UNUSED */ - (void)cmd; /* UNUSED */ - - archive_set_error(&self->archive->archive, -1, - "External compression programs not supported on this platform"); - return (ARCHIVE_FATAL); -} - -#else - -#include "filter_fork.h" - -/* - * The bidder object stores the command and the signature to watch for. - * The 'inhibit' entry here is used to ensure that unchecked filters never - * bid twice in the same pipeline. - */ -struct program_bidder { - char *cmd; - void *signature; - size_t signature_len; - int inhibit; -}; - -static int program_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *upstream); -static int program_bidder_init(struct archive_read_filter *); -static int program_bidder_free(struct archive_read_filter_bidder *); - -/* - * The actual filter needs to track input and output data. - */ -struct program_filter { - char *description; - pid_t child; - int exit_status; - int waitpid_return; - int child_stdin, child_stdout; - - char *out_buf; - size_t out_buf_len; -}; - -static ssize_t program_filter_read(struct archive_read_filter *, - const void **); -static int program_filter_close(struct archive_read_filter *); - -int -archive_read_support_compression_program_signature(struct archive *_a, - const char *cmd, const void *signature, size_t signature_len) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder; - struct program_bidder *state; - - /* - * Get a bidder object from the read core. - */ - bidder = __archive_read_get_bidder(a); - if (bidder == NULL) - return (ARCHIVE_FATAL); - - /* - * Allocate our private state. - */ - state = (struct program_bidder *)calloc(sizeof (*state), 1); - if (state == NULL) - return (ARCHIVE_FATAL); - state->cmd = strdup(cmd); - if (signature != NULL && signature_len > 0) { - state->signature_len = signature_len; - state->signature = malloc(signature_len); - memcpy(state->signature, signature, signature_len); - } - - /* - * Fill in the bidder object. - */ - bidder->data = state; - bidder->bid = program_bidder_bid; - bidder->init = program_bidder_init; - bidder->options = NULL; - bidder->free = program_bidder_free; - return (ARCHIVE_OK); -} - -static int -program_bidder_free(struct archive_read_filter_bidder *self) -{ - struct program_bidder *state = (struct program_bidder *)self->data; - free(state->cmd); - free(state->signature); - free(self->data); - return (ARCHIVE_OK); -} - -/* - * If we do have a signature, bid only if that matches. - * - * If there's no signature, we bid INT_MAX the first time - * we're called, then never bid again. - */ -static int -program_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *upstream) -{ - struct program_bidder *state = self->data; - const char *p; - - /* If we have a signature, use that to match. */ - if (state->signature_len > 0) { - p = __archive_read_filter_ahead(upstream, - state->signature_len, NULL); - if (p == NULL) - return (0); - /* No match, so don't bid. */ - if (memcmp(p, state->signature, state->signature_len) != 0) - return (0); - return ((int)state->signature_len * 8); - } - - /* Otherwise, bid once and then never bid again. */ - if (state->inhibit) - return (0); - state->inhibit = 1; - return (INT_MAX); -} - -/* - * Shut down the child, return ARCHIVE_OK if it exited normally. - * - * Note that the return value is sticky; if we're called again, - * we won't reap the child again, but we will return the same status - * (including error message if the child came to a bad end). - */ -static int -child_stop(struct archive_read_filter *self, struct program_filter *state) -{ - /* Close our side of the I/O with the child. */ - if (state->child_stdin != -1) { - close(state->child_stdin); - state->child_stdin = -1; - } - if (state->child_stdout != -1) { - close(state->child_stdout); - state->child_stdout = -1; - } - - if (state->child != 0) { - /* Reap the child. */ - do { - state->waitpid_return - = waitpid(state->child, &state->exit_status, 0); - } while (state->waitpid_return == -1 && errno == EINTR); - state->child = 0; - } - - if (state->waitpid_return < 0) { - /* waitpid() failed? This is ugly. */ - archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, - "Child process exited badly"); - return (ARCHIVE_WARN); - } - -#if !defined(_WIN32) || defined(__CYGWIN__) - if (WIFSIGNALED(state->exit_status)) { -#ifdef SIGPIPE - /* If the child died because we stopped reading before - * it was done, that's okay. Some archive formats - * have padding at the end that we routinely ignore. */ - /* The alternative to this would be to add a step - * before close(child_stdout) above to read from the - * child until the child has no more to write. */ - if (WTERMSIG(state->exit_status) == SIGPIPE) - return (ARCHIVE_OK); -#endif - archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, - "Child process exited with signal %d", - WTERMSIG(state->exit_status)); - return (ARCHIVE_WARN); - } -#endif /* !_WIN32 || __CYGWIN__ */ - - if (WIFEXITED(state->exit_status)) { - if (WEXITSTATUS(state->exit_status) == 0) - return (ARCHIVE_OK); - - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Child process exited with status %d", - WEXITSTATUS(state->exit_status)); - return (ARCHIVE_WARN); - } - - return (ARCHIVE_WARN); -} - -/* - * Use select() to decide whether the child is ready for read or write. - */ -static ssize_t -child_read(struct archive_read_filter *self, char *buf, size_t buf_len) -{ - struct program_filter *state = self->data; - ssize_t ret, requested, avail; - const char *p; - - requested = buf_len > SSIZE_MAX ? SSIZE_MAX : buf_len; - - for (;;) { - do { - ret = read(state->child_stdout, buf, requested); - } while (ret == -1 && errno == EINTR); - - if (ret > 0) - return (ret); - if (ret == 0 || (ret == -1 && errno == EPIPE)) - /* Child has closed its output; reap the child - * and return the status. */ - return (child_stop(self, state)); - if (ret == -1 && errno != EAGAIN) - return (-1); - - if (state->child_stdin == -1) { - /* Block until child has some I/O ready. */ - __archive_check_child(state->child_stdin, - state->child_stdout); - continue; - } - - /* Get some more data from upstream. */ - p = __archive_read_filter_ahead(self->upstream, 1, &avail); - if (p == NULL) { - close(state->child_stdin); - state->child_stdin = -1; - fcntl(state->child_stdout, F_SETFL, 0); - if (avail < 0) - return (avail); - continue; - } - - do { - ret = write(state->child_stdin, p, avail); - } while (ret == -1 && errno == EINTR); - - if (ret > 0) { - /* Consume whatever we managed to write. */ - __archive_read_filter_consume(self->upstream, ret); - } else if (ret == -1 && errno == EAGAIN) { - /* Block until child has some I/O ready. */ - __archive_check_child(state->child_stdin, - state->child_stdout); - } else { - /* Write failed. */ - close(state->child_stdin); - state->child_stdin = -1; - fcntl(state->child_stdout, F_SETFL, 0); - /* If it was a bad error, we're done; otherwise - * it was EPIPE or EOF, and we can still read - * from the child. */ - if (ret == -1 && errno != EPIPE) - return (-1); - } - } -} - -int -__archive_read_program(struct archive_read_filter *self, const char *cmd) -{ - struct program_filter *state; - static const size_t out_buf_len = 65536; - char *out_buf; - char *description; - const char *prefix = "Program: "; - - state = (struct program_filter *)calloc(1, sizeof(*state)); - out_buf = (char *)malloc(out_buf_len); - description = (char *)malloc(strlen(prefix) + strlen(cmd) + 1); - if (state == NULL || out_buf == NULL || description == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate input data"); - free(state); - free(out_buf); - free(description); - return (ARCHIVE_FATAL); - } - - self->code = ARCHIVE_COMPRESSION_PROGRAM; - state->description = description; - strcpy(state->description, prefix); - strcat(state->description, cmd); - self->name = state->description; - - state->out_buf = out_buf; - state->out_buf_len = out_buf_len; - - if ((state->child = __archive_create_child(cmd, - &state->child_stdin, &state->child_stdout)) == -1) { - free(state->out_buf); - free(state); - archive_set_error(&self->archive->archive, EINVAL, - "Can't initialise filter"); - return (ARCHIVE_FATAL); - } - - self->data = state; - self->read = program_filter_read; - self->skip = NULL; - self->close = program_filter_close; - - /* XXX Check that we can read at least one byte? */ - return (ARCHIVE_OK); -} - -static int -program_bidder_init(struct archive_read_filter *self) -{ - struct program_bidder *bidder_state; - - bidder_state = (struct program_bidder *)self->bidder->data; - return (__archive_read_program(self, bidder_state->cmd)); -} - -static ssize_t -program_filter_read(struct archive_read_filter *self, const void **buff) -{ - struct program_filter *state; - ssize_t bytes; - size_t total; - char *p; - - state = (struct program_filter *)self->data; - - total = 0; - p = state->out_buf; - while (state->child_stdout != -1 && total < state->out_buf_len) { - bytes = child_read(self, p, state->out_buf_len - total); - if (bytes < 0) - /* No recovery is possible if we can no longer - * read from the child. */ - return (ARCHIVE_FATAL); - if (bytes == 0) - /* We got EOF from the child. */ - break; - total += bytes; - p += bytes; - } - - *buff = state->out_buf; - return (total); -} - -static int -program_filter_close(struct archive_read_filter *self) -{ - struct program_filter *state; - int e; - - state = (struct program_filter *)self->data; - e = child_stop(self, state); - - /* Release our private data. */ - free(state->out_buf); - free(state->description); - free(state); - - return (e); -} - -#endif /* !defined(HAVE_PIPE) || !defined(HAVE_VFORK) || !defined(HAVE_FCNTL) */ diff --git a/lib/libarchive/archive_read_support_compression_rpm.c b/lib/libarchive/archive_read_support_compression_rpm.c deleted file mode 100644 index f8bd878..0000000 --- a/lib/libarchive/archive_read_support_compression_rpm.c +++ /dev/null @@ -1,288 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif - -#include "archive.h" -#include "archive_endian.h" -#include "archive_private.h" -#include "archive_read_private.h" - -struct rpm { - int64_t total_in; - size_t hpos; - size_t hlen; - unsigned char header[16]; - enum { - ST_LEAD, /* Skipping 'Lead' section. */ - ST_HEADER, /* Reading 'Header' section; - * first 16 bytes. */ - ST_HEADER_DATA, /* Skipping 'Header' section. */ - ST_PADDING, /* Skipping padding data after the - * 'Header' section. */ - ST_ARCHIVE /* Reading 'Archive' section. */ - } state; - int first_header; -}; -#define RPM_LEAD_SIZE 96 /* Size of 'Lead' section. */ - -static int rpm_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *); -static int rpm_bidder_init(struct archive_read_filter *); - -static ssize_t rpm_filter_read(struct archive_read_filter *, - const void **); -static int rpm_filter_close(struct archive_read_filter *); - -int -archive_read_support_compression_rpm(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder; - - bidder = __archive_read_get_bidder(a); - archive_clear_error(_a); - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = rpm_bidder_bid; - bidder->init = rpm_bidder_init; - bidder->options = NULL; - bidder->free = NULL; - return (ARCHIVE_OK); -} - -static int -rpm_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - const unsigned char *b; - ssize_t avail; - int bits_checked; - - (void)self; /* UNUSED */ - - b = __archive_read_filter_ahead(filter, 8, &avail); - if (b == NULL) - return (0); - - bits_checked = 0; - /* - * Verify Header Magic Bytes : 0xed 0xab 0xee 0xdb - */ - if (b[0] != 0xed) - return (0); - bits_checked += 8; - if (b[1] != 0xab) - return (0); - bits_checked += 8; - if (b[2] != 0xee) - return (0); - bits_checked += 8; - if (b[3] != 0xdb) - return (0); - bits_checked += 8; - /* - * Check major version. - */ - if (b[4] != 3 && b[4] != 4) - return (0); - bits_checked += 8; - /* - * Check package type; binary or source. - */ - if (b[6] != 0) - return (0); - bits_checked += 8; - if (b[7] != 0 && b[7] != 1) - return (0); - bits_checked += 8; - - return (bits_checked); -} - -static int -rpm_bidder_init(struct archive_read_filter *self) -{ - struct rpm *rpm; - - self->code = ARCHIVE_COMPRESSION_RPM; - self->name = "rpm"; - self->read = rpm_filter_read; - self->skip = NULL; /* not supported */ - self->close = rpm_filter_close; - - rpm = (struct rpm *)calloc(sizeof(*rpm), 1); - if (rpm == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for rpm"); - return (ARCHIVE_FATAL); - } - - self->data = rpm; - rpm->state = ST_LEAD; - - return (ARCHIVE_OK); -} - -static ssize_t -rpm_filter_read(struct archive_read_filter *self, const void **buff) -{ - struct rpm *rpm; - const unsigned char *b; - ssize_t avail_in, total; - size_t used, n; - uint32_t section; - uint32_t bytes; - - rpm = (struct rpm *)self->data; - *buff = NULL; - total = avail_in = 0; - b = NULL; - used = 0; - do { - if (b == NULL) { - b = __archive_read_filter_ahead(self->upstream, 1, - &avail_in); - if (b == NULL) { - if (avail_in < 0) - return (ARCHIVE_FATAL); - else - break; - } - } - - switch (rpm->state) { - case ST_LEAD: - if (rpm->total_in + avail_in < RPM_LEAD_SIZE) - used += avail_in; - else { - n = RPM_LEAD_SIZE - rpm->total_in; - used += n; - b += n; - rpm->state = ST_HEADER; - rpm->hpos = 0; - rpm->hlen = 0; - rpm->first_header = 1; - } - break; - case ST_HEADER: - n = 16 - rpm->hpos; - if (n > avail_in - used) - n = avail_in - used; - memcpy(rpm->header+rpm->hpos, b, n); - b += n; - used += n; - rpm->hpos += n; - - if (rpm->hpos == 16) { - if (rpm->header[0] != 0x8e || - rpm->header[1] != 0xad || - rpm->header[2] != 0xe8 || - rpm->header[3] != 0x01) { - if (rpm->first_header) { - archive_set_error( - &self->archive->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Unrecoginized rpm header"); - return (ARCHIVE_FATAL); - } - rpm->state = ST_ARCHIVE; - *buff = rpm->header; - total = rpm->hpos; - break; - } - /* Calculate 'Header' length. */ - section = archive_be32dec(rpm->header+8); - bytes = archive_be32dec(rpm->header+12); - rpm->hlen = 16 + section * 16 + bytes; - rpm->state = ST_HEADER_DATA; - rpm->first_header = 0; - } - break; - case ST_HEADER_DATA: - n = rpm->hlen - rpm->hpos; - if (n > avail_in - used) - n = avail_in - used; - b += n; - used += n; - rpm->hpos += n; - if (rpm->hpos == rpm->hlen) - rpm->state = ST_PADDING; - break; - case ST_PADDING: - while (used < (size_t)avail_in) { - if (*b != 0) { - /* Read next header. */ - rpm->state = ST_HEADER; - rpm->hpos = 0; - rpm->hlen = 0; - break; - } - b++; - used++; - } - break; - case ST_ARCHIVE: - *buff = b; - total = avail_in; - used = avail_in; - break; - } - if (used == (size_t)avail_in) { - rpm->total_in += used; - __archive_read_filter_consume(self->upstream, used); - b = NULL; - used = 0; - } - } while (total == 0 && avail_in > 0); - - if (used > 0 && b != NULL) { - rpm->total_in += used; - __archive_read_filter_consume(self->upstream, used); - } - return (total); -} - -static int -rpm_filter_close(struct archive_read_filter *self) -{ - struct rpm *rpm; - - rpm = (struct rpm *)self->data; - free(rpm); - - return (ARCHIVE_OK); -} - diff --git a/lib/libarchive/archive_read_support_compression_uu.c b/lib/libarchive/archive_read_support_compression_uu.c deleted file mode 100644 index 1b6a54c..0000000 --- a/lib/libarchive/archive_read_support_compression_uu.c +++ /dev/null @@ -1,637 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -struct uudecode { - int64_t total; - unsigned char *in_buff; -#define IN_BUFF_SIZE (1024) - int in_cnt; - size_t in_allocated; - unsigned char *out_buff; -#define OUT_BUFF_SIZE (64 * 1024) - int state; -#define ST_FIND_HEAD 0 -#define ST_READ_UU 1 -#define ST_UUEND 2 -#define ST_READ_BASE64 3 -}; - -static int uudecode_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *filter); -static int uudecode_bidder_init(struct archive_read_filter *); - -static ssize_t uudecode_filter_read(struct archive_read_filter *, - const void **); -static int uudecode_filter_close(struct archive_read_filter *); - -int -archive_read_support_compression_uu(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder; - - bidder = __archive_read_get_bidder(a); - archive_clear_error(_a); - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = uudecode_bidder_bid; - bidder->init = uudecode_bidder_init; - bidder->options = NULL; - bidder->free = NULL; - return (ARCHIVE_OK); -} - -static const unsigned char ascii[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\n', 0, 0, '\r', 0, 0, /* 00 - 0F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30 - 3F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, /* 70 - 7F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */ -}; - -static const unsigned char uuchar[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30 - 3F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 70 - 7F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */ -}; - -static const unsigned char base64[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, /* 20 - 2F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 30 - 3F */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 50 - 5F */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 70 - 7F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */ -}; - -static const int base64num[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 62, 0, 0, 0, 63, /* 20 - 2F */ - 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 0, 0, 0, 0, 0, 0, /* 30 - 3F */ - 0, 0, 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, /* 40 - 4F */ - 15, 16, 17, 18, 19, 20, 21, 22, - 23, 24, 25, 0, 0, 0, 0, 0, /* 50 - 5F */ - 0, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, /* 60 - 6F */ - 41, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, 0, 0, 0, 0, 0, /* 70 - 7F */ -}; - -static ssize_t -get_line(const unsigned char *b, ssize_t avail, ssize_t *nlsize) -{ - ssize_t len; - - len = 0; - while (len < avail) { - switch (ascii[*b]) { - case 0: /* Non-ascii character or control character. */ - if (nlsize != NULL) - *nlsize = 0; - return (-1); - case '\r': - if (avail-len > 1 && b[1] == '\n') { - if (nlsize != NULL) - *nlsize = 2; - return (len+2); - } - /* FALL THROUGH */ - case '\n': - if (nlsize != NULL) - *nlsize = 1; - return (len+1); - case 1: - b++; - len++; - break; - } - } - if (nlsize != NULL) - *nlsize = 0; - return (avail); -} - -static ssize_t -bid_get_line(struct archive_read_filter *filter, - const unsigned char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl) -{ - ssize_t len; - int quit; - - quit = 0; - if (*avail == 0) { - *nl = 0; - len = 0; - } else - len = get_line(*b, *avail, nl); - /* - * Read bytes more while it does not reach the end of line. - */ - while (*nl == 0 && len == *avail && !quit) { - ssize_t diff = *ravail - *avail; - - *b = __archive_read_filter_ahead(filter, 160 + *ravail, avail); - if (*b == NULL) { - if (*ravail >= *avail) - return (0); - /* Reading bytes reaches the end of file. */ - *b = __archive_read_filter_ahead(filter, *avail, avail); - quit = 1; - } - *ravail = *avail; - *b += diff; - *avail -= diff; - len = get_line(*b, *avail, nl); - } - return (len); -} - -#define UUDECODE(c) (((c) - 0x20) & 0x3f) - -static int -uudecode_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - const unsigned char *b; - ssize_t avail, ravail; - ssize_t len, nl; - int l; - int firstline; - - (void)self; /* UNUSED */ - - b = __archive_read_filter_ahead(filter, 1, &avail); - if (b == NULL) - return (0); - - firstline = 20; - ravail = avail; - for (;;) { - len = bid_get_line(filter, &b, &avail, &ravail, &nl); - if (len < 0 || nl == 0) - return (0);/* Binary data. */ - if (memcmp(b, "begin ", 6) == 0 && len - nl >= 11) - l = 6; - else if (memcmp(b, "begin-base64 ", 13) == 0 && len - nl >= 18) - l = 13; - else - l = 0; - - if (l > 0 && (b[l] < '0' || b[l] > '7' || - b[l+1] < '0' || b[l+1] > '7' || - b[l+2] < '0' || b[l+2] > '7' || b[l+3] != ' ')) - l = 0; - - b += len; - avail -= len; - if (l) - break; - firstline = 0; - } - if (!avail) - return (0); - len = bid_get_line(filter, &b, &avail, &ravail, &nl); - if (len < 0 || nl == 0) - return (0);/* There are non-ascii characters. */ - avail -= len; - - if (l == 6) { - if (!uuchar[*b]) - return (0); - /* Get a length of decoded bytes. */ - l = UUDECODE(*b++); len--; - if (l > 45) - /* Normally, maximum length is 45(character 'M'). */ - return (0); - while (l && len-nl > 0) { - if (l > 0) { - if (!uuchar[*b++]) - return (0); - if (!uuchar[*b++]) - return (0); - len -= 2; - --l; - } - if (l > 0) { - if (!uuchar[*b++]) - return (0); - --len; - --l; - } - if (l > 0) { - if (!uuchar[*b++]) - return (0); - --len; - --l; - } - } - if (len-nl < 0) - return (0); - if (len-nl == 1 && - (uuchar[*b] || /* Check sum. */ - (*b >= 'a' && *b <= 'z'))) {/* Padding data(MINIX). */ - ++b; - --len; - } - b += nl; - if (avail && uuchar[*b]) - return (firstline+30); - } - if (l == 13) { - while (len-nl > 0) { - if (!base64[*b++]) - return (0); - --len; - } - b += nl; - - if (avail >= 5 && memcmp(b, "====\n", 5) == 0) - return (firstline+40); - if (avail >= 6 && memcmp(b, "====\r\n", 6) == 0) - return (firstline+40); - if (avail > 0 && base64[*b]) - return (firstline+30); - } - - return (0); -} - -static int -uudecode_bidder_init(struct archive_read_filter *self) -{ - struct uudecode *uudecode; - void *out_buff; - void *in_buff; - - self->code = ARCHIVE_COMPRESSION_UU; - self->name = "uu"; - self->read = uudecode_filter_read; - self->skip = NULL; /* not supported */ - self->close = uudecode_filter_close; - - uudecode = (struct uudecode *)calloc(sizeof(*uudecode), 1); - out_buff = malloc(OUT_BUFF_SIZE); - in_buff = malloc(IN_BUFF_SIZE); - if (uudecode == NULL || out_buff == NULL || in_buff == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for uudecode"); - free(uudecode); - free(out_buff); - free(in_buff); - return (ARCHIVE_FATAL); - } - - self->data = uudecode; - uudecode->in_buff = in_buff; - uudecode->in_cnt = 0; - uudecode->in_allocated = IN_BUFF_SIZE; - uudecode->out_buff = out_buff; - uudecode->state = ST_FIND_HEAD; - - return (ARCHIVE_OK); -} - -static int -ensure_in_buff_size(struct archive_read_filter *self, - struct uudecode *uudecode, size_t size) -{ - - if (size > uudecode->in_allocated) { - unsigned char *ptr; - size_t newsize; - - /* - * Calculate a new buffer size for in_buff. - * Increase its value until it has enough size we need. - */ - newsize = uudecode->in_allocated; - do { - if (newsize < IN_BUFF_SIZE*32) - newsize <<= 1; - else - newsize += IN_BUFF_SIZE; - } while (size > newsize); - ptr = malloc(newsize); - if (ptr == NULL || - newsize < uudecode->in_allocated) { - free(ptr); - archive_set_error(&self->archive->archive, - ENOMEM, - "Can't allocate data for uudecode"); - return (ARCHIVE_FATAL); - } - if (uudecode->in_cnt) - memmove(ptr, uudecode->in_buff, - uudecode->in_cnt); - free(uudecode->in_buff); - uudecode->in_buff = ptr; - uudecode->in_allocated = newsize; - } - return (ARCHIVE_OK); -} - -static ssize_t -uudecode_filter_read(struct archive_read_filter *self, const void **buff) -{ - struct uudecode *uudecode; - const unsigned char *b, *d; - unsigned char *out; - ssize_t avail_in, ravail; - ssize_t used; - ssize_t total; - ssize_t len, llen, nl; - - uudecode = (struct uudecode *)self->data; - -read_more: - d = __archive_read_filter_ahead(self->upstream, 1, &avail_in); - if (d == NULL && avail_in < 0) - return (ARCHIVE_FATAL); - /* Quiet a code analyzer; make sure avail_in must be zero - * when d is NULL. */ - if (d == NULL) - avail_in = 0; - used = 0; - total = 0; - out = uudecode->out_buff; - ravail = avail_in; - if (uudecode->in_cnt) { - /* - * If there is remaining data which is saved by - * previous calling, use it first. - */ - if (ensure_in_buff_size(self, uudecode, - avail_in + uudecode->in_cnt) != ARCHIVE_OK) - return (ARCHIVE_FATAL); - memcpy(uudecode->in_buff + uudecode->in_cnt, - d, avail_in); - d = uudecode->in_buff; - avail_in += uudecode->in_cnt; - uudecode->in_cnt = 0; - } - for (;used < avail_in; d += llen, used += llen) { - int l, body; - - b = d; - len = get_line(b, avail_in - used, &nl); - if (len < 0) { - /* Non-ascii character is found. */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Insufficient compressed data"); - return (ARCHIVE_FATAL); - } - llen = len; - if (nl == 0) { - /* - * Save remaining data which does not contain - * NL('\n','\r'). - */ - if (ensure_in_buff_size(self, uudecode, len) - != ARCHIVE_OK) - return (ARCHIVE_FATAL); - if (uudecode->in_buff != b) - memmove(uudecode->in_buff, b, len); - uudecode->in_cnt = len; - if (total == 0) { - /* Do not return 0; it means end-of-file. - * We should try to read bytes more. */ - __archive_read_filter_consume( - self->upstream, ravail); - goto read_more; - } - break; - } - if (total + len * 2 > OUT_BUFF_SIZE) - break; - switch (uudecode->state) { - default: - case ST_FIND_HEAD: - if (len - nl >= 11 && memcmp(b, "begin ", 6) == 0) - l = 6; - else if (len - nl >= 18 && - memcmp(b, "begin-base64 ", 13) == 0) - l = 13; - else - l = 0; - if (l != 0 && b[l] >= '0' && b[l] <= '7' && - b[l+1] >= '0' && b[l+1] <= '7' && - b[l+2] >= '0' && b[l+2] <= '7' && b[l+3] == ' ') { - if (l == 6) - uudecode->state = ST_READ_UU; - else - uudecode->state = ST_READ_BASE64; - } - break; - case ST_READ_UU: - body = len - nl; - if (!uuchar[*b] || body <= 0) { - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Insufficient compressed data"); - return (ARCHIVE_FATAL); - } - /* Get length of undecoded bytes of curent line. */ - l = UUDECODE(*b++); - body--; - if (l > body) { - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Insufficient compressed data"); - return (ARCHIVE_FATAL); - } - if (l == 0) { - uudecode->state = ST_UUEND; - break; - } - while (l > 0) { - int n = 0; - - if (l > 0) { - if (!uuchar[b[0]] || !uuchar[b[1]]) - break; - n = UUDECODE(*b++) << 18; - n |= UUDECODE(*b++) << 12; - *out++ = n >> 16; total++; - --l; - } - if (l > 0) { - if (!uuchar[b[0]]) - break; - n |= UUDECODE(*b++) << 6; - *out++ = (n >> 8) & 0xFF; total++; - --l; - } - if (l > 0) { - if (!uuchar[b[0]]) - break; - n |= UUDECODE(*b++); - *out++ = n & 0xFF; total++; - --l; - } - } - if (l) { - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Insufficient compressed data"); - return (ARCHIVE_FATAL); - } - break; - case ST_UUEND: - if (len - nl == 3 && memcmp(b, "end ", 3) == 0) - uudecode->state = ST_FIND_HEAD; - else { - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Insufficient compressed data"); - return (ARCHIVE_FATAL); - } - break; - case ST_READ_BASE64: - l = len - nl; - if (l >= 3 && b[0] == '=' && b[1] == '=' && - b[2] == '=') { - uudecode->state = ST_FIND_HEAD; - break; - } - while (l > 0) { - int n = 0; - - if (l > 0) { - if (!base64[b[0]] || !base64[b[1]]) - break; - n = base64num[*b++] << 18; - n |= base64num[*b++] << 12; - *out++ = n >> 16; total++; - l -= 2; - } - if (l > 0) { - if (*b == '=') - break; - if (!base64[*b]) - break; - n |= base64num[*b++] << 6; - *out++ = (n >> 8) & 0xFF; total++; - --l; - } - if (l > 0) { - if (*b == '=') - break; - if (!base64[*b]) - break; - n |= base64num[*b++]; - *out++ = n & 0xFF; total++; - --l; - } - } - if (l && *b != '=') { - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Insufficient compressed data"); - return (ARCHIVE_FATAL); - } - break; - } - } - - __archive_read_filter_consume(self->upstream, ravail); - - *buff = uudecode->out_buff; - uudecode->total += total; - return (total); -} - -static int -uudecode_filter_close(struct archive_read_filter *self) -{ - struct uudecode *uudecode; - - uudecode = (struct uudecode *)self->data; - free(uudecode->in_buff); - free(uudecode->out_buff); - free(uudecode); - - return (ARCHIVE_OK); -} - diff --git a/lib/libarchive/archive_read_support_compression_xz.c b/lib/libarchive/archive_read_support_compression_xz.c deleted file mode 100644 index 1554d99..0000000 --- a/lib/libarchive/archive_read_support_compression_xz.c +++ /dev/null @@ -1,708 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2008 Tim Kientzle and Miklos Vajna - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" - -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#if HAVE_LZMA_H -#include -#elif HAVE_LZMADEC_H -#include -#endif - -#include "archive.h" -#include "archive_endian.h" -#include "archive_private.h" -#include "archive_read_private.h" - -#if HAVE_LZMA_H && HAVE_LIBLZMA - -struct private_data { - lzma_stream stream; - unsigned char *out_block; - size_t out_block_size; - int64_t total_out; - char eof; /* True = found end of compressed data. */ -}; - -/* Combined lzma/xz filter */ -static ssize_t xz_filter_read(struct archive_read_filter *, const void **); -static int xz_filter_close(struct archive_read_filter *); -static int xz_lzma_bidder_init(struct archive_read_filter *); - -#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC - -struct private_data { - lzmadec_stream stream; - unsigned char *out_block; - size_t out_block_size; - int64_t total_out; - char eof; /* True = found end of compressed data. */ -}; - -/* Lzma-only filter */ -static ssize_t lzma_filter_read(struct archive_read_filter *, const void **); -static int lzma_filter_close(struct archive_read_filter *); -#endif - -/* - * Note that we can detect xz and lzma compressed files even if we - * can't decompress them. (In fact, we like detecting them because we - * can give better error messages.) So the bid framework here gets - * compiled even if no lzma library is available. - */ -static int xz_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *); -static int xz_bidder_init(struct archive_read_filter *); -static int lzma_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *); -static int lzma_bidder_init(struct archive_read_filter *); - -int -archive_read_support_compression_xz(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a); - - archive_clear_error(_a); - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = xz_bidder_bid; - bidder->init = xz_bidder_init; - bidder->options = NULL; - bidder->free = NULL; -#if HAVE_LZMA_H && HAVE_LIBLZMA - return (ARCHIVE_OK); -#else - archive_set_error(_a, ARCHIVE_ERRNO_MISC, - "Using external unxz program for xz decompression"); - return (ARCHIVE_WARN); -#endif -} - -int -archive_read_support_compression_lzma(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a); - - archive_clear_error(_a); - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = lzma_bidder_bid; - bidder->init = lzma_bidder_init; - bidder->options = NULL; - bidder->free = NULL; -#if HAVE_LZMA_H && HAVE_LIBLZMA - return (ARCHIVE_OK); -#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC - return (ARCHIVE_OK); -#else - archive_set_error(_a, ARCHIVE_ERRNO_MISC, - "Using external unlzma program for lzma decompression"); - return (ARCHIVE_WARN); -#endif -} - -/* - * Test whether we can handle this data. - */ -static int -xz_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - const unsigned char *buffer; - ssize_t avail; - int bits_checked; - - (void)self; /* UNUSED */ - - buffer = __archive_read_filter_ahead(filter, 6, &avail); - if (buffer == NULL) - return (0); - - /* - * Verify Header Magic Bytes : FD 37 7A 58 5A 00 - */ - bits_checked = 0; - if (buffer[0] != 0xFD) - return (0); - bits_checked += 8; - if (buffer[1] != 0x37) - return (0); - bits_checked += 8; - if (buffer[2] != 0x7A) - return (0); - bits_checked += 8; - if (buffer[3] != 0x58) - return (0); - bits_checked += 8; - if (buffer[4] != 0x5A) - return (0); - bits_checked += 8; - if (buffer[5] != 0x00) - return (0); - bits_checked += 8; - - return (bits_checked); -} - -/* - * Test whether we can handle this data. - * - * LZMA has a rather poor file signature. Zeros do not - * make good signature bytes as a rule, and the only non-zero byte - * here is an ASCII character. For example, an uncompressed tar - * archive whose first file is ']' would satisfy this check. It may - * be necessary to exclude LZMA from compression_all() because of - * this. Clients of libarchive would then have to explicitly enable - * LZMA checking instead of (or in addition to) compression_all() when - * they have other evidence (file name, command-line option) to go on. - */ -static int -lzma_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - const unsigned char *buffer; - ssize_t avail; - uint32_t dicsize; - uint64_t uncompressed_size; - int bits_checked; - - (void)self; /* UNUSED */ - - buffer = __archive_read_filter_ahead(filter, 14, &avail); - if (buffer == NULL) - return (0); - - /* First byte of raw LZMA stream is commonly 0x5d. - * The first byte is a special number, which consists of - * three parameters of LZMA compression, a number of literal - * context bits(which is from 0 to 8, default is 3), a number - * of literal pos bits(which is from 0 to 4, default is 0), - * a number of pos bits(which is from 0 to 4, default is 2). - * The first byte is made by - * (pos bits * 5 + literal pos bit) * 9 + * literal contest bit, - * and so the default value in this field is - * (2 * 5 + 0) * 9 + 3 = 0x5d. - * lzma of LZMA SDK has options to change those parameters. - * It means a range of this field is from 0 to 224. And lzma of - * XZ Utils with option -e records 0x5e in this field. */ - /* NOTE: If this checking of the first byte increases false - * recognition, we should allow only 0x5d and 0x5e for the first - * byte of LZMA stream. */ - bits_checked = 0; - if (buffer[0] > (4 * 5 + 4) * 9 + 8) - return (0); - /* Most likely value in the first byte of LZMA stream. */ - if (buffer[0] == 0x5d || buffer[0] == 0x5e) - bits_checked += 8; - - /* Sixth through fourteenth bytes are uncompressed size, - * stored in little-endian order. `-1' means uncompressed - * size is unknown and lzma of XZ Utils always records `-1' - * in this field. */ - uncompressed_size = archive_le64dec(buffer+5); - if (uncompressed_size == (uint64_t)ARCHIVE_LITERAL_LL(-1)) - bits_checked += 64; - - /* Second through fifth bytes are dictionary size, stored in - * little-endian order. The minimum dictionary size is - * 1 << 12(4KiB) which the lzma of LZMA SDK uses with option - * -d12 and the maxinam dictionary size is 1 << 27(128MiB) - * which the one uses with option -d27. - * NOTE: A comment of LZMA SDK source code says this dictionary - * range is from 1 << 12 to 1 << 30. */ - dicsize = archive_le32dec(buffer+1); - switch (dicsize) { - case 0x00001000:/* lzma of LZMA SDK option -d12. */ - case 0x00002000:/* lzma of LZMA SDK option -d13. */ - case 0x00004000:/* lzma of LZMA SDK option -d14. */ - case 0x00008000:/* lzma of LZMA SDK option -d15. */ - case 0x00010000:/* lzma of XZ Utils option -0 and -1. - * lzma of LZMA SDK option -d16. */ - case 0x00020000:/* lzma of LZMA SDK option -d17. */ - case 0x00040000:/* lzma of LZMA SDK option -d18. */ - case 0x00080000:/* lzma of XZ Utils option -2. - * lzma of LZMA SDK option -d19. */ - case 0x00100000:/* lzma of XZ Utils option -3. - * lzma of LZMA SDK option -d20. */ - case 0x00200000:/* lzma of XZ Utils option -4. - * lzma of LZMA SDK option -d21. */ - case 0x00400000:/* lzma of XZ Utils option -5. - * lzma of LZMA SDK option -d22. */ - case 0x00800000:/* lzma of XZ Utils option -6. - * lzma of LZMA SDK option -d23. */ - case 0x01000000:/* lzma of XZ Utils option -7. - * lzma of LZMA SDK option -d24. */ - case 0x02000000:/* lzma of XZ Utils option -8. - * lzma of LZMA SDK option -d25. */ - case 0x04000000:/* lzma of XZ Utils option -9. - * lzma of LZMA SDK option -d26. */ - case 0x08000000:/* lzma of LZMA SDK option -d27. */ - bits_checked += 32; - break; - default: - /* If a memory usage for encoding was not enough on - * the platform where LZMA stream was made, lzma of - * XZ Utils automatically decreased the dictionary - * size to enough memory for encoding by 1Mi bytes - * (1 << 20).*/ - if (dicsize <= 0x03F00000 && dicsize >= 0x00300000 && - (dicsize & ((1 << 20)-1)) == 0 && - bits_checked == 8 + 64) { - bits_checked += 32; - break; - } - /* Otherwise dictionary size is unlikely. But it is - * possible that someone makes lzma stream with - * liblzma/LZMA SDK in one's dictionary size. */ - return (0); - } - - /* TODO: The above test is still very weak. It would be - * good to do better. */ - - return (bits_checked); -} - -#if HAVE_LZMA_H && HAVE_LIBLZMA - -/* - * liblzma 4.999.7 and later support both lzma and xz streams. - */ -static int -xz_bidder_init(struct archive_read_filter *self) -{ - self->code = ARCHIVE_COMPRESSION_XZ; - self->name = "xz"; - return (xz_lzma_bidder_init(self)); -} - -static int -lzma_bidder_init(struct archive_read_filter *self) -{ - self->code = ARCHIVE_COMPRESSION_LZMA; - self->name = "lzma"; - return (xz_lzma_bidder_init(self)); -} - -/* - * Setup the callbacks. - */ -static int -xz_lzma_bidder_init(struct archive_read_filter *self) -{ - static const size_t out_block_size = 64 * 1024; - void *out_block; - struct private_data *state; - int ret; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = (unsigned char *)malloc(out_block_size); - if (state == NULL || out_block == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for xz decompression"); - free(out_block); - free(state); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = xz_filter_read; - self->skip = NULL; /* not supported */ - self->close = xz_filter_close; - - state->stream.avail_in = 0; - - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Initialize compression library. - * TODO: I don't know what value is best for memlimit. - * maybe, it needs to check memory size which - * running system has. - */ - if (self->code == ARCHIVE_COMPRESSION_XZ) - ret = lzma_stream_decoder(&(state->stream), - (1U << 30),/* memlimit */ - LZMA_CONCATENATED); - else - ret = lzma_alone_decoder(&(state->stream), - (1U << 30));/* memlimit */ - - if (ret == LZMA_OK) - return (ARCHIVE_OK); - - /* Library setup failed: Choose an error message and clean up. */ - switch (ret) { - case LZMA_MEM_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Internal error initializing compression library: " - "Cannot allocate memory"); - break; - case LZMA_OPTIONS_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "Invalid or unsupported options"); - break; - default: - archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing lzma library"); - break; - } - - free(state->out_block); - free(state); - self->data = NULL; - return (ARCHIVE_FATAL); -} - -/* - * Return the next block of decompressed data. - */ -static ssize_t -xz_filter_read(struct archive_read_filter *self, const void **p) -{ - struct private_data *state; - size_t decompressed; - ssize_t avail_in; - int ret; - - state = (struct private_data *)self->data; - - /* Empty our output buffer. */ - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Try to fill the output buffer. */ - while (state->stream.avail_out > 0 && !state->eof) { - state->stream.next_in = - __archive_read_filter_ahead(self->upstream, 1, &avail_in); - if (state->stream.next_in == NULL && avail_in < 0) - return (ARCHIVE_FATAL); - state->stream.avail_in = avail_in; - - /* Decompress as much as we can in one pass. */ - ret = lzma_code(&(state->stream), - (state->stream.avail_in == 0)? LZMA_FINISH: LZMA_RUN); - switch (ret) { - case LZMA_STREAM_END: /* Found end of stream. */ - state->eof = 1; - /* FALL THROUGH */ - case LZMA_OK: /* Decompressor made some progress. */ - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - break; - case LZMA_MEM_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Lzma library error: Cannot allocate memory"); - return (ARCHIVE_FATAL); - case LZMA_MEMLIMIT_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Lzma library error: Out of memory"); - return (ARCHIVE_FATAL); - case LZMA_FORMAT_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma library error: format not recognized"); - return (ARCHIVE_FATAL); - case LZMA_OPTIONS_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma library error: Invalid options"); - return (ARCHIVE_FATAL); - case LZMA_DATA_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma library error: Corrupted input data"); - return (ARCHIVE_FATAL); - case LZMA_BUF_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma library error: No progress is possible"); - return (ARCHIVE_FATAL); - default: - /* Return an error. */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma decompression failed: Unknown error"); - return (ARCHIVE_FATAL); - } - } - - decompressed = state->stream.next_out - state->out_block; - state->total_out += decompressed; - if (decompressed == 0) - *p = NULL; - else - *p = state->out_block; - return (decompressed); -} - -/* - * Clean up the decompressor. - */ -static int -xz_filter_close(struct archive_read_filter *self) -{ - struct private_data *state; - - state = (struct private_data *)self->data; - lzma_end(&(state->stream)); - free(state->out_block); - free(state); - return (ARCHIVE_OK); -} - -#else - -#if HAVE_LZMADEC_H && HAVE_LIBLZMADEC - -/* - * If we have the older liblzmadec library, then we can handle - * LZMA streams but not XZ streams. - */ - -/* - * Setup the callbacks. - */ -static int -lzma_bidder_init(struct archive_read_filter *self) -{ - static const size_t out_block_size = 64 * 1024; - void *out_block; - struct private_data *state; - ssize_t ret, avail_in; - - self->code = ARCHIVE_COMPRESSION_LZMA; - self->name = "lzma"; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = (unsigned char *)malloc(out_block_size); - if (state == NULL || out_block == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for lzma decompression"); - free(out_block); - free(state); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = lzma_filter_read; - self->skip = NULL; /* not supported */ - self->close = lzma_filter_close; - - /* Prime the lzma library with 18 bytes of input. */ - state->stream.next_in = (unsigned char *)(uintptr_t) - __archive_read_filter_ahead(self->upstream, 18, &avail_in); - if (state->stream.next_in == NULL) - return (ARCHIVE_FATAL); - state->stream.avail_in = avail_in; - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Initialize compression library. */ - ret = lzmadec_init(&(state->stream)); - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - if (ret == LZMADEC_OK) - return (ARCHIVE_OK); - - /* Library setup failed: Clean up. */ - archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing lzma library"); - - /* Override the error message if we know what really went wrong. */ - switch (ret) { - case LZMADEC_HEADER_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "invalid header"); - break; - case LZMADEC_MEM_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Internal error initializing compression library: " - "out of memory"); - break; - } - - free(state->out_block); - free(state); - self->data = NULL; - return (ARCHIVE_FATAL); -} - -/* - * Return the next block of decompressed data. - */ -static ssize_t -lzma_filter_read(struct archive_read_filter *self, const void **p) -{ - struct private_data *state; - size_t decompressed; - ssize_t avail_in, ret; - - state = (struct private_data *)self->data; - - /* Empty our output buffer. */ - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Try to fill the output buffer. */ - while (state->stream.avail_out > 0 && !state->eof) { - state->stream.next_in = (unsigned char *)(uintptr_t) - __archive_read_filter_ahead(self->upstream, 1, &avail_in); - if (state->stream.next_in == NULL && avail_in < 0) - return (ARCHIVE_FATAL); - state->stream.avail_in = avail_in; - - /* Decompress as much as we can in one pass. */ - ret = lzmadec_decode(&(state->stream), avail_in == 0); - switch (ret) { - case LZMADEC_STREAM_END: /* Found end of stream. */ - state->eof = 1; - /* FALL THROUGH */ - case LZMADEC_OK: /* Decompressor made some progress. */ - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - break; - case LZMADEC_BUF_ERROR: /* Insufficient input data? */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Insufficient compressed data"); - return (ARCHIVE_FATAL); - default: - /* Return an error. */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma decompression failed"); - return (ARCHIVE_FATAL); - } - } - - decompressed = state->stream.next_out - state->out_block; - state->total_out += decompressed; - if (decompressed == 0) - *p = NULL; - else - *p = state->out_block; - return (decompressed); -} - -/* - * Clean up the decompressor. - */ -static int -lzma_filter_close(struct archive_read_filter *self) -{ - struct private_data *state; - int ret; - - state = (struct private_data *)self->data; - ret = ARCHIVE_OK; - switch (lzmadec_end(&(state->stream))) { - case LZMADEC_OK: - break; - default: - archive_set_error(&(self->archive->archive), - ARCHIVE_ERRNO_MISC, - "Failed to clean up %s compressor", - self->archive->archive.compression_name); - ret = ARCHIVE_FATAL; - } - - free(state->out_block); - free(state); - return (ret); -} - -#else - -/* - * - * If we have no suitable library on this system, we can't actually do - * the decompression. We can, however, still detect compressed - * archives and emit a useful message. - * - */ -static int -lzma_bidder_init(struct archive_read_filter *self) -{ - int r; - - r = __archive_read_program(self, "unlzma"); - /* Note: We set the format here even if __archive_read_program() - * above fails. We do, after all, know what the format is - * even if we weren't able to read it. */ - self->code = ARCHIVE_COMPRESSION_LZMA; - self->name = "lzma"; - return (r); -} - -#endif /* HAVE_LZMADEC_H */ - - -static int -xz_bidder_init(struct archive_read_filter *self) -{ - int r; - - r = __archive_read_program(self, "unxz"); - /* Note: We set the format here even if __archive_read_program() - * above fails. We do, after all, know what the format is - * even if we weren't able to read it. */ - self->code = ARCHIVE_COMPRESSION_XZ; - self->name = "xz"; - return (r); -} - - -#endif /* HAVE_LZMA_H */ diff --git a/lib/libarchive/archive_read_support_format_all.c b/lib/libarchive/archive_read_support_format_all.c deleted file mode 100644 index e57cd43..0000000 --- a/lib/libarchive/archive_read_support_format_all.c +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c) 2003-2011 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#include "archive.h" - -int -archive_read_support_format_all(struct archive *a) -{ - archive_read_support_format_ar(a); - archive_read_support_format_cpio(a); - archive_read_support_format_empty(a); - archive_read_support_format_iso9660(a); - archive_read_support_format_mtree(a); - archive_read_support_format_tar(a); - archive_read_support_format_xar(a); - archive_read_support_format_zip(a); - - /* Note: We always return ARCHIVE_OK here, even if some of the - * above return ARCHIVE_WARN. The intent here is to enable - * "as much as possible." Clients who need specific - * compression should enable those individually so they can - * verify the level of support. */ - /* Clear any warning messages set by the above functions. */ - archive_clear_error(a); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_read_support_format_ar.c b/lib/libarchive/archive_read_support_format_ar.c deleted file mode 100644 index 8b95f22..0000000 --- a/lib/libarchive/archive_read_support_format_ar.c +++ /dev/null @@ -1,584 +0,0 @@ -/*- - * Copyright (c) 2007 Kai Wang - * Copyright (c) 2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_LIMITS_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" - -struct ar { - off_t entry_bytes_remaining; - off_t entry_offset; - off_t entry_padding; - char *strtab; - size_t strtab_size; -}; - -/* - * Define structure of the "ar" header. - */ -#define AR_name_offset 0 -#define AR_name_size 16 -#define AR_date_offset 16 -#define AR_date_size 12 -#define AR_uid_offset 28 -#define AR_uid_size 6 -#define AR_gid_offset 34 -#define AR_gid_size 6 -#define AR_mode_offset 40 -#define AR_mode_size 8 -#define AR_size_offset 48 -#define AR_size_size 10 -#define AR_fmag_offset 58 -#define AR_fmag_size 2 - -static int archive_read_format_ar_bid(struct archive_read *a); -static int archive_read_format_ar_cleanup(struct archive_read *a); -static int archive_read_format_ar_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset); -static int archive_read_format_ar_skip(struct archive_read *a); -static int archive_read_format_ar_read_header(struct archive_read *a, - struct archive_entry *e); -static uint64_t ar_atol8(const char *p, unsigned char_cnt); -static uint64_t ar_atol10(const char *p, unsigned char_cnt); -static int ar_parse_gnu_filename_table(struct archive_read *a); -static int ar_parse_common_header(struct ar *ar, struct archive_entry *, - const char *h); - -int -archive_read_support_format_ar(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct ar *ar; - int r; - - ar = (struct ar *)malloc(sizeof(*ar)); - if (ar == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate ar data"); - return (ARCHIVE_FATAL); - } - memset(ar, 0, sizeof(*ar)); - ar->strtab = NULL; - - r = __archive_read_register_format(a, - ar, - "ar", - archive_read_format_ar_bid, - NULL, - archive_read_format_ar_read_header, - archive_read_format_ar_read_data, - archive_read_format_ar_skip, - archive_read_format_ar_cleanup); - - if (r != ARCHIVE_OK) { - free(ar); - return (r); - } - return (ARCHIVE_OK); -} - -static int -archive_read_format_ar_cleanup(struct archive_read *a) -{ - struct ar *ar; - - ar = (struct ar *)(a->format->data); - if (ar->strtab) - free(ar->strtab); - free(ar); - (a->format->data) = NULL; - return (ARCHIVE_OK); -} - -static int -archive_read_format_ar_bid(struct archive_read *a) -{ - const void *h; - - if (a->archive.archive_format != 0 && - (a->archive.archive_format & ARCHIVE_FORMAT_BASE_MASK) != - ARCHIVE_FORMAT_AR) - return(0); - - /* - * Verify the 8-byte file signature. - * TODO: Do we need to check more than this? - */ - if ((h = __archive_read_ahead(a, 8, NULL)) == NULL) - return (-1); - if (strncmp((const char*)h, "!\n", 8) == 0) { - return (64); - } - return (-1); -} - -static int -archive_read_format_ar_read_header(struct archive_read *a, - struct archive_entry *entry) -{ - char filename[AR_name_size + 1]; - struct ar *ar; - uint64_t number; /* Used to hold parsed numbers before validation. */ - ssize_t bytes_read; - size_t bsd_name_length, entry_size; - char *p, *st; - const void *b; - const char *h; - int r; - - ar = (struct ar*)(a->format->data); - - if (a->archive.file_position == 0) { - /* - * We are now at the beginning of the archive, - * so we need first consume the ar global header. - */ - __archive_read_consume(a, 8); - /* Set a default format code for now. */ - a->archive.archive_format = ARCHIVE_FORMAT_AR; - } - - /* Read the header for the next file entry. */ - if ((b = __archive_read_ahead(a, 60, &bytes_read)) == NULL) - /* Broken header. */ - return (ARCHIVE_EOF); - __archive_read_consume(a, 60); - h = (const char *)b; - - /* Verify the magic signature on the file header. */ - if (strncmp(h + AR_fmag_offset, "`\n", 2) != 0) { - archive_set_error(&a->archive, EINVAL, - "Incorrect file header signature"); - return (ARCHIVE_WARN); - } - - /* Copy filename into work buffer. */ - strncpy(filename, h + AR_name_offset, AR_name_size); - filename[AR_name_size] = '\0'; - - /* - * Guess the format variant based on the filename. - */ - if (a->archive.archive_format == ARCHIVE_FORMAT_AR) { - /* We don't already know the variant, so let's guess. */ - /* - * Biggest clue is presence of '/': GNU starts special - * filenames with '/', appends '/' as terminator to - * non-special names, so anything with '/' should be - * GNU except for BSD long filenames. - */ - if (strncmp(filename, "#1/", 3) == 0) - a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; - else if (strchr(filename, '/') != NULL) - a->archive.archive_format = ARCHIVE_FORMAT_AR_GNU; - else if (strncmp(filename, "__.SYMDEF", 9) == 0) - a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; - /* - * XXX Do GNU/SVR4 'ar' programs ever omit trailing '/' - * if name exactly fills 16-byte field? If so, we - * can't assume entries without '/' are BSD. XXX - */ - } - - /* Update format name from the code. */ - if (a->archive.archive_format == ARCHIVE_FORMAT_AR_GNU) - a->archive.archive_format_name = "ar (GNU/SVR4)"; - else if (a->archive.archive_format == ARCHIVE_FORMAT_AR_BSD) - a->archive.archive_format_name = "ar (BSD)"; - else - a->archive.archive_format_name = "ar"; - - /* - * Remove trailing spaces from the filename. GNU and BSD - * variants both pad filename area out with spaces. - * This will only be wrong if GNU/SVR4 'ar' implementations - * omit trailing '/' for 16-char filenames and we have - * a 16-char filename that ends in ' '. - */ - p = filename + AR_name_size - 1; - while (p >= filename && *p == ' ') { - *p = '\0'; - p--; - } - - /* - * Remove trailing slash unless first character is '/'. - * (BSD entries never end in '/', so this will only trim - * GNU-format entries. GNU special entries start with '/' - * and are not terminated in '/', so we don't trim anything - * that starts with '/'.) - */ - if (filename[0] != '/' && *p == '/') - *p = '\0'; - - /* - * '//' is the GNU filename table. - * Later entries can refer to names in this table. - */ - if (strcmp(filename, "//") == 0) { - /* This must come before any call to _read_ahead. */ - ar_parse_common_header(ar, entry, h); - archive_entry_copy_pathname(entry, filename); - archive_entry_set_filetype(entry, AE_IFREG); - /* Get the size of the filename table. */ - number = ar_atol10(h + AR_size_offset, AR_size_size); - if (number > SIZE_MAX) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Filename table too large"); - return (ARCHIVE_FATAL); - } - entry_size = (size_t)number; - if (entry_size == 0) { - archive_set_error(&a->archive, EINVAL, - "Invalid string table"); - return (ARCHIVE_WARN); - } - if (ar->strtab != NULL) { - archive_set_error(&a->archive, EINVAL, - "More than one string tables exist"); - return (ARCHIVE_WARN); - } - - /* Read the filename table into memory. */ - st = malloc(entry_size); - if (st == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate filename table buffer"); - return (ARCHIVE_FATAL); - } - ar->strtab = st; - ar->strtab_size = entry_size; - if ((b = __archive_read_ahead(a, entry_size, NULL)) == NULL) - return (ARCHIVE_FATAL); - memcpy(st, b, entry_size); - __archive_read_consume(a, entry_size); - /* All contents are consumed. */ - ar->entry_bytes_remaining = 0; - archive_entry_set_size(entry, ar->entry_bytes_remaining); - - /* Parse the filename table. */ - return (ar_parse_gnu_filename_table(a)); - } - - /* - * GNU variant handles long filenames by storing / - * to indicate a name stored in the filename table. - * XXX TODO: Verify that it's all digits... Don't be fooled - * by "/9xyz" XXX - */ - if (filename[0] == '/' && filename[1] >= '0' && filename[1] <= '9') { - number = ar_atol10(h + AR_name_offset + 1, AR_name_size - 1); - /* - * If we can't look up the real name, warn and return - * the entry with the wrong name. - */ - if (ar->strtab == NULL || number > ar->strtab_size) { - archive_set_error(&a->archive, EINVAL, - "Can't find long filename for entry"); - archive_entry_copy_pathname(entry, filename); - /* Parse the time, owner, mode, size fields. */ - ar_parse_common_header(ar, entry, h); - return (ARCHIVE_WARN); - } - - archive_entry_copy_pathname(entry, &ar->strtab[(size_t)number]); - /* Parse the time, owner, mode, size fields. */ - return (ar_parse_common_header(ar, entry, h)); - } - - /* - * BSD handles long filenames by storing "#1/" followed by the - * length of filename as a decimal number, then prepends the - * the filename to the file contents. - */ - if (strncmp(filename, "#1/", 3) == 0) { - /* Parse the time, owner, mode, size fields. */ - /* This must occur before _read_ahead is called again. */ - ar_parse_common_header(ar, entry, h); - - /* Parse the size of the name, adjust the file size. */ - number = ar_atol10(h + AR_name_offset + 3, AR_name_size - 3); - bsd_name_length = (size_t)number; - /* Guard against the filename + trailing NUL - * overflowing a size_t and against the filename size - * being larger than the entire entry. */ - if (number > (uint64_t)(bsd_name_length + 1) - || (off_t)bsd_name_length > ar->entry_bytes_remaining) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Bad input file size"); - return (ARCHIVE_FATAL); - } - ar->entry_bytes_remaining -= bsd_name_length; - /* Adjust file size reported to client. */ - archive_entry_set_size(entry, ar->entry_bytes_remaining); - - /* Read the long name into memory. */ - if ((b = __archive_read_ahead(a, bsd_name_length, NULL)) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated input file"); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, bsd_name_length); - - /* Store it in the entry. */ - p = (char *)malloc(bsd_name_length + 1); - if (p == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate fname buffer"); - return (ARCHIVE_FATAL); - } - strncpy(p, b, bsd_name_length); - p[bsd_name_length] = '\0'; - archive_entry_copy_pathname(entry, p); - free(p); - return (ARCHIVE_OK); - } - - /* - * "/" is the SVR4/GNU archive symbol table. - */ - if (strcmp(filename, "/") == 0) { - archive_entry_copy_pathname(entry, "/"); - /* Parse the time, owner, mode, size fields. */ - r = ar_parse_common_header(ar, entry, h); - /* Force the file type to a regular file. */ - archive_entry_set_filetype(entry, AE_IFREG); - return (r); - } - - /* - * "__.SYMDEF" is a BSD archive symbol table. - */ - if (strcmp(filename, "__.SYMDEF") == 0) { - archive_entry_copy_pathname(entry, filename); - /* Parse the time, owner, mode, size fields. */ - return (ar_parse_common_header(ar, entry, h)); - } - - /* - * Otherwise, this is a standard entry. The filename - * has already been trimmed as much as possible, based - * on our current knowledge of the format. - */ - archive_entry_copy_pathname(entry, filename); - return (ar_parse_common_header(ar, entry, h)); -} - -static int -ar_parse_common_header(struct ar *ar, struct archive_entry *entry, - const char *h) -{ - uint64_t n; - - /* Copy remaining header */ - archive_entry_set_mtime(entry, - (time_t)ar_atol10(h + AR_date_offset, AR_date_size), 0L); - archive_entry_set_uid(entry, - (uid_t)ar_atol10(h + AR_uid_offset, AR_uid_size)); - archive_entry_set_gid(entry, - (gid_t)ar_atol10(h + AR_gid_offset, AR_gid_size)); - archive_entry_set_mode(entry, - (mode_t)ar_atol8(h + AR_mode_offset, AR_mode_size)); - n = ar_atol10(h + AR_size_offset, AR_size_size); - - ar->entry_offset = 0; - ar->entry_padding = n % 2; - archive_entry_set_size(entry, n); - ar->entry_bytes_remaining = n; - return (ARCHIVE_OK); -} - -static int -archive_read_format_ar_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - ssize_t bytes_read; - struct ar *ar; - - ar = (struct ar *)(a->format->data); - - if (ar->entry_bytes_remaining > 0) { - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read == 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated ar archive"); - return (ARCHIVE_FATAL); - } - if (bytes_read < 0) - return (ARCHIVE_FATAL); - if (bytes_read > ar->entry_bytes_remaining) - bytes_read = (ssize_t)ar->entry_bytes_remaining; - *size = bytes_read; - *offset = ar->entry_offset; - ar->entry_offset += bytes_read; - ar->entry_bytes_remaining -= bytes_read; - __archive_read_consume(a, (size_t)bytes_read); - return (ARCHIVE_OK); - } else { - while (ar->entry_padding > 0) { - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - if (bytes_read > ar->entry_padding) - bytes_read = (ssize_t)ar->entry_padding; - __archive_read_consume(a, (size_t)bytes_read); - ar->entry_padding -= bytes_read; - } - *buff = NULL; - *size = 0; - *offset = ar->entry_offset; - return (ARCHIVE_EOF); - } -} - -static int -archive_read_format_ar_skip(struct archive_read *a) -{ - off_t bytes_skipped; - struct ar* ar; - - ar = (struct ar *)(a->format->data); - - bytes_skipped = __archive_read_skip(a, - ar->entry_bytes_remaining + ar->entry_padding); - if (bytes_skipped < 0) - return (ARCHIVE_FATAL); - - ar->entry_bytes_remaining = 0; - ar->entry_padding = 0; - - return (ARCHIVE_OK); -} - -static int -ar_parse_gnu_filename_table(struct archive_read *a) -{ - struct ar *ar; - char *p; - size_t size; - - ar = (struct ar*)(a->format->data); - size = ar->strtab_size; - - for (p = ar->strtab; p < ar->strtab + size - 1; ++p) { - if (*p == '/') { - *p++ = '\0'; - if (*p != '\n') - goto bad_string_table; - *p = '\0'; - } - } - /* - * GNU ar always pads the table to an even size. - * The pad character is either '\n' or '`'. - */ - if (p != ar->strtab + size && *p != '\n' && *p != '`') - goto bad_string_table; - - /* Enforce zero termination. */ - ar->strtab[size - 1] = '\0'; - - return (ARCHIVE_OK); - -bad_string_table: - archive_set_error(&a->archive, EINVAL, - "Invalid string table"); - free(ar->strtab); - ar->strtab = NULL; - return (ARCHIVE_WARN); -} - -static uint64_t -ar_atol8(const char *p, unsigned char_cnt) -{ - uint64_t l, limit, last_digit_limit; - unsigned int digit, base; - - base = 8; - limit = UINT64_MAX / base; - last_digit_limit = UINT64_MAX % base; - - while ((*p == ' ' || *p == '\t') && char_cnt-- > 0) - p++; - - l = 0; - digit = *p - '0'; - while (*p >= '0' && digit < base && char_cnt-- > 0) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = UINT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (l); -} - -static uint64_t -ar_atol10(const char *p, unsigned char_cnt) -{ - uint64_t l, limit, last_digit_limit; - unsigned int base, digit; - - base = 10; - limit = UINT64_MAX / base; - last_digit_limit = UINT64_MAX % base; - - while ((*p == ' ' || *p == '\t') && char_cnt-- > 0) - p++; - l = 0; - digit = *p - '0'; - while (*p >= '0' && digit < base && char_cnt-- > 0) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = UINT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (l); -} diff --git a/lib/libarchive/archive_read_support_format_cpio.c b/lib/libarchive/archive_read_support_format_cpio.c deleted file mode 100644 index 790fa7a..0000000 --- a/lib/libarchive/archive_read_support_format_cpio.c +++ /dev/null @@ -1,777 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -/* #include */ /* See archive_platform.h */ -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" - -struct cpio_bin_header { - unsigned char c_magic[2]; - unsigned char c_dev[2]; - unsigned char c_ino[2]; - unsigned char c_mode[2]; - unsigned char c_uid[2]; - unsigned char c_gid[2]; - unsigned char c_nlink[2]; - unsigned char c_rdev[2]; - unsigned char c_mtime[4]; - unsigned char c_namesize[2]; - unsigned char c_filesize[4]; -} __packed; - -struct cpio_odc_header { - char c_magic[6]; - char c_dev[6]; - char c_ino[6]; - char c_mode[6]; - char c_uid[6]; - char c_gid[6]; - char c_nlink[6]; - char c_rdev[6]; - char c_mtime[11]; - char c_namesize[6]; - char c_filesize[11]; -} __packed; - -struct cpio_newc_header { - char c_magic[6]; - char c_ino[8]; - char c_mode[8]; - char c_uid[8]; - char c_gid[8]; - char c_nlink[8]; - char c_mtime[8]; - char c_filesize[8]; - char c_devmajor[8]; - char c_devminor[8]; - char c_rdevmajor[8]; - char c_rdevminor[8]; - char c_namesize[8]; - char c_crc[8]; -} __packed; - -struct links_entry { - struct links_entry *next; - struct links_entry *previous; - int links; - dev_t dev; - int64_t ino; - char *name; -}; - -#define CPIO_MAGIC 0x13141516 -struct cpio { - int magic; - int (*read_header)(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); - struct links_entry *links_head; - struct archive_string entry_name; - struct archive_string entry_linkname; - off_t entry_bytes_remaining; - off_t entry_offset; - off_t entry_padding; -}; - -static int64_t atol16(const char *, unsigned); -static int64_t atol8(const char *, unsigned); -static int archive_read_format_cpio_bid(struct archive_read *); -static int archive_read_format_cpio_cleanup(struct archive_read *); -static int archive_read_format_cpio_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_cpio_read_header(struct archive_read *, - struct archive_entry *); -static int be4(const unsigned char *); -static int find_odc_header(struct archive_read *); -static int find_newc_header(struct archive_read *); -static int header_bin_be(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); -static int header_bin_le(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); -static int header_newc(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); -static int header_odc(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); -static int is_octal(const char *, size_t); -static int is_hex(const char *, size_t); -static int le4(const unsigned char *); -static void record_hardlink(struct cpio *cpio, struct archive_entry *entry); - -int -archive_read_support_format_cpio(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct cpio *cpio; - int r; - - cpio = (struct cpio *)malloc(sizeof(*cpio)); - if (cpio == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); - return (ARCHIVE_FATAL); - } - memset(cpio, 0, sizeof(*cpio)); - cpio->magic = CPIO_MAGIC; - - r = __archive_read_register_format(a, - cpio, - "cpio", - archive_read_format_cpio_bid, - NULL, - archive_read_format_cpio_read_header, - archive_read_format_cpio_read_data, - NULL, - archive_read_format_cpio_cleanup); - - if (r != ARCHIVE_OK) - free(cpio); - return (ARCHIVE_OK); -} - - -static int -archive_read_format_cpio_bid(struct archive_read *a) -{ - const void *h; - const unsigned char *p; - struct cpio *cpio; - int bid; - - cpio = (struct cpio *)(a->format->data); - - if ((h = __archive_read_ahead(a, 6, NULL)) == NULL) - return (-1); - - p = (const unsigned char *)h; - bid = 0; - if (memcmp(p, "070707", 6) == 0) { - /* ASCII cpio archive (odc, POSIX.1) */ - cpio->read_header = header_odc; - bid += 48; - /* - * XXX TODO: More verification; Could check that only octal - * digits appear in appropriate header locations. XXX - */ - } else if (memcmp(p, "070701", 6) == 0) { - /* ASCII cpio archive (SVR4 without CRC) */ - cpio->read_header = header_newc; - bid += 48; - /* - * XXX TODO: More verification; Could check that only hex - * digits appear in appropriate header locations. XXX - */ - } else if (memcmp(p, "070702", 6) == 0) { - /* ASCII cpio archive (SVR4 with CRC) */ - /* XXX TODO: Flag that we should check the CRC. XXX */ - cpio->read_header = header_newc; - bid += 48; - /* - * XXX TODO: More verification; Could check that only hex - * digits appear in appropriate header locations. XXX - */ - } else if (p[0] * 256 + p[1] == 070707) { - /* big-endian binary cpio archives */ - cpio->read_header = header_bin_be; - bid += 16; - /* Is more verification possible here? */ - } else if (p[0] + p[1] * 256 == 070707) { - /* little-endian binary cpio archives */ - cpio->read_header = header_bin_le; - bid += 16; - /* Is more verification possible here? */ - } else - return (ARCHIVE_WARN); - - return (bid); -} - -static int -archive_read_format_cpio_read_header(struct archive_read *a, - struct archive_entry *entry) -{ - struct cpio *cpio; - const void *h; - size_t namelength; - size_t name_pad; - int r; - - cpio = (struct cpio *)(a->format->data); - r = (cpio->read_header(a, cpio, entry, &namelength, &name_pad)); - - if (r < ARCHIVE_WARN) - return (r); - - /* Read name from buffer. */ - h = __archive_read_ahead(a, namelength + name_pad, NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, namelength + name_pad); - archive_strncpy(&cpio->entry_name, (const char *)h, namelength); - archive_entry_set_pathname(entry, cpio->entry_name.s); - cpio->entry_offset = 0; - - /* If this is a symlink, read the link contents. */ - if (archive_entry_filetype(entry) == AE_IFLNK) { - h = __archive_read_ahead(a, cpio->entry_bytes_remaining, NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, cpio->entry_bytes_remaining); - archive_strncpy(&cpio->entry_linkname, (const char *)h, - cpio->entry_bytes_remaining); - archive_entry_set_symlink(entry, cpio->entry_linkname.s); - cpio->entry_bytes_remaining = 0; - } - - /* XXX TODO: If the full mode is 0160200, then this is a Solaris - * ACL description for the following entry. Read this body - * and parse it as a Solaris-style ACL, then read the next - * header. XXX */ - - /* Compare name to "TRAILER!!!" to test for end-of-archive. */ - if (namelength == 11 && strcmp((const char *)h, "TRAILER!!!") == 0) { - /* TODO: Store file location of start of block. */ - archive_clear_error(&a->archive); - return (ARCHIVE_EOF); - } - - /* Detect and record hardlinks to previously-extracted entries. */ - record_hardlink(cpio, entry); - - return (r); -} - -static int -archive_read_format_cpio_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - ssize_t bytes_read; - struct cpio *cpio; - - cpio = (struct cpio *)(a->format->data); - if (cpio->entry_bytes_remaining > 0) { - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - if (bytes_read > cpio->entry_bytes_remaining) - bytes_read = cpio->entry_bytes_remaining; - *size = bytes_read; - *offset = cpio->entry_offset; - cpio->entry_offset += bytes_read; - cpio->entry_bytes_remaining -= bytes_read; - __archive_read_consume(a, bytes_read); - return (ARCHIVE_OK); - } else { - while (cpio->entry_padding > 0) { - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - if (bytes_read > cpio->entry_padding) - bytes_read = cpio->entry_padding; - __archive_read_consume(a, bytes_read); - cpio->entry_padding -= bytes_read; - } - *buff = NULL; - *size = 0; - *offset = cpio->entry_offset; - return (ARCHIVE_EOF); - } -} - -/* - * Skip forward to the next cpio newc header by searching for the - * 07070[12] string. This should be generalized and merged with - * find_odc_header below. - */ -static int -is_hex(const char *p, size_t len) -{ - while (len-- > 0) { - if ((*p >= '0' && *p <= '9') - || (*p >= 'a' && *p <= 'f') - || (*p >= 'A' && *p <= 'F')) - ++p; - else - return (0); - } - return (1); -} - -static int -find_newc_header(struct archive_read *a) -{ - const void *h; - const char *p, *q; - size_t skip, skipped = 0; - ssize_t bytes; - - for (;;) { - h = __archive_read_ahead(a, sizeof(struct cpio_newc_header), &bytes); - if (h == NULL) - return (ARCHIVE_FATAL); - p = h; - q = p + bytes; - - /* Try the typical case first, then go into the slow search.*/ - if (memcmp("07070", p, 5) == 0 - && (p[5] == '1' || p[5] == '2') - && is_hex(p, sizeof(struct cpio_newc_header))) - return (ARCHIVE_OK); - - /* - * Scan ahead until we find something that looks - * like an odc header. - */ - while (p + sizeof(struct cpio_newc_header) <= q) { - switch (p[5]) { - case '1': - case '2': - if (memcmp("07070", p, 5) == 0 - && is_hex(p, sizeof(struct cpio_newc_header))) { - skip = p - (const char *)h; - __archive_read_consume(a, skip); - skipped += skip; - if (skipped > 0) { - archive_set_error(&a->archive, - 0, - "Skipped %d bytes before " - "finding valid header", - (int)skipped); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); - } - p += 2; - break; - case '0': - p++; - break; - default: - p += 6; - break; - } - } - skip = p - (const char *)h; - __archive_read_consume(a, skip); - skipped += skip; - } -} - -static int -header_newc(struct archive_read *a, struct cpio *cpio, - struct archive_entry *entry, size_t *namelength, size_t *name_pad) -{ - const void *h; - const struct cpio_newc_header *header; - int r; - - r = find_newc_header(a); - if (r < ARCHIVE_WARN) - return (r); - - /* Read fixed-size portion of header. */ - h = __archive_read_ahead(a, sizeof(struct cpio_newc_header), NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, sizeof(struct cpio_newc_header)); - - /* Parse out hex fields. */ - header = (const struct cpio_newc_header *)h; - - if (memcmp(header->c_magic, "070701", 6) == 0) { - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC; - a->archive.archive_format_name = "ASCII cpio (SVR4 with no CRC)"; - } else if (memcmp(header->c_magic, "070702", 6) == 0) { - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_CRC; - a->archive.archive_format_name = "ASCII cpio (SVR4 with CRC)"; - } else { - /* TODO: Abort here? */ - } - - archive_entry_set_devmajor(entry, atol16(header->c_devmajor, sizeof(header->c_devmajor))); - archive_entry_set_devminor(entry, atol16(header->c_devminor, sizeof(header->c_devminor))); - archive_entry_set_ino(entry, atol16(header->c_ino, sizeof(header->c_ino))); - archive_entry_set_mode(entry, atol16(header->c_mode, sizeof(header->c_mode))); - archive_entry_set_uid(entry, atol16(header->c_uid, sizeof(header->c_uid))); - archive_entry_set_gid(entry, atol16(header->c_gid, sizeof(header->c_gid))); - archive_entry_set_nlink(entry, atol16(header->c_nlink, sizeof(header->c_nlink))); - archive_entry_set_rdevmajor(entry, atol16(header->c_rdevmajor, sizeof(header->c_rdevmajor))); - archive_entry_set_rdevminor(entry, atol16(header->c_rdevminor, sizeof(header->c_rdevminor))); - archive_entry_set_mtime(entry, atol16(header->c_mtime, sizeof(header->c_mtime)), 0); - *namelength = atol16(header->c_namesize, sizeof(header->c_namesize)); - /* Pad name to 2 more than a multiple of 4. */ - *name_pad = (2 - *namelength) & 3; - - /* - * Note: entry_bytes_remaining is at least 64 bits and - * therefore guaranteed to be big enough for a 33-bit file - * size. - */ - cpio->entry_bytes_remaining = - atol16(header->c_filesize, sizeof(header->c_filesize)); - archive_entry_set_size(entry, cpio->entry_bytes_remaining); - /* Pad file contents to a multiple of 4. */ - cpio->entry_padding = 3 & -cpio->entry_bytes_remaining; - return (r); -} - -/* - * Skip forward to the next cpio odc header by searching for the - * 070707 string. This is a hand-optimized search that could - * probably be easily generalized to handle all character-based - * cpio variants. - */ -static int -is_octal(const char *p, size_t len) -{ - while (len-- > 0) { - if (*p < '0' || *p > '7') - return (0); - ++p; - } - return (1); -} - -static int -find_odc_header(struct archive_read *a) -{ - const void *h; - const char *p, *q; - size_t skip, skipped = 0; - ssize_t bytes; - - for (;;) { - h = __archive_read_ahead(a, sizeof(struct cpio_odc_header), &bytes); - if (h == NULL) - return (ARCHIVE_FATAL); - p = h; - q = p + bytes; - - /* Try the typical case first, then go into the slow search.*/ - if (memcmp("070707", p, 6) == 0 - && is_octal(p, sizeof(struct cpio_odc_header))) - return (ARCHIVE_OK); - - /* - * Scan ahead until we find something that looks - * like an odc header. - */ - while (p + sizeof(struct cpio_odc_header) <= q) { - switch (p[5]) { - case '7': - if (memcmp("070707", p, 6) == 0 - && is_octal(p, sizeof(struct cpio_odc_header))) { - skip = p - (const char *)h; - __archive_read_consume(a, skip); - skipped += skip; - if (skipped > 0) { - archive_set_error(&a->archive, - 0, - "Skipped %d bytes before " - "finding valid header", - (int)skipped); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); - } - p += 2; - break; - case '0': - p++; - break; - default: - p += 6; - break; - } - } - skip = p - (const char *)h; - __archive_read_consume(a, skip); - skipped += skip; - } -} - -static int -header_odc(struct archive_read *a, struct cpio *cpio, - struct archive_entry *entry, size_t *namelength, size_t *name_pad) -{ - const void *h; - int r; - const struct cpio_odc_header *header; - - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX; - a->archive.archive_format_name = "POSIX octet-oriented cpio"; - - /* Find the start of the next header. */ - r = find_odc_header(a); - if (r < ARCHIVE_WARN) - return (r); - - /* Read fixed-size portion of header. */ - h = __archive_read_ahead(a, sizeof(struct cpio_odc_header), NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, sizeof(struct cpio_odc_header)); - - /* Parse out octal fields. */ - header = (const struct cpio_odc_header *)h; - - archive_entry_set_dev(entry, atol8(header->c_dev, sizeof(header->c_dev))); - archive_entry_set_ino(entry, atol8(header->c_ino, sizeof(header->c_ino))); - archive_entry_set_mode(entry, atol8(header->c_mode, sizeof(header->c_mode))); - archive_entry_set_uid(entry, atol8(header->c_uid, sizeof(header->c_uid))); - archive_entry_set_gid(entry, atol8(header->c_gid, sizeof(header->c_gid))); - archive_entry_set_nlink(entry, atol8(header->c_nlink, sizeof(header->c_nlink))); - archive_entry_set_rdev(entry, atol8(header->c_rdev, sizeof(header->c_rdev))); - archive_entry_set_mtime(entry, atol8(header->c_mtime, sizeof(header->c_mtime)), 0); - *namelength = atol8(header->c_namesize, sizeof(header->c_namesize)); - *name_pad = 0; /* No padding of filename. */ - - /* - * Note: entry_bytes_remaining is at least 64 bits and - * therefore guaranteed to be big enough for a 33-bit file - * size. - */ - cpio->entry_bytes_remaining = - atol8(header->c_filesize, sizeof(header->c_filesize)); - archive_entry_set_size(entry, cpio->entry_bytes_remaining); - cpio->entry_padding = 0; - return (r); -} - -static int -header_bin_le(struct archive_read *a, struct cpio *cpio, - struct archive_entry *entry, size_t *namelength, size_t *name_pad) -{ - const void *h; - const struct cpio_bin_header *header; - - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_LE; - a->archive.archive_format_name = "cpio (little-endian binary)"; - - /* Read fixed-size portion of header. */ - h = __archive_read_ahead(a, sizeof(struct cpio_bin_header), NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, sizeof(struct cpio_bin_header)); - - /* Parse out binary fields. */ - header = (const struct cpio_bin_header *)h; - - archive_entry_set_dev(entry, header->c_dev[0] + header->c_dev[1] * 256); - archive_entry_set_ino(entry, header->c_ino[0] + header->c_ino[1] * 256); - archive_entry_set_mode(entry, header->c_mode[0] + header->c_mode[1] * 256); - archive_entry_set_uid(entry, header->c_uid[0] + header->c_uid[1] * 256); - archive_entry_set_gid(entry, header->c_gid[0] + header->c_gid[1] * 256); - archive_entry_set_nlink(entry, header->c_nlink[0] + header->c_nlink[1] * 256); - archive_entry_set_rdev(entry, header->c_rdev[0] + header->c_rdev[1] * 256); - archive_entry_set_mtime(entry, le4(header->c_mtime), 0); - *namelength = header->c_namesize[0] + header->c_namesize[1] * 256; - *name_pad = *namelength & 1; /* Pad to even. */ - - cpio->entry_bytes_remaining = le4(header->c_filesize); - archive_entry_set_size(entry, cpio->entry_bytes_remaining); - cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */ - return (ARCHIVE_OK); -} - -static int -header_bin_be(struct archive_read *a, struct cpio *cpio, - struct archive_entry *entry, size_t *namelength, size_t *name_pad) -{ - const void *h; - const struct cpio_bin_header *header; - - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_BE; - a->archive.archive_format_name = "cpio (big-endian binary)"; - - /* Read fixed-size portion of header. */ - h = __archive_read_ahead(a, sizeof(struct cpio_bin_header), NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, sizeof(struct cpio_bin_header)); - - /* Parse out binary fields. */ - header = (const struct cpio_bin_header *)h; - archive_entry_set_dev(entry, header->c_dev[0] * 256 + header->c_dev[1]); - archive_entry_set_ino(entry, header->c_ino[0] * 256 + header->c_ino[1]); - archive_entry_set_mode(entry, header->c_mode[0] * 256 + header->c_mode[1]); - archive_entry_set_uid(entry, header->c_uid[0] * 256 + header->c_uid[1]); - archive_entry_set_gid(entry, header->c_gid[0] * 256 + header->c_gid[1]); - archive_entry_set_nlink(entry, header->c_nlink[0] * 256 + header->c_nlink[1]); - archive_entry_set_rdev(entry, header->c_rdev[0] * 256 + header->c_rdev[1]); - archive_entry_set_mtime(entry, be4(header->c_mtime), 0); - *namelength = header->c_namesize[0] * 256 + header->c_namesize[1]; - *name_pad = *namelength & 1; /* Pad to even. */ - - cpio->entry_bytes_remaining = be4(header->c_filesize); - archive_entry_set_size(entry, cpio->entry_bytes_remaining); - cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */ - return (ARCHIVE_OK); -} - -static int -archive_read_format_cpio_cleanup(struct archive_read *a) -{ - struct cpio *cpio; - - cpio = (struct cpio *)(a->format->data); - /* Free inode->name map */ - while (cpio->links_head != NULL) { - struct links_entry *lp = cpio->links_head->next; - - if (cpio->links_head->name) - free(cpio->links_head->name); - free(cpio->links_head); - cpio->links_head = lp; - } - archive_string_free(&cpio->entry_name); - free(cpio); - (a->format->data) = NULL; - return (ARCHIVE_OK); -} - -static int -le4(const unsigned char *p) -{ - return ((p[0]<<16) + (p[1]<<24) + (p[2]<<0) + (p[3]<<8)); -} - - -static int -be4(const unsigned char *p) -{ - return ((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + (p[3])); -} - -/* - * Note that this implementation does not (and should not!) obey - * locale settings; you cannot simply substitute strtol here, since - * it does obey locale. - */ -static int64_t -atol8(const char *p, unsigned char_cnt) -{ - int64_t l; - int digit; - - l = 0; - while (char_cnt-- > 0) { - if (*p >= '0' && *p <= '7') - digit = *p - '0'; - else - return (l); - p++; - l <<= 3; - l |= digit; - } - return (l); -} - -static int64_t -atol16(const char *p, unsigned char_cnt) -{ - int64_t l; - int digit; - - l = 0; - while (char_cnt-- > 0) { - if (*p >= 'a' && *p <= 'f') - digit = *p - 'a' + 10; - else if (*p >= 'A' && *p <= 'F') - digit = *p - 'A' + 10; - else if (*p >= '0' && *p <= '9') - digit = *p - '0'; - else - return (l); - p++; - l <<= 4; - l |= digit; - } - return (l); -} - -static void -record_hardlink(struct cpio *cpio, struct archive_entry *entry) -{ - struct links_entry *le; - dev_t dev; - int64_t ino; - - if (archive_entry_nlink(entry) <= 1) - return; - - dev = archive_entry_dev(entry); - ino = archive_entry_ino64(entry); - - /* - * First look in the list of multiply-linked files. If we've - * already dumped it, convert this entry to a hard link entry. - */ - for (le = cpio->links_head; le; le = le->next) { - if (le->dev == dev && le->ino == ino) { - archive_entry_copy_hardlink(entry, le->name); - - if (--le->links <= 0) { - if (le->previous != NULL) - le->previous->next = le->next; - if (le->next != NULL) - le->next->previous = le->previous; - if (cpio->links_head == le) - cpio->links_head = le->next; - free(le->name); - free(le); - } - - return; - } - } - - le = (struct links_entry *)malloc(sizeof(struct links_entry)); - if (le == NULL) - __archive_errx(1, "Out of memory adding file to list"); - if (cpio->links_head != NULL) - cpio->links_head->previous = le; - le->next = cpio->links_head; - le->previous = NULL; - cpio->links_head = le; - le->dev = dev; - le->ino = ino; - le->links = archive_entry_nlink(entry) - 1; - le->name = strdup(archive_entry_pathname(entry)); - if (le->name == NULL) - __archive_errx(1, "Out of memory adding file to list"); -} diff --git a/lib/libarchive/archive_read_support_format_empty.c b/lib/libarchive/archive_read_support_format_empty.c deleted file mode 100644 index 05c4958..0000000 --- a/lib/libarchive/archive_read_support_format_empty.c +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" - -static int archive_read_format_empty_bid(struct archive_read *); -static int archive_read_format_empty_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_empty_read_header(struct archive_read *, - struct archive_entry *); -int -archive_read_support_format_empty(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - int r; - - r = __archive_read_register_format(a, - NULL, - NULL, - archive_read_format_empty_bid, - NULL, - archive_read_format_empty_read_header, - archive_read_format_empty_read_data, - NULL, - NULL); - - return (r); -} - - -static int -archive_read_format_empty_bid(struct archive_read *a) -{ - ssize_t avail; - - (void)__archive_read_ahead(a, 1, &avail); - if (avail != 0) - return (-1); - return (1); -} - -static int -archive_read_format_empty_read_header(struct archive_read *a, - struct archive_entry *entry) -{ - (void)a; /* UNUSED */ - (void)entry; /* UNUSED */ - - a->archive.archive_format = ARCHIVE_FORMAT_EMPTY; - a->archive.archive_format_name = "Empty file"; - - return (ARCHIVE_EOF); -} - -static int -archive_read_format_empty_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - (void)a; /* UNUSED */ - (void)buff; /* UNUSED */ - (void)size; /* UNUSED */ - (void)offset; /* UNUSED */ - - return (ARCHIVE_EOF); -} diff --git a/lib/libarchive/archive_read_support_format_iso9660.c b/lib/libarchive/archive_read_support_format_iso9660.c deleted file mode 100644 index f014eb3..0000000 --- a/lib/libarchive/archive_read_support_format_iso9660.c +++ /dev/null @@ -1,2964 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2009 Andreas Henriksson - * Copyright (c) 2009-2011 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -/* #include */ /* See archive_platform.h */ -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#include -#ifdef HAVE_ZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_endian.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" -#include "archive_string.h" - -/* - * An overview of ISO 9660 format: - * - * Each disk is laid out as follows: - * * 32k reserved for private use - * * Volume descriptor table. Each volume descriptor - * is 2k and specifies basic format information. - * The "Primary Volume Descriptor" (PVD) is defined by the - * standard and should always be present; other volume - * descriptors include various vendor-specific extensions. - * * Files and directories. Each file/dir is specified by - * an "extent" (starting sector and length in bytes). - * Dirs are just files with directory records packed one - * after another. The PVD contains a single dir entry - * specifying the location of the root directory. Everything - * else follows from there. - * - * This module works by first reading the volume descriptors, then - * building a list of directory entries, sorted by starting - * sector. At each step, I look for the earliest dir entry that - * hasn't yet been read, seek forward to that location and read - * that entry. If it's a dir, I slurp in the new dir entries and - * add them to the heap; if it's a regular file, I return the - * corresponding archive_entry and wait for the client to request - * the file body. This strategy allows us to read most compliant - * CDs with a single pass through the data, as required by libarchive. - */ -#define LOGICAL_BLOCK_SIZE 2048 -#define SYSTEM_AREA_BLOCK 16 - -/* Structure of on-disk primary volume descriptor. */ -#define PVD_type_offset 0 -#define PVD_type_size 1 -#define PVD_id_offset (PVD_type_offset + PVD_type_size) -#define PVD_id_size 5 -#define PVD_version_offset (PVD_id_offset + PVD_id_size) -#define PVD_version_size 1 -#define PVD_reserved1_offset (PVD_version_offset + PVD_version_size) -#define PVD_reserved1_size 1 -#define PVD_system_id_offset (PVD_reserved1_offset + PVD_reserved1_size) -#define PVD_system_id_size 32 -#define PVD_volume_id_offset (PVD_system_id_offset + PVD_system_id_size) -#define PVD_volume_id_size 32 -#define PVD_reserved2_offset (PVD_volume_id_offset + PVD_volume_id_size) -#define PVD_reserved2_size 8 -#define PVD_volume_space_size_offset (PVD_reserved2_offset + PVD_reserved2_size) -#define PVD_volume_space_size_size 8 -#define PVD_reserved3_offset (PVD_volume_space_size_offset + PVD_volume_space_size_size) -#define PVD_reserved3_size 32 -#define PVD_volume_set_size_offset (PVD_reserved3_offset + PVD_reserved3_size) -#define PVD_volume_set_size_size 4 -#define PVD_volume_sequence_number_offset (PVD_volume_set_size_offset + PVD_volume_set_size_size) -#define PVD_volume_sequence_number_size 4 -#define PVD_logical_block_size_offset (PVD_volume_sequence_number_offset + PVD_volume_sequence_number_size) -#define PVD_logical_block_size_size 4 -#define PVD_path_table_size_offset (PVD_logical_block_size_offset + PVD_logical_block_size_size) -#define PVD_path_table_size_size 8 -#define PVD_type_1_path_table_offset (PVD_path_table_size_offset + PVD_path_table_size_size) -#define PVD_type_1_path_table_size 4 -#define PVD_opt_type_1_path_table_offset (PVD_type_1_path_table_offset + PVD_type_1_path_table_size) -#define PVD_opt_type_1_path_table_size 4 -#define PVD_type_m_path_table_offset (PVD_opt_type_1_path_table_offset + PVD_opt_type_1_path_table_size) -#define PVD_type_m_path_table_size 4 -#define PVD_opt_type_m_path_table_offset (PVD_type_m_path_table_offset + PVD_type_m_path_table_size) -#define PVD_opt_type_m_path_table_size 4 -#define PVD_root_directory_record_offset (PVD_opt_type_m_path_table_offset + PVD_opt_type_m_path_table_size) -#define PVD_root_directory_record_size 34 -#define PVD_volume_set_id_offset (PVD_root_directory_record_offset + PVD_root_directory_record_size) -#define PVD_volume_set_id_size 128 -#define PVD_publisher_id_offset (PVD_volume_set_id_offset + PVD_volume_set_id_size) -#define PVD_publisher_id_size 128 -#define PVD_preparer_id_offset (PVD_publisher_id_offset + PVD_publisher_id_size) -#define PVD_preparer_id_size 128 -#define PVD_application_id_offset (PVD_preparer_id_offset + PVD_preparer_id_size) -#define PVD_application_id_size 128 -#define PVD_copyright_file_id_offset (PVD_application_id_offset + PVD_application_id_size) -#define PVD_copyright_file_id_size 37 -#define PVD_abstract_file_id_offset (PVD_copyright_file_id_offset + PVD_copyright_file_id_size) -#define PVD_abstract_file_id_size 37 -#define PVD_bibliographic_file_id_offset (PVD_abstract_file_id_offset + PVD_abstract_file_id_size) -#define PVD_bibliographic_file_id_size 37 -#define PVD_creation_date_offset (PVD_bibliographic_file_id_offset + PVD_bibliographic_file_id_size) -#define PVD_creation_date_size 17 -#define PVD_modification_date_offset (PVD_creation_date_offset + PVD_creation_date_size) -#define PVD_modification_date_size 17 -#define PVD_expiration_date_offset (PVD_modification_date_offset + PVD_modification_date_size) -#define PVD_expiration_date_size 17 -#define PVD_effective_date_offset (PVD_expiration_date_offset + PVD_expiration_date_size) -#define PVD_effective_date_size 17 -#define PVD_file_structure_version_offset (PVD_effective_date_offset + PVD_effective_date_size) -#define PVD_file_structure_version_size 1 -#define PVD_reserved4_offset (PVD_file_structure_version_offset + PVD_file_structure_version_size) -#define PVD_reserved4_size 1 -#define PVD_application_data_offset (PVD_reserved4_offset + PVD_reserved4_size) -#define PVD_application_data_size 512 -#define PVD_reserved5_offset (PVD_application_data_offset + PVD_application_data_size) -#define PVD_reserved5_size (2048 - PVD_reserved5_offset) - -/* TODO: It would make future maintenance easier to just hardcode the - * above values. In particular, ECMA119 states the offsets as part of - * the standard. That would eliminate the need for the following check.*/ -#if PVD_reserved5_offset != 1395 -#error PVD offset and size definitions are wrong. -#endif - - -/* Structure of optional on-disk supplementary volume descriptor. */ -#define SVD_type_offset 0 -#define SVD_type_size 1 -#define SVD_id_offset (SVD_type_offset + SVD_type_size) -#define SVD_id_size 5 -#define SVD_version_offset (SVD_id_offset + SVD_id_size) -#define SVD_version_size 1 -/* ... */ -#define SVD_reserved1_offset 72 -#define SVD_reserved1_size 8 -#define SVD_volume_space_size_offset 80 -#define SVD_volume_space_size_size 8 -#define SVD_escape_sequences_offset (SVD_volume_space_size_offset + SVD_volume_space_size_size) -#define SVD_escape_sequences_size 32 -/* ... */ -#define SVD_logical_block_size_offset 128 -#define SVD_logical_block_size_size 4 -#define SVD_type_L_path_table_offset 140 -#define SVD_type_M_path_table_offset 148 -/* ... */ -#define SVD_root_directory_record_offset 156 -#define SVD_root_directory_record_size 34 -#define SVD_file_structure_version_offset 881 -#define SVD_reserved2_offset 882 -#define SVD_reserved2_size 1 -#define SVD_reserved3_offset 1395 -#define SVD_reserved3_size 653 -/* ... */ -/* FIXME: validate correctness of last SVD entry offset. */ - -/* Structure of an on-disk directory record. */ -/* Note: ISO9660 stores each multi-byte integer twice, once in - * each byte order. The sizes here are the size of just one - * of the two integers. (This is why the offset of a field isn't - * the same as the offset+size of the previous field.) */ -#define DR_length_offset 0 -#define DR_length_size 1 -#define DR_ext_attr_length_offset 1 -#define DR_ext_attr_length_size 1 -#define DR_extent_offset 2 -#define DR_extent_size 4 -#define DR_size_offset 10 -#define DR_size_size 4 -#define DR_date_offset 18 -#define DR_date_size 7 -#define DR_flags_offset 25 -#define DR_flags_size 1 -#define DR_file_unit_size_offset 26 -#define DR_file_unit_size_size 1 -#define DR_interleave_offset 27 -#define DR_interleave_size 1 -#define DR_volume_sequence_number_offset 28 -#define DR_volume_sequence_number_size 2 -#define DR_name_len_offset 32 -#define DR_name_len_size 1 -#define DR_name_offset 33 - -#ifdef HAVE_ZLIB_H -static const unsigned char zisofs_magic[8] = { - 0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07 -}; - -struct zisofs { - /* Set 1 if this file compressed by paged zlib */ - int pz; - int pz_log2_bs; /* Log2 of block size */ - uint64_t pz_uncompressed_size; - - int initialized; - unsigned char *uncompressed_buffer; - size_t uncompressed_buffer_size; - - uint32_t pz_offset; - unsigned char header[16]; - size_t header_avail; - int header_passed; - unsigned char *block_pointers; - size_t block_pointers_alloc; - size_t block_pointers_size; - size_t block_pointers_avail; - size_t block_off; - uint32_t block_avail; - - z_stream stream; - int stream_valid; -}; -#else -struct zisofs { - /* Set 1 if this file compressed by paged zlib */ - int pz; -}; -#endif - -struct content { - uint64_t offset;/* Offset on disk. */ - uint64_t size; /* File size in bytes. */ - struct content *next; -}; - -/* In-memory storage for a directory record. */ -struct file_info { - struct file_info *use_next; - struct file_info *parent; - struct file_info *next; - struct file_info *re_next; - int subdirs; - uint64_t key; /* Heap Key. */ - uint64_t offset; /* Offset on disk. */ - uint64_t size; /* File size in bytes. */ - uint32_t ce_offset; /* Offset of CE. */ - uint32_t ce_size; /* Size of CE. */ - char rr_moved; /* Flag to rr_moved. */ - char rr_moved_has_re_only; - char re; /* Having RRIP "RE" extension. */ - char re_descendant; - uint64_t cl_offset; /* Having RRIP "CL" extension. */ - int birthtime_is_set; - time_t birthtime; /* File created time. */ - time_t mtime; /* File last modified time. */ - time_t atime; /* File last accessed time. */ - time_t ctime; /* File attribute change time. */ - uint64_t rdev; /* Device number. */ - mode_t mode; - uid_t uid; - gid_t gid; - int64_t number; - int nlinks; - struct archive_string name; /* Pathname */ - char name_continues; /* Non-zero if name continues */ - struct archive_string symlink; - char symlink_continues; /* Non-zero if link continues */ - /* Set 1 if this file compressed by paged zlib(zisofs) */ - int pz; - int pz_log2_bs; /* Log2 of block size */ - uint64_t pz_uncompressed_size; - /* Set 1 if this file is multi extent. */ - int multi_extent; - struct { - struct content *first; - struct content **last; - } contents; - struct { - struct file_info *first; - struct file_info **last; - } rede_files; - /* To check a ininity loop. */ - struct file_info *loop_by; -}; - -struct heap_queue { - struct file_info **files; - int allocated; - int used; -}; - -struct iso9660 { - int magic; -#define ISO9660_MAGIC 0x96609660 - - int opt_support_joliet; - int opt_support_rockridge; - - struct archive_string pathname; - char seenRockridge; /* Set true if RR extensions are used. */ - char seenSUSP; /* Set true if SUSP is beging used. */ - char seenJoliet; - - unsigned char suspOffset; - struct file_info *rr_moved; - struct read_ce_queue { - struct read_ce_req { - uint64_t offset;/* Offset of CE on disk. */ - struct file_info *file; - } *reqs; - int cnt; - int allocated; - } read_ce_req; - - int64_t previous_number; - struct archive_string previous_pathname; - - struct file_info *use_files; - struct heap_queue pending_files; - struct { - struct file_info *first; - struct file_info **last; - } cache_files; - struct { - struct file_info *first; - struct file_info **last; - } re_files; - - uint64_t current_position; - ssize_t logical_block_size; - uint64_t volume_size; /* Total size of volume in bytes. */ - int32_t volume_block;/* Total size of volume in logical blocks. */ - - struct vd { - int location; /* Location of Extent. */ - uint32_t size; - } primary, joliet; - - off_t entry_sparse_offset; - int64_t entry_bytes_remaining; - struct zisofs entry_zisofs; - struct content *entry_content; -}; - -static int archive_read_format_iso9660_bid(struct archive_read *); -static int archive_read_format_iso9660_options(struct archive_read *, - const char *, const char *); -static int archive_read_format_iso9660_cleanup(struct archive_read *); -static int archive_read_format_iso9660_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_iso9660_read_data_skip(struct archive_read *); -static int archive_read_format_iso9660_read_header(struct archive_read *, - struct archive_entry *); -static const char *build_pathname(struct archive_string *, struct file_info *); -#if DEBUG -static void dump_isodirrec(FILE *, const unsigned char *isodirrec); -#endif -static time_t time_from_tm(struct tm *); -static time_t isodate17(const unsigned char *); -static time_t isodate7(const unsigned char *); -static int isBootRecord(struct iso9660 *, const unsigned char *); -static int isVolumePartition(struct iso9660 *, const unsigned char *); -static int isVDSetTerminator(struct iso9660 *, const unsigned char *); -static int isJolietSVD(struct iso9660 *, const unsigned char *); -static int isSVD(struct iso9660 *, const unsigned char *); -static int isEVD(struct iso9660 *, const unsigned char *); -static int isPVD(struct iso9660 *, const unsigned char *); -static int next_cache_entry(struct archive_read *, struct iso9660 *, - struct file_info **); -static int next_entry_seek(struct archive_read *a, struct iso9660 *iso9660, - struct file_info **pfile); -static struct file_info * - parse_file_info(struct archive_read *a, - struct file_info *parent, const unsigned char *isodirrec); -static int parse_rockridge(struct archive_read *a, - struct file_info *file, const unsigned char *start, - const unsigned char *end); -static int register_CE(struct archive_read *a, int32_t location, - struct file_info *file); -static int read_CE(struct archive_read *a, struct iso9660 *iso9660); -static void parse_rockridge_NM1(struct file_info *, - const unsigned char *, int); -static void parse_rockridge_SL1(struct file_info *, - const unsigned char *, int); -static void parse_rockridge_TF1(struct file_info *, - const unsigned char *, int); -static void parse_rockridge_ZF1(struct file_info *, - const unsigned char *, int); -static void register_file(struct iso9660 *, struct file_info *); -static void release_files(struct iso9660 *); -static unsigned toi(const void *p, int n); -static inline void re_add_entry(struct iso9660 *, struct file_info *); -static inline struct file_info * re_get_entry(struct iso9660 *); -static inline int rede_add_entry(struct file_info *); -static inline struct file_info * rede_get_entry(struct file_info *); -static inline void cache_add_entry(struct iso9660 *iso9660, - struct file_info *file); -static inline struct file_info *cache_get_entry(struct iso9660 *iso9660); -static void heap_add_entry(struct heap_queue *heap, - struct file_info *file, uint64_t key); -static struct file_info *heap_get_entry(struct heap_queue *heap); - -#define add_entry(iso9660, file) \ - heap_add_entry(&((iso9660)->pending_files), file, file->offset) -#define next_entry(iso9660) \ - heap_get_entry(&((iso9660)->pending_files)) - -int -archive_read_support_format_iso9660(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct iso9660 *iso9660; - int r; - - iso9660 = (struct iso9660 *)malloc(sizeof(*iso9660)); - if (iso9660 == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate iso9660 data"); - return (ARCHIVE_FATAL); - } - memset(iso9660, 0, sizeof(*iso9660)); - iso9660->magic = ISO9660_MAGIC; - iso9660->cache_files.first = NULL; - iso9660->cache_files.last = &(iso9660->cache_files.first); - iso9660->re_files.first = NULL; - iso9660->re_files.last = &(iso9660->re_files.first); - /* Enable to support Joliet extensions by default. */ - iso9660->opt_support_joliet = 1; - /* Enable to support Rock Ridge extensions by default. */ - iso9660->opt_support_rockridge = 1; - - r = __archive_read_register_format(a, - iso9660, - "iso9660", - archive_read_format_iso9660_bid, - archive_read_format_iso9660_options, - archive_read_format_iso9660_read_header, - archive_read_format_iso9660_read_data, - archive_read_format_iso9660_read_data_skip, - archive_read_format_iso9660_cleanup); - - if (r != ARCHIVE_OK) { - free(iso9660); - return (r); - } - return (ARCHIVE_OK); -} - - -static int -archive_read_format_iso9660_bid(struct archive_read *a) -{ - struct iso9660 *iso9660; - ssize_t bytes_read; - const void *h; - const unsigned char *p; - int seenTerminator; - - iso9660 = (struct iso9660 *)(a->format->data); - - /* - * Skip the first 32k (reserved area) and get the first - * 8 sectors of the volume descriptor table. Of course, - * if the I/O layer gives us more, we'll take it. - */ -#define RESERVED_AREA (SYSTEM_AREA_BLOCK * LOGICAL_BLOCK_SIZE) - h = __archive_read_ahead(a, - RESERVED_AREA + 8 * LOGICAL_BLOCK_SIZE, - &bytes_read); - if (h == NULL) - return (-1); - p = (const unsigned char *)h; - - /* Skip the reserved area. */ - bytes_read -= RESERVED_AREA; - p += RESERVED_AREA; - - /* Check each volume descriptor. */ - seenTerminator = 0; - for (; bytes_read > LOGICAL_BLOCK_SIZE; - bytes_read -= LOGICAL_BLOCK_SIZE, p += LOGICAL_BLOCK_SIZE) { - /* Do not handle undefined Volume Descriptor Type. */ - if (p[0] >= 4 && p[0] <= 254) - return (0); - /* Standard Identifier must be "CD001" */ - if (memcmp(p + 1, "CD001", 5) != 0) - return (0); - if (!iso9660->primary.location) { - if (isPVD(iso9660, p)) - continue; - } - if (!iso9660->joliet.location) { - if (isJolietSVD(iso9660, p)) - continue; - } - if (isBootRecord(iso9660, p)) - continue; - if (isEVD(iso9660, p)) - continue; - if (isSVD(iso9660, p)) - continue; - if (isVolumePartition(iso9660, p)) - continue; - if (isVDSetTerminator(iso9660, p)) { - seenTerminator = 1; - break; - } - return (0); - } - /* - * ISO 9660 format must have Primary Volume Descriptor and - * Volume Descriptor Set Terminator. - */ - if (seenTerminator && iso9660->primary.location > 16) - return (48); - - /* We didn't find a valid PVD; return a bid of zero. */ - return (0); -} - -static int -archive_read_format_iso9660_options(struct archive_read *a, - const char *key, const char *val) -{ - struct iso9660 *iso9660; - - iso9660 = (struct iso9660 *)(a->format->data); - - if (strcmp(key, "joliet") == 0) { - if (val == NULL || strcmp(val, "off") == 0 || - strcmp(val, "ignore") == 0 || - strcmp(val, "disable") == 0 || - strcmp(val, "0") == 0) - iso9660->opt_support_joliet = 0; - else - iso9660->opt_support_joliet = 1; - return (ARCHIVE_OK); - } - if (strcmp(key, "rockridge") == 0 || - strcmp(key, "Rockridge") == 0) { - iso9660->opt_support_rockridge = val != NULL; - return (ARCHIVE_OK); - } - - /* Note: The "warn" return is just to inform the options - * supervisor that we didn't handle it. It will generate - * a suitable error if noone used this option. */ - return (ARCHIVE_WARN); -} - -static int -isBootRecord(struct iso9660 *iso9660, const unsigned char *h) -{ - (void)iso9660; /* UNUSED */ - - /* Type of the Volume Descriptor Boot Record must be 0. */ - if (h[0] != 0) - return (0); - - /* Volume Descriptor Version must be 1. */ - if (h[6] != 1) - return (0); - - return (1); -} - -static int -isVolumePartition(struct iso9660 *iso9660, const unsigned char *h) -{ - int32_t location; - - /* Type of the Volume Partition Descriptor must be 3. */ - if (h[0] != 3) - return (0); - - /* Volume Descriptor Version must be 1. */ - if (h[6] != 1) - return (0); - /* Unused Field */ - if (h[7] != 0) - return (0); - - location = archive_le32dec(h + 72); - if (location <= SYSTEM_AREA_BLOCK || - location >= iso9660->volume_block) - return (0); - if ((uint32_t)location != archive_be32dec(h + 76)) - return (0); - - return (1); -} - -static int -isVDSetTerminator(struct iso9660 *iso9660, const unsigned char *h) -{ - int i; - - (void)iso9660; /* UNUSED */ - - /* Type of the Volume Descriptor Set Terminator must be 255. */ - if (h[0] != 255) - return (0); - - /* Volume Descriptor Version must be 1. */ - if (h[6] != 1) - return (0); - - /* Reserved field must be 0. */ - for (i = 7; i < 2048; ++i) - if (h[i] != 0) - return (0); - - return (1); -} - -static int -isJolietSVD(struct iso9660 *iso9660, const unsigned char *h) -{ - const unsigned char *p; - ssize_t logical_block_size; - int32_t volume_block; - - /* Check if current sector is a kind of Supplementary Volume - * Descriptor. */ - if (!isSVD(iso9660, h)) - return (0); - - /* FIXME: do more validations according to joliet spec. */ - - /* check if this SVD contains joliet extension! */ - p = h + SVD_escape_sequences_offset; - /* N.B. Joliet spec says p[1] == '\\', but.... */ - if (p[0] == '%' && p[1] == '/') { - int level = 0; - - if (p[2] == '@') - level = 1; - else if (p[2] == 'C') - level = 2; - else if (p[2] == 'E') - level = 3; - else /* not joliet */ - return (0); - - iso9660->seenJoliet = level; - - } else /* not joliet */ - return (0); - - logical_block_size = - archive_le16dec(h + SVD_logical_block_size_offset); - volume_block = archive_le32dec(h + SVD_volume_space_size_offset); - - iso9660->logical_block_size = logical_block_size; - iso9660->volume_block = volume_block; - iso9660->volume_size = logical_block_size * (uint64_t)volume_block; - /* Read Root Directory Record in Volume Descriptor. */ - p = h + SVD_root_directory_record_offset; - iso9660->joliet.location = archive_le32dec(p + DR_extent_offset); - iso9660->joliet.size = archive_le32dec(p + DR_size_offset); - - return (48); -} - -static int -isSVD(struct iso9660 *iso9660, const unsigned char *h) -{ - const unsigned char *p; - ssize_t logical_block_size; - int32_t volume_block; - int32_t location; - int i; - - (void)iso9660; /* UNUSED */ - - /* Type 2 means it's a SVD. */ - if (h[SVD_type_offset] != 2) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < SVD_reserved1_size; ++i) - if (h[SVD_reserved1_offset + i] != 0) - return (0); - for (i = 0; i < SVD_reserved2_size; ++i) - if (h[SVD_reserved2_offset + i] != 0) - return (0); - for (i = 0; i < SVD_reserved3_size; ++i) - if (h[SVD_reserved3_offset + i] != 0) - return (0); - - /* File structure version must be 1 for ISO9660/ECMA119. */ - if (h[SVD_file_structure_version_offset] != 1) - return (0); - - logical_block_size = - archive_le16dec(h + SVD_logical_block_size_offset); - if (logical_block_size <= 0) - return (0); - - volume_block = archive_le32dec(h + SVD_volume_space_size_offset); - if (volume_block <= SYSTEM_AREA_BLOCK+4) - return (0); - - /* Location of Occurrence of Type L Path Table must be - * available location, - * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ - location = archive_le32dec(h+SVD_type_L_path_table_offset); - if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block) - return (0); - - /* The Type M Path Table must be at a valid location (WinISO - * and probably other programs omit this, so we allow zero) - * - * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ - location = archive_be32dec(h+SVD_type_M_path_table_offset); - if ((location > 0 && location < SYSTEM_AREA_BLOCK+2) - || location >= volume_block) - return (0); - - /* Read Root Directory Record in Volume Descriptor. */ - p = h + SVD_root_directory_record_offset; - if (p[DR_length_offset] != 34) - return (0); - - return (48); -} - -static int -isEVD(struct iso9660 *iso9660, const unsigned char *h) -{ - const unsigned char *p; - ssize_t logical_block_size; - int32_t volume_block; - int32_t location; - int i; - - (void)iso9660; /* UNUSED */ - - /* Type of the Enhanced Volume Descriptor must be 2. */ - if (h[PVD_type_offset] != 2) - return (0); - - /* EVD version must be 2. */ - if (h[PVD_version_offset] != 2) - return (0); - - /* Reserved field must be 0. */ - if (h[PVD_reserved1_offset] != 0) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved2_size; ++i) - if (h[PVD_reserved2_offset + i] != 0) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved3_size; ++i) - if (h[PVD_reserved3_offset + i] != 0) - return (0); - - /* Logical block size must be > 0. */ - /* I've looked at Ecma 119 and can't find any stronger - * restriction on this field. */ - logical_block_size = - archive_le16dec(h + PVD_logical_block_size_offset); - if (logical_block_size <= 0) - return (0); - - volume_block = - archive_le32dec(h + PVD_volume_space_size_offset); - if (volume_block <= SYSTEM_AREA_BLOCK+4) - return (0); - - /* File structure version must be 2 for ISO9660:1999. */ - if (h[PVD_file_structure_version_offset] != 2) - return (0); - - /* Location of Occurrence of Type L Path Table must be - * available location, - * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ - location = archive_le32dec(h+PVD_type_1_path_table_offset); - if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block) - return (0); - - /* Location of Occurrence of Type M Path Table must be - * available location, - * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ - location = archive_be32dec(h+PVD_type_m_path_table_offset); - if ((location > 0 && location < SYSTEM_AREA_BLOCK+2) - || location >= volume_block) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved4_size; ++i) - if (h[PVD_reserved4_offset + i] != 0) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved5_size; ++i) - if (h[PVD_reserved5_offset + i] != 0) - return (0); - - /* Read Root Directory Record in Volume Descriptor. */ - p = h + PVD_root_directory_record_offset; - if (p[DR_length_offset] != 34) - return (0); - - return (48); -} - -static int -isPVD(struct iso9660 *iso9660, const unsigned char *h) -{ - const unsigned char *p; - ssize_t logical_block_size; - int32_t volume_block; - int32_t location; - int i; - - /* Type of the Primary Volume Descriptor must be 1. */ - if (h[PVD_type_offset] != 1) - return (0); - - /* PVD version must be 1. */ - if (h[PVD_version_offset] != 1) - return (0); - - /* Reserved field must be 0. */ - if (h[PVD_reserved1_offset] != 0) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved2_size; ++i) - if (h[PVD_reserved2_offset + i] != 0) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved3_size; ++i) - if (h[PVD_reserved3_offset + i] != 0) - return (0); - - /* Logical block size must be > 0. */ - /* I've looked at Ecma 119 and can't find any stronger - * restriction on this field. */ - logical_block_size = - archive_le16dec(h + PVD_logical_block_size_offset); - if (logical_block_size <= 0) - return (0); - - volume_block = archive_le32dec(h + PVD_volume_space_size_offset); - if (volume_block <= SYSTEM_AREA_BLOCK+4) - return (0); - - /* File structure version must be 1 for ISO9660/ECMA119. */ - if (h[PVD_file_structure_version_offset] != 1) - return (0); - - /* Location of Occurrence of Type L Path Table must be - * available location, - * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ - location = archive_le32dec(h+PVD_type_1_path_table_offset); - if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block) - return (0); - - /* The Type M Path Table must also be at a valid location - * (although ECMA 119 requires a Type M Path Table, WinISO and - * probably other programs omit it, so we permit a zero here) - * - * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ - location = archive_be32dec(h+PVD_type_m_path_table_offset); - if ((location > 0 && location < SYSTEM_AREA_BLOCK+2) - || location >= volume_block) - return (0); - - /* Reserved field must be 0. */ - /* FreeBSD: makefs erroneously created images with 0x20 */ - for (i = 0; i < PVD_reserved4_size; ++i) - if (h[PVD_reserved4_offset + i] != 0 && - h[PVD_reserved4_offset + i] != 32) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved5_size; ++i) - if (h[PVD_reserved5_offset + i] != 0) - return (0); - - /* XXX TODO: Check other values for sanity; reject more - * malformed PVDs. XXX */ - - /* Read Root Directory Record in Volume Descriptor. */ - p = h + PVD_root_directory_record_offset; - if (p[DR_length_offset] != 34) - return (0); - - iso9660->logical_block_size = logical_block_size; - iso9660->volume_block = volume_block; - iso9660->volume_size = logical_block_size * (uint64_t)volume_block; - iso9660->primary.location = archive_le32dec(p + DR_extent_offset); - iso9660->primary.size = archive_le32dec(p + DR_size_offset); - - return (48); -} - -static int -read_children(struct archive_read *a, struct file_info *parent) -{ - struct iso9660 *iso9660; - const unsigned char *b, *p; - struct file_info *multi; - size_t step; - - iso9660 = (struct iso9660 *)(a->format->data); - if (iso9660->current_position > parent->offset) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring out-of-order directory (%s) %jd > %jd", - parent->name.s, - (intmax_t)iso9660->current_position, - (intmax_t)parent->offset); - return (ARCHIVE_WARN); - } - if (parent->offset + parent->size > iso9660->volume_size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Directory is beyond end-of-media: %s", - parent->name.s); - return (ARCHIVE_WARN); - } - if (iso9660->current_position < parent->offset) { - int64_t skipsize; - - skipsize = parent->offset - iso9660->current_position; - skipsize = __archive_read_skip(a, skipsize); - if (skipsize < 0) - return ((int)skipsize); - iso9660->current_position = parent->offset; - } - - step = ((parent->size + iso9660->logical_block_size -1) / - iso9660->logical_block_size) * iso9660->logical_block_size; - b = __archive_read_ahead(a, step, NULL); - if (b == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Failed to read full block when scanning " - "ISO9660 directory list"); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, step); - iso9660->current_position += step; - multi = NULL; - while (step) { - p = b; - b += iso9660->logical_block_size; - step -= iso9660->logical_block_size; - for (; *p != 0 && p < b && p + *p <= b; p += *p) { - struct file_info *child; - - /* N.B.: these special directory identifiers - * are 8 bit "values" even on a - * Joliet CD with UCS-2 (16bit) encoding. - */ - - /* Skip '.' entry. */ - if (*(p + DR_name_len_offset) == 1 - && *(p + DR_name_offset) == '\0') - continue; - /* Skip '..' entry. */ - if (*(p + DR_name_len_offset) == 1 - && *(p + DR_name_offset) == '\001') - continue; - child = parse_file_info(a, parent, p); - if (child == NULL) - return (ARCHIVE_FATAL); - if (child->cl_offset == 0 && - (child->multi_extent || multi != NULL)) { - struct content *con; - - if (multi == NULL) { - multi = child; - multi->contents.first = NULL; - multi->contents.last = - &(multi->contents.first); - } - con = malloc(sizeof(struct content)); - if (con == NULL) { - archive_set_error( - &a->archive, ENOMEM, - "No memory for " - "multi extent"); - return (ARCHIVE_FATAL); - } - con->offset = child->offset; - con->size = child->size; - con->next = NULL; - *multi->contents.last = con; - multi->contents.last = &(con->next); - if (multi == child) - add_entry(iso9660, child); - else { - multi->size += child->size; - if (!child->multi_extent) - multi = NULL; - } - } else - add_entry(iso9660, child); - } - } - - /* Read data which recorded by RRIP "CE" extension. */ - if (read_CE(a, iso9660) != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - return (ARCHIVE_OK); -} - -static int -archive_read_format_iso9660_read_header(struct archive_read *a, - struct archive_entry *entry) -{ - struct iso9660 *iso9660; - struct file_info *file; - int r, rd_r = ARCHIVE_OK; - - iso9660 = (struct iso9660 *)(a->format->data); - - if (!a->archive.archive_format) { - a->archive.archive_format = ARCHIVE_FORMAT_ISO9660; - a->archive.archive_format_name = "ISO9660"; - } - - if (iso9660->current_position == 0) { - int64_t skipsize; - struct vd *vd; - const void *block; - char seenJoliet; - - vd = &(iso9660->primary); - if (!iso9660->opt_support_joliet) - iso9660->seenJoliet = 0; - if (iso9660->seenJoliet && - vd->location > iso9660->joliet.location) - /* This condition is unlikely; by way of caution. */ - vd = &(iso9660->joliet); - - skipsize = LOGICAL_BLOCK_SIZE * vd->location; - skipsize = __archive_read_skip(a, skipsize); - if (skipsize < 0) - return ((int)skipsize); - iso9660->current_position = skipsize; - - block = __archive_read_ahead(a, vd->size, NULL); - if (block == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Failed to read full block when scanning " - "ISO9660 directory list"); - return (ARCHIVE_FATAL); - } - - /* - * While reading Root Directory, flag seenJoliet - * must be zero to avoid converting special name - * 0x00(Current Directory) and next byte to UCS2. - */ - seenJoliet = iso9660->seenJoliet;/* Save flag. */ - iso9660->seenJoliet = 0; - file = parse_file_info(a, NULL, block); - if (file == NULL) - return (ARCHIVE_FATAL); - iso9660->seenJoliet = seenJoliet; - if (vd == &(iso9660->primary) && iso9660->seenRockridge - && iso9660->seenJoliet) - /* - * If iso image has RockRidge and Joliet, - * we use RockRidge Extensions. - */ - iso9660->seenJoliet = 0; - if (vd == &(iso9660->primary) && !iso9660->seenRockridge - && iso9660->seenJoliet) { - /* Switch reading data from primary to joliet. */ - vd = &(iso9660->joliet); - skipsize = LOGICAL_BLOCK_SIZE * vd->location; - skipsize -= iso9660->current_position; - skipsize = __archive_read_skip(a, skipsize); - if (skipsize < 0) - return ((int)skipsize); - iso9660->current_position += skipsize; - - block = __archive_read_ahead(a, vd->size, NULL); - if (block == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Failed to read full block when scanning " - "ISO9660 directory list"); - return (ARCHIVE_FATAL); - } - seenJoliet = iso9660->seenJoliet;/* Save flag. */ - iso9660->seenJoliet = 0; - file = parse_file_info(a, NULL, block); - if (file == NULL) - return (ARCHIVE_FATAL); - iso9660->seenJoliet = seenJoliet; - } - /* Store the root directory in the pending list. */ - add_entry(iso9660, file); - if (iso9660->seenRockridge) { - a->archive.archive_format = - ARCHIVE_FORMAT_ISO9660_ROCKRIDGE; - a->archive.archive_format_name = - "ISO9660 with Rockridge extensions"; - } - } - - /* Get the next entry that appears after the current offset. */ - r = next_entry_seek(a, iso9660, &file); - if (r != ARCHIVE_OK) - return (r); - - iso9660->entry_bytes_remaining = file->size; - iso9660->entry_sparse_offset = 0; /* Offset for sparse-file-aware clients. */ - - if (file->offset + file->size > iso9660->volume_size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "File is beyond end-of-media: %s", file->name.s); - iso9660->entry_bytes_remaining = 0; - iso9660->entry_sparse_offset = 0; - return (ARCHIVE_WARN); - } - - /* Set up the entry structure with information about this entry. */ - archive_entry_set_mode(entry, file->mode); - archive_entry_set_uid(entry, file->uid); - archive_entry_set_gid(entry, file->gid); - archive_entry_set_nlink(entry, file->nlinks); - if (file->birthtime_is_set) - archive_entry_set_birthtime(entry, file->birthtime, 0); - else - archive_entry_unset_birthtime(entry); - archive_entry_set_mtime(entry, file->mtime, 0); - archive_entry_set_ctime(entry, file->ctime, 0); - archive_entry_set_atime(entry, file->atime, 0); - /* N.B.: Rock Ridge supports 64-bit device numbers. */ - archive_entry_set_rdev(entry, (dev_t)file->rdev); - archive_entry_set_size(entry, iso9660->entry_bytes_remaining); - archive_string_empty(&iso9660->pathname); - archive_entry_set_pathname(entry, - build_pathname(&iso9660->pathname, file)); - if (file->symlink.s != NULL) - archive_entry_copy_symlink(entry, file->symlink.s); - - /* Note: If the input isn't seekable, we can't rewind to - * return the same body again, so if the next entry refers to - * the same data, we have to return it as a hardlink to the - * original entry. */ - if (file->number != -1 && - file->number == iso9660->previous_number) { - archive_entry_set_hardlink(entry, - iso9660->previous_pathname.s); - archive_entry_unset_size(entry); - iso9660->entry_bytes_remaining = 0; - iso9660->entry_sparse_offset = 0; - return (ARCHIVE_OK); - } - - /* Except for the hardlink case above, if the offset of the - * next entry is before our current position, we can't seek - * backwards to extract it, so issue a warning. Note that - * this can only happen if this entry was added to the heap - * after we passed this offset, that is, only if the directory - * mentioning this entry is later than the body of the entry. - * Such layouts are very unusual; most ISO9660 writers lay out - * and record all directory information first, then store - * all file bodies. */ - /* TODO: Someday, libarchive's I/O core will support optional - * seeking. When that day comes, this code should attempt to - * seek and only return the error if the seek fails. That - * will give us support for whacky ISO images that require - * seeking while retaining the ability to read almost all ISO - * images in a streaming fashion. */ - if ((file->mode & AE_IFMT) != AE_IFDIR && - file->offset < iso9660->current_position) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring out-of-order file (%s) %jd < %jd", - iso9660->pathname.s, - (intmax_t)file->offset, - (intmax_t)iso9660->current_position); - iso9660->entry_bytes_remaining = 0; - iso9660->entry_sparse_offset = 0; - return (ARCHIVE_WARN); - } - - /* Initialize zisofs variables. */ - iso9660->entry_zisofs.pz = file->pz; - if (file->pz) { -#ifdef HAVE_ZLIB_H - struct zisofs *zisofs; - - zisofs = &iso9660->entry_zisofs; - zisofs->initialized = 0; - zisofs->pz_log2_bs = file->pz_log2_bs; - zisofs->pz_uncompressed_size = file->pz_uncompressed_size; - zisofs->pz_offset = 0; - zisofs->header_avail = 0; - zisofs->header_passed = 0; - zisofs->block_pointers_avail = 0; -#endif - archive_entry_set_size(entry, file->pz_uncompressed_size); - } - - iso9660->previous_number = file->number; - archive_strcpy(&iso9660->previous_pathname, iso9660->pathname.s); - - /* Reset entry_bytes_remaining if the file is multi extent. */ - iso9660->entry_content = file->contents.first; - if (iso9660->entry_content != NULL) - iso9660->entry_bytes_remaining = iso9660->entry_content->size; - - if (archive_entry_filetype(entry) == AE_IFDIR) { - /* Overwrite nlinks by proper link number which is - * calculated from number of sub directories. */ - archive_entry_set_nlink(entry, 2 + file->subdirs); - /* Directory data has been read completely. */ - iso9660->entry_bytes_remaining = 0; - iso9660->entry_sparse_offset = 0; - } - - if (rd_r != ARCHIVE_OK) - return (rd_r); - return (ARCHIVE_OK); -} - -static int -archive_read_format_iso9660_read_data_skip(struct archive_read *a) -{ - /* Because read_next_header always does an explicit skip - * to the next entry, we don't need to do anything here. */ - (void)a; /* UNUSED */ - return (ARCHIVE_OK); -} - -#ifdef HAVE_ZLIB_H - -static int -zisofs_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - struct iso9660 *iso9660; - struct zisofs *zisofs; - const unsigned char *p; - size_t avail; - ssize_t bytes_read; - size_t uncompressed_size; - int r; - - iso9660 = (struct iso9660 *)(a->format->data); - zisofs = &iso9660->entry_zisofs; - - p = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated zisofs file body"); - return (ARCHIVE_FATAL); - } - if (bytes_read > iso9660->entry_bytes_remaining) - bytes_read = iso9660->entry_bytes_remaining; - avail = bytes_read; - uncompressed_size = 0; - - if (!zisofs->initialized) { - size_t ceil, xsize; - - /* Allocate block pointers buffer. */ - ceil = (zisofs->pz_uncompressed_size + - (1LL << zisofs->pz_log2_bs) - 1) - >> zisofs->pz_log2_bs; - xsize = (ceil + 1) * 4; - if (zisofs->block_pointers_alloc < xsize) { - size_t alloc; - - if (zisofs->block_pointers != NULL) - free(zisofs->block_pointers); - alloc = ((xsize >> 10) + 1) << 10; - zisofs->block_pointers = malloc(alloc); - if (zisofs->block_pointers == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory for zisofs decompression"); - return (ARCHIVE_FATAL); - } - zisofs->block_pointers_alloc = alloc; - } - zisofs->block_pointers_size = xsize; - - /* Allocate uncompressed data buffer. */ - xsize = 1UL << zisofs->pz_log2_bs; - if (zisofs->uncompressed_buffer_size < xsize) { - if (zisofs->uncompressed_buffer != NULL) - free(zisofs->uncompressed_buffer); - zisofs->uncompressed_buffer = malloc(xsize); - if (zisofs->uncompressed_buffer == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory for zisofs decompression"); - return (ARCHIVE_FATAL); - } - } - zisofs->uncompressed_buffer_size = xsize; - - /* - * Read the file header, and check the magic code of zisofs. - */ - if (zisofs->header_avail < sizeof(zisofs->header)) { - xsize = sizeof(zisofs->header) - zisofs->header_avail; - if (avail < xsize) - xsize = avail; - memcpy(zisofs->header + zisofs->header_avail, p, xsize); - zisofs->header_avail += xsize; - avail -= xsize; - p += xsize; - } - if (!zisofs->header_passed && - zisofs->header_avail == sizeof(zisofs->header)) { - int err = 0; - - if (memcmp(zisofs->header, zisofs_magic, - sizeof(zisofs_magic)) != 0) - err = 1; - if (archive_le32dec(zisofs->header + 8) - != zisofs->pz_uncompressed_size) - err = 1; - if (zisofs->header[12] != 4) - err = 1; - if (zisofs->header[13] != zisofs->pz_log2_bs) - err = 1; - if (err) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Illegal zisofs file body"); - return (ARCHIVE_FATAL); - } - zisofs->header_passed = 1; - } - /* - * Read block pointers. - */ - if (zisofs->header_passed && - zisofs->block_pointers_avail < zisofs->block_pointers_size) { - xsize = zisofs->block_pointers_size - - zisofs->block_pointers_avail; - if (avail < xsize) - xsize = avail; - memcpy(zisofs->block_pointers - + zisofs->block_pointers_avail, p, xsize); - zisofs->block_pointers_avail += xsize; - avail -= xsize; - p += xsize; - if (zisofs->block_pointers_avail - == zisofs->block_pointers_size) { - /* We've got all block pointers and initialize - * related variables. */ - zisofs->block_off = 0; - zisofs->block_avail = 0; - /* Complete a initialization */ - zisofs->initialized = 1; - } - } - - if (!zisofs->initialized) - goto next_data; /* We need more datas. */ - } - - /* - * Get block offsets from block pointers. - */ - if (zisofs->block_avail == 0) { - uint32_t bst, bed; - - if (zisofs->block_off + 4 >= zisofs->block_pointers_size) { - /* There isn't a pair of offsets. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Illegal zisofs block pointers"); - return (ARCHIVE_FATAL); - } - bst = archive_le32dec(zisofs->block_pointers + zisofs->block_off); - if (bst != zisofs->pz_offset + (bytes_read - avail)) { - /* TODO: Should we seek offset of current file by bst ? */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Illegal zisofs block pointers(cannot seek)"); - return (ARCHIVE_FATAL); - } - bed = archive_le32dec( - zisofs->block_pointers + zisofs->block_off + 4); - if (bed < bst) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Illegal zisofs block pointers"); - return (ARCHIVE_FATAL); - } - zisofs->block_avail = bed - bst; - zisofs->block_off += 4; - - /* Initialize compression library for new block. */ - if (zisofs->stream_valid) - r = inflateReset(&zisofs->stream); - else - r = inflateInit(&zisofs->stream); - if (r != Z_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Can't initialize zisofs decompression."); - return (ARCHIVE_FATAL); - } - zisofs->stream_valid = 1; - zisofs->stream.total_in = 0; - zisofs->stream.total_out = 0; - } - - /* - * Make uncompressed datas. - */ - if (zisofs->block_avail == 0) { - memset(zisofs->uncompressed_buffer, 0, - zisofs->uncompressed_buffer_size); - uncompressed_size = zisofs->uncompressed_buffer_size; - } else { - zisofs->stream.next_in = (Bytef *)(uintptr_t)(const void *)p; - if (avail > zisofs->block_avail) - zisofs->stream.avail_in = zisofs->block_avail; - else - zisofs->stream.avail_in = avail; - zisofs->stream.next_out = zisofs->uncompressed_buffer; - zisofs->stream.avail_out = zisofs->uncompressed_buffer_size; - - r = inflate(&zisofs->stream, 0); - switch (r) { - case Z_OK: /* Decompressor made some progress.*/ - case Z_STREAM_END: /* Found end of stream. */ - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "zisofs decompression failed (%d)", r); - return (ARCHIVE_FATAL); - } - uncompressed_size = - zisofs->uncompressed_buffer_size - zisofs->stream.avail_out; - avail -= zisofs->stream.next_in - p; - zisofs->block_avail -= zisofs->stream.next_in - p; - } -next_data: - bytes_read -= avail; - *buff = zisofs->uncompressed_buffer; - *size = uncompressed_size; - *offset = iso9660->entry_sparse_offset; - iso9660->entry_sparse_offset += uncompressed_size; - iso9660->entry_bytes_remaining -= bytes_read; - iso9660->current_position += bytes_read; - zisofs->pz_offset += bytes_read; - __archive_read_consume(a, bytes_read); - - return (ARCHIVE_OK); -} - -#else /* HAVE_ZLIB_H */ - -static int -zisofs_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - - (void)buff;/* UNUSED */ - (void)size;/* UNUSED */ - (void)offset;/* UNUSED */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "zisofs is not supported on this platform."); - return (ARCHIVE_FAILED); -} - -#endif /* HAVE_ZLIB_H */ - -static int -archive_read_format_iso9660_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - ssize_t bytes_read; - struct iso9660 *iso9660; - - iso9660 = (struct iso9660 *)(a->format->data); - if (iso9660->entry_bytes_remaining <= 0) { - if (iso9660->entry_content != NULL) - iso9660->entry_content = iso9660->entry_content->next; - if (iso9660->entry_content == NULL) { - *buff = NULL; - *size = 0; - *offset = iso9660->entry_sparse_offset; - return (ARCHIVE_EOF); - } - /* Seek forward to the start of the entry. */ - if (iso9660->current_position < iso9660->entry_content->offset) { - int64_t step; - - step = iso9660->entry_content->offset - - iso9660->current_position; - step = __archive_read_skip(a, step); - if (step < 0) - return ((int)step); - iso9660->current_position = - iso9660->entry_content->offset; - } - if (iso9660->entry_content->offset < iso9660->current_position) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring out-of-order file (%s) %jd < %jd", - iso9660->pathname.s, - (intmax_t)iso9660->entry_content->offset, - (intmax_t)iso9660->current_position); - *buff = NULL; - *size = 0; - *offset = iso9660->entry_sparse_offset; - return (ARCHIVE_WARN); - } - iso9660->entry_bytes_remaining = iso9660->entry_content->size; - } - if (iso9660->entry_zisofs.pz) - return (zisofs_read_data(a, buff, size, offset)); - - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read == 0) - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated input file"); - if (*buff == NULL) - return (ARCHIVE_FATAL); - if (bytes_read > iso9660->entry_bytes_remaining) - bytes_read = iso9660->entry_bytes_remaining; - *size = bytes_read; - *offset = iso9660->entry_sparse_offset; - iso9660->entry_sparse_offset += bytes_read; - iso9660->entry_bytes_remaining -= bytes_read; - iso9660->current_position += bytes_read; - __archive_read_consume(a, bytes_read); - return (ARCHIVE_OK); -} - -static int -archive_read_format_iso9660_cleanup(struct archive_read *a) -{ - struct iso9660 *iso9660; - int r = ARCHIVE_OK; - - iso9660 = (struct iso9660 *)(a->format->data); - release_files(iso9660); - free(iso9660->read_ce_req.reqs); - archive_string_free(&iso9660->pathname); - archive_string_free(&iso9660->previous_pathname); - if (iso9660->pending_files.files) - free(iso9660->pending_files.files); -#ifdef HAVE_ZLIB_H - free(iso9660->entry_zisofs.uncompressed_buffer); - free(iso9660->entry_zisofs.block_pointers); - if (iso9660->entry_zisofs.stream_valid) { - if (inflateEnd(&iso9660->entry_zisofs.stream) != Z_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Failed to clean up zlib decompressor"); - r = ARCHIVE_FATAL; - } - } -#endif - free(iso9660); - (a->format->data) = NULL; - return (r); -} - -/* - * This routine parses a single ISO directory record, makes sense - * of any extensions, and stores the result in memory. - */ -static struct file_info * -parse_file_info(struct archive_read *a, struct file_info *parent, - const unsigned char *isodirrec) -{ - struct iso9660 *iso9660; - struct file_info *file; - size_t name_len; - const unsigned char *rr_start, *rr_end; - const unsigned char *p; - size_t dr_len; - uint64_t fsize; - int32_t location; - int flags; - - iso9660 = (struct iso9660 *)(a->format->data); - - dr_len = (size_t)isodirrec[DR_length_offset]; - name_len = (size_t)isodirrec[DR_name_len_offset]; - location = archive_le32dec(isodirrec + DR_extent_offset); - fsize = toi(isodirrec + DR_size_offset, DR_size_size); - /* Sanity check that dr_len needs at least 34. */ - if (dr_len < 34) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid length of directory record"); - return (NULL); - } - /* Sanity check that name_len doesn't exceed dr_len. */ - if (dr_len - 33 < name_len || name_len == 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid length of file identifier"); - return (NULL); - } - /* Sanity check that location doesn't exceed volume block. - * Don't check lower limit of location; it's possibility - * the location has negative value when file type is symbolic - * link or file size is zero. As far as I know latest mkisofs - * do that. - */ - if (location > 0 && - (location + ((fsize + iso9660->logical_block_size -1) - / iso9660->logical_block_size)) - > (uint32_t)iso9660->volume_block) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid location of extent of file"); - return (NULL); - } - - /* Create a new file entry and copy data from the ISO dir record. */ - file = (struct file_info *)malloc(sizeof(*file)); - if (file == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory for file entry"); - return (NULL); - } - memset(file, 0, sizeof(*file)); - file->parent = parent; - file->offset = iso9660->logical_block_size * (uint64_t)location; - file->size = fsize; - file->mtime = isodate7(isodirrec + DR_date_offset); - file->ctime = file->atime = file->mtime; - file->rede_files.first = NULL; - file->rede_files.last = &(file->rede_files.first); - - p = isodirrec + DR_name_offset; - /* Rockridge extensions (if any) follow name. Compute this - * before fidgeting the name_len below. */ - rr_start = p + name_len + (name_len & 1 ? 0 : 1); - rr_end = isodirrec + dr_len; - - if (iso9660->seenJoliet) { - /* Joliet names are max 64 chars (128 bytes) according to spec, - * but genisoimage/mkisofs allows recording longer Joliet - * names which are 103 UCS2 characters(206 bytes) by their - * option '-joliet-long'. - */ - wchar_t wbuff[103+1], *wp; - const unsigned char *c; - - if (name_len > 206) - name_len = 206; - /* convert BE UTF-16 to wchar_t */ - for (c = p, wp = wbuff; - c < (p + name_len) && - wp < (wbuff + sizeof(wbuff)/sizeof(*wbuff) - 1); - c += 2) { - *wp++ = (((255 & (int)c[0]) << 8) | (255 & (int)c[1])); - } - *wp = L'\0'; - -#if 0 /* untested code, is it at all useful on Joliet? */ - /* trim trailing first version and dot from filename. - * - * Remember we where in UTF-16BE land! - * SEPARATOR 1 (.) and SEPARATOR 2 (;) are both - * 16 bits big endian characters on Joliet. - * - * TODO: sanitize filename? - * Joliet allows any UCS-2 char except: - * *, /, :, ;, ? and \. - */ - /* Chop off trailing ';1' from files. */ - if (*(wp-2) == ';' && *(wp-1) == '1') { - wp-=2; - *wp = L'\0'; - } - - /* Chop off trailing '.' from filenames. */ - if (*(wp-1) == '.') - *(--wp) = L'\0'; -#endif - - /* store the result in the file name field. */ - archive_strappend_w_utf8(&file->name, wbuff); - } else { - /* Chop off trailing ';1' from files. */ - if (name_len > 2 && p[name_len - 2] == ';' && - p[name_len - 1] == '1') - name_len -= 2; - /* Chop off trailing '.' from filenames. */ - if (name_len > 1 && p[name_len - 1] == '.') - --name_len; - - archive_strncpy(&file->name, (const char *)p, name_len); - } - - flags = isodirrec[DR_flags_offset]; - if (flags & 0x02) - file->mode = AE_IFDIR | 0700; - else - file->mode = AE_IFREG | 0400; - if (flags & 0x80) - file->multi_extent = 1; - else - file->multi_extent = 0; - /* - * Use location for file number. - * File number is treated as inode number to find out harlink - * target. If Rockridge extensions is being used, file number - * will be overwritten by FILE SERIAL NUMBER of RRIP "PX" - * extension. - * NOTE: Old mkisofs did not record that FILE SERIAL NUMBER - * in ISO images. - */ - if (file->size == 0 && location >= 0) - /* If file->size is zero, its location points wrong place. - * Dot not use it for file number. - * When location has negative value, it can be used - * for file number. - */ - file->number = -1; - else - file->number = (int64_t)(uint32_t)location; - - /* Rockridge extensions overwrite information from above. */ - if (iso9660->opt_support_rockridge) { - if (parent == NULL && rr_end - rr_start >= 7) { - p = rr_start; - if (p[0] == 'S' && p[1] == 'P' - && p[2] == 7 && p[3] == 1 - && p[4] == 0xBE && p[5] == 0xEF) { - /* - * SP extension stores the suspOffset - * (Number of bytes to skip between - * filename and SUSP records.) - * It is mandatory by the SUSP standard - * (IEEE 1281). - * - * It allows SUSP to coexist with - * non-SUSP uses of the System - * Use Area by placing non-SUSP data - * before SUSP data. - * - * SP extension must be in the root - * directory entry, disable all SUSP - * processing if not found. - */ - iso9660->suspOffset = p[6]; - iso9660->seenSUSP = 1; - rr_start += 7; - } - } - if (iso9660->seenSUSP) { - int r; - - file->name_continues = 0; - file->symlink_continues = 0; - rr_start += iso9660->suspOffset; - r = parse_rockridge(a, file, rr_start, rr_end); - if (r != ARCHIVE_OK) { - free(file); - return (NULL); - } - } else - /* If there isn't SUSP, disable parsing - * rock ridge extensions. */ - iso9660->opt_support_rockridge = 0; - } - - file->nlinks = 1;/* Reset nlink. we'll calculate it later. */ - /* Tell file's parent how many children that parent has. */ - if (parent != NULL && (flags & 0x02)) - parent->subdirs++; - - if (iso9660->seenRockridge) { - if (parent != NULL && parent->parent == NULL && - (flags & 0x02) && iso9660->rr_moved == NULL && - (strcmp(file->name.s, "rr_moved") == 0 || - strcmp(file->name.s, ".rr_moved") == 0)) { - iso9660->rr_moved = file; - file->rr_moved = 1; - file->rr_moved_has_re_only = 1; - file->re = 0; - parent->subdirs--; - } else if (file->re) { - /* This file's parent is not rr_moved, clear invalid - * "RE" mark. */ - if (parent == NULL || parent->rr_moved == 0) - file->re = 0; - else if ((flags & 0x02) == 0) { - file->rr_moved_has_re_only = 0; - file->re = 0; - } - } else if (parent != NULL && parent->rr_moved) - file->rr_moved_has_re_only = 0; - else if (parent != NULL && (flags & 0x02) && - (parent->re || parent->re_descendant)) - file->re_descendant = 1; - if (file->cl_offset != 0) { - parent->subdirs++; - /* Overwrite an offset and a number of this "CL" entry - * to appear before other dirs. "+1" to those is to - * make sure to appear after "RE" entry which this - * "CL" entry should be connected with. */ - file->offset = file->number = file->cl_offset + 1; - } - } - -#if DEBUG - /* DEBUGGING: Warn about attributes I don't yet fully support. */ - if ((flags & ~0x02) != 0) { - fprintf(stderr, "\n ** Unrecognized flag: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } else if (toi(isodirrec + DR_volume_sequence_number_offset, 2) != 1) { - fprintf(stderr, "\n ** Unrecognized sequence number: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } else if (*(isodirrec + DR_file_unit_size_offset) != 0) { - fprintf(stderr, "\n ** Unexpected file unit size: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } else if (*(isodirrec + DR_interleave_offset) != 0) { - fprintf(stderr, "\n ** Unexpected interleave: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } else if (*(isodirrec + DR_ext_attr_length_offset) != 0) { - fprintf(stderr, "\n ** Unexpected extended attribute length: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } -#endif - register_file(iso9660, file); - return (file); -} - -static int -parse_rockridge(struct archive_read *a, struct file_info *file, - const unsigned char *p, const unsigned char *end) -{ - struct iso9660 *iso9660; - - iso9660 = (struct iso9660 *)(a->format->data); - - while (p + 4 <= end /* Enough space for another entry. */ - && p[0] >= 'A' && p[0] <= 'Z' /* Sanity-check 1st char of name. */ - && p[1] >= 'A' && p[1] <= 'Z' /* Sanity-check 2nd char of name. */ - && p[2] >= 4 /* Sanity-check length. */ - && p + p[2] <= end) { /* Sanity-check length. */ - const unsigned char *data = p + 4; - int data_length = p[2] - 4; - int version = p[3]; - - /* - * Yes, each 'if' here does test p[0] again. - * Otherwise, the fall-through handling to catch - * unsupported extensions doesn't work. - */ - switch(p[0]) { - case 'C': - if (p[0] == 'C' && p[1] == 'E') { - if (version == 1 && data_length == 24) { - /* - * CE extension comprises: - * 8 byte sector containing extension - * 8 byte offset w/in above sector - * 8 byte length of continuation - */ - int32_t location = - archive_le32dec(data); - file->ce_offset = - archive_le32dec(data+8); - file->ce_size = - archive_le32dec(data+16); - if (register_CE(a, location, file) - != ARCHIVE_OK) - return (ARCHIVE_FATAL); - } - break; - } - if (p[0] == 'C' && p[1] == 'L') { - if (version == 1 && data_length == 8) { - file->cl_offset = (uint64_t) - iso9660->logical_block_size * - (uint64_t)archive_le32dec(data); - iso9660->seenRockridge = 1; - } - break; - } - /* FALLTHROUGH */ - case 'N': - if (p[0] == 'N' && p[1] == 'M') { - if (version == 1) { - parse_rockridge_NM1(file, - data, data_length); - iso9660->seenRockridge = 1; - } - break; - } - /* FALLTHROUGH */ - case 'P': - if (p[0] == 'P' && p[1] == 'D') { - /* - * PD extension is padding; - * contents are always ignored. - */ - break; - } - if (p[0] == 'P' && p[1] == 'N') { - if (version == 1 && data_length == 16) { - file->rdev = toi(data,4); - file->rdev <<= 32; - file->rdev |= toi(data + 8, 4); - iso9660->seenRockridge = 1; - } - break; - } - if (p[0] == 'P' && p[1] == 'X') { - /* - * PX extension comprises: - * 8 bytes for mode, - * 8 bytes for nlinks, - * 8 bytes for uid, - * 8 bytes for gid, - * 8 bytes for inode. - */ - if (version == 1) { - if (data_length >= 8) - file->mode - = toi(data, 4); - if (data_length >= 16) - file->nlinks - = toi(data + 8, 4); - if (data_length >= 24) - file->uid - = toi(data + 16, 4); - if (data_length >= 32) - file->gid - = toi(data + 24, 4); - if (data_length >= 40) - file->number - = toi(data + 32, 4); - iso9660->seenRockridge = 1; - } - break; - } - /* FALLTHROUGH */ - case 'R': - if (p[0] == 'R' && p[1] == 'E' && version == 1) { - file->re = 1; - iso9660->seenRockridge = 1; - break; - } - if (p[0] == 'R' && p[1] == 'R' && version == 1) { - /* - * RR extension comprises: - * one byte flag value - * This extension is obsolete, - * so contents are always ignored. - */ - break; - } - /* FALLTHROUGH */ - case 'S': - if (p[0] == 'S' && p[1] == 'L') { - if (version == 1) { - parse_rockridge_SL1(file, - data, data_length); - iso9660->seenRockridge = 1; - } - break; - } - if (p[0] == 'S' && p[1] == 'T' - && data_length == 0 && version == 1) { - /* - * ST extension marks end of this - * block of SUSP entries. - * - * It allows SUSP to coexist with - * non-SUSP uses of the System - * Use Area by placing non-SUSP data - * after SUSP data. - */ - iso9660->seenSUSP = 0; - iso9660->seenRockridge = 0; - return (ARCHIVE_OK); - } - case 'T': - if (p[0] == 'T' && p[1] == 'F') { - if (version == 1) { - parse_rockridge_TF1(file, - data, data_length); - iso9660->seenRockridge = 1; - } - break; - } - /* FALLTHROUGH */ - case 'Z': - if (p[0] == 'Z' && p[1] == 'F') { - if (version == 1) - parse_rockridge_ZF1(file, - data, data_length); - break; - } - /* FALLTHROUGH */ - default: - /* The FALLTHROUGHs above leave us here for - * any unsupported extension. */ - break; - } - - - - p += p[2]; - } - return (ARCHIVE_OK); -} - -static int -register_CE(struct archive_read *a, int32_t location, - struct file_info *file) -{ - struct iso9660 *iso9660; - struct read_ce_queue *heap; - struct read_ce_req *p; - uint64_t offset, parent_offset; - int hole, parent; - - iso9660 = (struct iso9660 *)(a->format->data); - offset = ((uint64_t)location) * (uint64_t)iso9660->logical_block_size; - if (((file->mode & AE_IFMT) == AE_IFREG && - offset >= file->offset) || - offset < iso9660->current_position) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid location in SUSP \"CE\" extension"); - return (ARCHIVE_FATAL); - } - - /* Expand our CE list as necessary. */ - heap = &(iso9660->read_ce_req); - if (heap->cnt >= heap->allocated) { - int new_size; - - if (heap->allocated < 16) - new_size = 16; - else - new_size = heap->allocated * 2; - /* Overflow might keep us from growing the list. */ - if (new_size <= heap->allocated) - __archive_errx(1, "Out of memory"); - p = malloc(new_size * sizeof(p[0])); - if (p == NULL) - __archive_errx(1, "Out of memory"); - if (heap->reqs != NULL) { - memcpy(p, heap->reqs, heap->cnt * sizeof(*p)); - free(heap->reqs); - } - heap->reqs = p; - heap->allocated = new_size; - } - - /* - * Start with hole at end, walk it up tree to find insertion point. - */ - hole = heap->cnt++; - while (hole > 0) { - parent = (hole - 1)/2; - parent_offset = heap->reqs[parent].offset; - if (offset >= parent_offset) { - heap->reqs[hole].offset = offset; - heap->reqs[hole].file = file; - return (ARCHIVE_OK); - } - // Move parent into hole <==> move hole up tree. - heap->reqs[hole] = heap->reqs[parent]; - hole = parent; - } - heap->reqs[0].offset = offset; - heap->reqs[0].file = file; - return (ARCHIVE_OK); -} - -static void -next_CE(struct read_ce_queue *heap) -{ - uint64_t a_offset, b_offset, c_offset; - int a, b, c; - struct read_ce_req tmp; - - if (heap->cnt < 1) - return; - - /* - * Move the last item in the heap to the root of the tree - */ - heap->reqs[0] = heap->reqs[--(heap->cnt)]; - - /* - * Rebalance the heap. - */ - a = 0; // Starting element and its offset - a_offset = heap->reqs[a].offset; - for (;;) { - b = a + a + 1; // First child - if (b >= heap->cnt) - return; - b_offset = heap->reqs[b].offset; - c = b + 1; // Use second child if it is smaller. - if (c < heap->cnt) { - c_offset = heap->reqs[c].offset; - if (c_offset < b_offset) { - b = c; - b_offset = c_offset; - } - } - if (a_offset <= b_offset) - return; - tmp = heap->reqs[a]; - heap->reqs[a] = heap->reqs[b]; - heap->reqs[b] = tmp; - a = b; - } -} - - -static int -read_CE(struct archive_read *a, struct iso9660 *iso9660) -{ - struct read_ce_queue *heap; - const unsigned char *b, *p, *end; - struct file_info *file; - size_t step; - int r; - - /* Read data which RRIP "CE" extension points. */ - heap = &(iso9660->read_ce_req); - step = iso9660->logical_block_size; - while (heap->cnt && - heap->reqs[0].offset == iso9660->current_position) { - b = __archive_read_ahead(a, step, NULL); - if (b == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Failed to read full block when scanning " - "ISO9660 directory list"); - return (ARCHIVE_FATAL); - } - do { - file = heap->reqs[0].file; - p = b + file->ce_offset; - end = p + file->ce_size; - next_CE(heap); - r = parse_rockridge(a, file, p, end); - if (r != ARCHIVE_OK) - return (ARCHIVE_FATAL); - } while (heap->cnt && - heap->reqs[0].offset == iso9660->current_position); - /* NOTE: Do not move this consume's code to fron of - * do-while loop. Registration of nested CE extension - * might cause error because of current position. */ - __archive_read_consume(a, step); - iso9660->current_position += step; - } - return (ARCHIVE_OK); -} - -static void -parse_rockridge_NM1(struct file_info *file, - const unsigned char *data, int data_length) -{ - if (!file->name_continues) - archive_string_empty(&file->name); - file->name_continues = 0; - if (data_length < 1) - return; - /* - * NM version 1 extension comprises: - * 1 byte flag, value is one of: - * = 0: remainder is name - * = 1: remainder is name, next NM entry continues name - * = 2: "." - * = 4: ".." - * = 32: Implementation specific - * All other values are reserved. - */ - switch(data[0]) { - case 0: - if (data_length < 2) - return; - archive_strncat(&file->name, (const char *)data + 1, data_length - 1); - break; - case 1: - if (data_length < 2) - return; - archive_strncat(&file->name, (const char *)data + 1, data_length - 1); - file->name_continues = 1; - break; - case 2: - archive_strcat(&file->name, "."); - break; - case 4: - archive_strcat(&file->name, ".."); - break; - default: - return; - } - -} - -static void -parse_rockridge_TF1(struct file_info *file, const unsigned char *data, - int data_length) -{ - char flag; - /* - * TF extension comprises: - * one byte flag - * create time (optional) - * modify time (optional) - * access time (optional) - * attribute time (optional) - * Time format and presence of fields - * is controlled by flag bits. - */ - if (data_length < 1) - return; - flag = data[0]; - ++data; - --data_length; - if (flag & 0x80) { - /* Use 17-byte time format. */ - if ((flag & 1) && data_length >= 17) { - /* Create time. */ - file->birthtime_is_set = 1; - file->birthtime = isodate17(data); - data += 17; - data_length -= 17; - } - if ((flag & 2) && data_length >= 17) { - /* Modify time. */ - file->mtime = isodate17(data); - data += 17; - data_length -= 17; - } - if ((flag & 4) && data_length >= 17) { - /* Access time. */ - file->atime = isodate17(data); - data += 17; - data_length -= 17; - } - if ((flag & 8) && data_length >= 17) { - /* Attribute change time. */ - file->ctime = isodate17(data); - } - } else { - /* Use 7-byte time format. */ - if ((flag & 1) && data_length >= 7) { - /* Create time. */ - file->birthtime_is_set = 1; - file->birthtime = isodate7(data); - data += 7; - data_length -= 7; - } - if ((flag & 2) && data_length >= 7) { - /* Modify time. */ - file->mtime = isodate7(data); - data += 7; - data_length -= 7; - } - if ((flag & 4) && data_length >= 7) { - /* Access time. */ - file->atime = isodate7(data); - data += 7; - data_length -= 7; - } - if ((flag & 8) && data_length >= 7) { - /* Attribute change time. */ - file->ctime = isodate7(data); - } - } -} - -static void -parse_rockridge_SL1(struct file_info *file, const unsigned char *data, - int data_length) -{ - const char *separator = ""; - - if (!file->symlink_continues || file->symlink.length < 1) - archive_string_empty(&file->symlink); - else if (!file->symlink_continues && - file->symlink.s[file->symlink.length - 1] != '/') - separator = "/"; - file->symlink_continues = 0; - - /* - * Defined flag values: - * 0: This is the last SL record for this symbolic link - * 1: this symbolic link field continues in next SL entry - * All other values are reserved. - */ - if (data_length < 1) - return; - switch(*data) { - case 0: - break; - case 1: - file->symlink_continues = 1; - break; - default: - return; - } - ++data; /* Skip flag byte. */ - --data_length; - - /* - * SL extension body stores "components". - * Basically, this is a complicated way of storing - * a POSIX path. It also interferes with using - * symlinks for storing non-path data. - * - * Each component is 2 bytes (flag and length) - * possibly followed by name data. - */ - while (data_length >= 2) { - unsigned char flag = *data++; - unsigned char nlen = *data++; - data_length -= 2; - - archive_strcat(&file->symlink, separator); - separator = "/"; - - switch(flag) { - case 0: /* Usual case, this is text. */ - if (data_length < nlen) - return; - archive_strncat(&file->symlink, - (const char *)data, nlen); - break; - case 0x01: /* Text continues in next component. */ - if (data_length < nlen) - return; - archive_strncat(&file->symlink, - (const char *)data, nlen); - separator = ""; - break; - case 0x02: /* Current dir. */ - archive_strcat(&file->symlink, "."); - break; - case 0x04: /* Parent dir. */ - archive_strcat(&file->symlink, ".."); - break; - case 0x08: /* Root of filesystem. */ - archive_strcat(&file->symlink, "/"); - separator = ""; - break; - case 0x10: /* Undefined (historically "volume root" */ - archive_string_empty(&file->symlink); - archive_strcat(&file->symlink, "ROOT"); - break; - case 0x20: /* Undefined (historically "hostname") */ - archive_strcat(&file->symlink, "hostname"); - break; - default: - /* TODO: issue a warning ? */ - return; - } - data += nlen; - data_length -= nlen; - } -} - -static void -parse_rockridge_ZF1(struct file_info *file, const unsigned char *data, - int data_length) -{ - - if (data[0] == 0x70 && data[1] == 0x7a && data_length == 12) { - /* paged zlib */ - file->pz = 1; - file->pz_log2_bs = data[3]; - file->pz_uncompressed_size = archive_le32dec(&data[4]); - } -} - -static void -register_file(struct iso9660 *iso9660, struct file_info *file) -{ - - file->use_next = iso9660->use_files; - iso9660->use_files = file; -} - -static void -release_files(struct iso9660 *iso9660) -{ - struct content *con, *connext; - struct file_info *file; - - file = iso9660->use_files; - while (file != NULL) { - struct file_info *next = file->use_next; - - archive_string_free(&file->name); - archive_string_free(&file->symlink); - con = file->contents.first; - while (con != NULL) { - connext = con->next; - free(con); - con = connext; - } - free(file); - file = next; - } -} - -static int -next_entry_seek(struct archive_read *a, struct iso9660 *iso9660, - struct file_info **pfile) -{ - struct file_info *file; - int r; - - r = next_cache_entry(a, iso9660, pfile); - if (r != ARCHIVE_OK) - return (r); - file = *pfile; - - /* Don't waste time seeking for zero-length bodies. */ - if (file->size == 0) - file->offset = iso9660->current_position; - - /* Seek forward to the start of the entry. */ - if (iso9660->current_position < file->offset) { - int64_t step; - - step = file->offset - iso9660->current_position; - step = __archive_read_skip(a, step); - if (step < 0) - return ((int)step); - iso9660->current_position = file->offset; - } - - /* We found body of file; handle it now. */ - return (ARCHIVE_OK); -} - -static int -next_cache_entry(struct archive_read *a, struct iso9660 *iso9660, - struct file_info **pfile) -{ - struct file_info *file; - struct { - struct file_info *first; - struct file_info **last; - } empty_files; - int64_t number; - int count; - - file = cache_get_entry(iso9660); - if (file != NULL) { - *pfile = file; - return (ARCHIVE_OK); - } - - for (;;) { - struct file_info *re, *d; - - *pfile = file = next_entry(iso9660); - if (file == NULL) { - /* - * If directory entries all which are descendant of - * rr_moved are stil remaning, expose their. - */ - if (iso9660->re_files.first != NULL && - iso9660->rr_moved != NULL && - iso9660->rr_moved->rr_moved_has_re_only) - /* Expose "rr_moved" entry. */ - cache_add_entry(iso9660, iso9660->rr_moved); - while ((re = re_get_entry(iso9660)) != NULL) { - /* Expose its descendant dirs. */ - while ((d = rede_get_entry(re)) != NULL) - cache_add_entry(iso9660, d); - } - if (iso9660->cache_files.first != NULL) - return (next_cache_entry(a, iso9660, pfile)); - return (ARCHIVE_EOF); - } - - if (file->cl_offset) { - struct file_info *first_re = NULL; - int nexted_re = 0; - - /* - * Find "RE" dir for the current file, which - * has "CL" flag. - */ - while ((re = re_get_entry(iso9660)) - != first_re) { - if (first_re == NULL) - first_re = re; - if (re->offset == file->cl_offset) { - re->parent->subdirs--; - re->parent = file->parent; - re->re = 0; - if (re->parent->re_descendant) { - nexted_re = 1; - re->re_descendant = 1; - if (rede_add_entry(re) < 0) - goto fatal_rr; - /* Move a list of descendants - * to a new ancestor. */ - while ((d = rede_get_entry( - re)) != NULL) - if (rede_add_entry(d) - < 0) - goto fatal_rr; - break; - } - /* Replace the current file - * with "RE" dir */ - *pfile = file = re; - /* Expose its descendant */ - while ((d = rede_get_entry( - file)) != NULL) - cache_add_entry( - iso9660, d); - break; - } else - re_add_entry(iso9660, re); - } - if (nexted_re) { - /* - * Do not expose this at this time - * because we have not gotten its full-path - * name yet. - */ - continue; - } - } else if ((file->mode & AE_IFMT) == AE_IFDIR) { - int r; - - /* Read file entries in this dir. */ - r = read_children(a, file); - if (r != ARCHIVE_OK) - return (r); - - /* - * Handle a special dir of Rockridge extensions, - * "rr_moved". - */ - if (file->rr_moved) { - /* - * If this has only the subdirectories which - * have "RE" flags, do not expose at this time. - */ - if (file->rr_moved_has_re_only) - continue; - /* Otherwise expose "rr_moved" entry. */ - } else if (file->re) { - /* - * Do not expose this at this time - * because we have not gotten its full-path - * name yet. - */ - re_add_entry(iso9660, file); - continue; - } else if (file->re_descendant) { - /* - * If the top level "RE" entry of this entry - * is not exposed, we, accordingly, should not - * expose this entry at this time because - * we cannot make its proper full-path name. - */ - if (rede_add_entry(file) == 0) - continue; - /* Otherwise we can expose this entry because - * it seems its top level "RE" has already been - * exposed. */ - } - } - break; - } - - if ((file->mode & AE_IFMT) != AE_IFREG || file->number == -1) - return (ARCHIVE_OK); - - count = 0; - number = file->number; - iso9660->cache_files.first = NULL; - iso9660->cache_files.last = &(iso9660->cache_files.first); - empty_files.first = NULL; - empty_files.last = &empty_files.first; - /* Collect files which has the same file serial number. - * Peek pending_files so that file which number is different - * is not put bak. */ - while (iso9660->pending_files.used > 0 && - (iso9660->pending_files.files[0]->number == -1 || - iso9660->pending_files.files[0]->number == number)) { - if (file->number == -1) { - /* This file has the same offset - * but it's wrong offset which empty files - * and symlink files have. - * NOTE: This wrong offse was recorded by - * old mkisofs utility. If ISO images is - * created by latest mkisofs, this does not - * happen. - */ - file->next = NULL; - *empty_files.last = file; - empty_files.last = &(file->next); - } else { - count++; - cache_add_entry(iso9660, file); - } - file = next_entry(iso9660); - } - - if (count == 0) { - *pfile = file; - return ((file == NULL)?ARCHIVE_EOF:ARCHIVE_OK); - } - if (file->number == -1) { - file->next = NULL; - *empty_files.last = file; - empty_files.last = &(file->next); - } else { - count++; - cache_add_entry(iso9660, file); - } - - if (count > 1) { - /* The count is the same as number of hardlink, - * so much so that each nlinks of files in cache_file - * is overwritten by value of the count. - */ - for (file = iso9660->cache_files.first; - file != NULL; file = file->next) - file->nlinks = count; - } - /* If there are empty files, that files are added - * to the tail of the cache_files. */ - if (empty_files.first != NULL) { - *iso9660->cache_files.last = empty_files.first; - iso9660->cache_files.last = empty_files.last; - } - *pfile = cache_get_entry(iso9660); - return ((*pfile == NULL)?ARCHIVE_EOF:ARCHIVE_OK); - -fatal_rr: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Failed to connect 'CL' pointer to 'RE' rr_moved pointer of" - "Rockridge extensions"); - return (ARCHIVE_FATAL); -} - -static inline void -re_add_entry(struct iso9660 *iso9660, struct file_info *file) -{ - file->re_next = NULL; - *iso9660->re_files.last = file; - iso9660->re_files.last = &(file->re_next); -} - -static inline struct file_info * -re_get_entry(struct iso9660 *iso9660) -{ - struct file_info *file; - - if ((file = iso9660->re_files.first) != NULL) { - iso9660->re_files.first = file->re_next; - if (iso9660->re_files.first == NULL) - iso9660->re_files.last = - &(iso9660->re_files.first); - } - return (file); -} - -static inline int -rede_add_entry(struct file_info *file) -{ - struct file_info *re; - - re = file->parent; - while (re != NULL && !re->re) { - /* Sanity check to prevent a infinity loop - * cause by a currupted iso file. */ - if (re->loop_by == file) - return (-1); - re->loop_by = file; - re = re->parent; - } - if (re == NULL) - return (-1); - - file->re_next = NULL; - *re->rede_files.last = file; - re->rede_files.last = &(file->re_next); - return (0); -} - -static inline struct file_info * -rede_get_entry(struct file_info *re) -{ - struct file_info *file; - - if ((file = re->rede_files.first) != NULL) { - re->rede_files.first = file->re_next; - if (re->rede_files.first == NULL) - re->rede_files.last = - &(re->rede_files.first); - } - return (file); -} - -static inline void -cache_add_entry(struct iso9660 *iso9660, struct file_info *file) -{ - file->next = NULL; - *iso9660->cache_files.last = file; - iso9660->cache_files.last = &(file->next); -} - -static inline struct file_info * -cache_get_entry(struct iso9660 *iso9660) -{ - struct file_info *file; - - if ((file = iso9660->cache_files.first) != NULL) { - iso9660->cache_files.first = file->next; - if (iso9660->cache_files.first == NULL) - iso9660->cache_files.last = &(iso9660->cache_files.first); - } - return (file); -} - -static void -heap_add_entry(struct heap_queue *heap, struct file_info *file, uint64_t key) -{ - uint64_t file_key, parent_key; - int hole, parent; - - /* Expand our pending files list as necessary. */ - if (heap->used >= heap->allocated) { - struct file_info **new_pending_files; - int new_size = heap->allocated * 2; - - if (heap->allocated < 1024) - new_size = 1024; - /* Overflow might keep us from growing the list. */ - if (new_size <= heap->allocated) - __archive_errx(1, "Out of memory"); - new_pending_files = (struct file_info **) - malloc(new_size * sizeof(new_pending_files[0])); - if (new_pending_files == NULL) - __archive_errx(1, "Out of memory"); - memcpy(new_pending_files, heap->files, - heap->allocated * sizeof(new_pending_files[0])); - if (heap->files != NULL) - free(heap->files); - heap->files = new_pending_files; - heap->allocated = new_size; - } - - file_key = file->key = key; - - /* - * Start with hole at end, walk it up tree to find insertion point. - */ - hole = heap->used++; - while (hole > 0) { - parent = (hole - 1)/2; - parent_key = heap->files[parent]->key; - if (file_key >= parent_key) { - heap->files[hole] = file; - return; - } - // Move parent into hole <==> move hole up tree. - heap->files[hole] = heap->files[parent]; - hole = parent; - } - heap->files[0] = file; -} - -static struct file_info * -heap_get_entry(struct heap_queue *heap) -{ - uint64_t a_key, b_key, c_key; - int a, b, c; - struct file_info *r, *tmp; - - if (heap->used < 1) - return (NULL); - - /* - * The first file in the list is the earliest; we'll return this. - */ - r = heap->files[0]; - - /* - * Move the last item in the heap to the root of the tree - */ - heap->files[0] = heap->files[--(heap->used)]; - - /* - * Rebalance the heap. - */ - a = 0; // Starting element and its heap key - a_key = heap->files[a]->key; - for (;;) { - b = a + a + 1; // First child - if (b >= heap->used) - return (r); - b_key = heap->files[b]->key; - c = b + 1; // Use second child if it is smaller. - if (c < heap->used) { - c_key = heap->files[c]->key; - if (c_key < b_key) { - b = c; - b_key = c_key; - } - } - if (a_key <= b_key) - return (r); - tmp = heap->files[a]; - heap->files[a] = heap->files[b]; - heap->files[b] = tmp; - a = b; - } -} - -static unsigned int -toi(const void *p, int n) -{ - const unsigned char *v = (const unsigned char *)p; - if (n > 1) - return v[0] + 256 * toi(v + 1, n - 1); - if (n == 1) - return v[0]; - return (0); -} - -static time_t -isodate7(const unsigned char *v) -{ - struct tm tm; - int offset; - memset(&tm, 0, sizeof(tm)); - tm.tm_year = v[0]; - tm.tm_mon = v[1] - 1; - tm.tm_mday = v[2]; - tm.tm_hour = v[3]; - tm.tm_min = v[4]; - tm.tm_sec = v[5]; - /* v[6] is the signed timezone offset, in 1/4-hour increments. */ - offset = ((const signed char *)v)[6]; - if (offset > -48 && offset < 52) { - tm.tm_hour -= offset / 4; - tm.tm_min -= (offset % 4) * 15; - } - return (time_from_tm(&tm)); -} - -static time_t -isodate17(const unsigned char *v) -{ - struct tm tm; - int offset; - memset(&tm, 0, sizeof(tm)); - tm.tm_year = (v[0] - '0') * 1000 + (v[1] - '0') * 100 - + (v[2] - '0') * 10 + (v[3] - '0') - - 1900; - tm.tm_mon = (v[4] - '0') * 10 + (v[5] - '0'); - tm.tm_mday = (v[6] - '0') * 10 + (v[7] - '0'); - tm.tm_hour = (v[8] - '0') * 10 + (v[9] - '0'); - tm.tm_min = (v[10] - '0') * 10 + (v[11] - '0'); - tm.tm_sec = (v[12] - '0') * 10 + (v[13] - '0'); - /* v[16] is the signed timezone offset, in 1/4-hour increments. */ - offset = ((const signed char *)v)[16]; - if (offset > -48 && offset < 52) { - tm.tm_hour -= offset / 4; - tm.tm_min -= (offset % 4) * 15; - } - return (time_from_tm(&tm)); -} - -static time_t -time_from_tm(struct tm *t) -{ -#if HAVE_TIMEGM - /* Use platform timegm() if available. */ - return (timegm(t)); -#else - /* Else use direct calculation using POSIX assumptions. */ - /* First, fix up tm_yday based on the year/month/day. */ - mktime(t); - /* Then we can compute timegm() from first principles. */ - return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600 - + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000 - + ((t->tm_year - 69) / 4) * 86400 - - ((t->tm_year - 1) / 100) * 86400 - + ((t->tm_year + 299) / 400) * 86400); -#endif -} - -static const char * -build_pathname(struct archive_string *as, struct file_info *file) -{ - if (file->parent != NULL && archive_strlen(&file->parent->name) > 0) { - build_pathname(as, file->parent); - archive_strcat(as, "/"); - } - if (archive_strlen(&file->name) == 0) - archive_strcat(as, "."); - else - archive_string_concat(as, &file->name); - return (as->s); -} - -#if DEBUG -static void -dump_isodirrec(FILE *out, const unsigned char *isodirrec) -{ - fprintf(out, " l %d,", - toi(isodirrec + DR_length_offset, DR_length_size)); - fprintf(out, " a %d,", - toi(isodirrec + DR_ext_attr_length_offset, DR_ext_attr_length_size)); - fprintf(out, " ext 0x%x,", - toi(isodirrec + DR_extent_offset, DR_extent_size)); - fprintf(out, " s %d,", - toi(isodirrec + DR_size_offset, DR_extent_size)); - fprintf(out, " f 0x%02x,", - toi(isodirrec + DR_flags_offset, DR_flags_size)); - fprintf(out, " u %d,", - toi(isodirrec + DR_file_unit_size_offset, DR_file_unit_size_size)); - fprintf(out, " ilv %d,", - toi(isodirrec + DR_interleave_offset, DR_interleave_size)); - fprintf(out, " seq %d,", - toi(isodirrec + DR_volume_sequence_number_offset, DR_volume_sequence_number_size)); - fprintf(out, " nl %d:", - toi(isodirrec + DR_name_len_offset, DR_name_len_size)); - fprintf(out, " `%.*s'", - toi(isodirrec + DR_name_len_offset, DR_name_len_size), isodirrec + DR_name_offset); -} -#endif diff --git a/lib/libarchive/archive_read_support_format_mtree.c b/lib/libarchive/archive_read_support_format_mtree.c deleted file mode 100644 index 7ae0b02..0000000 --- a/lib/libarchive/archive_read_support_format_mtree.c +++ /dev/null @@ -1,1309 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2008 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#include -/* #include */ /* See archive_platform.h */ -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" -#include "archive_string.h" - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -#define MTREE_HAS_DEVICE 0x0001 -#define MTREE_HAS_FFLAGS 0x0002 -#define MTREE_HAS_GID 0x0004 -#define MTREE_HAS_GNAME 0x0008 -#define MTREE_HAS_MTIME 0x0010 -#define MTREE_HAS_NLINK 0x0020 -#define MTREE_HAS_PERM 0x0040 -#define MTREE_HAS_SIZE 0x0080 -#define MTREE_HAS_TYPE 0x0100 -#define MTREE_HAS_UID 0x0200 -#define MTREE_HAS_UNAME 0x0400 - -#define MTREE_HAS_OPTIONAL 0x0800 - -struct mtree_option { - struct mtree_option *next; - char *value; -}; - -struct mtree_entry { - struct mtree_entry *next; - struct mtree_option *options; - char *name; - char full; - char used; -}; - -struct mtree { - struct archive_string line; - size_t buffsize; - char *buff; - off_t offset; - int fd; - int filetype; - int archive_format; - const char *archive_format_name; - struct mtree_entry *entries; - struct mtree_entry *this_entry; - struct archive_string current_dir; - struct archive_string contents_name; - - struct archive_entry_linkresolver *resolver; - - off_t cur_size, cur_offset; -}; - -static int cleanup(struct archive_read *); -static int mtree_bid(struct archive_read *); -static int parse_file(struct archive_read *, struct archive_entry *, - struct mtree *, struct mtree_entry *, int *); -static void parse_escapes(char *, struct mtree_entry *); -static int parse_line(struct archive_read *, struct archive_entry *, - struct mtree *, struct mtree_entry *, int *); -static int parse_keyword(struct archive_read *, struct mtree *, - struct archive_entry *, struct mtree_option *, int *); -static int read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset); -static ssize_t readline(struct archive_read *, struct mtree *, char **, ssize_t); -static int skip(struct archive_read *a); -static int read_header(struct archive_read *, - struct archive_entry *); -static int64_t mtree_atol10(char **); -static int64_t mtree_atol8(char **); -static int64_t mtree_atol(char **); - -static void -free_options(struct mtree_option *head) -{ - struct mtree_option *next; - - for (; head != NULL; head = next) { - next = head->next; - free(head->value); - free(head); - } -} - -int -archive_read_support_format_mtree(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct mtree *mtree; - int r; - - mtree = (struct mtree *)malloc(sizeof(*mtree)); - if (mtree == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate mtree data"); - return (ARCHIVE_FATAL); - } - memset(mtree, 0, sizeof(*mtree)); - mtree->fd = -1; - - r = __archive_read_register_format(a, mtree, "mtree", - mtree_bid, NULL, read_header, read_data, skip, cleanup); - - if (r != ARCHIVE_OK) - free(mtree); - return (ARCHIVE_OK); -} - -static int -cleanup(struct archive_read *a) -{ - struct mtree *mtree; - struct mtree_entry *p, *q; - - mtree = (struct mtree *)(a->format->data); - - p = mtree->entries; - while (p != NULL) { - q = p->next; - free(p->name); - free_options(p->options); - free(p); - p = q; - } - archive_string_free(&mtree->line); - archive_string_free(&mtree->current_dir); - archive_string_free(&mtree->contents_name); - archive_entry_linkresolver_free(mtree->resolver); - - free(mtree->buff); - free(mtree); - (a->format->data) = NULL; - return (ARCHIVE_OK); -} - - -static int -mtree_bid(struct archive_read *a) -{ - const char *signature = "#mtree"; - const char *p; - - /* Now let's look at the actual header and see if it matches. */ - p = __archive_read_ahead(a, strlen(signature), NULL); - if (p == NULL) - return (-1); - - if (strncmp(p, signature, strlen(signature)) == 0) - return (8 * (int)strlen(signature)); - return (0); -} - -/* - * The extended mtree format permits multiple lines specifying - * attributes for each file. For those entries, only the last line - * is actually used. Practically speaking, that means we have - * to read the entire mtree file into memory up front. - * - * The parsing is done in two steps. First, it is decided if a line - * changes the global defaults and if it is, processed accordingly. - * Otherwise, the options of the line are merged with the current - * global options. - */ -static int -add_option(struct archive_read *a, struct mtree_option **global, - const char *value, size_t len) -{ - struct mtree_option *option; - - if ((option = malloc(sizeof(*option))) == NULL) { - archive_set_error(&a->archive, errno, "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - if ((option->value = malloc(len + 1)) == NULL) { - free(option); - archive_set_error(&a->archive, errno, "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - memcpy(option->value, value, len); - option->value[len] = '\0'; - option->next = *global; - *global = option; - return (ARCHIVE_OK); -} - -static void -remove_option(struct mtree_option **global, const char *value, size_t len) -{ - struct mtree_option *iter, *last; - - last = NULL; - for (iter = *global; iter != NULL; last = iter, iter = iter->next) { - if (strncmp(iter->value, value, len) == 0 && - (iter->value[len] == '\0' || - iter->value[len] == '=')) - break; - } - if (iter == NULL) - return; - if (last == NULL) - *global = iter->next; - else - last->next = iter->next; - - free(iter->value); - free(iter); -} - -static int -process_global_set(struct archive_read *a, - struct mtree_option **global, const char *line) -{ - const char *next, *eq; - size_t len; - int r; - - line += 4; - for (;;) { - next = line + strspn(line, " \t\r\n"); - if (*next == '\0') - return (ARCHIVE_OK); - line = next; - next = line + strcspn(line, " \t\r\n"); - eq = strchr(line, '='); - if (eq > next) - len = next - line; - else - len = eq - line; - - remove_option(global, line, len); - r = add_option(a, global, line, next - line); - if (r != ARCHIVE_OK) - return (r); - line = next; - } -} - -static int -process_global_unset(struct archive_read *a, - struct mtree_option **global, const char *line) -{ - const char *next; - size_t len; - - line += 6; - if (strchr(line, '=') != NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "/unset shall not contain `='"); - return ARCHIVE_FATAL; - } - - for (;;) { - next = line + strspn(line, " \t\r\n"); - if (*next == '\0') - return (ARCHIVE_OK); - line = next; - len = strcspn(line, " \t\r\n"); - - if (len == 3 && strncmp(line, "all", 3) == 0) { - free_options(*global); - *global = NULL; - } else { - remove_option(global, line, len); - } - - line += len; - } -} - -static int -process_add_entry(struct archive_read *a, struct mtree *mtree, - struct mtree_option **global, const char *line, - struct mtree_entry **last_entry) -{ - struct mtree_entry *entry; - struct mtree_option *iter; - const char *next, *eq; - size_t len; - int r; - - if ((entry = malloc(sizeof(*entry))) == NULL) { - archive_set_error(&a->archive, errno, "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - entry->next = NULL; - entry->options = NULL; - entry->name = NULL; - entry->used = 0; - entry->full = 0; - - /* Add this entry to list. */ - if (*last_entry == NULL) - mtree->entries = entry; - else - (*last_entry)->next = entry; - *last_entry = entry; - - len = strcspn(line, " \t\r\n"); - if ((entry->name = malloc(len + 1)) == NULL) { - archive_set_error(&a->archive, errno, "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - - memcpy(entry->name, line, len); - entry->name[len] = '\0'; - parse_escapes(entry->name, entry); - - line += len; - for (iter = *global; iter != NULL; iter = iter->next) { - r = add_option(a, &entry->options, iter->value, - strlen(iter->value)); - if (r != ARCHIVE_OK) - return (r); - } - - for (;;) { - next = line + strspn(line, " \t\r\n"); - if (*next == '\0') - return (ARCHIVE_OK); - line = next; - next = line + strcspn(line, " \t\r\n"); - eq = strchr(line, '='); - if (eq == NULL || eq > next) - len = next - line; - else - len = eq - line; - - remove_option(&entry->options, line, len); - r = add_option(a, &entry->options, line, next - line); - if (r != ARCHIVE_OK) - return (r); - line = next; - } -} - -static int -read_mtree(struct archive_read *a, struct mtree *mtree) -{ - ssize_t len; - uintmax_t counter; - char *p; - struct mtree_option *global; - struct mtree_entry *last_entry; - int r; - - mtree->archive_format = ARCHIVE_FORMAT_MTREE; - mtree->archive_format_name = "mtree"; - - global = NULL; - last_entry = NULL; - - for (counter = 1; ; ++counter) { - len = readline(a, mtree, &p, 256); - if (len == 0) { - mtree->this_entry = mtree->entries; - free_options(global); - return (ARCHIVE_OK); - } - if (len < 0) { - free_options(global); - return (len); - } - /* Leading whitespace is never significant, ignore it. */ - while (*p == ' ' || *p == '\t') { - ++p; - --len; - } - /* Skip content lines and blank lines. */ - if (*p == '#') - continue; - if (*p == '\r' || *p == '\n' || *p == '\0') - continue; - if (*p != '/') { - r = process_add_entry(a, mtree, &global, p, - &last_entry); - } else if (strncmp(p, "/set", 4) == 0) { - if (p[4] != ' ' && p[4] != '\t') - break; - r = process_global_set(a, &global, p); - } else if (strncmp(p, "/unset", 6) == 0) { - if (p[6] != ' ' && p[6] != '\t') - break; - r = process_global_unset(a, &global, p); - } else - break; - - if (r != ARCHIVE_OK) { - free_options(global); - return r; - } - } - - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't parse line %ju", counter); - free_options(global); - return (ARCHIVE_FATAL); -} - -/* - * Read in the entire mtree file into memory on the first request. - * Then use the next unused file to satisfy each header request. - */ -static int -read_header(struct archive_read *a, struct archive_entry *entry) -{ - struct mtree *mtree; - char *p; - int r, use_next; - - mtree = (struct mtree *)(a->format->data); - - if (mtree->fd >= 0) { - close(mtree->fd); - mtree->fd = -1; - } - - if (mtree->entries == NULL) { - mtree->resolver = archive_entry_linkresolver_new(); - if (mtree->resolver == NULL) - return ARCHIVE_FATAL; - archive_entry_linkresolver_set_strategy(mtree->resolver, - ARCHIVE_FORMAT_MTREE); - r = read_mtree(a, mtree); - if (r != ARCHIVE_OK) - return (r); - } - - a->archive.archive_format = mtree->archive_format; - a->archive.archive_format_name = mtree->archive_format_name; - - for (;;) { - if (mtree->this_entry == NULL) - return (ARCHIVE_EOF); - if (strcmp(mtree->this_entry->name, "..") == 0) { - mtree->this_entry->used = 1; - if (archive_strlen(&mtree->current_dir) > 0) { - /* Roll back current path. */ - p = mtree->current_dir.s - + mtree->current_dir.length - 1; - while (p >= mtree->current_dir.s && *p != '/') - --p; - if (p >= mtree->current_dir.s) - --p; - mtree->current_dir.length - = p - mtree->current_dir.s + 1; - } - } - if (!mtree->this_entry->used) { - use_next = 0; - r = parse_file(a, entry, mtree, mtree->this_entry, &use_next); - if (use_next == 0) - return (r); - } - mtree->this_entry = mtree->this_entry->next; - } -} - -/* - * A single file can have multiple lines contribute specifications. - * Parse as many lines as necessary, then pull additional information - * from a backing file on disk as necessary. - */ -static int -parse_file(struct archive_read *a, struct archive_entry *entry, - struct mtree *mtree, struct mtree_entry *mentry, int *use_next) -{ - const char *path; - struct stat st_storage, *st; - struct mtree_entry *mp; - struct archive_entry *sparse_entry; - int r = ARCHIVE_OK, r1, parsed_kws, mismatched_type; - - mentry->used = 1; - - /* Initialize reasonable defaults. */ - mtree->filetype = AE_IFREG; - archive_entry_set_size(entry, 0); - archive_string_empty(&mtree->contents_name); - - /* Parse options from this line. */ - parsed_kws = 0; - r = parse_line(a, entry, mtree, mentry, &parsed_kws); - - if (mentry->full) { - archive_entry_copy_pathname(entry, mentry->name); - /* - * "Full" entries are allowed to have multiple lines - * and those lines aren't required to be adjacent. We - * don't support multiple lines for "relative" entries - * nor do we make any attempt to merge data from - * separate "relative" and "full" entries. (Merging - * "relative" and "full" entries would require dealing - * with pathname canonicalization, which is a very - * tricky subject.) - */ - for (mp = mentry->next; mp != NULL; mp = mp->next) { - if (mp->full && !mp->used - && strcmp(mentry->name, mp->name) == 0) { - /* Later lines override earlier ones. */ - mp->used = 1; - r1 = parse_line(a, entry, mtree, mp, - &parsed_kws); - if (r1 < r) - r = r1; - } - } - } else { - /* - * Relative entries require us to construct - * the full path and possibly update the - * current directory. - */ - size_t n = archive_strlen(&mtree->current_dir); - if (n > 0) - archive_strcat(&mtree->current_dir, "/"); - archive_strcat(&mtree->current_dir, mentry->name); - archive_entry_copy_pathname(entry, mtree->current_dir.s); - if (archive_entry_filetype(entry) != AE_IFDIR) - mtree->current_dir.length = n; - } - - /* - * Try to open and stat the file to get the real size - * and other file info. It would be nice to avoid - * this here so that getting a listing of an mtree - * wouldn't require opening every referenced contents - * file. But then we wouldn't know the actual - * contents size, so I don't see a really viable way - * around this. (Also, we may want to someday pull - * other unspecified info from the contents file on - * disk.) - */ - mtree->fd = -1; - if (archive_strlen(&mtree->contents_name) > 0) - path = mtree->contents_name.s; - else - path = archive_entry_pathname(entry); - - if (archive_entry_filetype(entry) == AE_IFREG || - archive_entry_filetype(entry) == AE_IFDIR) { - mtree->fd = open(path, O_RDONLY | O_BINARY); - if (mtree->fd == -1 && - (errno != ENOENT || - archive_strlen(&mtree->contents_name) > 0)) { - archive_set_error(&a->archive, errno, - "Can't open %s", path); - r = ARCHIVE_WARN; - } - } - - st = &st_storage; - if (mtree->fd >= 0) { - if (fstat(mtree->fd, st) == -1) { - archive_set_error(&a->archive, errno, - "Could not fstat %s", path); - r = ARCHIVE_WARN; - /* If we can't stat it, don't keep it open. */ - close(mtree->fd); - mtree->fd = -1; - st = NULL; - } - } else if (lstat(path, st) == -1) { - st = NULL; - } - - /* - * Check for a mismatch between the type in the specification and - * the type of the contents object on disk. - */ - if (st != NULL) { - mismatched_type = 0; - if ((st->st_mode & S_IFMT) == S_IFREG && - archive_entry_filetype(entry) != AE_IFREG) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFLNK && - archive_entry_filetype(entry) != AE_IFLNK) - mismatched_type = 1; - if ((st->st_mode & S_IFSOCK) == S_IFSOCK && - archive_entry_filetype(entry) != AE_IFSOCK) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFCHR && - archive_entry_filetype(entry) != AE_IFCHR) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFBLK && - archive_entry_filetype(entry) != AE_IFBLK) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFDIR && - archive_entry_filetype(entry) != AE_IFDIR) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFIFO && - archive_entry_filetype(entry) != AE_IFIFO) - mismatched_type = 1; - - if (mismatched_type) { - if ((parsed_kws & MTREE_HAS_OPTIONAL) == 0) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "mtree specification has different type for %s", - archive_entry_pathname(entry)); - r = ARCHIVE_WARN; - } else { - *use_next = 1; - } - /* Don't hold a non-regular file open. */ - if (mtree->fd >= 0) - close(mtree->fd); - mtree->fd = -1; - st = NULL; - return r; - } - } - - /* - * If there is a contents file on disk, pick some of the metadata - * from that file. For most of these, we only set it from the contents - * if it wasn't already parsed from the specification. - */ - if (st != NULL) { - if ((parsed_kws & MTREE_HAS_DEVICE) == 0 && - (archive_entry_filetype(entry) == AE_IFCHR || - archive_entry_filetype(entry) == AE_IFBLK)) - archive_entry_set_rdev(entry, st->st_rdev); - if ((parsed_kws & (MTREE_HAS_GID | MTREE_HAS_GNAME)) == 0) - archive_entry_set_gid(entry, st->st_gid); - if ((parsed_kws & (MTREE_HAS_UID | MTREE_HAS_UNAME)) == 0) - archive_entry_set_uid(entry, st->st_uid); - if ((parsed_kws & MTREE_HAS_MTIME) == 0) { -#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - archive_entry_set_mtime(entry, st->st_mtime, - st->st_mtimespec.tv_nsec); -#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - archive_entry_set_mtime(entry, st->st_mtime, - st->st_mtim.tv_nsec); -#elif HAVE_STRUCT_STAT_ST_MTIME_N - archive_entry_set_mtime(entry, st->st_mtime, - st->st_mtime_n); -#elif HAVE_STRUCT_STAT_ST_UMTIME - archive_entry_set_mtime(entry, st->st_mtime, - st->st_umtime*1000); -#elif HAVE_STRUCT_STAT_ST_MTIME_USEC - archive_entry_set_mtime(entry, st->st_mtime, - st->st_mtime_usec*1000); -#else - archive_entry_set_mtime(entry, st->st_mtime, 0); -#endif - } - if ((parsed_kws & MTREE_HAS_NLINK) == 0) - archive_entry_set_nlink(entry, st->st_nlink); - if ((parsed_kws & MTREE_HAS_PERM) == 0) - archive_entry_set_perm(entry, st->st_mode); - if ((parsed_kws & MTREE_HAS_SIZE) == 0) - archive_entry_set_size(entry, st->st_size); - archive_entry_set_ino(entry, st->st_ino); - archive_entry_set_dev(entry, st->st_dev); - - archive_entry_linkify(mtree->resolver, &entry, &sparse_entry); - } else if (parsed_kws & MTREE_HAS_OPTIONAL) { - /* - * Couldn't open the entry, stat it or the on-disk type - * didn't match. If this entry is optional, just ignore it - * and read the next header entry. - */ - *use_next = 1; - return ARCHIVE_OK; - } - - mtree->cur_size = archive_entry_size(entry); - mtree->offset = 0; - - return r; -} - -/* - * Each line contains a sequence of keywords. - */ -static int -parse_line(struct archive_read *a, struct archive_entry *entry, - struct mtree *mtree, struct mtree_entry *mp, int *parsed_kws) -{ - struct mtree_option *iter; - int r = ARCHIVE_OK, r1; - - for (iter = mp->options; iter != NULL; iter = iter->next) { - r1 = parse_keyword(a, mtree, entry, iter, parsed_kws); - if (r1 < r) - r = r1; - } - if ((*parsed_kws & MTREE_HAS_TYPE) == 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Missing type keyword in mtree specification"); - return (ARCHIVE_WARN); - } - return (r); -} - -/* - * Device entries have one of the following forms: - * raw dev_t - * format,major,minor[,subdevice] - * - * Just use major and minor, no translation etc is done - * between formats. - */ -static int -parse_device(struct archive *a, struct archive_entry *entry, char *val) -{ - char *comma1, *comma2; - - comma1 = strchr(val, ','); - if (comma1 == NULL) { - archive_entry_set_dev(entry, mtree_atol10(&val)); - return (ARCHIVE_OK); - } - ++comma1; - comma2 = strchr(comma1, ','); - if (comma2 == NULL) { - archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT, - "Malformed device attribute"); - return (ARCHIVE_WARN); - } - ++comma2; - archive_entry_set_rdevmajor(entry, mtree_atol(&comma1)); - archive_entry_set_rdevminor(entry, mtree_atol(&comma2)); - return (ARCHIVE_OK); -} - -/* - * Parse a single keyword and its value. - */ -static int -parse_keyword(struct archive_read *a, struct mtree *mtree, - struct archive_entry *entry, struct mtree_option *option, int *parsed_kws) -{ - char *val, *key; - - key = option->value; - - if (*key == '\0') - return (ARCHIVE_OK); - - if (strcmp(key, "optional") == 0) { - *parsed_kws |= MTREE_HAS_OPTIONAL; - return (ARCHIVE_OK); - } - if (strcmp(key, "ignore") == 0) { - /* - * The mtree processing is not recursive, so - * recursion will only happen for explicitly listed - * entries. - */ - return (ARCHIVE_OK); - } - - val = strchr(key, '='); - if (val == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Malformed attribute \"%s\" (%d)", key, key[0]); - return (ARCHIVE_WARN); - } - - *val = '\0'; - ++val; - - switch (key[0]) { - case 'c': - if (strcmp(key, "content") == 0 - || strcmp(key, "contents") == 0) { - parse_escapes(val, NULL); - archive_strcpy(&mtree->contents_name, val); - break; - } - if (strcmp(key, "cksum") == 0) - break; - case 'd': - if (strcmp(key, "device") == 0) { - *parsed_kws |= MTREE_HAS_DEVICE; - return parse_device(&a->archive, entry, val); - } - case 'f': - if (strcmp(key, "flags") == 0) { - *parsed_kws |= MTREE_HAS_FFLAGS; - archive_entry_copy_fflags_text(entry, val); - break; - } - case 'g': - if (strcmp(key, "gid") == 0) { - *parsed_kws |= MTREE_HAS_GID; - archive_entry_set_gid(entry, mtree_atol10(&val)); - break; - } - if (strcmp(key, "gname") == 0) { - *parsed_kws |= MTREE_HAS_GNAME; - archive_entry_copy_gname(entry, val); - break; - } - case 'l': - if (strcmp(key, "link") == 0) { - archive_entry_copy_symlink(entry, val); - break; - } - case 'm': - if (strcmp(key, "md5") == 0 || strcmp(key, "md5digest") == 0) - break; - if (strcmp(key, "mode") == 0) { - if (val[0] >= '0' && val[0] <= '9') { - *parsed_kws |= MTREE_HAS_PERM; - archive_entry_set_perm(entry, - mtree_atol8(&val)); - } else { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Symbolic mode \"%s\" unsupported", val); - return ARCHIVE_WARN; - } - break; - } - case 'n': - if (strcmp(key, "nlink") == 0) { - *parsed_kws |= MTREE_HAS_NLINK; - archive_entry_set_nlink(entry, mtree_atol10(&val)); - break; - } - case 'r': - if (strcmp(key, "rmd160") == 0 || - strcmp(key, "rmd160digest") == 0) - break; - case 's': - if (strcmp(key, "sha1") == 0 || strcmp(key, "sha1digest") == 0) - break; - if (strcmp(key, "sha256") == 0 || - strcmp(key, "sha256digest") == 0) - break; - if (strcmp(key, "sha384") == 0 || - strcmp(key, "sha384digest") == 0) - break; - if (strcmp(key, "sha512") == 0 || - strcmp(key, "sha512digest") == 0) - break; - if (strcmp(key, "size") == 0) { - archive_entry_set_size(entry, mtree_atol10(&val)); - break; - } - case 't': - if (strcmp(key, "tags") == 0) { - /* - * Comma delimited list of tags. - * Ignore the tags for now, but the interface - * should be extended to allow inclusion/exclusion. - */ - break; - } - if (strcmp(key, "time") == 0) { - time_t m; - long ns; - - *parsed_kws |= MTREE_HAS_MTIME; - m = (time_t)mtree_atol10(&val); - if (*val == '.') { - ++val; - ns = (long)mtree_atol10(&val); - } else - ns = 0; - archive_entry_set_mtime(entry, m, ns); - break; - } - if (strcmp(key, "type") == 0) { - *parsed_kws |= MTREE_HAS_TYPE; - switch (val[0]) { - case 'b': - if (strcmp(val, "block") == 0) { - mtree->filetype = AE_IFBLK; - break; - } - case 'c': - if (strcmp(val, "char") == 0) { - mtree->filetype = AE_IFCHR; - break; - } - case 'd': - if (strcmp(val, "dir") == 0) { - mtree->filetype = AE_IFDIR; - break; - } - case 'f': - if (strcmp(val, "fifo") == 0) { - mtree->filetype = AE_IFIFO; - break; - } - if (strcmp(val, "file") == 0) { - mtree->filetype = AE_IFREG; - break; - } - case 'l': - if (strcmp(val, "link") == 0) { - mtree->filetype = AE_IFLNK; - break; - } - default: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Unrecognized file type \"%s\"", val); - return (ARCHIVE_WARN); - } - archive_entry_set_filetype(entry, mtree->filetype); - break; - } - case 'u': - if (strcmp(key, "uid") == 0) { - *parsed_kws |= MTREE_HAS_UID; - archive_entry_set_uid(entry, mtree_atol10(&val)); - break; - } - if (strcmp(key, "uname") == 0) { - *parsed_kws |= MTREE_HAS_UNAME; - archive_entry_copy_uname(entry, val); - break; - } - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Unrecognized key %s=%s", key, val); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); -} - -static int -read_data(struct archive_read *a, const void **buff, size_t *size, off_t *offset) -{ - size_t bytes_to_read; - ssize_t bytes_read; - struct mtree *mtree; - - mtree = (struct mtree *)(a->format->data); - if (mtree->fd < 0) { - *buff = NULL; - *offset = 0; - *size = 0; - return (ARCHIVE_EOF); - } - if (mtree->buff == NULL) { - mtree->buffsize = 64 * 1024; - mtree->buff = malloc(mtree->buffsize); - if (mtree->buff == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - } - - *buff = mtree->buff; - *offset = mtree->offset; - if ((off_t)mtree->buffsize > mtree->cur_size - mtree->offset) - bytes_to_read = mtree->cur_size - mtree->offset; - else - bytes_to_read = mtree->buffsize; - bytes_read = read(mtree->fd, mtree->buff, bytes_to_read); - if (bytes_read < 0) { - archive_set_error(&a->archive, errno, "Can't read"); - return (ARCHIVE_WARN); - } - if (bytes_read == 0) { - *size = 0; - return (ARCHIVE_EOF); - } - mtree->offset += bytes_read; - *size = bytes_read; - return (ARCHIVE_OK); -} - -/* Skip does nothing except possibly close the contents file. */ -static int -skip(struct archive_read *a) -{ - struct mtree *mtree; - - mtree = (struct mtree *)(a->format->data); - if (mtree->fd >= 0) { - close(mtree->fd); - mtree->fd = -1; - } - return (ARCHIVE_OK); -} - -/* - * Since parsing backslash sequences always makes strings shorter, - * we can always do this conversion in-place. - */ -static void -parse_escapes(char *src, struct mtree_entry *mentry) -{ - char *dest = src; - char c; - - if (mentry != NULL && strcmp(src, ".") == 0) - mentry->full = 1; - - while (*src != '\0') { - c = *src++; - if (c == '/' && mentry != NULL) - mentry->full = 1; - if (c == '\\') { - switch (src[0]) { - case '0': - if (src[1] < '0' || src[1] > '7') { - c = 0; - ++src; - break; - } - /* FALLTHROUGH */ - case '1': - case '2': - case '3': - if (src[1] >= '0' && src[1] <= '7' && - src[2] >= '0' && src[2] <= '7') { - c = (src[0] - '0') << 6; - c |= (src[1] - '0') << 3; - c |= (src[2] - '0'); - src += 3; - } - break; - case 'a': - c = '\a'; - ++src; - break; - case 'b': - c = '\b'; - ++src; - break; - case 'f': - c = '\f'; - ++src; - break; - case 'n': - c = '\n'; - ++src; - break; - case 'r': - c = '\r'; - ++src; - break; - case 's': - c = ' '; - ++src; - break; - case 't': - c = '\t'; - ++src; - break; - case 'v': - c = '\v'; - ++src; - break; - } - } - *dest++ = c; - } - *dest = '\0'; -} - -/* - * Note that this implementation does not (and should not!) obey - * locale settings; you cannot simply substitute strtol here, since - * it does obey locale. - */ -static int64_t -mtree_atol8(char **p) -{ - int64_t l, limit, last_digit_limit; - int digit, base; - - base = 8; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - l = 0; - digit = **p - '0'; - while (digit >= 0 && digit < base) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++(*p) - '0'; - } - return (l); -} - -/* - * Note that this implementation does not (and should not!) obey - * locale settings; you cannot simply substitute strtol here, since - * it does obey locale. - */ -static int64_t -mtree_atol10(char **p) -{ - int64_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 10; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - if (**p == '-') { - sign = -1; - ++(*p); - } else - sign = 1; - - l = 0; - digit = **p - '0'; - while (digit >= 0 && digit < base) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++(*p) - '0'; - } - return (sign < 0) ? -l : l; -} - -/* - * Note that this implementation does not (and should not!) obey - * locale settings; you cannot simply substitute strtol here, since - * it does obey locale. - */ -static int64_t -mtree_atol16(char **p) -{ - int64_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 16; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - if (**p == '-') { - sign = -1; - ++(*p); - } else - sign = 1; - - l = 0; - if (**p >= '0' && **p <= '9') - digit = **p - '0'; - else if (**p >= 'a' && **p <= 'f') - digit = **p - 'a' + 10; - else if (**p >= 'A' && **p <= 'F') - digit = **p - 'A' + 10; - else - digit = -1; - while (digit >= 0 && digit < base) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - if (**p >= '0' && **p <= '9') - digit = **p - '0'; - else if (**p >= 'a' && **p <= 'f') - digit = **p - 'a' + 10; - else if (**p >= 'A' && **p <= 'F') - digit = **p - 'A' + 10; - else - digit = -1; - } - return (sign < 0) ? -l : l; -} - -static int64_t -mtree_atol(char **p) -{ - if (**p != '0') - return mtree_atol10(p); - if ((*p)[1] == 'x' || (*p)[1] == 'X') { - *p += 2; - return mtree_atol16(p); - } - return mtree_atol8(p); -} - -/* - * Returns length of line (including trailing newline) - * or negative on error. 'start' argument is updated to - * point to first character of line. - */ -static ssize_t -readline(struct archive_read *a, struct mtree *mtree, char **start, ssize_t limit) -{ - ssize_t bytes_read; - ssize_t total_size = 0; - ssize_t find_off = 0; - const void *t; - const char *s; - void *p; - char *u; - - /* Accumulate line in a line buffer. */ - for (;;) { - /* Read some more. */ - t = __archive_read_ahead(a, 1, &bytes_read); - if (t == NULL) - return (0); - if (bytes_read < 0) - return (ARCHIVE_FATAL); - s = t; /* Start of line? */ - p = memchr(t, '\n', bytes_read); - /* If we found '\n', trim the read. */ - if (p != NULL) { - bytes_read = 1 + ((const char *)p) - s; - } - if (total_size + bytes_read + 1 > limit) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Line too long"); - return (ARCHIVE_FATAL); - } - if (archive_string_ensure(&mtree->line, - total_size + bytes_read + 1) == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate working buffer"); - return (ARCHIVE_FATAL); - } - memcpy(mtree->line.s + total_size, t, bytes_read); - __archive_read_consume(a, bytes_read); - total_size += bytes_read; - /* Null terminate. */ - mtree->line.s[total_size] = '\0'; - /* If we found an unescaped '\n', clean up and return. */ - for (u = mtree->line.s + find_off; *u; ++u) { - if (u[0] == '\n') { - *start = mtree->line.s; - return total_size; - } - if (u[0] == '#') { - if (p == NULL) - break; - *start = mtree->line.s; - return total_size; - } - if (u[0] != '\\') - continue; - if (u[1] == '\\') { - ++u; - continue; - } - if (u[1] == '\n') { - memmove(u, u + 1, - total_size - (u - mtree->line.s) + 1); - --total_size; - ++u; - break; - } - if (u[1] == '\0') - break; - } - find_off = u - mtree->line.s; - } -} diff --git a/lib/libarchive/archive_read_support_format_raw.c b/lib/libarchive/archive_read_support_format_raw.c deleted file mode 100644 index c994a5d..0000000 --- a/lib/libarchive/archive_read_support_format_raw.c +++ /dev/null @@ -1,185 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" - -struct raw_info { - int64_t offset; /* Current position in the file. */ - int end_of_file; -}; - -static int archive_read_format_raw_bid(struct archive_read *); -static int archive_read_format_raw_cleanup(struct archive_read *); -static int archive_read_format_raw_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_raw_read_data_skip(struct archive_read *); -static int archive_read_format_raw_read_header(struct archive_read *, - struct archive_entry *); - -int -archive_read_support_format_raw(struct archive *_a) -{ - struct raw_info *info; - struct archive_read *a = (struct archive_read *)_a; - int r; - - info = (struct raw_info *)calloc(1, sizeof(*info)); - if (info == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate raw_info data"); - return (ARCHIVE_FATAL); - } - - r = __archive_read_register_format(a, - info, - "raw", - archive_read_format_raw_bid, - NULL, - archive_read_format_raw_read_header, - archive_read_format_raw_read_data, - archive_read_format_raw_read_data_skip, - archive_read_format_raw_cleanup); - if (r != ARCHIVE_OK) - free(info); - return (r); -} - -/* - * Bid 1 if this is a non-empty file. Anyone who can really support - * this should outbid us, so it should generally be safe to use "raw" - * in conjunction with other formats. But, this could really confuse - * folks if there are bid errors or minor file damage, so we don't - * include "raw" as part of support_format_all(). - */ -static int -archive_read_format_raw_bid(struct archive_read *a) -{ - - if (__archive_read_ahead(a, 1, NULL) == NULL) - return (-1); - return (1); -} - -/* - * Mock up a fake header. - */ -static int -archive_read_format_raw_read_header(struct archive_read *a, - struct archive_entry *entry) -{ - struct raw_info *info; - - info = (struct raw_info *)(a->format->data); - if (info->end_of_file) - return (ARCHIVE_EOF); - - a->archive.archive_format = ARCHIVE_FORMAT_RAW; - a->archive.archive_format_name = "Raw data"; - archive_entry_set_pathname(entry, "data"); - /* XXX should we set mode to mimic a regular file? XXX */ - /* I'm deliberately leaving most fields unset here. */ - return (ARCHIVE_OK); -} - -static int -archive_read_format_raw_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - struct raw_info *info; - ssize_t avail; - - info = (struct raw_info *)(a->format->data); - if (info->end_of_file) - return (ARCHIVE_EOF); - - /* Get whatever bytes are immediately available. */ - *buff = __archive_read_ahead(a, 1, &avail); - if (avail > 0) { - /* Consume and return the bytes we just read */ - __archive_read_consume(a, avail); - *size = avail; - *offset = info->offset; - info->offset += *size; - return (ARCHIVE_OK); - } else if (0 == avail) { - /* Record and return end-of-file. */ - info->end_of_file = 1; - *size = 0; - *offset = info->offset; - return (ARCHIVE_EOF); - } else { - /* Record and return an error. */ - *size = 0; - *offset = info->offset; - return (avail); - } -} - -static int -archive_read_format_raw_read_data_skip(struct archive_read *a) -{ - struct raw_info *info; - off_t bytes_skipped; - int64_t request = 1024 * 1024 * 1024UL; /* Skip 1 GB at a time. */ - - info = (struct raw_info *)(a->format->data); - if (info->end_of_file) - return (ARCHIVE_EOF); - info->end_of_file = 1; - - for (;;) { - bytes_skipped = __archive_read_skip_lenient(a, request); - if (bytes_skipped < 0) - return (ARCHIVE_FATAL); - if (bytes_skipped < request) - return (ARCHIVE_OK); - /* We skipped all the bytes we asked for. There might - * be more, so try again. */ - } -} - -static int -archive_read_format_raw_cleanup(struct archive_read *a) -{ - struct raw_info *info; - - info = (struct raw_info *)(a->format->data); - free(info); - a->format->data = NULL; - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c deleted file mode 100644 index 62be309..0000000 --- a/lib/libarchive/archive_read_support_format_tar.c +++ /dev/null @@ -1,2418 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -/* #include */ /* See archive_platform.h */ -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -/* Obtain suitable wide-character manipulation functions. */ -#ifdef HAVE_WCHAR_H -#include -#else -/* Good enough for equality testing, which is all we need. */ -static int wcscmp(const wchar_t *s1, const wchar_t *s2) -{ - int diff = *s1 - *s2; - while (*s1 && diff == 0) - diff = (int)*++s1 - (int)*++s2; - return diff; -} -/* Good enough for equality testing, which is all we need. */ -static int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n) -{ - int diff = *s1 - *s2; - while (*s1 && diff == 0 && n-- > 0) - diff = (int)*++s1 - (int)*++s2; - return diff; -} -static size_t wcslen(const wchar_t *s) -{ - const wchar_t *p = s; - while (*p) - p++; - return p - s; -} -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" - -#define tar_min(a,b) ((a) < (b) ? (a) : (b)) - -/* - * Layout of POSIX 'ustar' tar header. - */ -struct archive_entry_header_ustar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char typeflag[1]; - char linkname[100]; /* "old format" header ends here */ - char magic[6]; /* For POSIX: "ustar\0" */ - char version[2]; /* For POSIX: "00" */ - char uname[32]; - char gname[32]; - char rdevmajor[8]; - char rdevminor[8]; - char prefix[155]; -}; - -/* - * Structure of GNU tar header - */ -struct gnu_sparse { - char offset[12]; - char numbytes[12]; -}; - -struct archive_entry_header_gnutar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char typeflag[1]; - char linkname[100]; - char magic[8]; /* "ustar \0" (note blank/blank/null at end) */ - char uname[32]; - char gname[32]; - char rdevmajor[8]; - char rdevminor[8]; - char atime[12]; - char ctime[12]; - char offset[12]; - char longnames[4]; - char unused[1]; - struct gnu_sparse sparse[4]; - char isextended[1]; - char realsize[12]; - /* - * Old GNU format doesn't use POSIX 'prefix' field; they use - * the 'L' (longname) entry instead. - */ -}; - -/* - * Data specific to this format. - */ -struct sparse_block { - struct sparse_block *next; - off_t offset; - off_t remaining; -}; - -struct tar { - struct archive_string acl_text; - struct archive_string entry_pathname; - /* For "GNU.sparse.name" and other similar path extensions. */ - struct archive_string entry_pathname_override; - struct archive_string entry_linkpath; - struct archive_string entry_uname; - struct archive_string entry_gname; - struct archive_string longlink; - struct archive_string longname; - struct archive_string pax_header; - struct archive_string pax_global; - struct archive_string line; - int pax_hdrcharset_binary; - wchar_t *pax_entry; - size_t pax_entry_length; - int header_recursion_depth; - int64_t entry_bytes_remaining; - int64_t entry_offset; - int64_t entry_padding; - int64_t realsize; - struct sparse_block *sparse_list; - struct sparse_block *sparse_last; - int64_t sparse_offset; - int64_t sparse_numbytes; - int sparse_gnu_major; - int sparse_gnu_minor; - char sparse_gnu_pending; -}; - -static ssize_t UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n); -static int archive_block_is_null(const unsigned char *p); -static char *base64_decode(const char *, size_t, size_t *); -static void gnu_add_sparse_entry(struct tar *, - off_t offset, off_t remaining); -static void gnu_clear_sparse_list(struct tar *); -static int gnu_sparse_old_read(struct archive_read *, struct tar *, - const struct archive_entry_header_gnutar *header); -static void gnu_sparse_old_parse(struct tar *, - const struct gnu_sparse *sparse, int length); -static int gnu_sparse_01_parse(struct tar *, const char *); -static ssize_t gnu_sparse_10_read(struct archive_read *, struct tar *); -static int header_Solaris_ACL(struct archive_read *, struct tar *, - struct archive_entry *, const void *); -static int header_common(struct archive_read *, struct tar *, - struct archive_entry *, const void *); -static int header_old_tar(struct archive_read *, struct tar *, - struct archive_entry *, const void *); -static int header_pax_extensions(struct archive_read *, struct tar *, - struct archive_entry *, const void *); -static int header_pax_global(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_longlink(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_longname(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_volume(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_ustar(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_gnutar(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int archive_read_format_tar_bid(struct archive_read *); -static int archive_read_format_tar_cleanup(struct archive_read *); -static int archive_read_format_tar_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset); -static int archive_read_format_tar_skip(struct archive_read *a); -static int archive_read_format_tar_read_header(struct archive_read *, - struct archive_entry *); -static int checksum(struct archive_read *, const void *); -static int pax_attribute(struct tar *, struct archive_entry *, - char *key, char *value); -static int pax_header(struct archive_read *, struct tar *, - struct archive_entry *, char *attr); -static void pax_time(const char *, int64_t *sec, long *nanos); -static ssize_t readline(struct archive_read *, struct tar *, const char **, - ssize_t limit); -static int read_body_to_string(struct archive_read *, struct tar *, - struct archive_string *, const void *h); -static int64_t tar_atol(const char *, unsigned); -static int64_t tar_atol10(const char *, unsigned); -static int64_t tar_atol256(const char *, unsigned); -static int64_t tar_atol8(const char *, unsigned); -static int tar_read_header(struct archive_read *, struct tar *, - struct archive_entry *); -static int tohex(int c); -static char *url_decode(const char *); -static wchar_t *utf8_decode(struct tar *, const char *, size_t length); - -int -archive_read_support_format_gnutar(struct archive *a) -{ - return (archive_read_support_format_tar(a)); -} - - -int -archive_read_support_format_tar(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct tar *tar; - int r; - - tar = (struct tar *)malloc(sizeof(*tar)); - if (tar == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate tar data"); - return (ARCHIVE_FATAL); - } - memset(tar, 0, sizeof(*tar)); - - r = __archive_read_register_format(a, tar, "tar", - archive_read_format_tar_bid, - NULL, - archive_read_format_tar_read_header, - archive_read_format_tar_read_data, - archive_read_format_tar_skip, - archive_read_format_tar_cleanup); - - if (r != ARCHIVE_OK) - free(tar); - return (ARCHIVE_OK); -} - -static int -archive_read_format_tar_cleanup(struct archive_read *a) -{ - struct tar *tar; - - tar = (struct tar *)(a->format->data); - gnu_clear_sparse_list(tar); - archive_string_free(&tar->acl_text); - archive_string_free(&tar->entry_pathname); - archive_string_free(&tar->entry_pathname_override); - archive_string_free(&tar->entry_linkpath); - archive_string_free(&tar->entry_uname); - archive_string_free(&tar->entry_gname); - archive_string_free(&tar->line); - archive_string_free(&tar->pax_global); - archive_string_free(&tar->pax_header); - archive_string_free(&tar->longname); - archive_string_free(&tar->longlink); - free(tar->pax_entry); - free(tar); - (a->format->data) = NULL; - return (ARCHIVE_OK); -} - - -static int -archive_read_format_tar_bid(struct archive_read *a) -{ - int bid; - const void *h; - const struct archive_entry_header_ustar *header; - - bid = 0; - - /* Now let's look at the actual header and see if it matches. */ - h = __archive_read_ahead(a, 512, NULL); - if (h == NULL) - return (-1); - - /* If it's an end-of-archive mark, we can handle it. */ - if ((*(const char *)h) == 0 - && archive_block_is_null((const unsigned char *)h)) { - /* - * Usually, I bid the number of bits verified, but - * in this case, 4096 seems excessive so I picked 10 as - * an arbitrary but reasonable-seeming value. - */ - return (10); - } - - /* If it's not an end-of-archive mark, it must have a valid checksum.*/ - if (!checksum(a, h)) - return (0); - bid += 48; /* Checksum is usually 6 octal digits. */ - - header = (const struct archive_entry_header_ustar *)h; - - /* Recognize POSIX formats. */ - if ((memcmp(header->magic, "ustar\0", 6) == 0) - &&(memcmp(header->version, "00", 2)==0)) - bid += 56; - - /* Recognize GNU tar format. */ - if ((memcmp(header->magic, "ustar ", 6) == 0) - &&(memcmp(header->version, " \0", 2)==0)) - bid += 56; - - /* Type flag must be null, digit or A-Z, a-z. */ - if (header->typeflag[0] != 0 && - !( header->typeflag[0] >= '0' && header->typeflag[0] <= '9') && - !( header->typeflag[0] >= 'A' && header->typeflag[0] <= 'Z') && - !( header->typeflag[0] >= 'a' && header->typeflag[0] <= 'z') ) - return (0); - bid += 2; /* 6 bits of variation in an 8-bit field leaves 2 bits. */ - - /* Sanity check: Look at first byte of mode field. */ - switch (255 & (unsigned)header->mode[0]) { - case 0: case 255: - /* Base-256 value: No further verification possible! */ - break; - case ' ': /* Not recommended, but not illegal, either. */ - break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - /* Octal Value. */ - /* TODO: Check format of remainder of this field. */ - break; - default: - /* Not a valid mode; bail out here. */ - return (0); - } - /* TODO: Sanity test uid/gid/size/mtime/rdevmajor/rdevminor fields. */ - - return (bid); -} - -/* - * The function invoked by archive_read_header(). This - * just sets up a few things and then calls the internal - * tar_read_header() function below. - */ -static int -archive_read_format_tar_read_header(struct archive_read *a, - struct archive_entry *entry) -{ - /* - * When converting tar archives to cpio archives, it is - * essential that each distinct file have a distinct inode - * number. To simplify this, we keep a static count here to - * assign fake dev/inode numbers to each tar entry. Note that - * pax format archives may overwrite this with something more - * useful. - * - * Ideally, we would track every file read from the archive so - * that we could assign the same dev/ino pair to hardlinks, - * but the memory required to store a complete lookup table is - * probably not worthwhile just to support the relatively - * obscure tar->cpio conversion case. - */ - static int default_inode; - static int default_dev; - struct tar *tar; - struct sparse_block *sp; - const char *p; - int r; - size_t l; - - /* Assign default device/inode values. */ - archive_entry_set_dev(entry, 1 + default_dev); /* Don't use zero. */ - archive_entry_set_ino(entry, ++default_inode); /* Don't use zero. */ - /* Limit generated st_ino number to 16 bits. */ - if (default_inode >= 0xffff) { - ++default_dev; - default_inode = 0; - } - - tar = (struct tar *)(a->format->data); - tar->entry_offset = 0; - while (tar->sparse_list != NULL) { - sp = tar->sparse_list; - tar->sparse_list = sp->next; - free(sp); - } - tar->sparse_last = NULL; - tar->realsize = -1; /* Mark this as "unset" */ - - r = tar_read_header(a, tar, entry); - - /* - * "non-sparse" files are really just sparse files with - * a single block. - */ - if (tar->sparse_list == NULL) - gnu_add_sparse_entry(tar, 0, tar->entry_bytes_remaining); - - if (r == ARCHIVE_OK) { - /* - * "Regular" entry with trailing '/' is really - * directory: This is needed for certain old tar - * variants and even for some broken newer ones. - */ - p = archive_entry_pathname(entry); - l = strlen(p); - if (archive_entry_filetype(entry) == AE_IFREG - && p[l-1] == '/') - archive_entry_set_filetype(entry, AE_IFDIR); - } - return (r); -} - -static int -archive_read_format_tar_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - ssize_t bytes_read; - struct tar *tar; - struct sparse_block *p; - - tar = (struct tar *)(a->format->data); - - if (tar->sparse_gnu_pending) { - if (tar->sparse_gnu_major == 1 && tar->sparse_gnu_minor == 0) { - tar->sparse_gnu_pending = 0; - /* Read initial sparse map. */ - bytes_read = gnu_sparse_10_read(a, tar); - tar->entry_bytes_remaining -= bytes_read; - if (bytes_read < 0) - return (bytes_read); - } else { - *size = 0; - *offset = 0; - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Unrecognized GNU sparse file format"); - return (ARCHIVE_WARN); - } - tar->sparse_gnu_pending = 0; - } - - /* Remove exhausted entries from sparse list. */ - while (tar->sparse_list != NULL && - tar->sparse_list->remaining == 0) { - p = tar->sparse_list; - tar->sparse_list = p->next; - free(p); - } - - /* If we're at end of file, return EOF. */ - if (tar->sparse_list == NULL || tar->entry_bytes_remaining == 0) { - if (__archive_read_skip(a, tar->entry_padding) < 0) - return (ARCHIVE_FATAL); - tar->entry_padding = 0; - *buff = NULL; - *size = 0; - *offset = tar->realsize; - return (ARCHIVE_EOF); - } - - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read < 0) - return (ARCHIVE_FATAL); - if (*buff == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated tar archive"); - return (ARCHIVE_FATAL); - } - if (bytes_read > tar->entry_bytes_remaining) - bytes_read = tar->entry_bytes_remaining; - /* Don't read more than is available in the - * current sparse block. */ - if (tar->sparse_list->remaining < bytes_read) - bytes_read = tar->sparse_list->remaining; - *size = bytes_read; - *offset = tar->sparse_list->offset; - tar->sparse_list->remaining -= bytes_read; - tar->sparse_list->offset += bytes_read; - tar->entry_bytes_remaining -= bytes_read; - __archive_read_consume(a, bytes_read); - return (ARCHIVE_OK); -} - -static int -archive_read_format_tar_skip(struct archive_read *a) -{ - int64_t bytes_skipped; - struct tar* tar; - - tar = (struct tar *)(a->format->data); - - /* - * Compression layer skip functions are required to either skip the - * length requested or fail, so we can rely upon the entire entry - * plus padding being skipped. - */ - bytes_skipped = __archive_read_skip(a, - tar->entry_bytes_remaining + tar->entry_padding); - if (bytes_skipped < 0) - return (ARCHIVE_FATAL); - - tar->entry_bytes_remaining = 0; - tar->entry_padding = 0; - - /* Free the sparse list. */ - gnu_clear_sparse_list(tar); - - return (ARCHIVE_OK); -} - -/* - * This function recursively interprets all of the headers associated - * with a single entry. - */ -static int -tar_read_header(struct archive_read *a, struct tar *tar, - struct archive_entry *entry) -{ - ssize_t bytes; - int err; - const void *h; - const struct archive_entry_header_ustar *header; - - /* Read 512-byte header record */ - h = __archive_read_ahead(a, 512, &bytes); - if (bytes < 0) - return (bytes); - if (bytes < 512) { /* Short read or EOF. */ - /* Try requesting just one byte and see what happens. */ - (void)__archive_read_ahead(a, 1, &bytes); - if (bytes == 0) { - /* - * The archive ends at a 512-byte boundary but - * without a proper end-of-archive marker. - * Yes, there are tar writers that do this; - * hold our nose and accept it. - */ - return (ARCHIVE_EOF); - } - /* Archive ends with a partial block; this is bad. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated tar archive"); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, 512); - - - /* Check for end-of-archive mark. */ - if (((*(const char *)h)==0) && archive_block_is_null((const unsigned char *)h)) { - /* Try to consume a second all-null record, as well. */ - h = __archive_read_ahead(a, 512, NULL); - if (h != NULL) - __archive_read_consume(a, 512); - archive_clear_error(&a->archive); - if (a->archive.archive_format_name == NULL) { - a->archive.archive_format = ARCHIVE_FORMAT_TAR; - a->archive.archive_format_name = "tar"; - } - return (ARCHIVE_EOF); - } - - /* - * Note: If the checksum fails and we return ARCHIVE_RETRY, - * then the client is likely to just retry. This is a very - * crude way to search for the next valid header! - * - * TODO: Improve this by implementing a real header scan. - */ - if (!checksum(a, h)) { - archive_set_error(&a->archive, EINVAL, "Damaged tar archive"); - return (ARCHIVE_RETRY); /* Retryable: Invalid header */ - } - - if (++tar->header_recursion_depth > 32) { - archive_set_error(&a->archive, EINVAL, "Too many special headers"); - return (ARCHIVE_WARN); - } - - /* Determine the format variant. */ - header = (const struct archive_entry_header_ustar *)h; - switch(header->typeflag[0]) { - case 'A': /* Solaris tar ACL */ - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = "Solaris tar"; - err = header_Solaris_ACL(a, tar, entry, h); - break; - case 'g': /* POSIX-standard 'g' header. */ - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = "POSIX pax interchange format"; - err = header_pax_global(a, tar, entry, h); - break; - case 'K': /* Long link name (GNU tar, others) */ - err = header_longlink(a, tar, entry, h); - break; - case 'L': /* Long filename (GNU tar, others) */ - err = header_longname(a, tar, entry, h); - break; - case 'V': /* GNU volume header */ - err = header_volume(a, tar, entry, h); - break; - case 'X': /* Used by SUN tar; same as 'x'. */ - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = - "POSIX pax interchange format (Sun variant)"; - err = header_pax_extensions(a, tar, entry, h); - break; - case 'x': /* POSIX-standard 'x' header. */ - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = "POSIX pax interchange format"; - err = header_pax_extensions(a, tar, entry, h); - break; - default: - if (memcmp(header->magic, "ustar \0", 8) == 0) { - a->archive.archive_format = ARCHIVE_FORMAT_TAR_GNUTAR; - a->archive.archive_format_name = "GNU tar format"; - err = header_gnutar(a, tar, entry, h); - } else if (memcmp(header->magic, "ustar", 5) == 0) { - if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE) { - a->archive.archive_format = ARCHIVE_FORMAT_TAR_USTAR; - a->archive.archive_format_name = "POSIX ustar format"; - } - err = header_ustar(a, tar, entry, h); - } else { - a->archive.archive_format = ARCHIVE_FORMAT_TAR; - a->archive.archive_format_name = "tar (non-POSIX)"; - err = header_old_tar(a, tar, entry, h); - } - } - --tar->header_recursion_depth; - /* We return warnings or success as-is. Anything else is fatal. */ - if (err == ARCHIVE_WARN || err == ARCHIVE_OK) - return (err); - if (err == ARCHIVE_EOF) - /* EOF when recursively reading a header is bad. */ - archive_set_error(&a->archive, EINVAL, "Damaged tar archive"); - return (ARCHIVE_FATAL); -} - -/* - * Return true if block checksum is correct. - */ -static int -checksum(struct archive_read *a, const void *h) -{ - const unsigned char *bytes; - const struct archive_entry_header_ustar *header; - int check, i, sum; - - (void)a; /* UNUSED */ - bytes = (const unsigned char *)h; - header = (const struct archive_entry_header_ustar *)h; - - /* - * Test the checksum. Note that POSIX specifies _unsigned_ - * bytes for this calculation. - */ - sum = tar_atol(header->checksum, sizeof(header->checksum)); - check = 0; - for (i = 0; i < 148; i++) - check += (unsigned char)bytes[i]; - for (; i < 156; i++) - check += 32; - for (; i < 512; i++) - check += (unsigned char)bytes[i]; - if (sum == check) - return (1); - - /* - * Repeat test with _signed_ bytes, just in case this archive - * was created by an old BSD, Solaris, or HP-UX tar with a - * broken checksum calculation. - */ - check = 0; - for (i = 0; i < 148; i++) - check += (signed char)bytes[i]; - for (; i < 156; i++) - check += 32; - for (; i < 512; i++) - check += (signed char)bytes[i]; - if (sum == check) - return (1); - - return (0); -} - -/* - * Return true if this block contains only nulls. - */ -static int -archive_block_is_null(const unsigned char *p) -{ - unsigned i; - - for (i = 0; i < 512; i++) - if (*p++) - return (0); - return (1); -} - -/* - * Interpret 'A' Solaris ACL header - */ -static int -header_Solaris_ACL(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - const struct archive_entry_header_ustar *header; - size_t size; - int err; - int64_t type; - char *acl, *p; - wchar_t *wp; - - /* - * read_body_to_string adds a NUL terminator, but we need a little - * more to make sure that we don't overrun acl_text later. - */ - header = (const struct archive_entry_header_ustar *)h; - size = tar_atol(header->size, sizeof(header->size)); - err = read_body_to_string(a, tar, &(tar->acl_text), h); - if (err != ARCHIVE_OK) - return (err); - /* Recursively read next header */ - err = tar_read_header(a, tar, entry); - if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) - return (err); - - /* TODO: Examine the first characters to see if this - * is an AIX ACL descriptor. We'll likely never support - * them, but it would be polite to recognize and warn when - * we do see them. */ - - /* Leading octal number indicates ACL type and number of entries. */ - p = acl = tar->acl_text.s; - type = 0; - while (*p != '\0' && p < acl + size) { - if (*p < '0' || *p > '7') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (invalid digit)"); - return(ARCHIVE_WARN); - } - type <<= 3; - type += *p - '0'; - if (type > 077777777) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (count too large)"); - return (ARCHIVE_WARN); - } - p++; - } - switch ((int)type & ~0777777) { - case 01000000: - /* POSIX.1e ACL */ - break; - case 03000000: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Solaris NFSv4 ACLs not supported"); - return (ARCHIVE_WARN); - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (unsupported type %o)", - (int)type); - return (ARCHIVE_WARN); - } - p++; - - if (p >= acl + size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (body overflow)"); - return(ARCHIVE_WARN); - } - - /* ACL text is null-terminated; find the end. */ - size -= (p - acl); - acl = p; - - while (*p != '\0' && p < acl + size) - p++; - - wp = utf8_decode(tar, acl, p - acl); - err = __archive_entry_acl_parse_w(entry, wp, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - if (err != ARCHIVE_OK) - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (unparsable)"); - return (err); -} - -/* - * Interpret 'K' long linkname header. - */ -static int -header_longlink(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - int err; - - err = read_body_to_string(a, tar, &(tar->longlink), h); - if (err != ARCHIVE_OK) - return (err); - err = tar_read_header(a, tar, entry); - if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) - return (err); - /* Set symlink if symlink already set, else hardlink. */ - archive_entry_copy_link(entry, tar->longlink.s); - return (ARCHIVE_OK); -} - -/* - * Interpret 'L' long filename header. - */ -static int -header_longname(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - int err; - - err = read_body_to_string(a, tar, &(tar->longname), h); - if (err != ARCHIVE_OK) - return (err); - /* Read and parse "real" header, then override name. */ - err = tar_read_header(a, tar, entry); - if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) - return (err); - archive_entry_copy_pathname(entry, tar->longname.s); - return (ARCHIVE_OK); -} - - -/* - * Interpret 'V' GNU tar volume header. - */ -static int -header_volume(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - (void)h; - - /* Just skip this and read the next header. */ - return (tar_read_header(a, tar, entry)); -} - -/* - * Read body of an archive entry into an archive_string object. - */ -static int -read_body_to_string(struct archive_read *a, struct tar *tar, - struct archive_string *as, const void *h) -{ - off_t size, padded_size; - const struct archive_entry_header_ustar *header; - const void *src; - - (void)tar; /* UNUSED */ - header = (const struct archive_entry_header_ustar *)h; - size = tar_atol(header->size, sizeof(header->size)); - if ((size > 1048576) || (size < 0)) { - archive_set_error(&a->archive, EINVAL, - "Special header too large"); - return (ARCHIVE_FATAL); - } - - /* Fail if we can't make our buffer big enough. */ - if (archive_string_ensure(as, size+1) == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory"); - return (ARCHIVE_FATAL); - } - - /* Read the body into the string. */ - padded_size = (size + 511) & ~ 511; - src = __archive_read_ahead(a, padded_size, NULL); - if (src == NULL) - return (ARCHIVE_FATAL); - memcpy(as->s, src, size); - __archive_read_consume(a, padded_size); - as->s[size] = '\0'; - return (ARCHIVE_OK); -} - -/* - * Parse out common header elements. - * - * This would be the same as header_old_tar, except that the - * filename is handled slightly differently for old and POSIX - * entries (POSIX entries support a 'prefix'). This factoring - * allows header_old_tar and header_ustar - * to handle filenames differently, while still putting most of the - * common parsing into one place. - */ -static int -header_common(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - const struct archive_entry_header_ustar *header; - char tartype; - - (void)a; /* UNUSED */ - - header = (const struct archive_entry_header_ustar *)h; - if (header->linkname[0]) - archive_strncpy(&(tar->entry_linkpath), header->linkname, - sizeof(header->linkname)); - else - archive_string_empty(&(tar->entry_linkpath)); - - /* Parse out the numeric fields (all are octal) */ - archive_entry_set_mode(entry, tar_atol(header->mode, sizeof(header->mode))); - archive_entry_set_uid(entry, tar_atol(header->uid, sizeof(header->uid))); - archive_entry_set_gid(entry, tar_atol(header->gid, sizeof(header->gid))); - tar->entry_bytes_remaining = tar_atol(header->size, sizeof(header->size)); - tar->realsize = tar->entry_bytes_remaining; - archive_entry_set_size(entry, tar->entry_bytes_remaining); - archive_entry_set_mtime(entry, tar_atol(header->mtime, sizeof(header->mtime)), 0); - - /* Handle the tar type flag appropriately. */ - tartype = header->typeflag[0]; - - switch (tartype) { - case '1': /* Hard link */ - archive_entry_copy_hardlink(entry, tar->entry_linkpath.s); - /* - * The following may seem odd, but: Technically, tar - * does not store the file type for a "hard link" - * entry, only the fact that it is a hard link. So, I - * leave the type zero normally. But, pax interchange - * format allows hard links to have data, which - * implies that the underlying entry is a regular - * file. - */ - if (archive_entry_size(entry) > 0) - archive_entry_set_filetype(entry, AE_IFREG); - - /* - * A tricky point: Traditionally, tar readers have - * ignored the size field when reading hardlink - * entries, and some writers put non-zero sizes even - * though the body is empty. POSIX blessed this - * convention in the 1988 standard, but broke with - * this tradition in 2001 by permitting hardlink - * entries to store valid bodies in pax interchange - * format, but not in ustar format. Since there is no - * hard and fast way to distinguish pax interchange - * from earlier archives (the 'x' and 'g' entries are - * optional, after all), we need a heuristic. - */ - if (archive_entry_size(entry) == 0) { - /* If the size is already zero, we're done. */ - } else if (a->archive.archive_format - == ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE) { - /* Definitely pax extended; must obey hardlink size. */ - } else if (a->archive.archive_format == ARCHIVE_FORMAT_TAR - || a->archive.archive_format == ARCHIVE_FORMAT_TAR_GNUTAR) - { - /* Old-style or GNU tar: we must ignore the size. */ - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - } else if (archive_read_format_tar_bid(a) > 50) { - /* - * We don't know if it's pax: If the bid - * function sees a valid ustar header - * immediately following, then let's ignore - * the hardlink size. - */ - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - } - /* - * TODO: There are still two cases I'd like to handle: - * = a ustar non-pax archive with a hardlink entry at - * end-of-archive. (Look for block of nulls following?) - * = a pax archive that has not seen any pax headers - * and has an entry which is a hardlink entry storing - * a body containing an uncompressed tar archive. - * The first is worth addressing; I don't see any reliable - * way to deal with the second possibility. - */ - break; - case '2': /* Symlink */ - archive_entry_set_filetype(entry, AE_IFLNK); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - archive_entry_copy_symlink(entry, tar->entry_linkpath.s); - break; - case '3': /* Character device */ - archive_entry_set_filetype(entry, AE_IFCHR); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - break; - case '4': /* Block device */ - archive_entry_set_filetype(entry, AE_IFBLK); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - break; - case '5': /* Dir */ - archive_entry_set_filetype(entry, AE_IFDIR); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - break; - case '6': /* FIFO device */ - archive_entry_set_filetype(entry, AE_IFIFO); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - break; - case 'D': /* GNU incremental directory type */ - /* - * No special handling is actually required here. - * It might be nice someday to preprocess the file list and - * provide it to the client, though. - */ - archive_entry_set_filetype(entry, AE_IFDIR); - break; - case 'M': /* GNU "Multi-volume" (remainder of file from last archive)*/ - /* - * As far as I can tell, this is just like a regular file - * entry, except that the contents should be _appended_ to - * the indicated file at the indicated offset. This may - * require some API work to fully support. - */ - break; - case 'N': /* Old GNU "long filename" entry. */ - /* The body of this entry is a script for renaming - * previously-extracted entries. Ugh. It will never - * be supported by libarchive. */ - archive_entry_set_filetype(entry, AE_IFREG); - break; - case 'S': /* GNU sparse files */ - /* - * Sparse files are really just regular files with - * sparse information in the extended area. - */ - /* FALLTHROUGH */ - default: /* Regular file and non-standard types */ - /* - * Per POSIX: non-recognized types should always be - * treated as regular files. - */ - archive_entry_set_filetype(entry, AE_IFREG); - break; - } - return (0); -} - -/* - * Parse out header elements for "old-style" tar archives. - */ -static int -header_old_tar(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - const struct archive_entry_header_ustar *header; - - /* Copy filename over (to ensure null termination). */ - header = (const struct archive_entry_header_ustar *)h; - archive_strncpy(&(tar->entry_pathname), header->name, sizeof(header->name)); - archive_entry_copy_pathname(entry, tar->entry_pathname.s); - - /* Grab rest of common fields */ - header_common(a, tar, entry, h); - - tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - return (0); -} - -/* - * Parse a file header for a pax extended archive entry. - */ -static int -header_pax_global(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - int err; - - err = read_body_to_string(a, tar, &(tar->pax_global), h); - if (err != ARCHIVE_OK) - return (err); - err = tar_read_header(a, tar, entry); - return (err); -} - -static int -header_pax_extensions(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - int err, err2; - - err = read_body_to_string(a, tar, &(tar->pax_header), h); - if (err != ARCHIVE_OK) - return (err); - - /* Parse the next header. */ - err = tar_read_header(a, tar, entry); - if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) - return (err); - - /* - * TODO: Parse global/default options into 'entry' struct here - * before handling file-specific options. - * - * This design (parse standard header, then overwrite with pax - * extended attribute data) usually works well, but isn't ideal; - * it would be better to parse the pax extended attributes first - * and then skip any fields in the standard header that were - * defined in the pax header. - */ - err2 = pax_header(a, tar, entry, tar->pax_header.s); - err = err_combine(err, err2); - tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - return (err); -} - - -/* - * Parse a file header for a Posix "ustar" archive entry. This also - * handles "pax" or "extended ustar" entries. - */ -static int -header_ustar(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - const struct archive_entry_header_ustar *header; - struct archive_string *as; - - header = (const struct archive_entry_header_ustar *)h; - - /* Copy name into an internal buffer to ensure null-termination. */ - as = &(tar->entry_pathname); - if (header->prefix[0]) { - archive_strncpy(as, header->prefix, sizeof(header->prefix)); - if (as->s[archive_strlen(as) - 1] != '/') - archive_strappend_char(as, '/'); - archive_strncat(as, header->name, sizeof(header->name)); - } else - archive_strncpy(as, header->name, sizeof(header->name)); - - archive_entry_copy_pathname(entry, as->s); - - /* Handle rest of common fields. */ - header_common(a, tar, entry, h); - - /* Handle POSIX ustar fields. */ - archive_strncpy(&(tar->entry_uname), header->uname, - sizeof(header->uname)); - archive_entry_copy_uname(entry, tar->entry_uname.s); - - archive_strncpy(&(tar->entry_gname), header->gname, - sizeof(header->gname)); - archive_entry_copy_gname(entry, tar->entry_gname.s); - - /* Parse out device numbers only for char and block specials. */ - if (header->typeflag[0] == '3' || header->typeflag[0] == '4') { - archive_entry_set_rdevmajor(entry, - tar_atol(header->rdevmajor, sizeof(header->rdevmajor))); - archive_entry_set_rdevminor(entry, - tar_atol(header->rdevminor, sizeof(header->rdevminor))); - } - - tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - - return (0); -} - - -/* - * Parse the pax extended attributes record. - * - * Returns non-zero if there's an error in the data. - */ -static int -pax_header(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, char *attr) -{ - size_t attr_length, l, line_length; - char *p; - char *key, *value; - int err, err2; - - attr_length = strlen(attr); - tar->pax_hdrcharset_binary = 0; - archive_string_empty(&(tar->entry_gname)); - archive_string_empty(&(tar->entry_linkpath)); - archive_string_empty(&(tar->entry_pathname)); - archive_string_empty(&(tar->entry_pathname_override)); - archive_string_empty(&(tar->entry_uname)); - err = ARCHIVE_OK; - while (attr_length > 0) { - /* Parse decimal length field at start of line. */ - line_length = 0; - l = attr_length; - p = attr; /* Record start of line. */ - while (l>0) { - if (*p == ' ') { - p++; - l--; - break; - } - if (*p < '0' || *p > '9') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring malformed pax extended attributes"); - return (ARCHIVE_WARN); - } - line_length *= 10; - line_length += *p - '0'; - if (line_length > 999999) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Rejecting pax extended attribute > 1MB"); - return (ARCHIVE_WARN); - } - p++; - l--; - } - - /* - * Parsed length must be no bigger than available data, - * at least 1, and the last character of the line must - * be '\n'. - */ - if (line_length > attr_length - || line_length < 1 - || attr[line_length - 1] != '\n') - { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring malformed pax extended attribute"); - return (ARCHIVE_WARN); - } - - /* Null-terminate the line. */ - attr[line_length - 1] = '\0'; - - /* Find end of key and null terminate it. */ - key = p; - if (key[0] == '=') - return (-1); - while (*p && *p != '=') - ++p; - if (*p == '\0') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid pax extended attributes"); - return (ARCHIVE_WARN); - } - *p = '\0'; - - /* Identify null-terminated 'value' portion. */ - value = p + 1; - - /* Identify this attribute and set it in the entry. */ - err2 = pax_attribute(tar, entry, key, value); - err = err_combine(err, err2); - - /* Skip to next line */ - attr += line_length; - attr_length -= line_length; - } - if (archive_strlen(&(tar->entry_gname)) > 0) { - value = tar->entry_gname.s; - if (tar->pax_hdrcharset_binary) - archive_entry_copy_gname(entry, value); - else { - if (!archive_entry_update_gname_utf8(entry, value)) { - err = ARCHIVE_WARN; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Gname in pax header can't " - "be converted to current locale."); - } - } - } - if (archive_strlen(&(tar->entry_linkpath)) > 0) { - value = tar->entry_linkpath.s; - if (tar->pax_hdrcharset_binary) - archive_entry_copy_link(entry, value); - else { - if (!archive_entry_update_link_utf8(entry, value)) { - err = ARCHIVE_WARN; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Linkname in pax header can't " - "be converted to current locale."); - } - } - } - /* - * Some extensions (such as the GNU sparse file extensions) - * deliberately store a synthetic name under the regular 'path' - * attribute and the real file name under a different attribute. - * Since we're supposed to not care about the order, we - * have no choice but to store all of the various filenames - * we find and figure it all out afterwards. This is the - * figuring out part. - */ - value = NULL; - if (archive_strlen(&(tar->entry_pathname_override)) > 0) - value = tar->entry_pathname_override.s; - else if (archive_strlen(&(tar->entry_pathname)) > 0) - value = tar->entry_pathname.s; - if (value != NULL) { - if (tar->pax_hdrcharset_binary) - archive_entry_copy_pathname(entry, value); - else { - if (!archive_entry_update_pathname_utf8(entry, value)) { - err = ARCHIVE_WARN; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Pathname in pax header can't be " - "converted to current locale."); - } - } - } - if (archive_strlen(&(tar->entry_uname)) > 0) { - value = tar->entry_uname.s; - if (tar->pax_hdrcharset_binary) - archive_entry_copy_uname(entry, value); - else { - if (!archive_entry_update_uname_utf8(entry, value)) { - err = ARCHIVE_WARN; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Uname in pax header can't " - "be converted to current locale."); - } - } - } - return (err); -} - -static int -pax_attribute_xattr(struct archive_entry *entry, - char *name, char *value) -{ - char *name_decoded; - void *value_decoded; - size_t value_len; - - if (strlen(name) < 18 || (strncmp(name, "LIBARCHIVE.xattr.", 17)) != 0) - return 3; - - name += 17; - - /* URL-decode name */ - name_decoded = url_decode(name); - if (name_decoded == NULL) - return 2; - - /* Base-64 decode value */ - value_decoded = base64_decode(value, strlen(value), &value_len); - if (value_decoded == NULL) { - free(name_decoded); - return 1; - } - - archive_entry_xattr_add_entry(entry, name_decoded, - value_decoded, value_len); - - free(name_decoded); - free(value_decoded); - return 0; -} - -/* - * Parse a single key=value attribute. key/value pointers are - * assumed to point into reasonably long-lived storage. - * - * Note that POSIX reserves all-lowercase keywords. Vendor-specific - * extensions should always have keywords of the form "VENDOR.attribute" - * In particular, it's quite feasible to support many different - * vendor extensions here. I'm using "LIBARCHIVE" for extensions - * unique to this library. - * - * Investigate other vendor-specific extensions and see if - * any of them look useful. - */ -static int -pax_attribute(struct tar *tar, struct archive_entry *entry, - char *key, char *value) -{ - int64_t s; - long n; - wchar_t *wp; - - switch (key[0]) { - case 'G': - /* GNU "0.0" sparse pax format. */ - if (strcmp(key, "GNU.sparse.numblocks") == 0) { - tar->sparse_offset = -1; - tar->sparse_numbytes = -1; - tar->sparse_gnu_major = 0; - tar->sparse_gnu_minor = 0; - } - if (strcmp(key, "GNU.sparse.offset") == 0) { - tar->sparse_offset = tar_atol10(value, strlen(value)); - if (tar->sparse_numbytes != -1) { - gnu_add_sparse_entry(tar, - tar->sparse_offset, tar->sparse_numbytes); - tar->sparse_offset = -1; - tar->sparse_numbytes = -1; - } - } - if (strcmp(key, "GNU.sparse.numbytes") == 0) { - tar->sparse_numbytes = tar_atol10(value, strlen(value)); - if (tar->sparse_numbytes != -1) { - gnu_add_sparse_entry(tar, - tar->sparse_offset, tar->sparse_numbytes); - tar->sparse_offset = -1; - tar->sparse_numbytes = -1; - } - } - if (strcmp(key, "GNU.sparse.size") == 0) { - tar->realsize = tar_atol10(value, strlen(value)); - archive_entry_set_size(entry, tar->realsize); - } - - /* GNU "0.1" sparse pax format. */ - if (strcmp(key, "GNU.sparse.map") == 0) { - tar->sparse_gnu_major = 0; - tar->sparse_gnu_minor = 1; - if (gnu_sparse_01_parse(tar, value) != ARCHIVE_OK) - return (ARCHIVE_WARN); - } - - /* GNU "1.0" sparse pax format */ - if (strcmp(key, "GNU.sparse.major") == 0) { - tar->sparse_gnu_major = tar_atol10(value, strlen(value)); - tar->sparse_gnu_pending = 1; - } - if (strcmp(key, "GNU.sparse.minor") == 0) { - tar->sparse_gnu_minor = tar_atol10(value, strlen(value)); - tar->sparse_gnu_pending = 1; - } - if (strcmp(key, "GNU.sparse.name") == 0) { - /* - * The real filename; when storing sparse - * files, GNU tar puts a synthesized name into - * the regular 'path' attribute in an attempt - * to limit confusion. ;-) - */ - archive_strcpy(&(tar->entry_pathname_override), value); - } - if (strcmp(key, "GNU.sparse.realsize") == 0) { - tar->realsize = tar_atol10(value, strlen(value)); - archive_entry_set_size(entry, tar->realsize); - } - break; - case 'L': - /* Our extensions */ -/* TODO: Handle arbitrary extended attributes... */ -/* - if (strcmp(key, "LIBARCHIVE.xxxxxxx")==0) - archive_entry_set_xxxxxx(entry, value); -*/ - if (strcmp(key, "LIBARCHIVE.creationtime")==0) { - pax_time(value, &s, &n); - archive_entry_set_birthtime(entry, s, n); - } - if (strncmp(key, "LIBARCHIVE.xattr.", 17)==0) - pax_attribute_xattr(entry, key, value); - break; - case 'S': - /* We support some keys used by the "star" archiver */ - if (strcmp(key, "SCHILY.acl.access")==0) { - wp = utf8_decode(tar, value, strlen(value)); - /* TODO: if (wp == NULL) */ - __archive_entry_acl_parse_w(entry, wp, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - } else if (strcmp(key, "SCHILY.acl.default")==0) { - wp = utf8_decode(tar, value, strlen(value)); - /* TODO: if (wp == NULL) */ - __archive_entry_acl_parse_w(entry, wp, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT); - } else if (strcmp(key, "SCHILY.devmajor")==0) { - archive_entry_set_rdevmajor(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.devminor")==0) { - archive_entry_set_rdevminor(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.fflags")==0) { - archive_entry_copy_fflags_text(entry, value); - } else if (strcmp(key, "SCHILY.dev")==0) { - archive_entry_set_dev(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.ino")==0) { - archive_entry_set_ino(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.nlink")==0) { - archive_entry_set_nlink(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.realsize")==0) { - tar->realsize = tar_atol10(value, strlen(value)); - archive_entry_set_size(entry, tar->realsize); - } - break; - case 'a': - if (strcmp(key, "atime")==0) { - pax_time(value, &s, &n); - archive_entry_set_atime(entry, s, n); - } - break; - case 'c': - if (strcmp(key, "ctime")==0) { - pax_time(value, &s, &n); - archive_entry_set_ctime(entry, s, n); - } else if (strcmp(key, "charset")==0) { - /* TODO: Publish charset information in entry. */ - } else if (strcmp(key, "comment")==0) { - /* TODO: Publish comment in entry. */ - } - break; - case 'g': - if (strcmp(key, "gid")==0) { - archive_entry_set_gid(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "gname")==0) { - archive_strcpy(&(tar->entry_gname), value); - } - break; - case 'h': - if (strcmp(key, "hdrcharset") == 0) { - if (strcmp(value, "BINARY") == 0) - tar->pax_hdrcharset_binary = 1; - else if (strcmp(value, "ISO-IR 10646 2000 UTF-8") == 0) - tar->pax_hdrcharset_binary = 0; - else { - /* TODO: Warn about unsupported hdrcharset */ - } - } - break; - case 'l': - /* pax interchange doesn't distinguish hardlink vs. symlink. */ - if (strcmp(key, "linkpath")==0) { - archive_strcpy(&(tar->entry_linkpath), value); - } - break; - case 'm': - if (strcmp(key, "mtime")==0) { - pax_time(value, &s, &n); - archive_entry_set_mtime(entry, s, n); - } - break; - case 'p': - if (strcmp(key, "path")==0) { - archive_strcpy(&(tar->entry_pathname), value); - } - break; - case 'r': - /* POSIX has reserved 'realtime.*' */ - break; - case 's': - /* POSIX has reserved 'security.*' */ - /* Someday: if (strcmp(key, "security.acl")==0) { ... } */ - if (strcmp(key, "size")==0) { - /* "size" is the size of the data in the entry. */ - tar->entry_bytes_remaining - = tar_atol10(value, strlen(value)); - /* - * But, "size" is not necessarily the size of - * the file on disk; if this is a sparse file, - * the disk size may have already been set from - * GNU.sparse.realsize or GNU.sparse.size or - * an old GNU header field or SCHILY.realsize - * or .... - */ - if (tar->realsize < 0) { - archive_entry_set_size(entry, - tar->entry_bytes_remaining); - tar->realsize - = tar->entry_bytes_remaining; - } - } - break; - case 'u': - if (strcmp(key, "uid")==0) { - archive_entry_set_uid(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "uname")==0) { - archive_strcpy(&(tar->entry_uname), value); - } - break; - } - return (0); -} - - - -/* - * parse a decimal time value, which may include a fractional portion - */ -static void -pax_time(const char *p, int64_t *ps, long *pn) -{ - char digit; - int64_t s; - unsigned long l; - int sign; - int64_t limit, last_digit_limit; - - limit = INT64_MAX / 10; - last_digit_limit = INT64_MAX % 10; - - s = 0; - sign = 1; - if (*p == '-') { - sign = -1; - p++; - } - while (*p >= '0' && *p <= '9') { - digit = *p - '0'; - if (s > limit || - (s == limit && digit > last_digit_limit)) { - s = INT64_MAX; - break; - } - s = (s * 10) + digit; - ++p; - } - - *ps = s * sign; - - /* Calculate nanoseconds. */ - *pn = 0; - - if (*p != '.') - return; - - l = 100000000UL; - do { - ++p; - if (*p >= '0' && *p <= '9') - *pn += (*p - '0') * l; - else - break; - } while (l /= 10); -} - -/* - * Parse GNU tar header - */ -static int -header_gnutar(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) -{ - const struct archive_entry_header_gnutar *header; - - (void)a; - - /* - * GNU header is like POSIX ustar, except 'prefix' is - * replaced with some other fields. This also means the - * filename is stored as in old-style archives. - */ - - /* Grab fields common to all tar variants. */ - header_common(a, tar, entry, h); - - /* Copy filename over (to ensure null termination). */ - header = (const struct archive_entry_header_gnutar *)h; - archive_strncpy(&(tar->entry_pathname), header->name, - sizeof(header->name)); - archive_entry_copy_pathname(entry, tar->entry_pathname.s); - - /* Fields common to ustar and GNU */ - /* XXX Can the following be factored out since it's common - * to ustar and gnu tar? Is it okay to move it down into - * header_common, perhaps? */ - archive_strncpy(&(tar->entry_uname), - header->uname, sizeof(header->uname)); - archive_entry_copy_uname(entry, tar->entry_uname.s); - - archive_strncpy(&(tar->entry_gname), - header->gname, sizeof(header->gname)); - archive_entry_copy_gname(entry, tar->entry_gname.s); - - /* Parse out device numbers only for char and block specials */ - if (header->typeflag[0] == '3' || header->typeflag[0] == '4') { - archive_entry_set_rdevmajor(entry, - tar_atol(header->rdevmajor, sizeof(header->rdevmajor))); - archive_entry_set_rdevminor(entry, - tar_atol(header->rdevminor, sizeof(header->rdevminor))); - } else - archive_entry_set_rdev(entry, 0); - - tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - - /* Grab GNU-specific fields. */ - archive_entry_set_atime(entry, - tar_atol(header->atime, sizeof(header->atime)), 0); - archive_entry_set_ctime(entry, - tar_atol(header->ctime, sizeof(header->ctime)), 0); - if (header->realsize[0] != 0) { - tar->realsize - = tar_atol(header->realsize, sizeof(header->realsize)); - archive_entry_set_size(entry, tar->realsize); - } - - if (header->sparse[0].offset[0] != 0) { - gnu_sparse_old_read(a, tar, header); - } else { - if (header->isextended[0] != 0) { - /* XXX WTF? XXX */ - } - } - - return (0); -} - -static void -gnu_add_sparse_entry(struct tar *tar, off_t offset, off_t remaining) -{ - struct sparse_block *p; - - p = (struct sparse_block *)malloc(sizeof(*p)); - if (p == NULL) - __archive_errx(1, "Out of memory"); - memset(p, 0, sizeof(*p)); - if (tar->sparse_last != NULL) - tar->sparse_last->next = p; - else - tar->sparse_list = p; - tar->sparse_last = p; - p->offset = offset; - p->remaining = remaining; -} - -static void -gnu_clear_sparse_list(struct tar *tar) -{ - struct sparse_block *p; - - while (tar->sparse_list != NULL) { - p = tar->sparse_list; - tar->sparse_list = p->next; - free(p); - } - tar->sparse_last = NULL; -} - -/* - * GNU tar old-format sparse data. - * - * GNU old-format sparse data is stored in a fixed-field - * format. Offset/size values are 11-byte octal fields (same - * format as 'size' field in ustart header). These are - * stored in the header, allocating subsequent header blocks - * as needed. Extending the header in this way is a pretty - * severe POSIX violation; this design has earned GNU tar a - * lot of criticism. - */ - -static int -gnu_sparse_old_read(struct archive_read *a, struct tar *tar, - const struct archive_entry_header_gnutar *header) -{ - ssize_t bytes_read; - const void *data; - struct extended { - struct gnu_sparse sparse[21]; - char isextended[1]; - char padding[7]; - }; - const struct extended *ext; - - gnu_sparse_old_parse(tar, header->sparse, 4); - if (header->isextended[0] == 0) - return (ARCHIVE_OK); - - do { - data = __archive_read_ahead(a, 512, &bytes_read); - if (bytes_read < 0) - return (ARCHIVE_FATAL); - if (bytes_read < 512) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated tar archive " - "detected while reading sparse file data"); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, 512); - ext = (const struct extended *)data; - gnu_sparse_old_parse(tar, ext->sparse, 21); - } while (ext->isextended[0] != 0); - if (tar->sparse_list != NULL) - tar->entry_offset = tar->sparse_list->offset; - return (ARCHIVE_OK); -} - -static void -gnu_sparse_old_parse(struct tar *tar, - const struct gnu_sparse *sparse, int length) -{ - while (length > 0 && sparse->offset[0] != 0) { - gnu_add_sparse_entry(tar, - tar_atol(sparse->offset, sizeof(sparse->offset)), - tar_atol(sparse->numbytes, sizeof(sparse->numbytes))); - sparse++; - length--; - } -} - -/* - * GNU tar sparse format 0.0 - * - * Beginning with GNU tar 1.15, sparse files are stored using - * information in the pax extended header. The GNU tar maintainers - * have gone through a number of variations in the process of working - * out this scheme; furtunately, they're all numbered. - * - * Sparse format 0.0 uses attribute GNU.sparse.numblocks to store the - * number of blocks, and GNU.sparse.offset/GNU.sparse.numbytes to - * store offset/size for each block. The repeated instances of these - * latter fields violate the pax specification (which frowns on - * duplicate keys), so this format was quickly replaced. - */ - -/* - * GNU tar sparse format 0.1 - * - * This version replaced the offset/numbytes attributes with - * a single "map" attribute that stored a list of integers. This - * format had two problems: First, the "map" attribute could be very - * long, which caused problems for some implementations. More - * importantly, the sparse data was lost when extracted by archivers - * that didn't recognize this extension. - */ - -static int -gnu_sparse_01_parse(struct tar *tar, const char *p) -{ - const char *e; - off_t offset = -1, size = -1; - - for (;;) { - e = p; - while (*e != '\0' && *e != ',') { - if (*e < '0' || *e > '9') - return (ARCHIVE_WARN); - e++; - } - if (offset < 0) { - offset = tar_atol10(p, e - p); - if (offset < 0) - return (ARCHIVE_WARN); - } else { - size = tar_atol10(p, e - p); - if (size < 0) - return (ARCHIVE_WARN); - gnu_add_sparse_entry(tar, offset, size); - offset = -1; - } - if (*e == '\0') - return (ARCHIVE_OK); - p = e + 1; - } -} - -/* - * GNU tar sparse format 1.0 - * - * The idea: The offset/size data is stored as a series of base-10 - * ASCII numbers prepended to the file data, so that dearchivers that - * don't support this format will extract the block map along with the - * data and a separate post-process can restore the sparseness. - * - * Unfortunately, GNU tar 1.16 had a bug that added unnecessary - * padding to the body of the file when using this format. GNU tar - * 1.17 corrected this bug without bumping the version number, so - * it's not possible to support both variants. This code supports - * the later variant at the expense of not supporting the former. - * - * This variant also replaced GNU.sparse.size with GNU.sparse.realsize - * and introduced the GNU.sparse.major/GNU.sparse.minor attributes. - */ - -/* - * Read the next line from the input, and parse it as a decimal - * integer followed by '\n'. Returns positive integer value or - * negative on error. - */ -static int64_t -gnu_sparse_10_atol(struct archive_read *a, struct tar *tar, - ssize_t *remaining) -{ - int64_t l, limit, last_digit_limit; - const char *p; - ssize_t bytes_read; - int base, digit; - - base = 10; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - /* - * Skip any lines starting with '#'; GNU tar specs - * don't require this, but they should. - */ - do { - bytes_read = readline(a, tar, &p, tar_min(*remaining, 100)); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - *remaining -= bytes_read; - } while (p[0] == '#'); - - l = 0; - while (bytes_read > 0) { - if (*p == '\n') - return (l); - if (*p < '0' || *p >= '0' + base) - return (ARCHIVE_WARN); - digit = *p - '0'; - if (l > limit || (l == limit && digit > last_digit_limit)) - l = INT64_MAX; /* Truncate on overflow. */ - else - l = (l * base) + digit; - p++; - bytes_read--; - } - /* TODO: Error message. */ - return (ARCHIVE_WARN); -} - -/* - * Returns length (in bytes) of the sparse data description - * that was read. - */ -static ssize_t -gnu_sparse_10_read(struct archive_read *a, struct tar *tar) -{ - ssize_t remaining, bytes_read; - int entries; - off_t offset, size, to_skip; - - /* Clear out the existing sparse list. */ - gnu_clear_sparse_list(tar); - - remaining = tar->entry_bytes_remaining; - - /* Parse entries. */ - entries = gnu_sparse_10_atol(a, tar, &remaining); - if (entries < 0) - return (ARCHIVE_FATAL); - /* Parse the individual entries. */ - while (entries-- > 0) { - /* Parse offset/size */ - offset = gnu_sparse_10_atol(a, tar, &remaining); - if (offset < 0) - return (ARCHIVE_FATAL); - size = gnu_sparse_10_atol(a, tar, &remaining); - if (size < 0) - return (ARCHIVE_FATAL); - /* Add a new sparse entry. */ - gnu_add_sparse_entry(tar, offset, size); - } - /* Skip rest of block... */ - bytes_read = tar->entry_bytes_remaining - remaining; - to_skip = 0x1ff & -bytes_read; - if (to_skip != __archive_read_skip(a, to_skip)) - return (ARCHIVE_FATAL); - return (bytes_read + to_skip); -} - -/*- - * Convert text->integer. - * - * Traditional tar formats (including POSIX) specify base-8 for - * all of the standard numeric fields. This is a significant limitation - * in practice: - * = file size is limited to 8GB - * = rdevmajor and rdevminor are limited to 21 bits - * = uid/gid are limited to 21 bits - * - * There are two workarounds for this: - * = pax extended headers, which use variable-length string fields - * = GNU tar and STAR both allow either base-8 or base-256 in - * most fields. The high bit is set to indicate base-256. - * - * On read, this implementation supports both extensions. - */ -static int64_t -tar_atol(const char *p, unsigned char_cnt) -{ - /* - * Technically, GNU tar considers a field to be in base-256 - * only if the first byte is 0xff or 0x80. - */ - if (*p & 0x80) - return (tar_atol256(p, char_cnt)); - return (tar_atol8(p, char_cnt)); -} - -/* - * Note that this implementation does not (and should not!) obey - * locale settings; you cannot simply substitute strtol here, since - * it does obey locale. - */ -static int64_t -tar_atol8(const char *p, unsigned char_cnt) -{ - int64_t l, limit, last_digit_limit; - int digit, sign, base; - - base = 8; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - while (*p == ' ' || *p == '\t') - p++; - if (*p == '-') { - sign = -1; - p++; - } else - sign = 1; - - l = 0; - digit = *p - '0'; - while (digit >= 0 && digit < base && char_cnt-- > 0) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (sign < 0) ? -l : l; -} - -/* - * Note that this implementation does not (and should not!) obey - * locale settings; you cannot simply substitute strtol here, since - * it does obey locale. - */ -static int64_t -tar_atol10(const char *p, unsigned char_cnt) -{ - int64_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 10; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - while (*p == ' ' || *p == '\t') - p++; - if (*p == '-') { - sign = -1; - p++; - } else - sign = 1; - - l = 0; - digit = *p - '0'; - while (digit >= 0 && digit < base && char_cnt-- > 0) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (sign < 0) ? -l : l; -} - -/* - * Parse a base-256 integer. This is just a straight signed binary - * value in big-endian order, except that the high-order bit is - * ignored. - */ -static int64_t -tar_atol256(const char *_p, unsigned char_cnt) -{ - int64_t l, upper_limit, lower_limit; - const unsigned char *p = (const unsigned char *)_p; - - upper_limit = INT64_MAX / 256; - lower_limit = INT64_MIN / 256; - - /* Pad with 1 or 0 bits, depending on sign. */ - if ((0x40 & *p) == 0x40) - l = (int64_t)-1; - else - l = 0; - l = (l << 6) | (0x3f & *p++); - while (--char_cnt > 0) { - if (l > upper_limit) { - l = INT64_MAX; /* Truncate on overflow */ - break; - } else if (l < lower_limit) { - l = INT64_MIN; - break; - } - l = (l << 8) | (0xff & (int64_t)*p++); - } - return (l); -} - -/* - * Returns length of line (including trailing newline) - * or negative on error. 'start' argument is updated to - * point to first character of line. This avoids copying - * when possible. - */ -static ssize_t -readline(struct archive_read *a, struct tar *tar, const char **start, - ssize_t limit) -{ - ssize_t bytes_read; - ssize_t total_size = 0; - const void *t; - const char *s; - void *p; - - t = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - s = t; /* Start of line? */ - p = memchr(t, '\n', bytes_read); - /* If we found '\n' in the read buffer, return pointer to that. */ - if (p != NULL) { - bytes_read = 1 + ((const char *)p) - s; - if (bytes_read > limit) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Line too long"); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, bytes_read); - *start = s; - return (bytes_read); - } - /* Otherwise, we need to accumulate in a line buffer. */ - for (;;) { - if (total_size + bytes_read > limit) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Line too long"); - return (ARCHIVE_FATAL); - } - if (archive_string_ensure(&tar->line, total_size + bytes_read) == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate working buffer"); - return (ARCHIVE_FATAL); - } - memcpy(tar->line.s + total_size, t, bytes_read); - __archive_read_consume(a, bytes_read); - total_size += bytes_read; - /* If we found '\n', clean up and return. */ - if (p != NULL) { - *start = tar->line.s; - return (total_size); - } - /* Read some more. */ - t = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - s = t; /* Start of line? */ - p = memchr(t, '\n', bytes_read); - /* If we found '\n', trim the read. */ - if (p != NULL) { - bytes_read = 1 + ((const char *)p) - s; - } - } -} - -static wchar_t * -utf8_decode(struct tar *tar, const char *src, size_t length) -{ - wchar_t *dest; - ssize_t n; - - /* Ensure pax_entry buffer is big enough. */ - if (tar->pax_entry_length <= length) { - wchar_t *old_entry; - - if (tar->pax_entry_length <= 0) - tar->pax_entry_length = 1024; - while (tar->pax_entry_length <= length + 1) - tar->pax_entry_length *= 2; - - old_entry = tar->pax_entry; - tar->pax_entry = (wchar_t *)realloc(tar->pax_entry, - tar->pax_entry_length * sizeof(wchar_t)); - if (tar->pax_entry == NULL) { - free(old_entry); - /* TODO: Handle this error. */ - return (NULL); - } - } - - dest = tar->pax_entry; - while (length > 0) { - n = UTF8_mbrtowc(dest, src, length); - if (n < 0) - return (NULL); - if (n == 0) - break; - dest++; - src += n; - length -= n; - } - *dest = L'\0'; - return (tar->pax_entry); -} - -/* - * Copied and simplified from FreeBSD libc/locale. - */ -static ssize_t -UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n) -{ - int ch, i, len, mask; - unsigned long wch; - - if (s == NULL || n == 0 || pwc == NULL) - return (0); - - /* - * Determine the number of octets that make up this character from - * the first octet, and a mask that extracts the interesting bits of - * the first octet. - */ - ch = (unsigned char)*s; - if ((ch & 0x80) == 0) { - mask = 0x7f; - len = 1; - } else if ((ch & 0xe0) == 0xc0) { - mask = 0x1f; - len = 2; - } else if ((ch & 0xf0) == 0xe0) { - mask = 0x0f; - len = 3; - } else if ((ch & 0xf8) == 0xf0) { - mask = 0x07; - len = 4; - } else { - /* Invalid first byte. */ - return (-1); - } - - if (n < (size_t)len) { - /* Valid first byte but truncated. */ - return (-2); - } - - /* - * Decode the octet sequence representing the character in chunks - * of 6 bits, most significant first. - */ - wch = (unsigned char)*s++ & mask; - i = len; - while (--i != 0) { - if ((*s & 0xc0) != 0x80) { - /* Invalid intermediate byte; consume one byte and - * emit '?' */ - *pwc = '?'; - return (1); - } - wch <<= 6; - wch |= *s++ & 0x3f; - } - - /* Assign the value to the output; out-of-range values - * just get truncated. */ - *pwc = (wchar_t)wch; -#ifdef WCHAR_MAX - /* - * If platform has WCHAR_MAX, we can do something - * more sensible with out-of-range values. - */ - if (wch >= WCHAR_MAX) - *pwc = '?'; -#endif - /* Return number of bytes input consumed: 0 for end-of-string. */ - return (wch == L'\0' ? 0 : len); -} - - -/* - * base64_decode - Base64 decode - * - * This accepts most variations of base-64 encoding, including: - * * with or without line breaks - * * with or without the final group padded with '=' or '_' characters - * (The most economical Base-64 variant does not pad the last group and - * omits line breaks; RFC1341 used for MIME requires both.) - */ -static char * -base64_decode(const char *s, size_t len, size_t *out_len) -{ - static const unsigned char digits[64] = { - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N', - 'O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b', - 'c','d','e','f','g','h','i','j','k','l','m','n','o','p', - 'q','r','s','t','u','v','w','x','y','z','0','1','2','3', - '4','5','6','7','8','9','+','/' }; - static unsigned char decode_table[128]; - char *out, *d; - const unsigned char *src = (const unsigned char *)s; - - /* If the decode table is not yet initialized, prepare it. */ - if (decode_table[digits[1]] != 1) { - unsigned i; - memset(decode_table, 0xff, sizeof(decode_table)); - for (i = 0; i < sizeof(digits); i++) - decode_table[digits[i]] = i; - } - - /* Allocate enough space to hold the entire output. */ - /* Note that we may not use all of this... */ - out = (char *)malloc(len - len / 4 + 1); - if (out == NULL) { - *out_len = 0; - return (NULL); - } - d = out; - - while (len > 0) { - /* Collect the next group of (up to) four characters. */ - int v = 0; - int group_size = 0; - while (group_size < 4 && len > 0) { - /* '=' or '_' padding indicates final group. */ - if (*src == '=' || *src == '_') { - len = 0; - break; - } - /* Skip illegal characters (including line breaks) */ - if (*src > 127 || *src < 32 - || decode_table[*src] == 0xff) { - len--; - src++; - continue; - } - v <<= 6; - v |= decode_table[*src++]; - len --; - group_size++; - } - /* Align a short group properly. */ - v <<= 6 * (4 - group_size); - /* Unpack the group we just collected. */ - switch (group_size) { - case 4: d[2] = v & 0xff; - /* FALLTHROUGH */ - case 3: d[1] = (v >> 8) & 0xff; - /* FALLTHROUGH */ - case 2: d[0] = (v >> 16) & 0xff; - break; - case 1: /* this is invalid! */ - break; - } - d += group_size * 3 / 4; - } - - *out_len = d - out; - return (out); -} - -static char * -url_decode(const char *in) -{ - char *out, *d; - const char *s; - - out = (char *)malloc(strlen(in) + 1); - if (out == NULL) - return (NULL); - for (s = in, d = out; *s != '\0'; ) { - if (s[0] == '%' && s[1] != '\0' && s[2] != '\0') { - /* Try to convert % escape */ - int digit1 = tohex(s[1]); - int digit2 = tohex(s[2]); - if (digit1 >= 0 && digit2 >= 0) { - /* Looks good, consume three chars */ - s += 3; - /* Convert output */ - *d++ = ((digit1 << 4) | digit2); - continue; - } - /* Else fall through and treat '%' as normal char */ - } - *d++ = *s++; - } - *d = '\0'; - return (out); -} - -static int -tohex(int c) -{ - if (c >= '0' && c <= '9') - return (c - '0'); - else if (c >= 'A' && c <= 'F') - return (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - return (c - 'a' + 10); - else - return (-1); -} diff --git a/lib/libarchive/archive_read_support_format_xar.c b/lib/libarchive/archive_read_support_format_xar.c deleted file mode 100644 index 7194fa5..0000000 --- a/lib/libarchive/archive_read_support_format_xar.c +++ /dev/null @@ -1,3151 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#if HAVE_LIBXML_XMLREADER_H -#include -#elif HAVE_BSDXML_H -#include -#elif HAVE_EXPAT_H -#include -#endif -#ifdef HAVE_BZLIB_H -#include -#endif -#if HAVE_LZMA_H -#include -#elif HAVE_LZMADEC_H -#include -#endif -#ifdef HAVE_ZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_endian.h" -#include "archive_entry.h" -#include "archive_hash.h" -#include "archive_private.h" -#include "archive_read_private.h" - -#if (!defined(HAVE_LIBXML_XMLREADER_H) && \ - !defined(HAVE_BSDXML_H) && !defined(HAVE_EXPAT_H)) ||\ - !defined(HAVE_ZLIB_H) || \ - !defined(ARCHIVE_HAS_MD5) || !defined(ARCHIVE_HAS_SHA1) -/* - * xar needs several external libraries. - * o libxml2 or expat --- XML parser - * o openssl or MD5/SHA1 hash function - * o zlib - * o bzlib2 (option) - * o liblzma (option) - */ -int -archive_read_support_format_xar(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Xar not supported on this platform"); - return (ARCHIVE_WARN); -} - -#else /* Support xar format */ - -//#define DEBUG 1 -//#define DEBUG_PRINT_TOC 1 -#if DEBUG_PRINT_TOC -#define PRINT_TOC(d, outbytes) do { \ - unsigned char *x = (unsigned char *)(uintptr_t)d; \ - unsigned char c = x[outbytes-1]; \ - x[outbytes - 1] = 0; \ - fprintf(stderr, "%s", x); \ - fprintf(stderr, "%c", c); \ - x[outbytes - 1] = c; \ -} while (0) -#else -#define PRINT_TOC(d, outbytes) -#endif - -#define HEADER_MAGIC 0x78617221 -#define HEADER_SIZE 28 -#define HEADER_VERSION 1 -#define CKSUM_NONE 0 -#define CKSUM_SHA1 1 -#define CKSUM_MD5 2 - -#define MD5_SIZE 16 -#define SHA1_SIZE 20 -#define MAX_SUM_SIZE 20 - -enum enctype { - NONE, - GZIP, - BZIP2, - LZMA, - XZ, -}; - -struct chksumval { - int alg; - size_t len; - unsigned char val[MAX_SUM_SIZE]; -}; - -struct chksumwork { - int alg; -#ifdef ARCHIVE_HAS_MD5 - archive_md5_ctx md5ctx; -#endif -#ifdef ARCHIVE_HAS_SHA1 - archive_sha1_ctx sha1ctx; -#endif -}; - -struct xattr { - struct xattr *next; - struct archive_string name; - uint64_t id; - uint64_t length; - uint64_t offset; - uint64_t size; - enum enctype encoding; - struct chksumval a_sum; - struct chksumval e_sum; - struct archive_string fstype; -}; - -struct xar_file { - struct xar_file *next; - struct xar_file *hdnext; - struct xar_file *parent; - int subdirs; - - unsigned int has; -#define HAS_DATA 0x00001 -#define HAS_PATHNAME 0x00002 -#define HAS_SYMLINK 0x00004 -#define HAS_TIME 0x00008 -#define HAS_UID 0x00010 -#define HAS_GID 0x00020 -#define HAS_MODE 0x00040 -#define HAS_TYPE 0x00080 -#define HAS_DEV 0x00100 -#define HAS_DEVMAJOR 0x00200 -#define HAS_DEVMINOR 0x00400 -#define HAS_INO 0x00800 -#define HAS_FFLAGS 0x01000 -#define HAS_XATTR 0x02000 -#define HAS_ACL 0x04000 - - uint64_t id; - uint64_t length; - uint64_t offset; - uint64_t size; - enum enctype encoding; - struct chksumval a_sum; - struct chksumval e_sum; - struct archive_string pathname; - struct archive_string symlink; - time_t ctime; - time_t mtime; - time_t atime; - struct archive_string uname; - uid_t uid; - struct archive_string gname; - gid_t gid; - mode_t mode; - dev_t dev; - dev_t devmajor; - dev_t devminor; - int64_t ino64; - struct archive_string fflags_text; - unsigned int link; - unsigned int nlink; - struct archive_string hardlink; - struct xattr *xattr_list; -}; - -struct hdlink { - struct hdlink *next; - - unsigned int id; - int cnt; - struct xar_file *files; -}; - -struct heap_queue { - struct xar_file **files; - int allocated; - int used; -}; - -enum xmlstatus { - INIT, - XAR, - TOC, - TOC_CREATION_TIME, - TOC_CHECKSUM, - TOC_CHECKSUM_OFFSET, - TOC_CHECKSUM_SIZE, - TOC_FILE, - FILE_DATA, - FILE_DATA_LENGTH, - FILE_DATA_OFFSET, - FILE_DATA_SIZE, - FILE_DATA_ENCODING, - FILE_DATA_A_CHECKSUM, - FILE_DATA_E_CHECKSUM, - FILE_DATA_CONTENT, - FILE_EA, - FILE_EA_LENGTH, - FILE_EA_OFFSET, - FILE_EA_SIZE, - FILE_EA_ENCODING, - FILE_EA_A_CHECKSUM, - FILE_EA_E_CHECKSUM, - FILE_EA_NAME, - FILE_EA_FSTYPE, - FILE_CTIME, - FILE_MTIME, - FILE_ATIME, - FILE_GROUP, - FILE_GID, - FILE_USER, - FILE_UID, - FILE_MODE, - FILE_DEVICE, - FILE_DEVICE_MAJOR, - FILE_DEVICE_MINOR, - FILE_DEVICENO, - FILE_INODE, - FILE_LINK, - FILE_TYPE, - FILE_NAME, - FILE_ACL, - FILE_ACL_DEFAULT, - FILE_ACL_ACCESS, - FILE_ACL_APPLEEXTENDED, - /* BSD file flags. */ - FILE_FLAGS, - FILE_FLAGS_USER_NODUMP, - FILE_FLAGS_USER_IMMUTABLE, - FILE_FLAGS_USER_APPEND, - FILE_FLAGS_USER_OPAQUE, - FILE_FLAGS_USER_NOUNLINK, - FILE_FLAGS_SYS_ARCHIVED, - FILE_FLAGS_SYS_IMMUTABLE, - FILE_FLAGS_SYS_APPEND, - FILE_FLAGS_SYS_NOUNLINK, - FILE_FLAGS_SYS_SNAPSHOT, - /* Linux file flags. */ - FILE_EXT2, - FILE_EXT2_SecureDeletion, - FILE_EXT2_Undelete, - FILE_EXT2_Compress, - FILE_EXT2_Synchronous, - FILE_EXT2_Immutable, - FILE_EXT2_AppendOnly, - FILE_EXT2_NoDump, - FILE_EXT2_NoAtime, - FILE_EXT2_CompDirty, - FILE_EXT2_CompBlock, - FILE_EXT2_NoCompBlock, - FILE_EXT2_CompError, - FILE_EXT2_BTree, - FILE_EXT2_HashIndexed, - FILE_EXT2_iMagic, - FILE_EXT2_Journaled, - FILE_EXT2_NoTail, - FILE_EXT2_DirSync, - FILE_EXT2_TopDir, - FILE_EXT2_Reserved, - UNKNOWN, -}; - -struct unknown_tag { - struct unknown_tag *next; - struct archive_string name; -}; - -struct xar { - uint64_t offset; /* Current position in the file. */ - int64_t total; - uint64_t h_base; - int end_of_file; - unsigned char buff[1024*32]; - - enum xmlstatus xmlsts; - enum xmlstatus xmlsts_unknown; - struct unknown_tag *unknowntags; - int base64text; - - /* - * TOC - */ - uint64_t toc_remaining; - uint64_t toc_total; - uint64_t toc_chksum_offset; - uint64_t toc_chksum_size; - - /* - * For Decoding data. - */ - enum enctype rd_encoding; - z_stream stream; - int stream_valid; -#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) - bz_stream bzstream; - int bzstream_valid; -#endif -#if HAVE_LZMA_H && HAVE_LIBLZMA - lzma_stream lzstream; - int lzstream_valid; -#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC - lzmadec_stream lzstream; - int lzstream_valid; -#endif - /* - * For Checksum data. - */ - struct chksumwork a_sumwrk; - struct chksumwork e_sumwrk; - - struct xar_file *file; /* current reading file. */ - struct xattr *xattr; /* current reading extended attribute. */ - struct heap_queue file_queue; - struct xar_file *hdlink_orgs; - struct hdlink *hdlink_list; - - int entry_init; - uint64_t entry_total; - uint64_t entry_remaining; - uint64_t entry_size; - enum enctype entry_encoding; - struct chksumval entry_a_sum; - struct chksumval entry_e_sum; -}; - -struct xmlattr { - struct xmlattr *next; - char *name; - char *value; -}; - -struct xmlattr_list { - struct xmlattr *first; - struct xmlattr **last; -}; - -static int xar_bid(struct archive_read *); -static int xar_read_header(struct archive_read *, - struct archive_entry *); -static int xar_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int xar_read_data_skip(struct archive_read *); -static int xar_cleanup(struct archive_read *); -static int move_reading_point(struct archive_read *, uint64_t); -static int rd_contents_init(struct archive_read *, - enum enctype, int, int); -static int rd_contents(struct archive_read *, const void **, - size_t *, size_t *, uint64_t); -static uint64_t atol10(const char *, size_t); -static int64_t atol8(const char *, size_t); -static size_t atohex(unsigned char *, size_t, const char *, size_t); -static time_t parse_time(const char *p, size_t n); -static void heap_add_entry(struct heap_queue *, struct xar_file *); -static struct xar_file *heap_get_entry(struct heap_queue *); -static void add_link(struct xar *, struct xar_file *); -static void checksum_init(struct archive_read *, int, int); -static void checksum_update(struct archive_read *, const void *, - size_t, const void *, size_t); -static int checksum_final(struct archive_read *, const void *, - size_t, const void *, size_t); -static int decompression_init(struct archive_read *, enum enctype); -static int decompress(struct archive_read *, const void **, - size_t *, const void *, size_t *); -static int decompression_cleanup(struct archive_read *); -static void xmlattr_cleanup(struct xmlattr_list *); -static void file_new(struct xar *, struct xmlattr_list *); -static void file_free(struct xar_file *); -static void xattr_new(struct xar *, struct xmlattr_list *); -static void xattr_free(struct xattr *); -static int getencoding(struct xmlattr_list *); -static int getsumalgorithm(struct xmlattr_list *); -static void unknowntag_start(struct xar *, const char *); -static void unknowntag_end(struct xar *, const char *); -static void xml_start(void *, const char *, struct xmlattr_list *); -static void xml_end(void *, const char *); -static void xml_data(void *, const char *, int); -static int xml_parse_file_flags(struct xar *, const char *); -static int xml_parse_file_ext2(struct xar *, const char *); -#if defined(HAVE_LIBXML_XMLREADER_H) -static int xml2_xmlattr_setup(struct xmlattr_list *, xmlTextReaderPtr); -static int xml2_read_cb(void *, char *, int); -static int xml2_close_cb(void *); -static void xml2_error_hdr(void *, const char *, xmlParserSeverities, - xmlTextReaderLocatorPtr); -static int xml2_read_toc(struct archive_read *); -#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) -static void expat_xmlattr_setup(struct xmlattr_list *, const XML_Char **); -static void expat_start_cb(void *, const XML_Char *, const XML_Char **); -static void expat_end_cb(void *, const XML_Char *); -static void expat_data_cb(void *, const XML_Char *, int); -static int expat_read_toc(struct archive_read *); -#endif - -int -archive_read_support_format_xar(struct archive *_a) -{ - struct xar *xar; - struct archive_read *a = (struct archive_read *)_a; - int r; - - xar = (struct xar *)calloc(1, sizeof(*xar)); - if (xar == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate xar data"); - return (ARCHIVE_FATAL); - } - - r = __archive_read_register_format(a, - xar, - "xar", - xar_bid, - NULL, - xar_read_header, - xar_read_data, - xar_read_data_skip, - xar_cleanup); - if (r != ARCHIVE_OK) - free(xar); - return (r); -} - -static int -xar_bid(struct archive_read *a) -{ - const unsigned char *b; - int bid; - - b = __archive_read_ahead(a, HEADER_SIZE, NULL); - if (b == NULL) - return (-1); - - bid = 0; - /* - * Verify magic code - */ - if (archive_be32dec(b) != HEADER_MAGIC) - return (0); - bid += 32; - /* - * Verify header size - */ - if (archive_be16dec(b+4) != HEADER_SIZE) - return (0); - bid += 16; - /* - * Verify header version - */ - if (archive_be16dec(b+6) != HEADER_VERSION) - return (0); - bid += 16; - /* - * Verify type of checksum - */ - switch (archive_be32dec(b+24)) { - case CKSUM_NONE: - case CKSUM_SHA1: - case CKSUM_MD5: - bid += 32; - break; - default: - return (0); - } - - return (bid); -} - -static int -read_toc(struct archive_read *a) -{ - struct xar *xar; - struct xar_file *file; - const unsigned char *b; - uint64_t toc_compressed_size; - uint64_t toc_uncompressed_size; - uint32_t toc_chksum_alg; - ssize_t bytes; - int r; - - xar = (struct xar *)(a->format->data); - - /* - * Read xar header. - */ - b = __archive_read_ahead(a, HEADER_SIZE, &bytes); - if (bytes < 0) - return ((int)bytes); - if (bytes < HEADER_SIZE) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated archive header"); - return (ARCHIVE_FATAL); - } - - if (archive_be32dec(b) != HEADER_MAGIC) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Invalid header magic"); - return (ARCHIVE_FATAL); - } - if (archive_be16dec(b+6) != HEADER_VERSION) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Unsupported header version(%d)", - archive_be16dec(b+6)); - return (ARCHIVE_FATAL); - } - toc_compressed_size = archive_be64dec(b+8); - xar->toc_remaining = toc_compressed_size; - toc_uncompressed_size = archive_be64dec(b+16); - toc_chksum_alg = archive_be32dec(b+24); - __archive_read_consume(a, HEADER_SIZE); - xar->offset += HEADER_SIZE; - xar->toc_total = 0; - - /* - * Read TOC(Table of Contents). - */ - /* Initialize reading contents. */ - r = move_reading_point(a, HEADER_SIZE); - if (r != ARCHIVE_OK) - return (r); - r = rd_contents_init(a, GZIP, toc_chksum_alg, CKSUM_NONE); - if (r != ARCHIVE_OK) - return (r); - -#ifdef HAVE_LIBXML_XMLREADER_H - r = xml2_read_toc(a); -#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) - r = expat_read_toc(a); -#endif - if (r != ARCHIVE_OK) - return (r); - - /* Set 'The HEAP' base. */ - xar->h_base = xar->offset; - if (xar->toc_total != toc_uncompressed_size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "TOC uncompressed size error"); - return (ARCHIVE_FATAL); - } - - /* - * Checksum TOC - */ - if (toc_chksum_alg != CKSUM_NONE) { - r = move_reading_point(a, xar->toc_chksum_offset); - if (r != ARCHIVE_OK) - return (r); - b = __archive_read_ahead(a, xar->toc_chksum_size, &bytes); - if (bytes < 0) - return ((int)bytes); - if ((uint64_t)bytes < xar->toc_chksum_size) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated archive file"); - return (ARCHIVE_FATAL); - } - r = checksum_final(a, b, xar->toc_chksum_size, NULL, 0); - __archive_read_consume(a, xar->toc_chksum_size); - xar->offset += xar->toc_chksum_size; - if (r != ARCHIVE_OK) - return (ARCHIVE_FATAL); - } - - /* - * Connect hardlinked files. - */ - for (file = xar->hdlink_orgs; file != NULL; file = file->hdnext) { - struct hdlink **hdlink; - - for (hdlink = &(xar->hdlink_list); *hdlink != NULL; - hdlink = &((*hdlink)->next)) { - if ((*hdlink)->id == file->id) { - struct hdlink *hltmp; - struct xar_file *f2; - int nlink = (*hdlink)->cnt + 1; - - file->nlink = nlink; - for (f2 = (*hdlink)->files; f2 != NULL; - f2 = f2->hdnext) { - f2->nlink = nlink; - archive_string_copy( - &(f2->hardlink), &(file->pathname)); - } - /* Remove resolved files from hdlist_list. */ - hltmp = *hdlink; - *hdlink = hltmp->next; - free(hltmp); - break; - } - } - } - a->archive.archive_format = ARCHIVE_FORMAT_XAR; - a->archive.archive_format_name = "xar"; - - return (ARCHIVE_OK); -} - -static int -xar_read_header(struct archive_read *a, struct archive_entry *entry) -{ - struct xar *xar; - struct xar_file *file; - struct xattr *xattr; - int r; - - xar = (struct xar *)(a->format->data); - - if (xar->offset == 0) { - /* Read TOC. */ - r = read_toc(a); - if (r != ARCHIVE_OK) - return (r); - } - - for (;;) { - file = xar->file = heap_get_entry(&(xar->file_queue)); - if (file == NULL) { - xar->end_of_file = 1; - return (ARCHIVE_EOF); - } - if ((file->mode & AE_IFMT) != AE_IFDIR) - break; - if (file->has != (HAS_PATHNAME | HAS_TYPE)) - break; - /* - * If a file type is a directory and it does not have - * any metadata, do not export. - */ - file_free(file); - } - archive_entry_set_atime(entry, file->atime, 0); - archive_entry_set_ctime(entry, file->ctime, 0); - archive_entry_set_mtime(entry, file->mtime, 0); - archive_entry_set_gid(entry, file->gid); - if (file->gname.length > 0) - archive_entry_update_gname_utf8(entry, file->gname.s); - archive_entry_set_uid(entry, file->uid); - if (file->uname.length > 0) - archive_entry_update_uname_utf8(entry, file->uname.s); - archive_entry_set_mode(entry, file->mode); - archive_entry_update_pathname_utf8(entry, file->pathname.s); - if (file->symlink.length > 0) - archive_entry_update_symlink_utf8(entry, file->symlink.s); - /* Set proper nlink. */ - if ((file->mode & AE_IFMT) == AE_IFDIR) - archive_entry_set_nlink(entry, file->subdirs + 2); - else - archive_entry_set_nlink(entry, file->nlink); - archive_entry_set_size(entry, file->size); - if (archive_strlen(&(file->hardlink)) > 0) - archive_entry_update_hardlink_utf8(entry, - file->hardlink.s); - archive_entry_set_ino64(entry, file->ino64); - if (file->has & HAS_DEV) - archive_entry_set_dev(entry, file->dev); - if (file->has & HAS_DEVMAJOR) - archive_entry_set_devmajor(entry, file->devmajor); - if (file->has & HAS_DEVMINOR) - archive_entry_set_devminor(entry, file->devminor); - if (archive_strlen(&(file->fflags_text)) > 0) - archive_entry_copy_fflags_text(entry, file->fflags_text.s); - - xar->entry_init = 1; - xar->entry_total = 0; - xar->entry_remaining = file->length; - xar->entry_size = file->size; - xar->entry_encoding = file->encoding; - xar->entry_a_sum = file->a_sum; - xar->entry_e_sum = file->e_sum; - /* - * Read extended attributes. - */ - r = ARCHIVE_OK; - xattr = file->xattr_list; - while (xattr != NULL) { - const void *d; - size_t outbytes, used; - - r = move_reading_point(a, xattr->offset); - if (r != ARCHIVE_OK) - break; - r = rd_contents_init(a, xattr->encoding, - xattr->a_sum.alg, xattr->e_sum.alg); - if (r != ARCHIVE_OK) - break; - d = NULL; - r = rd_contents(a, &d, &outbytes, &used, xattr->length); - if (r != ARCHIVE_OK) - break; - if (outbytes != xattr->size) { - archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, - "Decompressed size error"); - r = ARCHIVE_FATAL; - break; - } - r = checksum_final(a, - xattr->a_sum.val, xattr->a_sum.len, - xattr->e_sum.val, xattr->e_sum.len); - if (r != ARCHIVE_OK) - break; - archive_entry_xattr_add_entry(entry, - xattr->name.s, d, outbytes); - xattr = xattr->next; - } - if (r != ARCHIVE_OK) { - file_free(file); - return (r); - } - - if (xar->entry_remaining > 0) - /* Move reading point to the beginning of current - * file contents. */ - r = move_reading_point(a, file->offset); - else - r = ARCHIVE_OK; - - file_free(file); - return (r); -} - -static int -xar_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - struct xar *xar; - size_t used; - int r; - - xar = (struct xar *)(a->format->data); - if (xar->end_of_file || xar->entry_remaining <= 0) { - r = ARCHIVE_EOF; - goto abort_read_data; - } - - if (xar->entry_init) { - r = rd_contents_init(a, xar->entry_encoding, - xar->entry_a_sum.alg, xar->entry_e_sum.alg); - if (r != ARCHIVE_OK) { - xar->entry_remaining = 0; - return (r); - } - xar->entry_init = 0; - } - - *buff = NULL; - r = rd_contents(a, buff, size, &used, xar->entry_remaining); - if (r != ARCHIVE_OK) - goto abort_read_data; - - *offset = xar->entry_total; - xar->entry_total += *size; - xar->total += *size; - xar->offset += used; - xar->entry_remaining -= used; - __archive_read_consume(a, used); - - if (xar->entry_remaining == 0) { - if (xar->entry_total != xar->entry_size) { - archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, - "Decompressed size error"); - r = ARCHIVE_FATAL; - goto abort_read_data; - } - r = checksum_final(a, - xar->entry_a_sum.val, xar->entry_a_sum.len, - xar->entry_e_sum.val, xar->entry_e_sum.len); - if (r != ARCHIVE_OK) - goto abort_read_data; - } - - return (ARCHIVE_OK); -abort_read_data: - *buff = NULL; - *size = 0; - *offset = xar->total; - return (r); -} - -static int -xar_read_data_skip(struct archive_read *a) -{ - struct xar *xar; - int64_t bytes_skipped; - - xar = (struct xar *)(a->format->data); - if (xar->end_of_file) - return (ARCHIVE_EOF); - bytes_skipped = __archive_read_skip(a, xar->entry_remaining); - if (bytes_skipped < 0) - return (ARCHIVE_FATAL); - xar->offset += bytes_skipped; - return (ARCHIVE_OK); -} - -static int -xar_cleanup(struct archive_read *a) -{ - struct xar *xar; - struct hdlink *hdlink; - int i; - int r; - - xar = (struct xar *)(a->format->data); - r = decompression_cleanup(a); - hdlink = xar->hdlink_list; - while (hdlink != NULL) { - struct hdlink *next = hdlink->next; - - free(hdlink); - hdlink = next; - } - for (i = 0; i < xar->file_queue.used; i++) - file_free(xar->file_queue.files[i]); - while (xar->unknowntags != NULL) { - struct unknown_tag *tag; - - tag = xar->unknowntags; - xar->unknowntags = tag->next; - archive_string_free(&(tag->name)); - free(tag); - } - free(xar); - a->format->data = NULL; - return (r); -} - -static int -move_reading_point(struct archive_read *a, uint64_t offset) -{ - struct xar *xar; - - xar = (struct xar *)(a->format->data); - if (xar->offset - xar->h_base != offset) { - /* Seek forward to the start of file contents. */ - int64_t step; - - step = offset - (xar->offset - xar->h_base); - if (step > 0) { - step = __archive_read_skip(a, step); - if (step < 0) - return ((int)step); - xar->offset += step; - } else { - archive_set_error(&(a->archive), - ARCHIVE_ERRNO_MISC, - "Cannot seek."); - return (ARCHIVE_FAILED); - } - } - return (ARCHIVE_OK); -} - -static int -rd_contents_init(struct archive_read *a, enum enctype encoding, - int a_sum_alg, int e_sum_alg) -{ - int r; - - /* Init decompress library. */ - if ((r = decompression_init(a, encoding)) != ARCHIVE_OK) - return (r); - /* Init checksum library. */ - checksum_init(a, a_sum_alg, e_sum_alg); - return (ARCHIVE_OK); -} - -static int -rd_contents(struct archive_read *a, const void **buff, size_t *size, - size_t *used, uint64_t remaining) -{ - const unsigned char *b; - ssize_t bytes; - - /* Get whatever bytes are immediately available. */ - b = __archive_read_ahead(a, 1, &bytes); - if (bytes < 0) - return ((int)bytes); - if (bytes == 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated archive file"); - return (ARCHIVE_FATAL); - } - if ((uint64_t)bytes > remaining) - bytes = (ssize_t)remaining; - - /* - * Decompress contents of file. - */ - *used = bytes; - if (decompress(a, buff, size, b, used) != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - /* - * Update checksum of a compressed data and a extracted data. - */ - checksum_update(a, b, *used, *buff, *size); - - return (ARCHIVE_OK); -} - -/* - * Note that this implementation does not (and should not!) obey - * locale settings; you cannot simply substitute strtol here, since - * it does obey locale. - */ - -static uint64_t -atol10(const char *p, size_t char_cnt) -{ - uint64_t l; - int digit; - - l = 0; - digit = *p - '0'; - while (digit >= 0 && digit < 10 && char_cnt-- > 0) { - l = (l * 10) + digit; - digit = *++p - '0'; - } - return (l); -} - -static int64_t -atol8(const char *p, size_t char_cnt) -{ - int64_t l; - int digit; - - l = 0; - while (char_cnt-- > 0) { - if (*p >= '0' && *p <= '7') - digit = *p - '0'; - else - break; - p++; - l <<= 3; - l |= digit; - } - return (l); -} - -static size_t -atohex(unsigned char *b, size_t bsize, const char *p, size_t psize) -{ - size_t fbsize = bsize; - - while (bsize && psize > 1) { - unsigned char x; - - if (p[0] >= 'a' && p[0] <= 'z') - x = (p[0] - 'a' + 0x0a) << 4; - else if (p[0] >= 'A' && p[0] <= 'Z') - x = (p[0] - 'A' + 0x0a) << 4; - else if (p[0] >= '0' && p[0] <= '9') - x = (p[0] - '0') << 4; - else - return (-1); - if (p[1] >= 'a' && p[1] <= 'z') - x |= p[1] - 'a' + 0x0a; - else if (p[1] >= 'A' && p[1] <= 'Z') - x |= p[1] - 'A' + 0x0a; - else if (p[1] >= '0' && p[1] <= '9') - x |= p[1] - '0'; - else - return (-1); - - *b++ = x; - bsize--; - p += 2; - psize -= 2; - } - return (fbsize - bsize); -} - -static time_t -time_from_tm(struct tm *t) -{ -#if HAVE_TIMEGM - /* Use platform timegm() if available. */ - return (timegm(t)); -#else - /* Else use direct calculation using POSIX assumptions. */ - /* First, fix up tm_yday based on the year/month/day. */ - mktime(t); - /* Then we can compute timegm() from first principles. */ - return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600 - + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000 - + ((t->tm_year - 69) / 4) * 86400 - - ((t->tm_year - 1) / 100) * 86400 - + ((t->tm_year + 299) / 400) * 86400); -#endif -} - -static time_t -parse_time(const char *p, size_t n) -{ - struct tm tm; - time_t t = 0; - int64_t data; - - memset(&tm, 0, sizeof(tm)); - if (n != 20) - return (t); - data = atol10(p, 4); - if (data < 1900) - return (t); - tm.tm_year = (int)data - 1900; - p += 4; - if (*p++ != '-') - return (t); - data = atol10(p, 2); - if (data < 1 || data > 12) - return (t); - tm.tm_mon = (int)data -1; - p += 2; - if (*p++ != '-') - return (t); - data = atol10(p, 2); - if (data < 1 || data > 31) - return (t); - tm.tm_mday = (int)data; - p += 2; - if (*p++ != 'T') - return (t); - data = atol10(p, 2); - if (data < 0 || data > 23) - return (t); - tm.tm_hour = (int)data; - p += 2; - if (*p++ != ':') - return (t); - data = atol10(p, 2); - if (data < 0 || data > 59) - return (t); - tm.tm_min = (int)data; - p += 2; - if (*p++ != ':') - return (t); - data = atol10(p, 2); - if (data < 0 || data > 60) - return (t); - tm.tm_sec = (int)data; -#if 0 - p += 2; - if (*p != 'Z') - return (t); -#endif - - t = time_from_tm(&tm); - - return (t); -} - -static void -heap_add_entry(struct heap_queue *heap, struct xar_file *file) -{ - uint64_t file_id, parent_id; - int hole, parent; - - /* Expand our pending files list as necessary. */ - if (heap->used >= heap->allocated) { - struct xar_file **new_pending_files; - int new_size = heap->allocated * 2; - - if (heap->allocated < 1024) - new_size = 1024; - /* Overflow might keep us from growing the list. */ - if (new_size <= heap->allocated) - __archive_errx(1, "Out of memory"); - new_pending_files = (struct xar_file **) - malloc(new_size * sizeof(new_pending_files[0])); - if (new_pending_files == NULL) - __archive_errx(1, "Out of memory"); - memcpy(new_pending_files, heap->files, - heap->allocated * sizeof(new_pending_files[0])); - if (heap->files != NULL) - free(heap->files); - heap->files = new_pending_files; - heap->allocated = new_size; - } - - file_id = file->id; - - /* - * Start with hole at end, walk it up tree to find insertion point. - */ - hole = heap->used++; - while (hole > 0) { - parent = (hole - 1)/2; - parent_id = heap->files[parent]->id; - if (file_id >= parent_id) { - heap->files[hole] = file; - return; - } - // Move parent into hole <==> move hole up tree. - heap->files[hole] = heap->files[parent]; - hole = parent; - } - heap->files[0] = file; -} - -static struct xar_file * -heap_get_entry(struct heap_queue *heap) -{ - uint64_t a_id, b_id, c_id; - int a, b, c; - struct xar_file *r, *tmp; - - if (heap->used < 1) - return (NULL); - - /* - * The first file in the list is the earliest; we'll return this. - */ - r = heap->files[0]; - - /* - * Move the last item in the heap to the root of the tree - */ - heap->files[0] = heap->files[--(heap->used)]; - - /* - * Rebalance the heap. - */ - a = 0; // Starting element and its heap key - a_id = heap->files[a]->id; - for (;;) { - b = a + a + 1; // First child - if (b >= heap->used) - return (r); - b_id = heap->files[b]->id; - c = b + 1; // Use second child if it is smaller. - if (c < heap->used) { - c_id = heap->files[c]->id; - if (c_id < b_id) { - b = c; - b_id = c_id; - } - } - if (a_id <= b_id) - return (r); - tmp = heap->files[a]; - heap->files[a] = heap->files[b]; - heap->files[b] = tmp; - a = b; - } -} - -static void -add_link(struct xar *xar, struct xar_file *file) -{ - struct hdlink *hdlink; - - for (hdlink = xar->hdlink_list; hdlink != NULL; hdlink = hdlink->next) { - if (hdlink->id == file->link) { - file->hdnext = hdlink->files; - hdlink->cnt++; - hdlink->files = file; - return; - } - } - hdlink = malloc(sizeof(*hdlink)); - if (hdlink == NULL) - __archive_errx(1, "No memory for add_link()"); - file->hdnext = NULL; - hdlink->id = file->link; - hdlink->cnt = 1; - hdlink->files = file; - hdlink->next = xar->hdlink_list; - xar->hdlink_list = hdlink; -} - -static void -_checksum_init(struct chksumwork *sumwrk, int sum_alg) -{ - sumwrk->alg = sum_alg; - switch (sum_alg) { - case CKSUM_NONE: - break; - case CKSUM_SHA1: - archive_sha1_init(&(sumwrk->sha1ctx)); - break; - case CKSUM_MD5: - archive_md5_init(&(sumwrk->md5ctx)); - break; - } -} - -static void -_checksum_update(struct chksumwork *sumwrk, const void *buff, size_t size) -{ - - switch (sumwrk->alg) { - case CKSUM_NONE: - break; - case CKSUM_SHA1: - archive_sha1_update(&(sumwrk->sha1ctx), buff, size); - break; - case CKSUM_MD5: - archive_md5_update(&(sumwrk->md5ctx), buff, size); - break; - } -} - -static int -_checksum_final(struct chksumwork *sumwrk, const void *val, size_t len) -{ - unsigned char sum[MAX_SUM_SIZE]; - int r = ARCHIVE_OK; - - switch (sumwrk->alg) { - case CKSUM_NONE: - break; - case CKSUM_SHA1: - archive_sha1_final(&(sumwrk->sha1ctx), sum); - if (len != SHA1_SIZE || - memcmp(val, sum, SHA1_SIZE) != 0) - r = ARCHIVE_FAILED; - break; - case CKSUM_MD5: - archive_md5_final(&(sumwrk->md5ctx), sum); - if (len != MD5_SIZE || - memcmp(val, sum, MD5_SIZE) != 0) - r = ARCHIVE_FAILED; - break; - } - return (r); -} - -static void -checksum_init(struct archive_read *a, int a_sum_alg, int e_sum_alg) -{ - struct xar *xar; - - xar = (struct xar *)(a->format->data); - _checksum_init(&(xar->a_sumwrk), a_sum_alg); - _checksum_init(&(xar->e_sumwrk), e_sum_alg); -} - -static void -checksum_update(struct archive_read *a, const void *abuff, size_t asize, - const void *ebuff, size_t esize) -{ - struct xar *xar; - - xar = (struct xar *)(a->format->data); - _checksum_update(&(xar->a_sumwrk), abuff, asize); - _checksum_update(&(xar->e_sumwrk), ebuff, esize); -} - -static int -checksum_final(struct archive_read *a, const void *a_sum_val, - size_t a_sum_len, const void *e_sum_val, size_t e_sum_len) -{ - struct xar *xar; - int r; - - xar = (struct xar *)(a->format->data); - r = _checksum_final(&(xar->a_sumwrk), a_sum_val, a_sum_len); - if (r == ARCHIVE_OK) - r = _checksum_final(&(xar->e_sumwrk), e_sum_val, e_sum_len); - if (r != ARCHIVE_OK) - archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, - "Sumcheck error"); - return (r); -} - -static int -decompression_init(struct archive_read *a, enum enctype encoding) -{ - struct xar *xar; - const char *detail; - int r; - - xar = (struct xar *)(a->format->data); - xar->rd_encoding = encoding; - switch (encoding) { - case NONE: - break; - case GZIP: - if (xar->stream_valid) - r = inflateReset(&(xar->stream)); - else - r = inflateInit(&(xar->stream)); - if (r != Z_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Couldn't initialize zlib stream."); - return (ARCHIVE_FATAL); - } - xar->stream_valid = 1; - xar->stream.total_in = 0; - xar->stream.total_out = 0; - break; -#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) - case BZIP2: - if (xar->bzstream_valid) { - BZ2_bzDecompressEnd(&(xar->bzstream)); - xar->bzstream_valid = 0; - } - r = BZ2_bzDecompressInit(&(xar->bzstream), 0, 0); - if (r == BZ_MEM_ERROR) - r = BZ2_bzDecompressInit(&(xar->bzstream), 0, 1); - if (r != BZ_OK) { - int err = ARCHIVE_ERRNO_MISC; - detail = NULL; - switch (r) { - case BZ_PARAM_ERROR: - detail = "invalid setup parameter"; - break; - case BZ_MEM_ERROR: - err = ENOMEM; - detail = "out of memory"; - break; - case BZ_CONFIG_ERROR: - detail = "mis-compiled library"; - break; - } - archive_set_error(&a->archive, err, - "Internal error initializing decompressor: %s", - detail == NULL ? "??" : detail); - xar->bzstream_valid = 0; - return (ARCHIVE_FATAL); - } - xar->bzstream_valid = 1; - xar->bzstream.total_in_lo32 = 0; - xar->bzstream.total_in_hi32 = 0; - xar->bzstream.total_out_lo32 = 0; - xar->bzstream.total_out_hi32 = 0; - break; -#endif -#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) - case XZ: - case LZMA: - if (xar->lzstream_valid) { - lzma_end(&(xar->lzstream)); - xar->lzstream_valid = 0; - } - if (xar->entry_encoding == XZ) - r = lzma_stream_decoder(&(xar->lzstream), - (1U << 30),/* memlimit */ - LZMA_CONCATENATED); - else - r = lzma_alone_decoder(&(xar->lzstream), - (1U << 30));/* memlimit */ - if (r != LZMA_OK) { - switch (r) { - case LZMA_MEM_ERROR: - archive_set_error(&a->archive, - ENOMEM, - "Internal error initializing " - "compression library: " - "Cannot allocate memory"); - break; - case LZMA_OPTIONS_ERROR: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing " - "compression library: " - "Invalid or unsupported options"); - break; - default: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing " - "lzma library"); - break; - } - return (ARCHIVE_FATAL); - } - xar->lzstream_valid = 1; - xar->lzstream.total_in = 0; - xar->lzstream.total_out = 0; - break; -#elif defined(HAVE_LZMADEC_H) && defined(HAVE_LIBLZMADEC) - case LZMA: - if (xar->lzstream_valid) - lzmadec_end(&(xar->lzstream)); - r = lzmadec_init(&(xar->lzstream)); - if (r != LZMADEC_OK) { - switch (r) { - case LZMADEC_HEADER_ERROR: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing " - "compression library: " - "invalid header"); - break; - case LZMADEC_MEM_ERROR: - archive_set_error(&a->archive, - ENOMEM, - "Internal error initializing " - "compression library: " - "out of memory"); - break; - } - return (ARCHIVE_FATAL); - } - xar->lzstream_valid = 1; - xar->lzstream.total_in = 0; - xar->lzstream.total_out = 0; - break; -#endif - /* - * Unsupported compression. - */ - default: -#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) - case BZIP2: -#endif -#if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA) -#if !defined(HAVE_LZMADEC_H) || !defined(HAVE_LIBLZMADEC) - case LZMA: -#endif - case XZ: -#endif - switch (xar->entry_encoding) { - case BZIP2: detail = "bzip2"; break; - case LZMA: detail = "lzma"; break; - case XZ: detail = "xz"; break; - default: detail = "??"; break; - } - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "%s compression not supported on this platform", - detail); - return (ARCHIVE_FAILED); - } - return (ARCHIVE_OK); -} - -static int -decompress(struct archive_read *a, const void **buff, size_t *outbytes, - const void *b, size_t *used) -{ - struct xar *xar; - void *outbuff; - size_t avail_in, avail_out; - int r; - - xar = (struct xar *)(a->format->data); - avail_in = *used; - outbuff = (void *)(uintptr_t)*buff; - if (outbuff == NULL) { - outbuff = xar->buff; - *buff = outbuff; - avail_out = sizeof(xar->buff); - } else - avail_out = *outbytes; - switch (xar->rd_encoding) { - case GZIP: - xar->stream.next_in = (Bytef *)(uintptr_t)b; - xar->stream.avail_in = avail_in; - xar->stream.next_out = (unsigned char *)outbuff; - xar->stream.avail_out = avail_out; - r = inflate(&(xar->stream), 0); - switch (r) { - case Z_OK: /* Decompressor made some progress.*/ - case Z_STREAM_END: /* Found end of stream. */ - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "File decompression failed (%d)", r); - return (ARCHIVE_FATAL); - } - *used = avail_in - xar->stream.avail_in; - *outbytes = avail_out - xar->stream.avail_out; - break; -#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) - case BZIP2: - xar->bzstream.next_in = (char *)(uintptr_t)b; - xar->bzstream.avail_in = avail_in; - xar->bzstream.next_out = (char *)outbuff; - xar->bzstream.avail_out = avail_out; - r = BZ2_bzDecompress(&(xar->bzstream)); - switch (r) { - case BZ_STREAM_END: /* Found end of stream. */ - switch (BZ2_bzDecompressEnd(&(xar->bzstream))) { - case BZ_OK: - break; - default: - archive_set_error(&(a->archive), - ARCHIVE_ERRNO_MISC, - "Failed to clean up decompressor"); - return (ARCHIVE_FATAL); - } - xar->bzstream_valid = 0; - /* FALLTHROUGH */ - case BZ_OK: /* Decompressor made some progress. */ - break; - default: - archive_set_error(&(a->archive), - ARCHIVE_ERRNO_MISC, - "bzip decompression failed"); - return (ARCHIVE_FATAL); - } - *used = avail_in - xar->bzstream.avail_in; - *outbytes = avail_out - xar->bzstream.avail_out; - break; -#endif -#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) - case LZMA: - case XZ: - xar->lzstream.next_in = b; - xar->lzstream.avail_in = avail_in; - xar->lzstream.next_out = (unsigned char *)outbuff; - xar->lzstream.avail_out = avail_out; - r = lzma_code(&(xar->lzstream), LZMA_RUN); - switch (r) { - case LZMA_STREAM_END: /* Found end of stream. */ - lzma_end(&(xar->lzstream)); - xar->lzstream_valid = 0; - /* FALLTHROUGH */ - case LZMA_OK: /* Decompressor made some progress. */ - break; - default: - archive_set_error(&(a->archive), - ARCHIVE_ERRNO_MISC, - "%s decompression failed(%d)", - (xar->entry_encoding == XZ)?"xz":"lzma", - r); - return (ARCHIVE_FATAL); - } - *used = avail_in - xar->lzstream.avail_in; - *outbytes = avail_out - xar->lzstream.avail_out; - break; -#elif defined(HAVE_LZMADEC_H) && defined(HAVE_LIBLZMADEC) - case LZMA: - xar->lzstream.next_in = (unsigned char *)(uintptr_t)b; - xar->lzstream.avail_in = avail_in; - xar->lzstream.next_out = (unsigned char *)outbuff; - xar->lzstream.avail_out = avail_out; - r = lzmadec_decode(&(xar->lzstream), 0); - switch (r) { - case LZMADEC_STREAM_END: /* Found end of stream. */ - switch (lzmadec_end(&(xar->lzstream))) { - case LZMADEC_OK: - break; - default: - archive_set_error(&(a->archive), - ARCHIVE_ERRNO_MISC, - "Failed to clean up lzmadec decompressor"); - return (ARCHIVE_FATAL); - } - xar->lzstream_valid = 0; - /* FALLTHROUGH */ - case LZMADEC_OK: /* Decompressor made some progress. */ - break; - default: - archive_set_error(&(a->archive), - ARCHIVE_ERRNO_MISC, - "lzmadec decompression failed(%d)", - r); - return (ARCHIVE_FATAL); - } - *used = avail_in - xar->lzstream.avail_in; - *outbytes = avail_out - xar->lzstream.avail_out; - break; -#endif -#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) - case BZIP2: -#endif -#if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA) -#if !defined(HAVE_LZMADEC_H) || !defined(HAVE_LIBLZMADEC) - case LZMA: -#endif - case XZ: -#endif - case NONE: - default: - if (outbuff == xar->buff) { - *buff = b; - *used = avail_in; - *outbytes = avail_in; - } else { - if (avail_out > avail_in) - avail_out = avail_in; - memcpy(outbuff, b, avail_out); - *used = avail_out; - *outbytes = avail_out; - } - break; - } - return (ARCHIVE_OK); -} - -static int -decompression_cleanup(struct archive_read *a) -{ - struct xar *xar; - int r; - - xar = (struct xar *)(a->format->data); - r = ARCHIVE_OK; - if (xar->stream_valid) { - if (inflateEnd(&(xar->stream)) != Z_OK) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Failed to clean up zlib decompressor"); - r = ARCHIVE_FATAL; - } - } -#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) - if (xar->bzstream_valid) { - if (BZ2_bzDecompressEnd(&(xar->bzstream)) != BZ_OK) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Failed to clean up bzip2 decompressor"); - r = ARCHIVE_FATAL; - } - } -#endif -#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) - if (xar->lzstream_valid) - lzma_end(&(xar->lzstream)); -#elif defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) - if (xar->lzstream_valid) { - if (lzmadec_end(&(xar->lzstream)) != LZMADEC_OK) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Failed to clean up lzmadec decompressor"); - r = ARCHIVE_FATAL; - } - } -#endif - return (r); -} - -static void -xmlattr_cleanup(struct xmlattr_list *list) -{ - struct xmlattr *attr, *next; - - attr = list->first; - while (attr != NULL) { - next = attr->next; - free(attr->name); - free(attr->value); - free(attr); - attr = next; - } - list->first = NULL; - list->last = &(list->first); -} - -static void -file_new(struct xar *xar, struct xmlattr_list *list) -{ - struct xar_file *file; - struct xmlattr *attr; - - file = calloc(1, sizeof(*file)); - if (file == NULL) - __archive_errx(1, "Out of memory"); - file->parent = xar->file; - file->mode = 0777 | AE_IFREG; - file->atime = time(NULL); - file->mtime = time(NULL); - xar->file = file; - xar->xattr = NULL; - for (attr = list->first; attr != NULL; attr = attr->next) { - if (strcmp(attr->name, "id") == 0) - file->id = atol10(attr->value, strlen(attr->value)); - } - file->nlink = 1; - heap_add_entry(&(xar->file_queue), file); -} - -static void -file_free(struct xar_file *file) -{ - struct xattr *xattr; - - archive_string_free(&(file->pathname)); - archive_string_free(&(file->symlink)); - archive_string_free(&(file->uname)); - archive_string_free(&(file->gname)); - archive_string_free(&(file->hardlink)); - xattr = file->xattr_list; - while (xattr != NULL) { - struct xattr *next; - - next = xattr->next; - xattr_free(xattr); - xattr = next; - } - - free(file); -} - -static void -xattr_new(struct xar *xar, struct xmlattr_list *list) -{ - struct xattr *xattr, **nx; - struct xmlattr *attr; - - xattr = calloc(1, sizeof(*xattr)); - if (xattr == NULL) - __archive_errx(1, "Out of memory"); - xar->xattr = xattr; - for (attr = list->first; attr != NULL; attr = attr->next) { - if (strcmp(attr->name, "id") == 0) - xattr->id = atol10(attr->value, strlen(attr->value)); - } - /* Chain to xattr list. */ - for (nx = &(xar->file->xattr_list); - *nx != NULL; nx = &((*nx)->next)) { - if (xattr->id < (*nx)->id) - break; - } - xattr->next = *nx; - *nx = xattr; -} - -static void -xattr_free(struct xattr *xattr) -{ - archive_string_free(&(xattr->name)); - free(xattr); -} - -static int -getencoding(struct xmlattr_list *list) -{ - struct xmlattr *attr; - enum enctype encoding = NONE; - - for (attr = list->first; attr != NULL; attr = attr->next) { - if (strcmp(attr->name, "style") == 0) { - if (strcmp(attr->value, "application/octet-stream") == 0) - encoding = NONE; - else if (strcmp(attr->value, "application/x-gzip") == 0) - encoding = GZIP; - else if (strcmp(attr->value, "application/x-bzip2") == 0) - encoding = BZIP2; - else if (strcmp(attr->value, "application/x-lzma") == 0) - encoding = LZMA; - else if (strcmp(attr->value, "application/x-xz") == 0) - encoding = XZ; - } - } - return (encoding); -} - -static int -getsumalgorithm(struct xmlattr_list *list) -{ - struct xmlattr *attr; - int alg = CKSUM_NONE; - - for (attr = list->first; attr != NULL; attr = attr->next) { - if (strcmp(attr->name, "style") == 0) { - const char *v = attr->value; - if ((v[0] == 'S' || v[0] == 's') && - (v[1] == 'H' || v[1] == 'h') && - (v[2] == 'A' || v[2] == 'a') && - v[3] == '1' && v[4] == '\0') - alg = CKSUM_SHA1; - if ((v[0] == 'M' || v[0] == 'm') && - (v[1] == 'D' || v[1] == 'd') && - v[2] == '5' && v[3] == '\0') - alg = CKSUM_MD5; - } - } - return (alg); -} - -static void -unknowntag_start(struct xar *xar, const char *name) -{ - struct unknown_tag *tag; - -#if DEBUG - fprintf(stderr, "unknowntag_start:%s\n", name); -#endif - tag = malloc(sizeof(*tag)); - if (tag == NULL) - __archive_errx(1, "Out of memory"); - tag->next = xar->unknowntags; - archive_string_init(&(tag->name)); - archive_strcpy(&(tag->name), name); - if (xar->unknowntags == NULL) { - xar->xmlsts_unknown = xar->xmlsts; - xar->xmlsts = UNKNOWN; - } - xar->unknowntags = tag; -} - -static void -unknowntag_end(struct xar *xar, const char *name) -{ - struct unknown_tag *tag; - -#if DEBUG - fprintf(stderr, "unknowntag_end:%s\n", name); -#endif - tag = xar->unknowntags; - if (tag == NULL || name == NULL) - return; - if (strcmp(tag->name.s, name) == 0) { - xar->unknowntags = tag->next; - archive_string_free(&(tag->name)); - free(tag); - if (xar->unknowntags == NULL) - xar->xmlsts = xar->xmlsts_unknown; - } -} - -static void -xml_start(void *userData, const char *name, struct xmlattr_list *list) -{ - struct archive_read *a; - struct xar *xar; - struct xmlattr *attr; - - a = (struct archive_read *)userData; - xar = (struct xar *)(a->format->data); - -#if DEBUG - fprintf(stderr, "xml_sta:[%s]\n", name); - for (attr = list->first; attr != NULL; attr = attr->next) - fprintf(stderr, " attr:\"%s\"=\"%s\"\n", - attr->name, attr->value); -#endif - xar->base64text = 0; - switch (xar->xmlsts) { - case INIT: - if (strcmp(name, "xar") == 0) - xar->xmlsts = XAR; - else - unknowntag_start(xar, name); - break; - case XAR: - if (strcmp(name, "toc") == 0) - xar->xmlsts = TOC; - else - unknowntag_start(xar, name); - break; - case TOC: - if (strcmp(name, "creation-time") == 0) - xar->xmlsts = TOC_CREATION_TIME; - else if (strcmp(name, "checksum") == 0) - xar->xmlsts = TOC_CHECKSUM; - else if (strcmp(name, "file") == 0) { - file_new(xar, list); - xar->xmlsts = TOC_FILE; - } - else - unknowntag_start(xar, name); - break; - case TOC_CHECKSUM: - if (strcmp(name, "offset") == 0) - xar->xmlsts = TOC_CHECKSUM_OFFSET; - else if (strcmp(name, "size") == 0) - xar->xmlsts = TOC_CHECKSUM_SIZE; - else - unknowntag_start(xar, name); - break; - case TOC_FILE: - if (strcmp(name, "file") == 0) { - file_new(xar, list); - } - else if (strcmp(name, "data") == 0) - xar->xmlsts = FILE_DATA; - else if (strcmp(name, "ea") == 0) { - xattr_new(xar, list); - xar->xmlsts = FILE_EA; - } - else if (strcmp(name, "ctime") == 0) - xar->xmlsts = FILE_CTIME; - else if (strcmp(name, "mtime") == 0) - xar->xmlsts = FILE_MTIME; - else if (strcmp(name, "atime") == 0) - xar->xmlsts = FILE_ATIME; - else if (strcmp(name, "group") == 0) - xar->xmlsts = FILE_GROUP; - else if (strcmp(name, "gid") == 0) - xar->xmlsts = FILE_GID; - else if (strcmp(name, "user") == 0) - xar->xmlsts = FILE_USER; - else if (strcmp(name, "uid") == 0) - xar->xmlsts = FILE_UID; - else if (strcmp(name, "mode") == 0) - xar->xmlsts = FILE_MODE; - else if (strcmp(name, "device") == 0) - xar->xmlsts = FILE_DEVICE; - else if (strcmp(name, "deviceno") == 0) - xar->xmlsts = FILE_DEVICENO; - else if (strcmp(name, "inode") == 0) - xar->xmlsts = FILE_INODE; - else if (strcmp(name, "link") == 0) - xar->xmlsts = FILE_LINK; - else if (strcmp(name, "type") == 0) { - xar->xmlsts = FILE_TYPE; - for (attr = list->first; attr != NULL; - attr = attr->next) { - if (strcmp(attr->name, "link") != 0) - continue; - if (strcmp(attr->value, "original") == 0) { - xar->file->hdnext = xar->hdlink_orgs; - xar->hdlink_orgs = xar->file; - } else { - xar->file->link = atol10(attr->value, - strlen(attr->value)); - if (xar->file->link > 0) - add_link(xar, xar->file); - } - } - } - else if (strcmp(name, "name") == 0) { - xar->xmlsts = FILE_NAME; - for (attr = list->first; attr != NULL; - attr = attr->next) { - if (strcmp(attr->name, "enctype") == 0 && - strcmp(attr->value, "base64") == 0) - xar->base64text = 1; - } - } - else if (strcmp(name, "acl") == 0) - xar->xmlsts = FILE_ACL; - else if (strcmp(name, "flags") == 0) - xar->xmlsts = FILE_FLAGS; - else if (strcmp(name, "ext2") == 0) - xar->xmlsts = FILE_EXT2; - else - unknowntag_start(xar, name); - break; - case FILE_DATA: - if (strcmp(name, "length") == 0) - xar->xmlsts = FILE_DATA_LENGTH; - else if (strcmp(name, "offset") == 0) - xar->xmlsts = FILE_DATA_OFFSET; - else if (strcmp(name, "size") == 0) - xar->xmlsts = FILE_DATA_SIZE; - else if (strcmp(name, "encoding") == 0) { - xar->xmlsts = FILE_DATA_ENCODING; - xar->file->encoding = getencoding(list); - } - else if (strcmp(name, "archived-checksum") == 0) { - xar->xmlsts = FILE_DATA_A_CHECKSUM; - xar->file->a_sum.alg = getsumalgorithm(list); - } - else if (strcmp(name, "extracted-checksum") == 0) { - xar->xmlsts = FILE_DATA_E_CHECKSUM; - xar->file->e_sum.alg = getsumalgorithm(list); - } - else if (strcmp(name, "content") == 0) - xar->xmlsts = FILE_DATA_CONTENT; - else - unknowntag_start(xar, name); - break; - case FILE_DEVICE: - if (strcmp(name, "major") == 0) - xar->xmlsts = FILE_DEVICE_MAJOR; - else if (strcmp(name, "minor") == 0) - xar->xmlsts = FILE_DEVICE_MINOR; - else - unknowntag_start(xar, name); - break; - case FILE_DATA_CONTENT: - unknowntag_start(xar, name); - break; - case FILE_EA: - if (strcmp(name, "length") == 0) - xar->xmlsts = FILE_EA_LENGTH; - else if (strcmp(name, "offset") == 0) - xar->xmlsts = FILE_EA_OFFSET; - else if (strcmp(name, "size") == 0) - xar->xmlsts = FILE_EA_SIZE; - else if (strcmp(name, "encoding") == 0) { - xar->xmlsts = FILE_EA_ENCODING; - xar->xattr->encoding = getencoding(list); - } else if (strcmp(name, "archived-checksum") == 0) - xar->xmlsts = FILE_EA_A_CHECKSUM; - else if (strcmp(name, "extracted-checksum") == 0) - xar->xmlsts = FILE_EA_E_CHECKSUM; - else if (strcmp(name, "name") == 0) - xar->xmlsts = FILE_EA_NAME; - else if (strcmp(name, "fstype") == 0) - xar->xmlsts = FILE_EA_FSTYPE; - else - unknowntag_start(xar, name); - break; - case FILE_ACL: - if (strcmp(name, "appleextended") == 0) - xar->xmlsts = FILE_ACL_APPLEEXTENDED; - if (strcmp(name, "default") == 0) - xar->xmlsts = FILE_ACL_DEFAULT; - else if (strcmp(name, "access") == 0) - xar->xmlsts = FILE_ACL_ACCESS; - else - unknowntag_start(xar, name); - break; - case FILE_FLAGS: - if (!xml_parse_file_flags(xar, name)) - unknowntag_start(xar, name); - break; - case FILE_EXT2: - if (!xml_parse_file_ext2(xar, name)) - unknowntag_start(xar, name); - break; - case TOC_CREATION_TIME: - case TOC_CHECKSUM_OFFSET: - case TOC_CHECKSUM_SIZE: - case FILE_DATA_LENGTH: - case FILE_DATA_OFFSET: - case FILE_DATA_SIZE: - case FILE_DATA_ENCODING: - case FILE_DATA_A_CHECKSUM: - case FILE_DATA_E_CHECKSUM: - case FILE_EA_LENGTH: - case FILE_EA_OFFSET: - case FILE_EA_SIZE: - case FILE_EA_ENCODING: - case FILE_EA_A_CHECKSUM: - case FILE_EA_E_CHECKSUM: - case FILE_EA_NAME: - case FILE_EA_FSTYPE: - case FILE_CTIME: - case FILE_MTIME: - case FILE_ATIME: - case FILE_GROUP: - case FILE_GID: - case FILE_USER: - case FILE_UID: - case FILE_INODE: - case FILE_DEVICE_MAJOR: - case FILE_DEVICE_MINOR: - case FILE_DEVICENO: - case FILE_MODE: - case FILE_TYPE: - case FILE_LINK: - case FILE_NAME: - case FILE_ACL_DEFAULT: - case FILE_ACL_ACCESS: - case FILE_ACL_APPLEEXTENDED: - case FILE_FLAGS_USER_NODUMP: - case FILE_FLAGS_USER_IMMUTABLE: - case FILE_FLAGS_USER_APPEND: - case FILE_FLAGS_USER_OPAQUE: - case FILE_FLAGS_USER_NOUNLINK: - case FILE_FLAGS_SYS_ARCHIVED: - case FILE_FLAGS_SYS_IMMUTABLE: - case FILE_FLAGS_SYS_APPEND: - case FILE_FLAGS_SYS_NOUNLINK: - case FILE_FLAGS_SYS_SNAPSHOT: - case FILE_EXT2_SecureDeletion: - case FILE_EXT2_Undelete: - case FILE_EXT2_Compress: - case FILE_EXT2_Synchronous: - case FILE_EXT2_Immutable: - case FILE_EXT2_AppendOnly: - case FILE_EXT2_NoDump: - case FILE_EXT2_NoAtime: - case FILE_EXT2_CompDirty: - case FILE_EXT2_CompBlock: - case FILE_EXT2_NoCompBlock: - case FILE_EXT2_CompError: - case FILE_EXT2_BTree: - case FILE_EXT2_HashIndexed: - case FILE_EXT2_iMagic: - case FILE_EXT2_Journaled: - case FILE_EXT2_NoTail: - case FILE_EXT2_DirSync: - case FILE_EXT2_TopDir: - case FILE_EXT2_Reserved: - case UNKNOWN: - unknowntag_start(xar, name); - break; - } -} - -static void -xml_end(void *userData, const char *name) -{ - struct archive_read *a; - struct xar *xar; - - a = (struct archive_read *)userData; - xar = (struct xar *)(a->format->data); - -#if DEBUG - fprintf(stderr, "xml_end:[%s]\n", name); -#endif - switch (xar->xmlsts) { - case INIT: - break; - case XAR: - if (strcmp(name, "xar") == 0) - xar->xmlsts = INIT; - break; - case TOC: - if (strcmp(name, "toc") == 0) - xar->xmlsts = XAR; - break; - case TOC_CREATION_TIME: - if (strcmp(name, "creation-time") == 0) - xar->xmlsts = TOC; - break; - case TOC_CHECKSUM: - if (strcmp(name, "checksum") == 0) - xar->xmlsts = TOC; - break; - case TOC_CHECKSUM_OFFSET: - if (strcmp(name, "offset") == 0) - xar->xmlsts = TOC_CHECKSUM; - break; - case TOC_CHECKSUM_SIZE: - if (strcmp(name, "size") == 0) - xar->xmlsts = TOC_CHECKSUM; - break; - case TOC_FILE: - if (strcmp(name, "file") == 0) { - if (xar->file->parent != NULL && - ((xar->file->mode & AE_IFMT) == AE_IFDIR)) - xar->file->parent->subdirs++; - xar->file = xar->file->parent; - if (xar->file == NULL) - xar->xmlsts = TOC; - } - break; - case FILE_DATA: - if (strcmp(name, "data") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_DATA_LENGTH: - if (strcmp(name, "length") == 0) - xar->xmlsts = FILE_DATA; - break; - case FILE_DATA_OFFSET: - if (strcmp(name, "offset") == 0) - xar->xmlsts = FILE_DATA; - break; - case FILE_DATA_SIZE: - if (strcmp(name, "size") == 0) - xar->xmlsts = FILE_DATA; - break; - case FILE_DATA_ENCODING: - if (strcmp(name, "encoding") == 0) - xar->xmlsts = FILE_DATA; - break; - case FILE_DATA_A_CHECKSUM: - if (strcmp(name, "archived-checksum") == 0) - xar->xmlsts = FILE_DATA; - break; - case FILE_DATA_E_CHECKSUM: - if (strcmp(name, "extracted-checksum") == 0) - xar->xmlsts = FILE_DATA; - break; - case FILE_DATA_CONTENT: - if (strcmp(name, "content") == 0) - xar->xmlsts = FILE_DATA; - break; - case FILE_EA: - if (strcmp(name, "ea") == 0) { - xar->xmlsts = TOC_FILE; - xar->xattr = NULL; - } - break; - case FILE_EA_LENGTH: - if (strcmp(name, "length") == 0) - xar->xmlsts = FILE_EA; - break; - case FILE_EA_OFFSET: - if (strcmp(name, "offset") == 0) - xar->xmlsts = FILE_EA; - break; - case FILE_EA_SIZE: - if (strcmp(name, "size") == 0) - xar->xmlsts = FILE_EA; - break; - case FILE_EA_ENCODING: - if (strcmp(name, "encoding") == 0) - xar->xmlsts = FILE_EA; - break; - case FILE_EA_A_CHECKSUM: - if (strcmp(name, "archived-checksum") == 0) - xar->xmlsts = FILE_EA; - break; - case FILE_EA_E_CHECKSUM: - if (strcmp(name, "extracted-checksum") == 0) - xar->xmlsts = FILE_EA; - break; - case FILE_EA_NAME: - if (strcmp(name, "name") == 0) - xar->xmlsts = FILE_EA; - break; - case FILE_EA_FSTYPE: - if (strcmp(name, "fstype") == 0) - xar->xmlsts = FILE_EA; - break; - case FILE_CTIME: - if (strcmp(name, "ctime") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_MTIME: - if (strcmp(name, "mtime") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_ATIME: - if (strcmp(name, "atime") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_GROUP: - if (strcmp(name, "group") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_GID: - if (strcmp(name, "gid") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_USER: - if (strcmp(name, "user") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_UID: - if (strcmp(name, "uid") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_MODE: - if (strcmp(name, "mode") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_DEVICE: - if (strcmp(name, "device") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_DEVICE_MAJOR: - if (strcmp(name, "major") == 0) - xar->xmlsts = FILE_DEVICE; - break; - case FILE_DEVICE_MINOR: - if (strcmp(name, "minor") == 0) - xar->xmlsts = FILE_DEVICE; - break; - case FILE_DEVICENO: - if (strcmp(name, "deviceno") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_INODE: - if (strcmp(name, "inode") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_LINK: - if (strcmp(name, "link") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_TYPE: - if (strcmp(name, "type") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_NAME: - if (strcmp(name, "name") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_ACL: - if (strcmp(name, "acl") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_ACL_DEFAULT: - if (strcmp(name, "default") == 0) - xar->xmlsts = FILE_ACL; - break; - case FILE_ACL_ACCESS: - if (strcmp(name, "access") == 0) - xar->xmlsts = FILE_ACL; - break; - case FILE_ACL_APPLEEXTENDED: - if (strcmp(name, "appleextended") == 0) - xar->xmlsts = FILE_ACL; - break; - case FILE_FLAGS: - if (strcmp(name, "flags") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_FLAGS_USER_NODUMP: - if (strcmp(name, "UserNoDump") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_FLAGS_USER_IMMUTABLE: - if (strcmp(name, "UserImmutable") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_FLAGS_USER_APPEND: - if (strcmp(name, "UserAppend") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_FLAGS_USER_OPAQUE: - if (strcmp(name, "UserOpaque") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_FLAGS_USER_NOUNLINK: - if (strcmp(name, "UserNoUnlink") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_FLAGS_SYS_ARCHIVED: - if (strcmp(name, "SystemArchived") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_FLAGS_SYS_IMMUTABLE: - if (strcmp(name, "SystemImmutable") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_FLAGS_SYS_APPEND: - if (strcmp(name, "SystemAppend") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_FLAGS_SYS_NOUNLINK: - if (strcmp(name, "SystemNoUnlink") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_FLAGS_SYS_SNAPSHOT: - if (strcmp(name, "SystemSnapshot") == 0) - xar->xmlsts = FILE_FLAGS; - break; - case FILE_EXT2: - if (strcmp(name, "ext2") == 0) - xar->xmlsts = TOC_FILE; - break; - case FILE_EXT2_SecureDeletion: - if (strcmp(name, "SecureDeletion") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_Undelete: - if (strcmp(name, "Undelete") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_Compress: - if (strcmp(name, "Compress") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_Synchronous: - if (strcmp(name, "Synchronous") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_Immutable: - if (strcmp(name, "Immutable") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_AppendOnly: - if (strcmp(name, "AppendOnly") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_NoDump: - if (strcmp(name, "NoDump") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_NoAtime: - if (strcmp(name, "NoAtime") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_CompDirty: - if (strcmp(name, "CompDirty") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_CompBlock: - if (strcmp(name, "CompBlock") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_NoCompBlock: - if (strcmp(name, "NoCompBlock") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_CompError: - if (strcmp(name, "CompError") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_BTree: - if (strcmp(name, "BTree") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_HashIndexed: - if (strcmp(name, "HashIndexed") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_iMagic: - if (strcmp(name, "iMagic") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_Journaled: - if (strcmp(name, "Journaled") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_NoTail: - if (strcmp(name, "NoTail") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_DirSync: - if (strcmp(name, "DirSync") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_TopDir: - if (strcmp(name, "TopDir") == 0) - xar->xmlsts = FILE_EXT2; - break; - case FILE_EXT2_Reserved: - if (strcmp(name, "Reserved") == 0) - xar->xmlsts = FILE_EXT2; - break; - case UNKNOWN: - unknowntag_end(xar, name); - break; - } -} - -static const int base64[256] = { - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* 00 - 0F */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* 10 - 1F */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 62, -1, -1, -1, 63, /* 20 - 2F */ - 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, -1, -1, -1, -1, -1, -1, /* 30 - 3F */ - -1, 0, 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, /* 40 - 4F */ - 15, 16, 17, 18, 19, 20, 21, 22, - 23, 24, 25, -1, -1, -1, -1, -1, /* 50 - 5F */ - -1, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, /* 60 - 6F */ - 41, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, -1, -1, -1, -1, -1, /* 70 - 7F */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* 80 - 8F */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* 90 - 9F */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* A0 - AF */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* B0 - BF */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* C0 - CF */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* D0 - DF */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* E0 - EF */ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, /* F0 - FF */ -}; - -static void -strappend_base64(struct archive_string *as, const char *s, size_t l) -{ - unsigned char buff[256]; - unsigned char *out; - const unsigned char *b; - size_t len; - - len = 0; - out = buff; - b = (const unsigned char *)s; - while (l > 0) { - int n = 0; - - if (l > 0) { - if (base64[b[0]] < 0 || base64[b[1]] < 0) - break; - n = base64[*b++] << 18; - n |= base64[*b++] << 12; - *out++ = n >> 16; - len++; - l -= 2; - } - if (l > 0) { - if (base64[*b] < 0) - break; - n |= base64[*b++] << 6; - *out++ = (n >> 8) & 0xFF; - len++; - --l; - } - if (l > 0) { - if (base64[*b] < 0) - break; - n |= base64[*b++]; - *out++ = n & 0xFF; - len++; - --l; - } - if (len+3 >= sizeof(buff)) { - archive_strncat(as, (const char *)buff, len); - len = 0; - out = buff; - } - } - if (len > 0) - archive_strncat(as, (const char *)buff, len); -} - -static void -xml_data(void *userData, const char *s, int len) -{ - struct archive_read *a; - struct xar *xar; - - a = (struct archive_read *)userData; - xar = (struct xar *)(a->format->data); - -#if DEBUG - { - char buff[1024]; - if (len > (int)sizeof(buff)-1) - len = (int)sizeof(buff)-1; - memcpy(buff, s, len); - buff[len] = 0; - fprintf(stderr, "\tlen=%d:\"%s\"\n", len, buff); - } -#endif - switch (xar->xmlsts) { - case TOC_CHECKSUM_OFFSET: - xar->toc_chksum_offset = atol10(s, len); - break; - case TOC_CHECKSUM_SIZE: - xar->toc_chksum_size = atol10(s, len); - break; - default: - break; - } - if (xar->file == NULL) - return; - - switch (xar->xmlsts) { - case FILE_NAME: - if (xar->file->parent != NULL) { - archive_string_concat(&(xar->file->pathname), - &(xar->file->parent->pathname)); - archive_strappend_char(&(xar->file->pathname), '/'); - } - xar->file->has |= HAS_PATHNAME; - if (xar->base64text) - strappend_base64(&(xar->file->pathname), s, len); - else - archive_strncat(&(xar->file->pathname), s, len); - break; - case FILE_LINK: - xar->file->has |= HAS_SYMLINK; - archive_strncpy(&(xar->file->symlink), s, len); - break; - case FILE_TYPE: - if (strncmp("file", s, len) == 0 || - strncmp("hardlink", s, len) == 0) - xar->file->mode = - (xar->file->mode & ~AE_IFMT) | AE_IFREG; - if (strncmp("directory", s, len) == 0) - xar->file->mode = - (xar->file->mode & ~AE_IFMT) | AE_IFDIR; - if (strncmp("symlink", s, len) == 0) - xar->file->mode = - (xar->file->mode & ~AE_IFMT) | AE_IFLNK; - if (strncmp("character special", s, len) == 0) - xar->file->mode = - (xar->file->mode & ~AE_IFMT) | AE_IFCHR; - if (strncmp("block special", s, len) == 0) - xar->file->mode = - (xar->file->mode & ~AE_IFMT) | AE_IFBLK; - if (strncmp("socket", s, len) == 0) - xar->file->mode = - (xar->file->mode & ~AE_IFMT) | AE_IFSOCK; - if (strncmp("fifo", s, len) == 0) - xar->file->mode = - (xar->file->mode & ~AE_IFMT) | AE_IFIFO; - xar->file->has |= HAS_TYPE; - break; - case FILE_INODE: - xar->file->has |= HAS_INO; - xar->file->ino64 = atol10(s, len); - break; - case FILE_DEVICE_MAJOR: - xar->file->has |= HAS_DEVMAJOR; - xar->file->devmajor = (dev_t)atol10(s, len); - break; - case FILE_DEVICE_MINOR: - xar->file->has |= HAS_DEVMINOR; - xar->file->devminor = (dev_t)atol10(s, len); - break; - case FILE_DEVICENO: - xar->file->has |= HAS_DEV; - xar->file->dev = (dev_t)atol10(s, len); - break; - case FILE_MODE: - xar->file->has |= HAS_MODE; - xar->file->mode = - (xar->file->mode & AE_IFMT) | - (atol8(s, len) & ~AE_IFMT); - break; - case FILE_GROUP: - xar->file->has |= HAS_GID; - archive_strncpy(&(xar->file->gname), s, len); - break; - case FILE_GID: - xar->file->has |= HAS_GID; - xar->file->gid = atol10(s, len); - break; - case FILE_USER: - xar->file->has |= HAS_UID; - archive_strncpy(&(xar->file->uname), s, len); - break; - case FILE_UID: - xar->file->has |= HAS_UID; - xar->file->uid = atol10(s, len); - break; - case FILE_CTIME: - xar->file->has |= HAS_TIME; - xar->file->ctime = parse_time(s, len); - break; - case FILE_MTIME: - xar->file->has |= HAS_TIME; - xar->file->mtime = parse_time(s, len); - break; - case FILE_ATIME: - xar->file->has |= HAS_TIME; - xar->file->atime = parse_time(s, len); - break; - case FILE_DATA_LENGTH: - xar->file->has |= HAS_DATA; - xar->file->length = atol10(s, len); - break; - case FILE_DATA_OFFSET: - xar->file->has |= HAS_DATA; - xar->file->offset = atol10(s, len); - break; - case FILE_DATA_SIZE: - xar->file->has |= HAS_DATA; - xar->file->size = atol10(s, len); - break; - case FILE_DATA_A_CHECKSUM: - xar->file->a_sum.len = atohex(xar->file->a_sum.val, - sizeof(xar->file->a_sum.val), s, len); - break; - case FILE_DATA_E_CHECKSUM: - xar->file->e_sum.len = atohex(xar->file->e_sum.val, - sizeof(xar->file->e_sum.val), s, len); - break; - case FILE_EA_LENGTH: - xar->file->has |= HAS_XATTR; - xar->xattr->length = atol10(s, len); - break; - case FILE_EA_OFFSET: - xar->file->has |= HAS_XATTR; - xar->xattr->offset = atol10(s, len); - break; - case FILE_EA_SIZE: - xar->file->has |= HAS_XATTR; - xar->xattr->size = atol10(s, len); - break; - case FILE_EA_A_CHECKSUM: - xar->file->has |= HAS_XATTR; - xar->xattr->a_sum.len = atohex(xar->xattr->a_sum.val, - sizeof(xar->xattr->a_sum.val), s, len); - break; - case FILE_EA_E_CHECKSUM: - xar->file->has |= HAS_XATTR; - xar->xattr->e_sum.len = atohex(xar->xattr->e_sum.val, - sizeof(xar->xattr->e_sum.val), s, len); - break; - case FILE_EA_NAME: - xar->file->has |= HAS_XATTR; - archive_strncpy(&(xar->xattr->name), s, len); - break; - case FILE_EA_FSTYPE: - xar->file->has |= HAS_XATTR; - archive_strncpy(&(xar->xattr->fstype), s, len); - break; - break; - case FILE_ACL_DEFAULT: - case FILE_ACL_ACCESS: - case FILE_ACL_APPLEEXTENDED: - xar->file->has |= HAS_ACL; - /* TODO */ - break; - case INIT: - case XAR: - case TOC: - case TOC_CREATION_TIME: - case TOC_CHECKSUM: - case TOC_CHECKSUM_OFFSET: - case TOC_CHECKSUM_SIZE: - case TOC_FILE: - case FILE_DATA: - case FILE_DATA_ENCODING: - case FILE_DATA_CONTENT: - case FILE_DEVICE: - case FILE_EA: - case FILE_EA_ENCODING: - case FILE_ACL: - case FILE_FLAGS: - case FILE_FLAGS_USER_NODUMP: - case FILE_FLAGS_USER_IMMUTABLE: - case FILE_FLAGS_USER_APPEND: - case FILE_FLAGS_USER_OPAQUE: - case FILE_FLAGS_USER_NOUNLINK: - case FILE_FLAGS_SYS_ARCHIVED: - case FILE_FLAGS_SYS_IMMUTABLE: - case FILE_FLAGS_SYS_APPEND: - case FILE_FLAGS_SYS_NOUNLINK: - case FILE_FLAGS_SYS_SNAPSHOT: - case FILE_EXT2: - case FILE_EXT2_SecureDeletion: - case FILE_EXT2_Undelete: - case FILE_EXT2_Compress: - case FILE_EXT2_Synchronous: - case FILE_EXT2_Immutable: - case FILE_EXT2_AppendOnly: - case FILE_EXT2_NoDump: - case FILE_EXT2_NoAtime: - case FILE_EXT2_CompDirty: - case FILE_EXT2_CompBlock: - case FILE_EXT2_NoCompBlock: - case FILE_EXT2_CompError: - case FILE_EXT2_BTree: - case FILE_EXT2_HashIndexed: - case FILE_EXT2_iMagic: - case FILE_EXT2_Journaled: - case FILE_EXT2_NoTail: - case FILE_EXT2_DirSync: - case FILE_EXT2_TopDir: - case FILE_EXT2_Reserved: - case UNKNOWN: - break; - } -} - -/* - * BSD file flags. - */ -static int -xml_parse_file_flags(struct xar *xar, const char *name) -{ - const char *flag = NULL; - - if (strcmp(name, "UserNoDump") == 0) { - xar->xmlsts = FILE_FLAGS_USER_NODUMP; - flag = "nodump"; - } - else if (strcmp(name, "UserImmutable") == 0) { - xar->xmlsts = FILE_FLAGS_USER_IMMUTABLE; - flag = "uimmutable"; - } - else if (strcmp(name, "UserAppend") == 0) { - xar->xmlsts = FILE_FLAGS_USER_APPEND; - flag = "uappend"; - } - else if (strcmp(name, "UserOpaque") == 0) { - xar->xmlsts = FILE_FLAGS_USER_OPAQUE; - flag = "opaque"; - } - else if (strcmp(name, "UserNoUnlink") == 0) { - xar->xmlsts = FILE_FLAGS_USER_NOUNLINK; - flag = "nouunlink"; - } - else if (strcmp(name, "SystemArchived") == 0) { - xar->xmlsts = FILE_FLAGS_SYS_ARCHIVED; - flag = "archived"; - } - else if (strcmp(name, "SystemImmutable") == 0) { - xar->xmlsts = FILE_FLAGS_SYS_IMMUTABLE; - flag = "simmutable"; - } - else if (strcmp(name, "SystemAppend") == 0) { - xar->xmlsts = FILE_FLAGS_SYS_APPEND; - flag = "sappend"; - } - else if (strcmp(name, "SystemNoUnlink") == 0) { - xar->xmlsts = FILE_FLAGS_SYS_NOUNLINK; - flag = "nosunlink"; - } - else if (strcmp(name, "SystemSnapshot") == 0) { - xar->xmlsts = FILE_FLAGS_SYS_SNAPSHOT; - flag = "snapshot"; - } - - if (flag == NULL) - return (0); - xar->file->has |= HAS_FFLAGS; - if (archive_strlen(&(xar->file->fflags_text)) > 0) - archive_strappend_char(&(xar->file->fflags_text), ','); - archive_strcat(&(xar->file->fflags_text), flag); - return (1); -} - -/* - * Linux file flags. - */ -static int -xml_parse_file_ext2(struct xar *xar, const char *name) -{ - const char *flag = NULL; - - if (strcmp(name, "SecureDeletion") == 0) { - xar->xmlsts = FILE_EXT2_SecureDeletion; - flag = "securedeletion"; - } - else if (strcmp(name, "Undelete") == 0) { - xar->xmlsts = FILE_EXT2_Undelete; - flag = "nouunlink"; - } - else if (strcmp(name, "Compress") == 0) { - xar->xmlsts = FILE_EXT2_Compress; - flag = "compress"; - } - else if (strcmp(name, "Synchronous") == 0) { - xar->xmlsts = FILE_EXT2_Synchronous; - flag = "sync"; - } - else if (strcmp(name, "Immutable") == 0) { - xar->xmlsts = FILE_EXT2_Immutable; - flag = "simmutable"; - } - else if (strcmp(name, "AppendOnly") == 0) { - xar->xmlsts = FILE_EXT2_AppendOnly; - flag = "sappend"; - } - else if (strcmp(name, "NoDump") == 0) { - xar->xmlsts = FILE_EXT2_NoDump; - flag = "nodump"; - } - else if (strcmp(name, "NoAtime") == 0) { - xar->xmlsts = FILE_EXT2_NoAtime; - flag = "noatime"; - } - else if (strcmp(name, "CompDirty") == 0) { - xar->xmlsts = FILE_EXT2_CompDirty; - flag = "compdirty"; - } - else if (strcmp(name, "CompBlock") == 0) { - xar->xmlsts = FILE_EXT2_CompBlock; - flag = "comprblk"; - } - else if (strcmp(name, "NoCompBlock") == 0) { - xar->xmlsts = FILE_EXT2_NoCompBlock; - flag = "nocomprblk"; - } - else if (strcmp(name, "CompError") == 0) { - xar->xmlsts = FILE_EXT2_CompError; - flag = "comperr"; - } - else if (strcmp(name, "BTree") == 0) { - xar->xmlsts = FILE_EXT2_BTree; - flag = "btree"; - } - else if (strcmp(name, "HashIndexed") == 0) { - xar->xmlsts = FILE_EXT2_HashIndexed; - flag = "hashidx"; - } - else if (strcmp(name, "iMagic") == 0) { - xar->xmlsts = FILE_EXT2_iMagic; - flag = "imagic"; - } - else if (strcmp(name, "Journaled") == 0) { - xar->xmlsts = FILE_EXT2_Journaled; - flag = "journal"; - } - else if (strcmp(name, "NoTail") == 0) { - xar->xmlsts = FILE_EXT2_NoTail; - flag = "notail"; - } - else if (strcmp(name, "DirSync") == 0) { - xar->xmlsts = FILE_EXT2_DirSync; - flag = "dirsync"; - } - else if (strcmp(name, "TopDir") == 0) { - xar->xmlsts = FILE_EXT2_TopDir; - flag = "topdir"; - } - else if (strcmp(name, "Reserved") == 0) { - xar->xmlsts = FILE_EXT2_Reserved; - flag = "reserved"; - } - - if (flag == NULL) - return (0); - if (archive_strlen(&(xar->file->fflags_text)) > 0) - archive_strappend_char(&(xar->file->fflags_text), ','); - archive_strcat(&(xar->file->fflags_text), flag); - return (1); -} - -#ifdef HAVE_LIBXML_XMLREADER_H - -static int -xml2_xmlattr_setup(struct xmlattr_list *list, xmlTextReaderPtr reader) -{ - struct xmlattr *attr; - int r; - - list->first = NULL; - list->last = &(list->first); - r = xmlTextReaderMoveToFirstAttribute(reader); - while (r == 1) { - attr = malloc(sizeof*(attr)); - if (attr == NULL) - __archive_errx(1, "Out of memory"); - attr->name = strdup( - (const char *)xmlTextReaderConstLocalName(reader)); - if (attr->name == NULL) - __archive_errx(1, "Out of memory"); - attr->value = strdup( - (const char *)xmlTextReaderConstValue(reader)); - if (attr->value == NULL) - __archive_errx(1, "Out of memory"); - attr->next = NULL; - *list->last = attr; - list->last = &(attr->next); - r = xmlTextReaderMoveToNextAttribute(reader); - } - return (r); -} - -static int -xml2_read_cb(void *context, char *buffer, int len) -{ - struct archive_read *a; - struct xar *xar; - const void *d; - size_t outbytes; - size_t used; - int r; - - a = (struct archive_read *)context; - xar = (struct xar *)(a->format->data); - - if (xar->toc_remaining <= 0) - return (0); - d = buffer; - outbytes = len; - r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining); - if (r != ARCHIVE_OK) - return (r); - __archive_read_consume(a, used); - xar->toc_remaining -= used; - xar->offset += used; - xar->toc_total += outbytes; - PRINT_TOC(buffer, len); - - return ((int)outbytes); -} - -static int -xml2_close_cb(void *context) -{ - - (void)context; /* UNUSED */ - return (0); -} - -static void -xml2_error_hdr(void *arg, const char *msg, xmlParserSeverities severity, - xmlTextReaderLocatorPtr locator) -{ - struct archive_read *a; - - (void)locator; /* UNUSED */ - a = (struct archive_read *)arg; - switch (severity) { - case XML_PARSER_SEVERITY_VALIDITY_WARNING: - case XML_PARSER_SEVERITY_WARNING: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "XML Parsing error: %s", msg); - break; - case XML_PARSER_SEVERITY_VALIDITY_ERROR: - case XML_PARSER_SEVERITY_ERROR: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "XML Parsing error: %s", msg); - break; - } -} - -static int -xml2_read_toc(struct archive_read *a) -{ - xmlTextReaderPtr reader; - struct xmlattr_list list; - int r; - - reader = xmlReaderForIO(xml2_read_cb, xml2_close_cb, a, NULL, NULL, 0); - if (reader == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Couldn't allocate memory for xml parser"); - return (ARCHIVE_FATAL); - } - xmlTextReaderSetErrorHandler(reader, xml2_error_hdr, a); - - while ((r = xmlTextReaderRead(reader)) == 1) { - const char *name, *value; - int type, empty; - - type = xmlTextReaderNodeType(reader); - name = (const char *)xmlTextReaderConstLocalName(reader); - switch (type) { - case XML_READER_TYPE_ELEMENT: - empty = xmlTextReaderIsEmptyElement(reader); - r = xml2_xmlattr_setup(&list, reader); - if (r == 0) { - xml_start(a, name, &list); - xmlattr_cleanup(&list); - if (empty) - xml_end(a, name); - } - break; - case XML_READER_TYPE_END_ELEMENT: - xml_end(a, name); - break; - case XML_READER_TYPE_TEXT: - value = (const char *)xmlTextReaderConstValue(reader); - xml_data(a, value, strlen(value)); - break; - case XML_READER_TYPE_SIGNIFICANT_WHITESPACE: - default: - break; - } - if (r < 0) - break; - } - xmlFreeTextReader(reader); - xmlCleanupParser(); - - return ((r == 0)?ARCHIVE_OK:ARCHIVE_FATAL); -} - -#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) - -static void -expat_xmlattr_setup(struct xmlattr_list *list, const XML_Char **atts) -{ - struct xmlattr *attr; - - list->first = NULL; - list->last = &(list->first); - if (atts == NULL) - return; - while (atts[0] != NULL && atts[1] != NULL) { - attr = malloc(sizeof*(attr)); - if (attr == NULL) - __archive_errx(1, "Out of memory"); - attr->name = strdup(atts[0]); - if (attr->name == NULL) - __archive_errx(1, "Out of memory"); - attr->value = strdup(atts[1]); - if (attr->value == NULL) - __archive_errx(1, "Out of memory"); - attr->next = NULL; - *list->last = attr; - list->last = &(attr->next); - atts += 2; - } -} - -static void -expat_start_cb(void *userData, const XML_Char *name, const XML_Char **atts) -{ - struct xmlattr_list list; - - expat_xmlattr_setup(&list, atts); - xml_start(userData, (const char *)name, &list); - xmlattr_cleanup(&list); -} - -static void -expat_end_cb(void *userData, const XML_Char *name) -{ - xml_end(userData, (const char *)name); -} - -static void -expat_data_cb(void *userData, const XML_Char *s, int len) -{ - xml_data(userData, s, len); -} - -static int -expat_read_toc(struct archive_read *a) -{ - struct xar *xar; - XML_Parser parser; - - xar = (struct xar *)(a->format->data); - - /* Initialize XML Parser library. */ - parser = XML_ParserCreate(NULL); - if (parser == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Couldn't allocate memory for xml parser"); - return (ARCHIVE_FATAL); - } - XML_SetUserData(parser, a); - XML_SetElementHandler(parser, expat_start_cb, expat_end_cb); - XML_SetCharacterDataHandler(parser, expat_data_cb); - xar->xmlsts = INIT; - - while (xar->toc_remaining) { - enum XML_Status xr; - const void *d; - size_t outbytes; - size_t used; - int r; - - d = NULL; - r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining); - if (r != ARCHIVE_OK) - return (r); - __archive_read_consume(a, used); - xar->toc_remaining -= used; - xar->offset += used; - xar->toc_total += outbytes; - PRINT_TOC(d, outbytes); - - xr = XML_Parse(parser, d, outbytes, xar->toc_remaining == 0); - if (xr == XML_STATUS_ERROR) { - XML_ParserFree(parser); - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "XML Parsing failed"); - return (ARCHIVE_FATAL); - } - } - XML_ParserFree(parser); - return (ARCHIVE_OK); -} -#endif /* defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) */ - -#endif /* Support xar format */ diff --git a/lib/libarchive/archive_read_support_format_zip.c b/lib/libarchive/archive_read_support_format_zip.c deleted file mode 100644 index a02a2c2..0000000 --- a/lib/libarchive/archive_read_support_format_zip.c +++ /dev/null @@ -1,950 +0,0 @@ -/*- - * Copyright (c) 2004 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#include -#ifdef HAVE_ZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_private.h" -#include "archive_endian.h" - -#ifndef HAVE_ZLIB_H -#include "archive_crc32.h" -#endif - -struct zip { - /* entry_bytes_remaining is the number of bytes we expect. */ - int64_t entry_bytes_remaining; - int64_t entry_offset; - - /* These count the number of bytes actually read for the entry. */ - int64_t entry_compressed_bytes_read; - int64_t entry_uncompressed_bytes_read; - - /* Running CRC32 of the decompressed data */ - unsigned long entry_crc32; - - unsigned version; - unsigned system; - unsigned flags; - unsigned compression; - const char * compression_name; - time_t mtime; - time_t ctime; - time_t atime; - mode_t mode; - uid_t uid; - gid_t gid; - - /* Flags to mark progress of decompression. */ - char decompress_init; - char end_of_entry; - - unsigned long crc32; - ssize_t filename_length; - ssize_t extra_length; - int64_t uncompressed_size; - int64_t compressed_size; - - unsigned char *uncompressed_buffer; - size_t uncompressed_buffer_size; -#ifdef HAVE_ZLIB_H - z_stream stream; - char stream_valid; -#endif - - struct archive_string pathname; - struct archive_string extra; - char format_name[64]; -}; - -#define ZIP_LENGTH_AT_END 8 - -struct zip_file_header { - char signature[4]; - char version[2]; - char flags[2]; - char compression[2]; - char timedate[4]; - char crc32[4]; - char compressed_size[4]; - char uncompressed_size[4]; - char filename_length[2]; - char extra_length[2]; -}; - -static const char *compression_names[] = { - "uncompressed", - "shrinking", - "reduced-1", - "reduced-2", - "reduced-3", - "reduced-4", - "imploded", - "reserved", - "deflation" -}; - -static int archive_read_format_zip_bid(struct archive_read *); -static int archive_read_format_zip_cleanup(struct archive_read *); -static int archive_read_format_zip_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_zip_read_data_skip(struct archive_read *a); -static int archive_read_format_zip_read_header(struct archive_read *, - struct archive_entry *); -static int search_next_signature(struct archive_read *); -static int zip_read_data_deflate(struct archive_read *a, const void **buff, - size_t *size, off_t *offset); -static int zip_read_data_none(struct archive_read *a, const void **buff, - size_t *size, off_t *offset); -static int zip_read_file_header(struct archive_read *a, - struct archive_entry *entry, struct zip *zip); -static time_t zip_time(const char *); -static void process_extra(const void* extra, struct zip* zip); - -int -archive_read_support_format_zip(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct zip *zip; - int r; - - zip = (struct zip *)malloc(sizeof(*zip)); - if (zip == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate zip data"); - return (ARCHIVE_FATAL); - } - memset(zip, 0, sizeof(*zip)); - - r = __archive_read_register_format(a, - zip, - "zip", - archive_read_format_zip_bid, - NULL, - archive_read_format_zip_read_header, - archive_read_format_zip_read_data, - archive_read_format_zip_read_data_skip, - archive_read_format_zip_cleanup); - - if (r != ARCHIVE_OK) - free(zip); - return (ARCHIVE_OK); -} - - -static int -archive_read_format_zip_bid(struct archive_read *a) -{ - const char *p; - const void *buff; - ssize_t bytes_avail, offset; - - if ((p = __archive_read_ahead(a, 4, NULL)) == NULL) - return (-1); - - /* - * Bid of 30 here is: 16 bits for "PK", - * next 16-bit field has four options (-2 bits). - * 16 + 16-2 = 30. - */ - if (p[0] == 'P' && p[1] == 'K') { - if ((p[2] == '\001' && p[3] == '\002') - || (p[2] == '\003' && p[3] == '\004') - || (p[2] == '\005' && p[3] == '\006') - || (p[2] == '\007' && p[3] == '\010') - || (p[2] == '0' && p[3] == '0')) - return (30); - } - - /* - * Attempt to handle self-extracting archives - * by noting a PE header and searching forward - * up to 128k for a 'PK\003\004' marker. - */ - if (p[0] == 'M' && p[1] == 'Z') { - /* - * TODO: Optimize by initializing 'offset' to an - * estimate of the likely start of the archive data - * based on values in the PE header. Note that we - * don't need to be exact, but we mustn't skip too - * far. The search below will compensate if we - * undershoot. - */ - offset = 0; - while (offset < 124000) { - /* Get 4k of data beyond where we stopped. */ - buff = __archive_read_ahead(a, offset + 4096, - &bytes_avail); - if (buff == NULL) - break; - p = (const char *)buff + offset; - while (p + 9 < (const char *)buff + bytes_avail) { - if (p[0] == 'P' && p[1] == 'K' /* signature */ - && p[2] == 3 && p[3] == 4 /* File entry */ - && p[8] == 8 /* compression == deflate */ - && p[9] == 0 /* High byte of compression */ - ) - { - return (30); - } - ++p; - } - offset = p - (const char *)buff; - } - } - - return (0); -} - -/* - * Search forward for a "PK\003\004" file header. This handles the - * case of self-extracting archives, where there is an executable - * prepended to the ZIP archive. - */ -static int -skip_sfx(struct archive_read *a) -{ - const void *h; - const char *p, *q; - size_t skip; - ssize_t bytes; - - /* - * TODO: We should be able to skip forward by a bunch - * by lifting some values from the PE header. We don't - * need to be exact (we're still going to search forward - * to find the header), but it will speed things up and - * reduce the chance of a false positive. - */ - for (;;) { - h = __archive_read_ahead(a, 4, &bytes); - if (bytes < 4) - return (ARCHIVE_FATAL); - p = h; - q = p + bytes; - - /* - * Scan ahead until we find something that looks - * like the zip header. - */ - while (p + 4 < q) { - switch (p[3]) { - case '\004': - /* TODO: Additional verification here. */ - if (memcmp("PK\003\004", p, 4) == 0) { - skip = p - (const char *)h; - __archive_read_consume(a, skip); - return (ARCHIVE_OK); - } - p += 4; - break; - case '\003': p += 1; break; - case 'K': p += 2; break; - case 'P': p += 3; break; - default: p += 4; break; - } - } - skip = p - (const char *)h; - __archive_read_consume(a, skip); - } -} - -static int -archive_read_format_zip_read_header(struct archive_read *a, - struct archive_entry *entry) -{ - const void *h; - const char *signature; - struct zip *zip; - int r = ARCHIVE_OK, r1; - - a->archive.archive_format = ARCHIVE_FORMAT_ZIP; - if (a->archive.archive_format_name == NULL) - a->archive.archive_format_name = "ZIP"; - - zip = (struct zip *)(a->format->data); - zip->decompress_init = 0; - zip->end_of_entry = 0; - zip->entry_uncompressed_bytes_read = 0; - zip->entry_compressed_bytes_read = 0; - zip->entry_crc32 = crc32(0, NULL, 0); - if ((h = __archive_read_ahead(a, 4, NULL)) == NULL) - return (ARCHIVE_FATAL); - - signature = (const char *)h; - if (signature[0] == 'M' && signature[1] == 'Z') { - /* This is an executable? Must be self-extracting... */ - r = skip_sfx(a); - if (r < ARCHIVE_WARN) - return (r); - if ((h = __archive_read_ahead(a, 4, NULL)) == NULL) - return (ARCHIVE_FATAL); - signature = (const char *)h; - } - - /* If we don't see a PK signature here, scan forward. */ - if (signature[0] != 'P' || signature[1] != 'K') { - r = search_next_signature(a); - if (r != ARCHIVE_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Bad ZIP file"); - return (ARCHIVE_FATAL); - } - if ((h = __archive_read_ahead(a, 4, NULL)) == NULL) - return (ARCHIVE_FATAL); - signature = (const char *)h; - } - - /* - * "PK00" signature is used for "split" archives that - * only have a single segment. This means we can just - * skip the PK00; the first real file header should follow. - */ - if (signature[2] == '0' && signature[3] == '0') { - __archive_read_consume(a, 4); - if ((h = __archive_read_ahead(a, 4, NULL)) == NULL) - return (ARCHIVE_FATAL); - signature = (const char *)h; - if (signature[0] != 'P' || signature[1] != 'K') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Bad ZIP file"); - return (ARCHIVE_FATAL); - } - } - - if (signature[2] == '\001' && signature[3] == '\002') { - /* Beginning of central directory. */ - return (ARCHIVE_EOF); - } - - if (signature[2] == '\003' && signature[3] == '\004') { - /* Regular file entry. */ - r1 = zip_read_file_header(a, entry, zip); - if (r1 != ARCHIVE_OK) - return (r1); - return (r); - } - - if (signature[2] == '\005' && signature[3] == '\006') { - /* End-of-archive record. */ - return (ARCHIVE_EOF); - } - - if (signature[2] == '\007' && signature[3] == '\010') { - /* - * We should never encounter this record here; - * see ZIP_LENGTH_AT_END handling below for details. - */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Bad ZIP file: Unexpected end-of-entry record"); - return (ARCHIVE_FATAL); - } - - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Damaged ZIP file or unsupported format variant (%d,%d)", - signature[2], signature[3]); - return (ARCHIVE_FATAL); -} - -static int -search_next_signature(struct archive_read *a) -{ - const void *h; - const char *p, *q; - size_t skip; - ssize_t bytes; - int64_t skipped = 0; - - for (;;) { - h = __archive_read_ahead(a, 4, &bytes); - if (h == NULL) - return (ARCHIVE_FATAL); - p = h; - q = p + bytes; - - while (p + 4 <= q) { - if (p[0] == 'P' && p[1] == 'K') { - if ((p[2] == '\001' && p[3] == '\002') - || (p[2] == '\003' && p[3] == '\004') - || (p[2] == '\005' && p[3] == '\006') - || (p[2] == '\007' && p[3] == '\010') - || (p[2] == '0' && p[3] == '0')) { - skip = p - (const char *)h; - __archive_read_consume(a, skip); - return (ARCHIVE_OK); - } - } - ++p; - } - skip = p - (const char *)h; - __archive_read_consume(a, skip); - skipped += skip; - } -} - -static int -zip_read_file_header(struct archive_read *a, struct archive_entry *entry, - struct zip *zip) -{ - const struct zip_file_header *p; - const void *h; - - if ((p = __archive_read_ahead(a, sizeof *p, NULL)) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file header"); - return (ARCHIVE_FATAL); - } - - zip->version = p->version[0]; - zip->system = p->version[1]; - zip->flags = archive_le16dec(p->flags); - zip->compression = archive_le16dec(p->compression); - if (zip->compression < - sizeof(compression_names)/sizeof(compression_names[0])) - zip->compression_name = compression_names[zip->compression]; - else - zip->compression_name = "??"; - zip->mtime = zip_time(p->timedate); - zip->ctime = 0; - zip->atime = 0; - zip->mode = 0; - zip->uid = 0; - zip->gid = 0; - zip->crc32 = archive_le32dec(p->crc32); - zip->filename_length = archive_le16dec(p->filename_length); - zip->extra_length = archive_le16dec(p->extra_length); - zip->uncompressed_size = archive_le32dec(p->uncompressed_size); - zip->compressed_size = archive_le32dec(p->compressed_size); - - __archive_read_consume(a, sizeof(struct zip_file_header)); - - - /* Read the filename. */ - if ((h = __archive_read_ahead(a, zip->filename_length, NULL)) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file header"); - return (ARCHIVE_FATAL); - } - if (archive_string_ensure(&zip->pathname, zip->filename_length) == NULL) - __archive_errx(1, "Out of memory"); - archive_strncpy(&zip->pathname, h, zip->filename_length); - __archive_read_consume(a, zip->filename_length); - archive_entry_set_pathname(entry, zip->pathname.s); - - if (zip->pathname.s[archive_strlen(&zip->pathname) - 1] == '/') - zip->mode = AE_IFDIR | 0777; - else - zip->mode = AE_IFREG | 0777; - - /* Read the extra data. */ - if ((h = __archive_read_ahead(a, zip->extra_length, NULL)) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file header"); - return (ARCHIVE_FATAL); - } - process_extra(h, zip); - __archive_read_consume(a, zip->extra_length); - - /* Populate some additional entry fields: */ - archive_entry_set_mode(entry, zip->mode); - archive_entry_set_uid(entry, zip->uid); - archive_entry_set_gid(entry, zip->gid); - archive_entry_set_mtime(entry, zip->mtime, 0); - archive_entry_set_ctime(entry, zip->ctime, 0); - archive_entry_set_atime(entry, zip->atime, 0); - /* Set the size only if it's meaningful. */ - if (0 == (zip->flags & ZIP_LENGTH_AT_END)) - archive_entry_set_size(entry, zip->uncompressed_size); - - zip->entry_bytes_remaining = zip->compressed_size; - zip->entry_offset = 0; - - /* If there's no body, force read_data() to return EOF immediately. */ - if (0 == (zip->flags & ZIP_LENGTH_AT_END) - && zip->entry_bytes_remaining < 1) - zip->end_of_entry = 1; - - /* Set up a more descriptive format name. */ - sprintf(zip->format_name, "ZIP %d.%d (%s)", - zip->version / 10, zip->version % 10, - zip->compression_name); - a->archive.archive_format_name = zip->format_name; - - return (ARCHIVE_OK); -} - -/* Convert an MSDOS-style date/time into Unix-style time. */ -static time_t -zip_time(const char *p) -{ - int msTime, msDate; - struct tm ts; - - msTime = (0xff & (unsigned)p[0]) + 256 * (0xff & (unsigned)p[1]); - msDate = (0xff & (unsigned)p[2]) + 256 * (0xff & (unsigned)p[3]); - - memset(&ts, 0, sizeof(ts)); - ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */ - ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */ - ts.tm_mday = msDate & 0x1f; /* Day of month. */ - ts.tm_hour = (msTime >> 11) & 0x1f; - ts.tm_min = (msTime >> 5) & 0x3f; - ts.tm_sec = (msTime << 1) & 0x3e; - ts.tm_isdst = -1; - return mktime(&ts); -} - -static int -archive_read_format_zip_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) -{ - int r; - struct zip *zip; - - zip = (struct zip *)(a->format->data); - - /* - * If we hit end-of-entry last time, clean up and return - * ARCHIVE_EOF this time. - */ - if (zip->end_of_entry) { - *offset = zip->entry_uncompressed_bytes_read; - *size = 0; - *buff = NULL; - return (ARCHIVE_EOF); - } - - switch(zip->compression) { - case 0: /* No compression. */ - r = zip_read_data_none(a, buff, size, offset); - break; - case 8: /* Deflate compression. */ - r = zip_read_data_deflate(a, buff, size, offset); - break; - default: /* Unsupported compression. */ - *buff = NULL; - *size = 0; - *offset = 0; - /* Return a warning. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Unsupported ZIP compression method (%s)", - zip->compression_name); - if (zip->flags & ZIP_LENGTH_AT_END) { - /* - * ZIP_LENGTH_AT_END requires us to - * decompress the entry in order to - * skip it, but we don't know this - * compression method, so we give up. - */ - r = ARCHIVE_FATAL; - } else { - /* We can't decompress this entry, but we will - * be able to skip() it and try the next entry. */ - r = ARCHIVE_WARN; - } - break; - } - if (r != ARCHIVE_OK) - return (r); - /* Update checksum */ - if (*size) - zip->entry_crc32 = crc32(zip->entry_crc32, *buff, *size); - /* If we hit the end, swallow any end-of-data marker. */ - if (zip->end_of_entry) { - if (zip->flags & ZIP_LENGTH_AT_END) { - const char *p; - - if ((p = __archive_read_ahead(a, 16, NULL)) == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP end-of-file record"); - return (ARCHIVE_FATAL); - } - zip->crc32 = archive_le32dec(p + 4); - zip->compressed_size = archive_le32dec(p + 8); - zip->uncompressed_size = archive_le32dec(p + 12); - __archive_read_consume(a, 16); - } - /* Check file size, CRC against these values. */ - if (zip->compressed_size != zip->entry_compressed_bytes_read) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP compressed data is wrong size"); - return (ARCHIVE_WARN); - } - /* Size field only stores the lower 32 bits of the actual size. */ - if ((zip->uncompressed_size & UINT32_MAX) - != (zip->entry_uncompressed_bytes_read & UINT32_MAX)) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP uncompressed data is wrong size"); - return (ARCHIVE_WARN); - } - /* Check computed CRC against header */ - if (zip->crc32 != zip->entry_crc32) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP bad CRC: 0x%lx should be 0x%lx", - zip->entry_crc32, zip->crc32); - return (ARCHIVE_WARN); - } - } - - /* Return EOF immediately if this is a non-regular file. */ - if (AE_IFREG != (zip->mode & AE_IFMT)) - return (ARCHIVE_EOF); - return (ARCHIVE_OK); -} - -/* - * Read "uncompressed" data. According to the current specification, - * if ZIP_LENGTH_AT_END is specified, then the size fields in the - * initial file header are supposed to be set to zero. This would, of - * course, make it impossible for us to read the archive, since we - * couldn't determine the end of the file data. Info-ZIP seems to - * include the real size fields both before and after the data in this - * case (the CRC only appears afterwards), so this works as you would - * expect. - * - * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets - * zip->end_of_entry if it consumes all of the data. - */ -static int -zip_read_data_none(struct archive_read *a, const void **buff, - size_t *size, off_t *offset) -{ - struct zip *zip; - ssize_t bytes_avail; - - zip = (struct zip *)(a->format->data); - - if (zip->entry_bytes_remaining == 0) { - *buff = NULL; - *size = 0; - *offset = zip->entry_offset; - zip->end_of_entry = 1; - return (ARCHIVE_OK); - } - /* - * Note: '1' here is a performance optimization. - * Recall that the decompression layer returns a count of - * available bytes; asking for more than that forces the - * decompressor to combine reads by copying data. - */ - *buff = __archive_read_ahead(a, 1, &bytes_avail); - if (bytes_avail <= 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file data"); - return (ARCHIVE_FATAL); - } - if (bytes_avail > zip->entry_bytes_remaining) - bytes_avail = zip->entry_bytes_remaining; - __archive_read_consume(a, bytes_avail); - *size = bytes_avail; - *offset = zip->entry_offset; - zip->entry_offset += *size; - zip->entry_bytes_remaining -= *size; - zip->entry_uncompressed_bytes_read += *size; - zip->entry_compressed_bytes_read += *size; - return (ARCHIVE_OK); -} - -#ifdef HAVE_ZLIB_H -static int -zip_read_data_deflate(struct archive_read *a, const void **buff, - size_t *size, off_t *offset) -{ - struct zip *zip; - ssize_t bytes_avail; - const void *compressed_buff; - int r; - - zip = (struct zip *)(a->format->data); - - /* If the buffer hasn't been allocated, allocate it now. */ - if (zip->uncompressed_buffer == NULL) { - zip->uncompressed_buffer_size = 32 * 1024; - zip->uncompressed_buffer - = (unsigned char *)malloc(zip->uncompressed_buffer_size); - if (zip->uncompressed_buffer == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory for ZIP decompression"); - return (ARCHIVE_FATAL); - } - } - - /* If we haven't yet read any data, initialize the decompressor. */ - if (!zip->decompress_init) { - if (zip->stream_valid) - r = inflateReset(&zip->stream); - else - r = inflateInit2(&zip->stream, - -15 /* Don't check for zlib header */); - if (r != Z_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Can't initialize ZIP decompression."); - return (ARCHIVE_FATAL); - } - /* Stream structure has been set up. */ - zip->stream_valid = 1; - /* We've initialized decompression for this stream. */ - zip->decompress_init = 1; - } - - /* - * Note: '1' here is a performance optimization. - * Recall that the decompression layer returns a count of - * available bytes; asking for more than that forces the - * decompressor to combine reads by copying data. - */ - compressed_buff = __archive_read_ahead(a, 1, &bytes_avail); - if (bytes_avail <= 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file body"); - return (ARCHIVE_FATAL); - } - - /* - * A bug in zlib.h: stream.next_in should be marked 'const' - * but isn't (the library never alters data through the - * next_in pointer, only reads it). The result: this ugly - * cast to remove 'const'. - */ - zip->stream.next_in = (Bytef *)(uintptr_t)(const void *)compressed_buff; - zip->stream.avail_in = bytes_avail; - zip->stream.total_in = 0; - zip->stream.next_out = zip->uncompressed_buffer; - zip->stream.avail_out = zip->uncompressed_buffer_size; - zip->stream.total_out = 0; - - r = inflate(&zip->stream, 0); - switch (r) { - case Z_OK: - break; - case Z_STREAM_END: - zip->end_of_entry = 1; - break; - case Z_MEM_ERROR: - archive_set_error(&a->archive, ENOMEM, - "Out of memory for ZIP decompression"); - return (ARCHIVE_FATAL); - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP decompression failed (%d)", r); - return (ARCHIVE_FATAL); - } - - /* Consume as much as the compressor actually used. */ - bytes_avail = zip->stream.total_in; - __archive_read_consume(a, bytes_avail); - zip->entry_bytes_remaining -= bytes_avail; - zip->entry_compressed_bytes_read += bytes_avail; - - *offset = zip->entry_offset; - *size = zip->stream.total_out; - zip->entry_uncompressed_bytes_read += *size; - *buff = zip->uncompressed_buffer; - zip->entry_offset += *size; - return (ARCHIVE_OK); -} -#else -static int -zip_read_data_deflate(struct archive_read *a, const void **buff, - size_t *size, off_t *offset) -{ - *buff = NULL; - *size = 0; - *offset = 0; - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "libarchive compiled without deflate support (no libz)"); - return (ARCHIVE_FATAL); -} -#endif - -static int -archive_read_format_zip_read_data_skip(struct archive_read *a) -{ - struct zip *zip; - const void *buff = NULL; - off_t bytes_skipped; - - zip = (struct zip *)(a->format->data); - - /* If we've already read to end of data, we're done. */ - if (zip->end_of_entry) - return (ARCHIVE_OK); - - /* - * If the length is at the end, we have no choice but - * to decompress all the data to find the end marker. - */ - if (zip->flags & ZIP_LENGTH_AT_END) { - size_t size; - off_t offset; - int r; - do { - r = archive_read_format_zip_read_data(a, &buff, - &size, &offset); - } while (r == ARCHIVE_OK); - return (r); - } - - /* - * If the length is at the beginning, we can skip the - * compressed data much more quickly. - */ - bytes_skipped = __archive_read_skip(a, zip->entry_bytes_remaining); - if (bytes_skipped < 0) - return (ARCHIVE_FATAL); - - /* This entry is finished and done. */ - zip->end_of_entry = 1; - return (ARCHIVE_OK); -} - -static int -archive_read_format_zip_cleanup(struct archive_read *a) -{ - struct zip *zip; - - zip = (struct zip *)(a->format->data); -#ifdef HAVE_ZLIB_H - if (zip->stream_valid) - inflateEnd(&zip->stream); -#endif - free(zip->uncompressed_buffer); - archive_string_free(&(zip->pathname)); - archive_string_free(&(zip->extra)); - free(zip); - (a->format->data) = NULL; - return (ARCHIVE_OK); -} - -/* - * The extra data is stored as a list of - * id1+size1+data1 + id2+size2+data2 ... - * triplets. id and size are 2 bytes each. - */ -static void -process_extra(const void* extra, struct zip* zip) -{ - int offset = 0; - const char *p = (const char *)extra; - while (offset < zip->extra_length - 4) - { - unsigned short headerid = archive_le16dec(p + offset); - unsigned short datasize = archive_le16dec(p + offset + 2); - offset += 4; - if (offset + datasize > zip->extra_length) - break; -#ifdef DEBUG - fprintf(stderr, "Header id 0x%04x, length %d\n", - headerid, datasize); -#endif - switch (headerid) { - case 0x0001: - /* Zip64 extended information extra field. */ - if (datasize >= 8) - zip->uncompressed_size = archive_le64dec(p + offset); - if (datasize >= 16) - zip->compressed_size = archive_le64dec(p + offset + 8); - break; - case 0x5455: - { - /* Extended time field "UT". */ - int flags = p[offset]; - offset++; - datasize--; - /* Flag bits indicate which dates are present. */ - if (flags & 0x01) - { -#ifdef DEBUG - fprintf(stderr, "mtime: %lld -> %d\n", - (long long)zip->mtime, - archive_le32dec(p + offset)); -#endif - if (datasize < 4) - break; - zip->mtime = archive_le32dec(p + offset); - offset += 4; - datasize -= 4; - } - if (flags & 0x02) - { - if (datasize < 4) - break; - zip->atime = archive_le32dec(p + offset); - offset += 4; - datasize -= 4; - } - if (flags & 0x04) - { - if (datasize < 4) - break; - zip->ctime = archive_le32dec(p + offset); - offset += 4; - datasize -= 4; - } - break; - } - case 0x7855: - /* Info-ZIP Unix Extra Field (type 2) "Ux". */ -#ifdef DEBUG - fprintf(stderr, "uid %d gid %d\n", - archive_le16dec(p + offset), - archive_le16dec(p + offset + 2)); -#endif - if (datasize >= 2) - zip->uid = archive_le16dec(p + offset); - if (datasize >= 4) - zip->gid = archive_le16dec(p + offset + 2); - break; - case 0x7875: - /* Info-Zip Unix Extra Field (type 3) "ux". */ - break; - default: - break; - } - offset += datasize; - } -#ifdef DEBUG - if (offset != zip->extra_length) - { - fprintf(stderr, - "Extra data field contents do not match reported size!"); - } -#endif -} diff --git a/lib/libarchive/archive_string.c b/lib/libarchive/archive_string.c deleted file mode 100644 index c67182d..0000000 --- a/lib/libarchive/archive_string.c +++ /dev/null @@ -1,453 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -/* - * Basic resizable string support, to simplify manipulating arbitrary-sized - * strings while minimizing heap activity. - */ - -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_WCHAR_H -#include -#endif -#if defined(_WIN32) && !defined(__CYGWIN__) -#include -#endif - -#include "archive_private.h" -#include "archive_string.h" - -struct archive_string * -__archive_string_append(struct archive_string *as, const char *p, size_t s) -{ - if (__archive_string_ensure(as, as->length + s + 1) == NULL) - __archive_errx(1, "Out of memory"); - memcpy(as->s + as->length, p, s); - as->s[as->length + s] = 0; - as->length += s; - return (as); -} - -void -__archive_string_copy(struct archive_string *dest, struct archive_string *src) -{ - if (src->length == 0) - dest->length = 0; - else { - if (__archive_string_ensure(dest, src->length + 1) == NULL) - __archive_errx(1, "Out of memory"); - memcpy(dest->s, src->s, src->length); - dest->length = src->length; - dest->s[dest->length] = 0; - } -} - -void -__archive_string_concat(struct archive_string *dest, struct archive_string *src) -{ - if (src->length > 0) { - if (__archive_string_ensure(dest, dest->length + src->length + 1) == NULL) - __archive_errx(1, "Out of memory"); - memcpy(dest->s + dest->length, src->s, src->length); - dest->length += src->length; - dest->s[dest->length] = 0; - } -} - -void -__archive_string_free(struct archive_string *as) -{ - as->length = 0; - as->buffer_length = 0; - if (as->s != NULL) { - free(as->s); - as->s = NULL; - } -} - -/* Returns NULL on any allocation failure. */ -struct archive_string * -__archive_string_ensure(struct archive_string *as, size_t s) -{ - /* If buffer is already big enough, don't reallocate. */ - if (as->s && (s <= as->buffer_length)) - return (as); - - /* - * Growing the buffer at least exponentially ensures that - * append operations are always linear in the number of - * characters appended. Using a smaller growth rate for - * larger buffers reduces memory waste somewhat at the cost of - * a larger constant factor. - */ - if (as->buffer_length < 32) - /* Start with a minimum 32-character buffer. */ - as->buffer_length = 32; - else if (as->buffer_length < 8192) - /* Buffers under 8k are doubled for speed. */ - as->buffer_length += as->buffer_length; - else { - /* Buffers 8k and over grow by at least 25% each time. */ - size_t old_length = as->buffer_length; - as->buffer_length += as->buffer_length / 4; - /* Be safe: If size wraps, release buffer and return NULL. */ - if (as->buffer_length < old_length) { - free(as->s); - as->s = NULL; - return (NULL); - } - } - /* - * The computation above is a lower limit to how much we'll - * grow the buffer. In any case, we have to grow it enough to - * hold the request. - */ - if (as->buffer_length < s) - as->buffer_length = s; - /* Now we can reallocate the buffer. */ - as->s = (char *)realloc(as->s, as->buffer_length); - if (as->s == NULL) - return (NULL); - return (as); -} - -struct archive_string * -__archive_strncat(struct archive_string *as, const void *_p, size_t n) -{ - size_t s; - const char *p, *pp; - - p = (const char *)_p; - - /* Like strlen(p), except won't examine positions beyond p[n]. */ - s = 0; - pp = p; - while (s < n && *pp) { - pp++; - s++; - } - return (__archive_string_append(as, p, s)); -} - -struct archive_string * -__archive_strappend_char(struct archive_string *as, char c) -{ - return (__archive_string_append(as, &c, 1)); -} - -/* - * Translates a wide character string into UTF-8 and appends - * to the archive_string. Note: returns NULL if conversion fails, - * but still leaves a best-effort conversion in the argument as. - */ -struct archive_string * -__archive_strappend_w_utf8(struct archive_string *as, const wchar_t *w) -{ - char *p; - unsigned wc; - char buff[256]; - struct archive_string *return_val = as; - - /* - * Convert one wide char at a time into 'buff', whenever that - * fills, append it to the string. - */ - p = buff; - while (*w != L'\0') { - /* Flush the buffer when we have <=16 bytes free. */ - /* (No encoding has a single character >16 bytes.) */ - if ((size_t)(p - buff) >= (size_t)(sizeof(buff) - 16)) { - *p = '\0'; - archive_strcat(as, buff); - p = buff; - } - wc = *w++; - /* If this is a surrogate pair, assemble the full code point.*/ - /* Note: wc must not be wchar_t here, because the full code - * point can be more than 16 bits! */ - if (wc >= 0xD800 && wc <= 0xDBff - && *w >= 0xDC00 && *w <= 0xDFFF) { - wc -= 0xD800; - wc *= 0x400; - wc += (*w - 0xDC00); - wc += 0x10000; - ++w; - } - /* Translate code point to UTF8 */ - if (wc <= 0x7f) { - *p++ = (char)wc; - } else if (wc <= 0x7ff) { - *p++ = 0xc0 | ((wc >> 6) & 0x1f); - *p++ = 0x80 | (wc & 0x3f); - } else if (wc <= 0xffff) { - *p++ = 0xe0 | ((wc >> 12) & 0x0f); - *p++ = 0x80 | ((wc >> 6) & 0x3f); - *p++ = 0x80 | (wc & 0x3f); - } else if (wc <= 0x1fffff) { - *p++ = 0xf0 | ((wc >> 18) & 0x07); - *p++ = 0x80 | ((wc >> 12) & 0x3f); - *p++ = 0x80 | ((wc >> 6) & 0x3f); - *p++ = 0x80 | (wc & 0x3f); - } else { - /* Unicode has no codes larger than 0x1fffff. */ - /* TODO: use \uXXXX escape here instead of ? */ - *p++ = '?'; - return_val = NULL; - } - } - *p = '\0'; - archive_strcat(as, buff); - return (return_val); -} - -static int -utf8_to_unicode(int *pwc, const char *s, size_t n) -{ - int ch; - - /* - * Decode 1-4 bytes depending on the value of the first byte. - */ - ch = (unsigned char)*s; - if (ch == 0) { - return (0); /* Standard: return 0 for end-of-string. */ - } - if ((ch & 0x80) == 0) { - *pwc = ch & 0x7f; - return (1); - } - if ((ch & 0xe0) == 0xc0) { - if (n < 2) - return (-1); - if ((s[1] & 0xc0) != 0x80) return (-1); - *pwc = ((ch & 0x1f) << 6) | (s[1] & 0x3f); - return (2); - } - if ((ch & 0xf0) == 0xe0) { - if (n < 3) - return (-1); - if ((s[1] & 0xc0) != 0x80) return (-1); - if ((s[2] & 0xc0) != 0x80) return (-1); - *pwc = ((ch & 0x0f) << 12) - | ((s[1] & 0x3f) << 6) - | (s[2] & 0x3f); - return (3); - } - if ((ch & 0xf8) == 0xf0) { - if (n < 4) - return (-1); - if ((s[1] & 0xc0) != 0x80) return (-1); - if ((s[2] & 0xc0) != 0x80) return (-1); - if ((s[3] & 0xc0) != 0x80) return (-1); - *pwc = ((ch & 0x07) << 18) - | ((s[1] & 0x3f) << 12) - | ((s[2] & 0x3f) << 6) - | (s[3] & 0x3f); - return (4); - } - /* Invalid first byte. */ - return (-1); -} - -/* - * Return a wide-character Unicode string by converting this archive_string - * from UTF-8. We assume that systems with 16-bit wchar_t always use - * UTF16 and systems with 32-bit wchar_t can accept UCS4. - */ -wchar_t * -__archive_string_utf8_w(struct archive_string *as) -{ - wchar_t *ws, *dest; - int wc, wc2;/* Must be large enough for a 21-bit Unicode code point. */ - const char *src; - int n; - - ws = (wchar_t *)malloc((as->length + 1) * sizeof(wchar_t)); - if (ws == NULL) - __archive_errx(1, "Out of memory"); - dest = ws; - src = as->s; - while (*src != '\0') { - n = utf8_to_unicode(&wc, src, 8); - if (n == 0) - break; - if (n < 0) { - free(ws); - return (NULL); - } - src += n; - if (wc >= 0xDC00 && wc <= 0xDBFF) { - /* This is a leading surrogate; some idiot - * has translated UTF16 to UTF8 without combining - * surrogates; rebuild the full code point before - * continuing. */ - n = utf8_to_unicode(&wc2, src, 8); - if (n < 0) { - free(ws); - return (NULL); - } - if (n == 0) /* Ignore the leading surrogate */ - break; - if (wc2 < 0xDC00 || wc2 > 0xDFFF) { - /* If the second character isn't a - * trailing surrogate, then someone - * has really screwed up and this is - * invalid. */ - free(ws); - return (NULL); - } else { - src += n; - wc -= 0xD800; - wc *= 0x400; - wc += wc2 - 0xDC00; - wc += 0x10000; - } - } - if ((sizeof(wchar_t) < 4) && (wc > 0xffff)) { - /* We have a code point that won't fit into a - * wchar_t; convert it to a surrogate pair. */ - wc -= 0x10000; - *dest++ = ((wc >> 10) & 0x3ff) + 0xD800; - *dest++ = (wc & 0x3ff) + 0xDC00; - } else - *dest++ = wc; - } - *dest = L'\0'; - return (ws); -} - -#if defined(_WIN32) && !defined(__CYGWIN__) - -/* - * Translates a wide character string into current locale character set - * and appends to the archive_string. Note: returns NULL if conversion - * fails. - * - * Win32 builds use WideCharToMultiByte from the Windows API. - * (Maybe Cygwin should too? WideCharToMultiByte will know a - * lot more about local character encodings than the wcrtomb() - * wrapper is going to know.) - */ -struct archive_string * -__archive_strappend_w_mbs(struct archive_string *as, const wchar_t *w) -{ - char *p; - int l, wl; - BOOL useDefaultChar = FALSE; - - wl = (int)wcslen(w); - l = wl * 4 + 4; - p = malloc(l); - if (p == NULL) - __archive_errx(1, "Out of memory"); - /* To check a useDefaultChar is to simulate error handling of - * the my_wcstombs() which is running on non Windows system with - * wctomb(). - * And to set NULL for last argument is necessary when a codepage - * is not CP_ACP(current locale). - */ - l = WideCharToMultiByte(CP_ACP, 0, w, wl, p, l, NULL, &useDefaultChar); - if (l == 0) { - free(p); - return (NULL); - } - __archive_string_append(as, p, l); - free(p); - return (as); -} - -#else - -/* - * Translates a wide character string into current locale character set - * and appends to the archive_string. Note: returns NULL if conversion - * fails. - * - * Non-Windows uses ISO C wcrtomb() or wctomb() to perform the conversion - * one character at a time. If a non-Windows platform doesn't have - * either of these, fall back to the built-in UTF8 conversion. - */ -struct archive_string * -__archive_strappend_w_mbs(struct archive_string *as, const wchar_t *w) -{ -#if !defined(HAVE_WCTOMB) && !defined(HAVE_WCRTOMB) - /* If there's no built-in locale support, fall back to UTF8 always. */ - return __archive_strappend_w_utf8(as, w); -#else - /* We cannot use the standard wcstombs() here because it - * cannot tell us how big the output buffer should be. So - * I've built a loop around wcrtomb() or wctomb() that - * converts a character at a time and resizes the string as - * needed. We prefer wcrtomb() when it's available because - * it's thread-safe. */ - int n; - char *p; - char buff[256]; -#if HAVE_WCRTOMB - mbstate_t shift_state; - - memset(&shift_state, 0, sizeof(shift_state)); -#else - /* Clear the shift state before starting. */ - wctomb(NULL, L'\0'); -#endif - - /* - * Convert one wide char at a time into 'buff', whenever that - * fills, append it to the string. - */ - p = buff; - while (*w != L'\0') { - /* Flush the buffer when we have <=16 bytes free. */ - /* (No encoding has a single character >16 bytes.) */ - if ((size_t)(p - buff) >= (size_t)(sizeof(buff) - MB_CUR_MAX)) { - *p = '\0'; - archive_strcat(as, buff); - p = buff; - } -#if HAVE_WCRTOMB - n = wcrtomb(p, *w++, &shift_state); -#else - n = wctomb(p, *w++); -#endif - if (n == -1) - return (NULL); - p += n; - } - *p = '\0'; - archive_strcat(as, buff); - return (as); -#endif -} - -#endif /* _WIN32 && ! __CYGWIN__ */ diff --git a/lib/libarchive/archive_string.h b/lib/libarchive/archive_string.h deleted file mode 100644 index f0655d1..0000000 --- a/lib/libarchive/archive_string.h +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - * - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifndef ARCHIVE_STRING_H_INCLUDED -#define ARCHIVE_STRING_H_INCLUDED - -#include -#ifdef HAVE_STDLIB_H -#include /* required for wchar_t on some systems */ -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_WCHAR_H -#include -#endif - -#include "archive.h" - -/* - * Basic resizable/reusable string support a la Java's "StringBuffer." - * - * Unlike sbuf(9), the buffers here are fully reusable and track the - * length throughout. - * - * Note that all visible symbols here begin with "__archive" as they - * are internal symbols not intended for anyone outside of this library - * to see or use. - */ - -struct archive_string { - char *s; /* Pointer to the storage */ - size_t length; /* Length of 's' */ - size_t buffer_length; /* Length of malloc-ed storage */ -}; - -/* Initialize an archive_string object on the stack or elsewhere. */ -#define archive_string_init(a) \ - do { (a)->s = NULL; (a)->length = 0; (a)->buffer_length = 0; } while(0) - -/* Append a C char to an archive_string, resizing as necessary. */ -struct archive_string * -__archive_strappend_char(struct archive_string *, char); -#define archive_strappend_char __archive_strappend_char - -/* Convert a wide-char string to UTF-8 and append the result. */ -struct archive_string * -__archive_strappend_w_utf8(struct archive_string *, const wchar_t *); -#define archive_strappend_w_utf8 __archive_strappend_w_utf8 - -/* Convert a wide-char string to current locale and append the result. */ -/* Returns NULL if conversion fails. */ -struct archive_string * -__archive_strappend_w_mbs(struct archive_string *, const wchar_t *); -#define archive_strappend_w_mbs __archive_strappend_w_mbs - -/* Basic append operation. */ -struct archive_string * -__archive_string_append(struct archive_string *as, const char *p, size_t s); - -/* Copy one archive_string to another */ -void -__archive_string_copy(struct archive_string *dest, struct archive_string *src); -#define archive_string_copy(dest, src) \ - __archive_string_copy(dest, src) - -/* Concatenate one archive_string to another */ -void -__archive_string_concat(struct archive_string *dest, struct archive_string *src); -#define archive_string_concat(dest, src) \ - __archive_string_concat(dest, src) - -/* Ensure that the underlying buffer is at least as large as the request. */ -struct archive_string * -__archive_string_ensure(struct archive_string *, size_t); -#define archive_string_ensure __archive_string_ensure - -/* Append C string, which may lack trailing \0. */ -/* The source is declared void * here because this gets used with - * "signed char *", "unsigned char *" and "char *" arguments. - * Declaring it "char *" as with some of the other functions just - * leads to a lot of extra casts. */ -struct archive_string * -__archive_strncat(struct archive_string *, const void *, size_t); -#define archive_strncat __archive_strncat - -/* Append a C string to an archive_string, resizing as necessary. */ -#define archive_strcat(as,p) __archive_string_append((as),(p),strlen(p)) - -/* Copy a C string to an archive_string, resizing as necessary. */ -#define archive_strcpy(as,p) \ - ((as)->length = 0, __archive_string_append((as), (p), p == NULL ? 0 : strlen(p))) - -/* Copy a C string to an archive_string with limit, resizing as necessary. */ -#define archive_strncpy(as,p,l) \ - ((as)->length=0, archive_strncat((as), (p), (l))) - -/* Return length of string. */ -#define archive_strlen(a) ((a)->length) - -/* Set string length to zero. */ -#define archive_string_empty(a) ((a)->length = 0) - -/* Release any allocated storage resources. */ -void __archive_string_free(struct archive_string *); -#define archive_string_free __archive_string_free - -/* Like 'vsprintf', but resizes the underlying string as necessary. */ -void __archive_string_vsprintf(struct archive_string *, const char *, - va_list) __LA_PRINTF(2, 0); -#define archive_string_vsprintf __archive_string_vsprintf - -void __archive_string_sprintf(struct archive_string *, const char *, ...) - __LA_PRINTF(2, 3); -#define archive_string_sprintf __archive_string_sprintf - -/* Allocates a fresh buffer and converts as (assumed to be UTF-8) into it. - * Returns NULL if conversion failed in any way. */ -wchar_t *__archive_string_utf8_w(struct archive_string *as); - - -#endif diff --git a/lib/libarchive/archive_string_sprintf.c b/lib/libarchive/archive_string_sprintf.c deleted file mode 100644 index 9199106..0000000 --- a/lib/libarchive/archive_string_sprintf.c +++ /dev/null @@ -1,164 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -/* - * The use of printf()-family functions can be troublesome - * for space-constrained applications. In addition, correctly - * implementing this function in terms of vsnprintf() requires - * two calls (one to determine the size, another to format the - * result), which in turn requires duplicating the argument list - * using va_copy, which isn't yet universally available. - * - * So, I've implemented a bare minimum of printf()-like capability - * here. This is only used to format error messages, so doesn't - * require any floating-point support or field-width handling. - */ - -#include - -#include "archive_string.h" -#include "archive_private.h" - -/* - * Utility functions to format signed/unsigned integers and append - * them to an archive_string. - */ -static void -append_uint(struct archive_string *as, uintmax_t d, unsigned base) -{ - static const char *digits = "0123456789abcdef"; - if (d >= base) - append_uint(as, d/base, base); - archive_strappend_char(as, digits[d % base]); -} - -static void -append_int(struct archive_string *as, intmax_t d, unsigned base) -{ - if (d < 0) { - archive_strappend_char(as, '-'); - d = -d; - } - append_uint(as, d, base); -} - - -void -__archive_string_sprintf(struct archive_string *as, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - archive_string_vsprintf(as, fmt, ap); - va_end(ap); -} - -/* - * Like 'vsprintf', but ensures the target is big enough, resizing if - * necessary. - */ -void -__archive_string_vsprintf(struct archive_string *as, const char *fmt, - va_list ap) -{ - char long_flag; - intmax_t s; /* Signed integer temp. */ - uintmax_t u; /* Unsigned integer temp. */ - const char *p, *p2; - - if (__archive_string_ensure(as, 64) == NULL) - __archive_errx(1, "Out of memory"); - - if (fmt == NULL) { - as->s[0] = 0; - return; - } - - for (p = fmt; *p != '\0'; p++) { - const char *saved_p = p; - - if (*p != '%') { - archive_strappend_char(as, *p); - continue; - } - - p++; - - long_flag = '\0'; - switch(*p) { - case 'j': - long_flag = 'j'; - p++; - break; - case 'l': - long_flag = 'l'; - p++; - break; - } - - switch (*p) { - case '%': - __archive_strappend_char(as, '%'); - break; - case 'c': - s = va_arg(ap, int); - __archive_strappend_char(as, s); - break; - case 'd': - switch(long_flag) { - case 'j': s = va_arg(ap, intmax_t); break; - case 'l': s = va_arg(ap, long); break; - default: s = va_arg(ap, int); break; - } - append_int(as, s, 10); - break; - case 's': - p2 = va_arg(ap, char *); - archive_strcat(as, p2); - break; - case 'o': case 'u': case 'x': case 'X': - /* Common handling for unsigned integer formats. */ - switch(long_flag) { - case 'j': u = va_arg(ap, uintmax_t); break; - case 'l': u = va_arg(ap, unsigned long); break; - default: u = va_arg(ap, unsigned int); break; - } - /* Format it in the correct base. */ - switch (*p) { - case 'o': append_uint(as, u, 8); break; - case 'u': append_uint(as, u, 10); break; - default: append_uint(as, u, 16); break; - } - break; - default: - /* Rewind and print the initial '%' literally. */ - p = saved_p; - archive_strappend_char(as, *p); - } - } -} diff --git a/lib/libarchive/archive_util.3 b/lib/libarchive/archive_util.3 deleted file mode 100644 index 69e3d7a..0000000 --- a/lib/libarchive/archive_util.3 +++ /dev/null @@ -1,160 +0,0 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd January 8, 2005 -.Dt ARCHIVE_UTIL 3 -.Os -.Sh NAME -.Nm archive_clear_error , -.Nm archive_compression , -.Nm archive_compression_name , -.Nm archive_copy_error , -.Nm archive_errno , -.Nm archive_error_string , -.Nm archive_file_count , -.Nm archive_format , -.Nm archive_format_name , -.Nm archive_set_error -.Nd libarchive utility functions -.Sh SYNOPSIS -.In archive.h -.Ft void -.Fn archive_clear_error "struct archive *" -.Ft int -.Fn archive_compression "struct archive *" -.Ft const char * -.Fn archive_compression_name "struct archive *" -.Ft void -.Fn archive_copy_error "struct archive *" "struct archive *" -.Ft int -.Fn archive_errno "struct archive *" -.Ft const char * -.Fn archive_error_string "struct archive *" -.Ft int -.Fn archive_file_count "struct archive *" -.Ft int -.Fn archive_format "struct archive *" -.Ft const char * -.Fn archive_format_name "struct archive *" -.Ft void -.Fo archive_set_error -.Fa "struct archive *" -.Fa "int error_code" -.Fa "const char *fmt" -.Fa "..." -.Fc -.Sh DESCRIPTION -These functions provide access to various information about the -.Tn struct archive -object used in the -.Xr libarchive 3 -library. -.Bl -tag -compact -width indent -.It Fn archive_clear_error -Clears any error information left over from a previous call. -Not generally used in client code. -.It Fn archive_compression -Returns a numeric code indicating the current compression. -This value is set by -.Fn archive_read_open . -.It Fn archive_compression_name -Returns a text description of the current compression suitable for display. -.It Fn archive_copy_error -Copies error information from one archive to another. -.It Fn archive_errno -Returns a numeric error code (see -.Xr errno 2 ) -indicating the reason for the most recent error return. -.It Fn archive_error_string -Returns a textual error message suitable for display. -The error message here is usually more specific than that -obtained from passing the result of -.Fn archive_errno -to -.Xr strerror 3 . -.It Fn archive_file_count -Returns a count of the number of files processed by this archive object. -The count is incremented by calls to -.Xr archive_write_header -or -.Xr archive_read_next_header . -.It Fn archive_format -Returns a numeric code indicating the format of the current -archive entry. -This value is set by a successful call to -.Fn archive_read_next_header . -Note that it is common for this value to change from -entry to entry. -For example, a tar archive might have several entries that -utilize GNU tar extensions and several entries that do not. -These entries will have different format codes. -.It Fn archive_format_name -A textual description of the format of the current entry. -.It Fn archive_set_error -Sets the numeric error code and error description that will be returned -by -.Fn archive_errno -and -.Fn archive_error_string . -This function should be used within I/O callbacks to set system-specific -error codes and error descriptions. -This function accepts a printf-like format string and arguments. -However, you should be careful to use only the following printf -format specifiers: -.Dq %c , -.Dq %d , -.Dq %jd , -.Dq %jo , -.Dq %ju , -.Dq %jx , -.Dq %ld , -.Dq %lo , -.Dq %lu , -.Dq %lx , -.Dq %o , -.Dq %u , -.Dq %s , -.Dq %x , -.Dq %% . -Field-width specifiers and other printf features are -not uniformly supported and should not be used. -.El -.Sh SEE ALSO -.Xr archive_read 3 , -.Xr archive_write 3 , -.Xr libarchive 3 , -.Xr printf 3 -.Sh HISTORY -The -.Nm libarchive -library first appeared in -.Fx 5.3 . -.Sh AUTHORS -.An -nosplit -The -.Nm libarchive -library was written by -.An Tim Kientzle Aq kientzle@acm.org . diff --git a/lib/libarchive/archive_util.c b/lib/libarchive/archive_util.c deleted file mode 100644 index 8f2b4c6..0000000 --- a/lib/libarchive/archive_util.c +++ /dev/null @@ -1,392 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_string.h" - -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* These disappear in libarchive 3.0 */ -/* Deprecated. */ -int -archive_api_feature(void) -{ - return (ARCHIVE_API_FEATURE); -} - -/* Deprecated. */ -int -archive_api_version(void) -{ - return (ARCHIVE_API_VERSION); -} - -/* Deprecated synonym for archive_version_number() */ -int -archive_version_stamp(void) -{ - return (archive_version_number()); -} - -/* Deprecated synonym for archive_version_string() */ -const char * -archive_version(void) -{ - return (archive_version_string()); -} -#endif - -int -archive_version_number(void) -{ - return (ARCHIVE_VERSION_NUMBER); -} - -const char * -archive_version_string(void) -{ - return (ARCHIVE_VERSION_STRING); -} - -int -archive_errno(struct archive *a) -{ - return (a->archive_error_number); -} - -const char * -archive_error_string(struct archive *a) -{ - - if (a->error != NULL && *a->error != '\0') - return (a->error); - else - return ("(Empty error message)"); -} - -int -archive_file_count(struct archive *a) -{ - return (a->file_count); -} - -int -archive_format(struct archive *a) -{ - return (a->archive_format); -} - -const char * -archive_format_name(struct archive *a) -{ - return (a->archive_format_name); -} - - -int -archive_compression(struct archive *a) -{ - return (a->compression_code); -} - -const char * -archive_compression_name(struct archive *a) -{ - return (a->compression_name); -} - - -/* - * Return a count of the number of compressed bytes processed. - */ -int64_t -archive_position_compressed(struct archive *a) -{ - return (a->raw_position); -} - -/* - * Return a count of the number of uncompressed bytes processed. - */ -int64_t -archive_position_uncompressed(struct archive *a) -{ - return (a->file_position); -} - -void -archive_clear_error(struct archive *a) -{ - archive_string_empty(&a->error_string); - a->error = NULL; - a->archive_error_number = 0; -} - -void -archive_set_error(struct archive *a, int error_number, const char *fmt, ...) -{ - va_list ap; - - a->archive_error_number = error_number; - if (fmt == NULL) { - a->error = NULL; - return; - } - - va_start(ap, fmt); - archive_string_vsprintf(&(a->error_string), fmt, ap); - va_end(ap); - a->error = a->error_string.s; -} - -void -archive_copy_error(struct archive *dest, struct archive *src) -{ - dest->archive_error_number = src->archive_error_number; - - archive_string_copy(&dest->error_string, &src->error_string); - dest->error = dest->error_string.s; -} - -void -__archive_errx(int retvalue, const char *msg) -{ - static const char *msg1 = "Fatal Internal Error in libarchive: "; - size_t s; - - s = write(2, msg1, strlen(msg1)); - (void)s; /* UNUSED */ - s = write(2, msg, strlen(msg)); - (void)s; /* UNUSED */ - s = write(2, "\n", 1); - (void)s; /* UNUSED */ - exit(retvalue); -} - -/* - * Parse option strings - * Detail of option format. - * - The option can accept: - * "opt-name", "!opt-name", "opt-name=value". - * - * - The option entries are separated by comma. - * e.g "compression=9,opt=XXX,opt-b=ZZZ" - * - * - The name of option string consist of '-' and alphabet - * but character '-' cannot be used for the first character. - * (Regular expression is [a-z][-a-z]+) - * - * - For a specfic format/filter, using the format name with ':'. - * e.g "zip:compression=9" - * (This "compression=9" option entry is for "zip" format only) - * - * If another entries follow it, those are not for - * the specfic format/filter. - * e.g handle "zip:compression=9,opt=XXX,opt-b=ZZZ" - * "zip" format/filter handler will get "compression=9" - * all format/filter handler will get "opt=XXX" - * all format/filter handler will get "opt-b=ZZZ" - * - * - Whitespace and tab are bypassed. - * - */ -int -__archive_parse_options(const char *p, const char *fn, int keysize, char *key, - int valsize, char *val) -{ - const char *p_org; - int apply; - int kidx, vidx; - int negative; - enum { - /* Requested for initialization. */ - INIT, - /* Finding format/filter-name and option-name. */ - F_BOTH, - /* Finding option-name only. - * (already detected format/filter-name) */ - F_NAME, - /* Getting option-value. */ - G_VALUE, - } state; - - p_org = p; - state = INIT; - kidx = vidx = negative = 0; - apply = 1; - while (*p) { - switch (state) { - case INIT: - kidx = vidx = 0; - negative = 0; - apply = 1; - state = F_BOTH; - break; - case F_BOTH: - case F_NAME: - if ((*p >= 'a' && *p <= 'z') || - (*p >= '0' && *p <= '9') || *p == '-') { - if (kidx == 0 && !(*p >= 'a' && *p <= 'z')) - /* Illegal sequence. */ - return (-1); - if (kidx >= keysize -1) - /* Too many characters. */ - return (-1); - key[kidx++] = *p++; - } else if (*p == '!') { - if (kidx != 0) - /* Illegal sequence. */ - return (-1); - negative = 1; - ++p; - } else if (*p == ',') { - if (kidx == 0) - /* Illegal sequence. */ - return (-1); - if (!negative) - val[vidx++] = '1'; - /* We have got boolean option data. */ - ++p; - if (apply) - goto complete; - else - /* This option does not apply to the - * format which the fn variable - * indicate. */ - state = INIT; - } else if (*p == ':') { - /* obuf data is format name */ - if (state == F_NAME) - /* We already found it. */ - return (-1); - if (kidx == 0) - /* Illegal sequence. */ - return (-1); - if (negative) - /* We cannot accept "!format-name:". */ - return (-1); - key[kidx] = '\0'; - if (strcmp(fn, key) != 0) - /* This option does not apply to the - * format which the fn variable - * indicate. */ - apply = 0; - kidx = 0; - ++p; - state = F_NAME; - } else if (*p == '=') { - if (kidx == 0) - /* Illegal sequence. */ - return (-1); - if (negative) - /* We cannot accept "!opt-name=value". */ - return (-1); - ++p; - state = G_VALUE; - } else if (*p == ' ') { - /* Pass the space character */ - ++p; - } else { - /* Illegal character. */ - return (-1); - } - break; - case G_VALUE: - if (*p == ',') { - if (vidx == 0) - /* Illegal sequence. */ - return (-1); - /* We have got option data. */ - ++p; - if (apply) - goto complete; - else - /* This option does not apply to the - * format which the fn variable - * indicate. */ - state = INIT; - } else if (*p == ' ') { - /* Pass the space character */ - ++p; - } else { - if (vidx >= valsize -1) - /* Too many characters. */ - return (-1); - val[vidx++] = *p++; - } - break; - } - } - - switch (state) { - case F_BOTH: - case F_NAME: - if (kidx != 0) { - if (!negative) - val[vidx++] = '1'; - /* We have got boolean option. */ - if (apply) - /* This option apply to the format which the - * fn variable indicate. */ - goto complete; - } - break; - case G_VALUE: - if (vidx == 0) - /* Illegal sequence. */ - return (-1); - /* We have got option value. */ - if (apply) - /* This option apply to the format which the fn - * variable indicate. */ - goto complete; - break; - case INIT:/* nothing */ - break; - } - - /* End of Option string. */ - return (0); - -complete: - key[kidx] = '\0'; - val[vidx] = '\0'; - /* Return a size which we've consumed for detecting option */ - return ((int)(p - p_org)); -} diff --git a/lib/libarchive/archive_virtual.c b/lib/libarchive/archive_virtual.c deleted file mode 100644 index 0214b00..0000000 --- a/lib/libarchive/archive_virtual.c +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" - -int -archive_write_close(struct archive *a) -{ - return ((a->vtable->archive_close)(a)); -} - -int -archive_read_close(struct archive *a) -{ - return ((a->vtable->archive_close)(a)); -} - -int -archive_write_free(struct archive *a) -{ - return ((a->vtable->archive_free)(a)); -} - -#if ARCHIVE_VERSION_NUMBER < 4000000 -/* For backwards compatibility; will be removed with libarchive 4.0. */ -int -archive_write_finish(struct archive *a) -{ - return ((a->vtable->archive_free)(a)); -} -#endif - -int -archive_read_free(struct archive *a) -{ - return ((a->vtable->archive_free)(a)); -} - -#if ARCHIVE_VERSION_NUMBER < 4000000 -/* For backwards compatibility; will be removed with libarchive 4.0. */ -int -archive_read_finish(struct archive *a) -{ - return ((a->vtable->archive_free)(a)); -} -#endif - -int -archive_write_header(struct archive *a, struct archive_entry *entry) -{ - ++a->file_count; - return ((a->vtable->archive_write_header)(a, entry)); -} - -int -archive_write_finish_entry(struct archive *a) -{ - return ((a->vtable->archive_write_finish_entry)(a)); -} - -ssize_t -archive_write_data(struct archive *a, const void *buff, size_t s) -{ - return ((a->vtable->archive_write_data)(a, buff, s)); -} - -ssize_t -archive_write_data_block(struct archive *a, const void *buff, size_t s, off_t o) -{ - return ((a->vtable->archive_write_data_block)(a, buff, s, o)); -} diff --git a/lib/libarchive/archive_write.3 b/lib/libarchive/archive_write.3 deleted file mode 100644 index 2de392a..0000000 --- a/lib/libarchive/archive_write.3 +++ /dev/null @@ -1,629 +0,0 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd May 11, 2008 -.Dt ARCHIVE_WRITE 3 -.Os -.Sh NAME -.Nm archive_write_new , -.Nm archive_write_set_format_cpio , -.Nm archive_write_set_format_pax , -.Nm archive_write_set_format_pax_restricted , -.Nm archive_write_set_format_shar , -.Nm archive_write_set_format_shar_binary , -.Nm archive_write_set_format_ustar , -.Nm archive_write_get_bytes_per_block , -.Nm archive_write_set_bytes_per_block , -.Nm archive_write_set_bytes_in_last_block , -.Nm archive_write_set_compression_bzip2 , -.Nm archive_write_set_compression_compress , -.Nm archive_write_set_compression_gzip , -.Nm archive_write_set_compression_none , -.Nm archive_write_set_compression_program , -.Nm archive_write_set_compressor_options , -.Nm archive_write_set_format_options , -.Nm archive_write_set_options , -.Nm archive_write_open , -.Nm archive_write_open_fd , -.Nm archive_write_open_FILE , -.Nm archive_write_open_filename , -.Nm archive_write_open_memory , -.Nm archive_write_header , -.Nm archive_write_data , -.Nm archive_write_finish_entry , -.Nm archive_write_close , -.Nm archive_write_free -.Nd functions for creating archives -.Sh SYNOPSIS -.In archive.h -.Ft struct archive * -.Fn archive_write_new "void" -.Ft int -.Fn archive_write_get_bytes_per_block "struct archive *" -.Ft int -.Fn archive_write_set_bytes_per_block "struct archive *" "int bytes_per_block" -.Ft int -.Fn archive_write_set_bytes_in_last_block "struct archive *" "int" -.Ft int -.Fn archive_write_set_compression_bzip2 "struct archive *" -.Ft int -.Fn archive_write_set_compression_compress "struct archive *" -.Ft int -.Fn archive_write_set_compression_gzip "struct archive *" -.Ft int -.Fn archive_write_set_compression_none "struct archive *" -.Ft int -.Fn archive_write_set_compression_program "struct archive *" "const char * cmd" -.Ft int -.Fn archive_write_set_format_cpio "struct archive *" -.Ft int -.Fn archive_write_set_format_pax "struct archive *" -.Ft int -.Fn archive_write_set_format_pax_restricted "struct archive *" -.Ft int -.Fn archive_write_set_format_shar "struct archive *" -.Ft int -.Fn archive_write_set_format_shar_binary "struct archive *" -.Ft int -.Fn archive_write_set_format_ustar "struct archive *" -.Ft int -.Fn archive_write_set_format_options "struct archive *" "const char *" -.Ft int -.Fn archive_write_set_compressor_options "struct archive *" "const char *" -.Ft int -.Fn archive_write_set_options "struct archive *" "const char *" -.Ft int -.Fo archive_write_open -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "archive_open_callback *" -.Fa "archive_write_callback *" -.Fa "archive_close_callback *" -.Fc -.Ft int -.Fn archive_write_open_fd "struct archive *" "int fd" -.Ft int -.Fn archive_write_open_FILE "struct archive *" "FILE *file" -.Ft int -.Fn archive_write_open_filename "struct archive *" "const char *filename" -.Ft int -.Fo archive_write_open_memory -.Fa "struct archive *" -.Fa "void *buffer" -.Fa "size_t bufferSize" -.Fa "size_t *outUsed" -.Fc -.Ft int -.Fn archive_write_header "struct archive *" "struct archive_entry *" -.Ft ssize_t -.Fn archive_write_data "struct archive *" "const void *" "size_t" -.Ft int -.Fn archive_write_finish_entry "struct archive *" -.Ft int -.Fn archive_write_close "struct archive *" -.Ft int -.Fn archive_write_free "struct archive *" -.Sh DESCRIPTION -These functions provide a complete API for creating streaming -archive files. -The general process is to first create the -.Tn struct archive -object, set any desired options, initialize the archive, append entries, then -close the archive and release all resources. -The following summary describes the functions in approximately -the order they are ordinarily used: -.Bl -tag -width indent -.It Fn archive_write_new -Allocates and initializes a -.Tn struct archive -object suitable for writing a tar archive. -.It Fn archive_write_set_bytes_per_block -Sets the block size used for writing the archive data. -Every call to the write callback function, except possibly the last one, will -use this value for the length. -The third parameter is a boolean that specifies whether or not the final block -written will be padded to the full block size. -If it is zero, the last block will not be padded. -If it is non-zero, padding will be added both before and after compression. -The default is to use a block size of 10240 bytes and to pad the last block. -Note that a block size of zero will suppress internal blocking -and cause writes to be sent directly to the write callback as they occur. -.It Fn archive_write_get_bytes_per_block -Retrieve the block size to be used for writing. -A value of -1 here indicates that the library should use default values. -A value of zero indicates that internal blocking is suppressed. -.It Fn archive_write_set_bytes_in_last_block -Sets the block size used for writing the last block. -If this value is zero, the last block will be padded to the same size -as the other blocks. -Otherwise, the final block will be padded to a multiple of this size. -In particular, setting it to 1 will cause the final block to not be padded. -For compressed output, any padding generated by this option -is applied only after the compression. -The uncompressed data is always unpadded. -The default is to pad the last block to the full block size (note that -.Fn archive_write_open_filename -will set this based on the file type). -Unlike the other -.Dq set -functions, this function can be called after the archive is opened. -.It Fn archive_write_get_bytes_in_last_block -Retrieve the currently-set value for last block size. -A value of -1 here indicates that the library should use default values. -.It Xo -.Fn archive_write_set_format_cpio , -.Fn archive_write_set_format_pax , -.Fn archive_write_set_format_pax_restricted , -.Fn archive_write_set_format_shar , -.Fn archive_write_set_format_shar_binary , -.Fn archive_write_set_format_ustar -.Xc -Sets the format that will be used for the archive. -The library can write -POSIX octet-oriented cpio format archives, -POSIX-standard -.Dq pax interchange -format archives, -traditional -.Dq shar -archives, -enhanced -.Dq binary -shar archives that store a variety of file attributes and handle binary files, -and -POSIX-standard -.Dq ustar -archives. -The pax interchange format is a backwards-compatible tar format that -adds key/value attributes to each entry and supports arbitrary -filenames, linknames, uids, sizes, etc. -.Dq Restricted pax interchange format -is the library default; this is the same as pax format, but suppresses -the pax extended header for most normal files. -In most cases, this will result in ordinary ustar archives. -.It Xo -.Fn archive_write_set_compression_bzip2 , -.Fn archive_write_set_compression_compress , -.Fn archive_write_set_compression_gzip , -.Fn archive_write_set_compression_none -.Xc -The resulting archive will be compressed as specified. -Note that the compressed output is always properly blocked. -.It Fn archive_write_set_compression_program -The archive will be fed into the specified compression program. -The output of that program is blocked and written to the client -write callbacks. -.It Xo -.Fn archive_write_set_compressor_options , -.Fn archive_write_set_format_options , -.Fn archive_write_set_options -.Xc -Specifies options that will be passed to the currently-enabled -compressor and/or format writer. -The argument is a comma-separated list of individual options. -Individual options have one of the following forms: -.Bl -tag -compact -width indent -.It Ar option=value -The option/value pair will be provided to every module. -Modules that do not accept an option with this name will ignore it. -.It Ar option -The option will be provided to every module with a value of -.Dq 1 . -.It Ar !option -The option will be provided to every module with a NULL value. -.It Ar module:option=value , Ar module:option , Ar module:!option -As above, but the corresponding option and value will be provided -only to modules whose name matches -.Ar module . -.El -The return value will be -.Cm ARCHIVE_OK -if any module accepts the option, or -.Cm ARCHIVE_WARN -if no module accepted the option, or -.Cm ARCHIVE_FATAL -if there was a fatal error while attempting to process the option. -.Pp -The currently supported options are: -.Bl -tag -compact -width indent -.It Compressor gzip -.Bl -tag -compact -width indent -.It Cm compression-level -The value is interpreted as a decimal integer specifying the -gzip compression level. -.El -.It Compressor xz -.Bl -tag -compact -width indent -.It Cm compression-level -The value is interpreted as a decimal integer specifying the -compression level. -.El -.It Format mtree -.Bl -tag -compact -width indent -.It Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent , Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 , Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname -Enable a particular keyword in the mtree output. -Prefix with an exclamation mark to disable the corresponding keyword. -The default is equivalent to -.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname . -.It Cm all -Enables all of the above keywords. -.It Cm use-set -Enables generation of -.Cm /set -lines that specify default values for the following files and/or directories. -.It Cm indent -XXX needs explanation XXX -.El -.El -.It Fn archive_write_open -Freeze the settings, open the archive, and prepare for writing entries. -This is the most generic form of this function, which accepts -pointers to three callback functions which will be invoked by -the compression layer to write the constructed archive. -.It Fn archive_write_open_fd -A convenience form of -.Fn archive_write_open -that accepts a file descriptor. -The -.Fn archive_write_open_fd -function is safe for use with tape drives or other -block-oriented devices. -.It Fn archive_write_open_FILE -A convenience form of -.Fn archive_write_open -that accepts a -.Ft "FILE *" -pointer. -Note that -.Fn archive_write_open_FILE -is not safe for writing to tape drives or other devices -that require correct blocking. -.It Fn archive_write_open_file -A deprecated synonym for -.Fn archive_write_open_filename . -.It Fn archive_write_open_filename -A convenience form of -.Fn archive_write_open -that accepts a filename. -A NULL argument indicates that the output should be written to standard output; -an argument of -.Dq - -will open a file with that name. -If you have not invoked -.Fn archive_write_set_bytes_in_last_block , -then -.Fn archive_write_open_filename -will adjust the last-block padding depending on the file: -it will enable padding when writing to standard output or -to a character or block device node, it will disable padding otherwise. -You can override this by manually invoking -.Fn archive_write_set_bytes_in_last_block -before calling -.Fn archive_write_open . -The -.Fn archive_write_open_filename -function is safe for use with tape drives or other -block-oriented devices. -.It Fn archive_write_open_memory -A convenience form of -.Fn archive_write_open -that accepts a pointer to a block of memory that will receive -the archive. -The final -.Ft "size_t *" -argument points to a variable that will be updated -after each write to reflect how much of the buffer -is currently in use. -You should be careful to ensure that this variable -remains allocated until after the archive is -closed. -.It Fn archive_write_header -Build and write a header using the data in the provided -.Tn struct archive_entry -structure. -See -.Xr archive_entry 3 -for information on creating and populating -.Tn struct archive_entry -objects. -.It Fn archive_write_data -Write data corresponding to the header just written. -Returns number of bytes written or -1 on error. -.It Fn archive_write_finish_entry -Close out the entry just written. -In particular, this writes out the final padding required by some formats. -Ordinarily, clients never need to call this, as it -is called automatically by -.Fn archive_write_next_header -and -.Fn archive_write_close -as needed. -.It Fn archive_write_close -Complete the archive and invoke the close callback. -.It Fn archive_write_free -Invokes -.Fn archive_write_close -if necessary, then releases all resources. -If you need detailed information about -.Fn archive_write_close -failures, you should be careful to call it separately, as -you cannot obtain error information after -.Fn archive_write_free -returns. -.El -More information about the -.Va struct archive -object and the overall design of the library can be found in the -.Xr libarchive 3 -overview. -.Sh IMPLEMENTATION -Compression support is built-in to libarchive, which uses zlib and bzlib -to handle gzip and bzip2 compression, respectively. -.Sh CLIENT CALLBACKS -To use this library, you will need to define and register -callback functions that will be invoked to write data to the -resulting archive. -These functions are registered by calling -.Fn archive_write_open : -.Bl -item -offset indent -.It -.Ft typedef int -.Fn archive_open_callback "struct archive *" "void *client_data" -.El -.Pp -The open callback is invoked by -.Fn archive_write_open . -It should return -.Cm ARCHIVE_OK -if the underlying file or data source is successfully -opened. -If the open fails, it should call -.Fn archive_set_error -to register an error code and message and return -.Cm ARCHIVE_FATAL . -.Bl -item -offset indent -.It -.Ft typedef ssize_t -.Fo archive_write_callback -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "const void *buffer" -.Fa "size_t length" -.Fc -.El -.Pp -The write callback is invoked whenever the library -needs to write raw bytes to the archive. -For correct blocking, each call to the write callback function -should translate into a single -.Xr write 2 -system call. -This is especially critical when writing archives to tape drives. -On success, the write callback should return the -number of bytes actually written. -On error, the callback should invoke -.Fn archive_set_error -to register an error code and message and return -1. -.Bl -item -offset indent -.It -.Ft typedef int -.Fn archive_close_callback "struct archive *" "void *client_data" -.El -.Pp -The close callback is invoked by archive_close when -the archive processing is complete. -The callback should return -.Cm ARCHIVE_OK -on success. -On failure, the callback should invoke -.Fn archive_set_error -to register an error code and message and -return -.Cm ARCHIVE_FATAL. -.Sh EXAMPLE -The following sketch illustrates basic usage of the library. -In this example, -the callback functions are simply wrappers around the standard -.Xr open 2 , -.Xr write 2 , -and -.Xr close 2 -system calls. -.Bd -literal -offset indent -#ifdef __linux__ -#define _FILE_OFFSET_BITS 64 -#endif -#include -#include -#include -#include -#include -#include - -struct mydata { - const char *name; - int fd; -}; - -int -myopen(struct archive *a, void *client_data) -{ - struct mydata *mydata = client_data; - - mydata->fd = open(mydata->name, O_WRONLY | O_CREAT, 0644); - if (mydata->fd >= 0) - return (ARCHIVE_OK); - else - return (ARCHIVE_FATAL); -} - -ssize_t -mywrite(struct archive *a, void *client_data, const void *buff, size_t n) -{ - struct mydata *mydata = client_data; - - return (write(mydata->fd, buff, n)); -} - -int -myclose(struct archive *a, void *client_data) -{ - struct mydata *mydata = client_data; - - if (mydata->fd > 0) - close(mydata->fd); - return (0); -} - -void -write_archive(const char *outname, const char **filename) -{ - struct mydata *mydata = malloc(sizeof(struct mydata)); - struct archive *a; - struct archive_entry *entry; - struct stat st; - char buff[8192]; - int len; - int fd; - - a = archive_write_new(); - mydata->name = outname; - archive_write_set_compression_gzip(a); - archive_write_set_format_ustar(a); - archive_write_open(a, mydata, myopen, mywrite, myclose); - while (*filename) { - stat(*filename, &st); - entry = archive_entry_new(); - archive_entry_copy_stat(entry, &st); - archive_entry_set_pathname(entry, *filename); - archive_write_header(a, entry); - fd = open(*filename, O_RDONLY); - len = read(fd, buff, sizeof(buff)); - while ( len > 0 ) { - archive_write_data(a, buff, len); - len = read(fd, buff, sizeof(buff)); - } - archive_entry_free(entry); - filename++; - } - archive_write_free(a); -} - -int main(int argc, const char **argv) -{ - const char *outname; - argv++; - outname = argv++; - write_archive(outname, argv); - return 0; -} -.Ed -.Sh RETURN VALUES -Most functions return -.Cm ARCHIVE_OK -(zero) on success, or one of several non-zero -error codes for errors. -Specific error codes include: -.Cm ARCHIVE_RETRY -for operations that might succeed if retried, -.Cm ARCHIVE_WARN -for unusual conditions that do not prevent further operations, and -.Cm ARCHIVE_FATAL -for serious errors that make remaining operations impossible. -The -.Fn archive_errno -and -.Fn archive_error_string -functions can be used to retrieve an appropriate error code and a -textual error message. -.Pp -.Fn archive_write_new -returns a pointer to a newly-allocated -.Tn struct archive -object. -.Pp -.Fn archive_write_data -returns a count of the number of bytes actually written. -On error, -1 is returned and the -.Fn archive_errno -and -.Fn archive_error_string -functions will return appropriate values. -Note that if the client-provided write callback function -returns a non-zero value, that error will be propagated back to the caller -through whatever API function resulted in that call, which -may include -.Fn archive_write_header , -.Fn archive_write_data , -.Fn archive_write_close , -or -.Fn archive_write_free . -The client callback can call -.Fn archive_set_error -to provide values that can then be retrieved by -.Fn archive_errno -and -.Fn archive_error_string . -.Sh SEE ALSO -.Xr tar 1 , -.Xr libarchive 3 , -.Xr tar 5 -.Sh HISTORY -The -.Nm libarchive -library first appeared in -.Fx 5.3 . -.Sh AUTHORS -.An -nosplit -The -.Nm libarchive -library was written by -.An Tim Kientzle Aq kientzle@acm.org . -.Sh BUGS -There are many peculiar bugs in historic tar implementations that may cause -certain programs to reject archives written by this library. -For example, several historic implementations calculated header checksums -incorrectly and will thus reject valid archives; GNU tar does not fully support -pax interchange format; some old tar implementations required specific -field terminations. -.Pp -The default pax interchange format eliminates most of the historic -tar limitations and provides a generic key/value attribute facility -for vendor-defined extensions. -One oversight in POSIX is the failure to provide a standard attribute -for large device numbers. -This library uses -.Dq SCHILY.devminor -and -.Dq SCHILY.devmajor -for device numbers that exceed the range supported by the backwards-compatible -ustar header. -These keys are compatible with Joerg Schilling's -.Nm star -archiver. -Other implementations may not recognize these keys and will thus be unable -to correctly restore device nodes with large device numbers from archives -created by this library. diff --git a/lib/libarchive/archive_write.c b/lib/libarchive/archive_write.c deleted file mode 100644 index 70af46f..0000000 --- a/lib/libarchive/archive_write.c +++ /dev/null @@ -1,466 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -/* - * This file contains the "essential" portions of the write API, that - * is, stuff that will essentially always be used by any client that - * actually needs to write a archive. Optional pieces have been, as - * far as possible, separated out into separate files to reduce - * needlessly bloating statically-linked clients. - */ - -#ifdef HAVE_SYS_WAIT_H -#include -#endif -#ifdef HAVE_LIMITS_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#include -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_write_private.h" - -static struct archive_vtable *archive_write_vtable(void); - -static int _archive_write_close(struct archive *); -static int _archive_write_free(struct archive *); -static int _archive_write_header(struct archive *, struct archive_entry *); -static int _archive_write_finish_entry(struct archive *); -static ssize_t _archive_write_data(struct archive *, const void *, size_t); - -static struct archive_vtable * -archive_write_vtable(void) -{ - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_close = _archive_write_close; - av.archive_free = _archive_write_free; - av.archive_write_header = _archive_write_header; - av.archive_write_finish_entry = _archive_write_finish_entry; - av.archive_write_data = _archive_write_data; - } - return (&av); -} - -/* - * Allocate, initialize and return an archive object. - */ -struct archive * -archive_write_new(void) -{ - struct archive_write *a; - unsigned char *nulls; - - a = (struct archive_write *)malloc(sizeof(*a)); - if (a == NULL) - return (NULL); - memset(a, 0, sizeof(*a)); - a->archive.magic = ARCHIVE_WRITE_MAGIC; - a->archive.state = ARCHIVE_STATE_NEW; - a->archive.vtable = archive_write_vtable(); - /* - * The value 10240 here matches the traditional tar default, - * but is otherwise arbitrary. - * TODO: Set the default block size from the format selected. - */ - a->bytes_per_block = 10240; - a->bytes_in_last_block = -1; /* Default */ - - /* Initialize a block of nulls for padding purposes. */ - a->null_length = 1024; - nulls = (unsigned char *)malloc(a->null_length); - if (nulls == NULL) { - free(a); - return (NULL); - } - memset(nulls, 0, a->null_length); - a->nulls = nulls; - /* - * Set default compression, but don't set a default format. - * Were we to set a default format here, we would force every - * client to link in support for that format, even if they didn't - * ever use it. - */ - archive_write_set_compression_none(&a->archive); - return (&a->archive); -} - -/* - * Set write options for the format. Returns 0 if successful. - */ -int -archive_write_set_format_options(struct archive *_a, const char *s) -{ - struct archive_write *a = (struct archive_write *)_a; - char key[64], val[64]; - int len, r, ret = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_format_options"); - archive_clear_error(&a->archive); - - if (s == NULL || *s == '\0') - return (ARCHIVE_OK); - if (a->format_options == NULL) - /* This format does not support option. */ - return (ARCHIVE_OK); - - while ((len = __archive_parse_options(s, a->format_name, - sizeof(key), key, sizeof(val), val)) > 0) { - if (val[0] == '\0') - r = a->format_options(a, key, NULL); - else - r = a->format_options(a, key, val); - if (r == ARCHIVE_FATAL) - return (r); - if (r < ARCHIVE_OK) { /* This key was not handled. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Unsupported option ``%s''", key); - ret = ARCHIVE_WARN; - } - s += len; - } - if (len < 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed options string."); - return (ARCHIVE_WARN); - } - return (ret); -} - -/* - * Set write options for the compressor. Returns 0 if successful. - */ -int -archive_write_set_compressor_options(struct archive *_a, const char *s) -{ - struct archive_write *a = (struct archive_write *)_a; - char key[64], val[64]; - int len, r; - int ret = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compressor_options"); - archive_clear_error(&a->archive); - - if (s == NULL || *s == '\0') - return (ARCHIVE_OK); - if (a->compressor.options == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Unsupported option ``%s''", s); - /* This compressor does not support option. */ - return (ARCHIVE_WARN); - } - - while ((len = __archive_parse_options(s, a->archive.compression_name, - sizeof(key), key, sizeof(val), val)) > 0) { - if (val[0] == '\0') - r = a->compressor.options(a, key, NULL); - else - r = a->compressor.options(a, key, val); - if (r == ARCHIVE_FATAL) - return (r); - if (r < ARCHIVE_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Unsupported option ``%s''", key); - ret = ARCHIVE_WARN; - } - s += len; - } - if (len < 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Illegal format options."); - return (ARCHIVE_WARN); - } - return (ret); -} - -/* - * Set write options for the format and the compressor. Returns 0 if successful. - */ -int -archive_write_set_options(struct archive *_a, const char *s) -{ - int r1, r2; - - r1 = archive_write_set_format_options(_a, s); - if (r1 < ARCHIVE_WARN) - return (r1); - r2 = archive_write_set_compressor_options(_a, s); - if (r2 < ARCHIVE_WARN) - return (r2); - if (r1 == ARCHIVE_WARN && r2 == ARCHIVE_WARN) - return (ARCHIVE_WARN); - return (ARCHIVE_OK); -} - -/* - * Set the block size. Returns 0 if successful. - */ -int -archive_write_set_bytes_per_block(struct archive *_a, int bytes_per_block) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_bytes_per_block"); - a->bytes_per_block = bytes_per_block; - return (ARCHIVE_OK); -} - -/* - * Get the current block size. -1 if it has never been set. - */ -int -archive_write_get_bytes_per_block(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_get_bytes_per_block"); - return (a->bytes_per_block); -} - -/* - * Set the size for the last block. - * Returns 0 if successful. - */ -int -archive_write_set_bytes_in_last_block(struct archive *_a, int bytes) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_set_bytes_in_last_block"); - a->bytes_in_last_block = bytes; - return (ARCHIVE_OK); -} - -/* - * Return the value set above. -1 indicates it has not been set. - */ -int -archive_write_get_bytes_in_last_block(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_get_bytes_in_last_block"); - return (a->bytes_in_last_block); -} - - -/* - * dev/ino of a file to be rejected. Used to prevent adding - * an archive to itself recursively. - */ -int -archive_write_set_skip_file(struct archive *_a, dev_t d, ino_t i) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_set_skip_file"); - a->skip_file_dev = d; - a->skip_file_ino = i; - return (ARCHIVE_OK); -} - - -/* - * Open the archive using the current settings. - */ -int -archive_write_open(struct archive *_a, void *client_data, - archive_open_callback *opener, archive_write_callback *writer, - archive_close_callback *closer) -{ - struct archive_write *a = (struct archive_write *)_a; - int ret; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_open"); - archive_clear_error(&a->archive); - a->archive.state = ARCHIVE_STATE_HEADER; - a->client_data = client_data; - a->client_writer = writer; - a->client_opener = opener; - a->client_closer = closer; - ret = (a->compressor.init)(a); - if (a->format_init && ret == ARCHIVE_OK) - ret = (a->format_init)(a); - return (ret); -} - - -/* - * Close out the archive. - * - * Be careful: user might just call write_new and then write_finish. - * Don't assume we actually wrote anything or performed any non-trivial - * initialization. - */ -static int -_archive_write_close(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - int r = ARCHIVE_OK, r1 = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_close"); - - /* Finish the last entry. */ - if (a->archive.state & ARCHIVE_STATE_DATA) - r = ((a->format_finish_entry)(a)); - - /* Finish off the archive. */ - if (a->format_finish != NULL) { - r1 = (a->format_finish)(a); - if (r1 < r) - r = r1; - } - - /* Release format resources. */ - if (a->format_destroy != NULL) { - r1 = (a->format_destroy)(a); - if (r1 < r) - r = r1; - } - - /* Finish the compression and close the stream. */ - if (a->compressor.finish != NULL) { - r1 = (a->compressor.finish)(a); - if (r1 < r) - r = r1; - } - - /* Close out the client stream. */ - if (a->client_closer != NULL) { - r1 = (a->client_closer)(&a->archive, a->client_data); - if (r1 < r) - r = r1; - } - - a->archive.state = ARCHIVE_STATE_CLOSED; - return (r); -} - -/* - * Destroy the archive structure. - */ -static int -_archive_write_free(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - int r = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_free"); - if (a->archive.state != ARCHIVE_STATE_CLOSED) - r = archive_write_close(&a->archive); - - /* Release various dynamic buffers. */ - free((void *)(uintptr_t)(const void *)a->nulls); - archive_string_free(&a->archive.error_string); - a->archive.magic = 0; - free(a); - return (r); -} - -/* - * Write the appropriate header. - */ -static int -_archive_write_header(struct archive *_a, struct archive_entry *entry) -{ - struct archive_write *a = (struct archive_write *)_a; - int ret, r2; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_DATA | ARCHIVE_STATE_HEADER, "archive_write_header"); - archive_clear_error(&a->archive); - - /* In particular, "retry" and "fatal" get returned immediately. */ - ret = archive_write_finish_entry(&a->archive); - if (ret < ARCHIVE_OK && ret != ARCHIVE_WARN) - return (ret); - - if (a->skip_file_dev != 0 && - archive_entry_dev(entry) == a->skip_file_dev && - a->skip_file_ino != 0 && - archive_entry_ino64(entry) == a->skip_file_ino) { - archive_set_error(&a->archive, 0, - "Can't add archive to itself"); - return (ARCHIVE_FAILED); - } - - /* Format and write header. */ - r2 = ((a->format_write_header)(a, entry)); - if (r2 < ret) - ret = r2; - - a->archive.state = ARCHIVE_STATE_DATA; - return (ret); -} - -static int -_archive_write_finish_entry(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - int ret = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_write_finish_entry"); - if (a->archive.state & ARCHIVE_STATE_DATA) - ret = (a->format_finish_entry)(a); - a->archive.state = ARCHIVE_STATE_HEADER; - return (ret); -} - -/* - * Note that the compressor is responsible for blocking. - */ -static ssize_t -_archive_write_data(struct archive *_a, const void *buff, size_t s) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_DATA, "archive_write_data"); - archive_clear_error(&a->archive); - return ((a->format_write_data)(a, buff, s)); -} diff --git a/lib/libarchive/archive_write_disk.3 b/lib/libarchive/archive_write_disk.3 deleted file mode 100644 index 61138b8..0000000 --- a/lib/libarchive/archive_write_disk.3 +++ /dev/null @@ -1,375 +0,0 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd August 5, 2008 -.Dt ARCHIVE_WRITE_DISK 3 -.Os -.Sh NAME -.Nm archive_write_disk_new , -.Nm archive_write_disk_set_options , -.Nm archive_write_disk_set_skip_file , -.Nm archive_write_disk_set_group_lookup , -.Nm archive_write_disk_set_standard_lookup , -.Nm archive_write_disk_set_user_lookup , -.Nm archive_write_header , -.Nm archive_write_data , -.Nm archive_write_finish_entry , -.Nm archive_write_close , -.Nm archive_write_free -.Nd functions for creating objects on disk -.Sh SYNOPSIS -.In archive.h -.Ft struct archive * -.Fn archive_write_disk_new "void" -.Ft int -.Fn archive_write_disk_set_options "struct archive *" "int flags" -.Ft int -.Fn archive_write_disk_set_skip_file "struct archive *" "dev_t" "ino_t" -.Ft int -.Fo archive_write_disk_set_group_lookup -.Fa "struct archive *" -.Fa "void *" -.Fa "gid_t (*)(void *, const char *gname, gid_t gid)" -.Fa "void (*cleanup)(void *)" -.Fc -.Ft int -.Fn archive_write_disk_set_standard_lookup "struct archive *" -.Ft int -.Fo archive_write_disk_set_user_lookup -.Fa "struct archive *" -.Fa "void *" -.Fa "uid_t (*)(void *, const char *uname, uid_t uid)" -.Fa "void (*cleanup)(void *)" -.Fc -.Ft int -.Fn archive_write_header "struct archive *" "struct archive_entry *" -.Ft ssize_t -.Fn archive_write_data "struct archive *" "const void *" "size_t" -.Ft int -.Fn archive_write_finish_entry "struct archive *" -.Ft int -.Fn archive_write_close "struct archive *" -.Ft int -.Fn archive_write_free "struct archive *" -.Sh DESCRIPTION -These functions provide a complete API for creating objects on -disk from -.Tn struct archive_entry -descriptions. -They are most naturally used when extracting objects from an archive -using the -.Fn archive_read -interface. -The general process is to read -.Tn struct archive_entry -objects from an archive, then write those objects to a -.Tn struct archive -object created using the -.Fn archive_write_disk -family functions. -This interface is deliberately very similar to the -.Fn archive_write -interface used to write objects to a streaming archive. -.Bl -tag -width indent -.It Fn archive_write_disk_new -Allocates and initializes a -.Tn struct archive -object suitable for writing objects to disk. -.It Fn archive_write_disk_set_skip_file -Records the device and inode numbers of a file that should not be -overwritten. -This is typically used to ensure that an extraction process does not -overwrite the archive from which objects are being read. -This capability is technically unnecessary but can be a significant -performance optimization in practice. -.It Fn archive_write_disk_set_options -The options field consists of a bitwise OR of one or more of the -following values: -.Bl -tag -compact -width "indent" -.It Cm ARCHIVE_EXTRACT_OWNER -The user and group IDs should be set on the restored file. -By default, the user and group IDs are not restored. -.It Cm ARCHIVE_EXTRACT_PERM -Full permissions (including SGID, SUID, and sticky bits) should -be restored exactly as specified, without obeying the -current umask. -Note that SUID and SGID bits can only be restored if the -user and group ID of the object on disk are correct. -If -.Cm ARCHIVE_EXTRACT_OWNER -is not specified, then SUID and SGID bits will only be restored -if the default user and group IDs of newly-created objects on disk -happen to match those specified in the archive entry. -By default, only basic permissions are restored, and umask is obeyed. -.It Cm ARCHIVE_EXTRACT_TIME -The timestamps (mtime, ctime, and atime) should be restored. -By default, they are ignored. -Note that restoring of atime is not currently supported. -.It Cm ARCHIVE_EXTRACT_NO_OVERWRITE -Existing files on disk will not be overwritten. -By default, existing regular files are truncated and overwritten; -existing directories will have their permissions updated; -other pre-existing objects are unlinked and recreated from scratch. -.It Cm ARCHIVE_EXTRACT_UNLINK -Existing files on disk will be unlinked before any attempt to -create them. -In some cases, this can prove to be a significant performance improvement. -By default, existing files are truncated and rewritten, but -the file is not recreated. -In particular, the default behavior does not break existing hard links. -.It Cm ARCHIVE_EXTRACT_ACL -Attempt to restore ACLs. -By default, extended ACLs are ignored. -.It Cm ARCHIVE_EXTRACT_FFLAGS -Attempt to restore extended file flags. -By default, file flags are ignored. -.It Cm ARCHIVE_EXTRACT_XATTR -Attempt to restore POSIX.1e extended attributes. -By default, they are ignored. -.It Cm ARCHIVE_EXTRACT_SECURE_SYMLINKS -Refuse to extract any object whose final location would be altered -by a symlink on disk. -This is intended to help guard against a variety of mischief -caused by archives that (deliberately or otherwise) extract -files outside of the current directory. -The default is not to perform this check. -If -.Cm ARCHIVE_EXTRACT_UNLINK -is specified together with this option, the library will -remove any intermediate symlinks it finds and return an -error only if such symlink could not be removed. -.It Cm ARCHIVE_EXTRACT_SECURE_NODOTDOT -Refuse to extract a path that contains a -.Pa .. -element anywhere within it. -The default is to not refuse such paths. -Note that paths ending in -.Pa .. -always cause an error, regardless of this flag. -.It Cm ARCHIVE_EXTRACT_SPARSE -Scan data for blocks of NUL bytes and try to recreate them with holes. -This results in sparse files, independent of whether the archive format -supports or uses them. -.El -.It Xo -.Fn archive_write_disk_set_group_lookup , -.Fn archive_write_disk_set_user_lookup -.Xc -The -.Tn struct archive_entry -objects contain both names and ids that can be used to identify users -and groups. -These names and ids describe the ownership of the file itself and -also appear in ACL lists. -By default, the library uses the ids and ignores the names, but -this can be overridden by registering user and group lookup functions. -To register, you must provide a lookup function which -accepts both a name and id and returns a suitable id. -You may also provide a -.Tn void * -pointer to a private data structure and a cleanup function for -that data. -The cleanup function will be invoked when the -.Tn struct archive -object is destroyed. -.It Fn archive_write_disk_set_standard_lookup -This convenience function installs a standard set of user -and group lookup functions. -These functions use -.Xr getpwnam 3 -and -.Xr getgrnam 3 -to convert names to ids, defaulting to the ids if the names cannot -be looked up. -These functions also implement a simple memory cache to reduce -the number of calls to -.Xr getpwnam 3 -and -.Xr getgrnam 3 . -.It Fn archive_write_header -Build and write a header using the data in the provided -.Tn struct archive_entry -structure. -See -.Xr archive_entry 3 -for information on creating and populating -.Tn struct archive_entry -objects. -.It Fn archive_write_data -Write data corresponding to the header just written. -Returns number of bytes written or -1 on error. -.It Fn archive_write_finish_entry -Close out the entry just written. -Ordinarily, clients never need to call this, as it -is called automatically by -.Fn archive_write_next_header -and -.Fn archive_write_close -as needed. -.It Fn archive_write_close -Set any attributes that could not be set during the initial restore. -For example, directory timestamps are not restored initially because -restoring a subsequent file would alter that timestamp. -Similarly, non-writable directories are initially created with -write permissions (so that their contents can be restored). -The -.Nm -library maintains a list of all such deferred attributes and -sets them when this function is invoked. -.It Fn archive_write_free -Invokes -.Fn archive_write_close -if it was not invoked manually, then releases all resources. -.El -More information about the -.Va struct archive -object and the overall design of the library can be found in the -.Xr libarchive 3 -overview. -Many of these functions are also documented under -.Xr archive_write 3 . -.Sh RETURN VALUES -Most functions return -.Cm ARCHIVE_OK -(zero) on success, or one of several non-zero -error codes for errors. -Specific error codes include: -.Cm ARCHIVE_RETRY -for operations that might succeed if retried, -.Cm ARCHIVE_WARN -for unusual conditions that do not prevent further operations, and -.Cm ARCHIVE_FATAL -for serious errors that make remaining operations impossible. -The -.Fn archive_errno -and -.Fn archive_error_string -functions can be used to retrieve an appropriate error code and a -textual error message. -.Pp -.Fn archive_write_disk_new -returns a pointer to a newly-allocated -.Tn struct archive -object. -.Pp -.Fn archive_write_data -returns a count of the number of bytes actually written. -On error, -1 is returned and the -.Fn archive_errno -and -.Fn archive_error_string -functions will return appropriate values. -.Sh SEE ALSO -.Xr archive_read 3 , -.Xr archive_write 3 , -.Xr tar 1 , -.Xr libarchive 3 -.Sh HISTORY -The -.Nm libarchive -library first appeared in -.Fx 5.3 . -The -.Nm archive_write_disk -interface was added to -.Nm libarchive 2.0 -and first appeared in -.Fx 6.3 . -.Sh AUTHORS -.An -nosplit -The -.Nm libarchive -library was written by -.An Tim Kientzle Aq kientzle@acm.org . -.Sh BUGS -Directories are actually extracted in two distinct phases. -Directories are created during -.Fn archive_write_header , -but final permissions are not set until -.Fn archive_write_close . -This separation is necessary to correctly handle borderline -cases such as a non-writable directory containing -files, but can cause unexpected results. -In particular, directory permissions are not fully -restored until the archive is closed. -If you use -.Xr chdir 2 -to change the current directory between calls to -.Fn archive_read_extract -or before calling -.Fn archive_read_close , -you may confuse the permission-setting logic with -the result that directory permissions are restored -incorrectly. -.Pp -The library attempts to create objects with filenames longer than -.Cm PATH_MAX -by creating prefixes of the full path and changing the current directory. -Currently, this logic is limited in scope; the fixup pass does -not work correctly for such objects and the symlink security check -option disables the support for very long pathnames. -.Pp -Restoring the path -.Pa aa/../bb -does create each intermediate directory. -In particular, the directory -.Pa aa -is created as well as the final object -.Pa bb . -In theory, this can be exploited to create an entire directory hierarchy -with a single request. -Of course, this does not work if the -.Cm ARCHIVE_EXTRACT_NODOTDOT -option is specified. -.Pp -Implicit directories are always created obeying the current umask. -Explicit objects are created obeying the current umask unless -.Cm ARCHIVE_EXTRACT_PERM -is specified, in which case they current umask is ignored. -.Pp -SGID and SUID bits are restored only if the correct user and -group could be set. -If -.Cm ARCHIVE_EXTRACT_OWNER -is not specified, then no attempt is made to set the ownership. -In this case, SGID and SUID bits are restored only if the -user and group of the final object happen to match those specified -in the entry. -.Pp -The -.Dq standard -user-id and group-id lookup functions are not the defaults because -.Xr getgrnam 3 -and -.Xr getpwnam 3 -are sometimes too large for particular applications. -The current design allows the application author to use a more -compact implementation when appropriate. -.Pp -There should be a corresponding -.Nm archive_read_disk -interface that walks a directory hierarchy and returns archive -entry objects. diff --git a/lib/libarchive/archive_write_disk.c b/lib/libarchive/archive_write_disk.c deleted file mode 100644 index 49ced58..0000000 --- a/lib/libarchive/archive_write_disk.c +++ /dev/null @@ -1,2712 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_ACL_H -#include -#endif -#ifdef HAVE_SYS_EXTATTR_H -#include -#endif -#ifdef HAVE_SYS_XATTR_H -#include -#endif -#ifdef HAVE_ATTR_XATTR_H -#include -#endif -#ifdef HAVE_SYS_IOCTL_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_SYS_TIME_H -#include -#endif -#ifdef HAVE_SYS_UTIME_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_GRP_H -#include -#endif -#ifdef HAVE_LINUX_FS_H -#include /* for Linux file flags */ -#endif -/* - * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. - * As the include guards don't agree, the order of include is important. - */ -#ifdef HAVE_LINUX_EXT2_FS_H -#include /* for Linux file flags */ -#endif -#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) -#include /* Linux file flags, broken on Cygwin */ -#endif -#ifdef HAVE_LIMITS_H -#include -#endif -#ifdef HAVE_PWD_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_UTIME_H -#include -#endif - -#include "archive.h" -#include "archive_string.h" -#include "archive_entry.h" -#include "archive_private.h" - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -struct fixup_entry { - struct fixup_entry *next; - mode_t mode; - int64_t atime; - int64_t birthtime; - int64_t mtime; - unsigned long atime_nanos; - unsigned long birthtime_nanos; - unsigned long mtime_nanos; - unsigned long fflags_set; - int fixup; /* bitmask of what needs fixing */ - char *name; -}; - -/* - * We use a bitmask to track which operations remain to be done for - * this file. In particular, this helps us avoid unnecessary - * operations when it's possible to take care of one step as a - * side-effect of another. For example, mkdir() can specify the mode - * for the newly-created object but symlink() cannot. This means we - * can skip chmod() if mkdir() succeeded, but we must explicitly - * chmod() if we're trying to create a directory that already exists - * (mkdir() failed) or if we're restoring a symlink. Similarly, we - * need to verify UID/GID before trying to restore SUID/SGID bits; - * that verification can occur explicitly through a stat() call or - * implicitly because of a successful chown() call. - */ -#define TODO_MODE_FORCE 0x40000000 -#define TODO_MODE_BASE 0x20000000 -#define TODO_SUID 0x10000000 -#define TODO_SUID_CHECK 0x08000000 -#define TODO_SGID 0x04000000 -#define TODO_SGID_CHECK 0x02000000 -#define TODO_MODE (TODO_MODE_BASE|TODO_SUID|TODO_SGID) -#define TODO_TIMES ARCHIVE_EXTRACT_TIME -#define TODO_OWNER ARCHIVE_EXTRACT_OWNER -#define TODO_FFLAGS ARCHIVE_EXTRACT_FFLAGS -#define TODO_ACLS ARCHIVE_EXTRACT_ACL -#define TODO_XATTR ARCHIVE_EXTRACT_XATTR - -struct archive_write_disk { - struct archive archive; - - mode_t user_umask; - struct fixup_entry *fixup_list; - struct fixup_entry *current_fixup; - uid_t user_uid; - dev_t skip_file_dev; - ino_t skip_file_ino; - time_t start_time; - - gid_t (*lookup_gid)(void *private, const char *gname, gid_t gid); - void (*cleanup_gid)(void *private); - void *lookup_gid_data; - uid_t (*lookup_uid)(void *private, const char *gname, gid_t gid); - void (*cleanup_uid)(void *private); - void *lookup_uid_data; - - /* - * Full path of last file to satisfy symlink checks. - */ - struct archive_string path_safe; - - /* - * Cached stat data from disk for the current entry. - * If this is valid, pst points to st. Otherwise, - * pst is null. - */ - struct stat st; - struct stat *pst; - - /* Information about the object being restored right now. */ - struct archive_entry *entry; /* Entry being extracted. */ - char *name; /* Name of entry, possibly edited. */ - struct archive_string _name_data; /* backing store for 'name' */ - /* Tasks remaining for this object. */ - int todo; - /* Tasks deferred until end-of-archive. */ - int deferred; - /* Options requested by the client. */ - int flags; - /* Handle for the file we're restoring. */ - int fd; - /* Current offset for writing data to the file. */ - off_t offset; - /* Last offset actually written to disk. */ - off_t fd_offset; - /* Maximum size of file, -1 if unknown. */ - off_t filesize; - /* Dir we were in before this restore; only for deep paths. */ - int restore_pwd; - /* Mode we should use for this entry; affected by _PERM and umask. */ - mode_t mode; - /* UID/GID to use in restoring this entry. */ - uid_t uid; - gid_t gid; -}; - -/* - * Default mode for dirs created automatically (will be modified by umask). - * Note that POSIX specifies 0777 for implicity-created dirs, "modified - * by the process' file creation mask." - */ -#define DEFAULT_DIR_MODE 0777 -/* - * Dir modes are restored in two steps: During the extraction, the permissions - * in the archive are modified to match the following limits. During - * the post-extract fixup pass, the permissions from the archive are - * applied. - */ -#define MINIMUM_DIR_MODE 0700 -#define MAXIMUM_DIR_MODE 0775 - -static int check_symlinks(struct archive_write_disk *); -static int create_filesystem_object(struct archive_write_disk *); -static struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname); -#ifdef HAVE_FCHDIR -static void edit_deep_directories(struct archive_write_disk *ad); -#endif -static int cleanup_pathname(struct archive_write_disk *); -static int create_dir(struct archive_write_disk *, char *); -static int create_parent_dir(struct archive_write_disk *, char *); -static int older(struct stat *, struct archive_entry *); -static int restore_entry(struct archive_write_disk *); -#ifdef HAVE_POSIX_ACL -static int set_acl(struct archive_write_disk *, int fd, struct archive_entry *, - acl_type_t, int archive_entry_acl_type, const char *tn); -#endif -static int set_acls(struct archive_write_disk *); -static int set_xattrs(struct archive_write_disk *); -static int set_fflags(struct archive_write_disk *); -static int set_fflags_platform(struct archive_write_disk *, int fd, - const char *name, mode_t mode, - unsigned long fflags_set, unsigned long fflags_clear); -static int set_ownership(struct archive_write_disk *); -static int set_mode(struct archive_write_disk *, int mode); -static int set_time(int, int, const char *, time_t, long, time_t, long); -static int set_times(struct archive_write_disk *); -static struct fixup_entry *sort_dir_list(struct fixup_entry *p); -static gid_t trivial_lookup_gid(void *, const char *, gid_t); -static uid_t trivial_lookup_uid(void *, const char *, uid_t); -static ssize_t write_data_block(struct archive_write_disk *, - const char *, size_t); - -static struct archive_vtable *archive_write_disk_vtable(void); - -static int _archive_write_close(struct archive *); -static int _archive_write_free(struct archive *); -static int _archive_write_header(struct archive *, struct archive_entry *); -static int _archive_write_finish_entry(struct archive *); -static ssize_t _archive_write_data(struct archive *, const void *, size_t); -static ssize_t _archive_write_data_block(struct archive *, const void *, size_t, off_t); - -static int -_archive_write_disk_lazy_stat(struct archive_write_disk *a) -{ - if (a->pst != NULL) { - /* Already have stat() data available. */ - return (ARCHIVE_OK); - } -#ifdef HAVE_FSTAT - if (a->fd >= 0 && fstat(a->fd, &a->st) == 0) { - a->pst = &a->st; - return (ARCHIVE_OK); - } -#endif - /* - * XXX At this point, symlinks should not be hit, otherwise - * XXX a race occured. Do we want to check explicitly for that? - */ - if (lstat(a->name, &a->st) == 0) { - a->pst = &a->st; - return (ARCHIVE_OK); - } - archive_set_error(&a->archive, errno, "Couldn't stat file"); - return (ARCHIVE_WARN); -} - -static struct archive_vtable * -archive_write_disk_vtable(void) -{ - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_close = _archive_write_close; - av.archive_free = _archive_write_free; - av.archive_write_header = _archive_write_header; - av.archive_write_finish_entry = _archive_write_finish_entry; - av.archive_write_data = _archive_write_data; - av.archive_write_data_block = _archive_write_data_block; - } - return (&av); -} - - -int -archive_write_disk_set_options(struct archive *_a, int flags) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - - a->flags = flags; - return (ARCHIVE_OK); -} - - -/* - * Extract this entry to disk. - * - * TODO: Validate hardlinks. According to the standards, we're - * supposed to check each extracted hardlink and squawk if it refers - * to a file that we didn't restore. I'm not entirely convinced this - * is a good idea, but more importantly: Is there any way to validate - * hardlinks without keeping a complete list of filenames from the - * entire archive?? Ugh. - * - */ -static int -_archive_write_header(struct archive *_a, struct archive_entry *entry) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - struct fixup_entry *fe; - int ret, r; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_write_disk_header"); - archive_clear_error(&a->archive); - if (a->archive.state & ARCHIVE_STATE_DATA) { - r = _archive_write_finish_entry(&a->archive); - if (r == ARCHIVE_FATAL) - return (r); - } - - /* Set up for this particular entry. */ - a->pst = NULL; - a->current_fixup = NULL; - a->deferred = 0; - if (a->entry) { - archive_entry_free(a->entry); - a->entry = NULL; - } - a->entry = archive_entry_clone(entry); - a->fd = -1; - a->fd_offset = 0; - a->offset = 0; - a->uid = a->user_uid; - a->mode = archive_entry_mode(a->entry); - if (archive_entry_size_is_set(a->entry)) - a->filesize = archive_entry_size(a->entry); - else - a->filesize = -1; - archive_strcpy(&(a->_name_data), archive_entry_pathname(a->entry)); - a->name = a->_name_data.s; - archive_clear_error(&a->archive); - - /* - * Clean up the requested path. This is necessary for correct - * dir restores; the dir restore logic otherwise gets messed - * up by nonsense like "dir/.". - */ - ret = cleanup_pathname(a); - if (ret != ARCHIVE_OK) - return (ret); - - /* - * Set the umask to zero so we get predictable mode settings. - * This gets done on every call to _write_header in case the - * user edits their umask during the extraction for some - * reason. This will be reset before we return. Note that we - * don't need to do this in _finish_entry, as the chmod(), etc, - * system calls don't obey umask. - */ - a->user_umask = umask(0); - /* From here on, early exit requires "goto done" to clean up. */ - - /* Figure out what we need to do for this entry. */ - a->todo = TODO_MODE_BASE; - if (a->flags & ARCHIVE_EXTRACT_PERM) { - a->todo |= TODO_MODE_FORCE; /* Be pushy about permissions. */ - /* - * SGID requires an extra "check" step because we - * cannot easily predict the GID that the system will - * assign. (Different systems assign GIDs to files - * based on a variety of criteria, including process - * credentials and the gid of the enclosing - * directory.) We can only restore the SGID bit if - * the file has the right GID, and we only know the - * GID if we either set it (see set_ownership) or if - * we've actually called stat() on the file after it - * was restored. Since there are several places at - * which we might verify the GID, we need a TODO bit - * to keep track. - */ - if (a->mode & S_ISGID) - a->todo |= TODO_SGID | TODO_SGID_CHECK; - /* - * Verifying the SUID is simpler, but can still be - * done in multiple ways, hence the separate "check" bit. - */ - if (a->mode & S_ISUID) - a->todo |= TODO_SUID | TODO_SUID_CHECK; - } else { - /* - * User didn't request full permissions, so don't - * restore SUID, SGID bits and obey umask. - */ - a->mode &= ~S_ISUID; - a->mode &= ~S_ISGID; - a->mode &= ~S_ISVTX; - a->mode &= ~a->user_umask; - } -#if !defined(_WIN32) || defined(__CYGWIN__) - if (a->flags & ARCHIVE_EXTRACT_OWNER) - a->todo |= TODO_OWNER; -#endif - if (a->flags & ARCHIVE_EXTRACT_TIME) - a->todo |= TODO_TIMES; - if (a->flags & ARCHIVE_EXTRACT_ACL) - a->todo |= TODO_ACLS; - if (a->flags & ARCHIVE_EXTRACT_XATTR) - a->todo |= TODO_XATTR; - if (a->flags & ARCHIVE_EXTRACT_FFLAGS) - a->todo |= TODO_FFLAGS; - if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) { - ret = check_symlinks(a); - if (ret != ARCHIVE_OK) - goto done; - } -#ifdef HAVE_FCHDIR - /* If path exceeds PATH_MAX, shorten the path. */ - edit_deep_directories(a); -#endif - - ret = restore_entry(a); - - /* - * TODO: There are rumours that some extended attributes must - * be restored before file data is written. If this is true, - * then we either need to write all extended attributes both - * before and after restoring the data, or find some rule for - * determining which must go first and which last. Due to the - * many ways people are using xattrs, this may prove to be an - * intractable problem. - */ - -#ifdef HAVE_FCHDIR - /* If we changed directory above, restore it here. */ - if (a->restore_pwd >= 0) { - r = fchdir(a->restore_pwd); - if (r != 0) { - archive_set_error(&a->archive, errno, "chdir() failure"); - ret = ARCHIVE_FATAL; - } - close(a->restore_pwd); - a->restore_pwd = -1; - } -#endif - - /* - * Fixup uses the unedited pathname from archive_entry_pathname(), - * because it is relative to the base dir and the edited path - * might be relative to some intermediate dir as a result of the - * deep restore logic. - */ - if (a->deferred & TODO_MODE) { - fe = current_fixup(a, archive_entry_pathname(entry)); - fe->fixup |= TODO_MODE_BASE; - fe->mode = a->mode; - } - - if ((a->deferred & TODO_TIMES) - && (archive_entry_mtime_is_set(entry) - || archive_entry_atime_is_set(entry))) { - fe = current_fixup(a, archive_entry_pathname(entry)); - fe->fixup |= TODO_TIMES; - if (archive_entry_atime_is_set(entry)) { - fe->atime = archive_entry_atime(entry); - fe->atime_nanos = archive_entry_atime_nsec(entry); - } else { - /* If atime is unset, use start time. */ - fe->atime = a->start_time; - fe->atime_nanos = 0; - } - if (archive_entry_mtime_is_set(entry)) { - fe->mtime = archive_entry_mtime(entry); - fe->mtime_nanos = archive_entry_mtime_nsec(entry); - } else { - /* If mtime is unset, use start time. */ - fe->mtime = a->start_time; - fe->mtime_nanos = 0; - } - if (archive_entry_birthtime_is_set(entry)) { - fe->birthtime = archive_entry_birthtime(entry); - fe->birthtime_nanos = archive_entry_birthtime_nsec(entry); - } else { - /* If birthtime is unset, use mtime. */ - fe->birthtime = fe->mtime; - fe->birthtime_nanos = fe->mtime_nanos; - } - } - - if (a->deferred & TODO_FFLAGS) { - fe = current_fixup(a, archive_entry_pathname(entry)); - fe->fixup |= TODO_FFLAGS; - /* TODO: Complete this.. defer fflags from below. */ - } - - /* We've created the object and are ready to pour data into it. */ - if (ret >= ARCHIVE_WARN) - a->archive.state = ARCHIVE_STATE_DATA; - /* - * If it's not open, tell our client not to try writing. - * In particular, dirs, links, etc, don't get written to. - */ - if (a->fd < 0) { - archive_entry_set_size(entry, 0); - a->filesize = 0; - } -done: - /* Restore the user's umask before returning. */ - umask(a->user_umask); - - return (ret); -} - -int -archive_write_disk_set_skip_file(struct archive *_a, dev_t d, ino_t i) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_disk_set_skip_file"); - a->skip_file_dev = d; - a->skip_file_ino = i; - return (ARCHIVE_OK); -} - -static ssize_t -write_data_block(struct archive_write_disk *a, const char *buff, size_t size) -{ - uint64_t start_size = size; - ssize_t bytes_written = 0; - ssize_t block_size = 0, bytes_to_write; - - if (size == 0) - return (ARCHIVE_OK); - - if (a->filesize == 0 || a->fd < 0) { - archive_set_error(&a->archive, 0, - "Attempt to write to an empty file"); - return (ARCHIVE_WARN); - } - - if (a->flags & ARCHIVE_EXTRACT_SPARSE) { -#if HAVE_STRUCT_STAT_ST_BLKSIZE - int r; - if ((r = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK) - return (r); - block_size = a->pst->st_blksize; -#else - /* XXX TODO XXX Is there a more appropriate choice here ? */ - /* This needn't match the filesystem allocation size. */ - block_size = 16*1024; -#endif - } - - /* If this write would run beyond the file size, truncate it. */ - if (a->filesize >= 0 && (off_t)(a->offset + size) > a->filesize) - start_size = size = (size_t)(a->filesize - a->offset); - - /* Write the data. */ - while (size > 0) { - if (block_size == 0) { - bytes_to_write = size; - } else { - /* We're sparsifying the file. */ - const char *p, *end; - off_t block_end; - - /* Skip leading zero bytes. */ - for (p = buff, end = buff + size; p < end; ++p) { - if (*p != '\0') - break; - } - a->offset += p - buff; - size -= p - buff; - buff = p; - if (size == 0) - break; - - /* Calculate next block boundary after offset. */ - block_end - = (a->offset / block_size + 1) * block_size; - - /* If the adjusted write would cross block boundary, - * truncate it to the block boundary. */ - bytes_to_write = size; - if (a->offset + bytes_to_write > block_end) - bytes_to_write = block_end - a->offset; - } - /* Seek if necessary to the specified offset. */ - if (a->offset != a->fd_offset) { - if (lseek(a->fd, a->offset, SEEK_SET) < 0) { - archive_set_error(&a->archive, errno, - "Seek failed"); - return (ARCHIVE_FATAL); - } - a->fd_offset = a->offset; - a->archive.file_position = a->offset; - a->archive.raw_position = a->offset; - } - bytes_written = write(a->fd, buff, bytes_to_write); - if (bytes_written < 0) { - archive_set_error(&a->archive, errno, "Write failed"); - return (ARCHIVE_WARN); - } - buff += bytes_written; - size -= bytes_written; - a->offset += bytes_written; - a->archive.file_position += bytes_written; - a->archive.raw_position += bytes_written; - a->fd_offset = a->offset; - } - return (start_size - size); -} - -static ssize_t -_archive_write_data_block(struct archive *_a, - const void *buff, size_t size, off_t offset) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - ssize_t r; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_DATA, "archive_write_disk_block"); - - a->offset = offset; - r = write_data_block(a, buff, size); - if (r < ARCHIVE_OK) - return (r); - if ((size_t)r < size) { - archive_set_error(&a->archive, 0, - "Write request too large"); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); -} - -static ssize_t -_archive_write_data(struct archive *_a, const void *buff, size_t size) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_DATA, "archive_write_data"); - - return (write_data_block(a, buff, size)); -} - -static int -_archive_write_finish_entry(struct archive *_a) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - int ret = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_write_finish_entry"); - if (a->archive.state & ARCHIVE_STATE_HEADER) - return (ARCHIVE_OK); - archive_clear_error(&a->archive); - - /* Pad or truncate file to the right size. */ - if (a->fd < 0) { - /* There's no file. */ - } else if (a->filesize < 0) { - /* File size is unknown, so we can't set the size. */ - } else if (a->fd_offset == a->filesize) { - /* Last write ended at exactly the filesize; we're done. */ - /* Hopefully, this is the common case. */ - } else { -#if HAVE_FTRUNCATE - if (ftruncate(a->fd, a->filesize) == -1 && - a->filesize == 0) { - archive_set_error(&a->archive, errno, - "File size could not be restored"); - return (ARCHIVE_FAILED); - } -#endif - /* - * Not all platforms implement the XSI option to - * extend files via ftruncate. Stat() the file again - * to see what happened. - */ - a->pst = NULL; - if ((ret = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK) - return (ret); - /* We can use lseek()/write() to extend the file if - * ftruncate didn't work or isn't available. */ - if (a->st.st_size < a->filesize) { - const char nul = '\0'; - if (lseek(a->fd, a->filesize - 1, SEEK_SET) < 0) { - archive_set_error(&a->archive, errno, - "Seek failed"); - return (ARCHIVE_FATAL); - } - if (write(a->fd, &nul, 1) < 0) { - archive_set_error(&a->archive, errno, - "Write to restore size failed"); - return (ARCHIVE_FATAL); - } - a->pst = NULL; - } - } - - /* Restore metadata. */ - - /* - * Look up the "real" UID only if we're going to need it. - * TODO: the TODO_SGID condition can be dropped here, can't it? - */ - if (a->todo & (TODO_OWNER | TODO_SUID | TODO_SGID)) { - a->uid = a->lookup_uid(a->lookup_uid_data, - archive_entry_uname(a->entry), - archive_entry_uid(a->entry)); - } - /* Look up the "real" GID only if we're going to need it. */ - /* TODO: the TODO_SUID condition can be dropped here, can't it? */ - if (a->todo & (TODO_OWNER | TODO_SGID | TODO_SUID)) { - a->gid = a->lookup_gid(a->lookup_gid_data, - archive_entry_gname(a->entry), - archive_entry_gid(a->entry)); - } - /* - * If restoring ownership, do it before trying to restore suid/sgid - * bits. If we set the owner, we know what it is and can skip - * a stat() call to examine the ownership of the file on disk. - */ - if (a->todo & TODO_OWNER) - ret = set_ownership(a); - if (a->todo & TODO_MODE) { - int r2 = set_mode(a, a->mode); - if (r2 < ret) ret = r2; - } - if (a->todo & TODO_ACLS) { - int r2 = set_acls(a); - if (r2 < ret) ret = r2; - } - - /* - * Security-related extended attributes (such as - * security.capability on Linux) have to be restored last, - * since they're implicitly removed by other file changes. - */ - if (a->todo & TODO_XATTR) { - int r2 = set_xattrs(a); - if (r2 < ret) ret = r2; - } - - /* - * Some flags prevent file modification; they must be restored after - * file contents are written. - */ - if (a->todo & TODO_FFLAGS) { - int r2 = set_fflags(a); - if (r2 < ret) ret = r2; - } - /* - * Time has to be restored after all other metadata; - * otherwise atime will get changed. - */ - if (a->todo & TODO_TIMES) { - int r2 = set_times(a); - if (r2 < ret) ret = r2; - } - - /* If there's an fd, we can close it now. */ - if (a->fd >= 0) { - close(a->fd); - a->fd = -1; - } - /* If there's an entry, we can release it now. */ - if (a->entry) { - archive_entry_free(a->entry); - a->entry = NULL; - } - a->archive.state = ARCHIVE_STATE_HEADER; - return (ret); -} - -int -archive_write_disk_set_group_lookup(struct archive *_a, - void *private_data, - gid_t (*lookup_gid)(void *private, const char *gname, gid_t gid), - void (*cleanup_gid)(void *private)) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_disk_set_group_lookup"); - - a->lookup_gid = lookup_gid; - a->cleanup_gid = cleanup_gid; - a->lookup_gid_data = private_data; - return (ARCHIVE_OK); -} - -int -archive_write_disk_set_user_lookup(struct archive *_a, - void *private_data, - uid_t (*lookup_uid)(void *private, const char *uname, uid_t uid), - void (*cleanup_uid)(void *private)) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_disk_set_user_lookup"); - - a->lookup_uid = lookup_uid; - a->cleanup_uid = cleanup_uid; - a->lookup_uid_data = private_data; - return (ARCHIVE_OK); -} - - -/* - * Create a new archive_write_disk object and initialize it with global state. - */ -struct archive * -archive_write_disk_new(void) -{ - struct archive_write_disk *a; - - a = (struct archive_write_disk *)malloc(sizeof(*a)); - if (a == NULL) - return (NULL); - memset(a, 0, sizeof(*a)); - a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC; - /* We're ready to write a header immediately. */ - a->archive.state = ARCHIVE_STATE_HEADER; - a->archive.vtable = archive_write_disk_vtable(); - a->lookup_uid = trivial_lookup_uid; - a->lookup_gid = trivial_lookup_gid; - a->start_time = time(NULL); -#ifdef HAVE_GETEUID - a->user_uid = geteuid(); -#endif /* HAVE_GETEUID */ - if (archive_string_ensure(&a->path_safe, 512) == NULL) { - free(a); - return (NULL); - } - return (&a->archive); -} - - -/* - * If pathname is longer than PATH_MAX, chdir to a suitable - * intermediate dir and edit the path down to a shorter suffix. Note - * that this routine never returns an error; if the chdir() attempt - * fails for any reason, we just go ahead with the long pathname. The - * object creation is likely to fail, but any error will get handled - * at that time. - */ -#ifdef HAVE_FCHDIR -static void -edit_deep_directories(struct archive_write_disk *a) -{ - int ret; - char *tail = a->name; - - a->restore_pwd = -1; - - /* If path is short, avoid the open() below. */ - if (strlen(tail) <= PATH_MAX) - return; - - /* Try to record our starting dir. */ - a->restore_pwd = open(".", O_RDONLY | O_BINARY); - if (a->restore_pwd < 0) - return; - - /* As long as the path is too long... */ - while (strlen(tail) > PATH_MAX) { - /* Locate a dir prefix shorter than PATH_MAX. */ - tail += PATH_MAX - 8; - while (tail > a->name && *tail != '/') - tail--; - /* Exit if we find a too-long path component. */ - if (tail <= a->name) - return; - /* Create the intermediate dir and chdir to it. */ - *tail = '\0'; /* Terminate dir portion */ - ret = create_dir(a, a->name); - if (ret == ARCHIVE_OK && chdir(a->name) != 0) - ret = ARCHIVE_FAILED; - *tail = '/'; /* Restore the / we removed. */ - if (ret != ARCHIVE_OK) - return; - tail++; - /* The chdir() succeeded; we've now shortened the path. */ - a->name = tail; - } - return; -} -#endif - -/* - * The main restore function. - */ -static int -restore_entry(struct archive_write_disk *a) -{ - int ret = ARCHIVE_OK, en; - - if (a->flags & ARCHIVE_EXTRACT_UNLINK && !S_ISDIR(a->mode)) { - /* - * TODO: Fix this. Apparently, there are platforms - * that still allow root to hose the entire filesystem - * by unlinking a dir. The S_ISDIR() test above - * prevents us from using unlink() here if the new - * object is a dir, but that doesn't mean the old - * object isn't a dir. - */ - if (unlink(a->name) == 0) { - /* We removed it, reset cached stat. */ - a->pst = NULL; - } else if (errno == ENOENT) { - /* File didn't exist, that's just as good. */ - } else if (rmdir(a->name) == 0) { - /* It was a dir, but now it's gone. */ - a->pst = NULL; - } else { - /* We tried, but couldn't get rid of it. */ - archive_set_error(&a->archive, errno, - "Could not unlink"); - return(ARCHIVE_FAILED); - } - } - - /* Try creating it first; if this fails, we'll try to recover. */ - en = create_filesystem_object(a); - - if ((en == ENOTDIR || en == ENOENT) - && !(a->flags & ARCHIVE_EXTRACT_NO_AUTODIR)) { - /* If the parent dir doesn't exist, try creating it. */ - create_parent_dir(a, a->name); - /* Now try to create the object again. */ - en = create_filesystem_object(a); - } - - if ((en == EISDIR || en == EEXIST) - && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { - /* If we're not overwriting, we're done. */ - archive_set_error(&a->archive, en, "Already exists"); - return (ARCHIVE_FAILED); - } - - /* - * Some platforms return EISDIR if you call - * open(O_WRONLY | O_EXCL | O_CREAT) on a directory, some - * return EEXIST. POSIX is ambiguous, requiring EISDIR - * for open(O_WRONLY) on a dir and EEXIST for open(O_EXCL | O_CREAT) - * on an existing item. - */ - if (en == EISDIR) { - /* A dir is in the way of a non-dir, rmdir it. */ - if (rmdir(a->name) != 0) { - archive_set_error(&a->archive, errno, - "Can't remove already-existing dir"); - return (ARCHIVE_FAILED); - } - a->pst = NULL; - /* Try again. */ - en = create_filesystem_object(a); - } else if (en == EEXIST) { - /* - * We know something is in the way, but we don't know what; - * we need to find out before we go any further. - */ - int r = 0; - /* - * The SECURE_SYMLINK logic has already removed a - * symlink to a dir if the client wants that. So - * follow the symlink if we're creating a dir. - */ - if (S_ISDIR(a->mode)) - r = stat(a->name, &a->st); - /* - * If it's not a dir (or it's a broken symlink), - * then don't follow it. - */ - if (r != 0 || !S_ISDIR(a->mode)) - r = lstat(a->name, &a->st); - if (r != 0) { - archive_set_error(&a->archive, errno, - "Can't stat existing object"); - return (ARCHIVE_FAILED); - } - - /* - * NO_OVERWRITE_NEWER doesn't apply to directories. - */ - if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER) - && !S_ISDIR(a->st.st_mode)) { - if (!older(&(a->st), a->entry)) { - archive_set_error(&a->archive, 0, - "File on disk is not older; skipping."); - return (ARCHIVE_FAILED); - } - } - - /* If it's our archive, we're done. */ - if (a->skip_file_dev > 0 && - a->skip_file_ino > 0 && - a->st.st_dev == a->skip_file_dev && - a->st.st_ino == a->skip_file_ino) { - archive_set_error(&a->archive, 0, "Refusing to overwrite archive"); - return (ARCHIVE_FAILED); - } - - if (!S_ISDIR(a->st.st_mode)) { - /* A non-dir is in the way, unlink it. */ - if (unlink(a->name) != 0) { - archive_set_error(&a->archive, errno, - "Can't unlink already-existing object"); - return (ARCHIVE_FAILED); - } - a->pst = NULL; - /* Try again. */ - en = create_filesystem_object(a); - } else if (!S_ISDIR(a->mode)) { - /* A dir is in the way of a non-dir, rmdir it. */ - if (rmdir(a->name) != 0) { - archive_set_error(&a->archive, errno, - "Can't remove already-existing dir"); - return (ARCHIVE_FAILED); - } - /* Try again. */ - en = create_filesystem_object(a); - } else { - /* - * There's a dir in the way of a dir. Don't - * waste time with rmdir()/mkdir(), just fix - * up the permissions on the existing dir. - * Note that we don't change perms on existing - * dirs unless _EXTRACT_PERM is specified. - */ - if ((a->mode != a->st.st_mode) - && (a->todo & TODO_MODE_FORCE)) - a->deferred |= (a->todo & TODO_MODE); - /* Ownership doesn't need deferred fixup. */ - en = 0; /* Forget the EEXIST. */ - } - } - - if (en) { - /* Everything failed; give up here. */ - archive_set_error(&a->archive, en, "Can't create '%s'", - a->name); - return (ARCHIVE_FAILED); - } - - a->pst = NULL; /* Cached stat data no longer valid. */ - return (ret); -} - -/* - * Returns 0 if creation succeeds, or else returns errno value from - * the failed system call. Note: This function should only ever perform - * a single system call. - */ -static int -create_filesystem_object(struct archive_write_disk *a) -{ - /* Create the entry. */ - const char *linkname; - mode_t final_mode, mode; - int r; - - /* We identify hard/symlinks according to the link names. */ - /* Since link(2) and symlink(2) don't handle modes, we're done here. */ - linkname = archive_entry_hardlink(a->entry); - if (linkname != NULL) { -#if !HAVE_LINK - return (EPERM); -#else - r = link(linkname, a->name) ? errno : 0; - /* - * New cpio and pax formats allow hardlink entries - * to carry data, so we may have to open the file - * for hardlink entries. - * - * If the hardlink was successfully created and - * the archive doesn't have carry data for it, - * consider it to be non-authoritive for meta data. - * This is consistent with GNU tar and BSD pax. - * If the hardlink does carry data, let the last - * archive entry decide ownership. - */ - if (r == 0 && a->filesize <= 0) { - a->todo = 0; - a->deferred = 0; - } if (r == 0 && a->filesize > 0) { - a->fd = open(a->name, O_WRONLY | O_TRUNC | O_BINARY); - if (a->fd < 0) - r = errno; - } - return (r); -#endif - } - linkname = archive_entry_symlink(a->entry); - if (linkname != NULL) { -#if HAVE_SYMLINK - return symlink(linkname, a->name) ? errno : 0; -#else - return (EPERM); -#endif - } - - /* - * The remaining system calls all set permissions, so let's - * try to take advantage of that to avoid an extra chmod() - * call. (Recall that umask is set to zero right now!) - */ - - /* Mode we want for the final restored object (w/o file type bits). */ - final_mode = a->mode & 07777; - /* - * The mode that will actually be restored in this step. Note - * that SUID, SGID, etc, require additional work to ensure - * security, so we never restore them at this point. - */ - mode = final_mode & 0777; - - switch (a->mode & AE_IFMT) { - default: - /* POSIX requires that we fall through here. */ - /* FALLTHROUGH */ - case AE_IFREG: - a->fd = open(a->name, - O_WRONLY | O_CREAT | O_EXCL | O_BINARY, mode); - r = (a->fd < 0); - break; - case AE_IFCHR: -#ifdef HAVE_MKNOD - /* Note: we use AE_IFCHR for the case label, and - * S_IFCHR for the mknod() call. This is correct. */ - r = mknod(a->name, mode | S_IFCHR, - archive_entry_rdev(a->entry)); - break; -#else - /* TODO: Find a better way to warn about our inability - * to restore a char device node. */ - return (EINVAL); -#endif /* HAVE_MKNOD */ - case AE_IFBLK: -#ifdef HAVE_MKNOD - r = mknod(a->name, mode | S_IFBLK, - archive_entry_rdev(a->entry)); - break; -#else - /* TODO: Find a better way to warn about our inability - * to restore a block device node. */ - return (EINVAL); -#endif /* HAVE_MKNOD */ - case AE_IFDIR: - mode = (mode | MINIMUM_DIR_MODE) & MAXIMUM_DIR_MODE; - r = mkdir(a->name, mode); - if (r == 0) { - /* Defer setting dir times. */ - a->deferred |= (a->todo & TODO_TIMES); - a->todo &= ~TODO_TIMES; - /* Never use an immediate chmod(). */ - /* We can't avoid the chmod() entirely if EXTRACT_PERM - * because of SysV SGID inheritance. */ - if ((mode != final_mode) - || (a->flags & ARCHIVE_EXTRACT_PERM)) - a->deferred |= (a->todo & TODO_MODE); - a->todo &= ~TODO_MODE; - } - break; - case AE_IFIFO: -#ifdef HAVE_MKFIFO - r = mkfifo(a->name, mode); - break; -#else - /* TODO: Find a better way to warn about our inability - * to restore a fifo. */ - return (EINVAL); -#endif /* HAVE_MKFIFO */ - } - - /* All the system calls above set errno on failure. */ - if (r) - return (errno); - - /* If we managed to set the final mode, we've avoided a chmod(). */ - if (mode == final_mode) - a->todo &= ~TODO_MODE; - return (0); -} - -/* - * Cleanup function for archive_extract. Mostly, this involves processing - * the fixup list, which is used to address a number of problems: - * * Dir permissions might prevent us from restoring a file in that - * dir, so we restore the dir with minimum 0700 permissions first, - * then correct the mode at the end. - * * Similarly, the act of restoring a file touches the directory - * and changes the timestamp on the dir, so we have to touch-up dir - * timestamps at the end as well. - * * Some file flags can interfere with the restore by, for example, - * preventing the creation of hardlinks to those files. - * - * Note that tar/cpio do not require that archives be in a particular - * order; there is no way to know when the last file has been restored - * within a directory, so there's no way to optimize the memory usage - * here by fixing up the directory any earlier than the - * end-of-archive. - * - * XXX TODO: Directory ACLs should be restored here, for the same - * reason we set directory perms here. XXX - */ -static int -_archive_write_close(struct archive *_a) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - struct fixup_entry *next, *p; - int ret; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_write_disk_close"); - ret = _archive_write_finish_entry(&a->archive); - - /* Sort dir list so directories are fixed up in depth-first order. */ - p = sort_dir_list(a->fixup_list); - - while (p != NULL) { - a->pst = NULL; /* Mark stat cache as out-of-date. */ - if (p->fixup & TODO_TIMES) { -#ifdef HAVE_UTIMES - /* {f,l,}utimes() are preferred, when available. */ -#if defined(_WIN32) && !defined(__CYGWIN__) - struct __timeval times[2]; -#else - struct timeval times[2]; -#endif - times[0].tv_sec = p->atime; - times[0].tv_usec = p->atime_nanos / 1000; -#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME - /* if it's valid and not mtime, push the birthtime first */ - if (((times[1].tv_sec = p->birthtime) < p->mtime) && - (p->birthtime > 0)) - { - times[1].tv_usec = p->birthtime_nanos / 1000; - utimes(p->name, times); - } -#endif - times[1].tv_sec = p->mtime; - times[1].tv_usec = p->mtime_nanos / 1000; -#ifdef HAVE_LUTIMES - lutimes(p->name, times); -#else - utimes(p->name, times); -#endif -#else - /* utime() is more portable, but less precise. */ - struct utimbuf times; - times.modtime = p->mtime; - times.actime = p->atime; - - utime(p->name, ×); -#endif - } - if (p->fixup & TODO_MODE_BASE) - chmod(p->name, p->mode); - - if (p->fixup & TODO_FFLAGS) - set_fflags_platform(a, -1, p->name, - p->mode, p->fflags_set, 0); - - next = p->next; - free(p->name); - free(p); - p = next; - } - a->fixup_list = NULL; - return (ret); -} - -static int -_archive_write_free(struct archive *_a) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - int ret; - ret = _archive_write_close(&a->archive); - if (a->cleanup_gid != NULL && a->lookup_gid_data != NULL) - (a->cleanup_gid)(a->lookup_gid_data); - if (a->cleanup_uid != NULL && a->lookup_uid_data != NULL) - (a->cleanup_uid)(a->lookup_uid_data); - if (a->entry) - archive_entry_free(a->entry); - archive_string_free(&a->_name_data); - archive_string_free(&a->archive.error_string); - archive_string_free(&a->path_safe); - free(a); - return (ret); -} - -/* - * Simple O(n log n) merge sort to order the fixup list. In - * particular, we want to restore dir timestamps depth-first. - */ -static struct fixup_entry * -sort_dir_list(struct fixup_entry *p) -{ - struct fixup_entry *a, *b, *t; - - if (p == NULL) - return (NULL); - /* A one-item list is already sorted. */ - if (p->next == NULL) - return (p); - - /* Step 1: split the list. */ - t = p; - a = p->next->next; - while (a != NULL) { - /* Step a twice, t once. */ - a = a->next; - if (a != NULL) - a = a->next; - t = t->next; - } - /* Now, t is at the mid-point, so break the list here. */ - b = t->next; - t->next = NULL; - a = p; - - /* Step 2: Recursively sort the two sub-lists. */ - a = sort_dir_list(a); - b = sort_dir_list(b); - - /* Step 3: Merge the returned lists. */ - /* Pick the first element for the merged list. */ - if (strcmp(a->name, b->name) > 0) { - t = p = a; - a = a->next; - } else { - t = p = b; - b = b->next; - } - - /* Always put the later element on the list first. */ - while (a != NULL && b != NULL) { - if (strcmp(a->name, b->name) > 0) { - t->next = a; - a = a->next; - } else { - t->next = b; - b = b->next; - } - t = t->next; - } - - /* Only one list is non-empty, so just splice it on. */ - if (a != NULL) - t->next = a; - if (b != NULL) - t->next = b; - - return (p); -} - -/* - * Returns a new, initialized fixup entry. - * - * TODO: Reduce the memory requirements for this list by using a tree - * structure rather than a simple list of names. - */ -static struct fixup_entry * -new_fixup(struct archive_write_disk *a, const char *pathname) -{ - struct fixup_entry *fe; - - fe = (struct fixup_entry *)malloc(sizeof(struct fixup_entry)); - if (fe == NULL) - return (NULL); - fe->next = a->fixup_list; - a->fixup_list = fe; - fe->fixup = 0; - fe->name = strdup(pathname); - return (fe); -} - -/* - * Returns a fixup structure for the current entry. - */ -static struct fixup_entry * -current_fixup(struct archive_write_disk *a, const char *pathname) -{ - if (a->current_fixup == NULL) - a->current_fixup = new_fixup(a, pathname); - return (a->current_fixup); -} - -/* TODO: Make this work. */ -/* - * TODO: The deep-directory support bypasses this; disable deep directory - * support if we're doing symlink checks. - */ -/* - * TODO: Someday, integrate this with the deep dir support; they both - * scan the path and both can be optimized by comparing against other - * recent paths. - */ -/* TODO: Extend this to support symlinks on Windows Vista and later. */ -static int -check_symlinks(struct archive_write_disk *a) -{ -#if !defined(HAVE_LSTAT) - /* Platform doesn't have lstat, so we can't look for symlinks. */ - (void)a; /* UNUSED */ - return (ARCHIVE_OK); -#else - char *pn, *p; - char c; - int r; - struct stat st; - - /* - * Guard against symlink tricks. Reject any archive entry whose - * destination would be altered by a symlink. - */ - /* Whatever we checked last time doesn't need to be re-checked. */ - pn = a->name; - p = a->path_safe.s; - while ((*pn != '\0') && (*p == *pn)) - ++p, ++pn; - c = pn[0]; - /* Keep going until we've checked the entire name. */ - while (pn[0] != '\0' && (pn[0] != '/' || pn[1] != '\0')) { - /* Skip the next path element. */ - while (*pn != '\0' && *pn != '/') - ++pn; - c = pn[0]; - pn[0] = '\0'; - /* Check that we haven't hit a symlink. */ - r = lstat(a->name, &st); - if (r != 0) { - /* We've hit a dir that doesn't exist; stop now. */ - if (errno == ENOENT) - break; - } else if (S_ISLNK(st.st_mode)) { - if (c == '\0') { - /* - * Last element is symlink; remove it - * so we can overwrite it with the - * item being extracted. - */ - if (unlink(a->name)) { - archive_set_error(&a->archive, errno, - "Could not remove symlink %s", - a->name); - pn[0] = c; - return (ARCHIVE_FAILED); - } - a->pst = NULL; - /* - * Even if we did remove it, a warning - * is in order. The warning is silly, - * though, if we're just replacing one - * symlink with another symlink. - */ - if (!S_ISLNK(a->mode)) { - archive_set_error(&a->archive, 0, - "Removing symlink %s", - a->name); - } - /* Symlink gone. No more problem! */ - pn[0] = c; - return (0); - } else if (a->flags & ARCHIVE_EXTRACT_UNLINK) { - /* User asked us to remove problems. */ - if (unlink(a->name) != 0) { - archive_set_error(&a->archive, 0, - "Cannot remove intervening symlink %s", - a->name); - pn[0] = c; - return (ARCHIVE_FAILED); - } - a->pst = NULL; - } else { - archive_set_error(&a->archive, 0, - "Cannot extract through symlink %s", - a->name); - pn[0] = c; - return (ARCHIVE_FAILED); - } - } - } - pn[0] = c; - /* We've checked and/or cleaned the whole path, so remember it. */ - archive_strcpy(&a->path_safe, a->name); - return (ARCHIVE_OK); -#endif -} - -#if defined(_WIN32) || defined(__CYGWIN__) -static int -guidword(const char *p, int n) -{ - int i; - - for (i = 0; i < n; i++) { - if ((*p >= '0' && *p <= '9') || - (*p >= 'a' && *p <= 'f') || - (*p >= 'A' && *p <= 'F')) - p++; - else - return (-1); - } - return (0); -} - -/* - * 1. Convert a path separator from '\' to '/' . - * We shouldn't check multi-byte character directly because some - * character-set have been using the '\' character for a part of - * its multibyte character code. - * 2. Replace unusable characters in Windows with underscore('_'). - * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx - */ -static int -cleanup_pathname_win(struct archive_write_disk *a) -{ - wchar_t wc; - char *p; - size_t alen, l; - - p = a->name; - /* Skip leading "\\.\" or "\\?\" or "\\?\UNC\" or - * "\\?\Volume{GUID}\" - * (absolute path prefixes used by Windows API) */ - if ((p[0] == '\\' || p[0] == '/') && (p[1] == '\\' || p[1] == '/' ) && - (p[2] == '.' || p[2] == '?') && (p[3] == '\\' || p[3] == '/')) - { - /* A path begin with "\\?\UNC\" */ - if (p[2] == '?' && - (p[4] == 'U' || p[4] == 'u') && - (p[5] == 'N' || p[5] == 'n') && - (p[6] == 'C' || p[6] == 'c') && - (p[7] == '\\' || p[7] == '/')) - p += 8; - /* A path begin with "\\?\Volume{GUID}\" */ - else if (p[2] == '?' && - (p[4] == 'V' || p[4] == 'v') && - (p[5] == 'O' || p[5] == 'o') && - (p[6] == 'L' || p[6] == 'l') && - (p[7] == 'U' || p[7] == 'u') && - (p[8] == 'M' || p[8] == 'm') && - (p[9] == 'E' || p[9] == 'e') && - p[10] == '{') { - if (guidword(p+11, 8) == 0 && p[19] == '-' && - guidword(p+20, 4) == 0 && p[24] == '-' && - guidword(p+25, 4) == 0 && p[29] == '-' && - guidword(p+30, 4) == 0 && p[34] == '-' && - guidword(p+35, 12) == 0 && p[47] == '}' && - (p[48] == '\\' || p[48] == '/')) - p += 49; - else - p += 4; - /* A path begin with "\\.\PhysicalDriveX" */ - } else if (p[2] == '.' && - (p[4] == 'P' || p[4] == 'p') && - (p[5] == 'H' || p[5] == 'h') && - (p[6] == 'Y' || p[6] == 'y') && - (p[7] == 'S' || p[7] == 's') && - (p[8] == 'I' || p[8] == 'i') && - (p[9] == 'C' || p[9] == 'c') && - (p[9] == 'A' || p[9] == 'a') && - (p[9] == 'L' || p[9] == 'l') && - (p[9] == 'D' || p[9] == 'd') && - (p[9] == 'R' || p[9] == 'r') && - (p[9] == 'I' || p[9] == 'i') && - (p[9] == 'V' || p[9] == 'v') && - (p[9] == 'E' || p[9] == 'e') && - (p[10] >= '0' && p[10] <= '9') && - p[11] == '\0') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Path is a physical drive name"); - return (ARCHIVE_FAILED); - } else - p += 4; - } - - /* Skip leading drive letter from archives created - * on Windows. */ - if (((p[0] >= 'a' && p[0] <= 'z') || - (p[0] >= 'A' && p[0] <= 'Z')) && - p[1] == ':') { - if (p[2] == '\0') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Path is a drive name"); - return (ARCHIVE_FAILED); - } - if (p[2] == '\\' || p[2] == '/') - p += 3; - } - - for (; *p != '\0'; p++) { - /* Rewrite the path name if its character is a unusable. */ - if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || - *p == '<' || *p == '>' || *p == '|') - *p = '_'; - } - alen = p - a->name; - if (alen == 0 || strchr(a->name, '\\') == NULL) - return (ARCHIVE_OK); - /* - * Convert path separator. - */ - p = a->name; - while (*p != '\0' && alen) { - l = mbtowc(&wc, p, alen); - if (l == -1) { - while (*p != '\0') { - if (*p == '\\') - *p = '/'; - ++p; - } - break; - } - if (l == 1 && wc == L'\\') - *p = '/'; - p += l; - alen -= l; - } - return (ARCHIVE_OK); -} -#endif - -/* - * Canonicalize the pathname. In particular, this strips duplicate - * '/' characters, '.' elements, and trailing '/'. It also raises an - * error for an empty path, a trailing '..' or (if _SECURE_NODOTDOT is - * set) any '..' in the path. - */ -static int -cleanup_pathname(struct archive_write_disk *a) -{ - char *dest, *src; - char separator = '\0'; - - dest = src = a->name; - if (*src == '\0') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid empty pathname"); - return (ARCHIVE_FAILED); - } - -#if defined(_WIN32) || defined(__CYGWIN__) - if (cleanup_pathname_win(a) != ARCHIVE_OK) - return (ARCHIVE_FAILED); -#endif - /* Skip leading '/'. */ - if (*src == '/') - separator = *src++; - - /* Scan the pathname one element at a time. */ - for (;;) { - /* src points to first char after '/' */ - if (src[0] == '\0') { - break; - } else if (src[0] == '/') { - /* Found '//', ignore second one. */ - src++; - continue; - } else if (src[0] == '.') { - if (src[1] == '\0') { - /* Ignore trailing '.' */ - break; - } else if (src[1] == '/') { - /* Skip './'. */ - src += 2; - continue; - } else if (src[1] == '.') { - if (src[2] == '/' || src[2] == '\0') { - /* Conditionally warn about '..' */ - if (a->flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Path contains '..'"); - return (ARCHIVE_FAILED); - } - } - /* - * Note: Under no circumstances do we - * remove '..' elements. In - * particular, restoring - * '/foo/../bar/' should create the - * 'foo' dir as a side-effect. - */ - } - } - - /* Copy current element, including leading '/'. */ - if (separator) - *dest++ = '/'; - while (*src != '\0' && *src != '/') { - *dest++ = *src++; - } - - if (*src == '\0') - break; - - /* Skip '/' separator. */ - separator = *src++; - } - /* - * We've just copied zero or more path elements, not including the - * final '/'. - */ - if (dest == a->name) { - /* - * Nothing got copied. The path must have been something - * like '.' or '/' or './' or '/././././/./'. - */ - if (separator) - *dest++ = '/'; - else - *dest++ = '.'; - } - /* Terminate the result. */ - *dest = '\0'; - return (ARCHIVE_OK); -} - -/* - * Create the parent directory of the specified path, assuming path - * is already in mutable storage. - */ -static int -create_parent_dir(struct archive_write_disk *a, char *path) -{ - char *slash; - int r; - - /* Remove tail element to obtain parent name. */ - slash = strrchr(path, '/'); - if (slash == NULL) - return (ARCHIVE_OK); - *slash = '\0'; - r = create_dir(a, path); - *slash = '/'; - return (r); -} - -/* - * Create the specified dir, recursing to create parents as necessary. - * - * Returns ARCHIVE_OK if the path exists when we're done here. - * Otherwise, returns ARCHIVE_FAILED. - * Assumes path is in mutable storage; path is unchanged on exit. - */ -static int -create_dir(struct archive_write_disk *a, char *path) -{ - struct stat st; - struct fixup_entry *le; - char *slash, *base; - mode_t mode_final, mode; - int r; - - /* Check for special names and just skip them. */ - slash = strrchr(path, '/'); - if (slash == NULL) - base = path; - else - base = slash + 1; - - if (base[0] == '\0' || - (base[0] == '.' && base[1] == '\0') || - (base[0] == '.' && base[1] == '.' && base[2] == '\0')) { - /* Don't bother trying to create null path, '.', or '..'. */ - if (slash != NULL) { - *slash = '\0'; - r = create_dir(a, path); - *slash = '/'; - return (r); - } - return (ARCHIVE_OK); - } - - /* - * Yes, this should be stat() and not lstat(). Using lstat() - * here loses the ability to extract through symlinks. Also note - * that this should not use the a->st cache. - */ - if (stat(path, &st) == 0) { - if (S_ISDIR(st.st_mode)) - return (ARCHIVE_OK); - if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { - archive_set_error(&a->archive, EEXIST, - "Can't create directory '%s'", path); - return (ARCHIVE_FAILED); - } - if (unlink(path) != 0) { - archive_set_error(&a->archive, errno, - "Can't create directory '%s': " - "Conflicting file cannot be removed", path); - return (ARCHIVE_FAILED); - } - } else if (errno != ENOENT && errno != ENOTDIR) { - /* Stat failed? */ - archive_set_error(&a->archive, errno, "Can't test directory '%s'", path); - return (ARCHIVE_FAILED); - } else if (slash != NULL) { - *slash = '\0'; - r = create_dir(a, path); - *slash = '/'; - if (r != ARCHIVE_OK) - return (r); - } - - /* - * Mode we want for the final restored directory. Per POSIX, - * implicitly-created dirs must be created obeying the umask. - * There's no mention whether this is different for privileged - * restores (which the rest of this code handles by pretending - * umask=0). I've chosen here to always obey the user's umask for - * implicit dirs, even if _EXTRACT_PERM was specified. - */ - mode_final = DEFAULT_DIR_MODE & ~a->user_umask; - /* Mode we want on disk during the restore process. */ - mode = mode_final; - mode |= MINIMUM_DIR_MODE; - mode &= MAXIMUM_DIR_MODE; - if (mkdir(path, mode) == 0) { - if (mode != mode_final) { - le = new_fixup(a, path); - le->fixup |=TODO_MODE_BASE; - le->mode = mode_final; - } - return (ARCHIVE_OK); - } - - /* - * Without the following check, a/b/../b/c/d fails at the - * second visit to 'b', so 'd' can't be created. Note that we - * don't add it to the fixup list here, as it's already been - * added. - */ - if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) - return (ARCHIVE_OK); - - archive_set_error(&a->archive, errno, "Failed to create dir '%s'", - path); - return (ARCHIVE_FAILED); -} - -/* - * Note: Although we can skip setting the user id if the desired user - * id matches the current user, we cannot skip setting the group, as - * many systems set the gid based on the containing directory. So - * we have to perform a chown syscall if we want to set the SGID - * bit. (The alternative is to stat() and then possibly chown(); it's - * more efficient to skip the stat() and just always chown().) Note - * that a successful chown() here clears the TODO_SGID_CHECK bit, which - * allows set_mode to skip the stat() check for the GID. - */ -static int -set_ownership(struct archive_write_disk *a) -{ -#ifndef __CYGWIN__ -/* unfortunately, on win32 there is no 'root' user with uid 0, - so we just have to try the chown and see if it works */ - - /* If we know we can't change it, don't bother trying. */ - if (a->user_uid != 0 && a->user_uid != a->uid) { - archive_set_error(&a->archive, errno, - "Can't set UID=%d", a->uid); - return (ARCHIVE_WARN); - } -#endif - -#ifdef HAVE_FCHOWN - /* If we have an fd, we can avoid a race. */ - if (a->fd >= 0 && fchown(a->fd, a->uid, a->gid) == 0) { - /* We've set owner and know uid/gid are correct. */ - a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); - return (ARCHIVE_OK); - } -#endif - - /* We prefer lchown() but will use chown() if that's all we have. */ - /* Of course, if we have neither, this will always fail. */ -#ifdef HAVE_LCHOWN - if (lchown(a->name, a->uid, a->gid) == 0) { - /* We've set owner and know uid/gid are correct. */ - a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); - return (ARCHIVE_OK); - } -#elif HAVE_CHOWN - if (!S_ISLNK(a->mode) && chown(a->name, a->uid, a->gid) == 0) { - /* We've set owner and know uid/gid are correct. */ - a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); - return (ARCHIVE_OK); - } -#endif - - archive_set_error(&a->archive, errno, - "Can't set user=%d/group=%d for %s", a->uid, a->gid, - a->name); - return (ARCHIVE_WARN); -} - - -#if defined(HAVE_UTIMENSAT) && defined(HAVE_FUTIMENS) -/* - * utimensat() and futimens() are defined in POSIX.1-2008. They provide ns - * resolution and setting times on fd and on symlinks, too. - */ -static int -set_time(int fd, int mode, const char *name, - time_t atime, long atime_nsec, - time_t mtime, long mtime_nsec) -{ - struct timespec ts[2]; - ts[0].tv_sec = atime; - ts[0].tv_nsec = atime_nsec; - ts[1].tv_sec = mtime; - ts[1].tv_nsec = mtime_nsec; - if (fd >= 0) - return futimens(fd, ts); - return utimensat(AT_FDCWD, name, ts, AT_SYMLINK_NOFOLLOW); -} -#elif HAVE_UTIMES -/* - * The utimes()-family functions provide µs-resolution and - * a way to set time on an fd or a symlink. We prefer them - * when they're available and utimensat/futimens aren't there. - */ -static int -set_time(int fd, int mode, const char *name, - time_t atime, long atime_nsec, - time_t mtime, long mtime_nsec) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - struct __timeval times[2]; -#else - struct timeval times[2]; -#endif - - times[0].tv_sec = atime; - times[0].tv_usec = atime_nsec / 1000; - times[1].tv_sec = mtime; - times[1].tv_usec = mtime_nsec / 1000; - -#ifdef HAVE_FUTIMES - if (fd >= 0) - return (futimes(fd, times)); -#else - (void)fd; /* UNUSED */ -#endif -#ifdef HAVE_LUTIMES - (void)mode; /* UNUSED */ - return (lutimes(name, times)); -#else - if (S_ISLNK(mode)) - return (0); - return (utimes(name, times)); -#endif -} -#elif defined(HAVE_UTIME) -/* - * utime() is an older, more standard interface that we'll use - * if utimes() isn't available. - */ -static int -set_time(int fd, int mode, const char *name, - time_t atime, long atime_nsec, - time_t mtime, long mtime_nsec) -{ - struct utimbuf times; - (void)fd; /* UNUSED */ - (void)name; /* UNUSED */ - (void)atime_nsec; /* UNUSED */ - (void)mtime_nsec; /* UNUSED */ - times.actime = atime; - times.modtime = mtime; - if (S_ISLNK(mode)) - return (ARCHIVE_OK); - return (utime(name, ×)); -} -#else -static int -set_time(int fd, int mode, const char *name, - time_t atime, long atime_nsec, - time_t mtime, long mtime_nsec) -{ - return (ARCHIVE_WARN); -} -#endif - -static int -set_times(struct archive_write_disk *a) -{ - time_t atime = a->start_time, mtime = a->start_time; - long atime_nsec = 0, mtime_nsec = 0; - - /* If no time was provided, we're done. */ - if (!archive_entry_atime_is_set(a->entry) -#if HAVE_STRUCT_STAT_ST_BIRTHTIME - && !archive_entry_birthtime_is_set(a->entry) -#endif - && !archive_entry_mtime_is_set(a->entry)) - return (ARCHIVE_OK); - - /* If no atime was specified, use start time instead. */ - /* In theory, it would be marginally more correct to use - * time(NULL) here, but that would cost us an extra syscall - * for little gain. */ - if (archive_entry_atime_is_set(a->entry)) { - atime = archive_entry_atime(a->entry); - atime_nsec = archive_entry_atime_nsec(a->entry); - } - - /* - * If you have struct stat.st_birthtime, we assume BSD birthtime - * semantics, in which {f,l,}utimes() updates birthtime to earliest - * mtime. So we set the time twice, first using the birthtime, - * then using the mtime. - */ -#if HAVE_STRUCT_STAT_ST_BIRTHTIME - /* If birthtime is set, flush that through to disk first. */ - if (archive_entry_birthtime_is_set(a->entry)) - if (set_time(a->fd, a->mode, a->name, atime, atime_nsec, - archive_entry_birthtime(a->entry), - archive_entry_birthtime_nsec(a->entry))) { - archive_set_error(&a->archive, errno, - "Can't update time for %s", - a->name); - return (ARCHIVE_WARN); - } -#endif - - if (archive_entry_mtime_is_set(a->entry)) { - mtime = archive_entry_mtime(a->entry); - mtime_nsec = archive_entry_mtime_nsec(a->entry); - } - if (set_time(a->fd, a->mode, a->name, - atime, atime_nsec, mtime, mtime_nsec)) { - archive_set_error(&a->archive, errno, - "Can't update time for %s", - a->name); - return (ARCHIVE_WARN); - } - - /* - * Note: POSIX does not provide a portable way to restore ctime. - * (Apart from resetting the system clock, which is distasteful.) - * So, any restoration of ctime will necessarily be OS-specific. - */ - - return (ARCHIVE_OK); -} - -static int -set_mode(struct archive_write_disk *a, int mode) -{ - int r = ARCHIVE_OK; - mode &= 07777; /* Strip off file type bits. */ - - if (a->todo & TODO_SGID_CHECK) { - /* - * If we don't know the GID is right, we must stat() - * to verify it. We can't just check the GID of this - * process, since systems sometimes set GID from - * the enclosing dir or based on ACLs. - */ - if ((r = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK) - return (r); - if (a->pst->st_gid != a->gid) { - mode &= ~ S_ISGID; -#if !defined(_WIN32) || defined(__CYGWIN__) - if (a->flags & ARCHIVE_EXTRACT_OWNER) { - /* - * This is only an error if you - * requested owner restore. If you - * didn't, we'll try to restore - * sgid/suid, but won't consider it a - * problem if we can't. - */ - archive_set_error(&a->archive, -1, - "Can't restore SGID bit"); - r = ARCHIVE_WARN; - } -#endif - } - /* While we're here, double-check the UID. */ - if (a->pst->st_uid != a->uid - && (a->todo & TODO_SUID)) { - mode &= ~ S_ISUID; -#if !defined(_WIN32) || defined(__CYGWIN__) - if (a->flags & ARCHIVE_EXTRACT_OWNER) { - archive_set_error(&a->archive, -1, - "Can't restore SUID bit"); - r = ARCHIVE_WARN; - } -#endif - } - a->todo &= ~TODO_SGID_CHECK; - a->todo &= ~TODO_SUID_CHECK; - } else if (a->todo & TODO_SUID_CHECK) { - /* - * If we don't know the UID is right, we can just check - * the user, since all systems set the file UID from - * the process UID. - */ - if (a->user_uid != a->uid) { - mode &= ~ S_ISUID; -#if !defined(_WIN32) || defined(__CYGWIN__) - if (a->flags & ARCHIVE_EXTRACT_OWNER) { - archive_set_error(&a->archive, -1, - "Can't make file SUID"); - r = ARCHIVE_WARN; - } -#endif - } - a->todo &= ~TODO_SUID_CHECK; - } - - if (S_ISLNK(a->mode)) { -#ifdef HAVE_LCHMOD - /* - * If this is a symlink, use lchmod(). If the - * platform doesn't support lchmod(), just skip it. A - * platform that doesn't provide a way to set - * permissions on symlinks probably ignores - * permissions on symlinks, so a failure here has no - * impact. - */ - if (lchmod(a->name, mode) != 0) { - archive_set_error(&a->archive, errno, - "Can't set permissions to 0%o", (int)mode); - r = ARCHIVE_WARN; - } -#endif - } else if (!S_ISDIR(a->mode)) { - /* - * If it's not a symlink and not a dir, then use - * fchmod() or chmod(), depending on whether we have - * an fd. Dirs get their perms set during the - * post-extract fixup, which is handled elsewhere. - */ -#ifdef HAVE_FCHMOD - if (a->fd >= 0) { - if (fchmod(a->fd, mode) != 0) { - archive_set_error(&a->archive, errno, - "Can't set permissions to 0%o", (int)mode); - r = ARCHIVE_WARN; - } - } else -#endif - /* If this platform lacks fchmod(), then - * we'll just use chmod(). */ - if (chmod(a->name, mode) != 0) { - archive_set_error(&a->archive, errno, - "Can't set permissions to 0%o", (int)mode); - r = ARCHIVE_WARN; - } - } - return (r); -} - -static int -set_fflags(struct archive_write_disk *a) -{ - struct fixup_entry *le; - unsigned long set, clear; - int r; - int critical_flags; - mode_t mode = archive_entry_mode(a->entry); - - /* - * Make 'critical_flags' hold all file flags that can't be - * immediately restored. For example, on BSD systems, - * SF_IMMUTABLE prevents hardlinks from being created, so - * should not be set until after any hardlinks are created. To - * preserve some semblance of portability, this uses #ifdef - * extensively. Ugly, but it works. - * - * Yes, Virginia, this does create a security race. It's mitigated - * somewhat by the practice of creating dirs 0700 until the extract - * is done, but it would be nice if we could do more than that. - * People restoring critical file systems should be wary of - * other programs that might try to muck with files as they're - * being restored. - */ - /* Hopefully, the compiler will optimize this mess into a constant. */ - critical_flags = 0; -#ifdef SF_IMMUTABLE - critical_flags |= SF_IMMUTABLE; -#endif -#ifdef UF_IMMUTABLE - critical_flags |= UF_IMMUTABLE; -#endif -#ifdef SF_APPEND - critical_flags |= SF_APPEND; -#endif -#ifdef UF_APPEND - critical_flags |= UF_APPEND; -#endif -#ifdef EXT2_APPEND_FL - critical_flags |= EXT2_APPEND_FL; -#endif -#ifdef EXT2_IMMUTABLE_FL - critical_flags |= EXT2_IMMUTABLE_FL; -#endif - - if (a->todo & TODO_FFLAGS) { - archive_entry_fflags(a->entry, &set, &clear); - - /* - * The first test encourages the compiler to eliminate - * all of this if it's not necessary. - */ - if ((critical_flags != 0) && (set & critical_flags)) { - le = current_fixup(a, a->name); - le->fixup |= TODO_FFLAGS; - le->fflags_set = set; - /* Store the mode if it's not already there. */ - if ((le->fixup & TODO_MODE) == 0) - le->mode = mode; - } else { - r = set_fflags_platform(a, a->fd, - a->name, mode, set, clear); - if (r != ARCHIVE_OK) - return (r); - } - } - return (ARCHIVE_OK); -} - - -#if ( defined(HAVE_LCHFLAGS) || defined(HAVE_CHFLAGS) || defined(HAVE_FCHFLAGS) ) && defined(HAVE_STRUCT_STAT_ST_FLAGS) -/* - * BSD reads flags using stat() and sets them with one of {f,l,}chflags() - */ -static int -set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, - mode_t mode, unsigned long set, unsigned long clear) -{ - int r; - - (void)mode; /* UNUSED */ - if (set == 0 && clear == 0) - return (ARCHIVE_OK); - - /* - * XXX Is the stat here really necessary? Or can I just use - * the 'set' flags directly? In particular, I'm not sure - * about the correct approach if we're overwriting an existing - * file that already has flags on it. XXX - */ - if ((r = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK) - return (r); - - a->st.st_flags &= ~clear; - a->st.st_flags |= set; -#ifdef HAVE_FCHFLAGS - /* If platform has fchflags() and we were given an fd, use it. */ - if (fd >= 0 && fchflags(fd, a->st.st_flags) == 0) - return (ARCHIVE_OK); -#endif - /* - * If we can't use the fd to set the flags, we'll use the - * pathname to set flags. We prefer lchflags() but will use - * chflags() if we must. - */ -#ifdef HAVE_LCHFLAGS - if (lchflags(name, a->st.st_flags) == 0) - return (ARCHIVE_OK); -#elif defined(HAVE_CHFLAGS) - if (S_ISLNK(a->st.st_mode)) { - archive_set_error(&a->archive, errno, - "Can't set file flags on symlink."); - return (ARCHIVE_WARN); - } - if (chflags(name, a->st.st_flags) == 0) - return (ARCHIVE_OK); -#endif - archive_set_error(&a->archive, errno, - "Failed to set file flags"); - return (ARCHIVE_WARN); -} - -#elif defined(EXT2_IOC_GETFLAGS) && defined(EXT2_IOC_SETFLAGS) -/* - * Linux uses ioctl() to read and write file flags. - */ -static int -set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, - mode_t mode, unsigned long set, unsigned long clear) -{ - int ret; - int myfd = fd; - unsigned long newflags, oldflags; - unsigned long sf_mask = 0; - - if (set == 0 && clear == 0) - return (ARCHIVE_OK); - /* Only regular files and dirs can have flags. */ - if (!S_ISREG(mode) && !S_ISDIR(mode)) - return (ARCHIVE_OK); - - /* If we weren't given an fd, open it ourselves. */ - if (myfd < 0) - myfd = open(name, O_RDONLY | O_NONBLOCK | O_BINARY); - if (myfd < 0) - return (ARCHIVE_OK); - - /* - * Linux has no define for the flags that are only settable by - * the root user. This code may seem a little complex, but - * there seem to be some Linux systems that lack these - * defines. (?) The code below degrades reasonably gracefully - * if sf_mask is incomplete. - */ -#ifdef EXT2_IMMUTABLE_FL - sf_mask |= EXT2_IMMUTABLE_FL; -#endif -#ifdef EXT2_APPEND_FL - sf_mask |= EXT2_APPEND_FL; -#endif - /* - * XXX As above, this would be way simpler if we didn't have - * to read the current flags from disk. XXX - */ - ret = ARCHIVE_OK; - /* Try setting the flags as given. */ - if (ioctl(myfd, EXT2_IOC_GETFLAGS, &oldflags) >= 0) { - newflags = (oldflags & ~clear) | set; - if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0) - goto cleanup; - if (errno != EPERM) - goto fail; - } - /* If we couldn't set all the flags, try again with a subset. */ - if (ioctl(myfd, EXT2_IOC_GETFLAGS, &oldflags) >= 0) { - newflags &= ~sf_mask; - oldflags &= sf_mask; - newflags |= oldflags; - if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0) - goto cleanup; - } - /* We couldn't set the flags, so report the failure. */ -fail: - archive_set_error(&a->archive, errno, - "Failed to set file flags"); - ret = ARCHIVE_WARN; -cleanup: - if (fd < 0) - close(myfd); - return (ret); -} - -#else - -/* - * Of course, some systems have neither BSD chflags() nor Linux' flags - * support through ioctl(). - */ -static int -set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, - mode_t mode, unsigned long set, unsigned long clear) -{ - (void)a; /* UNUSED */ - (void)fd; /* UNUSED */ - (void)name; /* UNUSED */ - (void)mode; /* UNUSED */ - (void)set; /* UNUSED */ - (void)clear; /* UNUSED */ - return (ARCHIVE_OK); -} - -#endif /* __linux */ - -#ifndef HAVE_POSIX_ACL -/* Default empty function body to satisfy mainline code. */ -static int -set_acls(struct archive_write_disk *a) -{ - (void)a; /* UNUSED */ - return (ARCHIVE_OK); -} - -#else - -/* - * XXX TODO: What about ACL types other than ACCESS and DEFAULT? - */ -static int -set_acls(struct archive_write_disk *a) -{ - int ret; - - ret = set_acl(a, a->fd, a->entry, ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, "access"); - if (ret != ARCHIVE_OK) - return (ret); - ret = set_acl(a, a->fd, a->entry, ACL_TYPE_DEFAULT, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, "default"); - return (ret); -} - - -static int -set_acl(struct archive_write_disk *a, int fd, struct archive_entry *entry, - acl_type_t acl_type, int ae_requested_type, const char *tname) -{ - acl_t acl; - acl_entry_t acl_entry; - acl_permset_t acl_permset; - int ret; - int ae_type, ae_permset, ae_tag, ae_id; - uid_t ae_uid; - gid_t ae_gid; - const char *ae_name; - int entries; - const char *name; - - ret = ARCHIVE_OK; - entries = archive_entry_acl_reset(entry, ae_requested_type); - if (entries == 0) - return (ARCHIVE_OK); - acl = acl_init(entries); - while (archive_entry_acl_next(entry, ae_requested_type, &ae_type, - &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) { - acl_create_entry(&acl, &acl_entry); - - switch (ae_tag) { - case ARCHIVE_ENTRY_ACL_USER: - acl_set_tag_type(acl_entry, ACL_USER); - ae_uid = a->lookup_uid(a->lookup_uid_data, - ae_name, ae_id); - acl_set_qualifier(acl_entry, &ae_uid); - break; - case ARCHIVE_ENTRY_ACL_GROUP: - acl_set_tag_type(acl_entry, ACL_GROUP); - ae_gid = a->lookup_gid(a->lookup_gid_data, - ae_name, ae_id); - acl_set_qualifier(acl_entry, &ae_gid); - break; - case ARCHIVE_ENTRY_ACL_USER_OBJ: - acl_set_tag_type(acl_entry, ACL_USER_OBJ); - break; - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - acl_set_tag_type(acl_entry, ACL_GROUP_OBJ); - break; - case ARCHIVE_ENTRY_ACL_MASK: - acl_set_tag_type(acl_entry, ACL_MASK); - break; - case ARCHIVE_ENTRY_ACL_OTHER: - acl_set_tag_type(acl_entry, ACL_OTHER); - break; - default: - /* XXX */ - break; - } - - acl_get_permset(acl_entry, &acl_permset); - acl_clear_perms(acl_permset); - if (ae_permset & ARCHIVE_ENTRY_ACL_EXECUTE) - acl_add_perm(acl_permset, ACL_EXECUTE); - if (ae_permset & ARCHIVE_ENTRY_ACL_WRITE) - acl_add_perm(acl_permset, ACL_WRITE); - if (ae_permset & ARCHIVE_ENTRY_ACL_READ) - acl_add_perm(acl_permset, ACL_READ); - } - - name = archive_entry_pathname(entry); - - /* Try restoring the ACL through 'fd' if we can. */ -#if HAVE_ACL_SET_FD - if (fd >= 0 && acl_type == ACL_TYPE_ACCESS && acl_set_fd(fd, acl) == 0) - ret = ARCHIVE_OK; - else -#else -#if HAVE_ACL_SET_FD_NP - if (fd >= 0 && acl_set_fd_np(fd, acl, acl_type) == 0) - ret = ARCHIVE_OK; - else -#endif -#endif - if (acl_set_file(name, acl_type, acl) != 0) { - archive_set_error(&a->archive, errno, "Failed to set %s acl", tname); - ret = ARCHIVE_WARN; - } - acl_free(acl); - return (ret); -} -#endif - -#if HAVE_LSETXATTR -/* - * Restore extended attributes - Linux implementation - */ -static int -set_xattrs(struct archive_write_disk *a) -{ - struct archive_entry *entry = a->entry; - static int warning_done = 0; - int ret = ARCHIVE_OK; - int i = archive_entry_xattr_reset(entry); - - while (i--) { - const char *name; - const void *value; - size_t size; - archive_entry_xattr_next(entry, &name, &value, &size); - if (name != NULL && - strncmp(name, "xfsroot.", 8) != 0 && - strncmp(name, "system.", 7) != 0) { - int e; -#if HAVE_FSETXATTR - if (a->fd >= 0) - e = fsetxattr(a->fd, name, value, size, 0); - else -#endif - { - e = lsetxattr(archive_entry_pathname(entry), - name, value, size, 0); - } - if (e == -1) { - if (errno == ENOTSUP) { - if (!warning_done) { - warning_done = 1; - archive_set_error(&a->archive, errno, - "Cannot restore extended " - "attributes on this file " - "system"); - } - } else - archive_set_error(&a->archive, errno, - "Failed to set extended attribute"); - ret = ARCHIVE_WARN; - } - } else { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Invalid extended attribute encountered"); - ret = ARCHIVE_WARN; - } - } - return (ret); -} -#elif HAVE_EXTATTR_SET_FILE && HAVE_DECL_EXTATTR_NAMESPACE_USER -/* - * Restore extended attributes - FreeBSD implementation - */ -static int -set_xattrs(struct archive_write_disk *a) -{ - struct archive_entry *entry = a->entry; - static int warning_done = 0; - int ret = ARCHIVE_OK; - int i = archive_entry_xattr_reset(entry); - - while (i--) { - const char *name; - const void *value; - size_t size; - archive_entry_xattr_next(entry, &name, &value, &size); - if (name != NULL) { - int e; - int namespace; - - if (strncmp(name, "user.", 5) == 0) { - /* "user." attributes go to user namespace */ - name += 5; - namespace = EXTATTR_NAMESPACE_USER; - } else { - /* Warn about other extended attributes. */ - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Can't restore extended attribute ``%s''", - name); - ret = ARCHIVE_WARN; - continue; - } - errno = 0; -#if HAVE_EXTATTR_SET_FD - if (a->fd >= 0) - e = extattr_set_fd(a->fd, namespace, name, value, size); - else -#endif - /* TODO: should we use extattr_set_link() instead? */ - { - e = extattr_set_file(archive_entry_pathname(entry), - namespace, name, value, size); - } - if (e != (int)size) { - if (errno == ENOTSUP) { - if (!warning_done) { - warning_done = 1; - archive_set_error(&a->archive, errno, - "Cannot restore extended " - "attributes on this file " - "system"); - } - } else { - archive_set_error(&a->archive, errno, - "Failed to set extended attribute"); - } - - ret = ARCHIVE_WARN; - } - } - } - return (ret); -} -#else -/* - * Restore extended attributes - stub implementation for unsupported systems - */ -static int -set_xattrs(struct archive_write_disk *a) -{ - static int warning_done = 0; - - /* If there aren't any extended attributes, then it's okay not - * to extract them, otherwise, issue a single warning. */ - if (archive_entry_xattr_count(a->entry) != 0 && !warning_done) { - warning_done = 1; - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Cannot restore extended attributes on this system"); - return (ARCHIVE_WARN); - } - /* Warning was already emitted; suppress further warnings. */ - return (ARCHIVE_OK); -} -#endif - - -/* - * Trivial implementations of gid/uid lookup functions. - * These are normally overridden by the client, but these stub - * versions ensure that we always have something that works. - */ -static gid_t -trivial_lookup_gid(void *private_data, const char *gname, gid_t gid) -{ - (void)private_data; /* UNUSED */ - (void)gname; /* UNUSED */ - return (gid); -} - -static uid_t -trivial_lookup_uid(void *private_data, const char *uname, uid_t uid) -{ - (void)private_data; /* UNUSED */ - (void)uname; /* UNUSED */ - return (uid); -} - -/* - * Test if file on disk is older than entry. - */ -static int -older(struct stat *st, struct archive_entry *entry) -{ - /* First, test the seconds and return if we have a definite answer. */ - /* Definitely older. */ - if (st->st_mtime < archive_entry_mtime(entry)) - return (1); - /* Definitely younger. */ - if (st->st_mtime > archive_entry_mtime(entry)) - return (0); - /* If this platform supports fractional seconds, try those. */ -#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - /* Definitely older. */ - if (st->st_mtimespec.tv_nsec < archive_entry_mtime_nsec(entry)) - return (1); -#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - /* Definitely older. */ - if (st->st_mtim.tv_nsec < archive_entry_mtime_nsec(entry)) - return (1); -#elif HAVE_STRUCT_STAT_ST_MTIME_N - /* older. */ - if (st->st_mtime_n < archive_entry_mtime_nsec(entry)) - return (1); -#elif HAVE_STRUCT_STAT_ST_UMTIME - /* older. */ - if (st->st_umtime * 1000 < archive_entry_mtime_nsec(entry)) - return (1); -#elif HAVE_STRUCT_STAT_ST_MTIME_USEC - /* older. */ - if (st->st_mtime_usec * 1000 < archive_entry_mtime_nsec(entry)) - return (1); -#else - /* This system doesn't have high-res timestamps. */ -#endif - /* Same age or newer, so not older. */ - return (0); -} diff --git a/lib/libarchive/archive_write_disk_private.h b/lib/libarchive/archive_write_disk_private.h deleted file mode 100644 index 8ec6391..0000000 --- a/lib/libarchive/archive_write_disk_private.h +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifndef ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED -#define ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED - -struct archive_write_disk; - -#endif diff --git a/lib/libarchive/archive_write_disk_set_standard_lookup.c b/lib/libarchive/archive_write_disk_set_standard_lookup.c deleted file mode 100644 index ae9c12a..0000000 --- a/lib/libarchive/archive_write_disk_set_standard_lookup.c +++ /dev/null @@ -1,262 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_GRP_H -#include -#endif -#ifdef HAVE_PWD_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" -#include "archive_write_disk_private.h" - -struct bucket { - char *name; - int hash; - id_t id; -}; - -static const size_t cache_size = 127; -static unsigned int hash(const char *); -static gid_t lookup_gid(void *, const char *uname, gid_t); -static uid_t lookup_uid(void *, const char *uname, uid_t); -static void cleanup(void *); - -/* - * Installs functions that use getpwnam()/getgrnam()---along with - * a simple cache to accelerate such lookups---into the archive_write_disk - * object. This is in a separate file because getpwnam()/getgrnam() - * can pull in a LOT of library code (including NIS/LDAP functions, which - * pull in DNS resolveers, etc). This can easily top 500kB, which makes - * it inappropriate for some space-constrained applications. - * - * Applications that are size-sensitive may want to just use the - * real default functions (defined in archive_write_disk.c) that just - * use the uid/gid without the lookup. Or define your own custom functions - * if you prefer. - * - * TODO: Replace these hash tables with simpler move-to-front LRU - * lists with a bounded size (128 items?). The hash is a bit faster, - * but has a bad pathology in which it thrashes a single bucket. Even - * walking a list of 128 items is a lot faster than calling - * getpwnam()! - */ -int -archive_write_disk_set_standard_lookup(struct archive *a) -{ - struct bucket *ucache = malloc(cache_size * sizeof(struct bucket)); - struct bucket *gcache = malloc(cache_size * sizeof(struct bucket)); - memset(ucache, 0, cache_size * sizeof(struct bucket)); - memset(gcache, 0, cache_size * sizeof(struct bucket)); - archive_write_disk_set_group_lookup(a, gcache, lookup_gid, cleanup); - archive_write_disk_set_user_lookup(a, ucache, lookup_uid, cleanup); - return (ARCHIVE_OK); -} - -static gid_t -lookup_gid(void *private_data, const char *gname, gid_t gid) -{ - int h; - struct bucket *b; - struct bucket *gcache = (struct bucket *)private_data; - - /* If no gname, just use the gid provided. */ - if (gname == NULL || *gname == '\0') - return (gid); - - /* Try to find gname in the cache. */ - h = hash(gname); - b = &gcache[h % cache_size ]; - if (b->name != NULL && b->hash == h && strcmp(gname, b->name) == 0) - return ((gid_t)b->id); - - /* Free the cache slot for a new entry. */ - if (b->name != NULL) - free(b->name); - b->name = strdup(gname); - /* Note: If strdup fails, that's okay; we just won't cache. */ - b->hash = h; -#if HAVE_GRP_H -# if HAVE_GETGRNAM_R - { - char _buffer[128]; - size_t bufsize = 128; - char *buffer = _buffer; - struct group grent, *result; - int r; - - for (;;) { - result = &grent; /* Old getgrnam_r ignores last arg. */ - r = getgrnam_r(gname, &grent, buffer, bufsize, &result); - if (r == 0) - break; - if (r != ERANGE) - break; - bufsize *= 2; - if (buffer != _buffer) - free(buffer); - buffer = malloc(bufsize); - if (buffer == NULL) - break; - } - if (result != NULL) - gid = result->gr_gid; - if (buffer != _buffer) - free(buffer); - } -# else /* HAVE_GETGRNAM_R */ - { - struct group *result; - - result = getgrnam(gname); - if (result != NULL) - gid = result->gr_gid; - } -# endif /* HAVE_GETGRNAM_R */ -#elif defined(_WIN32) && !defined(__CYGWIN__) - /* TODO: do a gname->gid lookup for Windows. */ -#else - #error No way to perform gid lookups on this platform -#endif - b->id = gid; - - return (gid); -} - -static uid_t -lookup_uid(void *private_data, const char *uname, uid_t uid) -{ - int h; - struct bucket *b; - struct bucket *ucache = (struct bucket *)private_data; - - /* If no uname, just use the uid provided. */ - if (uname == NULL || *uname == '\0') - return (uid); - - /* Try to find uname in the cache. */ - h = hash(uname); - b = &ucache[h % cache_size ]; - if (b->name != NULL && b->hash == h && strcmp(uname, b->name) == 0) - return ((uid_t)b->id); - - /* Free the cache slot for a new entry. */ - if (b->name != NULL) - free(b->name); - b->name = strdup(uname); - /* Note: If strdup fails, that's okay; we just won't cache. */ - b->hash = h; -#if HAVE_PWD_H -# if HAVE_GETPWNAM_R - { - char _buffer[128]; - size_t bufsize = 128; - char *buffer = _buffer; - struct passwd pwent, *result; - int r; - - for (;;) { - result = &pwent; /* Old getpwnam_r ignores last arg. */ - r = getpwnam_r(uname, &pwent, buffer, bufsize, &result); - if (r == 0) - break; - if (r != ERANGE) - break; - bufsize *= 2; - if (buffer != _buffer) - free(buffer); - buffer = malloc(bufsize); - if (buffer == NULL) - break; - } - if (result != NULL) - uid = result->pw_uid; - if (buffer != _buffer) - free(buffer); - } -# else /* HAVE_GETPWNAM_R */ - { - struct passwd *result; - - result = getpwnam(uname); - if (result != NULL) - uid = result->pw_uid; - } -#endif /* HAVE_GETPWNAM_R */ -#elif defined(_WIN32) && !defined(__CYGWIN__) - /* TODO: do a uname->uid lookup for Windows. */ -#else - #error No way to look up uids on this platform -#endif - b->id = uid; - - return (uid); -} - -static void -cleanup(void *private) -{ - size_t i; - struct bucket *cache = (struct bucket *)private; - - for (i = 0; i < cache_size; i++) - free(cache[i].name); - free(cache); -} - - -static unsigned int -hash(const char *p) -{ - /* A 32-bit version of Peter Weinberger's (PJW) hash algorithm, - as used by ELF for hashing function names. */ - unsigned g, h = 0; - while (*p != '\0') { - h = (h << 4) + *p++; - if ((g = h & 0xF0000000) != 0) { - h ^= g >> 24; - h &= 0x0FFFFFFF; - } - } - return h; -} diff --git a/lib/libarchive/archive_write_open_fd.c b/lib/libarchive/archive_write_open_fd.c deleted file mode 100644 index 1d27ce3..0000000 --- a/lib/libarchive/archive_write_open_fd.c +++ /dev/null @@ -1,144 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_IO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" - -struct write_fd_data { - int fd; -}; - -static int file_close(struct archive *, void *); -static int file_open(struct archive *, void *); -static ssize_t file_write(struct archive *, void *, const void *buff, size_t); - -int -archive_write_open_fd(struct archive *a, int fd) -{ - struct write_fd_data *mine; - - mine = (struct write_fd_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - mine->fd = fd; -#if defined(__CYGWIN__) || defined(_WIN32) - setmode(mine->fd, O_BINARY); -#endif - return (archive_write_open(a, mine, - file_open, file_write, file_close)); -} - -static int -file_open(struct archive *a, void *client_data) -{ - struct write_fd_data *mine; - struct stat st; - - mine = (struct write_fd_data *)client_data; - - if (fstat(mine->fd, &st) != 0) { - archive_set_error(a, errno, "Couldn't stat fd %d", mine->fd); - return (ARCHIVE_FATAL); - } - - /* - * If this is a regular file, don't add it to itself. - */ - if (S_ISREG(st.st_mode)) - archive_write_set_skip_file(a, st.st_dev, st.st_ino); - - /* - * If client hasn't explicitly set the last block handling, - * then set it here. - */ - if (archive_write_get_bytes_in_last_block(a) < 0) { - /* If the output is a block or character device, fifo, - * or stdout, pad the last block, otherwise leave it - * unpadded. */ - if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || - S_ISFIFO(st.st_mode) || (mine->fd == 1)) - /* Last block will be fully padded. */ - archive_write_set_bytes_in_last_block(a, 0); - else - archive_write_set_bytes_in_last_block(a, 1); - } - - return (ARCHIVE_OK); -} - -static ssize_t -file_write(struct archive *a, void *client_data, const void *buff, size_t length) -{ - struct write_fd_data *mine; - ssize_t bytesWritten; - - mine = (struct write_fd_data *)client_data; - for (;;) { - bytesWritten = write(mine->fd, buff, length); - if (bytesWritten <= 0) { - if (errno == EINTR) - continue; - archive_set_error(a, errno, "Write error"); - return (-1); - } - return (bytesWritten); - } -} - -static int -file_close(struct archive *a, void *client_data) -{ - struct write_fd_data *mine = (struct write_fd_data *)client_data; - - (void)a; /* UNUSED */ - free(mine); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_write_open_file.c b/lib/libarchive/archive_write_open_file.c deleted file mode 100644 index 68bf236..0000000 --- a/lib/libarchive/archive_write_open_file.c +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" - -struct write_FILE_data { - FILE *f; -}; - -static int file_close(struct archive *, void *); -static int file_open(struct archive *, void *); -static ssize_t file_write(struct archive *, void *, const void *buff, size_t); - -int -archive_write_open_FILE(struct archive *a, FILE *f) -{ - struct write_FILE_data *mine; - - mine = (struct write_FILE_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - mine->f = f; - return (archive_write_open(a, mine, - file_open, file_write, file_close)); -} - -static int -file_open(struct archive *a, void *client_data) -{ - (void)a; /* UNUSED */ - (void)client_data; /* UNUSED */ - - return (ARCHIVE_OK); -} - -static ssize_t -file_write(struct archive *a, void *client_data, const void *buff, size_t length) -{ - struct write_FILE_data *mine; - size_t bytesWritten; - - mine = client_data; - for (;;) { - bytesWritten = fwrite(buff, 1, length, mine->f); - if (bytesWritten <= 0) { - if (errno == EINTR) - continue; - archive_set_error(a, errno, "Write error"); - return (-1); - } - return (bytesWritten); - } -} - -static int -file_close(struct archive *a, void *client_data) -{ - struct write_FILE_data *mine = client_data; - - (void)a; /* UNUSED */ - free(mine); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_write_open_filename.c b/lib/libarchive/archive_write_open_filename.c deleted file mode 100644 index 0c1e189..0000000 --- a/lib/libarchive/archive_write_open_filename.c +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -struct write_file_data { - int fd; - char filename[1]; -}; - -static int file_close(struct archive *, void *); -static int file_open(struct archive *, void *); -static ssize_t file_write(struct archive *, void *, const void *buff, size_t); - -int -archive_write_open_file(struct archive *a, const char *filename) -{ - return (archive_write_open_filename(a, filename)); -} - -int -archive_write_open_filename(struct archive *a, const char *filename) -{ - struct write_file_data *mine; - - if (filename == NULL || filename[0] == '\0') - return (archive_write_open_fd(a, 1)); - - mine = (struct write_file_data *)malloc(sizeof(*mine) + strlen(filename)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - strcpy(mine->filename, filename); - mine->fd = -1; - return (archive_write_open(a, mine, - file_open, file_write, file_close)); -} - -static int -file_open(struct archive *a, void *client_data) -{ - int flags; - struct write_file_data *mine; - struct stat st; - - mine = (struct write_file_data *)client_data; - flags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY; - - /* - * Open the file. - */ - mine->fd = open(mine->filename, flags, 0666); - if (mine->fd < 0) { - archive_set_error(a, errno, "Failed to open '%s'", - mine->filename); - return (ARCHIVE_FATAL); - } - - if (fstat(mine->fd, &st) != 0) { - archive_set_error(a, errno, "Couldn't stat '%s'", - mine->filename); - return (ARCHIVE_FATAL); - } - - /* - * Set up default last block handling. - */ - if (archive_write_get_bytes_in_last_block(a) < 0) { - if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || - S_ISFIFO(st.st_mode)) - /* Pad last block when writing to device or FIFO. */ - archive_write_set_bytes_in_last_block(a, 0); - else - /* Don't pad last block otherwise. */ - archive_write_set_bytes_in_last_block(a, 1); - } - - /* - * If the output file is a regular file, don't add it to - * itself. If it's a device file, it's okay to add the device - * entry to the output archive. - */ - if (S_ISREG(st.st_mode)) - archive_write_set_skip_file(a, st.st_dev, st.st_ino); - - return (ARCHIVE_OK); -} - -static ssize_t -file_write(struct archive *a, void *client_data, const void *buff, size_t length) -{ - struct write_file_data *mine; - ssize_t bytesWritten; - - mine = (struct write_file_data *)client_data; - for (;;) { - bytesWritten = write(mine->fd, buff, length); - if (bytesWritten <= 0) { - if (errno == EINTR) - continue; - archive_set_error(a, errno, "Write error"); - return (-1); - } - return (bytesWritten); - } -} - -static int -file_close(struct archive *a, void *client_data) -{ - struct write_file_data *mine = (struct write_file_data *)client_data; - - (void)a; /* UNUSED */ - close(mine->fd); - free(mine); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_write_open_memory.c b/lib/libarchive/archive_write_open_memory.c deleted file mode 100644 index 02c0022..0000000 --- a/lib/libarchive/archive_write_open_memory.c +++ /dev/null @@ -1,126 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -#include "archive.h" - -/* - * This is a little tricky. I used to allow the - * compression handling layer to fork the compressor, - * which means this write function gets invoked in - * a separate process. That would, of course, make it impossible - * to actually use the data stored into memory here. - * Fortunately, none of the compressors fork today and - * I'm reluctant to use that route in the future but, if - * forking compressors ever do reappear, this will have - * to get a lot more complicated. - */ - -struct write_memory_data { - size_t used; - size_t size; - size_t * client_size; - unsigned char * buff; -}; - -static int memory_write_close(struct archive *, void *); -static int memory_write_open(struct archive *, void *); -static ssize_t memory_write(struct archive *, void *, const void *buff, size_t); - -/* - * Client provides a pointer to a block of memory to receive - * the data. The 'size' param both tells us the size of the - * client buffer and lets us tell the client the final size. - */ -int -archive_write_open_memory(struct archive *a, void *buff, size_t buffSize, size_t *used) -{ - struct write_memory_data *mine; - - mine = (struct write_memory_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - memset(mine, 0, sizeof(*mine)); - mine->buff = buff; - mine->size = buffSize; - mine->client_size = used; - return (archive_write_open(a, mine, - memory_write_open, memory_write, memory_write_close)); -} - -static int -memory_write_open(struct archive *a, void *client_data) -{ - struct write_memory_data *mine; - mine = client_data; - mine->used = 0; - if (mine->client_size != NULL) - *mine->client_size = mine->used; - /* Disable padding if it hasn't been set explicitly. */ - if (-1 == archive_write_get_bytes_in_last_block(a)) - archive_write_set_bytes_in_last_block(a, 1); - return (ARCHIVE_OK); -} - -/* - * Copy the data into the client buffer. - * Note that we update mine->client_size on every write. - * In particular, this means the client can follow exactly - * how much has been written into their buffer at any time. - */ -static ssize_t -memory_write(struct archive *a, void *client_data, const void *buff, size_t length) -{ - struct write_memory_data *mine; - mine = client_data; - - if (mine->used + length > mine->size) { - archive_set_error(a, ENOMEM, "Buffer exhausted"); - return (ARCHIVE_FATAL); - } - memcpy(mine->buff + mine->used, buff, length); - mine->used += length; - if (mine->client_size != NULL) - *mine->client_size = mine->used; - return (length); -} - -static int -memory_write_close(struct archive *a, void *client_data) -{ - struct write_memory_data *mine; - (void)a; /* UNUSED */ - mine = client_data; - free(mine); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_write_private.h b/lib/libarchive/archive_write_private.h deleted file mode 100644 index f902f08..0000000 --- a/lib/libarchive/archive_write_private.h +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED -#define ARCHIVE_WRITE_PRIVATE_H_INCLUDED - -#include "archive.h" -#include "archive_string.h" -#include "archive_private.h" - -struct archive_write { - struct archive archive; - - /* Dev/ino of the archive being written. */ - dev_t skip_file_dev; - int64_t skip_file_ino; - - /* Utility: Pointer to a block of nulls. */ - const unsigned char *nulls; - size_t null_length; - - /* Callbacks to open/read/write/close archive stream. */ - archive_open_callback *client_opener; - archive_write_callback *client_writer; - archive_close_callback *client_closer; - void *client_data; - - /* - * Blocking information. Note that bytes_in_last_block is - * misleadingly named; I should find a better name. These - * control the final output from all compressors, including - * compression_none. - */ - int bytes_per_block; - int bytes_in_last_block; - - /* - * These control whether data within a gzip/bzip2 compressed - * stream gets padded or not. If pad_uncompressed is set, - * the data will be padded to a full block before being - * compressed. The pad_uncompressed_byte determines the value - * that will be used for padding. Note that these have no - * effect on compression "none." - */ - int pad_uncompressed; - int pad_uncompressed_byte; /* TODO: Support this. */ - - /* - * On write, the client just invokes an archive_write_set function - * which sets up the data here directly. - */ - struct { - void *data; - void *config; - int (*init)(struct archive_write *); - int (*options)(struct archive_write *, - const char *key, const char *value); - int (*finish)(struct archive_write *); - int (*write)(struct archive_write *, const void *, size_t); - } compressor; - - /* - * Pointers to format-specific functions for writing. They're - * initialized by archive_write_set_format_XXX() calls. - */ - void *format_data; - const char *format_name; - int (*format_init)(struct archive_write *); - int (*format_options)(struct archive_write *, - const char *key, const char *value); - int (*format_finish)(struct archive_write *); - int (*format_destroy)(struct archive_write *); - int (*format_finish_entry)(struct archive_write *); - int (*format_write_header)(struct archive_write *, - struct archive_entry *); - ssize_t (*format_write_data)(struct archive_write *, - const void *buff, size_t); -}; - -/* - * Utility function to format a USTAR header into a buffer. If - * "strict" is set, this tries to create the absolutely most portable - * version of a ustar header. If "strict" is set to 0, then it will - * relax certain requirements. - * - * Generally, format-specific declarations don't belong in this - * header; this is a rare example of a function that is shared by - * two very similar formats (ustar and pax). - */ -int -__archive_write_format_header_ustar(struct archive_write *, char buff[512], - struct archive_entry *, int tartype, int strict); - -#endif diff --git a/lib/libarchive/archive_write_set_compression_bzip2.c b/lib/libarchive/archive_write_set_compression_bzip2.c deleted file mode 100644 index a3ed307..0000000 --- a/lib/libarchive/archive_write_set_compression_bzip2.c +++ /dev/null @@ -1,408 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" - -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_BZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) -int -archive_write_set_compression_bzip2(struct archive *a) -{ - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "bzip2 compression not supported on this platform"); - return (ARCHIVE_FATAL); -} -#else -/* Don't compile this if we don't have bzlib. */ - -struct private_data { - bz_stream stream; - int64_t total_in; - char *compressed; - size_t compressed_buffer_size; -}; - -struct private_config { - int compression_level; -}; - -/* - * Yuck. bzlib.h is not const-correct, so I need this one bit - * of ugly hackery to convert a const * pointer to a non-const pointer. - */ -#define SET_NEXT_IN(st,src) \ - (st)->stream.next_in = (char *)(uintptr_t)(const void *)(src) - -static int archive_compressor_bzip2_finish(struct archive_write *); -static int archive_compressor_bzip2_init(struct archive_write *); -static int archive_compressor_bzip2_options(struct archive_write *, - const char *, const char *); -static int archive_compressor_bzip2_write(struct archive_write *, - const void *, size_t); -static int drive_compressor(struct archive_write *, struct private_data *, - int finishing); - -/* - * Allocate, initialize and return an archive object. - */ -int -archive_write_set_compression_bzip2(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct private_config *config; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_bzip2"); - config = malloc(sizeof(*config)); - if (config == NULL) { - archive_set_error(&a->archive, ENOMEM, "Out of memory"); - return (ARCHIVE_FATAL); - } - a->compressor.config = config; - a->compressor.finish = archive_compressor_bzip2_finish; - config->compression_level = 9; /* default */ - a->compressor.init = &archive_compressor_bzip2_init; - a->compressor.options = &archive_compressor_bzip2_options; - a->archive.compression_code = ARCHIVE_COMPRESSION_BZIP2; - a->archive.compression_name = "bzip2"; - return (ARCHIVE_OK); -} - -/* - * Setup callback. - */ -static int -archive_compressor_bzip2_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - struct private_config *config; - - config = (struct private_config *)a->compressor.config; - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != 0) - return (ret); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - state->compressed_buffer_size = a->bytes_per_block; - state->compressed = (char *)malloc(state->compressed_buffer_size); - - if (state->compressed == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - - state->stream.next_out = state->compressed; - state->stream.avail_out = state->compressed_buffer_size; - a->compressor.write = archive_compressor_bzip2_write; - - /* Initialize compression library */ - ret = BZ2_bzCompressInit(&(state->stream), - config->compression_level, 0, 30); - if (ret == BZ_OK) { - a->compressor.data = state; - return (ARCHIVE_OK); - } - - /* Library setup failed: clean up. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library"); - free(state->compressed); - free(state); - - /* Override the error message if we know what really went wrong. */ - switch (ret) { - case BZ_PARAM_ERROR: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "invalid setup parameter"); - break; - case BZ_MEM_ERROR: - archive_set_error(&a->archive, ENOMEM, - "Internal error initializing compression library: " - "out of memory"); - break; - case BZ_CONFIG_ERROR: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "mis-compiled library"); - break; - } - - return (ARCHIVE_FATAL); - -} - -/* - * Set write options. - */ -static int -archive_compressor_bzip2_options(struct archive_write *a, const char *key, - const char *value) -{ - struct private_config *config; - - config = (struct private_config *)a->compressor.config; - if (strcmp(key, "compression-level") == 0) { - if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || - value[1] != '\0') - return (ARCHIVE_WARN); - config->compression_level = value[0] - '0'; - /* Make '0' be a synonym for '1'. */ - /* This way, bzip2 compressor supports the same 0..9 - * range of levels as gzip. */ - if (config->compression_level < 1) - config->compression_level = 1; - return (ARCHIVE_OK); - } - - return (ARCHIVE_WARN); -} - -/* - * Write data to the compressed stream. - * - * Returns ARCHIVE_OK if all data written, error otherwise. - */ -static int -archive_compressor_bzip2_write(struct archive_write *a, const void *buff, - size_t length) -{ - struct private_data *state; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - /* Update statistics */ - state->total_in += length; - - /* Compress input data to output buffer */ - SET_NEXT_IN(state, buff); - state->stream.avail_in = length; - if (drive_compressor(a, state, 0)) - return (ARCHIVE_FATAL); - a->archive.file_position += length; - return (ARCHIVE_OK); -} - - -/* - * Finish the compression. - */ -static int -archive_compressor_bzip2_finish(struct archive_write *a) -{ - ssize_t block_length; - int ret; - struct private_data *state; - ssize_t target_block_length; - ssize_t bytes_written; - unsigned tocopy; - - ret = ARCHIVE_OK; - state = (struct private_data *)a->compressor.data; - if (state != NULL) { - if (a->client_writer == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered?\n" - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* By default, always pad the uncompressed data. */ - if (a->pad_uncompressed) { - tocopy = a->bytes_per_block - - (state->total_in % a->bytes_per_block); - while (tocopy > 0 && tocopy < (unsigned)a->bytes_per_block) { - SET_NEXT_IN(state, a->nulls); - state->stream.avail_in = tocopy < a->null_length ? - tocopy : a->null_length; - state->total_in += state->stream.avail_in; - tocopy -= state->stream.avail_in; - ret = drive_compressor(a, state, 0); - if (ret != ARCHIVE_OK) - goto cleanup; - } - } - - /* Finish compression cycle. */ - if ((ret = drive_compressor(a, state, 1))) - goto cleanup; - - /* Optionally, pad the final compressed block. */ - block_length = state->stream.next_out - state->compressed; - - /* Tricky calculation to determine size of last block. */ - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round length to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->stream.next_out, 0, - target_block_length - block_length); - block_length = target_block_length; - } - - /* Write the last block */ - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, block_length); - - /* TODO: Handle short write of final block. */ - if (bytes_written <= 0) - ret = ARCHIVE_FATAL; - else { - a->archive.raw_position += ret; - ret = ARCHIVE_OK; - } - - /* Cleanup: shut down compressor, release memory, etc. */ -cleanup: - switch (BZ2_bzCompressEnd(&(state->stream))) { - case BZ_OK: - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "Failed to clean up compressor"); - ret = ARCHIVE_FATAL; - } - - free(state->compressed); - free(state); - } - /* Free configuration data even if we were never fully initialized. */ - free(a->compressor.config); - a->compressor.config = NULL; - return (ret); -} - -/* - * Utility function to push input data through compressor, writing - * full output blocks as necessary. - * - * Note that this handles both the regular write case (finishing == - * false) and the end-of-archive case (finishing == true). - */ -static int -drive_compressor(struct archive_write *a, struct private_data *state, int finishing) -{ - ssize_t bytes_written; - int ret; - - for (;;) { - if (state->stream.avail_out == 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->compressed, - state->compressed_buffer_size); - if (bytes_written <= 0) { - /* TODO: Handle this write failure */ - return (ARCHIVE_FATAL); - } else if ((size_t)bytes_written < state->compressed_buffer_size) { - /* Short write: Move remainder to - * front and keep filling */ - memmove(state->compressed, - state->compressed + bytes_written, - state->compressed_buffer_size - bytes_written); - } - - a->archive.raw_position += bytes_written; - state->stream.next_out = state->compressed + - state->compressed_buffer_size - bytes_written; - state->stream.avail_out = bytes_written; - } - - /* If there's nothing to do, we're done. */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - - ret = BZ2_bzCompress(&(state->stream), - finishing ? BZ_FINISH : BZ_RUN); - - switch (ret) { - case BZ_RUN_OK: - /* In non-finishing case, did compressor - * consume everything? */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - break; - case BZ_FINISH_OK: /* Finishing: There's more work to do */ - break; - case BZ_STREAM_END: /* Finishing: all done */ - /* Only occurs in finishing case */ - return (ARCHIVE_OK); - default: - /* Any other return value indicates an error */ - archive_set_error(&a->archive, - ARCHIVE_ERRNO_PROGRAMMER, - "Bzip2 compression failed;" - " BZ2_bzCompress() returned %d", - ret); - return (ARCHIVE_FATAL); - } - } -} - -#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */ diff --git a/lib/libarchive/archive_write_set_compression_compress.c b/lib/libarchive/archive_write_set_compression_compress.c deleted file mode 100644 index da44b04..0000000 --- a/lib/libarchive/archive_write_set_compression_compress.c +++ /dev/null @@ -1,492 +0,0 @@ -/*- - * Copyright (c) 2008 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/*- - * Copyright (c) 1985, 1986, 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Diomidis Spinellis and James A. Woods, derived from original - * work by Spencer Thomas and Joseph Orost. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "archive_platform.h" - -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#define HSIZE 69001 /* 95% occupancy */ -#define HSHIFT 8 /* 8 - trunc(log2(HSIZE / 65536)) */ -#define CHECK_GAP 10000 /* Ratio check interval. */ - -#define MAXCODE(bits) ((1 << (bits)) - 1) - -/* - * the next two codes should not be changed lightly, as they must not - * lie within the contiguous general code space. - */ -#define FIRST 257 /* First free entry. */ -#define CLEAR 256 /* Table clear output code. */ - -struct private_data { - off_t in_count, out_count, checkpoint; - - int code_len; /* Number of bits/code. */ - int cur_maxcode; /* Maximum code, given n_bits. */ - int max_maxcode; /* Should NEVER generate this code. */ - int hashtab [HSIZE]; - unsigned short codetab [HSIZE]; - int first_free; /* First unused entry. */ - int compress_ratio; - - int cur_code, cur_fcode; - - int bit_offset; - unsigned char bit_buf; - - unsigned char *compressed; - size_t compressed_buffer_size; - size_t compressed_offset; -}; - -static int archive_compressor_compress_finish(struct archive_write *); -static int archive_compressor_compress_init(struct archive_write *); -static int archive_compressor_compress_write(struct archive_write *, - const void *, size_t); - -/* - * Allocate, initialize and return a archive object. - */ -int -archive_write_set_compression_compress(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_compress"); - a->compressor.init = &archive_compressor_compress_init; - a->archive.compression_code = ARCHIVE_COMPRESSION_COMPRESS; - a->archive.compression_name = "compress"; - return (ARCHIVE_OK); -} - -/* - * Setup callback. - */ -static int -archive_compressor_compress_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - - a->archive.compression_code = ARCHIVE_COMPRESSION_COMPRESS; - a->archive.compression_name = "compress"; - - if (a->bytes_per_block < 4) { - archive_set_error(&a->archive, EINVAL, - "Can't write Compress header as single block"); - return (ARCHIVE_FATAL); - } - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != ARCHIVE_OK) - return (ret); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - state->compressed_buffer_size = a->bytes_per_block; - state->compressed = malloc(state->compressed_buffer_size); - - if (state->compressed == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - - a->compressor.write = archive_compressor_compress_write; - a->compressor.finish = archive_compressor_compress_finish; - - state->max_maxcode = 0x10000; /* Should NEVER generate this code. */ - state->in_count = 0; /* Length of input. */ - state->bit_buf = 0; - state->bit_offset = 0; - state->out_count = 3; /* Includes 3-byte header mojo. */ - state->compress_ratio = 0; - state->checkpoint = CHECK_GAP; - state->code_len = 9; - state->cur_maxcode = MAXCODE(state->code_len); - state->first_free = FIRST; - - memset(state->hashtab, 0xff, sizeof(state->hashtab)); - - /* Prime output buffer with a gzip header. */ - state->compressed[0] = 0x1f; /* Compress */ - state->compressed[1] = 0x9d; - state->compressed[2] = 0x90; /* Block mode, 16bit max */ - state->compressed_offset = 3; - - a->compressor.data = state; - return (0); -} - -/*- - * Output the given code. - * Inputs: - * code: A n_bits-bit integer. If == -1, then EOF. This assumes - * that n_bits =< (long)wordsize - 1. - * Outputs: - * Outputs code to the file. - * Assumptions: - * Chars are 8 bits long. - * Algorithm: - * Maintain a BITS character long buffer (so that 8 codes will - * fit in it exactly). Use the VAX insv instruction to insert each - * code in turn. When the buffer fills up empty it and start over. - */ - -static unsigned char rmask[9] = - {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; - -static int -output_byte(struct archive_write *a, unsigned char c) -{ - struct private_data *state = a->compressor.data; - ssize_t bytes_written; - - state->compressed[state->compressed_offset++] = c; - ++state->out_count; - - if (state->compressed_buffer_size == state->compressed_offset) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, - state->compressed, state->compressed_buffer_size); - if (bytes_written <= 0) - return ARCHIVE_FATAL; - a->archive.raw_position += bytes_written; - state->compressed_offset = 0; - } - - return ARCHIVE_OK; -} - -static int -output_code(struct archive_write *a, int ocode) -{ - struct private_data *state = a->compressor.data; - int bits, ret, clear_flg, bit_offset; - - clear_flg = ocode == CLEAR; - - /* - * Since ocode is always >= 8 bits, only need to mask the first - * hunk on the left. - */ - bit_offset = state->bit_offset % 8; - state->bit_buf |= (ocode << bit_offset) & 0xff; - output_byte(a, state->bit_buf); - - bits = state->code_len - (8 - bit_offset); - ocode >>= 8 - bit_offset; - /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */ - if (bits >= 8) { - output_byte(a, ocode & 0xff); - ocode >>= 8; - bits -= 8; - } - /* Last bits. */ - state->bit_offset += state->code_len; - state->bit_buf = ocode & rmask[bits]; - if (state->bit_offset == state->code_len * 8) - state->bit_offset = 0; - - /* - * If the next entry is going to be too big for the ocode size, - * then increase it, if possible. - */ - if (clear_flg || state->first_free > state->cur_maxcode) { - /* - * Write the whole buffer, because the input side won't - * discover the size increase until after it has read it. - */ - if (state->bit_offset > 0) { - while (state->bit_offset < state->code_len * 8) { - ret = output_byte(a, state->bit_buf); - if (ret != ARCHIVE_OK) - return ret; - state->bit_offset += 8; - state->bit_buf = 0; - } - } - state->bit_buf = 0; - state->bit_offset = 0; - - if (clear_flg) { - state->code_len = 9; - state->cur_maxcode = MAXCODE(state->code_len); - } else { - state->code_len++; - if (state->code_len == 16) - state->cur_maxcode = state->max_maxcode; - else - state->cur_maxcode = MAXCODE(state->code_len); - } - } - - return (ARCHIVE_OK); -} - -static int -output_flush(struct archive_write *a) -{ - struct private_data *state = a->compressor.data; - int ret; - - /* At EOF, write the rest of the buffer. */ - if (state->bit_offset % 8) { - state->code_len = (state->bit_offset % 8 + 7) / 8; - ret = output_byte(a, state->bit_buf); - if (ret != ARCHIVE_OK) - return ret; - } - - return (ARCHIVE_OK); -} - -/* - * Write data to the compressed stream. - */ -static int -archive_compressor_compress_write(struct archive_write *a, const void *buff, - size_t length) -{ - struct private_data *state; - int i; - int ratio; - int c, disp, ret; - const unsigned char *bp; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - if (length == 0) - return ARCHIVE_OK; - - bp = buff; - - if (state->in_count == 0) { - state->cur_code = *bp++; - ++state->in_count; - --length; - } - - while (length--) { - c = *bp++; - state->in_count++; - state->cur_fcode = (c << 16) + state->cur_code; - i = ((c << HSHIFT) ^ state->cur_code); /* Xor hashing. */ - - if (state->hashtab[i] == state->cur_fcode) { - state->cur_code = state->codetab[i]; - continue; - } - if (state->hashtab[i] < 0) /* Empty slot. */ - goto nomatch; - /* Secondary hash (after G. Knott). */ - if (i == 0) - disp = 1; - else - disp = HSIZE - i; - probe: - if ((i -= disp) < 0) - i += HSIZE; - - if (state->hashtab[i] == state->cur_fcode) { - state->cur_code = state->codetab[i]; - continue; - } - if (state->hashtab[i] >= 0) - goto probe; - nomatch: - ret = output_code(a, state->cur_code); - if (ret != ARCHIVE_OK) - return ret; - state->cur_code = c; - if (state->first_free < state->max_maxcode) { - state->codetab[i] = state->first_free++; /* code -> hashtable */ - state->hashtab[i] = state->cur_fcode; - continue; - } - if (state->in_count < state->checkpoint) - continue; - - state->checkpoint = state->in_count + CHECK_GAP; - - if (state->in_count <= 0x007fffff) - ratio = state->in_count * 256 / state->out_count; - else if ((ratio = state->out_count / 256) == 0) - ratio = 0x7fffffff; - else - ratio = state->in_count / ratio; - - if (ratio > state->compress_ratio) - state->compress_ratio = ratio; - else { - state->compress_ratio = 0; - memset(state->hashtab, 0xff, sizeof(state->hashtab)); - state->first_free = FIRST; - ret = output_code(a, CLEAR); - if (ret != ARCHIVE_OK) - return ret; - } - } - - return (ARCHIVE_OK); -} - - -/* - * Finish the compression... - */ -static int -archive_compressor_compress_finish(struct archive_write *a) -{ - ssize_t block_length, target_block_length, bytes_written; - int ret; - struct private_data *state; - size_t tocopy; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* By default, always pad the uncompressed data. */ - if (a->pad_uncompressed) { - while (state->in_count % a->bytes_per_block != 0) { - tocopy = a->bytes_per_block - - (state->in_count % a->bytes_per_block); - if (tocopy > a->null_length) - tocopy = a->null_length; - ret = archive_compressor_compress_write(a, a->nulls, - tocopy); - if (ret != ARCHIVE_OK) - goto cleanup; - } - } - - ret = output_code(a, state->cur_code); - if (ret != ARCHIVE_OK) - goto cleanup; - ret = output_flush(a); - if (ret != ARCHIVE_OK) - goto cleanup; - - /* Optionally, pad the final compressed block. */ - block_length = state->compressed_offset; - - /* Tricky calculation to determine size of last block. */ - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round length to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->compressed + state->compressed_offset, 0, - target_block_length - block_length); - block_length = target_block_length; - } - - /* Write the last block */ - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, block_length); - if (bytes_written <= 0) - ret = ARCHIVE_FATAL; - else - a->archive.raw_position += bytes_written; - -cleanup: - free(state->compressed); - free(state); - return (ret); -} diff --git a/lib/libarchive/archive_write_set_compression_gzip.c b/lib/libarchive/archive_write_set_compression_gzip.c deleted file mode 100644 index 6ecb4ea..0000000 --- a/lib/libarchive/archive_write_set_compression_gzip.c +++ /dev/null @@ -1,477 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" - -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#include -#ifdef HAVE_ZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#ifndef HAVE_ZLIB_H -int -archive_write_set_compression_gzip(struct archive *a) -{ - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "gzip compression not supported on this platform"); - return (ARCHIVE_FATAL); -} -#else -/* Don't compile this if we don't have zlib. */ - -struct private_data { - z_stream stream; - int64_t total_in; - unsigned char *compressed; - size_t compressed_buffer_size; - unsigned long crc; -}; - -struct private_config { - int compression_level; -}; - - -/* - * Yuck. zlib.h is not const-correct, so I need this one bit - * of ugly hackery to convert a const * pointer to a non-const pointer. - */ -#define SET_NEXT_IN(st,src) \ - (st)->stream.next_in = (Bytef *)(uintptr_t)(const void *)(src) - -static int archive_compressor_gzip_finish(struct archive_write *); -static int archive_compressor_gzip_init(struct archive_write *); -static int archive_compressor_gzip_options(struct archive_write *, - const char *, const char *); -static int archive_compressor_gzip_write(struct archive_write *, - const void *, size_t); -static int drive_compressor(struct archive_write *, struct private_data *, - int finishing); - - -/* - * Allocate, initialize and return a archive object. - */ -int -archive_write_set_compression_gzip(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct private_config *config; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_gzip"); - config = malloc(sizeof(*config)); - if (config == NULL) { - archive_set_error(&a->archive, ENOMEM, "Out of memory"); - return (ARCHIVE_FATAL); - } - a->compressor.config = config; - a->compressor.finish = &archive_compressor_gzip_finish; - config->compression_level = Z_DEFAULT_COMPRESSION; - a->compressor.init = &archive_compressor_gzip_init; - a->compressor.options = &archive_compressor_gzip_options; - a->archive.compression_code = ARCHIVE_COMPRESSION_GZIP; - a->archive.compression_name = "gzip"; - return (ARCHIVE_OK); -} - -/* - * Setup callback. - */ -static int -archive_compressor_gzip_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - struct private_config *config; - time_t t; - - config = (struct private_config *)a->compressor.config; - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != ARCHIVE_OK) - return (ret); - } - - /* - * The next check is a temporary workaround until the gzip - * code can be overhauled some. The code should not require - * that compressed_buffer_size == bytes_per_block. Removing - * this assumption will allow us to compress larger chunks at - * a time, which should improve overall performance - * marginally. As a minor side-effect, such a cleanup would - * allow us to support truly arbitrary block sizes. - */ - if (a->bytes_per_block < 10) { - archive_set_error(&a->archive, EINVAL, - "GZip compressor requires a minimum 10 byte block size"); - return (ARCHIVE_FATAL); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - /* - * See comment above. We should set compressed_buffer_size to - * max(bytes_per_block, 65536), but the code can't handle that yet. - */ - state->compressed_buffer_size = a->bytes_per_block; - state->compressed = (unsigned char *)malloc(state->compressed_buffer_size); - state->crc = crc32(0L, NULL, 0); - - if (state->compressed == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - - state->stream.next_out = state->compressed; - state->stream.avail_out = state->compressed_buffer_size; - - /* Prime output buffer with a gzip header. */ - t = time(NULL); - state->compressed[0] = 0x1f; /* GZip signature bytes */ - state->compressed[1] = 0x8b; - state->compressed[2] = 0x08; /* "Deflate" compression */ - state->compressed[3] = 0; /* No options */ - state->compressed[4] = (t)&0xff; /* Timestamp */ - state->compressed[5] = (t>>8)&0xff; - state->compressed[6] = (t>>16)&0xff; - state->compressed[7] = (t>>24)&0xff; - state->compressed[8] = 0; /* No deflate options */ - state->compressed[9] = 3; /* OS=Unix */ - state->stream.next_out += 10; - state->stream.avail_out -= 10; - - a->compressor.write = archive_compressor_gzip_write; - - /* Initialize compression library. */ - ret = deflateInit2(&(state->stream), - config->compression_level, - Z_DEFLATED, - -15 /* < 0 to suppress zlib header */, - 8, - Z_DEFAULT_STRATEGY); - - if (ret == Z_OK) { - a->compressor.data = state; - return (0); - } - - /* Library setup failed: clean up. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal error " - "initializing compression library"); - free(state->compressed); - free(state); - - /* Override the error message if we know what really went wrong. */ - switch (ret) { - case Z_STREAM_ERROR: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing " - "compression library: invalid setup parameter"); - break; - case Z_MEM_ERROR: - archive_set_error(&a->archive, ENOMEM, "Internal error initializing " - "compression library"); - break; - case Z_VERSION_ERROR: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing " - "compression library: invalid library version"); - break; - } - - return (ARCHIVE_FATAL); -} - -/* - * Set write options. - */ -static int -archive_compressor_gzip_options(struct archive_write *a, const char *key, - const char *value) -{ - struct private_config *config; - - config = (struct private_config *)a->compressor.config; - if (strcmp(key, "compression-level") == 0) { - if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || - value[1] != '\0') - return (ARCHIVE_WARN); - config->compression_level = value[0] - '0'; - return (ARCHIVE_OK); - } - - return (ARCHIVE_WARN); -} - -/* - * Write data to the compressed stream. - */ -static int -archive_compressor_gzip_write(struct archive_write *a, const void *buff, - size_t length) -{ - struct private_data *state; - int ret; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - /* Update statistics */ - state->crc = crc32(state->crc, (const Bytef *)buff, length); - state->total_in += length; - - /* Compress input data to output buffer */ - SET_NEXT_IN(state, buff); - state->stream.avail_in = length; - if ((ret = drive_compressor(a, state, 0)) != ARCHIVE_OK) - return (ret); - - a->archive.file_position += length; - return (ARCHIVE_OK); -} - -/* - * Finish the compression... - */ -static int -archive_compressor_gzip_finish(struct archive_write *a) -{ - ssize_t block_length, target_block_length, bytes_written; - int ret; - struct private_data *state; - unsigned tocopy; - unsigned char trailer[8]; - - state = (struct private_data *)a->compressor.data; - ret = 0; - if (state != NULL) { - if (a->client_writer == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* By default, always pad the uncompressed data. */ - if (a->pad_uncompressed) { - tocopy = a->bytes_per_block - - (state->total_in % a->bytes_per_block); - while (tocopy > 0 && tocopy < (unsigned)a->bytes_per_block) { - SET_NEXT_IN(state, a->nulls); - state->stream.avail_in = tocopy < a->null_length ? - tocopy : a->null_length; - state->crc = crc32(state->crc, a->nulls, - state->stream.avail_in); - state->total_in += state->stream.avail_in; - tocopy -= state->stream.avail_in; - ret = drive_compressor(a, state, 0); - if (ret != ARCHIVE_OK) - goto cleanup; - } - } - - /* Finish compression cycle */ - if (((ret = drive_compressor(a, state, 1))) != ARCHIVE_OK) - goto cleanup; - - /* Build trailer: 4-byte CRC and 4-byte length. */ - trailer[0] = (state->crc)&0xff; - trailer[1] = (state->crc >> 8)&0xff; - trailer[2] = (state->crc >> 16)&0xff; - trailer[3] = (state->crc >> 24)&0xff; - trailer[4] = (state->total_in)&0xff; - trailer[5] = (state->total_in >> 8)&0xff; - trailer[6] = (state->total_in >> 16)&0xff; - trailer[7] = (state->total_in >> 24)&0xff; - - /* Add trailer to current block. */ - tocopy = 8; - if (tocopy > state->stream.avail_out) - tocopy = state->stream.avail_out; - memcpy(state->stream.next_out, trailer, tocopy); - state->stream.next_out += tocopy; - state->stream.avail_out -= tocopy; - - /* If it overflowed, flush and start a new block. */ - if (tocopy < 8) { - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, state->compressed_buffer_size); - if (bytes_written <= 0) { - ret = ARCHIVE_FATAL; - goto cleanup; - } - a->archive.raw_position += bytes_written; - state->stream.next_out = state->compressed; - state->stream.avail_out = state->compressed_buffer_size; - memcpy(state->stream.next_out, trailer + tocopy, 8-tocopy); - state->stream.next_out += 8-tocopy; - state->stream.avail_out -= 8-tocopy; - } - - /* Optionally, pad the final compressed block. */ - block_length = state->stream.next_out - state->compressed; - - /* Tricky calculation to determine size of last block. */ - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round length to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->stream.next_out, 0, - target_block_length - block_length); - block_length = target_block_length; - } - - /* Write the last block */ - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, block_length); - if (bytes_written <= 0) { - ret = ARCHIVE_FATAL; - goto cleanup; - } - a->archive.raw_position += bytes_written; - - /* Cleanup: shut down compressor, release memory, etc. */ - cleanup: - switch (deflateEnd(&(state->stream))) { - case Z_OK: - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Failed to clean up compressor"); - ret = ARCHIVE_FATAL; - } - free(state->compressed); - free(state); - } - /* Clean up config area even if we never initialized. */ - free(a->compressor.config); - a->compressor.config = NULL; - return (ret); -} - -/* - * Utility function to push input data through compressor, - * writing full output blocks as necessary. - * - * Note that this handles both the regular write case (finishing == - * false) and the end-of-archive case (finishing == true). - */ -static int -drive_compressor(struct archive_write *a, struct private_data *state, int finishing) -{ - ssize_t bytes_written; - int ret; - - for (;;) { - if (state->stream.avail_out == 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->compressed, - state->compressed_buffer_size); - if (bytes_written <= 0) { - /* TODO: Handle this write failure */ - return (ARCHIVE_FATAL); - } else if ((size_t)bytes_written < state->compressed_buffer_size) { - /* Short write: Move remaining to - * front of block and keep filling */ - memmove(state->compressed, - state->compressed + bytes_written, - state->compressed_buffer_size - bytes_written); - } - a->archive.raw_position += bytes_written; - state->stream.next_out - = state->compressed + - state->compressed_buffer_size - bytes_written; - state->stream.avail_out = bytes_written; - } - - /* If there's nothing to do, we're done. */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - - ret = deflate(&(state->stream), - finishing ? Z_FINISH : Z_NO_FLUSH ); - - switch (ret) { - case Z_OK: - /* In non-finishing case, check if compressor - * consumed everything */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - /* In finishing case, this return always means - * there's more work */ - break; - case Z_STREAM_END: - /* This return can only occur in finishing case. */ - return (ARCHIVE_OK); - default: - /* Any other return value indicates an error. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "GZip compression failed:" - " deflate() call returned status %d", - ret); - return (ARCHIVE_FATAL); - } - } -} - -#endif /* HAVE_ZLIB_H */ diff --git a/lib/libarchive/archive_write_set_compression_none.c b/lib/libarchive/archive_write_set_compression_none.c deleted file mode 100644 index 4527485..0000000 --- a/lib/libarchive/archive_write_set_compression_none.c +++ /dev/null @@ -1,257 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -static int archive_compressor_none_finish(struct archive_write *a); -static int archive_compressor_none_init(struct archive_write *); -static int archive_compressor_none_write(struct archive_write *, - const void *, size_t); - -struct archive_none { - char *buffer; - ssize_t buffer_size; - char *next; /* Current insert location */ - ssize_t avail; /* Free space left in buffer */ -}; - -int -archive_write_set_compression_none(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_none"); - a->compressor.init = &archive_compressor_none_init; - return (0); -} - -/* - * Setup callback. - */ -static int -archive_compressor_none_init(struct archive_write *a) -{ - int ret; - struct archive_none *state; - - a->archive.compression_code = ARCHIVE_COMPRESSION_NONE; - a->archive.compression_name = "none"; - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != 0) - return (ret); - } - - state = (struct archive_none *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for output buffering"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - state->buffer_size = a->bytes_per_block; - if (state->buffer_size != 0) { - state->buffer = (char *)malloc(state->buffer_size); - if (state->buffer == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate output buffer"); - free(state); - return (ARCHIVE_FATAL); - } - } - - state->next = state->buffer; - state->avail = state->buffer_size; - - a->compressor.data = state; - a->compressor.write = archive_compressor_none_write; - a->compressor.finish = archive_compressor_none_finish; - return (ARCHIVE_OK); -} - -/* - * Write data to the stream. - */ -static int -archive_compressor_none_write(struct archive_write *a, const void *vbuff, - size_t length) -{ - const char *buff; - ssize_t remaining, to_copy; - ssize_t bytes_written; - struct archive_none *state; - - state = (struct archive_none *)a->compressor.data; - buff = (const char *)vbuff; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - remaining = length; - - /* - * If there is no buffer for blocking, just pass the data - * straight through to the client write callback. In - * particular, this supports "no write delay" operation for - * special applications. Just set the block size to zero. - */ - if (state->buffer_size == 0) { - while (remaining > 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, buff, remaining); - if (bytes_written <= 0) - return (ARCHIVE_FATAL); - a->archive.raw_position += bytes_written; - remaining -= bytes_written; - buff += bytes_written; - } - a->archive.file_position += length; - return (ARCHIVE_OK); - } - - /* If the copy buffer isn't empty, try to fill it. */ - if (state->avail < state->buffer_size) { - /* If buffer is not empty... */ - /* ... copy data into buffer ... */ - to_copy = (remaining > state->avail) ? - state->avail : remaining; - memcpy(state->next, buff, to_copy); - state->next += to_copy; - state->avail -= to_copy; - buff += to_copy; - remaining -= to_copy; - /* ... if it's full, write it out. */ - if (state->avail == 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->buffer, state->buffer_size); - if (bytes_written <= 0) - return (ARCHIVE_FATAL); - /* XXX TODO: if bytes_written < state->buffer_size */ - a->archive.raw_position += bytes_written; - state->next = state->buffer; - state->avail = state->buffer_size; - } - } - - while (remaining > state->buffer_size) { - /* Write out full blocks directly to client. */ - bytes_written = (a->client_writer)(&a->archive, - a->client_data, buff, state->buffer_size); - if (bytes_written <= 0) - return (ARCHIVE_FATAL); - a->archive.raw_position += bytes_written; - buff += bytes_written; - remaining -= bytes_written; - } - - if (remaining > 0) { - /* Copy last bit into copy buffer. */ - memcpy(state->next, buff, remaining); - state->next += remaining; - state->avail -= remaining; - } - - a->archive.file_position += length; - return (ARCHIVE_OK); -} - - -/* - * Finish the compression. - */ -static int -archive_compressor_none_finish(struct archive_write *a) -{ - ssize_t block_length; - ssize_t target_block_length; - ssize_t bytes_written; - int ret; - struct archive_none *state; - - state = (struct archive_none *)a->compressor.data; - ret = ARCHIVE_OK; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - /* If there's pending data, pad and write the last block */ - if (state->next != state->buffer) { - block_length = state->buffer_size - state->avail; - - /* Tricky calculation to determine size of last block */ - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->next, 0, - target_block_length - block_length); - block_length = target_block_length; - } - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->buffer, block_length); - if (bytes_written <= 0) - ret = ARCHIVE_FATAL; - else { - a->archive.raw_position += bytes_written; - ret = ARCHIVE_OK; - } - } - if (state->buffer) - free(state->buffer); - free(state); - a->compressor.data = NULL; - - return (ret); -} diff --git a/lib/libarchive/archive_write_set_compression_program.c b/lib/libarchive/archive_write_set_compression_program.c deleted file mode 100644 index 68c86cc..0000000 --- a/lib/libarchive/archive_write_set_compression_program.c +++ /dev/null @@ -1,347 +0,0 @@ -/*- - * Copyright (c) 2007 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" - -__FBSDID("$FreeBSD$"); - -/* This capability is only available on POSIX systems. */ -#if (!defined(HAVE_PIPE) || !defined(HAVE_FCNTL) || \ - !(defined(HAVE_FORK) || defined(HAVE_VFORK))) && (!defined(_WIN32) || defined(__CYGWIN__)) -#include "archive.h" - -/* - * On non-Posix systems, allow the program to build, but choke if - * this function is actually invoked. - */ -int -archive_write_set_compression_program(struct archive *_a, const char *cmd) -{ - archive_set_error(_a, -1, - "External compression programs not supported on this platform"); - return (ARCHIVE_FATAL); -} - -#else - -#ifdef HAVE_SYS_WAIT_H -# include -#endif -#ifdef HAVE_ERRNO_H -# include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -#ifdef HAVE_STDLIB_H -# include -#endif -#ifdef HAVE_STRING_H -# include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#include "filter_fork.h" - -struct private_data { - char *description; - pid_t child; - int child_stdin, child_stdout; - - char *child_buf; - size_t child_buf_len, child_buf_avail; -}; - -static int archive_compressor_program_finish(struct archive_write *); -static int archive_compressor_program_init(struct archive_write *); -static int archive_compressor_program_write(struct archive_write *, - const void *, size_t); - -/* - * Allocate, initialize and return a archive object. - */ -int -archive_write_set_compression_program(struct archive *_a, const char *cmd) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_program"); - a->compressor.init = &archive_compressor_program_init; - a->compressor.config = strdup(cmd); - return (ARCHIVE_OK); -} - -/* - * Setup callback. - */ -static int -archive_compressor_program_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - static const char *prefix = "Program: "; - char *cmd = a->compressor.config; - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != ARCHIVE_OK) - return (ret); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - a->archive.compression_code = ARCHIVE_COMPRESSION_PROGRAM; - state->description = (char *)malloc(strlen(prefix) + strlen(cmd) + 1); - strcpy(state->description, prefix); - strcat(state->description, cmd); - a->archive.compression_name = state->description; - - state->child_buf_len = a->bytes_per_block; - state->child_buf_avail = 0; - state->child_buf = malloc(state->child_buf_len); - - if (state->child_buf == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - - if ((state->child = __archive_create_child(cmd, - &state->child_stdin, &state->child_stdout)) == -1) { - archive_set_error(&a->archive, EINVAL, - "Can't initialise filter"); - free(state->child_buf); - free(state); - return (ARCHIVE_FATAL); - } - - a->compressor.write = archive_compressor_program_write; - a->compressor.finish = archive_compressor_program_finish; - - a->compressor.data = state; - return (0); -} - -static ssize_t -child_write(struct archive_write *a, const char *buf, size_t buf_len) -{ - struct private_data *state = a->compressor.data; - ssize_t ret; - - if (state->child_stdin == -1) - return (-1); - - if (buf_len == 0) - return (-1); - -restart_write: - do { - ret = write(state->child_stdin, buf, buf_len); - } while (ret == -1 && errno == EINTR); - - if (ret > 0) - return (ret); - if (ret == 0) { - close(state->child_stdin); - state->child_stdin = -1; - fcntl(state->child_stdout, F_SETFL, 0); - return (0); - } - if (ret == -1 && errno != EAGAIN) - return (-1); - - if (state->child_stdout == -1) { - fcntl(state->child_stdin, F_SETFL, 0); - __archive_check_child(state->child_stdin, state->child_stdout); - goto restart_write; - } - - do { - ret = read(state->child_stdout, - state->child_buf + state->child_buf_avail, - state->child_buf_len - state->child_buf_avail); - } while (ret == -1 && errno == EINTR); - - if (ret == 0 || (ret == -1 && errno == EPIPE)) { - close(state->child_stdout); - state->child_stdout = -1; - fcntl(state->child_stdin, F_SETFL, 0); - goto restart_write; - } - if (ret == -1 && errno == EAGAIN) { - __archive_check_child(state->child_stdin, state->child_stdout); - goto restart_write; - } - if (ret == -1) - return (-1); - - state->child_buf_avail += ret; - - ret = (a->client_writer)(&a->archive, a->client_data, - state->child_buf, state->child_buf_avail); - if (ret <= 0) - return (-1); - - if ((size_t)ret < state->child_buf_avail) { - memmove(state->child_buf, state->child_buf + ret, - state->child_buf_avail - ret); - } - state->child_buf_avail -= ret; - a->archive.raw_position += ret; - goto restart_write; -} - -/* - * Write data to the compressed stream. - */ -static int -archive_compressor_program_write(struct archive_write *a, const void *buff, - size_t length) -{ - ssize_t ret; - const char *buf; - - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - buf = buff; - while (length > 0) { - ret = child_write(a, buf, length); - if (ret == -1 || ret == 0) { - archive_set_error(&a->archive, EIO, - "Can't write to filter"); - return (ARCHIVE_FATAL); - } - length -= ret; - buf += ret; - } - - a->archive.file_position += length; - return (ARCHIVE_OK); -} - - -/* - * Finish the compression... - */ -static int -archive_compressor_program_finish(struct archive_write *a) -{ - int ret, status; - ssize_t bytes_read, bytes_written; - struct private_data *state; - - state = (struct private_data *)a->compressor.data; - ret = 0; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* XXX pad compressed data. */ - - close(state->child_stdin); - state->child_stdin = -1; - fcntl(state->child_stdout, F_SETFL, 0); - - for (;;) { - do { - bytes_read = read(state->child_stdout, - state->child_buf + state->child_buf_avail, - state->child_buf_len - state->child_buf_avail); - } while (bytes_read == -1 && errno == EINTR); - - if (bytes_read == 0 || (bytes_read == -1 && errno == EPIPE)) - break; - - if (bytes_read == -1) { - archive_set_error(&a->archive, errno, - "Read from filter failed unexpectedly."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - state->child_buf_avail += bytes_read; - - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->child_buf, state->child_buf_avail); - if (bytes_written <= 0) { - ret = ARCHIVE_FATAL; - goto cleanup; - } - if ((size_t)bytes_written < state->child_buf_avail) { - memmove(state->child_buf, - state->child_buf + bytes_written, - state->child_buf_avail - bytes_written); - } - state->child_buf_avail -= bytes_written; - a->archive.raw_position += bytes_written; - } - - /* XXX pad final compressed block. */ - -cleanup: - /* Shut down the child. */ - if (state->child_stdin != -1) - close(state->child_stdin); - if (state->child_stdout != -1) - close(state->child_stdout); - while (waitpid(state->child, &status, 0) == -1 && errno == EINTR) - continue; - - if (status != 0) { - archive_set_error(&a->archive, EIO, - "Filter exited with failure."); - ret = ARCHIVE_FATAL; - } - - /* Release our configuration data. */ - free(a->compressor.config); - a->compressor.config = NULL; - - /* Release our private state data. */ - free(state->child_buf); - free(state->description); - free(state); - return (ret); -} - -#endif /* !defined(HAVE_PIPE) || !defined(HAVE_VFORK) || !defined(HAVE_FCNTL) */ diff --git a/lib/libarchive/archive_write_set_compression_xz.c b/lib/libarchive/archive_write_set_compression_xz.c deleted file mode 100644 index 15b6cc2..0000000 --- a/lib/libarchive/archive_write_set_compression_xz.c +++ /dev/null @@ -1,439 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" - -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#include -#ifdef HAVE_LZMA_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#ifndef HAVE_LZMA_H -int -archive_write_set_compression_xz(struct archive *a) -{ - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "xz compression not supported on this platform"); - return (ARCHIVE_FATAL); -} - -int -archive_write_set_compression_lzma(struct archive *a) -{ - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "lzma compression not supported on this platform"); - return (ARCHIVE_FATAL); -} -#else -/* Don't compile this if we don't have liblzma. */ - -struct private_data { - lzma_stream stream; - lzma_filter lzmafilters[2]; - lzma_options_lzma lzma_opt; - int64_t total_in; - unsigned char *compressed; - size_t compressed_buffer_size; -}; - -struct private_config { - int compression_level; -}; - -static int archive_compressor_xz_init(struct archive_write *); -static int archive_compressor_xz_options(struct archive_write *, - const char *, const char *); -static int archive_compressor_xz_finish(struct archive_write *); -static int archive_compressor_xz_write(struct archive_write *, - const void *, size_t); -static int drive_compressor(struct archive_write *, struct private_data *, - int finishing); - - -/* - * Allocate, initialize and return a archive object. - */ -int -archive_write_set_compression_xz(struct archive *_a) -{ - struct private_config *config; - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_xz"); - config = calloc(1, sizeof(*config)); - if (config == NULL) { - archive_set_error(&a->archive, ENOMEM, "Out of memory"); - return (ARCHIVE_FATAL); - } - a->compressor.config = config; - a->compressor.finish = archive_compressor_xz_finish; - config->compression_level = LZMA_PRESET_DEFAULT; - a->compressor.init = &archive_compressor_xz_init; - a->compressor.options = &archive_compressor_xz_options; - a->archive.compression_code = ARCHIVE_COMPRESSION_XZ; - a->archive.compression_name = "xz"; - return (ARCHIVE_OK); -} - -/* LZMA is handled identically, we just need a different compression - * code set. (The liblzma setup looks at the code to determine - * the one place that XZ and LZMA require different handling.) */ -int -archive_write_set_compression_lzma(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - int r = archive_write_set_compression_xz(_a); - if (r != ARCHIVE_OK) - return (r); - a->archive.compression_code = ARCHIVE_COMPRESSION_LZMA; - a->archive.compression_name = "lzma"; - return (ARCHIVE_OK); -} - -static int -archive_compressor_xz_init_stream(struct archive_write *a, - struct private_data *state) -{ - static const lzma_stream lzma_stream_init_data = LZMA_STREAM_INIT; - int ret; - - state->stream = lzma_stream_init_data; - state->stream.next_out = state->compressed; - state->stream.avail_out = state->compressed_buffer_size; - if (a->archive.compression_code == ARCHIVE_COMPRESSION_XZ) - ret = lzma_stream_encoder(&(state->stream), - state->lzmafilters, LZMA_CHECK_CRC64); - else - ret = lzma_alone_encoder(&(state->stream), &state->lzma_opt); - if (ret == LZMA_OK) - return (ARCHIVE_OK); - - switch (ret) { - case LZMA_MEM_ERROR: - archive_set_error(&a->archive, ENOMEM, - "Internal error initializing compression library: " - "Cannot allocate memory"); - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "It's a bug in liblzma"); - break; - } - return (ARCHIVE_FATAL); -} - -/* - * Setup callback. - */ -static int -archive_compressor_xz_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - struct private_config *config; - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != ARCHIVE_OK) - return (ret); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - config = a->compressor.config; - - /* - * See comment above. We should set compressed_buffer_size to - * max(bytes_per_block, 65536), but the code can't handle that yet. - */ - state->compressed_buffer_size = a->bytes_per_block; - state->compressed = (unsigned char *)malloc(state->compressed_buffer_size); - if (state->compressed == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - a->compressor.write = archive_compressor_xz_write; - - /* Initialize compression library. */ - if (lzma_lzma_preset(&state->lzma_opt, config->compression_level)) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library"); - free(state->compressed); - free(state); - } - state->lzmafilters[0].id = LZMA_FILTER_LZMA2; - state->lzmafilters[0].options = &state->lzma_opt; - state->lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */ - ret = archive_compressor_xz_init_stream(a, state); - if (ret == LZMA_OK) { - a->compressor.data = state; - return (0); - } - /* Library setup failed: clean up. */ - free(state->compressed); - free(state); - - return (ARCHIVE_FATAL); -} - -/* - * Set write options. - */ -static int -archive_compressor_xz_options(struct archive_write *a, const char *key, - const char *value) -{ - struct private_config *config; - - config = (struct private_config *)a->compressor.config; - if (strcmp(key, "compression-level") == 0) { - if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || - value[1] != '\0') - return (ARCHIVE_WARN); - config->compression_level = value[0] - '0'; - if (config->compression_level > 6) - config->compression_level = 6; - return (ARCHIVE_OK); - } - - return (ARCHIVE_WARN); -} - -/* - * Write data to the compressed stream. - */ -static int -archive_compressor_xz_write(struct archive_write *a, const void *buff, - size_t length) -{ - struct private_data *state; - int ret; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - /* Update statistics */ - state->total_in += length; - - /* Compress input data to output buffer */ - state->stream.next_in = buff; - state->stream.avail_in = length; - if ((ret = drive_compressor(a, state, 0)) != ARCHIVE_OK) - return (ret); - - a->archive.file_position += length; - return (ARCHIVE_OK); -} - - -/* - * Finish the compression... - */ -static int -archive_compressor_xz_finish(struct archive_write *a) -{ - ssize_t block_length, target_block_length, bytes_written; - int ret; - struct private_data *state; - unsigned tocopy; - - ret = ARCHIVE_OK; - state = (struct private_data *)a->compressor.data; - if (state != NULL) { - if (a->client_writer == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* By default, always pad the uncompressed data. */ - if (a->pad_uncompressed) { - tocopy = a->bytes_per_block - - (state->total_in % a->bytes_per_block); - while (tocopy > 0 && tocopy < (unsigned)a->bytes_per_block) { - state->stream.next_in = a->nulls; - state->stream.avail_in = tocopy < a->null_length ? - tocopy : a->null_length; - state->total_in += state->stream.avail_in; - tocopy -= state->stream.avail_in; - ret = drive_compressor(a, state, 0); - if (ret != ARCHIVE_OK) - goto cleanup; - } - } - - /* Finish compression cycle */ - if (((ret = drive_compressor(a, state, 1))) != ARCHIVE_OK) - goto cleanup; - - /* Optionally, pad the final compressed block. */ - block_length = state->stream.next_out - state->compressed; - - /* Tricky calculation to determine size of last block. */ - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round length to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->stream.next_out, 0, - target_block_length - block_length); - block_length = target_block_length; - } - - /* Write the last block */ - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, block_length); - if (bytes_written <= 0) { - ret = ARCHIVE_FATAL; - goto cleanup; - } - a->archive.raw_position += bytes_written; - - /* Cleanup: shut down compressor, release memory, etc. */ - cleanup: - lzma_end(&(state->stream)); - free(state->compressed); - free(state); - } - free(a->compressor.config); - a->compressor.config = NULL; - return (ret); -} - -/* - * Utility function to push input data through compressor, - * writing full output blocks as necessary. - * - * Note that this handles both the regular write case (finishing == - * false) and the end-of-archive case (finishing == true). - */ -static int -drive_compressor(struct archive_write *a, struct private_data *state, int finishing) -{ - ssize_t bytes_written; - int ret; - - for (;;) { - if (state->stream.avail_out == 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->compressed, - state->compressed_buffer_size); - if (bytes_written <= 0) { - /* TODO: Handle this write failure */ - return (ARCHIVE_FATAL); - } else if ((size_t)bytes_written < state->compressed_buffer_size) { - /* Short write: Move remaining to - * front of block and keep filling */ - memmove(state->compressed, - state->compressed + bytes_written, - state->compressed_buffer_size - bytes_written); - } - a->archive.raw_position += bytes_written; - state->stream.next_out - = state->compressed + - state->compressed_buffer_size - bytes_written; - state->stream.avail_out = bytes_written; - } - - /* If there's nothing to do, we're done. */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - - ret = lzma_code(&(state->stream), - finishing ? LZMA_FINISH : LZMA_RUN ); - - switch (ret) { - case LZMA_OK: - /* In non-finishing case, check if compressor - * consumed everything */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - /* In finishing case, this return always means - * there's more work */ - break; - case LZMA_STREAM_END: - /* This return can only occur in finishing case. */ - if (finishing) - return (ARCHIVE_OK); - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "lzma compression data error"); - return (ARCHIVE_FATAL); - case LZMA_MEMLIMIT_ERROR: - archive_set_error(&a->archive, ENOMEM, - "lzma compression error: " - "%ju MiB would have been needed", - (uintmax_t)((lzma_memusage(&(state->stream)) + 1024 * 1024 -1) - / (1024 * 1024))); - return (ARCHIVE_FATAL); - default: - /* Any other return value indicates an error. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "lzma compression failed:" - " lzma_code() call returned status %d", - ret); - return (ARCHIVE_FATAL); - } - } -} - -#endif /* HAVE_LZMA_H */ diff --git a/lib/libarchive/archive_write_set_format.c b/lib/libarchive/archive_write_set_format.c deleted file mode 100644 index dd91d44..0000000 --- a/lib/libarchive/archive_write_set_format.c +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#ifdef HAVE_ERRNO_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" - -/* A table that maps format codes to functions. */ -static -struct { int code; int (*setter)(struct archive *); } codes[] = -{ - { ARCHIVE_FORMAT_CPIO, archive_write_set_format_cpio }, - { ARCHIVE_FORMAT_CPIO_SVR4_NOCRC, archive_write_set_format_cpio_newc }, - { ARCHIVE_FORMAT_CPIO_POSIX, archive_write_set_format_cpio }, - { ARCHIVE_FORMAT_MTREE, archive_write_set_format_mtree }, - { ARCHIVE_FORMAT_SHAR, archive_write_set_format_shar }, - { ARCHIVE_FORMAT_SHAR_BASE, archive_write_set_format_shar }, - { ARCHIVE_FORMAT_SHAR_DUMP, archive_write_set_format_shar_dump }, - { ARCHIVE_FORMAT_TAR, archive_write_set_format_pax_restricted }, - { ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, archive_write_set_format_pax }, - { ARCHIVE_FORMAT_TAR_PAX_RESTRICTED, - archive_write_set_format_pax_restricted }, - { ARCHIVE_FORMAT_TAR_USTAR, archive_write_set_format_ustar }, - { ARCHIVE_FORMAT_ZIP, archive_write_set_format_zip }, - { 0, NULL } -}; - -int -archive_write_set_format(struct archive *a, int code) -{ - int i; - - for (i = 0; codes[i].code != 0; i++) { - if (code == codes[i].code) - return ((codes[i].setter)(a)); - } - - archive_set_error(a, EINVAL, "No such format"); - return (ARCHIVE_FATAL); -} diff --git a/lib/libarchive/archive_write_set_format_ar.c b/lib/libarchive/archive_write_set_format_ar.c deleted file mode 100644 index cb8ddaa..0000000 --- a/lib/libarchive/archive_write_set_format_ar.c +++ /dev/null @@ -1,550 +0,0 @@ -/*- - * Copyright (c) 2007 Kai Wang - * Copyright (c) 2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_write_private.h" - -struct ar_w { - uint64_t entry_bytes_remaining; - uint64_t entry_padding; - int is_strtab; - int has_strtab; - char *strtab; -}; - -/* - * Define structure of the "ar" header. - */ -#define AR_name_offset 0 -#define AR_name_size 16 -#define AR_date_offset 16 -#define AR_date_size 12 -#define AR_uid_offset 28 -#define AR_uid_size 6 -#define AR_gid_offset 34 -#define AR_gid_size 6 -#define AR_mode_offset 40 -#define AR_mode_size 8 -#define AR_size_offset 48 -#define AR_size_size 10 -#define AR_fmag_offset 58 -#define AR_fmag_size 2 - -static int archive_write_set_format_ar(struct archive_write *); -static int archive_write_ar_header(struct archive_write *, - struct archive_entry *); -static ssize_t archive_write_ar_data(struct archive_write *, - const void *buff, size_t s); -static int archive_write_ar_destroy(struct archive_write *); -static int archive_write_ar_finish(struct archive_write *); -static int archive_write_ar_finish_entry(struct archive_write *); -static const char *ar_basename(const char *path); -static int format_octal(int64_t v, char *p, int s); -static int format_decimal(int64_t v, char *p, int s); - -int -archive_write_set_format_ar_bsd(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - int r = archive_write_set_format_ar(a); - if (r == ARCHIVE_OK) { - a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; - a->archive.archive_format_name = "ar (BSD)"; - } - return (r); -} - -int -archive_write_set_format_ar_svr4(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - int r = archive_write_set_format_ar(a); - if (r == ARCHIVE_OK) { - a->archive.archive_format = ARCHIVE_FORMAT_AR_GNU; - a->archive.archive_format_name = "ar (GNU/SVR4)"; - } - return (r); -} - -/* - * Generic initialization. - */ -static int -archive_write_set_format_ar(struct archive_write *a) -{ - struct ar_w *ar; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - ar = (struct ar_w *)malloc(sizeof(*ar)); - if (ar == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate ar data"); - return (ARCHIVE_FATAL); - } - memset(ar, 0, sizeof(*ar)); - a->format_data = ar; - - a->format_name = "ar"; - a->format_write_header = archive_write_ar_header; - a->format_write_data = archive_write_ar_data; - a->format_finish = archive_write_ar_finish; - a->format_destroy = archive_write_ar_destroy; - a->format_finish_entry = archive_write_ar_finish_entry; - return (ARCHIVE_OK); -} - -static int -archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) -{ - int ret, append_fn; - char buff[60]; - char *ss, *se; - struct ar_w *ar; - const char *pathname; - const char *filename; - int64_t size; - - append_fn = 0; - ar = (struct ar_w *)a->format_data; - ar->is_strtab = 0; - filename = NULL; - size = archive_entry_size(entry); - - - /* - * Reject files with empty name. - */ - pathname = archive_entry_pathname(entry); - if (*pathname == '\0') { - archive_set_error(&a->archive, EINVAL, - "Invalid filename"); - return (ARCHIVE_WARN); - } - - /* - * If we are now at the beginning of the archive, - * we need first write the ar global header. - */ - if (a->archive.file_position == 0) - (a->compressor.write)(a, "!\n", 8); - - memset(buff, ' ', 60); - strncpy(&buff[AR_fmag_offset], "`\n", 2); - - if (strcmp(pathname, "/") == 0 ) { - /* Entry is archive symbol table in GNU format */ - buff[AR_name_offset] = '/'; - goto stat; - } - if (strcmp(pathname, "__.SYMDEF") == 0) { - /* Entry is archive symbol table in BSD format */ - strncpy(buff + AR_name_offset, "__.SYMDEF", 9); - goto stat; - } - if (strcmp(pathname, "//") == 0) { - /* - * Entry is archive filename table, inform that we should - * collect strtab in next _data call. - */ - ar->is_strtab = 1; - buff[AR_name_offset] = buff[AR_name_offset + 1] = '/'; - /* - * For archive string table, only ar_size filed should - * be set. - */ - goto size; - } - - /* - * Otherwise, entry is a normal archive member. - * Strip leading paths from filenames, if any. - */ - if ((filename = ar_basename(pathname)) == NULL) { - /* Reject filenames with trailing "/" */ - archive_set_error(&a->archive, EINVAL, - "Invalid filename"); - return (ARCHIVE_WARN); - } - - if (a->archive.archive_format == ARCHIVE_FORMAT_AR_GNU) { - /* - * SVR4/GNU variant use a "/" to mark then end of the filename, - * make it possible to have embedded spaces in the filename. - * So, the longest filename here (without extension) is - * actually 15 bytes. - */ - if (strlen(filename) <= 15) { - strncpy(&buff[AR_name_offset], - filename, strlen(filename)); - buff[AR_name_offset + strlen(filename)] = '/'; - } else { - /* - * For filename longer than 15 bytes, GNU variant - * makes use of a string table and instead stores the - * offset of the real filename to in the ar_name field. - * The string table should have been written before. - */ - if (ar->has_strtab <= 0) { - archive_set_error(&a->archive, EINVAL, - "Can't find string table"); - return (ARCHIVE_WARN); - } - - se = (char *)malloc(strlen(filename) + 3); - if (se == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate filename buffer"); - return (ARCHIVE_FATAL); - } - - strncpy(se, filename, strlen(filename)); - strcpy(se + strlen(filename), "/\n"); - - ss = strstr(ar->strtab, se); - free(se); - - if (ss == NULL) { - archive_set_error(&a->archive, EINVAL, - "Invalid string table"); - return (ARCHIVE_WARN); - } - - /* - * GNU variant puts "/" followed by digits into - * ar_name field. These digits indicates the real - * filename string's offset to the string table. - */ - buff[AR_name_offset] = '/'; - if (format_decimal(ss - ar->strtab, - buff + AR_name_offset + 1, - AR_name_size - 1)) { - archive_set_error(&a->archive, ERANGE, - "string table offset too large"); - return (ARCHIVE_WARN); - } - } - } else if (a->archive.archive_format == ARCHIVE_FORMAT_AR_BSD) { - /* - * BSD variant: for any file name which is more than - * 16 chars or contains one or more embedded space(s), the - * string "#1/" followed by the ASCII length of the name is - * put into the ar_name field. The file size (stored in the - * ar_size field) is incremented by the length of the name. - * The name is then written immediately following the - * archive header. - */ - if (strlen(filename) <= 16 && strchr(filename, ' ') == NULL) { - strncpy(&buff[AR_name_offset], filename, strlen(filename)); - buff[AR_name_offset + strlen(filename)] = ' '; - } - else { - strncpy(buff + AR_name_offset, "#1/", 3); - if (format_decimal(strlen(filename), - buff + AR_name_offset + 3, - AR_name_size - 3)) { - archive_set_error(&a->archive, ERANGE, - "File name too long"); - return (ARCHIVE_WARN); - } - append_fn = 1; - size += strlen(filename); - } - } - -stat: - if (format_decimal(archive_entry_mtime(entry), buff + AR_date_offset, AR_date_size)) { - archive_set_error(&a->archive, ERANGE, - "File modification time too large"); - return (ARCHIVE_WARN); - } - if (format_decimal(archive_entry_uid(entry), buff + AR_uid_offset, AR_uid_size)) { - archive_set_error(&a->archive, ERANGE, - "Numeric user ID too large"); - return (ARCHIVE_WARN); - } - if (format_decimal(archive_entry_gid(entry), buff + AR_gid_offset, AR_gid_size)) { - archive_set_error(&a->archive, ERANGE, - "Numeric group ID too large"); - return (ARCHIVE_WARN); - } - if (format_octal(archive_entry_mode(entry), buff + AR_mode_offset, AR_mode_size)) { - archive_set_error(&a->archive, ERANGE, - "Numeric mode too large"); - return (ARCHIVE_WARN); - } - /* - * Sanity Check: A non-pseudo archive member should always be - * a regular file. - */ - if (filename != NULL && archive_entry_filetype(entry) != AE_IFREG) { - archive_set_error(&a->archive, EINVAL, - "Regular file required for non-pseudo member"); - return (ARCHIVE_WARN); - } - -size: - if (format_decimal(size, buff + AR_size_offset, AR_size_size)) { - archive_set_error(&a->archive, ERANGE, - "File size out of range"); - return (ARCHIVE_WARN); - } - - ret = (a->compressor.write)(a, buff, 60); - if (ret != ARCHIVE_OK) - return (ret); - - ar->entry_bytes_remaining = size; - ar->entry_padding = ar->entry_bytes_remaining % 2; - - if (append_fn > 0) { - ret = (a->compressor.write)(a, filename, strlen(filename)); - if (ret != ARCHIVE_OK) - return (ret); - ar->entry_bytes_remaining -= strlen(filename); - } - - return (ARCHIVE_OK); -} - -static ssize_t -archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) -{ - struct ar_w *ar; - int ret; - - ar = (struct ar_w *)a->format_data; - if (s > ar->entry_bytes_remaining) - s = ar->entry_bytes_remaining; - - if (ar->is_strtab > 0) { - if (ar->has_strtab > 0) { - archive_set_error(&a->archive, EINVAL, - "More than one string tables exist"); - return (ARCHIVE_WARN); - } - - ar->strtab = (char *)malloc(s); - if (ar->strtab == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate strtab buffer"); - return (ARCHIVE_FATAL); - } - strncpy(ar->strtab, buff, s); - ar->has_strtab = 1; - } - - ret = (a->compressor.write)(a, buff, s); - if (ret != ARCHIVE_OK) - return (ret); - - ar->entry_bytes_remaining -= s; - return (s); -} - -static int -archive_write_ar_destroy(struct archive_write *a) -{ - struct ar_w *ar; - - ar = (struct ar_w *)a->format_data; - - if (ar == NULL) - return (ARCHIVE_OK); - - if (ar->has_strtab > 0) { - free(ar->strtab); - ar->strtab = NULL; - } - - free(ar); - a->format_data = NULL; - return (ARCHIVE_OK); -} - -static int -archive_write_ar_finish(struct archive_write *a) -{ - int ret; - - /* - * If we haven't written anything yet, we need to write - * the ar global header now to make it a valid ar archive. - */ - if (a->archive.file_position == 0) { - ret = (a->compressor.write)(a, "!\n", 8); - return (ret); - } - - return (ARCHIVE_OK); -} - -static int -archive_write_ar_finish_entry(struct archive_write *a) -{ - struct ar_w *ar; - int ret; - - ar = (struct ar_w *)a->format_data; - - if (ar->entry_bytes_remaining != 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Entry remaining bytes larger than 0"); - return (ARCHIVE_WARN); - } - - if (ar->entry_padding == 0) { - return (ARCHIVE_OK); - } - - if (ar->entry_padding != 1) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Padding wrong size: %d should be 1 or 0", - (int)ar->entry_padding); - return (ARCHIVE_WARN); - } - - ret = (a->compressor.write)(a, "\n", 1); - return (ret); -} - -/* - * Format a number into the specified field using base-8. - * NB: This version is slightly different from the one in - * _ustar.c - */ -static int -format_octal(int64_t v, char *p, int s) -{ - int len; - char *h; - - len = s; - h = p; - - /* Octal values can't be negative, so use 0. */ - if (v < 0) { - while (len-- > 0) - *p++ = '0'; - return (-1); - } - - p += s; /* Start at the end and work backwards. */ - do { - *--p = (char)('0' + (v & 7)); - v >>= 3; - } while (--s > 0 && v > 0); - - if (v == 0) { - memmove(h, p, len - s); - p = h + len - s; - while (s-- > 0) - *p++ = ' '; - return (0); - } - /* If it overflowed, fill field with max value. */ - while (len-- > 0) - *p++ = '7'; - - return (-1); -} - -/* - * Format a number into the specified field using base-10. - */ -static int -format_decimal(int64_t v, char *p, int s) -{ - int len; - char *h; - - len = s; - h = p; - - /* Negative values in ar header are meaningless , so use 0. */ - if (v < 0) { - while (len-- > 0) - *p++ = '0'; - return (-1); - } - - p += s; - do { - *--p = (char)('0' + (v % 10)); - v /= 10; - } while (--s > 0 && v > 0); - - if (v == 0) { - memmove(h, p, len - s); - p = h + len - s; - while (s-- > 0) - *p++ = ' '; - return (0); - } - /* If it overflowed, fill field with max value. */ - while (len-- > 0) - *p++ = '9'; - - return (-1); -} - -static const char * -ar_basename(const char *path) -{ - const char *endp, *startp; - - endp = path + strlen(path) - 1; - /* - * For filename with trailing slash(es), we return - * NULL indicating an error. - */ - if (*endp == '/') - return (NULL); - - /* Find the start of the base */ - startp = endp; - while (startp > path && *(startp - 1) != '/') - startp--; - - return (startp); -} diff --git a/lib/libarchive/archive_write_set_format_by_name.c b/lib/libarchive/archive_write_set_format_by_name.c deleted file mode 100644 index 593f544..0000000 --- a/lib/libarchive/archive_write_set_format_by_name.c +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" - -/* A table that maps names to functions. */ -static -struct { const char *name; int (*setter)(struct archive *); } names[] = -{ - { "ar", archive_write_set_format_ar_bsd }, - { "arbsd", archive_write_set_format_ar_bsd }, - { "argnu", archive_write_set_format_ar_svr4 }, - { "arsvr4", archive_write_set_format_ar_svr4 }, - { "cpio", archive_write_set_format_cpio }, - { "mtree", archive_write_set_format_mtree }, - { "newc", archive_write_set_format_cpio_newc }, - { "odc", archive_write_set_format_cpio }, - { "pax", archive_write_set_format_pax }, - { "posix", archive_write_set_format_pax }, - { "shar", archive_write_set_format_shar }, - { "shardump", archive_write_set_format_shar_dump }, - { "ustar", archive_write_set_format_ustar }, - { "zip", archive_write_set_format_zip }, - { NULL, NULL } -}; - -int -archive_write_set_format_by_name(struct archive *a, const char *name) -{ - int i; - - for (i = 0; names[i].name != NULL; i++) { - if (strcmp(name, names[i].name) == 0) - return ((names[i].setter)(a)); - } - - archive_set_error(a, EINVAL, "No such format '%s'", name); - return (ARCHIVE_FATAL); -} diff --git a/lib/libarchive/archive_write_set_format_cpio.c b/lib/libarchive/archive_write_set_format_cpio.c deleted file mode 100644 index 798646a..0000000 --- a/lib/libarchive/archive_write_set_format_cpio.c +++ /dev/null @@ -1,344 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_write_private.h" - -static ssize_t archive_write_cpio_data(struct archive_write *, - const void *buff, size_t s); -static int archive_write_cpio_finish(struct archive_write *); -static int archive_write_cpio_destroy(struct archive_write *); -static int archive_write_cpio_finish_entry(struct archive_write *); -static int archive_write_cpio_header(struct archive_write *, - struct archive_entry *); -static int format_octal(int64_t, void *, int); -static int64_t format_octal_recursive(int64_t, char *, int); - -struct cpio { - uint64_t entry_bytes_remaining; - - int64_t ino_next; - - struct { int64_t old; int new;} *ino_list; - size_t ino_list_size; - size_t ino_list_next; -}; - -struct cpio_header { - char c_magic[6]; - char c_dev[6]; - char c_ino[6]; - char c_mode[6]; - char c_uid[6]; - char c_gid[6]; - char c_nlink[6]; - char c_rdev[6]; - char c_mtime[11]; - char c_namesize[6]; - char c_filesize[11]; -} __packed; - -/* - * Set output format to 'cpio' format. - */ -int -archive_write_set_format_cpio(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct cpio *cpio; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - cpio = (struct cpio *)malloc(sizeof(*cpio)); - if (cpio == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); - return (ARCHIVE_FATAL); - } - memset(cpio, 0, sizeof(*cpio)); - a->format_data = cpio; - - a->pad_uncompressed = 1; - a->format_name = "cpio"; - a->format_write_header = archive_write_cpio_header; - a->format_write_data = archive_write_cpio_data; - a->format_finish_entry = archive_write_cpio_finish_entry; - a->format_finish = archive_write_cpio_finish; - a->format_destroy = archive_write_cpio_destroy; - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX; - a->archive.archive_format_name = "POSIX cpio"; - return (ARCHIVE_OK); -} - -/* - * Ino values are as long as 64 bits on some systems; cpio format - * only allows 18 bits and relies on the ino values to identify hardlinked - * files. So, we can't merely "hash" the ino numbers since collisions - * would corrupt the archive. Instead, we generate synthetic ino values - * to store in the archive and maintain a map of original ino values to - * synthetic ones so we can preserve hardlink information. - * - * TODO: Make this more efficient. It's not as bad as it looks (most - * files don't have any hardlinks and we don't do any work here for those), - * but it wouldn't be hard to do better. - * - * TODO: Work with dev/ino pairs here instead of just ino values. - */ -static int -synthesize_ino_value(struct cpio *cpio, struct archive_entry *entry) -{ - int64_t ino = archive_entry_ino64(entry); - int ino_new; - size_t i; - - /* - * If no index number was given, don't assign one. In - * particular, this handles the end-of-archive marker - * correctly by giving it a zero index value. (This is also - * why we start our synthetic index numbers with one below.) - */ - if (ino == 0) - return (0); - - /* Don't store a mapping if we don't need to. */ - if (archive_entry_nlink(entry) < 2) { - return ++cpio->ino_next; - } - - /* Look up old ino; if we have it, this is a hardlink - * and we reuse the same value. */ - for (i = 0; i < cpio->ino_list_next; ++i) { - if (cpio->ino_list[i].old == ino) - return (cpio->ino_list[i].new); - } - - /* Assign a new index number. */ - ino_new = ++cpio->ino_next; - - /* Ensure space for the new mapping. */ - if (cpio->ino_list_size <= cpio->ino_list_next) { - size_t newsize = cpio->ino_list_size < 512 - ? 512 : cpio->ino_list_size * 2; - void *newlist = realloc(cpio->ino_list, - sizeof(cpio->ino_list[0]) * newsize); - if (newlist == NULL) - return (-1); - - cpio->ino_list_size = newsize; - cpio->ino_list = newlist; - } - - /* Record and return the new value. */ - cpio->ino_list[cpio->ino_list_next].old = ino; - cpio->ino_list[cpio->ino_list_next].new = ino_new; - ++cpio->ino_list_next; - return (ino_new); -} - -static int -archive_write_cpio_header(struct archive_write *a, struct archive_entry *entry) -{ - struct cpio *cpio; - const char *p, *path; - int pathlength, ret, ret2; - int64_t ino; - struct cpio_header h; - - cpio = (struct cpio *)a->format_data; - ret2 = ARCHIVE_OK; - - path = archive_entry_pathname(entry); - pathlength = (int)strlen(path) + 1; /* Include trailing null. */ - - memset(&h, 0, sizeof(h)); - format_octal(070707, &h.c_magic, sizeof(h.c_magic)); - format_octal(archive_entry_dev(entry), &h.c_dev, sizeof(h.c_dev)); - - ino = synthesize_ino_value(cpio, entry); - if (ino < 0) { - archive_set_error(&a->archive, ENOMEM, - "No memory for ino translation table"); - return (ARCHIVE_FATAL); - } else if (ino > 0777777) { - archive_set_error(&a->archive, ERANGE, - "Too many files for this cpio format"); - return (ARCHIVE_FATAL); - } - format_octal(ino & 0777777, &h.c_ino, sizeof(h.c_ino)); - - format_octal(archive_entry_mode(entry), &h.c_mode, sizeof(h.c_mode)); - format_octal(archive_entry_uid(entry), &h.c_uid, sizeof(h.c_uid)); - format_octal(archive_entry_gid(entry), &h.c_gid, sizeof(h.c_gid)); - format_octal(archive_entry_nlink(entry), &h.c_nlink, sizeof(h.c_nlink)); - if (archive_entry_filetype(entry) == AE_IFBLK - || archive_entry_filetype(entry) == AE_IFCHR) - format_octal(archive_entry_dev(entry), &h.c_rdev, sizeof(h.c_rdev)); - else - format_octal(0, &h.c_rdev, sizeof(h.c_rdev)); - format_octal(archive_entry_mtime(entry), &h.c_mtime, sizeof(h.c_mtime)); - format_octal(pathlength, &h.c_namesize, sizeof(h.c_namesize)); - - /* Non-regular files don't store bodies. */ - if (archive_entry_filetype(entry) != AE_IFREG) - archive_entry_set_size(entry, 0); - - /* Symlinks get the link written as the body of the entry. */ - p = archive_entry_symlink(entry); - if (p != NULL && *p != '\0') - format_octal(strlen(p), &h.c_filesize, sizeof(h.c_filesize)); - else - format_octal(archive_entry_size(entry), - &h.c_filesize, sizeof(h.c_filesize)); - - ret = (a->compressor.write)(a, &h, sizeof(h)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - ret = (a->compressor.write)(a, path, pathlength); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - cpio->entry_bytes_remaining = archive_entry_size(entry); - - /* Write the symlink now. */ - if (p != NULL && *p != '\0') - ret = (a->compressor.write)(a, p, strlen(p)); - - if (ret == ARCHIVE_OK) - ret = ret2; - return (ret); -} - -static ssize_t -archive_write_cpio_data(struct archive_write *a, const void *buff, size_t s) -{ - struct cpio *cpio; - int ret; - - cpio = (struct cpio *)a->format_data; - if (s > cpio->entry_bytes_remaining) - s = cpio->entry_bytes_remaining; - - ret = (a->compressor.write)(a, buff, s); - cpio->entry_bytes_remaining -= s; - if (ret >= 0) - return (s); - else - return (ret); -} - -/* - * Format a number into the specified field. - */ -static int -format_octal(int64_t v, void *p, int digits) -{ - int64_t max; - int ret; - - max = (((int64_t)1) << (digits * 3)) - 1; - if (v >= 0 && v <= max) { - format_octal_recursive(v, (char *)p, digits); - ret = 0; - } else { - format_octal_recursive(max, (char *)p, digits); - ret = -1; - } - return (ret); -} - -static int64_t -format_octal_recursive(int64_t v, char *p, int s) -{ - if (s == 0) - return (v); - v = format_octal_recursive(v, p+1, s-1); - *p = '0' + (v & 7); - return (v >> 3); -} - -static int -archive_write_cpio_finish(struct archive_write *a) -{ - int er; - struct archive_entry *trailer; - - trailer = archive_entry_new(); - /* nlink = 1 here for GNU cpio compat. */ - archive_entry_set_nlink(trailer, 1); - archive_entry_set_pathname(trailer, "TRAILER!!!"); - er = archive_write_cpio_header(a, trailer); - archive_entry_free(trailer); - return (er); -} - -static int -archive_write_cpio_destroy(struct archive_write *a) -{ - struct cpio *cpio; - - cpio = (struct cpio *)a->format_data; - free(cpio->ino_list); - free(cpio); - a->format_data = NULL; - return (ARCHIVE_OK); -} - -static int -archive_write_cpio_finish_entry(struct archive_write *a) -{ - struct cpio *cpio; - size_t to_write; - int ret; - - cpio = (struct cpio *)a->format_data; - ret = ARCHIVE_OK; - while (cpio->entry_bytes_remaining > 0) { - to_write = cpio->entry_bytes_remaining < a->null_length ? - cpio->entry_bytes_remaining : a->null_length; - ret = (a->compressor.write)(a, a->nulls, to_write); - if (ret != ARCHIVE_OK) - return (ret); - cpio->entry_bytes_remaining -= to_write; - } - return (ret); -} diff --git a/lib/libarchive/archive_write_set_format_cpio_newc.c b/lib/libarchive/archive_write_set_format_cpio_newc.c deleted file mode 100644 index 187e7d6..0000000 --- a/lib/libarchive/archive_write_set_format_cpio_newc.c +++ /dev/null @@ -1,295 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2006 Rudolf Marek SYSGO s.r.o. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_write_private.h" - -static ssize_t archive_write_newc_data(struct archive_write *, - const void *buff, size_t s); -static int archive_write_newc_finish(struct archive_write *); -static int archive_write_newc_destroy(struct archive_write *); -static int archive_write_newc_finish_entry(struct archive_write *); -static int archive_write_newc_header(struct archive_write *, - struct archive_entry *); -static int format_hex(int64_t, void *, int); -static int64_t format_hex_recursive(int64_t, char *, int); - -struct cpio { - uint64_t entry_bytes_remaining; - int padding; -}; - -struct cpio_header_newc { - char c_magic[6]; - char c_ino[8]; - char c_mode[8]; - char c_uid[8]; - char c_gid[8]; - char c_nlink[8]; - char c_mtime[8]; - char c_filesize[8]; - char c_devmajor[8]; - char c_devminor[8]; - char c_rdevmajor[8]; - char c_rdevminor[8]; - char c_namesize[8]; - char c_checksum[8]; -}; - -/* Logic trick: difference between 'n' and next multiple of 4 */ -#define PAD4(n) (3 & (1 + ~(n))) - -/* - * Set output format to 'cpio' format. - */ -int -archive_write_set_format_cpio_newc(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct cpio *cpio; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - cpio = (struct cpio *)malloc(sizeof(*cpio)); - if (cpio == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); - return (ARCHIVE_FATAL); - } - memset(cpio, 0, sizeof(*cpio)); - a->format_data = cpio; - - a->pad_uncompressed = 1; - a->format_name = "cpio"; - a->format_write_header = archive_write_newc_header; - a->format_write_data = archive_write_newc_data; - a->format_finish_entry = archive_write_newc_finish_entry; - a->format_finish = archive_write_newc_finish; - a->format_destroy = archive_write_newc_destroy; - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC; - a->archive.archive_format_name = "SVR4 cpio nocrc"; - return (ARCHIVE_OK); -} - -static int -archive_write_newc_header(struct archive_write *a, struct archive_entry *entry) -{ - int64_t ino; - struct cpio *cpio; - const char *p, *path; - int pathlength, ret, ret2; - struct cpio_header_newc h; - int pad; - - cpio = (struct cpio *)a->format_data; - ret2 = ARCHIVE_OK; - - path = archive_entry_pathname(entry); - pathlength = (int)strlen(path) + 1; /* Include trailing null. */ - - memset(&h, 0, sizeof(h)); - format_hex(0x070701, &h.c_magic, sizeof(h.c_magic)); - format_hex(archive_entry_devmajor(entry), &h.c_devmajor, - sizeof(h.c_devmajor)); - format_hex(archive_entry_devminor(entry), &h.c_devminor, - sizeof(h.c_devminor)); - - ino = archive_entry_ino64(entry); - if (ino > 0xffffffff) { - archive_set_error(&a->archive, ERANGE, - "large inode number truncated"); - ret2 = ARCHIVE_WARN; - } - - format_hex(ino & 0xffffffff, &h.c_ino, sizeof(h.c_ino)); - format_hex(archive_entry_mode(entry), &h.c_mode, sizeof(h.c_mode)); - format_hex(archive_entry_uid(entry), &h.c_uid, sizeof(h.c_uid)); - format_hex(archive_entry_gid(entry), &h.c_gid, sizeof(h.c_gid)); - format_hex(archive_entry_nlink(entry), &h.c_nlink, sizeof(h.c_nlink)); - if (archive_entry_filetype(entry) == AE_IFBLK - || archive_entry_filetype(entry) == AE_IFCHR) { - format_hex(archive_entry_rdevmajor(entry), &h.c_rdevmajor, sizeof(h.c_rdevmajor)); - format_hex(archive_entry_rdevminor(entry), &h.c_rdevminor, sizeof(h.c_rdevminor)); - } else { - format_hex(0, &h.c_rdevmajor, sizeof(h.c_rdevmajor)); - format_hex(0, &h.c_rdevminor, sizeof(h.c_rdevminor)); - } - format_hex(archive_entry_mtime(entry), &h.c_mtime, sizeof(h.c_mtime)); - format_hex(pathlength, &h.c_namesize, sizeof(h.c_namesize)); - format_hex(0, &h.c_checksum, sizeof(h.c_checksum)); - - /* Non-regular files don't store bodies. */ - if (archive_entry_filetype(entry) != AE_IFREG) - archive_entry_set_size(entry, 0); - - /* Symlinks get the link written as the body of the entry. */ - p = archive_entry_symlink(entry); - if (p != NULL && *p != '\0') - format_hex(strlen(p), &h.c_filesize, sizeof(h.c_filesize)); - else - format_hex(archive_entry_size(entry), - &h.c_filesize, sizeof(h.c_filesize)); - - ret = (a->compressor.write)(a, &h, sizeof(h)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - /* Pad pathname to even length. */ - ret = (a->compressor.write)(a, path, pathlength); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - pad = PAD4(pathlength + sizeof(struct cpio_header_newc)); - if (pad) - ret = (a->compressor.write)(a, "\0\0\0", pad); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - cpio->entry_bytes_remaining = archive_entry_size(entry); - cpio->padding = PAD4(cpio->entry_bytes_remaining); - - /* Write the symlink now. */ - if (p != NULL && *p != '\0') { - ret = (a->compressor.write)(a, p, strlen(p)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - pad = PAD4(strlen(p)); - ret = (a->compressor.write)(a, "\0\0\0", pad); - } - - if (ret == ARCHIVE_OK) - ret = ret2; - return (ret); -} - -static ssize_t -archive_write_newc_data(struct archive_write *a, const void *buff, size_t s) -{ - struct cpio *cpio; - int ret; - - cpio = (struct cpio *)a->format_data; - if (s > cpio->entry_bytes_remaining) - s = cpio->entry_bytes_remaining; - - ret = (a->compressor.write)(a, buff, s); - cpio->entry_bytes_remaining -= s; - if (ret >= 0) - return (s); - else - return (ret); -} - -/* - * Format a number into the specified field. - */ -static int -format_hex(int64_t v, void *p, int digits) -{ - int64_t max; - int ret; - - max = (((int64_t)1) << (digits * 4)) - 1; - if (v >= 0 && v <= max) { - format_hex_recursive(v, (char *)p, digits); - ret = 0; - } else { - format_hex_recursive(max, (char *)p, digits); - ret = -1; - } - return (ret); -} - -static int64_t -format_hex_recursive(int64_t v, char *p, int s) -{ - if (s == 0) - return (v); - v = format_hex_recursive(v, p+1, s-1); - *p = "0123456789abcdef"[v & 0xf]; - return (v >> 4); -} - -static int -archive_write_newc_finish(struct archive_write *a) -{ - int er; - struct archive_entry *trailer; - - trailer = archive_entry_new(); - archive_entry_set_nlink(trailer, 1); - archive_entry_set_pathname(trailer, "TRAILER!!!"); - er = archive_write_newc_header(a, trailer); - archive_entry_free(trailer); - return (er); -} - -static int -archive_write_newc_destroy(struct archive_write *a) -{ - struct cpio *cpio; - - cpio = (struct cpio *)a->format_data; - free(cpio); - a->format_data = NULL; - return (ARCHIVE_OK); -} - -static int -archive_write_newc_finish_entry(struct archive_write *a) -{ - struct cpio *cpio; - size_t to_write; - int ret; - - cpio = (struct cpio *)a->format_data; - while (cpio->entry_bytes_remaining > 0) { - to_write = cpio->entry_bytes_remaining < a->null_length ? - cpio->entry_bytes_remaining : a->null_length; - ret = (a->compressor.write)(a, a->nulls, to_write); - if (ret != ARCHIVE_OK) - return (ret); - cpio->entry_bytes_remaining -= to_write; - } - ret = (a->compressor.write)(a, a->nulls, cpio->padding); - return (ret); -} diff --git a/lib/libarchive/archive_write_set_format_mtree.c b/lib/libarchive/archive_write_set_format_mtree.c deleted file mode 100644 index 1b46147..0000000 --- a/lib/libarchive/archive_write_set_format_mtree.c +++ /dev/null @@ -1,1050 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2008 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#include -#include -#include - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#include "archive_hash.h" - -#define INDENTNAMELEN 15 -#define MAXLINELEN 80 - -struct mtree_writer { - struct archive_entry *entry; - struct archive_string ebuf; - struct archive_string buf; - int first; - uint64_t entry_bytes_remaining; - struct { - int output; - int processed; - struct archive_string parent; - mode_t type; - int keys; - uid_t uid; - gid_t gid; - mode_t mode; - unsigned long fflags_set; - unsigned long fflags_clear; - } set; - /* chekc sum */ - int compute_sum; - uint32_t crc; - uint64_t crc_len; -#ifdef ARCHIVE_HAS_MD5 - archive_md5_ctx md5ctx; -#endif -#ifdef ARCHIVE_HAS_RMD160 - archive_rmd160_ctx rmd160ctx; -#endif -#ifdef ARCHIVE_HAS_SHA1 - archive_sha1_ctx sha1ctx; -#endif -#ifdef ARCHIVE_HAS_SHA256 - archive_sha256_ctx sha256ctx; -#endif -#ifdef ARCHIVE_HAS_SHA384 - archive_sha384_ctx sha384ctx; -#endif -#ifdef ARCHIVE_HAS_SHA512 - archive_sha512_ctx sha512ctx; -#endif - /* Keyword options */ - int keys; -#define F_CKSUM 0x00000001 /* check sum */ -#define F_DEV 0x00000002 /* device type */ -#define F_DONE 0x00000004 /* directory done */ -#define F_FLAGS 0x00000008 /* file flags */ -#define F_GID 0x00000010 /* gid */ -#define F_GNAME 0x00000020 /* group name */ -#define F_IGN 0x00000040 /* ignore */ -#define F_MAGIC 0x00000080 /* name has magic chars */ -#define F_MD5 0x00000100 /* MD5 digest */ -#define F_MODE 0x00000200 /* mode */ -#define F_NLINK 0x00000400 /* number of links */ -#define F_NOCHANGE 0x00000800 /* If owner/mode "wrong", do - * not change */ -#define F_OPT 0x00001000 /* existence optional */ -#define F_RMD160 0x00002000 /* RIPEMD160 digest */ -#define F_SHA1 0x00004000 /* SHA-1 digest */ -#define F_SIZE 0x00008000 /* size */ -#define F_SLINK 0x00010000 /* symbolic link */ -#define F_TAGS 0x00020000 /* tags */ -#define F_TIME 0x00040000 /* modification time */ -#define F_TYPE 0x00080000 /* file type */ -#define F_UID 0x00100000 /* uid */ -#define F_UNAME 0x00200000 /* user name */ -#define F_VISIT 0x00400000 /* file visited */ -#define F_SHA256 0x00800000 /* SHA-256 digest */ -#define F_SHA384 0x01000000 /* SHA-384 digest */ -#define F_SHA512 0x02000000 /* SHA-512 digest */ - - /* Options */ - int dironly; /* if the dironly is 1, ignore everything except - * directory type files. like mtree(8) -d option. - */ - int indent; /* if the indent is 1, indent writing data. */ -}; - -#define DEFAULT_KEYS (F_DEV | F_FLAGS | F_GID | F_GNAME | F_SLINK | F_MODE\ - | F_NLINK | F_SIZE | F_TIME | F_TYPE | F_UID\ - | F_UNAME) - -#define COMPUTE_CRC(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)] -static const uint32_t crctab[] = { - 0x0, - 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, - 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, - 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, - 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, - 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, - 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, - 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, - 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, - 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, - 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, - 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, - 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, - 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, - 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, - 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, - 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, - 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, - 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, - 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, - 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, - 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, - 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, - 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, - 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, - 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, - 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, - 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, - 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, - 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, - 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, - 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, - 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, - 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, - 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, - 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, - 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, - 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, - 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, - 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, - 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, - 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, - 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, - 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, - 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, - 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, - 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, - 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, - 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 -}; - -static int -mtree_safe_char(char c) -{ - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) - return 1; - if (c >= '0' && c <= '9') - return 1; - if (c == 35 || c == 61 || c == 92) - return 0; /* #, = and \ are always quoted */ - - if (c >= 33 && c <= 47) /* !"$%&'()*+,-./ */ - return 1; - if (c >= 58 && c <= 64) /* :;<>?@ */ - return 1; - if (c >= 91 && c <= 96) /* []^_` */ - return 1; - if (c >= 123 && c <= 126) /* {|}~ */ - return 1; - return 0; -} - -static void -mtree_quote(struct archive_string *s, const char *str) -{ - const char *start; - char buf[4]; - unsigned char c; - - for (start = str; *str != '\0'; ++str) { - if (mtree_safe_char(*str)) - continue; - if (start != str) - archive_strncat(s, start, str - start); - c = (unsigned char)*str; - buf[0] = '\\'; - buf[1] = (c / 64) + '0'; - buf[2] = (c / 8 % 8) + '0'; - buf[3] = (c % 8) + '0'; - archive_strncat(s, buf, 4); - start = str + 1; - } - - if (start != str) - archive_strncat(s, start, str - start); -} - -static void -mtree_indent(struct mtree_writer *mtree) -{ - int i, fn; - const char *r, *s, *x; - - fn = 1; - s = r = mtree->ebuf.s; - x = NULL; - while (*r == ' ') - r++; - while ((r = strchr(r, ' ')) != NULL) { - if (fn) { - fn = 0; - archive_strncat(&mtree->buf, s, r - s); - if (r -s > INDENTNAMELEN) { - archive_strncat(&mtree->buf, " \\\n", 3); - for (i = 0; i < (INDENTNAMELEN + 1); i++) - archive_strappend_char(&mtree->buf, ' '); - } else { - for (i = r -s; i < (INDENTNAMELEN + 1); i++) - archive_strappend_char(&mtree->buf, ' '); - } - s = ++r; - x = NULL; - continue; - } - if (r - s <= MAXLINELEN - 3 - INDENTNAMELEN) - x = r++; - else { - if (x == NULL) - x = r; - archive_strncat(&mtree->buf, s, x - s); - archive_strncat(&mtree->buf, " \\\n", 3); - for (i = 0; i < (INDENTNAMELEN + 1); i++) - archive_strappend_char(&mtree->buf, ' '); - s = r = ++x; - x = NULL; - } - } - if (x != NULL && strlen(s) > MAXLINELEN - 3 - INDENTNAMELEN) { - /* Last keyword is longer. */ - archive_strncat(&mtree->buf, s, x - s); - archive_strncat(&mtree->buf, " \\\n", 3); - for (i = 0; i < (INDENTNAMELEN + 1); i++) - archive_strappend_char(&mtree->buf, ' '); - s = ++x; - } - archive_strcat(&mtree->buf, s); - archive_string_empty(&mtree->ebuf); -} - -#if !defined(_WIN32) || defined(__CYGWIN__) -static size_t -dir_len(struct archive_entry *entry) -{ - const char *path, *r; - - path = archive_entry_pathname(entry); - r = strrchr(path, '/'); - if (r == NULL) - return (0); - /* Include a separator size */ - return (r - path + 1); -} - -#else /* _WIN32 && !__CYGWIN__ */ -/* - * Note: We should use wide-character for findng '\' character, - * a directory separator on Windows, because some character-set have - * been using the '\' character for a part of its multibyte character - * code. - */ -static size_t -dir_len(struct archive_entry *entry) -{ - wchar_t wc; - const char *path; - const char *p, *rp; - size_t al, l, size; - - path = archive_entry_pathname(entry); - al = l = -1; - for (p = path; *p != '\0'; ++p) { - if (*p == '\\') - al = l = p - path; - else if (*p == '/') - al = p - path; - } - if (l == -1) - goto alen; - size = p - path; - rp = p = path; - while (*p != '\0') { - l = mbtowc(&wc, p, size); - if (l == -1) - goto alen; - if (l == 1 && (wc == L'/' || wc == L'\\')) - rp = p; - p += l; - size -= l; - } - return (rp - path + 1); -alen: - if (al == -1) - return (0); - return (al + 1); -} -#endif /* _WIN32 && !__CYGWIN__ */ - -static int -parent_dir_changed(struct archive_string *dir, struct archive_entry *entry) -{ - const char *path; - size_t l; - - l = dir_len(entry); - path = archive_entry_pathname(entry); - if (archive_strlen(dir) > 0) { - if (l == 0) { - archive_string_empty(dir); - return (1); - } - if (strncmp(dir->s, path, l) == 0) - return (0); /* The parent directory is the same. */ - } else if (l == 0) - return (0); /* The parent directory is the same. */ - archive_strncpy(dir, path, l); - return (1); -} - -/* - * Write /set keyword. It means set global datas. - * [directory-only mode] - * - It is only once to write /set keyword. It is using values of the - * first entry. - * [normal mode] - * - Write /set keyword. It is using values of the first entry whose - * filetype is a regular file. - * - When a parent directory of the entry whose filetype is the regular - * file is changed, check the global datas and write it again if its - * values are different from the entry's. - */ -static void -set_global(struct mtree_writer *mtree, struct archive_entry *entry) -{ - struct archive_string setstr; - struct archive_string unsetstr; - const char *name; - int keys, oldkeys, effkeys; - mode_t set_type = 0; - - switch (archive_entry_filetype(entry)) { - case AE_IFLNK: case AE_IFSOCK: case AE_IFCHR: - case AE_IFBLK: case AE_IFIFO: - break; - case AE_IFDIR: - if (mtree->dironly) - set_type = AE_IFDIR; - break; - case AE_IFREG: - default: /* Handle unknown file types as regular files. */ - if (!mtree->dironly) - set_type = AE_IFREG; - break; - } - if (set_type == 0) - return; - if (mtree->set.processed && - !parent_dir_changed(&mtree->set.parent, entry)) - return; - /* At first, save a parent directory of the entry for following - * entries. */ - if (!mtree->set.processed && set_type == AE_IFREG) - parent_dir_changed(&mtree->set.parent, entry); - - archive_string_init(&setstr); - archive_string_init(&unsetstr); - keys = mtree->keys & (F_FLAGS | F_GID | F_GNAME | F_NLINK | F_MODE - | F_TYPE | F_UID | F_UNAME); - oldkeys = mtree->set.keys; - effkeys = keys; - if (mtree->set.processed) { - /* - * Check the global datas for whether it needs updating. - */ - effkeys &= ~F_TYPE; - if ((oldkeys & (F_UNAME | F_UID)) != 0 && - mtree->set.uid == archive_entry_uid(entry)) - effkeys &= ~(F_UNAME | F_UID); - if ((oldkeys & (F_GNAME | F_GID)) != 0 && - mtree->set.gid == archive_entry_gid(entry)) - effkeys &= ~(F_GNAME | F_GID); - if ((oldkeys & F_MODE) != 0 && - mtree->set.mode == (archive_entry_mode(entry) & 07777)) - effkeys &= ~F_MODE; - if ((oldkeys & F_FLAGS) != 0) { - unsigned long fflags_set; - unsigned long fflags_clear; - - archive_entry_fflags(entry, &fflags_set, &fflags_clear); - if (fflags_set == mtree->set.fflags_set && - fflags_clear == mtree->set.fflags_clear) - effkeys &= ~F_FLAGS; - } - } - if ((keys & effkeys & F_TYPE) != 0) { - mtree->set.type = set_type; - if (set_type == AE_IFDIR) - archive_strcat(&setstr, " type=dir"); - else - archive_strcat(&setstr, " type=file"); - } - if ((keys & effkeys & F_UNAME) != 0) { - if ((name = archive_entry_uname(entry)) != NULL) { - archive_strcat(&setstr, " uname="); - mtree_quote(&setstr, name); - } else if ((oldkeys & F_UNAME) != 0) - archive_strcat(&unsetstr, " uname"); - else - keys &= ~F_UNAME; - } - if ((keys & effkeys & F_UID) != 0) { - mtree->set.uid = archive_entry_uid(entry); - archive_string_sprintf(&setstr, " uid=%jd", - (intmax_t)mtree->set.uid); - } - if ((keys & effkeys & F_GNAME) != 0) { - if ((name = archive_entry_gname(entry)) != NULL) { - archive_strcat(&setstr, " gname="); - mtree_quote(&setstr, name); - } else if ((oldkeys & F_GNAME) != 0) - archive_strcat(&unsetstr, " gname"); - else - keys &= ~F_GNAME; - } - if ((keys & effkeys & F_GID) != 0) { - mtree->set.gid = archive_entry_gid(entry); - archive_string_sprintf(&setstr, " gid=%jd", - (intmax_t)mtree->set.gid); - } - if ((keys & effkeys & F_MODE) != 0) { - mtree->set.mode = archive_entry_mode(entry) & 07777; - archive_string_sprintf(&setstr, " mode=%o", mtree->set.mode); - } - if ((keys & effkeys & F_FLAGS) != 0) { - if ((name = archive_entry_fflags_text(entry)) != NULL) { - archive_strcat(&setstr, " flags="); - mtree_quote(&setstr, name); - archive_entry_fflags(entry, &mtree->set.fflags_set, - &mtree->set.fflags_clear); - } else if ((oldkeys & F_FLAGS) != 0) - archive_strcat(&unsetstr, " flags"); - else - keys &= ~F_FLAGS; - } - if (unsetstr.length > 0) - archive_string_sprintf(&mtree->buf, "/unset%s\n", unsetstr.s); - archive_string_free(&unsetstr); - if (setstr.length > 0) - archive_string_sprintf(&mtree->buf, "/set%s\n", setstr.s); - archive_string_free(&setstr); - mtree->set.keys = keys; - mtree->set.processed = 1; - /* On directory-only mode, it is only once to write /set keyword. */ - if (mtree->dironly) - mtree->set.output = 0; -} - -static int -get_keys(struct mtree_writer *mtree, struct archive_entry *entry) -{ - int keys; - - keys = mtree->keys; - if (mtree->set.keys == 0) - return (keys); - if ((mtree->set.keys & (F_GNAME | F_GID)) != 0 && - mtree->set.gid == archive_entry_gid(entry)) - keys &= ~(F_GNAME | F_GID); - if ((mtree->set.keys & (F_UNAME | F_UID)) != 0 && - mtree->set.uid == archive_entry_uid(entry)) - keys &= ~(F_UNAME | F_UID); - if (mtree->set.keys & F_FLAGS) { - unsigned long set, clear; - - archive_entry_fflags(entry, &set, &clear); - if (mtree->set.fflags_set == set && - mtree->set.fflags_clear == clear) - keys &= ~F_FLAGS; - } - if ((mtree->set.keys & F_MODE) != 0 && - mtree->set.mode == (archive_entry_mode(entry) & 07777)) - keys &= ~F_MODE; - - switch (archive_entry_filetype(entry)) { - case AE_IFLNK: case AE_IFSOCK: case AE_IFCHR: - case AE_IFBLK: case AE_IFIFO: - break; - case AE_IFDIR: - if ((mtree->set.keys & F_TYPE) != 0 && - mtree->set.type == AE_IFDIR) - keys &= ~F_TYPE; - break; - case AE_IFREG: - default: /* Handle unknown file types as regular files. */ - if ((mtree->set.keys & F_TYPE) != 0 && - mtree->set.type == AE_IFREG) - keys &= ~F_TYPE; - break; - } - - return (keys); -} - -static int -archive_write_mtree_header(struct archive_write *a, - struct archive_entry *entry) -{ - struct mtree_writer *mtree= a->format_data; - struct archive_string *str; - const char *path; - - mtree->entry = archive_entry_clone(entry); - path = archive_entry_pathname(mtree->entry); - - if (mtree->first) { - mtree->first = 0; - archive_strcat(&mtree->buf, "#mtree\n"); - } - if (mtree->set.output) - set_global(mtree, entry); - - archive_string_empty(&mtree->ebuf); - str = (mtree->indent)? &mtree->ebuf : &mtree->buf; - if (!mtree->dironly || archive_entry_filetype(entry) == AE_IFDIR) - mtree_quote(str, path); - - mtree->entry_bytes_remaining = archive_entry_size(entry); - if ((mtree->keys & F_CKSUM) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_CKSUM; - mtree->crc = 0; - mtree->crc_len = 0; - } else - mtree->compute_sum &= ~F_CKSUM; -#ifdef ARCHIVE_HAS_MD5 - if ((mtree->keys & F_MD5) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_MD5; - archive_md5_init(&mtree->md5ctx); - } else - mtree->compute_sum &= ~F_MD5; -#endif -#ifdef ARCHIVE_HAS_RMD160 - if ((mtree->keys & F_RMD160) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_RMD160; - archive_rmd160_init(&mtree->rmd160ctx); - } else - mtree->compute_sum &= ~F_RMD160; -#endif -#ifdef ARCHIVE_HAS_SHA1 - if ((mtree->keys & F_SHA1) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_SHA1; - archive_sha1_init(&mtree->sha1ctx); - } else - mtree->compute_sum &= ~F_SHA1; -#endif -#ifdef ARCHIVE_HAS_SHA256 - if ((mtree->keys & F_SHA256) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_SHA256; - archive_sha256_init(&mtree->sha256ctx); - } else - mtree->compute_sum &= ~F_SHA256; -#endif -#ifdef ARCHIVE_HAS_SHA384 - if ((mtree->keys & F_SHA384) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_SHA384; - archive_sha384_init(&mtree->sha384ctx); - } else - mtree->compute_sum &= ~F_SHA384; -#endif -#ifdef ARCHIVE_HAS_SHA512 - if ((mtree->keys & F_SHA512) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_SHA512; - archive_sha512_init(&mtree->sha512ctx); - } else - mtree->compute_sum &= ~F_SHA512; -#endif - - return (ARCHIVE_OK); -} - -#if defined(ARCHIVE_HAS_MD5) || defined(ARCHIVE_HAS_RMD160) || \ - defined(ARCHIVE_HAS_SHA1) || defined(ARCHIVE_HAS_SHA256) || \ - defined(ARCHIVE_HAS_SHA384) || defined(ARCHIVE_HAS_SHA512) -static void -strappend_bin(struct archive_string *s, const unsigned char *bin, int n) -{ - static const char hex[] = "0123456789abcdef"; - int i; - - for (i = 0; i < n; i++) { - archive_strappend_char(s, hex[bin[i] >> 4]); - archive_strappend_char(s, hex[bin[i] & 0x0f]); - } -} -#endif - -static int -archive_write_mtree_finish_entry(struct archive_write *a) -{ - struct mtree_writer *mtree = a->format_data; - struct archive_entry *entry; - struct archive_string *str; - const char *name; - int keys, ret; - - entry = mtree->entry; - if (entry == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "Finished entry without being open first."); - return (ARCHIVE_FATAL); - } - mtree->entry = NULL; - - if (mtree->dironly && archive_entry_filetype(entry) != AE_IFDIR) { - archive_entry_free(entry); - return (ARCHIVE_OK); - } - - str = (mtree->indent)? &mtree->ebuf : &mtree->buf; - keys = get_keys(mtree, entry); - if ((keys & F_NLINK) != 0 && - archive_entry_nlink(entry) != 1 && - archive_entry_filetype(entry) != AE_IFDIR) - archive_string_sprintf(str, - " nlink=%u", archive_entry_nlink(entry)); - - if ((keys & F_GNAME) != 0 && - (name = archive_entry_gname(entry)) != NULL) { - archive_strcat(str, " gname="); - mtree_quote(str, name); - } - if ((keys & F_UNAME) != 0 && - (name = archive_entry_uname(entry)) != NULL) { - archive_strcat(str, " uname="); - mtree_quote(str, name); - } - if ((keys & F_FLAGS) != 0 && - (name = archive_entry_fflags_text(entry)) != NULL) { - archive_strcat(str, " flags="); - mtree_quote(str, name); - } - if ((keys & F_TIME) != 0) - archive_string_sprintf(str, " time=%jd.%jd", - (intmax_t)archive_entry_mtime(entry), - (intmax_t)archive_entry_mtime_nsec(entry)); - if ((keys & F_MODE) != 0) - archive_string_sprintf(str, " mode=%o", - archive_entry_mode(entry) & 07777); - if ((keys & F_GID) != 0) - archive_string_sprintf(str, " gid=%jd", - (intmax_t)archive_entry_gid(entry)); - if ((keys & F_UID) != 0) - archive_string_sprintf(str, " uid=%jd", - (intmax_t)archive_entry_uid(entry)); - - switch (archive_entry_filetype(entry)) { - case AE_IFLNK: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=link"); - if ((keys & F_SLINK) != 0) { - archive_strcat(str, " link="); - mtree_quote(str, archive_entry_symlink(entry)); - } - break; - case AE_IFSOCK: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=socket"); - break; - case AE_IFCHR: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=char"); - if ((keys & F_DEV) != 0) { - archive_string_sprintf(str, - " device=native,%d,%d", - archive_entry_rdevmajor(entry), - archive_entry_rdevminor(entry)); - } - break; - case AE_IFBLK: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=block"); - if ((keys & F_DEV) != 0) { - archive_string_sprintf(str, - " device=native,%d,%d", - archive_entry_rdevmajor(entry), - archive_entry_rdevminor(entry)); - } - break; - case AE_IFDIR: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=dir"); - break; - case AE_IFIFO: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=fifo"); - break; - case AE_IFREG: - default: /* Handle unknown file types as regular files. */ - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=file"); - if ((keys & F_SIZE) != 0) - archive_string_sprintf(str, " size=%jd", - (intmax_t)archive_entry_size(entry)); - break; - } - - if (mtree->compute_sum & F_CKSUM) { - uint64_t len; - /* Include the length of the file. */ - for (len = mtree->crc_len; len != 0; len >>= 8) - COMPUTE_CRC(mtree->crc, len & 0xff); - mtree->crc = ~mtree->crc; - archive_string_sprintf(str, " cksum=%ju", - (uintmax_t)mtree->crc); - } -#ifdef ARCHIVE_HAS_MD5 - if (mtree->compute_sum & F_MD5) { - unsigned char buf[16]; - - archive_md5_final(&mtree->md5ctx, buf); - archive_strcat(str, " md5digest="); - strappend_bin(str, buf, sizeof(buf)); - } -#endif -#ifdef ARCHIVE_HAS_RMD160 - if (mtree->compute_sum & F_RMD160) { - unsigned char buf[20]; - - archive_rmd160_final(&mtree->rmd160ctx, buf); - archive_strcat(str, " rmd160digest="); - strappend_bin(str, buf, sizeof(buf)); - } -#endif -#ifdef ARCHIVE_HAS_SHA1 - if (mtree->compute_sum & F_SHA1) { - unsigned char buf[20]; - - archive_sha1_final(&mtree->sha1ctx, buf); - archive_strcat(str, " sha1digest="); - strappend_bin(str, buf, sizeof(buf)); - } -#endif -#ifdef ARCHIVE_HAS_SHA256 - if (mtree->compute_sum & F_SHA256) { - unsigned char buf[32]; - - archive_sha256_final(&mtree->sha256ctx, buf); - archive_strcat(str, " sha256digest="); - strappend_bin(str, buf, sizeof(buf)); - } -#endif -#ifdef ARCHIVE_HAS_SHA384 - if (mtree->compute_sum & F_SHA384) { - unsigned char buf[48]; - - archive_sha384_final(&mtree->sha384ctx, buf); - archive_strcat(str, " sha384digest="); - strappend_bin(str, buf, sizeof(buf)); - } -#endif -#ifdef ARCHIVE_HAS_SHA512 - if (mtree->compute_sum & F_SHA512) { - unsigned char buf[64]; - - archive_sha512_final(&mtree->sha512ctx, buf); - archive_strcat(str, " sha512digest="); - strappend_bin(str, buf, sizeof(buf)); - } -#endif - archive_strcat(str, "\n"); - if (mtree->indent) - mtree_indent(mtree); - - archive_entry_free(entry); - - if (mtree->buf.length > 32768) { - ret = (a->compressor.write)(a, mtree->buf.s, mtree->buf.length); - archive_string_empty(&mtree->buf); - } else - ret = ARCHIVE_OK; - - return (ret == ARCHIVE_OK ? ret : ARCHIVE_FATAL); -} - -static int -archive_write_mtree_finish(struct archive_write *a) -{ - struct mtree_writer *mtree= a->format_data; - - archive_write_set_bytes_in_last_block(&a->archive, 1); - - return (a->compressor.write)(a, mtree->buf.s, mtree->buf.length); -} - -static ssize_t -archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n) -{ - struct mtree_writer *mtree= a->format_data; - - if (n > mtree->entry_bytes_remaining) - n = mtree->entry_bytes_remaining; - if (mtree->dironly) - /* We don't need compute a regular file sum */ - return (n); - if (mtree->compute_sum & F_CKSUM) { - /* - * Compute a POSIX 1003.2 checksum - */ - const unsigned char *p; - size_t nn; - - for (nn = n, p = buff; nn--; ++p) - COMPUTE_CRC(mtree->crc, *p); - mtree->crc_len += n; - } -#ifdef ARCHIVE_HAS_MD5 - if (mtree->compute_sum & F_MD5) - archive_md5_update(&mtree->md5ctx, buff, n); -#endif -#ifdef ARCHIVE_HAS_RMD160 - if (mtree->compute_sum & F_RMD160) - archive_rmd160_update(&mtree->rmd160ctx, buff, n); -#endif -#ifdef ARCHIVE_HAS_SHA1 - if (mtree->compute_sum & F_SHA1) - archive_sha1_update(&mtree->sha1ctx, buff, n); -#endif -#ifdef ARCHIVE_HAS_SHA256 - if (mtree->compute_sum & F_SHA256) - archive_sha256_update(&mtree->sha256ctx, buff, n); -#endif -#ifdef ARCHIVE_HAS_SHA384 - if (mtree->compute_sum & F_SHA384) - archive_sha384_update(&mtree->sha384ctx, buff, n); -#endif -#ifdef ARCHIVE_HAS_SHA512 - if (mtree->compute_sum & F_SHA512) - archive_sha512_update(&mtree->sha512ctx, buff, n); -#endif - return (n); -} - -static int -archive_write_mtree_destroy(struct archive_write *a) -{ - struct mtree_writer *mtree= a->format_data; - - if (mtree == NULL) - return (ARCHIVE_OK); - - archive_entry_free(mtree->entry); - archive_string_free(&mtree->ebuf); - archive_string_free(&mtree->buf); - archive_string_free(&mtree->set.parent); - free(mtree); - a->format_data = NULL; - return (ARCHIVE_OK); -} - -static int -archive_write_mtree_options(struct archive_write *a, const char *key, - const char *value) -{ - struct mtree_writer *mtree= a->format_data; - int keybit = 0; - - switch (key[0]) { - case 'a': - if (strcmp(key, "all") == 0) - keybit = ~0; - break; - case 'c': - if (strcmp(key, "cksum") == 0) - keybit = F_CKSUM; - break; - case 'd': - if (strcmp(key, "device") == 0) - keybit = F_DEV; - else if (strcmp(key, "dironly") == 0) { - mtree->dironly = (value != NULL)? 1: 0; - return (ARCHIVE_OK); - } - break; - case 'f': - if (strcmp(key, "flags") == 0) - keybit = F_FLAGS; - break; - case 'g': - if (strcmp(key, "gid") == 0) - keybit = F_GID; - else if (strcmp(key, "gname") == 0) - keybit = F_GNAME; - break; - case 'i': - if (strcmp(key, "indent") == 0) { - mtree->indent = (value != NULL)? 1: 0; - return (ARCHIVE_OK); - } - break; - case 'l': - if (strcmp(key, "link") == 0) - keybit = F_SLINK; - break; - case 'm': - if (strcmp(key, "md5") == 0 || - strcmp(key, "md5digest") == 0) - keybit = F_MD5; - if (strcmp(key, "mode") == 0) - keybit = F_MODE; - break; - case 'n': - if (strcmp(key, "nlink") == 0) - keybit = F_NLINK; - break; - case 'r': - if (strcmp(key, "ripemd160digest") == 0 || - strcmp(key, "rmd160") == 0 || - strcmp(key, "rmd160digest") == 0) - keybit = F_RMD160; - break; - case 's': - if (strcmp(key, "sha1") == 0 || - strcmp(key, "sha1digest") == 0) - keybit = F_SHA1; - if (strcmp(key, "sha256") == 0 || - strcmp(key, "sha256digest") == 0) - keybit = F_SHA256; - if (strcmp(key, "sha384") == 0 || - strcmp(key, "sha384digest") == 0) - keybit = F_SHA384; - if (strcmp(key, "sha512") == 0 || - strcmp(key, "sha512digest") == 0) - keybit = F_SHA512; - if (strcmp(key, "size") == 0) - keybit = F_SIZE; - break; - case 't': - if (strcmp(key, "time") == 0) - keybit = F_TIME; - else if (strcmp(key, "type") == 0) - keybit = F_TYPE; - break; - case 'u': - if (strcmp(key, "uid") == 0) - keybit = F_UID; - else if (strcmp(key, "uname") == 0) - keybit = F_UNAME; - else if (strcmp(key, "use-set") == 0) { - mtree->set.output = (value != NULL)? 1: 0; - return (ARCHIVE_OK); - } - break; - } - if (keybit != 0) { - if (value != NULL) - mtree->keys |= keybit; - else - mtree->keys &= ~keybit; - return (ARCHIVE_OK); - } - - return (ARCHIVE_WARN); -} - -int -archive_write_set_format_mtree(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct mtree_writer *mtree; - - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - if ((mtree = malloc(sizeof(*mtree))) == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate mtree data"); - return (ARCHIVE_FATAL); - } - - mtree->entry = NULL; - mtree->first = 1; - memset(&(mtree->set), 0, sizeof(mtree->set)); - archive_string_init(&mtree->set.parent); - mtree->keys = DEFAULT_KEYS; - mtree->dironly = 0; - mtree->indent = 0; - archive_string_init(&mtree->ebuf); - archive_string_init(&mtree->buf); - a->format_data = mtree; - a->format_destroy = archive_write_mtree_destroy; - - a->pad_uncompressed = 0; - a->format_name = "mtree"; - a->format_options = archive_write_mtree_options; - a->format_write_header = archive_write_mtree_header; - a->format_finish = archive_write_mtree_finish; - a->format_write_data = archive_write_mtree_data; - a->format_finish_entry = archive_write_mtree_finish_entry; - a->archive.archive_format = ARCHIVE_FORMAT_MTREE; - a->archive.archive_format_name = "mtree"; - - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_write_set_format_pax.c b/lib/libarchive/archive_write_set_format_pax.c deleted file mode 100644 index 2929179..0000000 --- a/lib/libarchive/archive_write_set_format_pax.c +++ /dev/null @@ -1,1386 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_write_private.h" - -struct pax { - uint64_t entry_bytes_remaining; - uint64_t entry_padding; - struct archive_string pax_header; -}; - -static void add_pax_attr(struct archive_string *, const char *key, - const char *value); -static void add_pax_attr_int(struct archive_string *, - const char *key, int64_t value); -static void add_pax_attr_time(struct archive_string *, - const char *key, int64_t sec, - unsigned long nanos); -static void add_pax_attr_w(struct archive_string *, - const char *key, const wchar_t *wvalue); -static ssize_t archive_write_pax_data(struct archive_write *, - const void *, size_t); -static int archive_write_pax_finish(struct archive_write *); -static int archive_write_pax_destroy(struct archive_write *); -static int archive_write_pax_finish_entry(struct archive_write *); -static int archive_write_pax_header(struct archive_write *, - struct archive_entry *); -static char *base64_encode(const char *src, size_t len); -static char *build_pax_attribute_name(char *dest, const char *src); -static char *build_ustar_entry_name(char *dest, const char *src, - size_t src_length, const char *insert); -static char *format_int(char *dest, int64_t); -static int has_non_ASCII(const wchar_t *); -static char *url_encode(const char *in); -static int write_nulls(struct archive_write *, size_t); - -/* - * Set output format to 'restricted pax' format. - * - * This is the same as normal 'pax', but tries to suppress - * the pax header whenever possible. This is the default for - * bsdtar, for instance. - */ -int -archive_write_set_format_pax_restricted(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - int r; - r = archive_write_set_format_pax(&a->archive); - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; - a->archive.archive_format_name = "restricted POSIX pax interchange"; - return (r); -} - -/* - * Set output format to 'pax' format. - */ -int -archive_write_set_format_pax(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct pax *pax; - - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - pax = (struct pax *)malloc(sizeof(*pax)); - if (pax == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate pax data"); - return (ARCHIVE_FATAL); - } - memset(pax, 0, sizeof(*pax)); - a->format_data = pax; - - a->pad_uncompressed = 1; - a->format_name = "pax"; - a->format_write_header = archive_write_pax_header; - a->format_write_data = archive_write_pax_data; - a->format_finish = archive_write_pax_finish; - a->format_destroy = archive_write_pax_destroy; - a->format_finish_entry = archive_write_pax_finish_entry; - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = "POSIX pax interchange"; - return (ARCHIVE_OK); -} - -/* - * Note: This code assumes that 'nanos' has the same sign as 'sec', - * which implies that sec=-1, nanos=200000000 represents -1.2 seconds - * and not -0.8 seconds. This is a pretty pedantic point, as we're - * unlikely to encounter many real files created before Jan 1, 1970, - * much less ones with timestamps recorded to sub-second resolution. - */ -static void -add_pax_attr_time(struct archive_string *as, const char *key, - int64_t sec, unsigned long nanos) -{ - int digit, i; - char *t; - /* - * Note that each byte contributes fewer than 3 base-10 - * digits, so this will always be big enough. - */ - char tmp[1 + 3*sizeof(sec) + 1 + 3*sizeof(nanos)]; - - tmp[sizeof(tmp) - 1] = 0; - t = tmp + sizeof(tmp) - 1; - - /* Skip trailing zeros in the fractional part. */ - for (digit = 0, i = 10; i > 0 && digit == 0; i--) { - digit = nanos % 10; - nanos /= 10; - } - - /* Only format the fraction if it's non-zero. */ - if (i > 0) { - while (i > 0) { - *--t = "0123456789"[digit]; - digit = nanos % 10; - nanos /= 10; - i--; - } - *--t = '.'; - } - t = format_int(t, sec); - - add_pax_attr(as, key, t); -} - -static char * -format_int(char *t, int64_t i) -{ - int sign; - - if (i < 0) { - sign = -1; - i = -i; - } else - sign = 1; - - do { - *--t = "0123456789"[i % 10]; - } while (i /= 10); - if (sign < 0) - *--t = '-'; - return (t); -} - -static void -add_pax_attr_int(struct archive_string *as, const char *key, int64_t value) -{ - char tmp[1 + 3 * sizeof(value)]; - - tmp[sizeof(tmp) - 1] = 0; - add_pax_attr(as, key, format_int(tmp + sizeof(tmp) - 1, value)); -} - -static char * -utf8_encode(const wchar_t *wval) -{ - int utf8len; - const wchar_t *wp; - unsigned long wc; - char *utf8_value, *p; - - utf8len = 0; - for (wp = wval; *wp != L'\0'; ) { - wc = *wp++; - - if (wc >= 0xd800 && wc <= 0xdbff - && *wp >= 0xdc00 && *wp <= 0xdfff) { - /* This is a surrogate pair. Combine into a - * full Unicode value before encoding into - * UTF-8. */ - wc = (wc - 0xd800) << 10; /* High 10 bits */ - wc += (*wp++ - 0xdc00); /* Low 10 bits */ - wc += 0x10000; /* Skip BMP */ - } - if (wc <= 0x7f) - utf8len++; - else if (wc <= 0x7ff) - utf8len += 2; - else if (wc <= 0xffff) - utf8len += 3; - else if (wc <= 0x1fffff) - utf8len += 4; - else if (wc <= 0x3ffffff) - utf8len += 5; - else if (wc <= 0x7fffffff) - utf8len += 6; - /* Ignore larger values; UTF-8 can't encode them. */ - } - - utf8_value = (char *)malloc(utf8len + 1); - if (utf8_value == NULL) { - __archive_errx(1, "Not enough memory for attributes"); - return (NULL); - } - - for (wp = wval, p = utf8_value; *wp != L'\0'; ) { - wc = *wp++; - if (wc >= 0xd800 && wc <= 0xdbff - && *wp >= 0xdc00 && *wp <= 0xdfff) { - /* Combine surrogate pair. */ - wc = (wc - 0xd800) << 10; - wc += *wp++ - 0xdc00 + 0x10000; - } - if (wc <= 0x7f) { - *p++ = (char)wc; - } else if (wc <= 0x7ff) { - p[0] = 0xc0 | ((wc >> 6) & 0x1f); - p[1] = 0x80 | (wc & 0x3f); - p += 2; - } else if (wc <= 0xffff) { - p[0] = 0xe0 | ((wc >> 12) & 0x0f); - p[1] = 0x80 | ((wc >> 6) & 0x3f); - p[2] = 0x80 | (wc & 0x3f); - p += 3; - } else if (wc <= 0x1fffff) { - p[0] = 0xf0 | ((wc >> 18) & 0x07); - p[1] = 0x80 | ((wc >> 12) & 0x3f); - p[2] = 0x80 | ((wc >> 6) & 0x3f); - p[3] = 0x80 | (wc & 0x3f); - p += 4; - } else if (wc <= 0x3ffffff) { - p[0] = 0xf8 | ((wc >> 24) & 0x03); - p[1] = 0x80 | ((wc >> 18) & 0x3f); - p[2] = 0x80 | ((wc >> 12) & 0x3f); - p[3] = 0x80 | ((wc >> 6) & 0x3f); - p[4] = 0x80 | (wc & 0x3f); - p += 5; - } else if (wc <= 0x7fffffff) { - p[0] = 0xfc | ((wc >> 30) & 0x01); - p[1] = 0x80 | ((wc >> 24) & 0x3f); - p[1] = 0x80 | ((wc >> 18) & 0x3f); - p[2] = 0x80 | ((wc >> 12) & 0x3f); - p[3] = 0x80 | ((wc >> 6) & 0x3f); - p[4] = 0x80 | (wc & 0x3f); - p += 6; - } - /* Ignore larger values; UTF-8 can't encode them. */ - } - *p = '\0'; - - return (utf8_value); -} - -static void -add_pax_attr_w(struct archive_string *as, const char *key, const wchar_t *wval) -{ - char *utf8_value = utf8_encode(wval); - if (utf8_value == NULL) - return; - add_pax_attr(as, key, utf8_value); - free(utf8_value); -} - -/* - * Add a key/value attribute to the pax header. This function handles - * the length field and various other syntactic requirements. - */ -static void -add_pax_attr(struct archive_string *as, const char *key, const char *value) -{ - int digits, i, len, next_ten; - char tmp[1 + 3 * sizeof(int)]; /* < 3 base-10 digits per byte */ - - /*- - * PAX attributes have the following layout: - * <=> - */ - len = 1 + (int)strlen(key) + 1 + (int)strlen(value) + 1; - - /* - * The field includes the length of the field, so - * computing the correct length is tricky. I start by - * counting the number of base-10 digits in 'len' and - * computing the next higher power of 10. - */ - next_ten = 1; - digits = 0; - i = len; - while (i > 0) { - i = i / 10; - digits++; - next_ten = next_ten * 10; - } - /* - * For example, if string without the length field is 99 - * chars, then adding the 2 digit length "99" will force the - * total length past 100, requiring an extra digit. The next - * statement adjusts for this effect. - */ - if (len + digits >= next_ten) - digits++; - - /* Now, we have the right length so we can build the line. */ - tmp[sizeof(tmp) - 1] = 0; /* Null-terminate the work area. */ - archive_strcat(as, format_int(tmp + sizeof(tmp) - 1, len + digits)); - archive_strappend_char(as, ' '); - archive_strcat(as, key); - archive_strappend_char(as, '='); - archive_strcat(as, value); - archive_strappend_char(as, '\n'); -} - -static void -archive_write_pax_header_xattrs(struct pax *pax, struct archive_entry *entry) -{ - struct archive_string s; - int i = archive_entry_xattr_reset(entry); - - while (i--) { - const char *name; - const void *value; - char *encoded_value; - char *url_encoded_name = NULL, *encoded_name = NULL; - wchar_t *wcs_name = NULL; - size_t size; - - archive_entry_xattr_next(entry, &name, &value, &size); - /* Name is URL-encoded, then converted to wchar_t, - * then UTF-8 encoded. */ - url_encoded_name = url_encode(name); - if (url_encoded_name != NULL) { - /* Convert narrow-character to wide-character. */ - size_t wcs_length = strlen(url_encoded_name); - wcs_name = (wchar_t *)malloc((wcs_length + 1) * sizeof(wchar_t)); - if (wcs_name == NULL) - __archive_errx(1, "No memory for xattr conversion"); - mbstowcs(wcs_name, url_encoded_name, wcs_length); - wcs_name[wcs_length] = 0; - free(url_encoded_name); /* Done with this. */ - } - if (wcs_name != NULL) { - encoded_name = utf8_encode(wcs_name); - free(wcs_name); /* Done with wchar_t name. */ - } - - encoded_value = base64_encode((const char *)value, size); - - if (encoded_name != NULL && encoded_value != NULL) { - archive_string_init(&s); - archive_strcpy(&s, "LIBARCHIVE.xattr."); - archive_strcat(&s, encoded_name); - add_pax_attr(&(pax->pax_header), s.s, encoded_value); - archive_string_free(&s); - } - free(encoded_name); - free(encoded_value); - } -} - -/* - * TODO: Consider adding 'comment' and 'charset' fields to - * archive_entry so that clients can specify them. Also, consider - * adding generic key/value tags so clients can add arbitrary - * key/value data. - */ -static int -archive_write_pax_header(struct archive_write *a, - struct archive_entry *entry_original) -{ - struct archive_entry *entry_main; - const char *p; - char *t; - const wchar_t *wp; - const char *suffix; - int need_extension, r, ret; - struct pax *pax; - const char *hdrcharset = NULL; - const char *hardlink; - const char *path = NULL, *linkpath = NULL; - const char *uname = NULL, *gname = NULL; - const wchar_t *path_w = NULL, *linkpath_w = NULL; - const wchar_t *uname_w = NULL, *gname_w = NULL; - - char paxbuff[512]; - char ustarbuff[512]; - char ustar_entry_name[256]; - char pax_entry_name[256]; - - ret = ARCHIVE_OK; - need_extension = 0; - pax = (struct pax *)a->format_data; - - hardlink = archive_entry_hardlink(entry_original); - - /* Make sure this is a type of entry that we can handle here */ - if (hardlink == NULL) { - switch (archive_entry_filetype(entry_original)) { - case AE_IFBLK: - case AE_IFCHR: - case AE_IFIFO: - case AE_IFLNK: - case AE_IFREG: - break; - case AE_IFDIR: - /* - * Ensure a trailing '/'. Modify the original - * entry so the client sees the change. - */ - p = archive_entry_pathname(entry_original); - if (p[strlen(p) - 1] != '/') { - t = (char *)malloc(strlen(p) + 2); - if (t == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate pax data"); - return(ARCHIVE_FATAL); - } - strcpy(t, p); - strcat(t, "/"); - archive_entry_copy_pathname(entry_original, t); - free(t); - } - break; - case AE_IFSOCK: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "tar format cannot archive socket"); - return (ARCHIVE_WARN); - default: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "tar format cannot archive this (type=0%lo)", - (unsigned long)archive_entry_filetype(entry_original)); - return (ARCHIVE_WARN); - } - } - - /* Copy entry so we can modify it as needed. */ - entry_main = archive_entry_clone(entry_original); - archive_string_empty(&(pax->pax_header)); /* Blank our work area. */ - - /* - * First, check the name fields and see if any of them - * require binary coding. If any of them does, then all of - * them do. - */ - hdrcharset = NULL; - path = archive_entry_pathname(entry_main); - path_w = archive_entry_pathname_w(entry_main); - if (path != NULL && path_w == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't translate pathname '%s' to UTF-8", path); - ret = ARCHIVE_WARN; - hdrcharset = "BINARY"; - } - uname = archive_entry_uname(entry_main); - uname_w = archive_entry_uname_w(entry_main); - if (uname != NULL && uname_w == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't translate uname '%s' to UTF-8", uname); - ret = ARCHIVE_WARN; - hdrcharset = "BINARY"; - } - gname = archive_entry_gname(entry_main); - gname_w = archive_entry_gname_w(entry_main); - if (gname != NULL && gname_w == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't translate gname '%s' to UTF-8", gname); - ret = ARCHIVE_WARN; - hdrcharset = "BINARY"; - } - linkpath = hardlink; - if (linkpath != NULL) { - linkpath_w = archive_entry_hardlink_w(entry_main); - } else { - linkpath = archive_entry_symlink(entry_main); - if (linkpath != NULL) - linkpath_w = archive_entry_symlink_w(entry_main); - } - if (linkpath != NULL && linkpath_w == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't translate linkpath '%s' to UTF-8", linkpath); - ret = ARCHIVE_WARN; - hdrcharset = "BINARY"; - } - - /* Store the header encoding first, to be nice to readers. */ - if (hdrcharset != NULL) - add_pax_attr(&(pax->pax_header), "hdrcharset", hdrcharset); - - - /* - * If name is too long, or has non-ASCII characters, add - * 'path' to pax extended attrs. (Note that an unconvertible - * name must have non-ASCII characters.) - */ - if (path == NULL) { - /* We don't have a narrow version, so we have to store - * the wide version. */ - add_pax_attr_w(&(pax->pax_header), "path", path_w); - archive_entry_set_pathname(entry_main, "@WidePath"); - need_extension = 1; - } else if (has_non_ASCII(path_w)) { - /* We have non-ASCII characters. */ - if (path_w == NULL || hdrcharset != NULL) { - /* Can't do UTF-8, so store it raw. */ - add_pax_attr(&(pax->pax_header), "path", path); - } else { - /* Store UTF-8 */ - add_pax_attr_w(&(pax->pax_header), - "path", path_w); - } - archive_entry_set_pathname(entry_main, - build_ustar_entry_name(ustar_entry_name, - path, strlen(path), NULL)); - need_extension = 1; - } else { - /* We have an all-ASCII path; we'd like to just store - * it in the ustar header if it will fit. Yes, this - * duplicates some of the logic in - * write_set_format_ustar.c - */ - if (strlen(path) <= 100) { - /* Fits in the old 100-char tar name field. */ - } else { - /* Find largest suffix that will fit. */ - /* Note: strlen() > 100, so strlen() - 100 - 1 >= 0 */ - suffix = strchr(path + strlen(path) - 100 - 1, '/'); - /* Don't attempt an empty prefix. */ - if (suffix == path) - suffix = strchr(suffix + 1, '/'); - /* We can put it in the ustar header if it's - * all ASCII and it's either <= 100 characters - * or can be split at a '/' into a prefix <= - * 155 chars and a suffix <= 100 chars. (Note - * the strchr() above will return NULL exactly - * when the path can't be split.) - */ - if (suffix == NULL /* Suffix > 100 chars. */ - || suffix[1] == '\0' /* empty suffix */ - || suffix - path > 155) /* Prefix > 155 chars */ - { - if (path_w == NULL || hdrcharset != NULL) { - /* Can't do UTF-8, so store it raw. */ - add_pax_attr(&(pax->pax_header), - "path", path); - } else { - /* Store UTF-8 */ - add_pax_attr_w(&(pax->pax_header), - "path", path_w); - } - archive_entry_set_pathname(entry_main, - build_ustar_entry_name(ustar_entry_name, - path, strlen(path), NULL)); - need_extension = 1; - } - } - } - - if (linkpath != NULL) { - /* If link name is too long or has non-ASCII characters, add - * 'linkpath' to pax extended attrs. */ - if (strlen(linkpath) > 100 || linkpath_w == NULL - || linkpath_w == NULL || has_non_ASCII(linkpath_w)) { - if (linkpath_w == NULL || hdrcharset != NULL) - /* If the linkpath is not convertible - * to wide, or we're encoding in - * binary anyway, store it raw. */ - add_pax_attr(&(pax->pax_header), - "linkpath", linkpath); - else - /* If the link is long or has a - * non-ASCII character, store it as a - * pax extended attribute. */ - add_pax_attr_w(&(pax->pax_header), - "linkpath", linkpath_w); - if (strlen(linkpath) > 100) { - if (hardlink != NULL) - archive_entry_set_hardlink(entry_main, - "././@LongHardLink"); - else - archive_entry_set_symlink(entry_main, - "././@LongSymLink"); - } - need_extension = 1; - } - } - - /* If file size is too large, add 'size' to pax extended attrs. */ - if (archive_entry_size(entry_main) >= (((int64_t)1) << 33)) { - add_pax_attr_int(&(pax->pax_header), "size", - archive_entry_size(entry_main)); - need_extension = 1; - } - - /* If numeric GID is too large, add 'gid' to pax extended attrs. */ - if ((unsigned int)archive_entry_gid(entry_main) >= (1 << 18)) { - add_pax_attr_int(&(pax->pax_header), "gid", - archive_entry_gid(entry_main)); - need_extension = 1; - } - - /* If group name is too large or has non-ASCII characters, add - * 'gname' to pax extended attrs. */ - if (gname != NULL) { - if (strlen(gname) > 31 - || gname_w == NULL - || has_non_ASCII(gname_w)) - { - if (gname_w == NULL || hdrcharset != NULL) { - add_pax_attr(&(pax->pax_header), - "gname", gname); - } else { - add_pax_attr_w(&(pax->pax_header), - "gname", gname_w); - } - need_extension = 1; - } - } - - /* If numeric UID is too large, add 'uid' to pax extended attrs. */ - if ((unsigned int)archive_entry_uid(entry_main) >= (1 << 18)) { - add_pax_attr_int(&(pax->pax_header), "uid", - archive_entry_uid(entry_main)); - need_extension = 1; - } - - /* Add 'uname' to pax extended attrs if necessary. */ - if (uname != NULL) { - if (strlen(uname) > 31 - || uname_w == NULL - || has_non_ASCII(uname_w)) - { - if (uname_w == NULL || hdrcharset != NULL) { - add_pax_attr(&(pax->pax_header), - "uname", uname); - } else { - add_pax_attr_w(&(pax->pax_header), - "uname", uname_w); - } - need_extension = 1; - } - } - - /* - * POSIX/SUSv3 doesn't provide a standard key for large device - * numbers. I use the same keys here that Joerg Schilling - * used for 'star.' (Which, somewhat confusingly, are called - * "devXXX" even though they code "rdev" values.) No doubt, - * other implementations use other keys. Note that there's no - * reason we can't write the same information into a number of - * different keys. - * - * Of course, this is only needed for block or char device entries. - */ - if (archive_entry_filetype(entry_main) == AE_IFBLK - || archive_entry_filetype(entry_main) == AE_IFCHR) { - /* - * If rdevmajor is too large, add 'SCHILY.devmajor' to - * extended attributes. - */ - dev_t rdevmajor, rdevminor; - rdevmajor = archive_entry_rdevmajor(entry_main); - rdevminor = archive_entry_rdevminor(entry_main); - if (rdevmajor >= (1 << 18)) { - add_pax_attr_int(&(pax->pax_header), "SCHILY.devmajor", - rdevmajor); - /* - * Non-strict formatting below means we don't - * have to truncate here. Not truncating improves - * the chance that some more modern tar archivers - * (such as GNU tar 1.13) can restore the full - * value even if they don't understand the pax - * extended attributes. See my rant below about - * file size fields for additional details. - */ - /* archive_entry_set_rdevmajor(entry_main, - rdevmajor & ((1 << 18) - 1)); */ - need_extension = 1; - } - - /* - * If devminor is too large, add 'SCHILY.devminor' to - * extended attributes. - */ - if (rdevminor >= (1 << 18)) { - add_pax_attr_int(&(pax->pax_header), "SCHILY.devminor", - rdevminor); - /* Truncation is not necessary here, either. */ - /* archive_entry_set_rdevminor(entry_main, - rdevminor & ((1 << 18) - 1)); */ - need_extension = 1; - } - } - - /* - * Technically, the mtime field in the ustar header can - * support 33 bits, but many platforms use signed 32-bit time - * values. The cutoff of 0x7fffffff here is a compromise. - * Yes, this check is duplicated just below; this helps to - * avoid writing an mtime attribute just to handle a - * high-resolution timestamp in "restricted pax" mode. - */ - if (!need_extension && - ((archive_entry_mtime(entry_main) < 0) - || (archive_entry_mtime(entry_main) >= 0x7fffffff))) - need_extension = 1; - - /* I use a star-compatible file flag attribute. */ - p = archive_entry_fflags_text(entry_main); - if (!need_extension && p != NULL && *p != '\0') - need_extension = 1; - - /* If there are non-trivial ACL entries, we need an extension. */ - if (!need_extension && archive_entry_acl_count(entry_original, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS) > 0) - need_extension = 1; - - /* If there are non-trivial ACL entries, we need an extension. */ - if (!need_extension && archive_entry_acl_count(entry_original, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) > 0) - need_extension = 1; - - /* If there are extended attributes, we need an extension */ - if (!need_extension && archive_entry_xattr_count(entry_original) > 0) - need_extension = 1; - - /* - * The following items are handled differently in "pax - * restricted" format. In particular, in "pax restricted" - * format they won't be added unless need_extension is - * already set (we're already generating an extended header, so - * may as well include these). - */ - if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_RESTRICTED || - need_extension) { - - if (archive_entry_mtime(entry_main) < 0 || - archive_entry_mtime(entry_main) >= 0x7fffffff || - archive_entry_mtime_nsec(entry_main) != 0) - add_pax_attr_time(&(pax->pax_header), "mtime", - archive_entry_mtime(entry_main), - archive_entry_mtime_nsec(entry_main)); - - if (archive_entry_ctime(entry_main) != 0 || - archive_entry_ctime_nsec(entry_main) != 0) - add_pax_attr_time(&(pax->pax_header), "ctime", - archive_entry_ctime(entry_main), - archive_entry_ctime_nsec(entry_main)); - - if (archive_entry_atime(entry_main) != 0 || - archive_entry_atime_nsec(entry_main) != 0) - add_pax_attr_time(&(pax->pax_header), "atime", - archive_entry_atime(entry_main), - archive_entry_atime_nsec(entry_main)); - - /* Store birth/creationtime only if it's earlier than mtime */ - if (archive_entry_birthtime_is_set(entry_main) && - archive_entry_birthtime(entry_main) - < archive_entry_mtime(entry_main)) - add_pax_attr_time(&(pax->pax_header), - "LIBARCHIVE.creationtime", - archive_entry_birthtime(entry_main), - archive_entry_birthtime_nsec(entry_main)); - - /* I use a star-compatible file flag attribute. */ - p = archive_entry_fflags_text(entry_main); - if (p != NULL && *p != '\0') - add_pax_attr(&(pax->pax_header), "SCHILY.fflags", p); - - /* I use star-compatible ACL attributes. */ - wp = archive_entry_acl_text_w(entry_original, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS | - ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID); - if (wp != NULL && *wp != L'\0') - add_pax_attr_w(&(pax->pax_header), - "SCHILY.acl.access", wp); - wp = archive_entry_acl_text_w(entry_original, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT | - ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID); - if (wp != NULL && *wp != L'\0') - add_pax_attr_w(&(pax->pax_header), - "SCHILY.acl.default", wp); - - /* Include star-compatible metadata info. */ - /* Note: "SCHILY.dev{major,minor}" are NOT the - * major/minor portions of "SCHILY.dev". */ - add_pax_attr_int(&(pax->pax_header), "SCHILY.dev", - archive_entry_dev(entry_main)); - add_pax_attr_int(&(pax->pax_header), "SCHILY.ino", - archive_entry_ino64(entry_main)); - add_pax_attr_int(&(pax->pax_header), "SCHILY.nlink", - archive_entry_nlink(entry_main)); - - /* Store extended attributes */ - archive_write_pax_header_xattrs(pax, entry_original); - } - - /* Only regular files have data. */ - if (archive_entry_filetype(entry_main) != AE_IFREG) - archive_entry_set_size(entry_main, 0); - - /* - * Pax-restricted does not store data for hardlinks, in order - * to improve compatibility with ustar. - */ - if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE && - hardlink != NULL) - archive_entry_set_size(entry_main, 0); - - /* - * XXX Full pax interchange format does permit a hardlink - * entry to have data associated with it. I'm not supporting - * that here because the client expects me to tell them whether - * or not this format expects data for hardlinks. If I - * don't check here, then every pax archive will end up with - * duplicated data for hardlinks. Someday, there may be - * need to select this behavior, in which case the following - * will need to be revisited. XXX - */ - if (hardlink != NULL) - archive_entry_set_size(entry_main, 0); - - /* Format 'ustar' header for main entry. - * - * The trouble with file size: If the reader can't understand - * the file size, they may not be able to locate the next - * entry and the rest of the archive is toast. Pax-compliant - * readers are supposed to ignore the file size in the main - * header, so the question becomes how to maximize portability - * for readers that don't support pax attribute extensions. - * For maximum compatibility, I permit numeric extensions in - * the main header so that the file size stored will always be - * correct, even if it's in a format that only some - * implementations understand. The technique used here is: - * - * a) If possible, follow the standard exactly. This handles - * files up to 8 gigabytes minus 1. - * - * b) If that fails, try octal but omit the field terminator. - * That handles files up to 64 gigabytes minus 1. - * - * c) Otherwise, use base-256 extensions. That handles files - * up to 2^63 in this implementation, with the potential to - * go up to 2^94. That should hold us for a while. ;-) - * - * The non-strict formatter uses similar logic for other - * numeric fields, though they're less critical. - */ - __archive_write_format_header_ustar(a, ustarbuff, entry_main, -1, 0); - - /* If we built any extended attributes, write that entry first. */ - if (archive_strlen(&(pax->pax_header)) > 0) { - struct archive_entry *pax_attr_entry; - time_t s; - uid_t uid; - gid_t gid; - mode_t mode; - - pax_attr_entry = archive_entry_new(); - p = archive_entry_pathname(entry_main); - archive_entry_set_pathname(pax_attr_entry, - build_pax_attribute_name(pax_entry_name, p)); - archive_entry_set_size(pax_attr_entry, - archive_strlen(&(pax->pax_header))); - /* Copy uid/gid (but clip to ustar limits). */ - uid = archive_entry_uid(entry_main); - if ((unsigned int)uid >= 1 << 18) - uid = (uid_t)(1 << 18) - 1; - archive_entry_set_uid(pax_attr_entry, uid); - gid = archive_entry_gid(entry_main); - if ((unsigned int)gid >= 1 << 18) - gid = (gid_t)(1 << 18) - 1; - archive_entry_set_gid(pax_attr_entry, gid); - /* Copy mode over (but not setuid/setgid bits) */ - mode = archive_entry_mode(entry_main); -#ifdef S_ISUID - mode &= ~S_ISUID; -#endif -#ifdef S_ISGID - mode &= ~S_ISGID; -#endif -#ifdef S_ISVTX - mode &= ~S_ISVTX; -#endif - archive_entry_set_mode(pax_attr_entry, mode); - - /* Copy uname/gname. */ - archive_entry_set_uname(pax_attr_entry, - archive_entry_uname(entry_main)); - archive_entry_set_gname(pax_attr_entry, - archive_entry_gname(entry_main)); - - /* Copy mtime, but clip to ustar limits. */ - s = archive_entry_mtime(entry_main); - if (s < 0) { s = 0; } - if (s >= 0x7fffffff) { s = 0x7fffffff; } - archive_entry_set_mtime(pax_attr_entry, s, 0); - - /* Standard ustar doesn't support atime. */ - archive_entry_set_atime(pax_attr_entry, 0, 0); - - /* Standard ustar doesn't support ctime. */ - archive_entry_set_ctime(pax_attr_entry, 0, 0); - - r = __archive_write_format_header_ustar(a, paxbuff, - pax_attr_entry, 'x', 1); - - archive_entry_free(pax_attr_entry); - - /* Note that the 'x' header shouldn't ever fail to format */ - if (r != 0) { - const char *msg = "archive_write_pax_header: " - "'x' header failed?! This can't happen.\n"; - size_t u = write(2, msg, strlen(msg)); - (void)u; /* UNUSED */ - exit(1); - } - r = (a->compressor.write)(a, paxbuff, 512); - if (r != ARCHIVE_OK) { - pax->entry_bytes_remaining = 0; - pax->entry_padding = 0; - return (ARCHIVE_FATAL); - } - - pax->entry_bytes_remaining = archive_strlen(&(pax->pax_header)); - pax->entry_padding = 0x1ff & (-(int64_t)pax->entry_bytes_remaining); - - r = (a->compressor.write)(a, pax->pax_header.s, - archive_strlen(&(pax->pax_header))); - if (r != ARCHIVE_OK) { - /* If a write fails, we're pretty much toast. */ - return (ARCHIVE_FATAL); - } - /* Pad out the end of the entry. */ - r = write_nulls(a, pax->entry_padding); - if (r != ARCHIVE_OK) { - /* If a write fails, we're pretty much toast. */ - return (ARCHIVE_FATAL); - } - pax->entry_bytes_remaining = pax->entry_padding = 0; - } - - /* Write the header for main entry. */ - r = (a->compressor.write)(a, ustarbuff, 512); - if (r != ARCHIVE_OK) - return (r); - - /* - * Inform the client of the on-disk size we're using, so - * they can avoid unnecessarily writing a body for something - * that we're just going to ignore. - */ - archive_entry_set_size(entry_original, archive_entry_size(entry_main)); - pax->entry_bytes_remaining = archive_entry_size(entry_main); - pax->entry_padding = 0x1ff & (-(int64_t)pax->entry_bytes_remaining); - archive_entry_free(entry_main); - - return (ret); -} - -/* - * We need a valid name for the regular 'ustar' entry. This routine - * tries to hack something more-or-less reasonable. - * - * The approach here tries to preserve leading dir names. We do so by - * working with four sections: - * 1) "prefix" directory names, - * 2) "suffix" directory names, - * 3) inserted dir name (optional), - * 4) filename. - * - * These sections must satisfy the following requirements: - * * Parts 1 & 2 together form an initial portion of the dir name. - * * Part 3 is specified by the caller. (It should not contain a leading - * or trailing '/'.) - * * Part 4 forms an initial portion of the base filename. - * * The filename must be <= 99 chars to fit the ustar 'name' field. - * * Parts 2, 3, 4 together must be <= 99 chars to fit the ustar 'name' fld. - * * Part 1 must be <= 155 chars to fit the ustar 'prefix' field. - * * If the original name ends in a '/', the new name must also end in a '/' - * * Trailing '/.' sequences may be stripped. - * - * Note: Recall that the ustar format does not store the '/' separating - * parts 1 & 2, but does store the '/' separating parts 2 & 3. - */ -static char * -build_ustar_entry_name(char *dest, const char *src, size_t src_length, - const char *insert) -{ - const char *prefix, *prefix_end; - const char *suffix, *suffix_end; - const char *filename, *filename_end; - char *p; - int need_slash = 0; /* Was there a trailing slash? */ - size_t suffix_length = 99; - size_t insert_length; - - /* Length of additional dir element to be added. */ - if (insert == NULL) - insert_length = 0; - else - /* +2 here allows for '/' before and after the insert. */ - insert_length = strlen(insert) + 2; - - /* Step 0: Quick bailout in a common case. */ - if (src_length < 100 && insert == NULL) { - strncpy(dest, src, src_length); - dest[src_length] = '\0'; - return (dest); - } - - /* Step 1: Locate filename and enforce the length restriction. */ - filename_end = src + src_length; - /* Remove trailing '/' chars and '/.' pairs. */ - for (;;) { - if (filename_end > src && filename_end[-1] == '/') { - filename_end --; - need_slash = 1; /* Remember to restore trailing '/'. */ - continue; - } - if (filename_end > src + 1 && filename_end[-1] == '.' - && filename_end[-2] == '/') { - filename_end -= 2; - need_slash = 1; /* "foo/." will become "foo/" */ - continue; - } - break; - } - if (need_slash) - suffix_length--; - /* Find start of filename. */ - filename = filename_end - 1; - while ((filename > src) && (*filename != '/')) - filename --; - if ((*filename == '/') && (filename < filename_end - 1)) - filename ++; - /* Adjust filename_end so that filename + insert fits in 99 chars. */ - suffix_length -= insert_length; - if (filename_end > filename + suffix_length) - filename_end = filename + suffix_length; - /* Calculate max size for "suffix" section (#3 above). */ - suffix_length -= filename_end - filename; - - /* Step 2: Locate the "prefix" section of the dirname, including - * trailing '/'. */ - prefix = src; - prefix_end = prefix + 155; - if (prefix_end > filename) - prefix_end = filename; - while (prefix_end > prefix && *prefix_end != '/') - prefix_end--; - if ((prefix_end < filename) && (*prefix_end == '/')) - prefix_end++; - - /* Step 3: Locate the "suffix" section of the dirname, - * including trailing '/'. */ - suffix = prefix_end; - suffix_end = suffix + suffix_length; /* Enforce limit. */ - if (suffix_end > filename) - suffix_end = filename; - if (suffix_end < suffix) - suffix_end = suffix; - while (suffix_end > suffix && *suffix_end != '/') - suffix_end--; - if ((suffix_end < filename) && (*suffix_end == '/')) - suffix_end++; - - /* Step 4: Build the new name. */ - /* The OpenBSD strlcpy function is safer, but less portable. */ - /* Rather than maintain two versions, just use the strncpy version. */ - p = dest; - if (prefix_end > prefix) { - strncpy(p, prefix, prefix_end - prefix); - p += prefix_end - prefix; - } - if (suffix_end > suffix) { - strncpy(p, suffix, suffix_end - suffix); - p += suffix_end - suffix; - } - if (insert != NULL) { - /* Note: assume insert does not have leading or trailing '/' */ - strcpy(p, insert); - p += strlen(insert); - *p++ = '/'; - } - strncpy(p, filename, filename_end - filename); - p += filename_end - filename; - if (need_slash) - *p++ = '/'; - *p = '\0'; - - return (dest); -} - -/* - * The ustar header for the pax extended attributes must have a - * reasonable name: SUSv3 requires 'dirname'/PaxHeader.'pid'/'filename' - * where 'pid' is the PID of the archiving process. Unfortunately, - * that makes testing a pain since the output varies for each run, - * so I'm sticking with the simpler 'dirname'/PaxHeader/'filename' - * for now. (Someday, I'll make this settable. Then I can use the - * SUS recommendation as default and test harnesses can override it - * to get predictable results.) - * - * Joerg Schilling has argued that this is unnecessary because, in - * practice, if the pax extended attributes get extracted as regular - * files, noone is going to bother reading those attributes to - * manually restore them. Based on this, 'star' uses - * /tmp/PaxHeader/'basename' as the ustar header name. This is a - * tempting argument, in part because it's simpler than the SUSv3 - * recommendation, but I'm not entirely convinced. I'm also - * uncomfortable with the fact that "/tmp" is a Unix-ism. - * - * The following routine leverages build_ustar_entry_name() above and - * so is simpler than you might think. It just needs to provide the - * additional path element and handle a few pathological cases). - */ -static char * -build_pax_attribute_name(char *dest, const char *src) -{ - char buff[64]; - const char *p; - - /* Handle the null filename case. */ - if (src == NULL || *src == '\0') { - strcpy(dest, "PaxHeader/blank"); - return (dest); - } - - /* Prune final '/' and other unwanted final elements. */ - p = src + strlen(src); - for (;;) { - /* Ends in "/", remove the '/' */ - if (p > src && p[-1] == '/') { - --p; - continue; - } - /* Ends in "/.", remove the '.' */ - if (p > src + 1 && p[-1] == '.' - && p[-2] == '/') { - --p; - continue; - } - break; - } - - /* Pathological case: After above, there was nothing left. - * This includes "/." "/./." "/.//./." etc. */ - if (p == src) { - strcpy(dest, "/PaxHeader/rootdir"); - return (dest); - } - - /* Convert unadorned "." into a suitable filename. */ - if (*src == '.' && p == src + 1) { - strcpy(dest, "PaxHeader/currentdir"); - return (dest); - } - - /* - * TODO: Push this string into the 'pax' structure to avoid - * recomputing it every time. That will also open the door - * to having clients override it. - */ -#if HAVE_GETPID && 0 /* Disable this for now; see above comment. */ - sprintf(buff, "PaxHeader.%d", getpid()); -#else - /* If the platform can't fetch the pid, don't include it. */ - strcpy(buff, "PaxHeader"); -#endif - /* General case: build a ustar-compatible name adding "/PaxHeader/". */ - build_ustar_entry_name(dest, src, p - src, buff); - - return (dest); -} - -/* Write two null blocks for the end of archive */ -static int -archive_write_pax_finish(struct archive_write *a) -{ - int r; - - if (a->compressor.write == NULL) - return (ARCHIVE_OK); - - r = write_nulls(a, 512 * 2); - return (r); -} - -static int -archive_write_pax_destroy(struct archive_write *a) -{ - struct pax *pax; - - pax = (struct pax *)a->format_data; - if (pax == NULL) - return (ARCHIVE_OK); - - archive_string_free(&pax->pax_header); - free(pax); - a->format_data = NULL; - return (ARCHIVE_OK); -} - -static int -archive_write_pax_finish_entry(struct archive_write *a) -{ - struct pax *pax; - int ret; - - pax = (struct pax *)a->format_data; - ret = write_nulls(a, pax->entry_bytes_remaining + pax->entry_padding); - pax->entry_bytes_remaining = pax->entry_padding = 0; - return (ret); -} - -static int -write_nulls(struct archive_write *a, size_t padding) -{ - int ret; - size_t to_write; - - while (padding > 0) { - to_write = padding < a->null_length ? padding : a->null_length; - ret = (a->compressor.write)(a, a->nulls, to_write); - if (ret != ARCHIVE_OK) - return (ret); - padding -= to_write; - } - return (ARCHIVE_OK); -} - -static ssize_t -archive_write_pax_data(struct archive_write *a, const void *buff, size_t s) -{ - struct pax *pax; - int ret; - - pax = (struct pax *)a->format_data; - if (s > pax->entry_bytes_remaining) - s = pax->entry_bytes_remaining; - - ret = (a->compressor.write)(a, buff, s); - pax->entry_bytes_remaining -= s; - if (ret == ARCHIVE_OK) - return (s); - else - return (ret); -} - -static int -has_non_ASCII(const wchar_t *wp) -{ - if (wp == NULL) - return (1); - while (*wp != L'\0' && *wp < 128) - wp++; - return (*wp != L'\0'); -} - -/* - * Used by extended attribute support; encodes the name - * so that there will be no '=' characters in the result. - */ -static char * -url_encode(const char *in) -{ - const char *s; - char *d; - int out_len = 0; - char *out; - - for (s = in; *s != '\0'; s++) { - if (*s < 33 || *s > 126 || *s == '%' || *s == '=') - out_len += 3; - else - out_len++; - } - - out = (char *)malloc(out_len + 1); - if (out == NULL) - return (NULL); - - for (s = in, d = out; *s != '\0'; s++) { - /* encode any non-printable ASCII character or '%' or '=' */ - if (*s < 33 || *s > 126 || *s == '%' || *s == '=') { - /* URL encoding is '%' followed by two hex digits */ - *d++ = '%'; - *d++ = "0123456789ABCDEF"[0x0f & (*s >> 4)]; - *d++ = "0123456789ABCDEF"[0x0f & *s]; - } else { - *d++ = *s; - } - } - *d = '\0'; - return (out); -} - -/* - * Encode a sequence of bytes into a C string using base-64 encoding. - * - * Returns a null-terminated C string allocated with malloc(); caller - * is responsible for freeing the result. - */ -static char * -base64_encode(const char *s, size_t len) -{ - static const char digits[64] = - { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', - 'P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d', - 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s', - 't','u','v','w','x','y','z','0','1','2','3','4','5','6','7', - '8','9','+','/' }; - int v; - char *d, *out; - - /* 3 bytes becomes 4 chars, but round up and allow for trailing NUL */ - out = (char *)malloc((len * 4 + 2) / 3 + 1); - if (out == NULL) - return (NULL); - d = out; - - /* Convert each group of 3 bytes into 4 characters. */ - while (len >= 3) { - v = (((int)s[0] << 16) & 0xff0000) - | (((int)s[1] << 8) & 0xff00) - | (((int)s[2]) & 0x00ff); - s += 3; - len -= 3; - *d++ = digits[(v >> 18) & 0x3f]; - *d++ = digits[(v >> 12) & 0x3f]; - *d++ = digits[(v >> 6) & 0x3f]; - *d++ = digits[(v) & 0x3f]; - } - /* Handle final group of 1 byte (2 chars) or 2 bytes (3 chars). */ - switch (len) { - case 0: break; - case 1: - v = (((int)s[0] << 16) & 0xff0000); - *d++ = digits[(v >> 18) & 0x3f]; - *d++ = digits[(v >> 12) & 0x3f]; - break; - case 2: - v = (((int)s[0] << 16) & 0xff0000) - | (((int)s[1] << 8) & 0xff00); - *d++ = digits[(v >> 18) & 0x3f]; - *d++ = digits[(v >> 12) & 0x3f]; - *d++ = digits[(v >> 6) & 0x3f]; - break; - } - /* Add trailing NUL character so output is a valid C string. */ - *d = '\0'; - return (out); -} diff --git a/lib/libarchive/archive_write_set_format_shar.c b/lib/libarchive/archive_write_set_format_shar.c deleted file mode 100644 index bd62768..0000000 --- a/lib/libarchive/archive_write_set_format_shar.c +++ /dev/null @@ -1,625 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2008 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_write_private.h" - -struct shar { - int dump; - int end_of_line; - struct archive_entry *entry; - int has_data; - char *last_dir; - - /* Line buffer for uuencoded dump format */ - char outbuff[45]; - size_t outpos; - - int wrote_header; - struct archive_string work; - struct archive_string quoted_name; -}; - -static int archive_write_shar_finish(struct archive_write *); -static int archive_write_shar_destroy(struct archive_write *); -static int archive_write_shar_header(struct archive_write *, - struct archive_entry *); -static ssize_t archive_write_shar_data_sed(struct archive_write *, - const void * buff, size_t); -static ssize_t archive_write_shar_data_uuencode(struct archive_write *, - const void * buff, size_t); -static int archive_write_shar_finish_entry(struct archive_write *); - -/* - * Copy the given string to the buffer, quoting all shell meta characters - * found. - */ -static void -shar_quote(struct archive_string *buf, const char *str, int in_shell) -{ - static const char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~"; - size_t len; - - while (*str != '\0') { - if ((len = strcspn(str, meta)) != 0) { - archive_strncat(buf, str, len); - str += len; - } else if (*str == '\n') { - if (in_shell) - archive_strcat(buf, "\"\n\""); - else - archive_strcat(buf, "\\n"); - ++str; - } else { - archive_strappend_char(buf, '\\'); - archive_strappend_char(buf, *str); - ++str; - } - } -} - -/* - * Set output format to 'shar' format. - */ -int -archive_write_set_format_shar(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct shar *shar; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - shar = (struct shar *)malloc(sizeof(*shar)); - if (shar == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data"); - return (ARCHIVE_FATAL); - } - memset(shar, 0, sizeof(*shar)); - archive_string_init(&shar->work); - archive_string_init(&shar->quoted_name); - a->format_data = shar; - - a->pad_uncompressed = 0; - a->format_name = "shar"; - a->format_write_header = archive_write_shar_header; - a->format_finish = archive_write_shar_finish; - a->format_destroy = archive_write_shar_destroy; - a->format_write_data = archive_write_shar_data_sed; - a->format_finish_entry = archive_write_shar_finish_entry; - a->archive.archive_format = ARCHIVE_FORMAT_SHAR_BASE; - a->archive.archive_format_name = "shar"; - return (ARCHIVE_OK); -} - -/* - * An alternate 'shar' that uses uudecode instead of 'sed' to encode - * file contents and can therefore be used to archive binary files. - * In addition, this variant also attempts to restore ownership, file modes, - * and other extended file information. - */ -int -archive_write_set_format_shar_dump(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct shar *shar; - - archive_write_set_format_shar(&a->archive); - shar = (struct shar *)a->format_data; - shar->dump = 1; - a->format_write_data = archive_write_shar_data_uuencode; - a->archive.archive_format = ARCHIVE_FORMAT_SHAR_DUMP; - a->archive.archive_format_name = "shar dump"; - return (ARCHIVE_OK); -} - -static int -archive_write_shar_header(struct archive_write *a, struct archive_entry *entry) -{ - const char *linkname; - const char *name; - char *p, *pp; - struct shar *shar; - - shar = (struct shar *)a->format_data; - if (!shar->wrote_header) { - archive_strcat(&shar->work, "#!/bin/sh\n"); - archive_strcat(&shar->work, "# This is a shell archive\n"); - shar->wrote_header = 1; - } - - /* Save the entry for the closing. */ - if (shar->entry) - archive_entry_free(shar->entry); - shar->entry = archive_entry_clone(entry); - name = archive_entry_pathname(entry); - - /* Handle some preparatory issues. */ - switch(archive_entry_filetype(entry)) { - case AE_IFREG: - /* Only regular files have non-zero size. */ - break; - case AE_IFDIR: - archive_entry_set_size(entry, 0); - /* Don't bother trying to recreate '.' */ - if (strcmp(name, ".") == 0 || strcmp(name, "./") == 0) - return (ARCHIVE_OK); - break; - case AE_IFIFO: - case AE_IFCHR: - case AE_IFBLK: - /* All other file types have zero size in the archive. */ - archive_entry_set_size(entry, 0); - break; - default: - archive_entry_set_size(entry, 0); - if (archive_entry_hardlink(entry) == NULL && - archive_entry_symlink(entry) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "shar format cannot archive this"); - return (ARCHIVE_WARN); - } - } - - archive_string_empty(&shar->quoted_name); - shar_quote(&shar->quoted_name, name, 1); - - /* Stock preparation for all file types. */ - archive_string_sprintf(&shar->work, "echo x %s\n", shar->quoted_name.s); - - if (archive_entry_filetype(entry) != AE_IFDIR) { - /* Try to create the dir. */ - p = strdup(name); - pp = strrchr(p, '/'); - /* If there is a / character, try to create the dir. */ - if (pp != NULL) { - *pp = '\0'; - - /* Try to avoid a lot of redundant mkdir commands. */ - if (strcmp(p, ".") == 0) { - /* Don't try to "mkdir ." */ - free(p); - } else if (shar->last_dir == NULL) { - archive_strcat(&shar->work, "mkdir -p "); - shar_quote(&shar->work, p, 1); - archive_strcat(&shar->work, - " > /dev/null 2>&1\n"); - shar->last_dir = p; - } else if (strcmp(p, shar->last_dir) == 0) { - /* We've already created this exact dir. */ - free(p); - } else if (strlen(p) < strlen(shar->last_dir) && - strncmp(p, shar->last_dir, strlen(p)) == 0) { - /* We've already created a subdir. */ - free(p); - } else { - archive_strcat(&shar->work, "mkdir -p "); - shar_quote(&shar->work, p, 1); - archive_strcat(&shar->work, - " > /dev/null 2>&1\n"); - shar->last_dir = p; - } - } else { - free(p); - } - } - - /* Handle file-type specific issues. */ - shar->has_data = 0; - if ((linkname = archive_entry_hardlink(entry)) != NULL) { - archive_strcat(&shar->work, "ln -f "); - shar_quote(&shar->work, linkname, 1); - archive_string_sprintf(&shar->work, " %s\n", - shar->quoted_name.s); - } else if ((linkname = archive_entry_symlink(entry)) != NULL) { - archive_strcat(&shar->work, "ln -fs "); - shar_quote(&shar->work, linkname, 1); - archive_string_sprintf(&shar->work, " %s\n", - shar->quoted_name.s); - } else { - switch(archive_entry_filetype(entry)) { - case AE_IFREG: - if (archive_entry_size(entry) == 0) { - /* More portable than "touch." */ - archive_string_sprintf(&shar->work, - "test -e \"%s\" || :> \"%s\"\n", - shar->quoted_name.s, shar->quoted_name.s); - } else { - if (shar->dump) { - archive_string_sprintf(&shar->work, - "uudecode -p > %s << 'SHAR_END'\n", - shar->quoted_name.s); - archive_string_sprintf(&shar->work, - "begin %o ", - archive_entry_mode(entry) & 0777); - shar_quote(&shar->work, name, 0); - archive_strcat(&shar->work, "\n"); - } else { - archive_string_sprintf(&shar->work, - "sed 's/^X//' > %s << 'SHAR_END'\n", - shar->quoted_name.s); - } - shar->has_data = 1; - shar->end_of_line = 1; - shar->outpos = 0; - } - break; - case AE_IFDIR: - archive_string_sprintf(&shar->work, - "mkdir -p %s > /dev/null 2>&1\n", - shar->quoted_name.s); - /* Record that we just created this directory. */ - if (shar->last_dir != NULL) - free(shar->last_dir); - - shar->last_dir = strdup(name); - /* Trim a trailing '/'. */ - pp = strrchr(shar->last_dir, '/'); - if (pp != NULL && pp[1] == '\0') - *pp = '\0'; - /* - * TODO: Put dir name/mode on a list to be fixed - * up at end of archive. - */ - break; - case AE_IFIFO: - archive_string_sprintf(&shar->work, - "mkfifo %s\n", shar->quoted_name.s); - break; - case AE_IFCHR: - archive_string_sprintf(&shar->work, - "mknod %s c %d %d\n", shar->quoted_name.s, - archive_entry_rdevmajor(entry), - archive_entry_rdevminor(entry)); - break; - case AE_IFBLK: - archive_string_sprintf(&shar->work, - "mknod %s b %d %d\n", shar->quoted_name.s, - archive_entry_rdevmajor(entry), - archive_entry_rdevminor(entry)); - break; - default: - return (ARCHIVE_WARN); - } - } - - return (ARCHIVE_OK); -} - -static ssize_t -archive_write_shar_data_sed(struct archive_write *a, const void *buff, size_t n) -{ - static const size_t ensured = 65533; - struct shar *shar; - const char *src; - char *buf, *buf_end; - int ret; - size_t written = n; - - shar = (struct shar *)a->format_data; - if (!shar->has_data || n == 0) - return (0); - - src = (const char *)buff; - - /* - * ensure is the number of bytes in buffer before expanding the - * current character. Each operation writes the current character - * and optionally the start-of-new-line marker. This can happen - * twice before entering the loop, so make sure three additional - * bytes can be written. - */ - if (archive_string_ensure(&shar->work, ensured + 3) == NULL) - __archive_errx(1, "Out of memory"); - - if (shar->work.length > ensured) { - ret = (*a->compressor.write)(a, shar->work.s, - shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - archive_string_empty(&shar->work); - } - buf = shar->work.s + shar->work.length; - buf_end = shar->work.s + ensured; - - if (shar->end_of_line) { - *buf++ = 'X'; - shar->end_of_line = 0; - } - - while (n-- != 0) { - if ((*buf++ = *src++) == '\n') { - if (n == 0) - shar->end_of_line = 1; - else - *buf++ = 'X'; - } - - if (buf >= buf_end) { - shar->work.length = buf - shar->work.s; - ret = (*a->compressor.write)(a, shar->work.s, - shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - archive_string_empty(&shar->work); - buf = shar->work.s; - } - } - - shar->work.length = buf - shar->work.s; - - return (written); -} - -#define UUENC(c) (((c)!=0) ? ((c) & 077) + ' ': '`') - -static void -uuencode_group(const char _in[3], char out[4]) -{ - const unsigned char *in = (const unsigned char *)_in; - int t; - - t = (in[0] << 16) | (in[1] << 8) | in[2]; - out[0] = UUENC( 0x3f & (t >> 18) ); - out[1] = UUENC( 0x3f & (t >> 12) ); - out[2] = UUENC( 0x3f & (t >> 6) ); - out[3] = UUENC( 0x3f & t ); -} - -static void -uuencode_line(struct shar *shar, const char *inbuf, size_t len) -{ - char tmp_buf[3], *buf; - size_t alloc_len; - - /* len <= 45 -> expanded to 60 + len byte + new line */ - alloc_len = shar->work.length + 62; - if (archive_string_ensure(&shar->work, alloc_len) == NULL) - __archive_errx(1, "Out of memory"); - - buf = shar->work.s + shar->work.length; - *buf++ = UUENC(len); - while (len >= 3) { - uuencode_group(inbuf, buf); - len -= 3; - inbuf += 3; - buf += 4; - } - if (len != 0) { - tmp_buf[0] = inbuf[0]; - if (len == 1) - tmp_buf[1] = '\0'; - else - tmp_buf[1] = inbuf[1]; - tmp_buf[2] = '\0'; - uuencode_group(inbuf, buf); - buf += 4; - } - *buf++ = '\n'; - if ((buf - shar->work.s) > (ptrdiff_t)(shar->work.length + 62)) - __archive_errx(1, "Buffer overflow"); - shar->work.length = buf - shar->work.s; -} - -static ssize_t -archive_write_shar_data_uuencode(struct archive_write *a, const void *buff, - size_t length) -{ - struct shar *shar; - const char *src; - size_t n; - int ret; - - shar = (struct shar *)a->format_data; - if (!shar->has_data) - return (ARCHIVE_OK); - src = (const char *)buff; - - if (shar->outpos != 0) { - n = 45 - shar->outpos; - if (n > length) - n = length; - memcpy(shar->outbuff + shar->outpos, src, n); - if (shar->outpos + n < 45) { - shar->outpos += n; - return length; - } - uuencode_line(shar, shar->outbuff, 45); - src += n; - n = length - n; - } else { - n = length; - } - - while (n >= 45) { - uuencode_line(shar, src, 45); - src += 45; - n -= 45; - - if (shar->work.length < 65536) - continue; - ret = (*a->compressor.write)(a, shar->work.s, - shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - archive_string_empty(&shar->work); - } - if (n != 0) { - memcpy(shar->outbuff, src, n); - shar->outpos = n; - } - return (length); -} - -static int -archive_write_shar_finish_entry(struct archive_write *a) -{ - const char *g, *p, *u; - struct shar *shar; - int ret; - - shar = (struct shar *)a->format_data; - if (shar->entry == NULL) - return (0); - - if (shar->dump) { - /* Finish uuencoded data. */ - if (shar->has_data) { - if (shar->outpos > 0) - uuencode_line(shar, shar->outbuff, - shar->outpos); - archive_strcat(&shar->work, "`\nend\n"); - archive_strcat(&shar->work, "SHAR_END\n"); - } - /* Restore file mode, owner, flags. */ - /* - * TODO: Don't immediately restore mode for - * directories; defer that to end of script. - */ - archive_string_sprintf(&shar->work, "chmod %o ", - archive_entry_mode(shar->entry) & 07777); - shar_quote(&shar->work, archive_entry_pathname(shar->entry), 1); - archive_strcat(&shar->work, "\n"); - - u = archive_entry_uname(shar->entry); - g = archive_entry_gname(shar->entry); - if (u != NULL || g != NULL) { - archive_strcat(&shar->work, "chown "); - if (u != NULL) - shar_quote(&shar->work, u, 1); - if (g != NULL) { - archive_strcat(&shar->work, ":"); - shar_quote(&shar->work, g, 1); - } - shar_quote(&shar->work, - archive_entry_pathname(shar->entry), 1); - archive_strcat(&shar->work, "\n"); - } - - if ((p = archive_entry_fflags_text(shar->entry)) != NULL) { - archive_string_sprintf(&shar->work, "chflags %s ", p); - shar_quote(&shar->work, - archive_entry_pathname(shar->entry), 1); - archive_strcat(&shar->work, "\n"); - } - - /* TODO: restore ACLs */ - - } else { - if (shar->has_data) { - /* Finish sed-encoded data: ensure last line ends. */ - if (!shar->end_of_line) - archive_strappend_char(&shar->work, '\n'); - archive_strcat(&shar->work, "SHAR_END\n"); - } - } - - archive_entry_free(shar->entry); - shar->entry = NULL; - - if (shar->work.length < 65536) - return (ARCHIVE_OK); - - ret = (*a->compressor.write)(a, shar->work.s, shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - archive_string_empty(&shar->work); - - return (ARCHIVE_OK); -} - -static int -archive_write_shar_finish(struct archive_write *a) -{ - struct shar *shar; - int ret; - - /* - * TODO: Accumulate list of directory names/modes and - * fix them all up at end-of-archive. - */ - - shar = (struct shar *)a->format_data; - - /* - * Only write the end-of-archive markers if the archive was - * actually started. This avoids problems if someone sets - * shar format, then sets another format (which would invoke - * shar_finish to free the format-specific data). - */ - if (shar->wrote_header == 0) - return (ARCHIVE_OK); - - archive_strcat(&shar->work, "exit\n"); - - ret = (*a->compressor.write)(a, shar->work.s, shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - /* Shar output is never padded. */ - archive_write_set_bytes_in_last_block(&a->archive, 1); - /* - * TODO: shar should also suppress padding of - * uncompressed data within gzip/bzip2 streams. - */ - - return (ARCHIVE_OK); -} - -static int -archive_write_shar_destroy(struct archive_write *a) -{ - struct shar *shar; - - shar = (struct shar *)a->format_data; - if (shar == NULL) - return (ARCHIVE_OK); - - archive_entry_free(shar->entry); - free(shar->last_dir); - archive_string_free(&(shar->work)); - archive_string_free(&(shar->quoted_name)); - free(shar); - a->format_data = NULL; - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/archive_write_set_format_ustar.c b/lib/libarchive/archive_write_set_format_ustar.c deleted file mode 100644 index 54893d4..0000000 --- a/lib/libarchive/archive_write_set_format_ustar.c +++ /dev/null @@ -1,587 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_write_private.h" - -struct ustar { - uint64_t entry_bytes_remaining; - uint64_t entry_padding; -}; - -/* - * Define structure of POSIX 'ustar' tar header. - */ -#define USTAR_name_offset 0 -#define USTAR_name_size 100 -#define USTAR_mode_offset 100 -#define USTAR_mode_size 6 -#define USTAR_mode_max_size 8 -#define USTAR_uid_offset 108 -#define USTAR_uid_size 6 -#define USTAR_uid_max_size 8 -#define USTAR_gid_offset 116 -#define USTAR_gid_size 6 -#define USTAR_gid_max_size 8 -#define USTAR_size_offset 124 -#define USTAR_size_size 11 -#define USTAR_size_max_size 12 -#define USTAR_mtime_offset 136 -#define USTAR_mtime_size 11 -#define USTAR_mtime_max_size 11 -#define USTAR_checksum_offset 148 -#define USTAR_checksum_size 8 -#define USTAR_typeflag_offset 156 -#define USTAR_typeflag_size 1 -#define USTAR_linkname_offset 157 -#define USTAR_linkname_size 100 -#define USTAR_magic_offset 257 -#define USTAR_magic_size 6 -#define USTAR_version_offset 263 -#define USTAR_version_size 2 -#define USTAR_uname_offset 265 -#define USTAR_uname_size 32 -#define USTAR_gname_offset 297 -#define USTAR_gname_size 32 -#define USTAR_rdevmajor_offset 329 -#define USTAR_rdevmajor_size 6 -#define USTAR_rdevmajor_max_size 8 -#define USTAR_rdevminor_offset 337 -#define USTAR_rdevminor_size 6 -#define USTAR_rdevminor_max_size 8 -#define USTAR_prefix_offset 345 -#define USTAR_prefix_size 155 -#define USTAR_padding_offset 500 -#define USTAR_padding_size 12 - -/* - * A filled-in copy of the header for initialization. - */ -static const char template_header[] = { - /* name: 100 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0, - /* Mode, space-null termination: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* uid, space-null termination: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* gid, space-null termination: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* size, space termation: 12 bytes */ - '0','0','0','0','0','0','0','0','0','0','0', ' ', - /* mtime, space termation: 12 bytes */ - '0','0','0','0','0','0','0','0','0','0','0', ' ', - /* Initial checksum value: 8 spaces */ - ' ',' ',' ',' ',' ',' ',' ',' ', - /* Typeflag: 1 byte */ - '0', /* '0' = regular file */ - /* Linkname: 100 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0, - /* Magic: 6 bytes, Version: 2 bytes */ - 'u','s','t','a','r','\0', '0','0', - /* Uname: 32 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - /* Gname: 32 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - /* rdevmajor + space/null padding: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* rdevminor + space/null padding: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* Prefix: 155 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0, - /* Padding: 12 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0 -}; - -static ssize_t archive_write_ustar_data(struct archive_write *a, const void *buff, - size_t s); -static int archive_write_ustar_destroy(struct archive_write *); -static int archive_write_ustar_finish(struct archive_write *); -static int archive_write_ustar_finish_entry(struct archive_write *); -static int archive_write_ustar_header(struct archive_write *, - struct archive_entry *entry); -static int format_256(int64_t, char *, int); -static int format_number(int64_t, char *, int size, int max, int strict); -static int format_octal(int64_t, char *, int); -static int write_nulls(struct archive_write *a, size_t); - -/* - * Set output format to 'ustar' format. - */ -int -archive_write_set_format_ustar(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct ustar *ustar; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - /* Basic internal sanity test. */ - if (sizeof(template_header) != 512) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %d should be 512", (int)sizeof(template_header)); - return (ARCHIVE_FATAL); - } - - ustar = (struct ustar *)malloc(sizeof(*ustar)); - if (ustar == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate ustar data"); - return (ARCHIVE_FATAL); - } - memset(ustar, 0, sizeof(*ustar)); - a->format_data = ustar; - - a->pad_uncompressed = 1; /* Mimic gtar in this respect. */ - a->format_name = "ustar"; - a->format_write_header = archive_write_ustar_header; - a->format_write_data = archive_write_ustar_data; - a->format_finish = archive_write_ustar_finish; - a->format_destroy = archive_write_ustar_destroy; - a->format_finish_entry = archive_write_ustar_finish_entry; - a->archive.archive_format = ARCHIVE_FORMAT_TAR_USTAR; - a->archive.archive_format_name = "POSIX ustar"; - return (ARCHIVE_OK); -} - -static int -archive_write_ustar_header(struct archive_write *a, struct archive_entry *entry) -{ - char buff[512]; - int ret, ret2; - struct ustar *ustar; - - ustar = (struct ustar *)a->format_data; - - /* Only regular files (not hardlinks) have data. */ - if (archive_entry_hardlink(entry) != NULL || - archive_entry_symlink(entry) != NULL || - !(archive_entry_filetype(entry) == AE_IFREG)) - archive_entry_set_size(entry, 0); - - if (AE_IFDIR == archive_entry_filetype(entry)) { - const char *p; - char *t; - /* - * Ensure a trailing '/'. Modify the entry so - * the client sees the change. - */ - p = archive_entry_pathname(entry); - if (p[strlen(p) - 1] != '/') { - t = (char *)malloc(strlen(p) + 2); - if (t == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate ustar data"); - return(ARCHIVE_FATAL); - } - strcpy(t, p); - strcat(t, "/"); - archive_entry_copy_pathname(entry, t); - free(t); - } - } - - ret = __archive_write_format_header_ustar(a, buff, entry, -1, 1); - if (ret < ARCHIVE_WARN) - return (ret); - ret2 = (a->compressor.write)(a, buff, 512); - if (ret2 < ARCHIVE_WARN) - return (ret2); - if (ret2 < ret) - ret = ret2; - - ustar->entry_bytes_remaining = archive_entry_size(entry); - ustar->entry_padding = 0x1ff & (-(int64_t)ustar->entry_bytes_remaining); - return (ret); -} - -/* - * Format a basic 512-byte "ustar" header. - * - * Returns -1 if format failed (due to field overflow). - * Note that this always formats as much of the header as possible. - * If "strict" is set to zero, it will extend numeric fields as - * necessary (overwriting terminators or using base-256 extensions). - * - * This is exported so that other 'tar' formats can use it. - */ -int -__archive_write_format_header_ustar(struct archive_write *a, char h[512], - struct archive_entry *entry, int tartype, int strict) -{ - unsigned int checksum; - int i, ret; - size_t copy_length; - const char *p, *pp; - int mytartype; - - ret = 0; - mytartype = -1; - /* - * The "template header" already includes the "ustar" - * signature, various end-of-field markers and other required - * elements. - */ - memcpy(h, &template_header, 512); - - /* - * Because the block is already null-filled, and strings - * are allowed to exactly fill their destination (without null), - * I use memcpy(dest, src, strlen()) here a lot to copy strings. - */ - - pp = archive_entry_pathname(entry); - if (strlen(pp) <= USTAR_name_size) - memcpy(h + USTAR_name_offset, pp, strlen(pp)); - else { - /* Store in two pieces, splitting at a '/'. */ - p = strchr(pp + strlen(pp) - USTAR_name_size - 1, '/'); - /* - * Look for the next '/' if we chose the first character - * as the separator. (ustar format doesn't permit - * an empty prefix.) - */ - if (p == pp) - p = strchr(p + 1, '/'); - /* Fail if the name won't fit. */ - if (!p) { - /* No separator. */ - archive_set_error(&a->archive, ENAMETOOLONG, - "Pathname too long"); - ret = ARCHIVE_FAILED; - } else if (p[1] == '\0') { - /* - * The only feasible separator is a final '/'; - * this would result in a non-empty prefix and - * an empty name, which POSIX doesn't - * explicity forbid, but it just feels wrong. - */ - archive_set_error(&a->archive, ENAMETOOLONG, - "Pathname too long"); - ret = ARCHIVE_FAILED; - } else if (p > pp + USTAR_prefix_size) { - /* Prefix is too long. */ - archive_set_error(&a->archive, ENAMETOOLONG, - "Pathname too long"); - ret = ARCHIVE_FAILED; - } else { - /* Copy prefix and remainder to appropriate places */ - memcpy(h + USTAR_prefix_offset, pp, p - pp); - memcpy(h + USTAR_name_offset, p + 1, pp + strlen(pp) - p - 1); - } - } - - p = archive_entry_hardlink(entry); - if (p != NULL) - mytartype = '1'; - else - p = archive_entry_symlink(entry); - if (p != NULL && p[0] != '\0') { - copy_length = strlen(p); - if (copy_length > USTAR_linkname_size) { - archive_set_error(&a->archive, ENAMETOOLONG, - "Link contents too long"); - ret = ARCHIVE_FAILED; - copy_length = USTAR_linkname_size; - } - memcpy(h + USTAR_linkname_offset, p, copy_length); - } - - p = archive_entry_uname(entry); - if (p != NULL && p[0] != '\0') { - copy_length = strlen(p); - if (copy_length > USTAR_uname_size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Username too long"); - ret = ARCHIVE_FAILED; - copy_length = USTAR_uname_size; - } - memcpy(h + USTAR_uname_offset, p, copy_length); - } - - p = archive_entry_gname(entry); - if (p != NULL && p[0] != '\0') { - copy_length = strlen(p); - if (strlen(p) > USTAR_gname_size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Group name too long"); - ret = ARCHIVE_FAILED; - copy_length = USTAR_gname_size; - } - memcpy(h + USTAR_gname_offset, p, copy_length); - } - - if (format_number(archive_entry_mode(entry) & 07777, h + USTAR_mode_offset, USTAR_mode_size, USTAR_mode_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, "Numeric mode too large"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_uid(entry), h + USTAR_uid_offset, USTAR_uid_size, USTAR_uid_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, "Numeric user ID too large"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_gid(entry), h + USTAR_gid_offset, USTAR_gid_size, USTAR_gid_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, "Numeric group ID too large"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_size(entry), h + USTAR_size_offset, USTAR_size_size, USTAR_size_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, "File size out of range"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_mtime(entry), h + USTAR_mtime_offset, USTAR_mtime_size, USTAR_mtime_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, - "File modification time too large"); - ret = ARCHIVE_FAILED; - } - - if (archive_entry_filetype(entry) == AE_IFBLK - || archive_entry_filetype(entry) == AE_IFCHR) { - if (format_number(archive_entry_rdevmajor(entry), h + USTAR_rdevmajor_offset, - USTAR_rdevmajor_size, USTAR_rdevmajor_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, - "Major device number too large"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_rdevminor(entry), h + USTAR_rdevminor_offset, - USTAR_rdevminor_size, USTAR_rdevminor_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, - "Minor device number too large"); - ret = ARCHIVE_FAILED; - } - } - - if (tartype >= 0) { - h[USTAR_typeflag_offset] = tartype; - } else if (mytartype >= 0) { - h[USTAR_typeflag_offset] = mytartype; - } else { - switch (archive_entry_filetype(entry)) { - case AE_IFREG: h[USTAR_typeflag_offset] = '0' ; break; - case AE_IFLNK: h[USTAR_typeflag_offset] = '2' ; break; - case AE_IFCHR: h[USTAR_typeflag_offset] = '3' ; break; - case AE_IFBLK: h[USTAR_typeflag_offset] = '4' ; break; - case AE_IFDIR: h[USTAR_typeflag_offset] = '5' ; break; - case AE_IFIFO: h[USTAR_typeflag_offset] = '6' ; break; - case AE_IFSOCK: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "tar format cannot archive socket"); - return (ARCHIVE_FAILED); - default: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "tar format cannot archive this (mode=0%lo)", - (unsigned long)archive_entry_mode(entry)); - ret = ARCHIVE_FAILED; - } - } - - checksum = 0; - for (i = 0; i < 512; i++) - checksum += 255 & (unsigned int)h[i]; - h[USTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */ - /* h[USTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */ - format_octal(checksum, h + USTAR_checksum_offset, 6); - return (ret); -} - -/* - * Format a number into a field, with some intelligence. - */ -static int -format_number(int64_t v, char *p, int s, int maxsize, int strict) -{ - int64_t limit; - - limit = ((int64_t)1 << (s*3)); - - /* "Strict" only permits octal values with proper termination. */ - if (strict) - return (format_octal(v, p, s)); - - /* - * In non-strict mode, we allow the number to overwrite one or - * more bytes of the field termination. Even old tar - * implementations should be able to handle this with no - * problem. - */ - if (v >= 0) { - while (s <= maxsize) { - if (v < limit) - return (format_octal(v, p, s)); - s++; - limit <<= 3; - } - } - - /* Base-256 can handle any number, positive or negative. */ - return (format_256(v, p, maxsize)); -} - -/* - * Format a number into the specified field using base-256. - */ -static int -format_256(int64_t v, char *p, int s) -{ - p += s; - while (s-- > 0) { - *--p = (char)(v & 0xff); - v >>= 8; - } - *p |= 0x80; /* Set the base-256 marker bit. */ - return (0); -} - -/* - * Format a number into the specified field. - */ -static int -format_octal(int64_t v, char *p, int s) -{ - int len; - - len = s; - - /* Octal values can't be negative, so use 0. */ - if (v < 0) { - while (len-- > 0) - *p++ = '0'; - return (-1); - } - - p += s; /* Start at the end and work backwards. */ - while (s-- > 0) { - *--p = (char)('0' + (v & 7)); - v >>= 3; - } - - if (v == 0) - return (0); - - /* If it overflowed, fill field with max value. */ - while (len-- > 0) - *p++ = '7'; - - return (-1); -} - -static int -archive_write_ustar_finish(struct archive_write *a) -{ - int r; - - if (a->compressor.write == NULL) - return (ARCHIVE_OK); - - r = write_nulls(a, 512*2); - return (r); -} - -static int -archive_write_ustar_destroy(struct archive_write *a) -{ - struct ustar *ustar; - - ustar = (struct ustar *)a->format_data; - free(ustar); - a->format_data = NULL; - return (ARCHIVE_OK); -} - -static int -archive_write_ustar_finish_entry(struct archive_write *a) -{ - struct ustar *ustar; - int ret; - - ustar = (struct ustar *)a->format_data; - ret = write_nulls(a, - ustar->entry_bytes_remaining + ustar->entry_padding); - ustar->entry_bytes_remaining = ustar->entry_padding = 0; - return (ret); -} - -static int -write_nulls(struct archive_write *a, size_t padding) -{ - int ret; - size_t to_write; - - while (padding > 0) { - to_write = padding < a->null_length ? padding : a->null_length; - ret = (a->compressor.write)(a, a->nulls, to_write); - if (ret != ARCHIVE_OK) - return (ret); - padding -= to_write; - } - return (ARCHIVE_OK); -} - -static ssize_t -archive_write_ustar_data(struct archive_write *a, const void *buff, size_t s) -{ - struct ustar *ustar; - int ret; - - ustar = (struct ustar *)a->format_data; - if (s > ustar->entry_bytes_remaining) - s = ustar->entry_bytes_remaining; - ret = (a->compressor.write)(a, buff, s); - ustar->entry_bytes_remaining -= s; - if (ret != ARCHIVE_OK) - return (ret); - return (s); -} diff --git a/lib/libarchive/archive_write_set_format_zip.c b/lib/libarchive/archive_write_set_format_zip.c deleted file mode 100644 index 1bbbb6a..0000000 --- a/lib/libarchive/archive_write_set_format_zip.c +++ /dev/null @@ -1,670 +0,0 @@ -/*- - * Copyright (c) 2008 Anselm Strauss - * Copyright (c) 2009 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Development supported by Google Summer of Code 2008. - */ - -/* - * The current implementation is very limited: - * - * - No encryption support. - * - No ZIP64 support. - * - No support for splitting and spanning. - * - Only supports regular file and folder entries. - * - * Note that generally data in ZIP files is little-endian encoded, - * with some exceptions. - * - * TODO: Since Libarchive is generally 64bit oriented, but this implementation - * does not yet support sizes exceeding 32bit, it is highly fragile for - * big archives. This should change when ZIP64 is finally implemented, otherwise - * some serious checking has to be done. - * - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_ZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_endian.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#ifndef HAVE_ZLIB_H -#include "archive_crc32.h" -#endif - -#define ZIP_SIGNATURE_LOCAL_FILE_HEADER 0x04034b50 -#define ZIP_SIGNATURE_DATA_DESCRIPTOR 0x08074b50 -#define ZIP_SIGNATURE_FILE_HEADER 0x02014b50 -#define ZIP_SIGNATURE_CENTRAL_DIRECTORY_END 0x06054b50 -#define ZIP_SIGNATURE_EXTRA_TIMESTAMP 0x5455 -#define ZIP_SIGNATURE_EXTRA_UNIX 0x7855 -#define ZIP_VERSION_EXTRACT 0x0014 /* ZIP version 2.0 is needed. */ -#define ZIP_VERSION_BY 0x0314 /* Made by UNIX, using ZIP version 2.0. */ -#define ZIP_FLAGS 0x08 /* Flagging bit 3 (count from 0) for using data descriptor. */ - -enum compression { - COMPRESSION_STORE = 0 -#ifdef HAVE_ZLIB_H - , - COMPRESSION_DEFLATE = 8 -#endif -}; - -static ssize_t archive_write_zip_data(struct archive_write *, const void *buff, size_t s); -static int archive_write_zip_finish(struct archive_write *); -static int archive_write_zip_destroy(struct archive_write *); -static int archive_write_zip_finish_entry(struct archive_write *); -static int archive_write_zip_header(struct archive_write *, struct archive_entry *); -static unsigned int dos_time(const time_t); -static size_t path_length(struct archive_entry *); -static int write_path(struct archive_entry *, struct archive_write *); - -struct zip_local_file_header { - char signature[4]; - char version[2]; - char flags[2]; - char compression[2]; - char timedate[4]; - char crc32[4]; - char compressed_size[4]; - char uncompressed_size[4]; - char filename_length[2]; - char extra_length[2]; -}; - -struct zip_file_header { - char signature[4]; - char version_by[2]; - char version_extract[2]; - char flags[2]; - char compression[2]; - char timedate[4]; - char crc32[4]; - char compressed_size[4]; - char uncompressed_size[4]; - char filename_length[2]; - char extra_length[2]; - char comment_length[2]; - char disk_number[2]; - char attributes_internal[2]; - char attributes_external[4]; - char offset[4]; -}; - -struct zip_data_descriptor { - char signature[4]; /* Not mandatory, but recommended by specification. */ - char crc32[4]; - char compressed_size[4]; - char uncompressed_size[4]; -}; - -struct zip_extra_data_local { - char time_id[2]; - char time_size[2]; - char time_flag[1]; - char mtime[4]; - char atime[4]; - char ctime[4]; - char unix_id[2]; - char unix_size[2]; - char unix_uid[2]; - char unix_gid[2]; -}; - -struct zip_extra_data_central { - char time_id[2]; - char time_size[2]; - char time_flag[1]; - char mtime[4]; - char unix_id[2]; - char unix_size[2]; -}; - -struct zip_file_header_link { - struct zip_file_header_link *next; - struct archive_entry *entry; - off_t offset; - unsigned long crc32; - off_t compressed_size; - enum compression compression; -}; - -struct zip { - struct zip_data_descriptor data_descriptor; - struct zip_file_header_link *central_directory; - struct zip_file_header_link *central_directory_end; - int64_t offset; - int64_t written_bytes; - int64_t remaining_data_bytes; - enum compression compression; - -#ifdef HAVE_ZLIB_H - z_stream stream; - size_t len_buf; - unsigned char *buf; -#endif -}; - -struct zip_central_directory_end { - char signature[4]; - char disk[2]; - char start_disk[2]; - char entries_disk[2]; - char entries[2]; - char size[4]; - char offset[4]; - char comment_length[2]; -}; - -static int -archive_write_zip_options(struct archive_write *a, const char *key, - const char *value) -{ - struct zip *zip = a->format_data; - - if (strcmp(key, "compression") == 0) { - if (strcmp(value, "deflate") == 0) { -#ifdef HAVE_ZLIB_H - zip->compression = COMPRESSION_DEFLATE; -#else - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "deflate compression not supported"); - return ARCHIVE_WARN; -#endif - } else if (strcmp(value, "store") == 0) - zip->compression = COMPRESSION_STORE; - else - return (ARCHIVE_WARN); - return (ARCHIVE_OK); - } - return (ARCHIVE_WARN); -} - -int -archive_write_set_format_zip(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct zip *zip; - - /* If another format was already registered, unregister it. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - zip = (struct zip *) calloc(1, sizeof(*zip)); - if (zip == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate zip data"); - return (ARCHIVE_FATAL); - } - zip->central_directory = NULL; - zip->central_directory_end = NULL; - zip->offset = 0; - zip->written_bytes = 0; - zip->remaining_data_bytes = 0; - -#ifdef HAVE_ZLIB_H - zip->compression = COMPRESSION_DEFLATE; - zip->len_buf = 65536; - zip->buf = malloc(zip->len_buf); - if (zip->buf == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate compression buffer"); - return (ARCHIVE_FATAL); - } -#else - zip->compression = COMPRESSION_STORE; -#endif - - a->format_data = zip; - - a->pad_uncompressed = 0; /* Actually not needed for now, since no compression support yet. */ - a->format_name = "zip"; - a->format_options = archive_write_zip_options; - a->format_write_header = archive_write_zip_header; - a->format_write_data = archive_write_zip_data; - a->format_finish_entry = archive_write_zip_finish_entry; - a->format_finish = archive_write_zip_finish; - a->format_destroy = archive_write_zip_destroy; - a->archive.archive_format = ARCHIVE_FORMAT_ZIP; - a->archive.archive_format_name = "ZIP"; - - archive_le32enc(&zip->data_descriptor.signature, - ZIP_SIGNATURE_DATA_DESCRIPTOR); - - return (ARCHIVE_OK); -} - -static int -archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) -{ - struct zip *zip; - struct zip_local_file_header h; - struct zip_extra_data_local e; - struct zip_data_descriptor *d; - struct zip_file_header_link *l; - int ret; - int64_t size; - mode_t type; - - /* Entries other than a regular file or a folder are skipped. */ - type = archive_entry_filetype(entry); - if ((type != AE_IFREG) & (type != AE_IFDIR)) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Filetype not supported"); - return ARCHIVE_FAILED; - }; - - /* Directory entries should have a size of 0. */ - if (type == AE_IFDIR) - archive_entry_set_size(entry, 0); - - zip = a->format_data; - d = &zip->data_descriptor; - size = archive_entry_size(entry); - zip->remaining_data_bytes = size; - - /* Append archive entry to the central directory data. */ - l = (struct zip_file_header_link *) malloc(sizeof(*l)); - if (l == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate zip header data"); - return (ARCHIVE_FATAL); - } - l->entry = archive_entry_clone(entry); - /* Initialize the CRC variable and potentially the local crc32(). */ - l->crc32 = crc32(0, NULL, 0); - l->compression = zip->compression; - l->compressed_size = 0; - l->next = NULL; - if (zip->central_directory == NULL) { - zip->central_directory = l; - } else { - zip->central_directory_end->next = l; - } - zip->central_directory_end = l; - - /* Store the offset of this header for later use in central directory. */ - l->offset = zip->written_bytes; - - memset(&h, 0, sizeof(h)); - archive_le32enc(&h.signature, ZIP_SIGNATURE_LOCAL_FILE_HEADER); - archive_le16enc(&h.version, ZIP_VERSION_EXTRACT); - archive_le16enc(&h.flags, ZIP_FLAGS); - archive_le16enc(&h.compression, zip->compression); - archive_le32enc(&h.timedate, dos_time(archive_entry_mtime(entry))); - archive_le16enc(&h.filename_length, (uint16_t)path_length(entry)); - - switch (zip->compression) { - case COMPRESSION_STORE: - /* Setting compressed and uncompressed sizes even when specification says - * to set to zero when using data descriptors. Otherwise the end of the - * data for an entry is rather difficult to find. */ - archive_le32enc(&h.compressed_size, size); - archive_le32enc(&h.uncompressed_size, size); - break; -#ifdef HAVE_ZLIB_H - case COMPRESSION_DEFLATE: - archive_le32enc(&h.uncompressed_size, size); - - zip->stream.zalloc = Z_NULL; - zip->stream.zfree = Z_NULL; - zip->stream.opaque = Z_NULL; - zip->stream.next_out = zip->buf; - zip->stream.avail_out = zip->len_buf; - if (deflateInit2(&zip->stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, - -15, 8, Z_DEFAULT_STRATEGY) != Z_OK) { - archive_set_error(&a->archive, ENOMEM, "Can't init deflate compressor"); - return (ARCHIVE_FATAL); - } - break; -#endif - } - - /* Formatting extra data. */ - archive_le16enc(&h.extra_length, sizeof(e)); - archive_le16enc(&e.time_id, ZIP_SIGNATURE_EXTRA_TIMESTAMP); - archive_le16enc(&e.time_size, sizeof(e.time_flag) + - sizeof(e.mtime) + sizeof(e.atime) + sizeof(e.ctime)); - e.time_flag[0] = 0x07; - archive_le32enc(&e.mtime, archive_entry_mtime(entry)); - archive_le32enc(&e.atime, archive_entry_atime(entry)); - archive_le32enc(&e.ctime, archive_entry_ctime(entry)); - - archive_le16enc(&e.unix_id, ZIP_SIGNATURE_EXTRA_UNIX); - archive_le16enc(&e.unix_size, sizeof(e.unix_uid) + sizeof(e.unix_gid)); - archive_le16enc(&e.unix_uid, archive_entry_uid(entry)); - archive_le16enc(&e.unix_gid, archive_entry_gid(entry)); - - archive_le32enc(&d->uncompressed_size, size); - - ret = (a->compressor.write)(a, &h, sizeof(h)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(h); - - ret = write_path(entry, a); - if (ret <= ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += ret; - - ret = (a->compressor.write)(a, &e, sizeof(e)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(e); - - return (ARCHIVE_OK); -} - -static ssize_t -archive_write_zip_data(struct archive_write *a, const void *buff, size_t s) -{ - int ret; - struct zip *zip = a->format_data; - struct zip_file_header_link *l = zip->central_directory_end; - - if ((int64_t)s > zip->remaining_data_bytes) - s = (size_t)zip->remaining_data_bytes; - - if (s == 0) return 0; - - switch (zip->compression) { - case COMPRESSION_STORE: - ret = (a->compressor.write)(a, buff, s); - if (ret != ARCHIVE_OK) return (ret); - zip->written_bytes += s; - zip->remaining_data_bytes -= s; - l->compressed_size += s; - l->crc32 = crc32(l->crc32, buff, s); - return (s); -#if HAVE_ZLIB_H - case COMPRESSION_DEFLATE: - zip->stream.next_in = (unsigned char*)(uintptr_t)buff; - zip->stream.avail_in = s; - do { - ret = deflate(&zip->stream, Z_NO_FLUSH); - if (ret == Z_STREAM_ERROR) - return (ARCHIVE_FATAL); - if (zip->stream.avail_out == 0) { - ret = (a->compressor.write)(a, zip->buf, zip->len_buf); - if (ret != ARCHIVE_OK) - return (ret); - l->compressed_size += zip->len_buf; - zip->written_bytes += zip->len_buf; - zip->stream.next_out = zip->buf; - zip->stream.avail_out = zip->len_buf; - } - } while (zip->stream.avail_in != 0); - zip->remaining_data_bytes -= s; - /* If we have it, use zlib's fast crc32() */ - l->crc32 = crc32(l->crc32, buff, s); - return (s); -#endif - - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid ZIP compression type"); - return ARCHIVE_FATAL; - } -} - -static int -archive_write_zip_finish_entry(struct archive_write *a) -{ - /* Write the data descripter after file data has been written. */ - int ret; - struct zip *zip = a->format_data; - struct zip_data_descriptor *d = &zip->data_descriptor; - struct zip_file_header_link *l = zip->central_directory_end; -#if HAVE_ZLIB_H - size_t reminder; -#endif - - switch(zip->compression) { - case COMPRESSION_STORE: - break; -#if HAVE_ZLIB_H - case COMPRESSION_DEFLATE: - for (;;) { - ret = deflate(&zip->stream, Z_FINISH); - if (ret == Z_STREAM_ERROR) - return (ARCHIVE_FATAL); - reminder = zip->len_buf - zip->stream.avail_out; - ret = (a->compressor.write)(a, zip->buf, reminder); - if (ret != ARCHIVE_OK) - return (ret); - l->compressed_size += reminder; - zip->written_bytes += reminder; - zip->stream.next_out = zip->buf; - if (zip->stream.avail_out != 0) - break; - zip->stream.avail_out = zip->len_buf; - } - deflateEnd(&zip->stream); - break; -#endif - } - - archive_le32enc(&d->crc32, l->crc32); - archive_le32enc(&d->compressed_size, l->compressed_size); - ret = (a->compressor.write)(a, d, sizeof(*d)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(*d); - return (ARCHIVE_OK); -} - -static int -archive_write_zip_finish(struct archive_write *a) -{ - struct zip *zip; - struct zip_file_header_link *l; - struct zip_file_header h; - struct zip_central_directory_end end; - struct zip_extra_data_central e; - off_t offset_start, offset_end; - int entries; - int ret; - - if (a->compressor.write == NULL) - return (ARCHIVE_OK); - - zip = a->format_data; - l = zip->central_directory; - - /* - * Formatting central directory file header fields that are fixed for all entries. - * Fields not used (and therefor 0) are: - * - * - comment_length - * - disk_number - * - attributes_internal - */ - memset(&h, 0, sizeof(h)); - archive_le32enc(&h.signature, ZIP_SIGNATURE_FILE_HEADER); - archive_le16enc(&h.version_by, ZIP_VERSION_BY); - archive_le16enc(&h.version_extract, ZIP_VERSION_EXTRACT); - archive_le16enc(&h.flags, ZIP_FLAGS); - - entries = 0; - offset_start = zip->written_bytes; - - /* Formatting individual header fields per entry and - * writing each entry. */ - while (l != NULL) { - archive_le16enc(&h.compression, l->compression); - archive_le32enc(&h.timedate, dos_time(archive_entry_mtime(l->entry))); - archive_le32enc(&h.crc32, l->crc32); - archive_le32enc(&h.compressed_size, l->compressed_size); - archive_le32enc(&h.uncompressed_size, archive_entry_size(l->entry)); - archive_le16enc(&h.filename_length, (uint16_t)path_length(l->entry)); - archive_le16enc(&h.extra_length, sizeof(e)); - archive_le16enc(&h.attributes_external[2], archive_entry_mode(l->entry)); - archive_le32enc(&h.offset, l->offset); - - /* Formatting extra data. */ - archive_le16enc(&e.time_id, ZIP_SIGNATURE_EXTRA_TIMESTAMP); - archive_le16enc(&e.time_size, sizeof(e.mtime) + sizeof(e.time_flag)); - e.time_flag[0] = 0x07; - archive_le32enc(&e.mtime, archive_entry_mtime(l->entry)); - archive_le16enc(&e.unix_id, ZIP_SIGNATURE_EXTRA_UNIX); - archive_le16enc(&e.unix_size, 0x0000); - - ret = (a->compressor.write)(a, &h, sizeof(h)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(h); - - ret = write_path(l->entry, a); - if (ret <= ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += ret; - - ret = (a->compressor.write)(a, &e, sizeof(e)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(e); - - l = l->next; - entries++; - } - offset_end = zip->written_bytes; - - /* Formatting end of central directory. */ - memset(&end, 0, sizeof(end)); - archive_le32enc(&end.signature, ZIP_SIGNATURE_CENTRAL_DIRECTORY_END); - archive_le16enc(&end.entries_disk, entries); - archive_le16enc(&end.entries, entries); - archive_le32enc(&end.size, offset_end - offset_start); - archive_le32enc(&end.offset, offset_start); - - /* Writing end of central directory. */ - ret = (a->compressor.write)(a, &end, sizeof(end)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(end); - return (ARCHIVE_OK); -} - -static int -archive_write_zip_destroy(struct archive_write *a) -{ - struct zip *zip; - struct zip_file_header_link *l; - - zip = a->format_data; - while (zip->central_directory != NULL) { - l = zip->central_directory; - zip->central_directory = l->next; - archive_entry_free(l->entry); - free(l); - } -#ifdef HAVE_ZLIB_H - free(zip->buf); -#endif - free(zip); - a->format_data = NULL; - return (ARCHIVE_OK); -} - -/* Convert into MSDOS-style date/time. */ -static unsigned int -dos_time(const time_t unix_time) -{ - struct tm *t; - unsigned int dt; - - /* This will not preserve time when creating/extracting the archive - * on two systems with different time zones. */ - t = localtime(&unix_time); - - dt = 0; - dt += ((t->tm_year - 80) & 0x7f) << 9; - dt += ((t->tm_mon + 1) & 0x0f) << 5; - dt += (t->tm_mday & 0x1f); - dt <<= 16; - dt += (t->tm_hour & 0x1f) << 11; - dt += (t->tm_min & 0x3f) << 5; - dt += (t->tm_sec & 0x3e) >> 1; /* Only counting every 2 seconds. */ - return dt; -} - -static size_t -path_length(struct archive_entry *entry) -{ - mode_t type; - const char *path; - - type = archive_entry_filetype(entry); - path = archive_entry_pathname(entry); - - if ((type == AE_IFDIR) & (path[strlen(path) - 1] != '/')) { - return strlen(path) + 1; - } else { - return strlen(path); - } -} - -static int -write_path(struct archive_entry *entry, struct archive_write *archive) -{ - int ret; - const char *path; - mode_t type; - size_t written_bytes; - - path = archive_entry_pathname(entry); - type = archive_entry_filetype(entry); - written_bytes = 0; - - ret = (archive->compressor.write)(archive, path, strlen(path)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - written_bytes += strlen(path); - - /* Folders are recognized by a traling slash. */ - if ((type == AE_IFDIR) & (path[strlen(path) - 1] != '/')) { - ret = (archive->compressor.write)(archive, "/", 1); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - written_bytes += 1; - } - - return ((int)written_bytes); -} diff --git a/lib/libarchive/cpio.5 b/lib/libarchive/cpio.5 deleted file mode 100644 index 5bc60fe..0000000 --- a/lib/libarchive/cpio.5 +++ /dev/null @@ -1,325 +0,0 @@ -.\" Copyright (c) 2007 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd October 5, 2007 -.Dt CPIO 5 -.Os -.Sh NAME -.Nm cpio -.Nd format of cpio archive files -.Sh DESCRIPTION -The -.Nm -archive format collects any number of files, directories, and other -file system objects (symbolic links, device nodes, etc.) into a single -stream of bytes. -.Ss General Format -Each file system object in a -.Nm -archive comprises a header record with basic numeric metadata -followed by the full pathname of the entry and the file data. -The header record stores a series of integer values that generally -follow the fields in -.Va struct stat . -(See -.Xr stat 2 -for details.) -The variants differ primarily in how they store those integers -(binary, octal, or hexadecimal). -The header is followed by the pathname of the -entry (the length of the pathname is stored in the header) -and any file data. -The end of the archive is indicated by a special record with -the pathname -.Dq TRAILER!!! . -.Ss PWB format -XXX Any documentation of the original PWB/UNIX 1.0 format? XXX -.Ss Old Binary Format -The old binary -.Nm -format stores numbers as 2-byte and 4-byte binary values. -Each entry begins with a header in the following format: -.Bd -literal -offset indent -struct header_old_cpio { - unsigned short c_magic; - unsigned short c_dev; - unsigned short c_ino; - unsigned short c_mode; - unsigned short c_uid; - unsigned short c_gid; - unsigned short c_nlink; - unsigned short c_rdev; - unsigned short c_mtime[2]; - unsigned short c_namesize; - unsigned short c_filesize[2]; -}; -.Ed -.Pp -The -.Va unsigned short -fields here are 16-bit integer values; the -.Va unsigned int -fields are 32-bit integer values. -The fields are as follows -.Bl -tag -width indent -.It Va magic -The integer value octal 070707. -This value can be used to determine whether this archive is -written with little-endian or big-endian integers. -.It Va dev , Va ino -The device and inode numbers from the disk. -These are used by programs that read -.Nm -archives to determine when two entries refer to the same file. -Programs that synthesize -.Nm -archives should be careful to set these to distinct values for each entry. -.It Va mode -The mode specifies both the regular permissions and the file type. -It consists of several bit fields as follows: -.Bl -tag -width "MMMMMMM" -compact -.It 0170000 -This masks the file type bits. -.It 0140000 -File type value for sockets. -.It 0120000 -File type value for symbolic links. -For symbolic links, the link body is stored as file data. -.It 0100000 -File type value for regular files. -.It 0060000 -File type value for block special devices. -.It 0040000 -File type value for directories. -.It 0020000 -File type value for character special devices. -.It 0010000 -File type value for named pipes or FIFOs. -.It 0004000 -SUID bit. -.It 0002000 -SGID bit. -.It 0001000 -Sticky bit. -On some systems, this modifies the behavior of executables and/or directories. -.It 0000777 -The lower 9 bits specify read/write/execute permissions -for world, group, and user following standard POSIX conventions. -.El -.It Va uid , Va gid -The numeric user id and group id of the owner. -.It Va nlink -The number of links to this file. -Directories always have a value of at least two here. -Note that hardlinked files include file data with every copy in the archive. -.It Va rdev -For block special and character special entries, -this field contains the associated device number. -For all other entry types, it should be set to zero by writers -and ignored by readers. -.It Va mtime -Modification time of the file, indicated as the number -of seconds since the start of the epoch, -00:00:00 UTC January 1, 1970. -The four-byte integer is stored with the most-significant 16 bits first -followed by the least-significant 16 bits. -Each of the two 16 bit values are stored in machine-native byte order. -.It Va namesize -The number of bytes in the pathname that follows the header. -This count includes the trailing NUL byte. -.It Va filesize -The size of the file. -Note that this archive format is limited to -four gigabyte file sizes. -See -.Va mtime -above for a description of the storage of four-byte integers. -.El -.Pp -The pathname immediately follows the fixed header. -If the -.Cm namesize -is odd, an additional NUL byte is added after the pathname. -The file data is then appended, padded with NUL -bytes to an even length. -.Pp -Hardlinked files are not given special treatment; -the full file contents are included with each copy of the -file. -.Ss Portable ASCII Format -.St -susv2 -standardized an ASCII variant that is portable across all -platforms. -It is commonly known as the -.Dq old character -format or as the -.Dq odc -format. -It stores the same numeric fields as the old binary format, but -represents them as 6-character or 11-character octal values. -.Bd -literal -offset indent -struct cpio_odc_header { - char c_magic[6]; - char c_dev[6]; - char c_ino[6]; - char c_mode[6]; - char c_uid[6]; - char c_gid[6]; - char c_nlink[6]; - char c_rdev[6]; - char c_mtime[11]; - char c_namesize[6]; - char c_filesize[11]; -}; -.Ed -.Pp -The fields are identical to those in the old binary format. -The name and file body follow the fixed header. -Unlike the old binary format, there is no additional padding -after the pathname or file contents. -If the files being archived are themselves entirely ASCII, then -the resulting archive will be entirely ASCII, except for the -NUL byte that terminates the name field. -.Ss New ASCII Format -The "new" ASCII format uses 8-byte hexadecimal fields for -all numbers and separates device numbers into separate fields -for major and minor numbers. -.Bd -literal -offset indent -struct cpio_newc_header { - char c_magic[6]; - char c_ino[8]; - char c_mode[8]; - char c_uid[8]; - char c_gid[8]; - char c_nlink[8]; - char c_mtime[8]; - char c_filesize[8]; - char c_devmajor[8]; - char c_devminor[8]; - char c_rdevmajor[8]; - char c_rdevminor[8]; - char c_namesize[8]; - char c_check[8]; -}; -.Ed -.Pp -Except as specified below, the fields here match those specified -for the old binary format above. -.Bl -tag -width indent -.It Va magic -The string -.Dq 070701 . -.It Va check -This field is always set to zero by writers and ignored by readers. -See the next section for more details. -.El -.Pp -The pathname is followed by NUL bytes so that the total size -of the fixed header plus pathname is a multiple of four. -Likewise, the file data is padded to a multiple of four bytes. -Note that this format supports only 4 gigabyte files (unlike the -older ASCII format, which supports 8 gigabyte files). -.Pp -In this format, hardlinked files are handled by setting the -filesize to zero for each entry except the last one that -appears in the archive. -.Ss New CRC Format -The CRC format is identical to the new ASCII format described -in the previous section except that the magic field is set -to -.Dq 070702 -and the -.Va check -field is set to the sum of all bytes in the file data. -This sum is computed treating all bytes as unsigned values -and using unsigned arithmetic. -Only the least-significant 32 bits of the sum are stored. -.Ss HP variants -The -.Nm cpio -implementation distributed with HPUX used XXXX but stored -device numbers differently XXX. -.Ss Other Extensions and Variants -Sun Solaris uses additional file types to store extended file -data, including ACLs and extended attributes, as special -entries in cpio archives. -.Pp -XXX Others? XXX -.Sh SEE ALSO -.Xr cpio 1 , -.Xr tar 5 -.Sh STANDARDS -The -.Nm cpio -utility is no longer a part of POSIX or the Single Unix Standard. -It last appeared in -.St -susv2 . -It has been supplanted in subsequent standards by -.Xr pax 1 . -The portable ASCII format is currently part of the specification for the -.Xr pax 1 -utility. -.Sh HISTORY -The original cpio utility was written by Dick Haight -while working in AT&T's Unix Support Group. -It appeared in 1977 as part of PWB/UNIX 1.0, the -.Dq Programmer's Work Bench -derived from -.At v6 -that was used internally at AT&T. -Both the old binary and old character formats were in use -by 1980, according to the System III source released -by SCO under their -.Dq Ancient Unix -license. -The character format was adopted as part of -.St -p1003.1-88 . -XXX when did "newc" appear? Who invented it? When did HP come out with their variant? When did Sun introduce ACLs and extended attributes? XXX -.Sh BUGS -The -.Dq CRC -format is mis-named, as it uses a simple checksum and -not a cyclic redundancy check. -.Pp -The old binary format is limited to 16 bits for user id, -group id, device, and inode numbers. -It is limited to 4 gigabyte file sizes. -.Pp -The old ASCII format is limited to 18 bits for -the user id, group id, device, and inode numbers. -It is limited to 8 gigabyte file sizes. -.Pp -The new ASCII format is limited to 4 gigabyte file sizes. -.Pp -None of the cpio formats store user or group names, -which are essential when moving files between systems with -dissimilar user or group numbering. -.Pp -Especially when writing older cpio variants, it may be necessary -to map actual device/inode values to synthesized values that -fit the available fields. -With very large filesystems, this may be necessary even for -the newer formats. diff --git a/lib/libarchive/filter_fork.c b/lib/libarchive/filter_fork.c deleted file mode 100644 index d2a1e88..0000000 --- a/lib/libarchive/filter_fork.c +++ /dev/null @@ -1,161 +0,0 @@ -/*- - * Copyright (c) 2007 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" - -/* This capability is only available on POSIX systems. */ -#if defined(HAVE_PIPE) && defined(HAVE_FCNTL) && \ - (defined(HAVE_FORK) || defined(HAVE_VFORK)) - -__FBSDID("$FreeBSD$"); - -#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H)) -# if defined(HAVE_POLL_H) -# include -# elif defined(HAVE_SYS_POLL_H) -# include -# endif -#elif defined(HAVE_SELECT) -# if defined(HAVE_SYS_SELECT_H) -# include -# elif defined(HAVE_UNISTD_H) -# include -# endif -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif - -#include "filter_fork.h" - -pid_t -__archive_create_child(const char *path, int *child_stdin, int *child_stdout) -{ - pid_t child; - int stdin_pipe[2], stdout_pipe[2], tmp; - - if (pipe(stdin_pipe) == -1) - goto state_allocated; - if (stdin_pipe[0] == 1 /* stdout */) { - if ((tmp = dup(stdin_pipe[0])) == -1) - goto stdin_opened; - close(stdin_pipe[0]); - stdin_pipe[0] = tmp; - } - if (pipe(stdout_pipe) == -1) - goto stdin_opened; - if (stdout_pipe[1] == 0 /* stdin */) { - if ((tmp = dup(stdout_pipe[1])) == -1) - goto stdout_opened; - close(stdout_pipe[1]); - stdout_pipe[1] = tmp; - } - -#if HAVE_VFORK - switch ((child = vfork())) { -#else - switch ((child = fork())) { -#endif - case -1: - goto stdout_opened; - case 0: - close(stdin_pipe[1]); - close(stdout_pipe[0]); - if (dup2(stdin_pipe[0], 0 /* stdin */) == -1) - _exit(254); - if (stdin_pipe[0] != 0 /* stdin */) - close(stdin_pipe[0]); - if (dup2(stdout_pipe[1], 1 /* stdout */) == -1) - _exit(254); - if (stdout_pipe[1] != 1 /* stdout */) - close(stdout_pipe[1]); - execlp(path, path, (char *)NULL); - _exit(254); - default: - close(stdin_pipe[0]); - close(stdout_pipe[1]); - - *child_stdin = stdin_pipe[1]; - fcntl(*child_stdin, F_SETFL, O_NONBLOCK); - *child_stdout = stdout_pipe[0]; - fcntl(*child_stdout, F_SETFL, O_NONBLOCK); - } - - return child; - -stdout_opened: - close(stdout_pipe[0]); - close(stdout_pipe[1]); -stdin_opened: - close(stdin_pipe[0]); - close(stdin_pipe[1]); -state_allocated: - return -1; -} - -void -__archive_check_child(int in, int out) -{ -#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H)) - struct pollfd fds[2]; - int idx; - - idx = 0; - if (in != -1) { - fds[idx].fd = in; - fds[idx].events = POLLOUT; - ++idx; - } - if (out != -1) { - fds[idx].fd = out; - fds[idx].events = POLLIN; - ++idx; - } - - poll(fds, idx, -1); /* -1 == INFTIM, wait forever */ -#elif defined(HAVE_SELECT) - fd_set fds_in, fds_out, fds_error; - - FD_ZERO(&fds_in); - FD_ZERO(&fds_out); - FD_ZERO(&fds_error); - if (out != -1) { - FD_SET(out, &fds_in); - FD_SET(out, &fds_error); - } - if (in != -1) { - FD_SET(in, &fds_out); - FD_SET(in, &fds_error); - } - select(in < out ? out + 1 : in + 1, &fds_in, &fds_out, &fds_error, NULL); -#else - sleep(1); -#endif -} - -#endif /* defined(HAVE_PIPE) && defined(HAVE_VFORK) && defined(HAVE_FCNTL) */ diff --git a/lib/libarchive/filter_fork.h b/lib/libarchive/filter_fork.h deleted file mode 100644 index 77ff71b..0000000 --- a/lib/libarchive/filter_fork.h +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * Copyright (c) 2007 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifndef FILTER_FORK_H -#define FILTER_FORK_H - -pid_t -__archive_create_child(const char *path, int *child_stdin, int *child_stdout); - -void -__archive_check_child(int in, int out); - -#endif diff --git a/lib/libarchive/libarchive-formats.5 b/lib/libarchive/libarchive-formats.5 deleted file mode 100644 index e6849b9..0000000 --- a/lib/libarchive/libarchive-formats.5 +++ /dev/null @@ -1,355 +0,0 @@ -.\" Copyright (c) 2003-2009 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd December 27, 2009 -.Dt LIBARCHIVE-FORMATS 5 -.Os -.Sh NAME -.Nm libarchive-formats -.Nd archive formats supported by the libarchive library -.Sh DESCRIPTION -The -.Xr libarchive 3 -library reads and writes a variety of streaming archive formats. -Generally speaking, all of these archive formats consist of a series of -.Dq entries . -Each entry stores a single file system object, such as a file, directory, -or symbolic link. -.Pp -The following provides a brief description of each format supported -by libarchive, with some information about recognized extensions or -limitations of the current library support. -Note that just because a format is supported by libarchive does not -imply that a program that uses libarchive will support that format. -Applications that use libarchive specify which formats they wish -to support, though many programs do use libarchive convenience -functions to enable all supported formats. -.Ss Tar Formats -The -.Xr libarchive 3 -library can read most tar archives. -However, it only writes POSIX-standard -.Dq ustar -and -.Dq pax interchange -formats. -.Pp -All tar formats store each entry in one or more 512-byte records. -The first record is used for file metadata, including filename, -timestamp, and mode information, and the file data is stored in -subsequent records. -Later variants have extended this by either appropriating undefined -areas of the header record, extending the header to multiple records, -or by storing special entries that modify the interpretation of -subsequent entries. -.Pp -.Bl -tag -width indent -.It Cm gnutar -The -.Xr libarchive 3 -library can read GNU-format tar archives. -It currently supports the most popular GNU extensions, including -modern long filename and linkname support, as well as atime and ctime data. -The libarchive library does not support multi-volume -archives, nor the old GNU long filename format. -It can read GNU sparse file entries, including the new POSIX-based -formats, but cannot write GNU sparse file entries. -.It Cm pax -The -.Xr libarchive 3 -library can read and write POSIX-compliant pax interchange format -archives. -Pax interchange format archives are an extension of the older ustar -format that adds a separate entry with additional attributes stored -as key/value pairs immediately before each regular entry. -The presence of these additional entries is the only difference between -pax interchange format and the older ustar format. -The extended attributes are of unlimited length and are stored -as UTF-8 Unicode strings. -Keywords defined in the standard are in all lowercase; vendors are allowed -to define custom keys by preceding them with the vendor name in all uppercase. -When writing pax archives, libarchive uses many of the SCHILY keys -defined by Joerg Schilling's -.Dq star -archiver and a few LIBARCHIVE keys. -The libarchive library can read most of the SCHILY keys -and most of the GNU keys introduced by GNU tar. -It silently ignores any keywords that it does not understand. -.It Cm restricted pax -The libarchive library can also write pax archives in which it -attempts to suppress the extended attributes entry whenever -possible. -The result will be identical to a ustar archive unless the -extended attributes entry is required to store a long file -name, long linkname, extended ACL, file flags, or if any of the standard -ustar data (user name, group name, UID, GID, etc) cannot be fully -represented in the ustar header. -In all cases, the result can be dearchived by any program that -can read POSIX-compliant pax interchange format archives. -Programs that correctly read ustar format (see below) will also be -able to read this format; any extended attributes will be extracted as -separate files stored in -.Pa PaxHeader -directories. -.It Cm ustar -The libarchive library can both read and write this format. -This format has the following limitations: -.Bl -bullet -compact -.It -Device major and minor numbers are limited to 21 bits. -Nodes with larger numbers will not be added to the archive. -.It -Path names in the archive are limited to 255 bytes. -(Shorter if there is no / character in exactly the right place.) -.It -Symbolic links and hard links are stored in the archive with -the name of the referenced file. -This name is limited to 100 bytes. -.It -Extended attributes, file flags, and other extended -security information cannot be stored. -.It -Archive entries are limited to 8 gigabytes in size. -.El -Note that the pax interchange format has none of these restrictions. -.El -.Pp -The libarchive library also reads a variety of commonly-used extensions to -the basic tar format. -These extensions are recognized automatically whenever they appear. -.Bl -tag -width indent -.It Numeric extensions. -The POSIX standards require fixed-length numeric fields to be written with -some character position reserved for terminators. -Libarchive allows these fields to be written without terminator characters. -This extends the allowable range; in particular, ustar archives with this -extension can support entries up to 64 gigabytes in size. -Libarchive also recognizes base-256 values in most numeric fields. -This essentially removes all limitations on file size, modification time, -and device numbers. -.It Solaris extensions -Libarchive recognizes ACL and extended attribute records written -by Solaris tar. -Currently, libarchive only has support for old-style ACLs; the -newer NFSv4 ACLs are recognized but discarded. -.El -.Pp -The first tar program appeared in Seventh Edition Unix in 1979. -The first official standard for the tar file format was the -.Dq ustar -(Unix Standard Tar) format defined by POSIX in 1988. -POSIX.1-2001 extended the ustar format to create the -.Dq pax interchange -format. -.Ss Cpio Formats -The libarchive library can read a number of common cpio variants and can write -.Dq odc -and -.Dq newc -format archives. -A cpio archive stores each entry as a fixed-size header followed -by a variable-length filename and variable-length data. -Unlike the tar format, the cpio format does only minimal padding -of the header or file data. -There are several cpio variants, which differ primarily in -how they store the initial header: some store the values as -octal or hexadecimal numbers in ASCII, others as binary values of -varying byte order and length. -.Bl -tag -width indent -.It Cm binary -The libarchive library transparently reads both big-endian and little-endian -variants of the original binary cpio format. -This format used 32-bit binary values for file size and mtime, -and 16-bit binary values for the other fields. -.It Cm odc -The libarchive library can both read and write this -POSIX-standard format, which is officially known as the -.Dq cpio interchange format -or the -.Dq octet-oriented cpio archive format -and sometimes unofficially referred to as the -.Dq old character format . -This format stores the header contents as octal values in ASCII. -It is standard, portable, and immune from byte-order confusion. -File sizes and mtime are limited to 33 bits (8GB file size), -other fields are limited to 18 bits. -.It Cm SVR4 -The libarchive library can read both CRC and non-CRC variants of -this format. -The SVR4 format uses eight-digit hexadecimal values for -all header fields. -This limits file size to 4GB, and also limits the mtime and -other fields to 32 bits. -The SVR4 format can optionally include a CRC of the file -contents, although libarchive does not currently verify this CRC. -.El -.Pp -Cpio first appeared in PWB/UNIX 1.0, which was released within -AT&T in 1977. -PWB/UNIX 1.0 formed the basis of System III Unix, released outside -of AT&T in 1981. -This makes cpio older than tar, although cpio was not included -in Version 7 AT&T Unix. -As a result, the tar command became much better known in universities -and research groups that used Version 7. -The combination of the -.Nm find -and -.Nm cpio -utilities provided very precise control over file selection. -Unfortunately, the format has many limitations that make it unsuitable -for widespread use. -Only the POSIX format permits files over 4GB, and its 18-bit -limit for most other fields makes it unsuitable for modern systems. -In addition, cpio formats only store numeric UID/GID values (not -usernames and group names), which can make it very difficult to correctly -transfer archives across systems with dissimilar user numbering. -.Ss Shar Formats -A -.Dq shell archive -is a shell script that, when executed on a POSIX-compliant -system, will recreate a collection of file system objects. -The libarchive library can write two different kinds of shar archives: -.Bl -tag -width indent -.It Cm shar -The traditional shar format uses a limited set of POSIX -commands, including -.Xr echo 1 , -.Xr mkdir 1 , -and -.Xr sed 1 . -It is suitable for portably archiving small collections of plain text files. -However, it is not generally well-suited for large archives -(many implementations of -.Xr sh 1 -have limits on the size of a script) nor should it be used with non-text files. -.It Cm shardump -This format is similar to shar but encodes files using -.Xr uuencode 1 -so that the result will be a plain text file regardless of the file contents. -It also includes additional shell commands that attempt to reproduce as -many file attributes as possible, including owner, mode, and flags. -The additional commands used to restore file attributes make -shardump archives less portable than plain shar archives. -.El -.Ss ISO9660 format -Libarchive can read and extract from files containing ISO9660-compliant -CDROM images. -In many cases, this can remove the need to burn a physical CDROM -just in order to read the files contained in an ISO9660 image. -It also avoids security and complexity issues that come with -virtual mounts and loopback devices. -Libarchive supports the most common Rockridge extensions and has partial -support for Joliet extensions. -If both extensions are present, the Joliet extensions will be -used and the Rockridge extensions will be ignored. -In particular, this can create problems with hardlinks and symlinks, -which are supported by Rockridge but not by Joliet. -.Ss Zip format -Libarchive can read and write zip format archives that have -uncompressed entries and entries compressed with the -.Dq deflate -algorithm. -Older zip compression algorithms are not supported. -It can extract jar archives, archives that use Zip64 extensions and many -self-extracting zip archives. -Libarchive reads Zip archives as they are being streamed, -which allows it to read archives of arbitrary size. -It currently does not use the central directory; this -limits libarchive's ability to support some self-extracting -archives and ones that have been modified in certain ways. -.Ss Archive (library) file format -The Unix archive format (commonly created by the -.Xr ar 1 -archiver) is a general-purpose format which is -used almost exclusively for object files to be -read by the link editor -.Xr ld 1 . -The ar format has never been standardised. -There are two common variants: -the GNU format derived from SVR4, -and the BSD format, which first appeared in 4.4BSD. -The two differ primarily in their handling of filenames -longer than 15 characters: -the GNU/SVR4 variant writes a filename table at the beginning of the archive; -the BSD format stores each long filename in an extension -area adjacent to the entry. -Libarchive can read both extensions, -including archives that may include both types of long filenames. -Programs using libarchive can write GNU/SVR4 format -if they provide a filename table to be written into -the archive before any of the entries. -Any entries whose names are not in the filename table -will be written using BSD-style long filenames. -This can cause problems for programs such as -GNU ld that do not support the BSD-style long filenames. -.Ss mtree -Libarchive can read and write files in -.Xr mtree 5 -format. -This format is not a true archive format, but rather a textual description -of a file hierarchy in which each line specifies the name of a file and -provides specific metadata about that file. -Libarchive can read all of the keywords supported by both -the NetBSD and FreeBSD versions of -.Xr mtree 1 , -although many of the keywords cannot currently be stored in an -.Tn archive_entry -object. -When writing, libarchive supports use of the -.Xr archive_write_set_options 3 -interface to specify which keywords should be included in the -output. -If libarchive was compiled with access to suitable -cryptographic libraries (such as the OpenSSL libraries), -it can compute hash entries such as -.Cm sha512 -or -.Cm md5 -from file data being written to the mtree writer. -.Pp -When reading an mtree file, libarchive will locate the corresponding -files on disk using the -.Cm contents -keyword if present or the regular filename. -If it can locate and open the file on disk, it will use that -to fill in any metadata that is missing from the mtree file -and will read the file contents and return those to the program -using libarchive. -If it cannot locate and open the file on disk, libarchive -will return an error for any attempt to read the entry -body. -.Sh SEE ALSO -.Xr ar 1 , -.Xr cpio 1 , -.Xr mkisofs 1 , -.Xr shar 1 , -.Xr tar 1 , -.Xr zip 1 , -.Xr zlib 3 , -.Xr cpio 5 , -.Xr mtree 5 , -.Xr tar 5 diff --git a/lib/libarchive/libarchive.3 b/lib/libarchive/libarchive.3 deleted file mode 100644 index 70059dc..0000000 --- a/lib/libarchive/libarchive.3 +++ /dev/null @@ -1,371 +0,0 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd February 6, 2010 -.Dt LIBARCHIVE 3 -.Os -.Sh NAME -.Nm libarchive -.Nd functions for reading and writing streaming archives -.Sh LIBRARY -.Lb libarchive -.Sh OVERVIEW -The -.Nm -library provides a flexible interface for reading and writing -streaming archive files such as tar and cpio. -The library is inherently stream-oriented; readers serially iterate through -the archive, writers serially add things to the archive. -In particular, note that there is no built-in support for -random access nor for in-place modification. -.Pp -When reading an archive, the library automatically detects the -format and the compression. -The library currently has read support for: -.Bl -bullet -compact -.It -old-style tar archives, -.It -most variants of the POSIX -.Dq ustar -format, -.It -the POSIX -.Dq pax interchange -format, -.It -GNU-format tar archives, -.It -most common cpio archive formats, -.It -ISO9660 CD images (including RockRidge and Joliet extensions), -.It -Zip archives. -.El -The library automatically detects archives compressed with -.Xr gzip 1 , -.Xr bzip2 1 , -.Xr xz 1 , -or -.Xr compress 1 -and decompresses them transparently. -.Pp -When writing an archive, you can specify the compression -to be used and the format to use. -The library can write -.Bl -bullet -compact -.It -POSIX-standard -.Dq ustar -archives, -.It -POSIX -.Dq pax interchange format -archives, -.It -POSIX octet-oriented cpio archives, -.It -Zip archive, -.It -two different variants of shar archives. -.El -Pax interchange format is an extension of the tar archive format that -eliminates essentially all of the limitations of historic tar formats -in a standard fashion that is supported -by POSIX-compliant -.Xr pax 1 -implementations on many systems as well as several newer implementations of -.Xr tar 1 . -Note that the default write format will suppress the pax extended -attributes for most entries; explicitly requesting pax format will -enable those attributes for all entries. -.Pp -The read and write APIs are accessed through the -.Fn archive_read_XXX -functions and the -.Fn archive_write_XXX -functions, respectively, and either can be used independently -of the other. -.Pp -The rest of this manual page provides an overview of the library -operation. -More detailed information can be found in the individual manual -pages for each API or utility function. -.Sh READING AN ARCHIVE -To read an archive, you must first obtain an initialized -.Tn struct archive -object from -.Fn archive_read_new . -You can then modify this object for the desired operations with the -various -.Fn archive_read_set_XXX -and -.Fn archive_read_support_XXX -functions. -In particular, you will need to invoke appropriate -.Fn archive_read_support_XXX -functions to enable the corresponding compression and format -support. -Note that these latter functions perform two distinct operations: -they cause the corresponding support code to be linked into your -program, and they enable the corresponding auto-detect code. -Unless you have specific constraints, you will generally want -to invoke -.Fn archive_read_support_compression_all -and -.Fn archive_read_support_format_all -to enable auto-detect for all formats and compression types -currently supported by the library. -.Pp -Once you have prepared the -.Tn struct archive -object, you call -.Fn archive_read_open -to actually open the archive and prepare it for reading. -There are several variants of this function; -the most basic expects you to provide pointers to several -functions that can provide blocks of bytes from the archive. -There are convenience forms that allow you to -specify a filename, file descriptor, -.Ft "FILE *" -object, or a block of memory from which to read the archive data. -Note that the core library makes no assumptions about the -size of the blocks read; -callback functions are free to read whatever block size is -most appropriate for the medium. -.Pp -Each archive entry consists of a header followed by a certain -amount of data. -You can obtain the next header with -.Fn archive_read_next_header , -which returns a pointer to a -.Tn struct archive_entry -structure with information about the current archive element. -If the entry is a regular file, then the header will be followed -by the file data. -You can use -.Fn archive_read_data -(which works much like the -.Xr read 2 -system call) -to read this data from the archive, or -.Fn archive_read_data_block -which provides a slightly more efficient interface. -You may prefer to use the higher-level -.Fn archive_read_data_skip , -which reads and discards the data for this entry, -.Fn archive_read_data_to_buffer , -which reads the data into an in-memory buffer, -.Fn archive_read_data_to_file , -which copies the data to the provided file descriptor, or -.Fn archive_read_extract , -which recreates the specified entry on disk and copies data -from the archive. -In particular, note that -.Fn archive_read_extract -uses the -.Tn struct archive_entry -structure that you provide it, which may differ from the -entry just read from the archive. -In particular, many applications will want to override the -pathname, file permissions, or ownership. -.Pp -Once you have finished reading data from the archive, you -should call -.Fn archive_read_close -to close the archive, then call -.Fn archive_read_free -to release all resources, including all memory allocated by the library. -.Pp -The -.Xr archive_read 3 -manual page provides more detailed calling information for this API. -.Sh WRITING AN ARCHIVE -You use a similar process to write an archive. -The -.Fn archive_write_new -function creates an archive object useful for writing, -the various -.Fn archive_write_set_XXX -functions are used to set parameters for writing the archive, and -.Fn archive_write_open -completes the setup and opens the archive for writing. -.Pp -Individual archive entries are written in a three-step -process: -You first initialize a -.Tn struct archive_entry -structure with information about the new entry. -At a minimum, you should set the pathname of the -entry and provide a -.Va struct stat -with a valid -.Va st_mode -field, which specifies the type of object and -.Va st_size -field, which specifies the size of the data portion of the object. -The -.Fn archive_write_header -function actually writes the header data to the archive. -You can then use -.Fn archive_write_data -to write the actual data. -.Pp -After all entries have been written, use the -.Fn archive_write_free -function to release all resources. -.Pp -The -.Xr archive_write 3 -manual page provides more detailed calling information for this API. -.Sh WRITING ENTRIES TO DISK -The -.Xr archive_write_disk 3 -API allows you to write -.Xr archive_entry 3 -objects to disk using the same API used by -.Xr archive_write 3 . -The -.Xr archive_write_disk 3 -API is used internally by -.Fn archive_read_extract ; -using it directly can provide greater control over how entries -get written to disk. -This API also makes it possible to share code between -archive-to-archive copy and archive-to-disk extraction -operations. -.Sh READING ENTRIES FROM DISK -The -.Xr archive_read_disk 3 -provides some support for populating -.Xr archive_entry 3 -objects from information in the filesystem. -.Sh DESCRIPTION -Detailed descriptions of each function are provided by the -corresponding manual pages. -.Pp -All of the functions utilize an opaque -.Tn struct archive -datatype that provides access to the archive contents. -.Pp -The -.Tn struct archive_entry -structure contains a complete description of a single archive -entry. -It uses an opaque interface that is fully documented in -.Xr archive_entry 3 . -.Pp -Users familiar with historic formats should be aware that the newer -variants have eliminated most restrictions on the length of textual fields. -Clients should not assume that filenames, link names, user names, or -group names are limited in length. -In particular, pax interchange format can easily accommodate pathnames -in arbitrary character sets that exceed -.Va PATH_MAX . -.Sh RETURN VALUES -Most functions return -.Cm ARCHIVE_OK -(zero) on success, non-zero on error. -The return value indicates the general severity of the error, ranging -from -.Cm ARCHIVE_WARN , -which indicates a minor problem that should probably be reported -to the user, to -.Cm ARCHIVE_FATAL , -which indicates a serious problem that will prevent any further -operations on this archive. -On error, the -.Fn archive_errno -function can be used to retrieve a numeric error code (see -.Xr errno 2 ) . -The -.Fn archive_error_string -returns a textual error message suitable for display. -.Pp -.Fn archive_read_new -and -.Fn archive_write_new -return pointers to an allocated and initialized -.Tn struct archive -object. -.Pp -.Fn archive_read_data -and -.Fn archive_write_data -return a count of the number of bytes actually read or written. -A value of zero indicates the end of the data for this entry. -A negative value indicates an error, in which case the -.Fn archive_errno -and -.Fn archive_error_string -functions can be used to obtain more information. -.Sh ENVIRONMENT -There are character set conversions within the -.Xr archive_entry 3 -functions that are impacted by the currently-selected locale. -.Sh SEE ALSO -.Xr tar 1 , -.Xr archive_entry 3 , -.Xr archive_read 3 , -.Xr archive_util 3 , -.Xr archive_write 3 , -.Xr tar 5 -.Sh HISTORY -The -.Nm libarchive -library first appeared in -.Fx 5.3 . -.Sh AUTHORS -.An -nosplit -The -.Nm libarchive -library was written by -.An Tim Kientzle Aq kientzle@acm.org . -.Sh BUGS -Some archive formats support information that is not supported by -.Tn struct archive_entry . -Such information cannot be fully archived or restored using this library. -This includes, for example, comments, character sets, -or the arbitrary key/value pairs that can appear in -pax interchange format archives. -.Pp -Conversely, of course, not all of the information that can be -stored in a -.Tn struct archive_entry -is supported by all formats. -For example, cpio formats do not support nanosecond timestamps; -old tar formats do not support large device numbers. -.Pp -The -.Xr archive_read_disk 3 -API should support iterating over filesystems; -that would make it possible to share code among -disk-to-archive, archive-to-archive, archive-to-disk, -and disk-to-disk operations. -Currently, it only supports reading the -information for a single file. -(Which is still quite useful, as it hides a lot -of system-specific details.) diff --git a/lib/libarchive/libarchive_fe/err.c b/lib/libarchive/libarchive_fe/err.c deleted file mode 100644 index eb3f9f3..0000000 --- a/lib/libarchive/libarchive_fe/err.c +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "lafe_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_STDARG_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "err.h" - -const char *lafe_progname; - -static void -lafe_vwarnc(int code, const char *fmt, va_list ap) -{ - fprintf(stderr, "%s: ", lafe_progname); - vfprintf(stderr, fmt, ap); - if (code != 0) - fprintf(stderr, ": %s", strerror(code)); - fprintf(stderr, "\n"); -} - -void -lafe_warnc(int code, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - lafe_vwarnc(code, fmt, ap); - va_end(ap); -} - -void -lafe_errc(int eval, int code, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - lafe_vwarnc(code, fmt, ap); - va_end(ap); - exit(eval); -} diff --git a/lib/libarchive/libarchive_fe/err.h b/lib/libarchive/libarchive_fe/err.h deleted file mode 100644 index 4812b28..0000000 --- a/lib/libarchive/libarchive_fe/err.h +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * Copyright (c) 2009 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef LAFE_ERR_H -#define LAFE_ERR_H - -#if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) -#else -#define __LA_DEAD -#endif - -extern const char *lafe_progname; - -void lafe_warnc(int code, const char *fmt, ...); -void lafe_errc(int eval, int code, const char *fmt, ...) __LA_DEAD; - -#endif diff --git a/lib/libarchive/libarchive_fe/lafe_platform.h b/lib/libarchive/libarchive_fe/lafe_platform.h deleted file mode 100644 index 38e100d..0000000 --- a/lib/libarchive/libarchive_fe/lafe_platform.h +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * This header is the first thing included in any of the libarchive_fe - * source files. As far as possible, platform-specific issues should - * be dealt with here and not within individual source files. - */ - -#ifndef LAFE_PLATFORM_H_INCLUDED -#define LAFE_PLATFORM_H_INCLUDED - -#if defined(PLATFORM_CONFIG_H) -/* Use hand-built config.h in environments that need it. */ -#include PLATFORM_CONFIG_H -#else -/* Read config.h or die trying. */ -#include "config.h" -#endif - -/* Get a real definition for __FBSDID if we can */ -#if HAVE_SYS_CDEFS_H -#include -#endif - -/* If not, define it so as to avoid dangling semicolons. */ -#ifndef __FBSDID -#define __FBSDID(a) struct _undefined_hack -#endif - -#endif diff --git a/lib/libarchive/libarchive_fe/line_reader.c b/lib/libarchive/libarchive_fe/line_reader.c deleted file mode 100644 index 4af60de..0000000 --- a/lib/libarchive/libarchive_fe/line_reader.c +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * Copyright (c) 2008 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "lafe_platform.h" -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include "err.h" -#include "line_reader.h" - -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) -#define strdup _strdup -#endif - -/* - * Read lines from file and do something with each one. If option_null - * is set, lines are terminated with zero bytes; otherwise, they're - * terminated with newlines. - * - * This uses a self-sizing buffer to handle arbitrarily-long lines. - */ -struct lafe_line_reader { - FILE *f; - char *buff, *buff_end, *line_start, *line_end, *p; - char *pathname; - size_t buff_length; - int nullSeparator; /* Lines separated by null, not CR/CRLF/etc. */ - int ret; -}; - -struct lafe_line_reader * -lafe_line_reader(const char *pathname, int nullSeparator) -{ - struct lafe_line_reader *lr; - - lr = calloc(1, sizeof(*lr)); - if (lr == NULL) - lafe_errc(1, ENOMEM, "Can't open %s", pathname); - - lr->nullSeparator = nullSeparator; - lr->pathname = strdup(pathname); - - if (strcmp(pathname, "-") == 0) - lr->f = stdin; - else - lr->f = fopen(pathname, "r"); - if (lr->f == NULL) - lafe_errc(1, errno, "Couldn't open %s", pathname); - lr->buff_length = 8192; - lr->buff = malloc(lr->buff_length); - if (lr->buff == NULL) - lafe_errc(1, ENOMEM, "Can't read %s", pathname); - lr->line_start = lr->line_end = lr->buff_end = lr->buff; - - return (lr); -} - -const char * -lafe_line_reader_next(struct lafe_line_reader *lr) -{ - size_t bytes_wanted, bytes_read, new_buff_size; - char *line_start, *p; - - for (;;) { - /* If there's a line in the buffer, return it immediately. */ - while (lr->line_end < lr->buff_end) { - if (lr->nullSeparator) { - if (*lr->line_end == '\0') { - line_start = lr->line_start; - lr->line_start = lr->line_end + 1; - lr->line_end = lr->line_start; - return (line_start); - } - } else if (*lr->line_end == '\x0a' || *lr->line_end == '\x0d') { - *lr->line_end = '\0'; - line_start = lr->line_start; - lr->line_start = lr->line_end + 1; - lr->line_end = lr->line_start; - if (line_start[0] != '\0') - return (line_start); - } - lr->line_end++; - } - - /* If we're at end-of-file, process the final data. */ - if (lr->f == NULL) { - /* If there's more text, return one last line. */ - if (lr->line_end > lr->line_start) { - *lr->line_end = '\0'; - line_start = lr->line_start; - lr->line_start = lr->line_end + 1; - lr->line_end = lr->line_start; - return (line_start); - } - /* Otherwise, we're done. */ - return (NULL); - } - - /* Buffer only has part of a line. */ - if (lr->line_start > lr->buff) { - /* Move a leftover fractional line to the beginning. */ - memmove(lr->buff, lr->line_start, - lr->buff_end - lr->line_start); - lr->buff_end -= lr->line_start - lr->buff; - lr->line_end -= lr->line_start - lr->buff; - lr->line_start = lr->buff; - } else { - /* Line is too big; enlarge the buffer. */ - new_buff_size = lr->buff_length * 2; - if (new_buff_size <= lr->buff_length) - lafe_errc(1, ENOMEM, - "Line too long in %s", lr->pathname); - lr->buff_length = new_buff_size; - p = realloc(lr->buff, new_buff_size); - if (p == NULL) - lafe_errc(1, ENOMEM, - "Line too long in %s", lr->pathname); - lr->buff_end = p + (lr->buff_end - lr->buff); - lr->line_end = p + (lr->line_end - lr->buff); - lr->line_start = lr->buff = p; - } - - /* Get some more data into the buffer. */ - bytes_wanted = lr->buff + lr->buff_length - lr->buff_end; - bytes_read = fread(lr->buff_end, 1, bytes_wanted, lr->f); - lr->buff_end += bytes_read; - - if (ferror(lr->f)) - lafe_errc(1, errno, "Can't read %s", lr->pathname); - if (feof(lr->f)) { - if (lr->f != stdin) - fclose(lr->f); - lr->f = NULL; - } - } -} - -void -lafe_line_reader_free(struct lafe_line_reader *lr) -{ - free(lr->buff); - free(lr->pathname); - free(lr); -} diff --git a/lib/libarchive/libarchive_fe/line_reader.h b/lib/libarchive/libarchive_fe/line_reader.h deleted file mode 100644 index e4c3729..0000000 --- a/lib/libarchive/libarchive_fe/line_reader.h +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * Copyright (c) 2009 Joerg Sonnenberger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef LAFE_LINE_READER_H -#define LAFE_LINE_READER_H - -struct lafe_line_reader; - -struct lafe_line_reader *lafe_line_reader(const char *, int nullSeparator); -const char *lafe_line_reader_next(struct lafe_line_reader *); -void lafe_line_reader_free(struct lafe_line_reader *); - -#endif diff --git a/lib/libarchive/libarchive_fe/matching.c b/lib/libarchive/libarchive_fe/matching.c deleted file mode 100644 index 01e9c39..0000000 --- a/lib/libarchive/libarchive_fe/matching.c +++ /dev/null @@ -1,281 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "lafe_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "err.h" -#include "line_reader.h" -#include "matching.h" -#include "pathmatch.h" - -struct match { - struct match *next; - int matches; - char pattern[1]; -}; - -struct lafe_matching { - struct match *exclusions; - int exclusions_count; - struct match *inclusions; - int inclusions_count; - int inclusions_unmatched_count; -}; - -static void add_pattern(struct match **list, const char *pattern); -static void initialize_matching(struct lafe_matching **); -static int match_exclusion(struct match *, const char *pathname); -static int match_inclusion(struct match *, const char *pathname); - -/* - * The matching logic here needs to be re-thought. I started out to - * try to mimic gtar's matching logic, but it's not entirely - * consistent. In particular 'tar -t' and 'tar -x' interpret patterns - * on the command line as anchored, but --exclude doesn't. - */ - -/* - * Utility functions to manage exclusion/inclusion patterns - */ - -int -lafe_exclude(struct lafe_matching **matching, const char *pattern) -{ - - if (*matching == NULL) - initialize_matching(matching); - add_pattern(&((*matching)->exclusions), pattern); - (*matching)->exclusions_count++; - return (0); -} - -int -lafe_exclude_from_file(struct lafe_matching **matching, const char *pathname) -{ - struct lafe_line_reader *lr; - const char *p; - int ret = 0; - - lr = lafe_line_reader(pathname, 0); - while ((p = lafe_line_reader_next(lr)) != NULL) { - if (lafe_exclude(matching, p) != 0) - ret = -1; - } - lafe_line_reader_free(lr); - return (ret); -} - -int -lafe_include(struct lafe_matching **matching, const char *pattern) -{ - - if (*matching == NULL) - initialize_matching(matching); - add_pattern(&((*matching)->inclusions), pattern); - (*matching)->inclusions_count++; - (*matching)->inclusions_unmatched_count++; - return (0); -} - -int -lafe_include_from_file(struct lafe_matching **matching, const char *pathname, - int nullSeparator) -{ - struct lafe_line_reader *lr; - const char *p; - int ret = 0; - - lr = lafe_line_reader(pathname, nullSeparator); - while ((p = lafe_line_reader_next(lr)) != NULL) { - if (lafe_include(matching, p) != 0) - ret = -1; - } - lafe_line_reader_free(lr); - return (ret); -} - -static void -add_pattern(struct match **list, const char *pattern) -{ - struct match *match; - size_t len; - - len = strlen(pattern); - match = malloc(sizeof(*match) + len + 1); - if (match == NULL) - lafe_errc(1, errno, "Out of memory"); - strcpy(match->pattern, pattern); - /* Both "foo/" and "foo" should match "foo/bar". */ - if (len && match->pattern[len - 1] == '/') - match->pattern[strlen(match->pattern)-1] = '\0'; - match->next = *list; - *list = match; - match->matches = 0; -} - - -int -lafe_excluded(struct lafe_matching *matching, const char *pathname) -{ - struct match *match; - struct match *matched; - - if (matching == NULL) - return (0); - - /* Mark off any unmatched inclusions. */ - /* In particular, if a filename does appear in the archive and - * is explicitly included and excluded, then we don't report - * it as missing even though we don't extract it. - */ - matched = NULL; - for (match = matching->inclusions; match != NULL; match = match->next){ - if (match->matches == 0 - && match_inclusion(match, pathname)) { - matching->inclusions_unmatched_count--; - match->matches++; - matched = match; - } - } - - /* Exclusions take priority */ - for (match = matching->exclusions; match != NULL; match = match->next){ - if (match_exclusion(match, pathname)) - return (1); - } - - /* It's not excluded and we found an inclusion above, so it's included. */ - if (matched != NULL) - return (0); - - - /* We didn't find an unmatched inclusion, check the remaining ones. */ - for (match = matching->inclusions; match != NULL; match = match->next){ - /* We looked at previously-unmatched inclusions already. */ - if (match->matches > 0 - && match_inclusion(match, pathname)) { - match->matches++; - return (0); - } - } - - /* If there were inclusions, default is to exclude. */ - if (matching->inclusions != NULL) - return (1); - - /* No explicit inclusions, default is to match. */ - return (0); -} - -/* - * This is a little odd, but it matches the default behavior of - * gtar. In particular, 'a*b' will match 'foo/a1111/222b/bar' - * - */ -static int -match_exclusion(struct match *match, const char *pathname) -{ - return (lafe_pathmatch(match->pattern, - pathname, - PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); -} - -/* - * Again, mimic gtar: inclusions are always anchored (have to match - * the beginning of the path) even though exclusions are not anchored. - */ -static int -match_inclusion(struct match *match, const char *pathname) -{ - return (lafe_pathmatch(match->pattern, pathname, PATHMATCH_NO_ANCHOR_END)); -} - -void -lafe_cleanup_exclusions(struct lafe_matching **matching) -{ - struct match *p, *q; - - if (*matching == NULL) - return; - - for (p = (*matching)->inclusions; p != NULL; ) { - q = p; - p = p->next; - free(q); - } - - for (p = (*matching)->exclusions; p != NULL; ) { - q = p; - p = p->next; - free(q); - } - - free(*matching); - *matching = NULL; -} - -static void -initialize_matching(struct lafe_matching **matching) -{ - *matching = calloc(sizeof(**matching), 1); - if (*matching == NULL) - lafe_errc(1, errno, "No memory"); -} - -int -lafe_unmatched_inclusions(struct lafe_matching *matching) -{ - - if (matching == NULL) - return (0); - return (matching->inclusions_unmatched_count); -} - -int -lafe_unmatched_inclusions_warn(struct lafe_matching *matching, const char *msg) -{ - struct match *p; - - if (matching == NULL) - return (0); - - for (p = matching->inclusions; p != NULL; p = p->next) { - if (p->matches == 0) - lafe_warnc(0, "%s: %s", p->pattern, msg); - } - - return (matching->inclusions_unmatched_count); -} diff --git a/lib/libarchive/libarchive_fe/matching.h b/lib/libarchive/libarchive_fe/matching.h deleted file mode 100644 index f4edebd..0000000 --- a/lib/libarchive/libarchive_fe/matching.h +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef MATCHING_H -#define MATCHING_H - -struct lafe_matching; - -int lafe_exclude(struct lafe_matching **matching, const char *pattern); -int lafe_exclude_from_file(struct lafe_matching **matching, - const char *pathname); -int lafe_include(struct lafe_matching **matching, const char *pattern); -int lafe_include_from_file(struct lafe_matching **matching, - const char *pathname, int nullSeparator); - -int lafe_excluded(struct lafe_matching *, const char *pathname); -void lafe_cleanup_exclusions(struct lafe_matching **); -int lafe_unmatched_inclusions(struct lafe_matching *); -int lafe_unmatched_inclusions_warn(struct lafe_matching *, const char *msg); - -#endif diff --git a/lib/libarchive/libarchive_fe/pathmatch.c b/lib/libarchive/libarchive_fe/pathmatch.c deleted file mode 100644 index e211362..0000000 --- a/lib/libarchive/libarchive_fe/pathmatch.c +++ /dev/null @@ -1,255 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "lafe_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_STRING_H -#include -#endif - -#include "pathmatch.h" - -/* - * Check whether a character 'c' is matched by a list specification [...]: - * * Leading '!' or '^' negates the class. - * * - is a range of characters - * * \ removes any special meaning for - * - * Some interesting boundary cases: - * a-d-e is one range (a-d) followed by two single characters - and e. - * \a-\d is same as a-d - * a\-d is three single characters: a, d, - - * Trailing - is not special (so [a-] is two characters a and -). - * Initial - is not special ([a-] is same as [-a] is same as [\\-a]) - * This function never sees a trailing \. - * [] always fails - * [!] always succeeds - */ -static int -pm_list(const char *start, const char *end, const char c, int flags) -{ - const char *p = start; - char rangeStart = '\0', nextRangeStart; - int match = 1, nomatch = 0; - - /* This will be used soon... */ - (void)flags; /* UNUSED */ - - /* If this is a negated class, return success for nomatch. */ - if ((*p == '!' || *p == '^') && p < end) { - match = 0; - nomatch = 1; - ++p; - } - - while (p < end) { - nextRangeStart = '\0'; - switch (*p) { - case '-': - /* Trailing or initial '-' is not special. */ - if ((rangeStart == '\0') || (p == end - 1)) { - if (*p == c) - return (match); - } else { - char rangeEnd = *++p; - if (rangeEnd == '\\') - rangeEnd = *++p; - if ((rangeStart <= c) && (c <= rangeEnd)) - return (match); - } - break; - case '\\': - ++p; - /* Fall through */ - default: - if (*p == c) - return (match); - nextRangeStart = *p; /* Possible start of range. */ - } - rangeStart = nextRangeStart; - ++p; - } - return (nomatch); -} - -/* - * If s is pointing to "./", ".//", "./././" or the like, skip it. - */ -static const char * -pm_slashskip(const char *s) { - while ((*s == '/') - || (s[0] == '.' && s[1] == '/') - || (s[0] == '.' && s[1] == '\0')) - ++s; - return (s); -} - -static int -pm(const char *p, const char *s, int flags) -{ - const char *end; - - /* - * Ignore leading './', './/', '././', etc. - */ - if (s[0] == '.' && s[1] == '/') - s = pm_slashskip(s + 1); - if (p[0] == '.' && p[1] == '/') - p = pm_slashskip(p + 1); - - for (;;) { - switch (*p) { - case '\0': - if (s[0] == '/') { - if (flags & PATHMATCH_NO_ANCHOR_END) - return (1); - /* "dir" == "dir/" == "dir/." */ - s = pm_slashskip(s); - } - return (*s == '\0'); - case '?': - /* ? always succeds, unless we hit end of 's' */ - if (*s == '\0') - return (0); - break; - case '*': - /* "*" == "**" == "***" ... */ - while (*p == '*') - ++p; - /* Trailing '*' always succeeds. */ - if (*p == '\0') - return (1); - while (*s) { - if (lafe_pathmatch(p, s, flags)) - return (1); - ++s; - } - return (0); - case '[': - /* - * Find the end of the [...] character class, - * ignoring \] that might occur within the class. - */ - end = p + 1; - while (*end != '\0' && *end != ']') { - if (*end == '\\' && end[1] != '\0') - ++end; - ++end; - } - if (*end == ']') { - /* We found [...], try to match it. */ - if (!pm_list(p + 1, end, *s, flags)) - return (0); - p = end; /* Jump to trailing ']' char. */ - break; - } else - /* No final ']', so just match '['. */ - if (*p != *s) - return (0); - break; - case '\\': - /* Trailing '\\' matches itself. */ - if (p[1] == '\0') { - if (*s != '\\') - return (0); - } else { - ++p; - if (*p != *s) - return (0); - } - break; - case '/': - if (*s != '/' && *s != '\0') - return (0); - /* Note: pattern "/\./" won't match "/"; - * pm_slashskip() correctly stops at backslash. */ - p = pm_slashskip(p); - s = pm_slashskip(s); - if (*p == '\0' && (flags & PATHMATCH_NO_ANCHOR_END)) - return (1); - --p; /* Counteract the increment below. */ - --s; - break; - case '$': - /* '$' is special only at end of pattern and only - * if PATHMATCH_NO_ANCHOR_END is specified. */ - if (p[1] == '\0' && (flags & PATHMATCH_NO_ANCHOR_END)){ - /* "dir" == "dir/" == "dir/." */ - return (*pm_slashskip(s) == '\0'); - } - /* Otherwise, '$' is not special. */ - /* FALL THROUGH */ - default: - if (*p != *s) - return (0); - break; - } - ++p; - ++s; - } -} - -/* Main entry point. */ -int -lafe_pathmatch(const char *p, const char *s, int flags) -{ - /* Empty pattern only matches the empty string. */ - if (p == NULL || *p == '\0') - return (s == NULL || *s == '\0'); - - /* Leading '^' anchors the start of the pattern. */ - if (*p == '^') { - ++p; - flags &= ~PATHMATCH_NO_ANCHOR_START; - } - - if (*p == '/' && *s != '/') - return (0); - - /* Certain patterns and file names anchor implicitly. */ - if (*p == '*' || *p == '/' || *p == '/') { - while (*p == '/') - ++p; - while (*s == '/') - ++s; - return (pm(p, s, flags)); - } - - /* If start is unanchored, try to match start of each path element. */ - if (flags & PATHMATCH_NO_ANCHOR_START) { - for ( ; s != NULL; s = strchr(s, '/')) { - if (*s == '/') - s++; - if (pm(p, s, flags)) - return (1); - } - return (0); - } - - /* Default: Match from beginning. */ - return (pm(p, s, flags)); -} diff --git a/lib/libarchive/libarchive_fe/pathmatch.h b/lib/libarchive/libarchive_fe/pathmatch.h deleted file mode 100644 index a92f3ae..0000000 --- a/lib/libarchive/libarchive_fe/pathmatch.h +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef LAFE_PATHMATCH_H -#define LAFE_PATHMATCH_H - -/* Don't anchor at beginning unless the pattern starts with "^" */ -#define PATHMATCH_NO_ANCHOR_START 1 -/* Don't anchor at end unless the pattern ends with "$" */ -#define PATHMATCH_NO_ANCHOR_END 2 - -/* Note that "^" and "$" are not special unless you set the corresponding - * flag above. */ - -int lafe_pathmatch(const char *p, const char *s, int flags); - -#endif diff --git a/lib/libarchive/libarchive_internals.3 b/lib/libarchive/libarchive_internals.3 deleted file mode 100644 index 61a17c4..0000000 --- a/lib/libarchive/libarchive_internals.3 +++ /dev/null @@ -1,365 +0,0 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd April 16, 2007 -.Dt LIBARCHIVE 3 -.Os -.Sh NAME -.Nm libarchive_internals -.Nd description of libarchive internal interfaces -.Sh OVERVIEW -The -.Nm libarchive -library provides a flexible interface for reading and writing -streaming archive files such as tar and cpio. -Internally, it follows a modular layered design that should -make it easy to add new archive and compression formats. -.Sh GENERAL ARCHITECTURE -Externally, libarchive exposes most operations through an -opaque, object-style interface. -The -.Xr archive_entry 1 -objects store information about a single filesystem object. -The rest of the library provides facilities to write -.Xr archive_entry 1 -objects to archive files, -read them from archive files, -and write them to disk. -(There are plans to add a facility to read -.Xr archive_entry 1 -objects from disk as well.) -.Pp -The read and write APIs each have four layers: a public API -layer, a format layer that understands the archive file format, -a compression layer, and an I/O layer. -The I/O layer is completely exposed to clients who can replace -it entirely with their own functions. -.Pp -In order to provide as much consistency as possible for clients, -some public functions are virtualized. -Eventually, it should be possible for clients to open -an archive or disk writer, and then use a single set of -code to select and write entries, regardless of the target. -.Sh READ ARCHITECTURE -From the outside, clients use the -.Xr archive_read 3 -API to manipulate an -.Nm archive -object to read entries and bodies from an archive stream. -Internally, the -.Nm archive -object is cast to an -.Nm archive_read -object, which holds all read-specific data. -The API has four layers: -The lowest layer is the I/O layer. -This layer can be overridden by clients, but most clients use -the packaged I/O callbacks provided, for example, by -.Xr archive_read_open_memory 3 , -and -.Xr archive_read_open_fd 3 . -The compression layer calls the I/O layer to -read bytes and decompresses them for the format layer. -The format layer unpacks a stream of uncompressed bytes and -creates -.Nm archive_entry -objects from the incoming data. -The API layer tracks overall state -(for example, it prevents clients from reading data before reading a header) -and invokes the format and compression layer operations -through registered function pointers. -In particular, the API layer drives the format-detection process: -When opening the archive, it reads an initial block of data -and offers it to each registered compression handler. -The one with the highest bid is initialized with the first block. -Similarly, the format handlers are polled to see which handler -is the best for each archive. -(Prior to 2.4.0, the format bidders were invoked for each -entry, but this design hindered error recovery.) -.Ss I/O Layer and Client Callbacks -The read API goes to some lengths to be nice to clients. -As a result, there are few restrictions on the behavior of -the client callbacks. -.Pp -The client read callback is expected to provide a block -of data on each call. -A zero-length return does indicate end of file, but otherwise -blocks may be as small as one byte or as large as the entire file. -In particular, blocks may be of different sizes. -.Pp -The client skip callback returns the number of bytes actually -skipped, which may be much smaller than the skip requested. -The only requirement is that the skip not be larger. -In particular, clients are allowed to return zero for any -skip that they don't want to handle. -The skip callback must never be invoked with a negative value. -.Pp -Keep in mind that not all clients are reading from disk: -clients reading from networks may provide different-sized -blocks on every request and cannot skip at all; -advanced clients may use -.Xr mmap 2 -to read the entire file into memory at once and return the -entire file to libarchive as a single block; -other clients may begin asynchronous I/O operations for the -next block on each request. -.Ss Decompression Layer -The decompression layer not only handles decompression, -it also buffers data so that the format handlers see a -much nicer I/O model. -The decompression API is a two stage peek/consume model. -A read_ahead request specifies a minimum read amount; -the decompression layer must provide a pointer to at least -that much data. -If more data is immediately available, it should return more: -the format layer handles bulk data reads by asking for a minimum -of one byte and then copying as much data as is available. -.Pp -A subsequent call to the -.Fn consume -function advances the read pointer. -Note that data returned from a -.Fn read_ahead -call is guaranteed to remain in place until -the next call to -.Fn read_ahead . -Intervening calls to -.Fn consume -should not cause the data to move. -.Pp -Skip requests must always be handled exactly. -Decompression handlers that cannot seek forward should -not register a skip handler; -the API layer fills in a generic skip handler that reads and discards data. -.Pp -A decompression handler has a specific lifecycle: -.Bl -tag -compact -width indent -.It Registration/Configuration -When the client invokes the public support function, -the decompression handler invokes the internal -.Fn __archive_read_register_compression -function to provide bid and initialization functions. -This function returns -.Cm NULL -on error or else a pointer to a -.Cm struct decompressor_t . -This structure contains a -.Va void * config -slot that can be used for storing any customization information. -.It Bid -The bid function is invoked with a pointer and size of a block of data. -The decompressor can access its config data -through the -.Va decompressor -element of the -.Cm archive_read -object. -The bid function is otherwise stateless. -In particular, it must not perform any I/O operations. -.Pp -The value returned by the bid function indicates its suitability -for handling this data stream. -A bid of zero will ensure that this decompressor is never invoked. -Return zero if magic number checks fail. -Otherwise, your initial implementation should return the number of bits -actually checked. -For example, if you verify two full bytes and three bits of another -byte, bid 19. -Note that the initial block may be very short; -be careful to only inspect the data you are given. -(The current decompressors require two bytes for correct bidding.) -.It Initialize -The winning bidder will have its init function called. -This function should initialize the remaining slots of the -.Va struct decompressor_t -object pointed to by the -.Va decompressor -element of the -.Va archive_read -object. -In particular, it should allocate any working data it needs -in the -.Va data -slot of that structure. -The init function is called with the block of data that -was used for tasting. -At this point, the decompressor is responsible for all I/O -requests to the client callbacks. -The decompressor is free to read more data as and when -necessary. -.It Satisfy I/O requests -The format handler will invoke the -.Va read_ahead , -.Va consume , -and -.Va skip -functions as needed. -.It Finish -The finish method is called only once when the archive is closed. -It should release anything stored in the -.Va data -and -.Va config -slots of the -.Va decompressor -object. -It should not invoke the client close callback. -.El -.Ss Format Layer -The read formats have a similar lifecycle to the decompression handlers: -.Bl -tag -compact -width indent -.It Registration -Allocate your private data and initialize your pointers. -.It Bid -Formats bid by invoking the -.Fn read_ahead -decompression method but not calling the -.Fn consume -method. -This allows each bidder to look ahead in the input stream. -Bidders should not look further ahead than necessary, as long -look aheads put pressure on the decompression layer to buffer -lots of data. -Most formats only require a few hundred bytes of look ahead; -look aheads of a few kilobytes are reasonable. -(The ISO9660 reader sometimes looks ahead by 48k, which -should be considered an upper limit.) -.It Read header -The header read is usually the most complex part of any format. -There are a few strategies worth mentioning: -For formats such as tar or cpio, reading and parsing the header is -straightforward since headers alternate with data. -For formats that store all header data at the beginning of the file, -the first header read request may have to read all headers into -memory and store that data, sorted by the location of the file -data. -Subsequent header read requests will skip forward to the -beginning of the file data and return the corresponding header. -.It Read Data -The read data interface supports sparse files; this requires that -each call return a block of data specifying the file offset and -size. -This may require you to carefully track the location so that you -can return accurate file offsets for each read. -Remember that the decompressor will return as much data as it has. -Generally, you will want to request one byte, -examine the return value to see how much data is available, and -possibly trim that to the amount you can use. -You should invoke consume for each block just before you return it. -.It Skip All Data -The skip data call should skip over all file data and trailing padding. -This is called automatically by the API layer just before each -header read. -It is also called in response to the client calling the public -.Fn data_skip -function. -.It Cleanup -On cleanup, the format should release all of its allocated memory. -.El -.Ss API Layer -XXX to do XXX -.Sh WRITE ARCHITECTURE -The write API has a similar set of four layers: -an API layer, a format layer, a compression layer, and an I/O layer. -The registration here is much simpler because only -one format and one compression can be registered at a time. -.Ss I/O Layer and Client Callbacks -XXX To be written XXX -.Ss Compression Layer -XXX To be written XXX -.Ss Format Layer -XXX To be written XXX -.Ss API Layer -XXX To be written XXX -.Sh WRITE_DISK ARCHITECTURE -The write_disk API is intended to look just like the write API -to clients. -Since it does not handle multiple formats or compression, it -is not layered internally. -.Sh GENERAL SERVICES -The -.Nm archive_read , -.Nm archive_write , -and -.Nm archive_write_disk -objects all contain an initial -.Nm archive -object which provides common support for a set of standard services. -(Recall that ANSI/ISO C90 guarantees that you can cast freely between -a pointer to a structure and a pointer to the first element of that -structure.) -The -.Nm archive -object has a magic value that indicates which API this object -is associated with, -slots for storing error information, -and function pointers for virtualized API functions. -.Sh MISCELLANEOUS NOTES -Connecting existing archiving libraries into libarchive is generally -quite difficult. -In particular, many existing libraries strongly assume that you -are reading from a file; they seek forwards and backwards as necessary -to locate various pieces of information. -In contrast, libarchive never seeks backwards in its input, which -sometimes requires very different approaches. -.Pp -For example, libarchive's ISO9660 support operates very differently -from most ISO9660 readers. -The libarchive support utilizes a work-queue design that -keeps a list of known entries sorted by their location in the input. -Whenever libarchive's ISO9660 implementation is asked for the next -header, checks this list to find the next item on the disk. -Directories are parsed when they are encountered and new -items are added to the list. -This design relies heavily on the ISO9660 image being optimized so that -directories always occur earlier on the disk than the files they -describe. -.Pp -Depending on the specific format, such approaches may not be possible. -The ZIP format specification, for example, allows archivers to store -key information only at the end of the file. -In theory, it is possible to create ZIP archives that cannot -be read without seeking. -Fortunately, such archives are very rare, and libarchive can read -most ZIP archives, though it cannot always extract as much information -as a dedicated ZIP program. -.Sh SEE ALSO -.Xr archive 3 , -.Xr archive_entry 3 , -.Xr archive_read 3 , -.Xr archive_write 3 , -.Xr archive_write_disk 3 -.Sh HISTORY -The -.Nm libarchive -library first appeared in -.Fx 5.3 . -.Sh AUTHORS -.An -nosplit -The -.Nm libarchive -library was written by -.An Tim Kientzle Aq kientzle@acm.org . diff --git a/lib/libarchive/tar.5 b/lib/libarchive/tar.5 deleted file mode 100644 index c2c594b..0000000 --- a/lib/libarchive/tar.5 +++ /dev/null @@ -1,831 +0,0 @@ -.\" Copyright (c) 2003-2009 Tim Kientzle -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd December 27, 2009 -.Dt TAR 5 -.Os -.Sh NAME -.Nm tar -.Nd format of tape archive files -.Sh DESCRIPTION -The -.Nm -archive format collects any number of files, directories, and other -file system objects (symbolic links, device nodes, etc.) into a single -stream of bytes. -The format was originally designed to be used with -tape drives that operate with fixed-size blocks, but is widely used as -a general packaging mechanism. -.Ss General Format -A -.Nm -archive consists of a series of 512-byte records. -Each file system object requires a header record which stores basic metadata -(pathname, owner, permissions, etc.) and zero or more records containing any -file data. -The end of the archive is indicated by two records consisting -entirely of zero bytes. -.Pp -For compatibility with tape drives that use fixed block sizes, -programs that read or write tar files always read or write a fixed -number of records with each I/O operation. -These -.Dq blocks -are always a multiple of the record size. -The maximum block size supported by early -implementations was 10240 bytes or 20 records. -This is still the default for most implementations -although block sizes of 1MiB (2048 records) or larger are -commonly used with modern high-speed tape drives. -(Note: the terms -.Dq block -and -.Dq record -here are not entirely standard; this document follows the -convention established by John Gilmore in documenting -.Nm pdtar . ) -.Ss Old-Style Archive Format -The original tar archive format has been extended many times to -include additional information that various implementors found -necessary. -This section describes the variant implemented by the tar command -included in -.At v7 , -which seems to be the earliest widely-used version of the tar program. -.Pp -The header record for an old-style -.Nm -archive consists of the following: -.Bd -literal -offset indent -struct header_old_tar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char linkflag[1]; - char linkname[100]; - char pad[255]; -}; -.Ed -All unused bytes in the header record are filled with nulls. -.Bl -tag -width indent -.It Va name -Pathname, stored as a null-terminated string. -Early tar implementations only stored regular files (including -hardlinks to those files). -One common early convention used a trailing "/" character to indicate -a directory name, allowing directory permissions and owner information -to be archived and restored. -.It Va mode -File mode, stored as an octal number in ASCII. -.It Va uid , Va gid -User id and group id of owner, as octal numbers in ASCII. -.It Va size -Size of file, as octal number in ASCII. -For regular files only, this indicates the amount of data -that follows the header. -In particular, this field was ignored by early tar implementations -when extracting hardlinks. -Modern writers should always store a zero length for hardlink entries. -.It Va mtime -Modification time of file, as an octal number in ASCII. -This indicates the number of seconds since the start of the epoch, -00:00:00 UTC January 1, 1970. -Note that negative values should be avoided -here, as they are handled inconsistently. -.It Va checksum -Header checksum, stored as an octal number in ASCII. -To compute the checksum, set the checksum field to all spaces, -then sum all bytes in the header using unsigned arithmetic. -This field should be stored as six octal digits followed by a null and a space -character. -Note that many early implementations of tar used signed arithmetic -for the checksum field, which can cause interoperability problems -when transferring archives between systems. -Modern robust readers compute the checksum both ways and accept the -header if either computation matches. -.It Va linkflag , Va linkname -In order to preserve hardlinks and conserve tape, a file -with multiple links is only written to the archive the first -time it is encountered. -The next time it is encountered, the -.Va linkflag -is set to an ASCII -.Sq 1 -and the -.Va linkname -field holds the first name under which this file appears. -(Note that regular files have a null value in the -.Va linkflag -field.) -.El -.Pp -Early tar implementations varied in how they terminated these fields. -The tar command in -.At v7 -used the following conventions (this is also documented in early BSD manpages): -the pathname must be null-terminated; -the mode, uid, and gid fields must end in a space and a null byte; -the size and mtime fields must end in a space; -the checksum is terminated by a null and a space. -Early implementations filled the numeric fields with leading spaces. -This seems to have been common practice until the -.St -p1003.1-88 -standard was released. -For best portability, modern implementations should fill the numeric -fields with leading zeros. -.Ss Pre-POSIX Archives -An early draft of -.St -p1003.1-88 -served as the basis for John Gilmore's -.Nm pdtar -program and many system implementations from the late 1980s -and early 1990s. -These archives generally follow the POSIX ustar -format described below with the following variations: -.Bl -bullet -compact -width indent -.It -The magic value is -.Dq ustar\ \& -(note the following space). -The version field contains a space character followed by a null. -.It -The numeric fields are generally filled with leading spaces -(not leading zeros as recommended in the final standard). -.It -The prefix field is often not used, limiting pathnames to -the 100 characters of old-style archives. -.El -.Ss POSIX ustar Archives -.St -p1003.1-88 -defined a standard tar file format to be read and written -by compliant implementations of -.Xr tar 1 . -This format is often called the -.Dq ustar -format, after the magic value used -in the header. -(The name is an acronym for -.Dq Unix Standard TAR . ) -It extends the historic format with new fields: -.Bd -literal -offset indent -struct header_posix_ustar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char typeflag[1]; - char linkname[100]; - char magic[6]; - char version[2]; - char uname[32]; - char gname[32]; - char devmajor[8]; - char devminor[8]; - char prefix[155]; - char pad[12]; -}; -.Ed -.Bl -tag -width indent -.It Va typeflag -Type of entry. -POSIX extended the earlier -.Va linkflag -field with several new type values: -.Bl -tag -width indent -compact -.It Dq 0 -Regular file. -NUL should be treated as a synonym, for compatibility purposes. -.It Dq 1 -Hard link. -.It Dq 2 -Symbolic link. -.It Dq 3 -Character device node. -.It Dq 4 -Block device node. -.It Dq 5 -Directory. -.It Dq 6 -FIFO node. -.It Dq 7 -Reserved. -.It Other -A POSIX-compliant implementation must treat any unrecognized typeflag value -as a regular file. -In particular, writers should ensure that all entries -have a valid filename so that they can be restored by readers that do not -support the corresponding extension. -Uppercase letters "A" through "Z" are reserved for custom extensions. -Note that sockets and whiteout entries are not archivable. -.El -It is worth noting that the -.Va size -field, in particular, has different meanings depending on the type. -For regular files, of course, it indicates the amount of data -following the header. -For directories, it may be used to indicate the total size of all -files in the directory, for use by operating systems that pre-allocate -directory space. -For all other types, it should be set to zero by writers and ignored -by readers. -.It Va magic -Contains the magic value -.Dq ustar -followed by a NUL byte to indicate that this is a POSIX standard archive. -Full compliance requires the uname and gname fields be properly set. -.It Va version -Version. -This should be -.Dq 00 -(two copies of the ASCII digit zero) for POSIX standard archives. -.It Va uname , Va gname -User and group names, as null-terminated ASCII strings. -These should be used in preference to the uid/gid values -when they are set and the corresponding names exist on -the system. -.It Va devmajor , Va devminor -Major and minor numbers for character device or block device entry. -.It Va name , Va prefix -If the pathname is too long to fit in the 100 bytes provided by the standard -format, it can be split at any -.Pa / -character with the first portion going into the prefix field. -If the prefix field is not empty, the reader will prepend -the prefix value and a -.Pa / -character to the regular name field to obtain the full pathname. -The standard does not require a trailing -.Pa / -character on directory names, though most implementations still -include this for compatibility reasons. -.El -.Pp -Note that all unused bytes must be set to -.Dv NUL . -.Pp -Field termination is specified slightly differently by POSIX -than by previous implementations. -The -.Va magic , -.Va uname , -and -.Va gname -fields must have a trailing -.Dv NUL . -The -.Va pathname , -.Va linkname , -and -.Va prefix -fields must have a trailing -.Dv NUL -unless they fill the entire field. -(In particular, it is possible to store a 256-character pathname if it -happens to have a -.Pa / -as the 156th character.) -POSIX requires numeric fields to be zero-padded in the front, and requires -them to be terminated with either space or -.Dv NUL -characters. -.Pp -Currently, most tar implementations comply with the ustar -format, occasionally extending it by adding new fields to the -blank area at the end of the header record. -.Ss Pax Interchange Format -There are many attributes that cannot be portably stored in a -POSIX ustar archive. -.St -p1003.1-2001 -defined a -.Dq pax interchange format -that uses two new types of entries to hold text-formatted -metadata that applies to following entries. -Note that a pax interchange format archive is a ustar archive in every -respect. -The new data is stored in ustar-compatible archive entries that use the -.Dq x -or -.Dq g -typeflag. -In particular, older implementations that do not fully support these -extensions will extract the metadata into regular files, where the -metadata can be examined as necessary. -.Pp -An entry in a pax interchange format archive consists of one or -two standard ustar entries, each with its own header and data. -The first optional entry stores the extended attributes -for the following entry. -This optional first entry has an "x" typeflag and a size field that -indicates the total size of the extended attributes. -The extended attributes themselves are stored as a series of text-format -lines encoded in the portable UTF-8 encoding. -Each line consists of a decimal number, a space, a key string, an equals -sign, a value string, and a new line. -The decimal number indicates the length of the entire line, including the -initial length field and the trailing newline. -An example of such a field is: -.Dl 25 ctime=1084839148.1212\en -Keys in all lowercase are standard keys. -Vendors can add their own keys by prefixing them with an all uppercase -vendor name and a period. -Note that, unlike the historic header, numeric values are stored using -decimal, not octal. -A description of some common keys follows: -.Bl -tag -width indent -.It Cm atime , Cm ctime , Cm mtime -File access, inode change, and modification times. -These fields can be negative or include a decimal point and a fractional value. -.It Cm uname , Cm uid , Cm gname , Cm gid -User name, group name, and numeric UID and GID values. -The user name and group name stored here are encoded in UTF8 -and can thus include non-ASCII characters. -The UID and GID fields can be of arbitrary length. -.It Cm linkpath -The full path of the linked-to file. -Note that this is encoded in UTF8 and can thus include non-ASCII characters. -.It Cm path -The full pathname of the entry. -Note that this is encoded in UTF8 and can thus include non-ASCII characters. -.It Cm realtime.* , Cm security.* -These keys are reserved and may be used for future standardization. -.It Cm size -The size of the file. -Note that there is no length limit on this field, allowing conforming -archives to store files much larger than the historic 8GB limit. -.It Cm SCHILY.* -Vendor-specific attributes used by Joerg Schilling's -.Nm star -implementation. -.It Cm SCHILY.acl.access , Cm SCHILY.acl.default -Stores the access and default ACLs as textual strings in a format -that is an extension of the format specified by POSIX.1e draft 17. -In particular, each user or group access specification can include a fourth -colon-separated field with the numeric UID or GID. -This allows ACLs to be restored on systems that may not have complete -user or group information available (such as when NIS/YP or LDAP services -are temporarily unavailable). -.It Cm SCHILY.devminor , Cm SCHILY.devmajor -The full minor and major numbers for device nodes. -.It Cm SCHILY.fflags -The file flags. -.It Cm SCHILY.realsize -The full size of the file on disk. -XXX explain? XXX -.It Cm SCHILY.dev, Cm SCHILY.ino , Cm SCHILY.nlinks -The device number, inode number, and link count for the entry. -In particular, note that a pax interchange format archive using Joerg -Schilling's -.Cm SCHILY.* -extensions can store all of the data from -.Va struct stat . -.It Cm LIBARCHIVE.xattr. Ns Ar namespace Ns . Ns Ar key -Libarchive stores POSIX.1e-style extended attributes using -keys of this form. -The -.Ar key -value is URL-encoded: -All non-ASCII characters and the two special characters -.Dq = -and -.Dq % -are encoded as -.Dq % -followed by two uppercase hexadecimal digits. -The value of this key is the extended attribute value -encoded in base 64. -XXX Detail the base-64 format here XXX -.It Cm VENDOR.* -XXX document other vendor-specific extensions XXX -.El -.Pp -Any values stored in an extended attribute override the corresponding -values in the regular tar header. -Note that compliant readers should ignore the regular fields when they -are overridden. -This is important, as existing archivers are known to store non-compliant -values in the standard header fields in this situation. -There are no limits on length for any of these fields. -In particular, numeric fields can be arbitrarily large. -All text fields are encoded in UTF8. -Compliant writers should store only portable 7-bit ASCII characters in -the standard ustar header and use extended -attributes whenever a text value contains non-ASCII characters. -.Pp -In addition to the -.Cm x -entry described above, the pax interchange format -also supports a -.Cm g -entry. -The -.Cm g -entry is identical in format, but specifies attributes that serve as -defaults for all subsequent archive entries. -The -.Cm g -entry is not widely used. -.Pp -Besides the new -.Cm x -and -.Cm g -entries, the pax interchange format has a few other minor variations -from the earlier ustar format. -The most troubling one is that hardlinks are permitted to have -data following them. -This allows readers to restore any hardlink to a file without -having to rewind the archive to find an earlier entry. -However, it creates complications for robust readers, as it is no longer -clear whether or not they should ignore the size field for hardlink entries. -.Ss GNU Tar Archives -The GNU tar program started with a pre-POSIX format similar to that -described earlier and has extended it using several different mechanisms: -It added new fields to the empty space in the header (some of which was later -used by POSIX for conflicting purposes); -it allowed the header to be continued over multiple records; -and it defined new entries that modify following entries -(similar in principle to the -.Cm x -entry described above, but each GNU special entry is single-purpose, -unlike the general-purpose -.Cm x -entry). -As a result, GNU tar archives are not POSIX compatible, although -more lenient POSIX-compliant readers can successfully extract most -GNU tar archives. -.Bd -literal -offset indent -struct header_gnu_tar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char typeflag[1]; - char linkname[100]; - char magic[6]; - char version[2]; - char uname[32]; - char gname[32]; - char devmajor[8]; - char devminor[8]; - char atime[12]; - char ctime[12]; - char offset[12]; - char longnames[4]; - char unused[1]; - struct { - char offset[12]; - char numbytes[12]; - } sparse[4]; - char isextended[1]; - char realsize[12]; - char pad[17]; -}; -.Ed -.Bl -tag -width indent -.It Va typeflag -GNU tar uses the following special entry types, in addition to -those defined by POSIX: -.Bl -tag -width indent -.It "7" -GNU tar treats type "7" records identically to type "0" records, -except on one obscure RTOS where they are used to indicate the -pre-allocation of a contiguous file on disk. -.It "D" -This indicates a directory entry. -Unlike the POSIX-standard "5" -typeflag, the header is followed by data records listing the names -of files in this directory. -Each name is preceded by an ASCII "Y" -if the file is stored in this archive or "N" if the file is not -stored in this archive. -Each name is terminated with a null, and -an extra null marks the end of the name list. -The purpose of this -entry is to support incremental backups; a program restoring from -such an archive may wish to delete files on disk that did not exist -in the directory when the archive was made. -.Pp -Note that the "D" typeflag specifically violates POSIX, which requires -that unrecognized typeflags be restored as normal files. -In this case, restoring the "D" entry as a file could interfere -with subsequent creation of the like-named directory. -.It "K" -The data for this entry is a long linkname for the following regular entry. -.It "L" -The data for this entry is a long pathname for the following regular entry. -.It "M" -This is a continuation of the last file on the previous volume. -GNU multi-volume archives guarantee that each volume begins with a valid -entry header. -To ensure this, a file may be split, with part stored at the end of one volume, -and part stored at the beginning of the next volume. -The "M" typeflag indicates that this entry continues an existing file. -Such entries can only occur as the first or second entry -in an archive (the latter only if the first entry is a volume label). -The -.Va size -field specifies the size of this entry. -The -.Va offset -field at bytes 369-380 specifies the offset where this file fragment -begins. -The -.Va realsize -field specifies the total size of the file (which must equal -.Va size -plus -.Va offset ) . -When extracting, GNU tar checks that the header file name is the one it is -expecting, that the header offset is in the correct sequence, and that -the sum of offset and size is equal to realsize. -.It "N" -Type "N" records are no longer generated by GNU tar. -They contained a -list of files to be renamed or symlinked after extraction; this was -originally used to support long names. -The contents of this record -are a text description of the operations to be done, in the form -.Dq Rename %s to %s\en -or -.Dq Symlink %s to %s\en ; -in either case, both -filenames are escaped using K&R C syntax. -Due to security concerns, "N" records are now generally ignored -when reading archives. -.It "S" -This is a -.Dq sparse -regular file. -Sparse files are stored as a series of fragments. -The header contains a list of fragment offset/length pairs. -If more than four such entries are required, the header is -extended as necessary with -.Dq extra -header extensions (an older format that is no longer used), or -.Dq sparse -extensions. -.It "V" -The -.Va name -field should be interpreted as a tape/volume header name. -This entry should generally be ignored on extraction. -.El -.It Va magic -The magic field holds the five characters -.Dq ustar -followed by a space. -Note that POSIX ustar archives have a trailing null. -.It Va version -The version field holds a space character followed by a null. -Note that POSIX ustar archives use two copies of the ASCII digit -.Dq 0 . -.It Va atime , Va ctime -The time the file was last accessed and the time of -last change of file information, stored in octal as with -.Va mtime . -.It Va longnames -This field is apparently no longer used. -.It Sparse Va offset / Va numbytes -Each such structure specifies a single fragment of a sparse -file. -The two fields store values as octal numbers. -The fragments are each padded to a multiple of 512 bytes -in the archive. -On extraction, the list of fragments is collected from the -header (including any extension headers), and the data -is then read and written to the file at appropriate offsets. -.It Va isextended -If this is set to non-zero, the header will be followed by additional -.Dq sparse header -records. -Each such record contains information about as many as 21 additional -sparse blocks as shown here: -.Bd -literal -offset indent -struct gnu_sparse_header { - struct { - char offset[12]; - char numbytes[12]; - } sparse[21]; - char isextended[1]; - char padding[7]; -}; -.Ed -.It Va realsize -A binary representation of the file's complete size, with a much larger range -than the POSIX file size. -In particular, with -.Cm M -type files, the current entry is only a portion of the file. -In that case, the POSIX size field will indicate the size of this -entry; the -.Va realsize -field will indicate the total size of the file. -.El -.Ss GNU tar pax archives -GNU tar 1.14 (XXX check this XXX) and later will write -pax interchange format archives when you specify the -.Fl -posix -flag. -This format uses custom keywords to store sparse file information. -There have been three iterations of this support, referred to -as -.Dq 0.0 , -.Dq 0.1 , -and -.Dq 1.0 . -.Bl -tag -width indent -.It Cm GNU.sparse.numblocks , Cm GNU.sparse.offset , Cm GNU.sparse.numbytes , Cm GNU.sparse.size -The -.Dq 0.0 -format used an initial -.Cm GNU.sparse.numblocks -attribute to indicate the number of blocks in the file, a pair of -.Cm GNU.sparse.offset -and -.Cm GNU.sparse.numbytes -to indicate the offset and size of each block, -and a single -.Cm GNU.sparse.size -to indicate the full size of the file. -This is not the same as the size in the tar header because the -latter value does not include the size of any holes. -This format required that the order of attributes be preserved and -relied on readers accepting multiple appearances of the same attribute -names, which is not officially permitted by the standards. -.It Cm GNU.sparse.map -The -.Dq 0.1 -format used a single attribute that stored a comma-separated -list of decimal numbers. -Each pair of numbers indicated the offset and size, respectively, -of a block of data. -This does not work well if the archive is extracted by an archiver -that does not recognize this extension, since many pax implementations -simply discard unrecognized attributes. -.It Cm GNU.sparse.major , Cm GNU.sparse.minor , Cm GNU.sparse.name , Cm GNU.sparse.realsize -The -.Dq 1.0 -format stores the sparse block map in one or more 512-byte blocks -prepended to the file data in the entry body. -The pax attributes indicate the existence of this map -(via the -.Cm GNU.sparse.major -and -.Cm GNU.sparse.minor -fields) -and the full size of the file. -The -.Cm GNU.sparse.name -holds the true name of the file. -To avoid confusion, the name stored in the regular tar header -is a modified name so that extraction errors will be apparent -to users. -.El -.Ss Solaris Tar -XXX More Details Needed XXX -.Pp -Solaris tar (beginning with SunOS XXX 5.7 ?? XXX) supports an -.Dq extended -format that is fundamentally similar to pax interchange format, -with the following differences: -.Bl -bullet -compact -width indent -.It -Extended attributes are stored in an entry whose type is -.Cm X , -not -.Cm x , -as used by pax interchange format. -The detailed format of this entry appears to be the same -as detailed above for the -.Cm x -entry. -.It -An additional -.Cm A -entry is used to store an ACL for the following regular entry. -The body of this entry contains a seven-digit octal number -followed by a zero byte, followed by the -textual ACL description. -The octal value is the number of ACL entries -plus a constant that indicates the ACL type: 01000000 -for POSIX.1e ACLs and 03000000 for NFSv4 ACLs. -.El -.Ss AIX Tar -XXX More details needed XXX -.Ss Mac OS X Tar -The tar distributed with Apple's Mac OS X stores most regular files -as two separate entries in the tar archive. -The two entries have the same name except that the first -one has -.Dq ._ -added to the beginning of the name. -This first entry stores the -.Dq resource fork -with additional attributes for the file. -The Mac OS X -.Fn CopyFile -API is used to separate a file on disk into separate -resource and data streams and to reassemble those separate -streams when the file is restored to disk. -.Ss Other Extensions -One obvious extension to increase the size of files is to -eliminate the terminating characters from the various -numeric fields. -For example, the standard only allows the size field to contain -11 octal digits, reserving the twelfth byte for a trailing -NUL character. -Allowing 12 octal digits allows file sizes up to 64 GB. -.Pp -Another extension, utilized by GNU tar, star, and other newer -.Nm -implementations, permits binary numbers in the standard numeric fields. -This is flagged by setting the high bit of the first byte. -This permits 95-bit values for the length and time fields -and 63-bit values for the uid, gid, and device numbers. -GNU tar supports this extension for the -length, mtime, ctime, and atime fields. -Joerg Schilling's star program supports this extension for -all numeric fields. -Note that this extension is largely obsoleted by the extended attribute -record provided by the pax interchange format. -.Pp -Another early GNU extension allowed base-64 values rather than octal. -This extension was short-lived and is no longer supported by any -implementation. -.Sh SEE ALSO -.Xr ar 1 , -.Xr pax 1 , -.Xr tar 1 -.Sh STANDARDS -The -.Nm tar -utility is no longer a part of POSIX or the Single Unix Standard. -It last appeared in -.St -susv2 . -It has been supplanted in subsequent standards by -.Xr pax 1 . -The ustar format is currently part of the specification for the -.Xr pax 1 -utility. -The pax interchange file format is new with -.St -p1003.1-2001 . -.Sh HISTORY -A -.Nm tar -command appeared in Seventh Edition Unix, which was released in January, 1979. -It replaced the -.Nm tp -program from Fourth Edition Unix which in turn replaced the -.Nm tap -program from First Edition Unix. -John Gilmore's -.Nm pdtar -public-domain implementation (circa 1987) was highly influential -and formed the basis of -.Nm GNU tar -(circa 1988). -Joerg Shilling's -.Nm star -archiver is another open-source (GPL) archiver (originally developed -circa 1985) which features complete support for pax interchange -format. -.Pp -This documentation was written as part of the -.Nm libarchive -and -.Nm bsdtar -project by -.An Tim Kientzle Aq kientzle@FreeBSD.org . diff --git a/lib/libarchive/test/.cvsignore b/lib/libarchive/test/.cvsignore deleted file mode 100644 index b71f5a0..0000000 --- a/lib/libarchive/test/.cvsignore +++ /dev/null @@ -1,10 +0,0 @@ -*.tar -*.tar.gz -*.tgz -*.zip -.depend -.deps -.dirstamp -archive.h -libarchive_test -list.h diff --git a/lib/libarchive/test/Makefile b/lib/libarchive/test/Makefile index e05ff1f..c8fc0a6 100644 --- a/lib/libarchive/test/Makefile +++ b/lib/libarchive/test/Makefile @@ -1,8 +1,23 @@ # $FreeBSD$ -# Where to find the libarchive sources -LA_SRCDIR=${.CURDIR}/.. +LIBARCHIVEDIR= ${.CURDIR}/../../../contrib/libarchive +NO_MAN=yes + +PROG=libarchive_test +INTERNALPROG=yes # Don't install this; it's just for testing +DPADD=${LIBBZ2} ${LIBZ} ${LIBMD} ${LIBCRYPTO} ${LIBBSDXML} +LDADD= -L ${.OBJDIR}/.. -larchive +LDADD+= -lz -lbz2 -llzma -lmd -lcrypto -lbsdxml +CFLAGS+= -g +CFLAGS+= -I${.CURDIR}/.. -I${LIBARCHIVEDIR} -I${.OBJDIR} +CFLAGS+= -DHAVE_LIBLZMA=1 -DHAVE_LZMA_H=1 + +# Uncomment to link against dmalloc +#LDADD+= -L/usr/local/lib -ldmalloc +#CFLAGS+= -I/usr/local/include -DUSE_DMALLOC + +.PATH: ${LIBARCHIVEDIR}/libarchive/test TESTS= \ test_acl_basic.c \ test_acl_freebsd.c \ @@ -120,28 +135,14 @@ SRCS= \ main.c \ read_open_memory.c -NO_MAN=yes - -PROG=libarchive_test -INTERNALPROG=yes # Don't install this; it's just for testing -DPADD=${LIBBZ2} ${LIBZ} ${LIBMD} ${LIBCRYPTO} ${LIBBSDXML} -LDADD= -L ${.OBJDIR}/.. -larchive -LDADD+= -lz -lbz2 -llzma -lmd -lcrypto -lbsdxml -CFLAGS+= -g -CFLAGS+= -I${LA_SRCDIR} -I. -CFLAGS+= -DHAVE_LIBLZMA=1 -DHAVE_LZMA_H=1 - -# Uncomment to link against dmalloc -#LDADD+= -L/usr/local/lib -ldmalloc -#CFLAGS+= -I/usr/local/include -DUSE_DMALLOC - # Build libarchive_test and run it. check test: libarchive_test - ./libarchive_test -r ${.CURDIR} + ./libarchive_test -r ${LIBARCHIVEDIR}/libarchive/test # list.h is just a list of all tests, as indicated by DEFINE_TEST macro lines list.h: ${TESTS} Makefile - (cd ${.CURDIR}; cat test_*.c) | grep DEFINE_TEST > list.h + (cd ${LIBARCHIVEDIR}/libarchive/test; cat test_*.c) | \ + grep DEFINE_TEST > ${.OBJDIR}/list.h CLEANFILES += *.out *.o *.core *~ list.h .dirstamp .depend CLEANDIRS += .deps .libs diff --git a/lib/libarchive/test/README b/lib/libarchive/test/README deleted file mode 100644 index 0190b7c..0000000 --- a/lib/libarchive/test/README +++ /dev/null @@ -1,63 +0,0 @@ -$FreeBSD$ - -This is the test harness for libarchive. - -It compiles into a single program "libarchive_test" that is intended -to exercise as much of the library as possible. It is, of course, -very much a work in progress. - -Each test is a function named test_foo in a file named test_foo.c. -Note that the file name is the same as the function name. -Each file must start with this line: - - #include "test.h" - -The test function must be declared with a line of this form - - DEFINE_TEST(test_foo) - -Nothing else should appear on that line. - -When you add a test, please update the Makefile to add your -file to the list of tests. The Makefile and main.c use various -macro trickery to automatically collect a list of test functions -to be invoked. - -Each test function can rely on the following: - - * The current directory will be a freshly-created empty directory - suitable for that test. (The top-level main() creates a - directory for each separate test and chdir()s to that directory - before running the test.) - - * The test function should use assert(), assertA() and similar macros - defined in test.h. If you need to add new macros of this form, feel - free to do so. The current macro set includes assertEqualInt() and - assertEqualString() that print out additional detail about their - arguments if the assertion does fail. 'A' versions also accept - a struct archive * and display any error message from there on - failure. - - * You are encouraged to document each assertion with a failure() call - just before the assert. The failure() function is a printf-like - function whose text is displayed only if the assertion fails. It - can be used to display additional information relevant to the failure: - - failure("The data read from file %s did not match the data written to that file.", filename); - assert(strcmp(buff1, buff2) == 0); - - * Tests are encouraged to be economical with their memory and disk usage, - though this is not essential. The test is occasionally run under - a memory debugger to try to locate memory leaks in the library; - as a result, tests should be careful to release any memory they - allocate. - - * Disable tests on specific platforms as necessary. Please don't - use config.h to adjust feature requirements, as I want the tests - to also serve as a check on the configure process. The following - form is appropriate: - -#if !defined(__PLATFORM) && !defined(__Platform2__) - assert(xxxx) -#endif - diff --git a/lib/libarchive/test/main.c b/lib/libarchive/test/main.c deleted file mode 100644 index 0cd16a0..0000000 --- a/lib/libarchive/test/main.c +++ /dev/null @@ -1,2130 +0,0 @@ -/* - * Copyright (c) 2003-2009 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test.h" -#include -#include -#include -#include - -/* - * This same file is used pretty much verbatim for all test harnesses. - * - * The next few lines are the only differences. - * TODO: Move this into a separate configuration header, have all test - * suites share one copy of this file. - */ -__FBSDID("$FreeBSD$"); -#define KNOWNREF "test_compat_gtar_1.tar.uu" -#define ENVBASE "LIBARCHIVE" /* Prefix for environment variables. */ -#undef PROGRAM /* Testing a library, not a program. */ -#define LIBRARY "libarchive" -#define EXTRA_DUMP(x) archive_error_string((struct archive *)(x)) -#define EXTRA_VERSION archive_version() - -/* - * - * Windows support routines - * - * Note: Configuration is a tricky issue. Using HAVE_* feature macros - * in the test harness is dangerous because they cover up - * configuration errors. The classic example of this is omitting a - * configure check. If libarchive and libarchive_test both look for - * the same feature macro, such errors are hard to detect. Platform - * macros (e.g., _WIN32 or __GNUC__) are a little better, but can - * easily lead to very messy code. It's best to limit yourself - * to only the most generic programming techniques in the test harness - * and thus avoid conditionals altogether. Where that's not possible, - * try to minimize conditionals by grouping platform-specific tests in - * one place (e.g., test_acl_freebsd) or by adding new assert() - * functions (e.g., assertMakeHardlink()) to cover up platform - * differences. Platform-specific coding in libarchive_test is often - * a symptom that some capability is missing from libarchive itself. - */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#include -#include -#ifndef F_OK -#define F_OK (0) -#endif -#ifndef S_ISDIR -#define S_ISDIR(m) ((m) & _S_IFDIR) -#endif -#ifndef S_ISREG -#define S_ISREG(m) ((m) & _S_IFREG) -#endif -#if !defined(__BORLANDC__) -#define access _access -#define chdir _chdir -#endif -#ifndef fileno -#define fileno _fileno -#endif -/*#define fstat _fstat64*/ -#if !defined(__BORLANDC__) -#define getcwd _getcwd -#endif -#define lstat stat -/*#define lstat _stat64*/ -/*#define stat _stat64*/ -#define rmdir _rmdir -#if !defined(__BORLANDC__) -#define strdup _strdup -#define umask _umask -#endif -#define int64_t __int64 -#endif - -#if defined(HAVE__CrtSetReportMode) -# include -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) -void *GetFunctionKernel32(const char *name) -{ - static HINSTANCE lib; - static int set; - if (!set) { - set = 1; - lib = LoadLibrary("kernel32.dll"); - } - if (lib == NULL) { - fprintf(stderr, "Can't load kernel32.dll?!\n"); - exit(1); - } - return (void *)GetProcAddress(lib, name); -} - -static int -my_CreateSymbolicLinkA(const char *linkname, const char *target, int flags) -{ - static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateSymbolicLinkA"); - } - return f == NULL ? 0 : (*f)(linkname, target, flags); -} - -static int -my_CreateHardLinkA(const char *linkname, const char *target) -{ - static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateHardLinkA"); - } - return f == NULL ? 0 : (*f)(linkname, target, NULL); -} - -int -my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) -{ - HANDLE h; - int r; - - memset(bhfi, 0, sizeof(*bhfi)); - h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) - return (0); - r = GetFileInformationByHandle(h, bhfi); - CloseHandle(h); - return (r); -} -#endif - -#if defined(HAVE__CrtSetReportMode) -static void -invalid_parameter_handler(const wchar_t * expression, - const wchar_t * function, const wchar_t * file, - unsigned int line, uintptr_t pReserved) -{ - /* nop */ -} -#endif - -/* - * - * OPTIONS FLAGS - * - */ - -/* Enable core dump on failure. */ -static int dump_on_failure = 0; -/* Default is to remove temp dirs and log data for successful tests. */ -static int keep_temp_files = 0; -/* Default is to just report pass/fail for each test. */ -static int verbosity = 0; -#define VERBOSITY_SUMMARY_ONLY -1 /* -q */ -#define VERBOSITY_PASSFAIL 0 /* Default */ -#define VERBOSITY_LIGHT_REPORT 1 /* -v */ -#define VERBOSITY_FULL 2 /* -vv */ -/* A few places generate even more output for verbosity > VERBOSITY_FULL, - * mostly for debugging the test harness itself. */ -/* Cumulative count of assertion failures. */ -static int failures = 0; -/* Cumulative count of reported skips. */ -static int skips = 0; -/* Cumulative count of assertions checked. */ -static int assertions = 0; - -/* Directory where uuencoded reference files can be found. */ -static const char *refdir; - -/* - * Report log information selectively to console and/or disk log. - */ -static int log_console = 0; -static FILE *logfile; -static void -vlogprintf(const char *fmt, va_list ap) -{ -#ifdef va_copy - va_list lfap; - va_copy(lfap, ap); -#endif - if (log_console) - vfprintf(stdout, fmt, ap); - if (logfile != NULL) -#ifdef va_copy - vfprintf(logfile, fmt, lfap); - va_end(lfap); -#else - vfprintf(logfile, fmt, ap); -#endif -} - -static void -logprintf(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vlogprintf(fmt, ap); - va_end(ap); -} - -/* Set up a message to display only if next assertion fails. */ -static char msgbuff[4096]; -static const char *msg, *nextmsg; -void -failure(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vsprintf(msgbuff, fmt, ap); - va_end(ap); - nextmsg = msgbuff; -} - -/* - * Copy arguments into file-local variables. - * This was added to permit vararg assert() functions without needing - * variadic wrapper macros. Turns out that the vararg capability is almost - * never used, so almost all of the vararg assertions can be simplified - * by removing the vararg capability and reworking the wrapper macro to - * pass __FILE__, __LINE__ directly into the function instead of using - * this hook. I suspect this machinery is used so rarely that we - * would be better off just removing it entirely. That would simplify - * the code here noticably. - */ -static const char *test_filename; -static int test_line; -static void *test_extra; -void assertion_setup(const char *filename, int line) -{ - test_filename = filename; - test_line = line; -} - -/* Called at the beginning of each assert() function. */ -static void -assertion_count(const char *file, int line) -{ - (void)file; /* UNUSED */ - (void)line; /* UNUSED */ - ++assertions; - /* Proper handling of "failure()" message. */ - msg = nextmsg; - nextmsg = NULL; - /* Uncomment to print file:line after every assertion. - * Verbose, but occasionally useful in tracking down crashes. */ - /* printf("Checked %s:%d\n", file, line); */ -} - -/* - * For each test source file, we remember how many times each - * assertion was reported. Cleared before each new test, - * used by test_summarize(). - */ -static struct line { - int count; - int skip; -} failed_lines[10000]; - -/* Count this failure, setup up log destination and handle initial report. */ -static void -failure_start(const char *filename, int line, const char *fmt, ...) -{ - va_list ap; - - /* Record another failure for this line. */ - ++failures; - /* test_filename = filename; */ - failed_lines[line].count++; - - /* Determine whether to log header to console. */ - switch (verbosity) { - case VERBOSITY_LIGHT_REPORT: - log_console = (failed_lines[line].count < 2); - break; - default: - log_console = (verbosity >= VERBOSITY_FULL); - } - - /* Log file:line header for this failure */ - va_start(ap, fmt); -#if _MSC_VER - logprintf("%s(%d): ", filename, line); -#else - logprintf("%s:%d: ", filename, line); -#endif - vlogprintf(fmt, ap); - va_end(ap); - logprintf("\n"); - - if (msg != NULL && msg[0] != '\0') { - logprintf(" Description: %s\n", msg); - msg = NULL; - } - - /* Determine whether to log details to console. */ - if (verbosity == VERBOSITY_LIGHT_REPORT) - log_console = 0; -} - -/* Complete reporting of failed tests. */ -/* - * The 'extra' hook here is used by libarchive to include libarchive - * error messages with assertion failures. It could also be used - * to add strerror() output, for example. Just define the EXTRA_DUMP() - * macro appropriately. - */ -static void -failure_finish(void *extra) -{ - (void)extra; /* UNUSED (maybe) */ -#ifdef EXTRA_DUMP - if (extra != NULL) - logprintf(" detail: %s\n", EXTRA_DUMP(extra)); -#endif - - if (dump_on_failure) { - fprintf(stderr, - " *** forcing core dump so failure can be debugged ***\n"); - abort(); - exit(1); - } -} - -/* Inform user that we're skipping some checks. */ -void -test_skipping(const char *fmt, ...) -{ - char buff[1024]; - va_list ap; - - va_start(ap, fmt); - vsprintf(buff, fmt, ap); - va_end(ap); - /* failure_start() isn't quite right, but is awfully convenient. */ - failure_start(test_filename, test_line, "SKIPPING: %s", buff); - --failures; /* Undo failures++ in failure_start() */ - /* Don't failure_finish() here. */ - /* Mark as skip, so doesn't count as failed test. */ - failed_lines[test_line].skip = 1; - ++skips; -} - -/* - * - * ASSERTIONS - * - */ - -/* Generic assert() just displays the failed condition. */ -int -assertion_assert(const char *file, int line, int value, - const char *condition, void *extra) -{ - assertion_count(file, line); - if (!value) { - failure_start(file, line, "Assertion failed: %s", condition); - failure_finish(extra); - } - return (value); -} - -/* chdir() and report any errors */ -int -assertion_chdir(const char *file, int line, const char *pathname) -{ - assertion_count(file, line); - if (chdir(pathname) == 0) - return (1); - failure_start(file, line, "chdir(\"%s\")", pathname); - failure_finish(NULL); - return (0); - -} - -/* Verify two integers are equal. */ -int -assertion_equal_int(const char *file, int line, - long long v1, const char *e1, long long v2, const char *e2, void *extra) -{ - assertion_count(file, line); - if (v1 == v2) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - logprintf(" %s=%lld (0x%llx, 0%llo)\n", e1, v1, v1, v1); - logprintf(" %s=%lld (0x%llx, 0%llo)\n", e2, v2, v2, v2); - failure_finish(extra); - return (0); -} - -static void strdump(const char *e, const char *p) -{ - const char *q = p; - - logprintf(" %s = ", e); - if (p == NULL) { - logprintf("NULL"); - return; - } - logprintf("\""); - while (*p != '\0') { - unsigned int c = 0xff & *p++; - switch (c) { - case '\a': printf("\a"); break; - case '\b': printf("\b"); break; - case '\n': printf("\n"); break; - case '\r': printf("\r"); break; - default: - if (c >= 32 && c < 127) - logprintf("%c", c); - else - logprintf("\\x%02X", c); - } - } - logprintf("\""); - logprintf(" (length %d)\n", q == NULL ? -1 : (int)strlen(q)); -} - -/* Verify two strings are equal, dump them if not. */ -int -assertion_equal_string(const char *file, int line, - const char *v1, const char *e1, - const char *v2, const char *e2, - void *extra) -{ - assertion_count(file, line); - if (v1 == v2 || (v1 != NULL && v2 != NULL && strcmp(v1, v2) == 0)) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - strdump(e1, v1); - strdump(e2, v2); - failure_finish(extra); - return (0); -} - -static void -wcsdump(const char *e, const wchar_t *w) -{ - logprintf(" %s = ", e); - if (w == NULL) { - logprintf("(null)"); - return; - } - logprintf("\""); - while (*w != L'\0') { - unsigned int c = *w++; - if (c >= 32 && c < 127) - logprintf("%c", c); - else if (c < 256) - logprintf("\\x%02X", c); - else if (c < 0x10000) - logprintf("\\u%04X", c); - else - logprintf("\\U%08X", c); - } - logprintf("\"\n"); -} - -#ifndef HAVE_WCSCMP -static int -wcscmp(const wchar_t *s1, const wchar_t *s2) -{ - - while (*s1 == *s2++) { - if (*s1++ == L'\0') - return 0; - } - if (*s1 > *--s2) - return 1; - else - return -1; -} -#endif - -/* Verify that two wide strings are equal, dump them if not. */ -int -assertion_equal_wstring(const char *file, int line, - const wchar_t *v1, const char *e1, - const wchar_t *v2, const char *e2, - void *extra) -{ - assertion_count(file, line); - if (v1 == v2 || wcscmp(v1, v2) == 0) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - wcsdump(e1, v1); - wcsdump(e2, v2); - failure_finish(extra); - return (0); -} - -/* - * Pretty standard hexdump routine. As a bonus, if ref != NULL, then - * any bytes in p that differ from ref will be highlighted with '_' - * before and after the hex value. - */ -static void -hexdump(const char *p, const char *ref, size_t l, size_t offset) -{ - size_t i, j; - char sep; - - if (p == NULL) { - logprintf("(null)\n"); - return; - } - for(i=0; i < l; i+=16) { - logprintf("%04x", (unsigned)(i + offset)); - sep = ' '; - for (j = 0; j < 16 && i + j < l; j++) { - if (ref != NULL && p[i + j] != ref[i + j]) - sep = '_'; - logprintf("%c%02x", sep, 0xff & (int)p[i+j]); - if (ref != NULL && p[i + j] == ref[i + j]) - sep = ' '; - } - for (; j < 16; j++) { - logprintf("%c ", sep); - sep = ' '; - } - logprintf("%c", sep); - for (j=0; j < 16 && i + j < l; j++) { - int c = p[i + j]; - if (c >= ' ' && c <= 126) - logprintf("%c", c); - else - logprintf("."); - } - logprintf("\n"); - } -} - -/* Verify that two blocks of memory are the same, display the first - * block of differences if they're not. */ -int -assertion_equal_mem(const char *file, int line, - const void *_v1, const char *e1, - const void *_v2, const char *e2, - size_t l, const char *ld, void *extra) -{ - const char *v1 = (const char *)_v1; - const char *v2 = (const char *)_v2; - size_t offset; - - assertion_count(file, line); - if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0)) - return (1); - - failure_start(file, line, "%s != %s", e1, e2); - logprintf(" size %s = %d\n", ld, (int)l); - /* Dump 48 bytes (3 lines) so that the first difference is - * in the second line. */ - offset = 0; - while (l > 64 && memcmp(v1, v2, 32) == 0) { - /* Two lines agree, so step forward one line. */ - v1 += 16; - v2 += 16; - l -= 16; - offset += 16; - } - logprintf(" Dump of %s\n", e1); - hexdump(v1, v2, l < 64 ? l : 64, offset); - logprintf(" Dump of %s\n", e2); - hexdump(v2, v1, l < 64 ? l : 64, offset); - logprintf("\n"); - failure_finish(extra); - return (0); -} - -/* Verify that the named file exists and is empty. */ -int -assertion_empty_file(const char *f1fmt, ...) -{ - char buff[1024]; - char f1[1024]; - struct stat st; - va_list ap; - ssize_t s; - FILE *f; - - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); - - if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); - failure_finish(NULL); - return (0); - } - if (st.st_size == 0) - return (1); - - failure_start(test_filename, test_line, "File should be empty: %s", f1); - logprintf(" File size: %d\n", (int)st.st_size); - logprintf(" Contents:\n"); - f = fopen(f1, "rb"); - if (f == NULL) { - logprintf(" Unable to open %s\n", f1); - } else { - s = ((off_t)sizeof(buff) < st.st_size) ? - (ssize_t)sizeof(buff) : (ssize_t)st.st_size; - s = fread(buff, 1, s, f); - hexdump(buff, NULL, s, 0); - fclose(f); - } - failure_finish(NULL); - return (0); -} - -/* Verify that the named file exists and is not empty. */ -int -assertion_non_empty_file(const char *f1fmt, ...) -{ - char f1[1024]; - struct stat st; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); - - if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); - failure_finish(NULL); - return (0); - } - if (st.st_size == 0) { - failure_start(test_filename, test_line, "File empty: %s", f1); - failure_finish(NULL); - return (0); - } - return (1); -} - -/* Verify that two files have the same contents. */ -/* TODO: hexdump the first bytes that actually differ. */ -int -assertion_equal_file(const char *fn1, const char *f2pattern, ...) -{ - char fn2[1024]; - va_list ap; - char buff1[1024]; - char buff2[1024]; - FILE *f1, *f2; - int n1, n2; - - assertion_count(test_filename, test_line); - va_start(ap, f2pattern); - vsprintf(fn2, f2pattern, ap); - va_end(ap); - - f1 = fopen(fn1, "rb"); - f2 = fopen(fn2, "rb"); - for (;;) { - n1 = fread(buff1, 1, sizeof(buff1), f1); - n2 = fread(buff2, 1, sizeof(buff2), f2); - if (n1 != n2) - break; - if (n1 == 0 && n2 == 0) { - fclose(f1); - fclose(f2); - return (1); - } - if (memcmp(buff1, buff2, n1) != 0) - break; - } - fclose(f1); - fclose(f2); - failure_start(test_filename, test_line, "Files not identical"); - logprintf(" file1=\"%s\"\n", fn1); - logprintf(" file2=\"%s\"\n", fn2); - failure_finish(test_extra); - return (0); -} - -/* Verify that the named file does exist. */ -int -assertion_file_exists(const char *fpattern, ...) -{ - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); - -#if defined(_WIN32) && !defined(__CYGWIN__) - if (!_access(f, 0)) - return (1); -#else - if (!access(f, F_OK)) - return (1); -#endif - failure_start(test_filename, test_line, "File should exist: %s", f); - failure_finish(test_extra); - return (0); -} - -/* Verify that the named file doesn't exist. */ -int -assertion_file_not_exists(const char *fpattern, ...) -{ - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); - -#if defined(_WIN32) && !defined(__CYGWIN__) - if (_access(f, 0)) - return (1); -#else - if (access(f, F_OK)) - return (1); -#endif - failure_start(test_filename, test_line, "File should not exist: %s", f); - failure_finish(test_extra); - return (0); -} - -/* Compare the contents of a file to a block of memory. */ -int -assertion_file_contents(const void *buff, int s, const char *fpattern, ...) -{ - char fn[1024]; - va_list ap; - char *contents; - FILE *f; - int n; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(fn, fpattern, ap); - va_end(ap); - - f = fopen(fn, "rb"); - if (f == NULL) { - failure_start(test_filename, test_line, - "File should exist: %s", fn); - failure_finish(test_extra); - return (0); - } - contents = malloc(s * 2); - n = fread(contents, 1, s * 2, f); - fclose(f); - if (n == s && memcmp(buff, contents, s) == 0) { - free(contents); - return (1); - } - failure_start(test_filename, test_line, "File contents don't match"); - logprintf(" file=\"%s\"\n", fn); - if (n > 0) - hexdump(contents, buff, n > 512 ? 512 : n, 0); - else { - logprintf(" File empty, contents should be:\n"); - hexdump(buff, NULL, s > 512 ? 512 : n, 0); - } - failure_finish(test_extra); - free(contents); - return (0); -} - -/* Check the contents of a text file, being tolerant of line endings. */ -int -assertion_text_file_contents(const char *buff, const char *fn) -{ - char *contents; - const char *btxt, *ftxt; - FILE *f; - int n, s; - - assertion_count(test_filename, test_line); - f = fopen(fn, "r"); - s = strlen(buff); - contents = malloc(s * 2 + 128); - n = fread(contents, 1, s * 2 + 128 - 1, f); - if (n >= 0) - contents[n] = '\0'; - fclose(f); - /* Compare texts. */ - btxt = buff; - ftxt = (const char *)contents; - while (*btxt != '\0' && *ftxt != '\0') { - if (*btxt == *ftxt) { - ++btxt; - ++ftxt; - continue; - } - if (btxt[0] == '\n' && ftxt[0] == '\r' && ftxt[1] == '\n') { - /* Pass over different new line characters. */ - ++btxt; - ftxt += 2; - continue; - } - break; - } - if (*btxt == '\0' && *ftxt == '\0') { - free(contents); - return (1); - } - failure_start(test_filename, test_line, "Contents don't match"); - logprintf(" file=\"%s\"\n", fn); - if (n > 0) - hexdump(contents, buff, n, 0); - else { - logprintf(" File empty, contents should be:\n"); - hexdump(buff, NULL, s, 0); - } - failure_finish(test_extra); - free(contents); - return (0); -} - -/* Test that two paths point to the same file. */ -/* As a side-effect, asserts that both files exist. */ -static int -is_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2; - int r; - - assertion_count(file, line); - r = my_GetFileInformationByName(path1, &bhfi1); - if (r == 0) { - failure_start(file, line, "File %s can't be inspected?", path1); - failure_finish(NULL); - return (0); - } - r = my_GetFileInformationByName(path2, &bhfi2); - if (r == 0) { - failure_start(file, line, "File %s can't be inspected?", path2); - failure_finish(NULL); - return (0); - } - return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber - && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh - && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow); -#else - struct stat st1, st2; - int r; - - assertion_count(file, line); - r = lstat(path1, &st1); - if (r != 0) { - failure_start(file, line, "File should exist: %s", path1); - failure_finish(NULL); - return (0); - } - r = lstat(path2, &st2); - if (r != 0) { - failure_start(file, line, "File should exist: %s", path2); - failure_finish(NULL); - return (0); - } - return (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev); -#endif -} - -int -assertion_is_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ - if (is_hardlink(file, line, path1, path2)) - return (1); - failure_start(file, line, - "Files %s and %s are not hardlinked", path1, path2); - failure_finish(NULL); - return (0); -} - -int -assertion_is_not_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ - if (!is_hardlink(file, line, path1, path2)) - return (1); - failure_start(file, line, - "Files %s and %s should not be hardlinked", path1, path2); - failure_finish(NULL); - return (0); -} - -/* Verify a/b/mtime of 'pathname'. */ -/* If 'recent', verify that it's within last 10 seconds. */ -static int -assertion_file_time(const char *file, int line, - const char *pathname, long t, long nsec, char type, int recent) -{ - long long filet, filet_nsec; - int r; - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define EPOC_TIME (116444736000000000ULL) - FILETIME ftime, fbirthtime, fatime, fmtime; - ULARGE_INTEGER wintm; - HANDLE h; - ftime.dwLowDateTime = 0; - ftime.dwHighDateTime = 0; - - assertion_count(file, line); - h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) { - failure_start(file, line, "Can't access %s\n", pathname); - failure_finish(NULL); - return (0); - } - r = GetFileTime(h, &fbirthtime, &fatime, &fmtime); - switch (type) { - case 'a': ftime = fatime; break; - case 'b': ftime = fbirthtime; break; - case 'm': ftime = fmtime; break; - } - CloseHandle(h); - if (r == 0) { - failure_start(file, line, "Can't GetFileTime %s\n", pathname); - failure_finish(NULL); - return (0); - } - wintm.LowPart = ftime.dwLowDateTime; - wintm.HighPart = ftime.dwHighDateTime; - filet = (wintm.QuadPart - EPOC_TIME) / 10000000; - filet_nsec = ((wintm.QuadPart - EPOC_TIME) % 10000000) * 100; - nsec = (nsec / 100) * 100; /* Round the request */ -#else - struct stat st; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, "Can't stat %s\n", pathname); - failure_finish(NULL); - return (0); - } - switch (type) { - case 'a': filet = st.st_atime; break; - case 'm': filet = st.st_mtime; break; - case 'b': filet = 0; break; - default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); - exit(1); - } -#if defined(__FreeBSD__) - switch (type) { - case 'a': filet_nsec = st.st_atimespec.tv_nsec; break; - case 'b': filet = st.st_birthtime; - filet_nsec = st.st_birthtimespec.tv_nsec; break; - case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break; - default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); - exit(1); - } - /* FreeBSD generally only stores to microsecond res, so round. */ - filet_nsec = (filet_nsec / 1000) * 1000; - nsec = (nsec / 1000) * 1000; -#else - filet_nsec = nsec = 0; /* Generic POSIX only has whole seconds. */ - if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */ -#if defined(__HAIKU__) - if (type == 'a') return (1); /* Haiku doesn't have atime. */ -#endif -#endif -#endif - if (recent) { - /* Check that requested time is up-to-date. */ - time_t now = time(NULL); - if (filet < now - 10 || filet > now + 1) { - failure_start(file, line, - "File %s has %ctime %ld, %ld seconds ago\n", - pathname, type, filet, now - filet); - failure_finish(NULL); - return (0); - } - } else if (filet != t || filet_nsec != nsec) { - failure_start(file, line, - "File %s has %ctime %ld.%09ld, expected %ld.%09ld", - pathname, type, filet, filet_nsec, t, nsec); - failure_finish(NULL); - return (0); - } - return (1); -} - -/* Verify atime of 'pathname'. */ -int -assertion_file_atime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'a', 0); -} - -/* Verify atime of 'pathname' is up-to-date. */ -int -assertion_file_atime_recent(const char *file, int line, const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'a', 1); -} - -/* Verify birthtime of 'pathname'. */ -int -assertion_file_birthtime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'b', 0); -} - -/* Verify birthtime of 'pathname' is up-to-date. */ -int -assertion_file_birthtime_recent(const char *file, int line, - const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); -} - -/* Verify mtime of 'pathname'. */ -int -assertion_file_mtime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'm', 0); -} - -/* Verify mtime of 'pathname' is up-to-date. */ -int -assertion_file_mtime_recent(const char *file, int line, const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'm', 1); -} - -/* Verify number of links to 'pathname'. */ -int -assertion_file_nlinks(const char *file, int line, - const char *pathname, int nlinks) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - BY_HANDLE_FILE_INFORMATION bhfi; - int r; - - assertion_count(file, line); - r = my_GetFileInformationByName(pathname, &bhfi); - if (r != 0 && bhfi.nNumberOfLinks == (DWORD)nlinks) - return (1); - failure_start(file, line, "File %s has %d links, expected %d", - pathname, bhfi.nNumberOfLinks, nlinks); - failure_finish(NULL); - return (0); -#else - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r == 0 && st.st_nlink == nlinks) - return (1); - failure_start(file, line, "File %s has %d links, expected %d", - pathname, st.st_nlink, nlinks); - failure_finish(NULL); - return (0); -#endif -} - -/* Verify size of 'pathname'. */ -int -assertion_file_size(const char *file, int line, const char *pathname, long size) -{ - int64_t filesize; - int r; - - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - { - BY_HANDLE_FILE_INFORMATION bhfi; - r = !my_GetFileInformationByName(pathname, &bhfi); - filesize = ((int64_t)bhfi.nFileSizeHigh << 32) + bhfi.nFileSizeLow; - } -#else - { - struct stat st; - r = lstat(pathname, &st); - filesize = st.st_size; - } -#endif - if (r == 0 && filesize == size) - return (1); - failure_start(file, line, "File %s has size %ld, expected %ld", - pathname, (long)filesize, (long)size); - failure_finish(NULL); - return (0); -} - -/* Assert that 'pathname' is a dir. If mode >= 0, verify that too. */ -int -assertion_is_dir(const char *file, int line, const char *pathname, int mode) -{ - struct stat st; - int r; - -#if defined(_WIN32) && !defined(__CYGWIN__) - (void)mode; /* UNUSED */ -#endif - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, "Dir should exist: %s", pathname); - failure_finish(NULL); - return (0); - } - if (!S_ISDIR(st.st_mode)) { - failure_start(file, line, "%s is not a dir", pathname); - failure_finish(NULL); - return (0); - } -#if !defined(_WIN32) || defined(__CYGWIN__) - /* Windows doesn't handle permissions the same way as POSIX, - * so just ignore the mode tests. */ - /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { - failure_start(file, line, "Dir %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); - failure_finish(NULL); - return (0); - } -#endif - return (1); -} - -/* Verify that 'pathname' is a regular file. If 'mode' is >= 0, - * verify that too. */ -int -assertion_is_reg(const char *file, int line, const char *pathname, int mode) -{ - struct stat st; - int r; - -#if defined(_WIN32) && !defined(__CYGWIN__) - (void)mode; /* UNUSED */ -#endif - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0 || !S_ISREG(st.st_mode)) { - failure_start(file, line, "File should exist: %s", pathname); - failure_finish(NULL); - return (0); - } -#if !defined(_WIN32) || defined(__CYGWIN__) - /* Windows doesn't handle permissions the same way as POSIX, - * so just ignore the mode tests. */ - /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { - failure_start(file, line, "File %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); - failure_finish(NULL); - return (0); - } -#endif - return (1); -} - -/* Check whether 'pathname' is a symbolic link. If 'contents' is - * non-NULL, verify that the symlink has those contents. */ -static int -is_symlink(const char *file, int line, - const char *pathname, const char *contents) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - (void)pathname; /* UNUSED */ - (void)contents; /* UNUSED */ - assertion_count(file, line); - /* Windows sort-of has real symlinks, but they're only usable - * by privileged users and are crippled even then, so there's - * really not much point in bothering with this. */ - return (0); -#else - char buff[300]; - struct stat st; - ssize_t linklen; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, - "Symlink should exist: %s", pathname); - failure_finish(NULL); - return (0); - } - if (!S_ISLNK(st.st_mode)) - return (0); - if (contents == NULL) - return (1); - linklen = readlink(pathname, buff, sizeof(buff)); - if (linklen < 0) { - failure_start(file, line, "Can't read symlink %s", pathname); - failure_finish(NULL); - return (0); - } - buff[linklen] = '\0'; - if (strcmp(buff, contents) != 0) - return (0); - return (1); -#endif -} - -/* Assert that path is a symlink that (optionally) contains contents. */ -int -assertion_is_symlink(const char *file, int line, - const char *path, const char *contents) -{ - if (is_symlink(file, line, path, contents)) - return (1); - if (contents) - failure_start(file, line, "File %s is not a symlink to %s", - path, contents); - else - failure_start(file, line, "File %s is not a symlink", path); - failure_finish(NULL); - return (0); -} - - -/* Create a directory and report any errors. */ -int -assertion_make_dir(const char *file, int line, const char *dirname, int mode) -{ - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - (void)mode; /* UNUSED */ - if (0 == _mkdir(dirname)) - return (1); -#else - if (0 == mkdir(dirname, mode)) - return (1); -#endif - failure_start(file, line, "Could not create directory %s", dirname); - failure_finish(NULL); - return(0); -} - -/* Create a file with the specified contents and report any failures. */ -int -assertion_make_file(const char *file, int line, - const char *path, int mode, const char *contents) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* TODO: Rework this to set file mode as well. */ - FILE *f; - (void)mode; /* UNUSED */ - assertion_count(file, line); - f = fopen(path, "wb"); - if (f == NULL) { - failure_start(file, line, "Could not create file %s", path); - failure_finish(NULL); - return (0); - } - if (contents != NULL) { - if (strlen(contents) - != fwrite(contents, 1, strlen(contents), f)) { - fclose(f); - failure_start(file, line, - "Could not write file %s", path); - failure_finish(NULL); - return (0); - } - } - fclose(f); - return (1); -#else - int fd; - assertion_count(file, line); - fd = open(path, O_CREAT | O_WRONLY, mode >= 0 ? mode : 0644); - if (fd < 0) { - failure_start(file, line, "Could not create %s", path); - failure_finish(NULL); - return (0); - } - if (contents != NULL) { - if ((ssize_t)strlen(contents) - != write(fd, contents, strlen(contents))) { - close(fd); - failure_start(file, line, "Could not write to %s", path); - failure_finish(NULL); - return (0); - } - } - close(fd); - return (1); -#endif -} - -/* Create a hardlink and report any failures. */ -int -assertion_make_hardlink(const char *file, int line, - const char *newpath, const char *linkto) -{ - int succeeded; - - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - succeeded = my_CreateHardLinkA(newpath, linkto); -#elif HAVE_LINK - succeeded = !link(linkto, newpath); -#else - succeeded = 0; -#endif - if (succeeded) - return (1); - failure_start(file, line, "Could not create hardlink"); - logprintf(" New link: %s\n", newpath); - logprintf(" Old name: %s\n", linkto); - failure_finish(NULL); - return(0); -} - -/* Create a symlink and report any failures. */ -int -assertion_make_symlink(const char *file, int line, - const char *newpath, const char *linkto) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - int targetIsDir = 0; /* TODO: Fix this */ - assertion_count(file, line); - if (my_CreateSymbolicLinkA(newpath, linkto, targetIsDir)) - return (1); -#elif HAVE_SYMLINK - assertion_count(file, line); - if (0 == symlink(linkto, newpath)) - return (1); -#endif - failure_start(file, line, "Could not create symlink"); - logprintf(" New link: %s\n", newpath); - logprintf(" Old name: %s\n", linkto); - failure_finish(NULL); - return(0); -} - -/* Set umask, report failures. */ -int -assertion_umask(const char *file, int line, int mask) -{ - assertion_count(file, line); - (void)file; /* UNUSED */ - (void)line; /* UNUSED */ - umask(mask); - return (1); -} - -/* - * - * UTILITIES for use by tests. - * - */ - -/* - * Check whether platform supports symlinks. This is intended - * for tests to use in deciding whether to bother testing symlink - * support; if the platform doesn't support symlinks, there's no point - * in checking whether the program being tested can create them. - * - * Note that the first time this test is called, we actually go out to - * disk to create and verify a symlink. This is necessary because - * symlink support is actually a property of a particular filesystem - * and can thus vary between directories on a single system. After - * the first call, this returns the cached result from memory, so it's - * safe to call it as often as you wish. - */ -int -canSymlink(void) -{ - /* Remember the test result */ - static int value = 0, tested = 0; - if (tested) - return (value); - - ++tested; - assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a"); - /* Note: Cygwin has its own symlink() emulation that does not - * use the Win32 CreateSymbolicLink() function. */ -#if defined(_WIN32) && !defined(__CYGWIN__) - value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0) - && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0"); -#elif HAVE_SYMLINK - value = (0 == symlink("canSymlink.0", "canSymlink.1")) - && is_symlink(__FILE__, __LINE__, "canSymlink.1","canSymlink.0"); -#endif - return (value); -} - -/* - * Can this platform run the gzip program? - */ -/* Platform-dependent options for hiding the output of a subcommand. */ -#if defined(_WIN32) && !defined(__CYGWIN__) -static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ -#else -static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ -#endif -int -canGzip(void) -{ - static int tested = 0, value = 0; - if (!tested) { - tested = 1; - if (systemf("gzip -V %s", redirectArgs) == 0) - value = 1; - } - return (value); -} - -/* - * Can this platform run the gunzip program? - */ -int -canGunzip(void) -{ - static int tested = 0, value = 0; - if (!tested) { - tested = 1; - if (systemf("gunzip -V %s", redirectArgs) == 0) - value = 1; - } - return (value); -} - -/* - * Sleep as needed; useful for verifying disk timestamp changes by - * ensuring that the wall-clock time has actually changed before we - * go back to re-read something from disk. - */ -void -sleepUntilAfter(time_t t) -{ - while (t >= time(NULL)) -#if defined(_WIN32) && !defined(__CYGWIN__) - Sleep(500); -#else - sleep(1); -#endif -} - -/* - * Call standard system() call, but build up the command line using - * sprintf() conventions. - */ -int -systemf(const char *fmt, ...) -{ - char buff[8192]; - va_list ap; - int r; - - va_start(ap, fmt); - vsprintf(buff, fmt, ap); - if (verbosity > VERBOSITY_FULL) - logprintf("Cmd: %s\n", buff); - r = system(buff); - va_end(ap); - return (r); -} - -/* - * Slurp a file into memory for ease of comparison and testing. - * Returns size of file in 'sizep' if non-NULL, null-terminates - * data in memory for ease of use. - */ -char * -slurpfile(size_t * sizep, const char *fmt, ...) -{ - char filename[8192]; - struct stat st; - va_list ap; - char *p; - ssize_t bytes_read; - FILE *f; - int r; - - va_start(ap, fmt); - vsprintf(filename, fmt, ap); - va_end(ap); - - f = fopen(filename, "rb"); - if (f == NULL) { - /* Note: No error; non-existent file is okay here. */ - return (NULL); - } - r = fstat(fileno(f), &st); - if (r != 0) { - logprintf("Can't stat file %s\n", filename); - fclose(f); - return (NULL); - } - p = malloc((size_t)st.st_size + 1); - if (p == NULL) { - logprintf("Can't allocate %ld bytes of memory to read file %s\n", - (long int)st.st_size, filename); - fclose(f); - return (NULL); - } - bytes_read = fread(p, 1, (size_t)st.st_size, f); - if (bytes_read < st.st_size) { - logprintf("Can't read file %s\n", filename); - fclose(f); - free(p); - return (NULL); - } - p[st.st_size] = '\0'; - if (sizep != NULL) - *sizep = (size_t)st.st_size; - fclose(f); - return (p); -} - -/* Read a uuencoded file from the reference directory, decode, and - * write the result into the current directory. */ -#define UUDECODE(c) (((c) - 0x20) & 0x3f) -void -extract_reference_file(const char *name) -{ - char buff[1024]; - FILE *in, *out; - - sprintf(buff, "%s/%s.uu", refdir, name); - in = fopen(buff, "r"); - failure("Couldn't open reference file %s", buff); - assert(in != NULL); - if (in == NULL) - return; - /* Read up to and including the 'begin' line. */ - for (;;) { - if (fgets(buff, sizeof(buff), in) == NULL) { - /* TODO: This is a failure. */ - return; - } - if (memcmp(buff, "begin ", 6) == 0) - break; - } - /* Now, decode the rest and write it. */ - /* Not a lot of error checking here; the input better be right. */ - out = fopen(name, "wb"); - while (fgets(buff, sizeof(buff), in) != NULL) { - char *p = buff; - int bytes; - - if (memcmp(buff, "end", 3) == 0) - break; - - bytes = UUDECODE(*p++); - while (bytes > 0) { - int n = 0; - /* Write out 1-3 bytes from that. */ - if (bytes > 0) { - n = UUDECODE(*p++) << 18; - n |= UUDECODE(*p++) << 12; - fputc(n >> 16, out); - --bytes; - } - if (bytes > 0) { - n |= UUDECODE(*p++) << 6; - fputc((n >> 8) & 0xFF, out); - --bytes; - } - if (bytes > 0) { - n |= UUDECODE(*p++); - fputc(n & 0xFF, out); - --bytes; - } - } - } - fclose(out); - fclose(in); -} - -/* - * - * TEST management - * - */ - -/* - * "list.h" is simply created by "grep DEFINE_TEST test_*.c"; it has - * a line like - * DEFINE_TEST(test_function) - * for each test. - */ - -/* Use "list.h" to declare all of the test functions. */ -#undef DEFINE_TEST -#define DEFINE_TEST(name) void name(void); -#include "list.h" - -/* Use "list.h" to create a list of all tests (functions and names). */ -#undef DEFINE_TEST -#define DEFINE_TEST(n) { n, #n, 0 }, -struct { void (*func)(void); const char *name; int failures; } tests[] = { - #include "list.h" -}; - -/* - * Summarize repeated failures in the just-completed test. - */ -static void -test_summarize(const char *filename, int failed) -{ - unsigned int i; - - switch (verbosity) { - case VERBOSITY_SUMMARY_ONLY: - printf(failed ? "E" : "."); - fflush(stdout); - break; - case VERBOSITY_PASSFAIL: - printf(failed ? "FAIL\n" : "ok\n"); - break; - } - - log_console = (verbosity == VERBOSITY_LIGHT_REPORT); - - for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { - if (failed_lines[i].count > 1 && !failed_lines[i].skip) - logprintf("%s:%d: Summary: Failed %d times\n", - filename, i, failed_lines[i].count); - } - /* Clear the failure history for the next file. */ - memset(failed_lines, 0, sizeof(failed_lines)); -} - -/* - * Actually run a single test, with appropriate setup and cleanup. - */ -static int -test_run(int i, const char *tmpdir) -{ - char logfilename[64]; - int failures_before = failures; - int oldumask; - - switch (verbosity) { - case VERBOSITY_SUMMARY_ONLY: /* No per-test reports at all */ - break; - case VERBOSITY_PASSFAIL: /* rest of line will include ok/FAIL marker */ - printf("%3d: %-50s", i, tests[i].name); - fflush(stdout); - break; - default: /* Title of test, details will follow */ - printf("%3d: %s\n", i, tests[i].name); - } - - /* Chdir to the top-level work directory. */ - if (!assertChdir(tmpdir)) { - fprintf(stderr, - "ERROR: Can't chdir to top work dir %s\n", tmpdir); - exit(1); - } - /* Create a log file for this test. */ - sprintf(logfilename, "%s.log", tests[i].name); - logfile = fopen(logfilename, "w"); - fprintf(logfile, "%s\n\n", tests[i].name); - /* Chdir() to a work dir for this specific test. */ - if (!assertMakeDir(tests[i].name, 0755) - || !assertChdir(tests[i].name)) { - fprintf(stderr, - "ERROR: Can't chdir to work dir %s/%s\n", - tmpdir, tests[i].name); - exit(1); - } - /* Explicitly reset the locale before each test. */ - setlocale(LC_ALL, "C"); - /* Record the umask before we run the test. */ - umask(oldumask = umask(0)); - /* - * Run the actual test. - */ - (*tests[i].func)(); - /* - * Clean up and report afterwards. - */ - /* Restore umask */ - umask(oldumask); - /* Reset locale. */ - setlocale(LC_ALL, "C"); - /* Reset directory. */ - if (!assertChdir(tmpdir)) { - fprintf(stderr, "ERROR: Couldn't chdir to temp dir %s\n", - tmpdir); - exit(1); - } - /* Report per-test summaries. */ - tests[i].failures = failures - failures_before; - test_summarize(test_filename, tests[i].failures); - /* Close the per-test log file. */ - fclose(logfile); - logfile = NULL; - /* If there were no failures, we can remove the work dir and logfile. */ - if (tests[i].failures == 0) { - if (!keep_temp_files && assertChdir(tmpdir)) { -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Make sure not to leave empty directories. - * Sometimes a processing of closing files used by tests - * is not done, then rmdir will be failed and it will - * leave a empty test directory. So we should wait a few - * seconds and retry rmdir. */ - int r, t; - for (t = 0; t < 10; t++) { - if (t > 0) - Sleep(1000); - r = systemf("rmdir /S /Q %s", tests[i].name); - if (r == 0) - break; - } - systemf("del %s", logfilename); -#else - systemf("rm -rf %s", tests[i].name); - systemf("rm %s", logfilename); -#endif - } - } - /* Return appropriate status. */ - return (tests[i].failures); -} - -/* - * - * - * MAIN and support routines. - * - * - */ - -static void -usage(const char *program) -{ - static const int limit = sizeof(tests) / sizeof(tests[0]); - int i; - - printf("Usage: %s [options] ...\n", program); - printf("Default is to run all tests.\n"); - printf("Otherwise, specify the numbers of the tests you wish to run.\n"); - printf("Options:\n"); - printf(" -d Dump core after any failure, for debugging.\n"); - printf(" -k Keep all temp files.\n"); - printf(" Default: temp files for successful tests deleted.\n"); -#ifdef PROGRAM - printf(" -p Path to executable to be tested.\n"); - printf(" Default: path taken from " ENVBASE " environment variable.\n"); -#endif - printf(" -q Quiet.\n"); - printf(" -r Path to dir containing reference files.\n"); - printf(" Default: Current directory.\n"); - printf(" -v Verbose.\n"); - printf("Available tests:\n"); - for (i = 0; i < limit; i++) - printf(" %d: %s\n", i, tests[i].name); - exit(1); -} - -static char * -get_refdir(const char *d) -{ - char tried[512] = { '\0' }; - char buff[128]; - char *pwd, *p; - - /* If a dir was specified, try that */ - if (d != NULL) { - pwd = NULL; - snprintf(buff, sizeof(buff), "%s", d); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - goto failure; - } - - /* Get the current dir. */ - pwd = getcwd(NULL, 0); - while (pwd[strlen(pwd) - 1] == '\n') - pwd[strlen(pwd) - 1] = '\0'; - - /* Look for a known file. */ - snprintf(buff, sizeof(buff), "%s", pwd); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - snprintf(buff, sizeof(buff), "%s/test", pwd); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - -#if defined(LIBRARY) - snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY); -#else - snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM); -#endif - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - if (memcmp(pwd, "/usr/obj", 8) == 0) { - snprintf(buff, sizeof(buff), "%s", pwd + 8); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - snprintf(buff, sizeof(buff), "%s/test", pwd + 8); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - } - -failure: - printf("Unable to locate known reference file %s\n", KNOWNREF); - printf(" Checked following directories:\n%s\n", tried); -#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) - DebugBreak(); -#endif - exit(1); - -success: - free(p); - free(pwd); - return strdup(buff); -} - -int -main(int argc, char **argv) -{ - static const int limit = sizeof(tests) / sizeof(tests[0]); - int i, tests_run = 0, tests_failed = 0, option; - time_t now; - char *refdir_alloc = NULL; - const char *progname; - const char *tmp, *option_arg, *p; - char tmpdir[256]; - char tmpdir_timestamp[256]; - - (void)argc; /* UNUSED */ - -#if defined(HAVE__CrtSetReportMode) - /* To stop to run the default invalid parameter handler. */ - _set_invalid_parameter_handler(invalid_parameter_handler); - /* Disable annoying assertion message box. */ - _CrtSetReportMode(_CRT_ASSERT, 0); -#endif - - /* - * Name of this program, used to build root of our temp directory - * tree. - */ - progname = p = argv[0]; - while (*p != '\0') { - /* Support \ or / dir separators for Windows compat. */ - if (*p == '/' || *p == '\\') - progname = p + 1; - ++p; - } - -#ifdef PROGRAM - /* Get the target program from environment, if available. */ - testprogfile = getenv(ENVBASE); -#endif - - if (getenv("TMPDIR") != NULL) - tmp = getenv("TMPDIR"); - else if (getenv("TMP") != NULL) - tmp = getenv("TMP"); - else if (getenv("TEMP") != NULL) - tmp = getenv("TEMP"); - else if (getenv("TEMPDIR") != NULL) - tmp = getenv("TEMPDIR"); - else - tmp = "/tmp"; - - /* Allow -d to be controlled through the environment. */ - if (getenv(ENVBASE "_DEBUG") != NULL) - dump_on_failure = 1; - - /* Get the directory holding test files from environment. */ - refdir = getenv(ENVBASE "_TEST_FILES"); - - /* - * Parse options, without using getopt(), which isn't available - * on all platforms. - */ - ++argv; /* Skip program name */ - while (*argv != NULL) { - if (**argv != '-') - break; - p = *argv++; - ++p; /* Skip '-' */ - while (*p != '\0') { - option = *p++; - option_arg = NULL; - /* If 'opt' takes an argument, parse that. */ - if (option == 'p' || option == 'r') { - if (*p != '\0') - option_arg = p; - else if (*argv == NULL) { - fprintf(stderr, - "Option -%c requires argument.\n", - option); - usage(progname); - } else - option_arg = *argv++; - p = ""; /* End of this option word. */ - } - - /* Now, handle the option. */ - switch (option) { - case 'd': - dump_on_failure = 1; - break; - case 'k': - keep_temp_files = 1; - break; - case 'p': -#ifdef PROGRAM - testprogfile = option_arg; -#else - usage(progname); -#endif - break; - case 'q': - verbosity--; - break; - case 'r': - refdir = option_arg; - break; - case 'v': - verbosity++; - break; - default: - usage(progname); - } - } - } - - /* - * Sanity-check that our options make sense. - */ -#ifdef PROGRAM - if (testprogfile == NULL) - usage(progname); - { - char *testprg; -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Command.com sometimes rejects '/' separators. */ - testprg = strdup(testprogfile); - for (i = 0; testprg[i] != '\0'; i++) { - if (testprg[i] == '/') - testprg[i] = '\\'; - } - testprogfile = testprg; -#endif - /* Quote the name that gets put into shell command lines. */ - testprg = malloc(strlen(testprogfile) + 3); - strcpy(testprg, "\""); - strcat(testprg, testprogfile); - strcat(testprg, "\""); - testprog = testprg; - } -#endif - - /* - * Create a temp directory for the following tests. - * Include the time the tests started as part of the name, - * to make it easier to track the results of multiple tests. - */ - now = time(NULL); - for (i = 0; ; i++) { - strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), - "%Y-%m-%dT%H.%M.%S", - localtime(&now)); - sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname, - tmpdir_timestamp, i); - if (assertMakeDir(tmpdir,0755)) - break; - if (i >= 999) { - fprintf(stderr, - "ERROR: Unable to create temp directory %s\n", - tmpdir); - exit(1); - } - } - - /* - * If the user didn't specify a directory for locating - * reference files, try to find the reference files in - * the "usual places." - */ - refdir = refdir_alloc = get_refdir(refdir); - - /* - * Banner with basic information. - */ - printf("\n"); - printf("If tests fail or crash, details will be in:\n"); - printf(" %s\n", tmpdir); - printf("\n"); - if (verbosity > VERBOSITY_SUMMARY_ONLY) { - printf("Reference files will be read from: %s\n", refdir); -#ifdef PROGRAM - printf("Running tests on: %s\n", testprog); -#endif - printf("Exercising: "); - fflush(stdout); - printf("%s\n", EXTRA_VERSION); - } else { - printf("Running "); - fflush(stdout); - } - - /* - * Run some or all of the individual tests. - */ - if (*argv == NULL) { - /* Default: Run all tests. */ - for (i = 0; i < limit; i++) { - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - } - } else { - while (*(argv) != NULL) { - if (**argv >= '0' && **argv <= '9') { - i = atoi(*argv); - if (i < 0 || i >= limit) { - printf("*** INVALID Test %s\n", *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ - } - } else { - for (i = 0; i < limit; ++i) { - if (strcmp(*argv, tests[i].name) == 0) - break; - } - if (i >= limit) { - printf("*** INVALID Test ``%s''\n", - *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ - } - } - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - argv++; - } - } - - /* - * Report summary statistics. - */ - if (verbosity > VERBOSITY_SUMMARY_ONLY) { - printf("\n"); - printf("Totals:\n"); - printf(" Tests run: %8d\n", tests_run); - printf(" Tests failed: %8d\n", tests_failed); - printf(" Assertions checked:%8d\n", assertions); - printf(" Assertions failed: %8d\n", failures); - printf(" Skips reported: %8d\n", skips); - } - if (failures) { - printf("\n"); - printf("Failing tests:\n"); - for (i = 0; i < limit; ++i) { - if (tests[i].failures) - printf(" %d: %s (%d failures)\n", i, - tests[i].name, tests[i].failures); - } - printf("\n"); - printf("Details for failing tests: %s\n", tmpdir); - printf("\n"); - } else { - if (verbosity == VERBOSITY_SUMMARY_ONLY) - printf("\n"); - printf("%d tests passed, no failures\n", tests_run); - } - - free(refdir_alloc); - - /* If the final tmpdir is empty, we can remove it. */ - /* This should be the usual case when all tests succeed. */ - assertChdir(".."); - rmdir(tmpdir); - - return (tests_failed ? 1 : 0); -} diff --git a/lib/libarchive/test/read_open_memory.c b/lib/libarchive/test/read_open_memory.c deleted file mode 100644 index db0de85..0000000 --- a/lib/libarchive/test/read_open_memory.c +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -/* - * Read an archive from a block of memory. - * - * This is identical to archive_read_open_memory(), except - * that it goes out of its way to be a little bit unpleasant, - * in order to better test the libarchive internals. - */ - -struct read_memory_data { - unsigned char *buffer; - unsigned char *end; - size_t read_size; - size_t copy_buff_size; - size_t copy_buff_offset; - char *copy_buff; -}; - -static int memory_read_close(struct archive *, void *); -static int memory_read_open(struct archive *, void *); -static off_t memory_read_skip(struct archive *, void *, off_t request); -static ssize_t memory_read(struct archive *, void *, const void **buff); -static int read_open_memory_internal(struct archive *a, void *buff, - size_t size, size_t read_size, int fullapi); - - -int -read_open_memory(struct archive *a, void *buff, size_t size, size_t read_size) -{ - return read_open_memory_internal(a, buff, size, read_size, 1); -} - -/* - * As above, but don't register any optional part of the API, to verify - * that internals work correctly with just the minimal entry points. - */ -int -read_open_memory2(struct archive *a, void *buff, size_t size, size_t read_size) -{ - return read_open_memory_internal(a, buff, size, read_size, 0); -} - -static int -read_open_memory_internal(struct archive *a, void *buff, - size_t size, size_t read_size, int fullapi) -{ - struct read_memory_data *mine; - - mine = (struct read_memory_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - memset(mine, 0, sizeof(*mine)); - mine->buffer = (unsigned char *)buff; - mine->end = mine->buffer + size; - mine->read_size = read_size; - mine->copy_buff_offset = 32; - mine->copy_buff_size = read_size + mine->copy_buff_offset * 2; - mine->copy_buff = malloc(mine->copy_buff_size); - memset(mine->copy_buff, 0xA5, mine->copy_buff_size); - if (fullapi) - return (archive_read_open2(a, mine, memory_read_open, - memory_read, memory_read_skip, memory_read_close)); - else - return (archive_read_open2(a, mine, NULL, - memory_read, NULL, memory_read_close)); -} - -/* - * There's nothing to open. - */ -static int -memory_read_open(struct archive *a, void *client_data) -{ - (void)a; /* UNUSED */ - (void)client_data; /* UNUSED */ - return (ARCHIVE_OK); -} - -/* - * In order to exercise libarchive's internal read-combining logic, - * we deliberately copy data for each read to a separate buffer. - * That way, code that runs off the end of the provided data - * will screw up. - */ -static ssize_t -memory_read(struct archive *a, void *client_data, const void **buff) -{ - struct read_memory_data *mine = (struct read_memory_data *)client_data; - size_t size; - - (void)a; /* UNUSED */ - size = mine->end - mine->buffer; - if (size > mine->read_size) - size = mine->read_size; - else - memset(mine->copy_buff, 0xA5, mine->copy_buff_size); - memcpy(mine->copy_buff + mine->copy_buff_offset, mine->buffer, size); - *buff = mine->copy_buff + mine->copy_buff_offset; - - mine->buffer += size; - return ((ssize_t)size); -} - -/* - * How mean can a skip() routine be? Let's try to find out. - */ -static off_t -memory_read_skip(struct archive *a, void *client_data, off_t skip) -{ - struct read_memory_data *mine = (struct read_memory_data *)client_data; - - (void)a; /* UNUSED */ - /* We can't skip by more than is available. */ - if ((off_t)skip > (off_t)(mine->end - mine->buffer)) - skip = mine->end - mine->buffer; - /* Always do small skips by prime amounts. */ - if (skip > 71) - skip = 71; - mine->buffer += skip; - return (skip); -} - -/* - * Close is just cleaning up our one small bit of data. - */ -static int -memory_read_close(struct archive *a, void *client_data) -{ - struct read_memory_data *mine = (struct read_memory_data *)client_data; - (void)a; /* UNUSED */ - free(mine->copy_buff); - free(mine); - return (ARCHIVE_OK); -} diff --git a/lib/libarchive/test/test.h b/lib/libarchive/test/test.h deleted file mode 100644 index 725c899..0000000 --- a/lib/libarchive/test/test.h +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (c) 2003-2006 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* Every test program should #include "test.h" as the first thing. */ - -/* - * The goal of this file (and the matching test.c) is to - * simplify the very repetitive test-*.c test programs. - */ -#if defined(HAVE_CONFIG_H) -/* Most POSIX platforms use the 'configure' script to build config.h */ -#include "config.h" -#elif defined(__FreeBSD__) -/* Building as part of FreeBSD system requires a pre-built config.h. */ -#include "config_freebsd.h" -#elif defined(_WIN32) && !defined(__CYGWIN__) -/* Win32 can't run the 'configure' script. */ -#include "config_windows.h" -#else -/* Warn if the library hasn't been (automatically or manually) configured. */ -#error Oops: No config.h and no pre-built configuration in test.h. -#endif - -#include /* Windows requires this before sys/stat.h */ -#include - -#if HAVE_DIRENT_H -#include -#endif -#ifdef HAVE_DIRECT_H -#include -#define dirent direct -#endif -#include -#include -#ifdef HAVE_IO_H -#include -#endif -#ifdef HAVE_STDINT_H -#include -#endif -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#ifdef HAVE_WINDOWS_H -#include -#endif - -/* - * System-specific tweaks. We really want to minimize these - * as much as possible, since they make it harder to understand - * the mainline code. - */ - -/* Windows (including Visual Studio and MinGW but not Cygwin) */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#if !defined(__BORLANDC__) -#define strdup _strdup -#endif -#define LOCALE_UTF8 NULL -#else -#define LOCALE_UTF8 "de_DE.UTF-8" -#endif - -/* Visual Studio */ -#ifdef _MSC_VER -#define snprintf sprintf_s -#endif - -#if defined(__BORLANDC__) -#pragma warn -8068 /* Constant out of range in comparison. */ -#endif - -/* Cygwin */ -#if defined(__CYGWIN__) -/* Cygwin-1.7.x is lazy about populating nlinks, so don't - * expect it to be accurate. */ -# define NLINKS_INACCURATE_FOR_DIRS -#endif - -/* Haiku OS */ -#if defined(__HAIKU__) -/* Haiku has typedefs in stdint.h (needed for int64_t) */ -#include -#endif - -/* Get a real definition for __FBSDID if we can */ -#if HAVE_SYS_CDEFS_H -#include -#endif - -/* If not, define it so as to avoid dangling semicolons. */ -#ifndef __FBSDID -#define __FBSDID(a) struct _undefined_hack -#endif - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -/* - * Redefine DEFINE_TEST for use in defining the test functions. - */ -#undef DEFINE_TEST -#define DEFINE_TEST(name) void name(void); void name(void) - -/* An implementation of the standard assert() macro */ -#define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL) -/* chdir() and error if it fails */ -#define assertChdir(path) \ - assertion_chdir(__FILE__, __LINE__, path) -/* Assert two integers are the same. Reports value of each one if not. */ -#define assertEqualInt(v1,v2) \ - assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* Assert two strings are the same. Reports value of each one if not. */ -#define assertEqualString(v1,v2) \ - assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* As above, but v1 and v2 are wchar_t * */ -#define assertEqualWString(v1,v2) \ - assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* As above, but raw blocks of bytes. */ -#define assertEqualMem(v1, v2, l) \ - assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL) -/* Assert two files are the same; allow printf-style expansion of second name. - * See below for comments about variable arguments here... - */ -#define assertEqualFile \ - assertion_setup(__FILE__, __LINE__);assertion_equal_file -/* Assert that a file is empty; supports printf-style arguments. */ -#define assertEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_empty_file -/* Assert that a file is not empty; supports printf-style arguments. */ -#define assertNonEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_non_empty_file -#define assertFileAtime(pathname, sec, nsec) \ - assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileAtimeRecent(pathname) \ - assertion_file_atime_recent(__FILE__, __LINE__, pathname) -#define assertFileBirthtime(pathname, sec, nsec) \ - assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileBirthtimeRecent(pathname) \ - assertion_file_birthtime_recent(__FILE__, __LINE__, pathname) -/* Assert that a file exists; supports printf-style arguments. */ -#define assertFileExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_exists -/* Assert that a file exists; supports printf-style arguments. */ -#define assertFileNotExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_not_exists -/* Assert that file contents match a string; supports printf-style arguments. */ -#define assertFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_file_contents -#define assertFileMtime(pathname, sec, nsec) \ - assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileMtimeRecent(pathname) \ - assertion_file_mtime_recent(__FILE__, __LINE__, pathname) -#define assertFileNLinks(pathname, nlinks) \ - assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks) -#define assertFileSize(pathname, size) \ - assertion_file_size(__FILE__, __LINE__, pathname, size) -#define assertTextFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_text_file_contents -#define assertIsDir(pathname, mode) \ - assertion_is_dir(__FILE__, __LINE__, pathname, mode) -#define assertIsHardlink(path1, path2) \ - assertion_is_hardlink(__FILE__, __LINE__, path1, path2) -#define assertIsNotHardlink(path1, path2) \ - assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2) -#define assertIsReg(pathname, mode) \ - assertion_is_reg(__FILE__, __LINE__, pathname, mode) -#define assertIsSymlink(pathname, contents) \ - assertion_is_symlink(__FILE__, __LINE__, pathname, contents) -/* Create a directory, report error if it fails. */ -#define assertMakeDir(dirname, mode) \ - assertion_make_dir(__FILE__, __LINE__, dirname, mode) -#define assertMakeFile(path, mode, contents) \ - assertion_make_file(__FILE__, __LINE__, path, mode, contents) -#define assertMakeHardlink(newfile, oldfile) \ - assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile) -#define assertMakeSymlink(newfile, linkto) \ - assertion_make_symlink(__FILE__, __LINE__, newfile, linkto) -#define assertUmask(mask) \ - assertion_umask(__FILE__, __LINE__, mask) - -/* - * This would be simple with C99 variadic macros, but I don't want to - * require that. Instead, I insert a function call before each - * skipping() call to pass the file and line information down. Crude, - * but effective. - */ -#define skipping \ - assertion_setup(__FILE__, __LINE__);test_skipping - -/* Function declarations. These are defined in test_utility.c. */ -void failure(const char *fmt, ...); -int assertion_assert(const char *, int, int, const char *, void *); -int assertion_chdir(const char *, int, const char *); -int assertion_empty_file(const char *, ...); -int assertion_equal_file(const char *, const char *, ...); -int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *); -int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *); -int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *); -int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); -int assertion_file_atime(const char *, int, const char *, long, long); -int assertion_file_atime_recent(const char *, int, const char *); -int assertion_file_birthtime(const char *, int, const char *, long, long); -int assertion_file_birthtime_recent(const char *, int, const char *); -int assertion_file_contents(const void *, int, const char *, ...); -int assertion_file_exists(const char *, ...); -int assertion_file_mtime(const char *, int, const char *, long, long); -int assertion_file_mtime_recent(const char *, int, const char *); -int assertion_file_nlinks(const char *, int, const char *, int); -int assertion_file_not_exists(const char *, ...); -int assertion_file_size(const char *, int, const char *, long); -int assertion_is_dir(const char *, int, const char *, int); -int assertion_is_hardlink(const char *, int, const char *, const char *); -int assertion_is_not_hardlink(const char *, int, const char *, const char *); -int assertion_is_reg(const char *, int, const char *, int); -int assertion_is_symlink(const char *, int, const char *, const char *); -int assertion_make_dir(const char *, int, const char *, int); -int assertion_make_file(const char *, int, const char *, int, const char *); -int assertion_make_hardlink(const char *, int, const char *newpath, const char *); -int assertion_make_symlink(const char *, int, const char *newpath, const char *); -int assertion_non_empty_file(const char *, ...); -int assertion_text_file_contents(const char *buff, const char *f); -int assertion_umask(const char *, int, int); -void assertion_setup(const char *, int); - -void test_skipping(const char *fmt, ...); - -/* Like sprintf, then system() */ -int systemf(const char * fmt, ...); - -/* Delay until time() returns a value after this. */ -void sleepUntilAfter(time_t); - -/* Return true if this platform can create symlinks. */ -int canSymlink(void); - -/* Return true if this platform can run the "gzip" program. */ -int canGzip(void); - -/* Return true if this platform can run the "gunzip" program. */ -int canGunzip(void); - -/* Suck file into string allocated via malloc(). Call free() when done. */ -/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ -char *slurpfile(size_t *, const char *fmt, ...); - -/* Extracts named reference file to the current directory. */ -void extract_reference_file(const char *); - -/* - * Special interfaces for libarchive test harness. - */ - -#include "archive.h" -#include "archive_entry.h" - -/* Special customized read-from-memory interface. */ -int read_open_memory(struct archive *, void *, size_t, size_t); -/* "2" version exercises a slightly different set of libarchive APIs. */ -int read_open_memory2(struct archive *, void *, size_t, size_t); - -/* Versions of above that accept an archive argument for additional info. */ -#define assertA(e) assertion_assert(__FILE__, __LINE__, (e), #e, (a)) -#define assertEqualIntA(a,v1,v2) \ - assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a)) -#define assertEqualStringA(a,v1,v2) \ - assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a)) - -#ifdef USE_DMALLOC -#include -#endif diff --git a/lib/libarchive/test/test_acl_basic.c b/lib/libarchive/test/test_acl_basic.c deleted file mode 100644 index 8fbd3a0..0000000 --- a/lib/libarchive/test/test_acl_basic.c +++ /dev/null @@ -1,229 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Exercise the system-independent portion of the ACL support. - * Check that archive_entry objects can save and restore ACL data. - * - * This should work on all systems, regardless of whether local - * filesystems support ACLs or not. - */ - -struct acl_t { - int type; /* Type of ACL: "access" or "default" */ - int permset; /* Permissions for this class of users. */ - int tag; /* Owner, User, Owning group, group, other, etc. */ - int qual; /* GID or UID of user/group, depending on tag. */ - const char *name; /* Name of user/group, depending on tag. */ -}; - -static struct acl_t acls0[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_USER_OBJ, 0, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, - ARCHIVE_ENTRY_ACL_OTHER, 0, "" }, -}; - -static struct acl_t acls1[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, -}; - -static struct acl_t acls2[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, - ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, - ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, -}; - -static void -set_acls(struct archive_entry *ae, struct acl_t *acls, int n) -{ - int i; - - archive_entry_acl_clear(ae); - for (i = 0; i < n; i++) { - archive_entry_acl_add_entry(ae, - acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, - acls[i].name); - } -} - -static int -acl_match(struct acl_t *acl, int type, int permset, int tag, int qual, const char *name) -{ - if (type != acl->type) - return (0); - if (permset != acl->permset) - return (0); - if (tag != acl->tag) - return (0); - if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) - return (1); - if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) - return (1); - if (tag == ARCHIVE_ENTRY_ACL_OTHER) - return (1); - if (qual != acl->qual) - return (0); - if (name == NULL) { - if (acl->name == NULL || acl->name[0] == '\0') - return (1); - } - if (acl->name == NULL) { - if (name[0] == '\0') - return (1); - } - return (0 == strcmp(name, acl->name)); -} - -static void -compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode) -{ - int *marker = malloc(sizeof(marker[0]) * n); - int i; - int r; - int type, permset, tag, qual; - int matched; - const char *name; - - for (i = 0; i < n; i++) - marker[i] = i; - - while (0 == (r = archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name))) { - for (i = 0, matched = 0; i < n && !matched; i++) { - if (acl_match(&acls[marker[i]], type, permset, - tag, qual, name)) { - /* We found a match; remove it. */ - marker[i] = marker[n - 1]; - n--; - matched = 1; - } - } - if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) { - if (!matched) printf("No match for user_obj perm\n"); - failure("USER_OBJ permset (%02o) != user mode (%02o)", - permset, 07 & (mode >> 6)); - assert((permset << 6) == (mode & 0700)); - } else if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) { - if (!matched) printf("No match for group_obj perm\n"); - failure("GROUP_OBJ permset %02o != group mode %02o", - permset, 07 & (mode >> 3)); - assert((permset << 3) == (mode & 0070)); - } else if (tag == ARCHIVE_ENTRY_ACL_OTHER) { - if (!matched) printf("No match for other perm\n"); - failure("OTHER permset (%02o) != other mode (%02o)", - permset, mode & 07); - assert((permset << 0) == (mode & 0007)); - } else { - failure("Could not find match for ACL " - "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", - type, permset, tag, qual, name); - assert(matched == 1); - } - } -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* Known broken before 1.9.0. */ - skipping("archive_entry_acl_next() exits with ARCHIVE_EOF"); -#else - assertEqualInt(ARCHIVE_EOF, r); -#endif - assert((mode & 0777) == (archive_entry_mode(ae) & 0777)); - failure("Could not find match for ACL " - "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", - acls[marker[0]].type, acls[marker[0]].permset, - acls[marker[0]].tag, acls[marker[0]].qual, acls[marker[0]].name); - assert(n == 0); /* Number of ACLs not matched should == 0 */ - free(marker); -} - -DEFINE_TEST(test_acl_basic) -{ - struct archive_entry *ae; - - /* Create a simple archive_entry. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0777); - - /* Basic owner/owning group should just update mode bits. */ - set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); - failure("Basic ACLs shouldn't be stored as extended ACLs"); - assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - - /* With any extended ACL entry, we should read back a full set. */ - set_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0])); - failure("One extended ACL should flag all ACLs to be returned."); - assert(4 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - compare_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0]), 0142); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - - /* A more extensive set of ACLs. */ - set_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0])); - assertEqualInt(6, archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - compare_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0]), 0543); - failure("Basic ACLs should set mode to 0543, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0543); - - /* - * Check that clearing ACLs gets rid of them all by repeating - * the first test. - */ - set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); - failure("Basic ACLs shouldn't be stored as extended ACLs"); - assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - archive_entry_free(ae); -} diff --git a/lib/libarchive/test/test_acl_freebsd.c b/lib/libarchive/test/test_acl_freebsd.c deleted file mode 100644 index fbb744d..0000000 --- a/lib/libarchive/test/test_acl_freebsd.c +++ /dev/null @@ -1,260 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#if defined(__FreeBSD__) && __FreeBSD__ > 4 -#include - -struct myacl_t { - int type; /* Type of ACL: "access" or "default" */ - int permset; /* Permissions for this class of users. */ - int tag; /* Owner, User, Owning group, group, other, etc. */ - int qual; /* GID or UID of user/group, depending on tag. */ - const char *name; /* Name of user/group, depending on tag. */ -}; - -static struct myacl_t acls2[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, - ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, - ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_READ | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_MASK, -1, "" }, - { 0, 0, 0, 0, NULL } -}; - -static void -set_acls(struct archive_entry *ae, struct myacl_t *acls) -{ - int i; - - archive_entry_acl_clear(ae); - for (i = 0; acls[i].name != NULL; i++) { - archive_entry_acl_add_entry(ae, - acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, - acls[i].name); - } -} - -static int -acl_match(acl_entry_t aclent, struct myacl_t *myacl) -{ - gid_t g, *gp; - uid_t u, *up; - acl_tag_t tag_type; - acl_permset_t opaque_ps; - int permset = 0; - - acl_get_tag_type(aclent, &tag_type); - - /* translate the silly opaque permset to a bitmap */ - acl_get_permset(aclent, &opaque_ps); - if (acl_get_perm_np(opaque_ps, ACL_EXECUTE)) - permset |= ARCHIVE_ENTRY_ACL_EXECUTE; - if (acl_get_perm_np(opaque_ps, ACL_WRITE)) - permset |= ARCHIVE_ENTRY_ACL_WRITE; - if (acl_get_perm_np(opaque_ps, ACL_READ)) - permset |= ARCHIVE_ENTRY_ACL_READ; - - if (permset != myacl->permset) - return (0); - - switch (tag_type) { - case ACL_USER_OBJ: - if (myacl->tag != ARCHIVE_ENTRY_ACL_USER_OBJ) return (0); - break; - case ACL_USER: - if (myacl->tag != ARCHIVE_ENTRY_ACL_USER) - return (0); - up = acl_get_qualifier(aclent); - u = *up; - acl_free(up); - if ((uid_t)myacl->qual != u) - return (0); - break; - case ACL_GROUP_OBJ: - if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP_OBJ) return (0); - break; - case ACL_GROUP: - if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP) - return (0); - gp = acl_get_qualifier(aclent); - g = *gp; - acl_free(gp); - if ((gid_t)myacl->qual != g) - return (0); - break; - case ACL_MASK: - if (myacl->tag != ARCHIVE_ENTRY_ACL_MASK) return (0); - break; - case ACL_OTHER: - if (myacl->tag != ARCHIVE_ENTRY_ACL_OTHER) return (0); - break; - } - return (1); -} - -static void -compare_acls(acl_t acl, struct myacl_t *myacls) -{ - int *marker; - int entry_id = ACL_FIRST_ENTRY; - int matched; - int i, n; - acl_entry_t acl_entry; - - /* Count ACL entries in myacls array and allocate an indirect array. */ - for (n = 0; myacls[n].name != NULL; ++n) - continue; - marker = malloc(sizeof(marker[0]) * n); - for (i = 0; i < n; i++) - marker[i] = i; - - /* - * Iterate over acls in system acl object, try to match each - * one with an item in the myacls array. - */ - while (1 == acl_get_entry(acl, entry_id, &acl_entry)) { - /* After the first time... */ - entry_id = ACL_NEXT_ENTRY; - - /* Search for a matching entry (tag and qualifier) */ - for (i = 0, matched = 0; i < n && !matched; i++) { - if (acl_match(acl_entry, &myacls[marker[i]])) { - /* We found a match; remove it. */ - marker[i] = marker[n - 1]; - n--; - matched = 1; - } - } - - /* TODO: Print out more details in this case. */ - failure("ACL entry on file that shouldn't be there"); - assert(matched == 1); - } - - /* Dump entries in the myacls array that weren't in the system acl. */ - for (i = 0; i < n; ++i) { - failure(" ACL entry missing from file: " - "type=%d,permset=%d,tag=%d,qual=%d,name=``%s''\n", - myacls[marker[i]].type, myacls[marker[i]].permset, - myacls[marker[i]].tag, myacls[marker[i]].qual, - myacls[marker[i]].name); - assert(0); /* Record this as a failure. */ - } - free(marker); -} - -#endif - - -/* - * Verify ACL restore-to-disk. This test is FreeBSD-specific. - */ - -DEFINE_TEST(test_acl_freebsd) -{ -#if !defined(__FreeBSD__) - skipping("FreeBSD-specific ACL restore test"); -#elif __FreeBSD__ < 5 - skipping("ACL restore supported only on FreeBSD 5.0 and later"); -#else - struct stat st; - struct archive *a; - struct archive_entry *ae; - int n, fd; - acl_t acl; - - /* - * First, do a quick manual set/read of ACL data to - * verify that the local filesystem does support ACLs. - * If it doesn't, we'll simply skip the remaining tests. - */ - acl = acl_from_text("u::rwx,u:1:rw,g::rwx,g:15:rx,o::rwx,m::rwx"); - assert((void *)acl != NULL); - /* Create a test file and try to set an ACL on it. */ - fd = open("pretest", O_WRONLY | O_CREAT | O_EXCL, 0777); - failure("Could not create test file?!"); - if (!assert(fd >= 0)) { - acl_free(acl); - return; - } - - n = acl_set_fd(fd, acl); - acl_free(acl); - if (n != 0 && errno == EOPNOTSUPP) { - close(fd); - skipping("ACL tests require that ACL support be enabled on the filesystem"); - return; - } - if (n != 0 && errno == EINVAL) { - close(fd); - skipping("POSIX.1e ACL tests require that POSIX.1e ACL support be enabled on the filesystem"); - return; - } - failure("acl_set_fd(): errno = %d (%s)", - errno, strerror(errno)); - assertEqualInt(0, n); - close(fd); - - /* Create a write-to-disk object. */ - assert(NULL != (a = archive_write_disk_new())); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL); - - /* Populate an archive entry with some metadata, including ACL info */ - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_pathname(ae, "test0"); - archive_entry_set_mtime(ae, 123456, 7890); - archive_entry_set_size(ae, 0); - set_acls(ae, acls2); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* Verify the data on disk. */ - assertEqualInt(0, stat("test0", &st)); - assertEqualInt(st.st_mtime, 123456); - acl = acl_get_file("test0", ACL_TYPE_ACCESS); - assert(acl != (acl_t)NULL); - compare_acls(acl, acls2); - acl_free(acl); -#endif -} diff --git a/lib/libarchive/test/test_acl_pax.c b/lib/libarchive/test/test_acl_pax.c deleted file mode 100644 index f6b065d..0000000 --- a/lib/libarchive/test/test_acl_pax.c +++ /dev/null @@ -1,517 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Exercise the system-independent portion of the ACL support. - * Check that pax archive can save and restore ACL data. - * - * This should work on all systems, regardless of whether local - * filesystems support ACLs or not. - */ - -static unsigned char buff[16384]; - -static unsigned char reference[] = { -'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ',0,'0','0', -'0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','6','2',' ','0', -'0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','6','7',0,' ', -'x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r', -0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=','0',10, -'1','6',' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1','8',' ', -'S','C','H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ',0,'0','0', -'0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','0', -'0','0','0','0','0','0','0','0','0','0',' ','0','1','0','0','0','6',0,' ', -'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r', -0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ', -0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','1','7','2', -' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','7','1', -0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', -'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', -'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,'7','2',' ','S','C','H','I','L','Y','.','a','c','l','.', -'a','c','c','e','s','s','=','u','s','e','r',':',':','-','-','x',',','g','r', -'o','u','p',':',':','r','-','-',',','o','t','h','e','r',':',':','-','w','-', -',','u','s','e','r',':','u','s','e','r','7','7',':','r','-','-',':','7','7', -10,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=','0',10,'1','6', -' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1','8',' ','S','C', -'H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ',0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','0','0', -'0','0','0','0','0','0','0','0','0',' ','0','1','0','0','0','6',0,' ','0', -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0, -'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,'0','0','0','5','4','3',' ',0,'0','0','0','0','0','0',' ', -0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','2','4','3', -' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','7','5', -0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', -'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', -'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,'1','1','3',' ','S','C','H','I','L','Y','.','a','c','l', -'.','a','c','c','e','s','s','=','u','s','e','r',':',':','r','-','x',',','g', -'r','o','u','p',':',':','r','-','-',',','o','t','h','e','r',':',':','-','w', -'x',',','u','s','e','r',':','u','s','e','r','7','7',':','r','-','-',':','7', -'7',',','u','s','e','r',':','u','s','e','r','7','8',':','-','-','-',':','7', -'8',',','g','r','o','u','p',':','g','r','o','u','p','7','8',':','r','w','x', -':','7','8',10,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=','0', -10,'1','6',' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1','8', -' ','S','C','H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,'0','0','0','5','4','3',' ',0,'0','0','0','0','0','0',' ',0,'0','0', -'0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','0', -'0','0','0','0','0','0','0','0','0','0',' ','0','1','0','0','1','3',0,' ', -'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r', -0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ', -0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','6','2', -' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','6','7', -0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', -'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', -'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=', -'0',10,'1','6',' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1', -'8',' ','S','C','H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ', -0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0', -' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','0','0','0','6', -0,' ','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', -'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', -'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - - -struct acl_t { - int type; /* Type of ACL: "access" or "default" */ - int permset; /* Permissions for this class of users. */ - int tag; /* Owner, User, Owning group, group, other, etc. */ - int qual; /* GID or UID of user/group, depending on tag. */ - const char *name; /* Name of user/group, depending on tag. */ -}; - -static struct acl_t acls0[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_USER_OBJ, 0, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, - ARCHIVE_ENTRY_ACL_OTHER, 0, "" }, -}; - -static struct acl_t acls1[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, -}; - -static struct acl_t acls2[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, - ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, - ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, -}; - -static void -set_acls(struct archive_entry *ae, struct acl_t *acls, int n) -{ - int i; - - archive_entry_acl_clear(ae); - for (i = 0; i < n; i++) { - archive_entry_acl_add_entry(ae, - acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, - acls[i].name); - } -} - -static int -acl_match(struct acl_t *acl, int type, int permset, int tag, int qual, const char *name) -{ - if (type != acl->type) - return (0); - if (permset != acl->permset) - return (0); - if (tag != acl->tag) - return (0); - if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) - return (1); - if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) - return (1); - if (tag == ARCHIVE_ENTRY_ACL_OTHER) - return (1); - if (qual != acl->qual) - return (0); - if (name == NULL) - return (acl->name == NULL || acl->name[0] == '\0'); - if (acl->name == NULL) - return (name == NULL || name[0] == '\0'); - return (0 == strcmp(name, acl->name)); -} - -static void -compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode) -{ - int *marker = malloc(sizeof(marker[0]) * n); - int i; - int r; - int type, permset, tag, qual; - int matched; - const char *name; - - for (i = 0; i < n; i++) - marker[i] = i; - - while (0 == (r = archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name))) { - for (i = 0, matched = 0; i < n && !matched; i++) { - if (acl_match(&acls[marker[i]], type, permset, - tag, qual, name)) { - /* We found a match; remove it. */ - marker[i] = marker[n - 1]; - n--; - matched = 1; - } - } - if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) { - if (!matched) printf("No match for user_obj perm\n"); - failure("USER_OBJ permset (%02o) != user mode (%02o)", - permset, 07 & (mode >> 6)); - assert((permset << 6) == (mode & 0700)); - } else if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) { - if (!matched) printf("No match for group_obj perm\n"); - failure("GROUP_OBJ permset %02o != group mode %02o", - permset, 07 & (mode >> 3)); - assert((permset << 3) == (mode & 0070)); - } else if (tag == ARCHIVE_ENTRY_ACL_OTHER) { - if (!matched) printf("No match for other perm\n"); - failure("OTHER permset (%02o) != other mode (%02o)", - permset, mode & 07); - assert((permset << 0) == (mode & 0007)); - } else { - failure("Could not find match for ACL " - "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", - type, permset, tag, qual, name); - assert(matched == 1); - } - } -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* Known broken before 1.9.0. */ - skipping("archive_entry_acl_next() exits with ARCHIVE_EOF"); -#else - assertEqualInt(ARCHIVE_EOF, r); -#endif - assert((mode & 0777) == (archive_entry_mode(ae) & 0777)); - failure("Could not find match for ACL " - "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", - acls[marker[0]].type, acls[marker[0]].permset, - acls[marker[0]].tag, acls[marker[0]].qual, acls[marker[0]].name); - assert(n == 0); /* Number of ACLs not matched should == 0 */ - free(marker); -} - -DEFINE_TEST(test_acl_pax) -{ - struct archive *a; - struct archive_entry *ae; - size_t used; - FILE *f; - - /* Write an archive to memory. */ - assert(NULL != (a = archive_write_new())); - assertA(0 == archive_write_set_format_pax(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Write a series of files to the archive with different ACL info. */ - - /* Create a simple archive_entry. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0777); - - /* Basic owner/owning group should just update mode bits. */ - set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); - assertA(0 == archive_write_header(a, ae)); - - /* With any extended ACL entry, we should read back a full set. */ - set_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0])); - assertA(0 == archive_write_header(a, ae)); - - - /* A more extensive set of ACLs. */ - set_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0])); - assertA(0 == archive_write_header(a, ae)); - - /* - * Check that clearing ACLs gets rid of them all by repeating - * the first test. - */ - set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* Write out the data we generated to a file for manual inspection. */ - assert(NULL != (f = fopen("testout", "wb"))); - assertEqualInt(used, (size_t)fwrite(buff, 1, (unsigned int)used, f)); - fclose(f); - - /* Write out the reference data to a file for manual inspection. */ - assert(NULL != (f = fopen("reference", "wb"))); - assert(sizeof(reference) == fwrite(reference, 1, sizeof(reference), f)); - fclose(f); - - /* Assert that the generated data matches the built-in reference data.*/ - failure("Generated pax archive does not match reference; check 'testout' and 'reference' files."); - assertEqualMem(buff, reference, sizeof(reference)); - failure("Generated pax archive does not match reference; check 'testout' and 'reference' files."); - assertEqualInt((int)used, sizeof(reference)); - - /* Read back each entry and check that the ACL data is right. */ - assert(NULL != (a = archive_read_new())); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - /* First item has no ACLs */ - assertA(0 == archive_read_next_header(a, &ae)); - failure("Basic ACLs shouldn't be stored as extended ACLs"); - assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - /* Second item has a few ACLs */ - assertA(0 == archive_read_next_header(a, &ae)); - failure("One extended ACL should flag all ACLs to be returned."); - assert(4 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - compare_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0]), 0142); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - /* Third item has pretty extensive ACLs */ - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualInt(6, archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - compare_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0]), 0543); - failure("Basic ACLs should set mode to 0543, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0543); - - /* Fourth item has no ACLs */ - assertA(0 == archive_read_next_header(a, &ae)); - failure("Basic ACLs shouldn't be stored as extended ACLs"); - assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - /* Close the archive. */ - assertA(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertA(0 == archive_read_finish(a)); -#endif -} diff --git a/lib/libarchive/test/test_archive_api_feature.c b/lib/libarchive/test/test_archive_api_feature.c deleted file mode 100644 index 3324aad..0000000 --- a/lib/libarchive/test/test_archive_api_feature.c +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_archive_api_feature) -{ - char buff[128]; - const char *p; - - /* This is the (hopefully) final versioning API. */ - assertEqualInt(ARCHIVE_VERSION_NUMBER, archive_version_number()); - sprintf(buff, "libarchive %d.%d.%d", - archive_version_number() / 1000000, - (archive_version_number() / 1000) % 1000, - archive_version_number() % 1000); - failure("Version string is: %s, computed is: %s", - archive_version_string(), buff); - assert(memcmp(buff, archive_version_string(), strlen(buff)) == 0); - if (strlen(buff) < strlen(archive_version_string())) { - p = archive_version_string() + strlen(buff); - failure("Version string is: %s", archive_version_string()); - assert(*p == 'a' || *p == 'b' || *p == 'c' || *p == 'd'); - ++p; - failure("Version string is: %s", archive_version_string()); - assert(*p == '\0'); - } - -/* This is all scheduled to disappear in libarchive 3.0 */ -#if ARCHIVE_VERSION_NUMBER < 3000000 - assertEqualInt(ARCHIVE_VERSION_STAMP, ARCHIVE_VERSION_NUMBER); - assertEqualInt(ARCHIVE_API_FEATURE, archive_api_feature()); - assertEqualInt(ARCHIVE_API_VERSION, archive_api_version()); - /* - * Even though ARCHIVE_VERSION_STAMP only appears in - * archive.h after 1.9.0 and 2.2.3, the macro is synthesized - * in test.h, so this test is always valid. - */ - assertEqualInt(ARCHIVE_VERSION_STAMP / 1000, ARCHIVE_API_VERSION * 1000 + ARCHIVE_API_FEATURE); - /* - * The function, however, isn't always available. It appeared - * sometime in the middle of 2.2.3, but the synthesized value - * never has a release version, so the following conditional - * exactly determines whether the current library has the - * function. - */ -#if ARCHIVE_VERSION_STAMP / 1000 == 1009 || ARCHIVE_VERSION_STAMP > 2002000 - assertEqualInt(ARCHIVE_VERSION_STAMP, archive_version_stamp()); -#else - skipping("archive_version_stamp()"); -#endif - assertEqualString(ARCHIVE_LIBRARY_VERSION, archive_version()); -#endif -} diff --git a/lib/libarchive/test/test_bad_fd.c b/lib/libarchive/test/test_bad_fd.c deleted file mode 100644 index a0f9ae1..0000000 --- a/lib/libarchive/test/test_bad_fd.c +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* Verify that attempting to open an invalid fd returns correct error. */ -DEFINE_TEST(test_bad_fd) -{ - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(ARCHIVE_FATAL == archive_read_open_fd(a, -1, 1024)); - assertA(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertA(0 == archive_read_finish(a)); -#endif -} diff --git a/lib/libarchive/test/test_compat_bzip2.c b/lib/libarchive/test/test_compat_bzip2.c deleted file mode 100644 index 96eacad..0000000 --- a/lib/libarchive/test/test_compat_bzip2.c +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Verify our ability to read sample files compatibly with bunzip2. - * - * In particular: - * * bunzip2 will read multiple bzip2 streams, concatenating the output - * * bunzip2 will stop at the end of a stream if the following data - * doesn't start with a bzip2 signature. - */ - -/* - * All of the sample files have the same contents; they're just - * compressed in different ways. - */ -static void -compat_bzip2(const char *name) -{ - const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; - struct archive_entry *ae; - struct archive *a; - int i; - - assert((a = archive_read_new()) != NULL); - if (ARCHIVE_OK != archive_read_support_compression_bzip2(a)) { - skipping("Unsupported bzip2"); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); - - /* Read entries, match up names with list above. */ - for (i = 0; i < 6; ++i) { - failure("Could not read file %d (%s) from %s", i, n[i], name); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString(n[i], archive_entry_pathname(ae)); - } - - /* Verify the end-of-archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualString(archive_compression_name(a), "bzip2"); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - -DEFINE_TEST(test_compat_bzip2) -{ - compat_bzip2("test_compat_bzip2_1.tbz"); - compat_bzip2("test_compat_bzip2_2.tbz"); -} - - diff --git a/lib/libarchive/test/test_compat_bzip2_1.tbz.uu b/lib/libarchive/test/test_compat_bzip2_1.tbz.uu deleted file mode 100644 index 8c94414..0000000 --- a/lib/libarchive/test/test_compat_bzip2_1.tbz.uu +++ /dev/null @@ -1,24 +0,0 @@ -$FreeBSD$ - -begin 644 test_compat_bzip2_1.tbz -M0EIH.3%!62936;12^)(``#-;D=$00`!_@``!8RT>$`0`$```""``5#5/*'J> -MD#(&30_5!H4_5-ZH`T``327U4@&L('"(9-%8<7&$I,`:7FXH+*\GV#JF<`PK29-8'OPDG36S\7HR&C(T:/U0:$U'I -MJ!ZC0`#VECO\[$10H'-Z@F*:6A1$H$V("2G0Q(U0(8=(7AK$S04#!)RXOAP% -MP:D%#Q;NO)\4UL23'2[\7````6YC1 -M$$`$?X```6,M'A`$`!````@@`'4-4S*,U!HT!HT?J@T)E-I--!H`![60EIH.3%!629364RNM^,```#?L-$00`#_@`0```AG -M+1X0`!`$```((`!U#5-,:1IH`TT,1^J#)&H]3U`T``!CX[_.[`F40.64EC"D -M()+?KX6,VP?6Y;F%5$XR[Y/D#*9),K3^+N2*<*$@9@ -MX6(`0EIH.3%!62936>ZM4*4```);D-$00`#O@``(9ST>$`0```@@`'0:IFC2 -M&F@!B:/U0:$R&H:&@`"KS^U=Y`BC`#FY2*9-8%%&13E$@%8ZF(&J!##]!#E` -MKVL'2LUW2.*C08`$)::#DQ05DF -?4UDI/)=P````0!!```0`(``A`(*#%W)%.%"0*3R7<``` -` -end diff --git a/lib/libarchive/test/test_compat_bzip2_2.tbz.uu b/lib/libarchive/test/test_compat_bzip2_2.tbz.uu deleted file mode 100644 index 286b367..0000000 --- a/lib/libarchive/test/test_compat_bzip2_2.tbz.uu +++ /dev/null @@ -1,11 +0,0 @@ -$FreeBSD$ - -begin 644 test_compat_bzip2_2.tbz -M0EIH.3%!629361HI1P<``4#;D-$00`#_@``)9RT>$`0``!@P`/@#&$Q,F`F` -M`,83$R8"8``1133"1/2-J-#$/U3@;XVF9V'`Y3882XA$*KO6\WTL`]QU&J"8 -M$-=*Q$\@=`=QJ,TQ;3UH,NPT$-(!"HV&!ZO5D&@P-1D&1@'L<8&209QV9'G` -MW&PRZ0Q(-BT%&DG*DE.!U*#J.P]*#%-P9G`W9+34:#S&M`;@^1R^![C]:Y)U -MDF9/(\AR/@?P@^@I_B[DBG"A(#12C@X!3;VUE(&UOV=QL!06ER26`1T2G9F:EY)54XJ -MN>9`/*(`IX<(2#/D&F@GC`(Z``#S57',@'E&`TT,$I!EQ -M#;031@$5`0`Q!<\4Z`,``!^+"`B8OB))``-T97-T+7-P;&ET+G1A$0!3@\1D&;,-=!.&`5D``#7L]HO -MZ`,``!^+"`B8OB))``-T97-T+7-P;&ET+G1A57',@'E&`TT,$I!ER#;031@$>``"Y*#OBZ`,``!^+"`B8 -MOB))``-T97-T+7-P;&ET+G1A@ALXPP`]CXF=Q&A<:-UX>EN)C5M,AL;P -MO@V[0A=_.E39F2.B'*.?5QX2?Z\?XGE&27)F]L0)V>E_'7YY07\>OZ)Y1W6Q\!-J3!?H^Z_J7TG]%_"QK0?\]4[/>HZS^_^T\! -M_;>@@OY[=N2]6E\!JOH/P])_2OC^-X'YOV]+_]97@*K^A4K_C/Y;P/S?MZ5_ -MZRM`7?]<^L?_OR8P_P,`].D%,XR2*0`<``!4:&ES(&ES('5N $dir/f1 -echo "f2" > $dir/f2 -echo "f3" > $dir/f3 -mkdir $dir/d1 -echo "f1" > $dir/d1/f1 -echo "f2" > $dir/d1/f2 -echo "f3" > $dir/d1/f3 -(cd $dir; tar cf ../$name.tar f1 f2 f3 d1/f1 d1/f2 d1/f3) -rm -r $dir -} -mktarfile -$zcmd $name.tar -mv $name.tar.$zsuffix $name.$ztar_suffix -echo "This is unrelated junk data at the end of the file" >> $name.$ztar_suffix -uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu -rm -f $name.$ztar_suffix -# -# Use option -e -# -name=test_compat_lzma_2 -dir="$name`date +%Y%m%d%H%M%S`.$USER" -mktarfile -$zcmd -e $name.tar -mv $name.tar.$zsuffix $name.$ztar_suffix -uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu -rm -f $name.$ztar_suffix -# -# Use lzma command of LZMA SDK with option -d12. -# -name=test_compat_lzma_3 -zcmd=lzmasdk # Change this path to use lzma of LZMA SDK. -dir="$name`date +%Y%m%d%H%M%S`.$USER" -mktarfile -$zcmd e -d12 $name.tar $name.$ztar_suffix -rm -f $name.tar -uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu -rm -f $name.$ztar_suffix - -exit 0 -*/ - -/* - * Verify our ability to read sample files compatibly with unlzma. - * - * In particular: - * * unlzma will read multiple lzma streams, concatenating the output - * * unlzma will read lzma streams which is made by lzma with option -e, - * concatenating the output - * - * Verify our ability to read sample files compatibly with lzma of - * LZMA SDK. - * * lzma will read lzma streams which is made by lzma with option -d12, - * concatenating the output - */ - -/* - * All of the sample files have the same contents; they're just - * compressed in different ways. - */ -static void -compat_lzma(const char *name) -{ - const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; - struct archive_entry *ae; - struct archive *a; - int i, r; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); - - /* Read entries, match up names with list above. */ - for (i = 0; i < 6; ++i) { - failure("Could not read file %d (%s) from %s", i, n[i], name); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString(n[i], archive_entry_pathname(ae)); - } - - /* Verify the end-of-archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_LZMA); - assertEqualString(archive_compression_name(a), "lzma"); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - -DEFINE_TEST(test_compat_lzma) -{ - /* This sample has been added junk datas to its tail. */ - compat_lzma("test_compat_lzma_1.tlz"); - /* This sample has been made by lzma with option -e, - * the first byte of which is 0x5e. - * Not supported in libarchive 2.7.* and earlier */ - compat_lzma("test_compat_lzma_2.tlz"); - /* This sample has been made by lzma of LZMA SDK with - * option -d12, second byte and third byte of which is - * not zero. - * Not supported in libarchive 2.7.* and earlier */ - compat_lzma("test_compat_lzma_3.tlz"); -} diff --git a/lib/libarchive/test/test_compat_lzma_1.tlz.uu b/lib/libarchive/test/test_compat_lzma_1.tlz.uu deleted file mode 100644 index 3b63211..0000000 --- a/lib/libarchive/test/test_compat_lzma_1.tlz.uu +++ /dev/null @@ -1,10 +0,0 @@ -$FreeBSD$ - -begin 644 test_compat_lzma_1.tlz -M70``@`#__________P`S##P;IXPT!HUK`DO\DC[V2OB%Z^'=ZT59ANYMTD(/ -M^W;\8!%O7<+P&=#(9W<_!$Z.7/Y<&\(8+E0^,_-\Z"D^P'N0J^4-UH"WMJ<& -MV-P6=Y[-FY$IFNZ="RF24TO.B7EP[F]BGMJSP[]OZ_P9/#J'T=;7E&&A@J<[ -MA^C'Q*/Y&I)2^T930'MJTK-98U0D9R*-X2^5__6H:+A4:&ES(&ES('5N`W2"/3R1F1:P:&Q9A -MGH2JJI9$C?8.=WTE:O<1WA@X>DK-Y#SW;I2!P;NYG^2"-(D9/E(D_0XK_H,\ -95*/V"T#E9ZO][@'R,6E&^A([.##_\M#YU@`` -` -end diff --git a/lib/libarchive/test/test_compat_lzma_3.tlz.uu b/lib/libarchive/test/test_compat_lzma_3.tlz.uu deleted file mode 100644 index b8d61b7..0000000 --- a/lib/libarchive/test/test_compat_lzma_3.tlz.uu +++ /dev/null @@ -1,9 +0,0 @@ -$FreeBSD$ - -begin 644 test_compat_lzma_3.tlz -M70`0````'``````````S##P;IXPT!HUK`DO\DC[V2OB%Z^'=ZT59ANYMTD(1 -M$Y^=;\4%U_CXKQ*F$OFZKEQUG)1U8="](V<2K"U1\Z6%H(UNQ[Y3.=D'>_G- -MCO71X+M*7WH7$D1&E9Y$XHW,(`[X";GGTO+,'&1?F%<@`.$-OV;8P1?*M$A" -:MA+1XONREMK,1('455L=X1>WC#1YW"('I@`` -` -end diff --git a/lib/libarchive/test/test_compat_solaris_tar_acl.c b/lib/libarchive/test/test_compat_solaris_tar_acl.c deleted file mode 100644 index af4f9d3..0000000 --- a/lib/libarchive/test/test_compat_solaris_tar_acl.c +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Exercise support for reading Solaris-style ACL data - * from tar archives. - * - * This should work on all systems, regardless of whether local - * filesystems support ACLs or not. - */ - -DEFINE_TEST(test_compat_solaris_tar_acl) -{ - struct archive *a; - struct archive_entry *ae; - const char *reference1 = "test_compat_solaris_tar_acl.tar"; - int type, permset, tag, qual; - const char *name; - - /* Sample file generated on Solaris 10 */ - extract_reference_file(reference1); - assert(NULL != (a = archive_read_new())); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_filename(a, reference1, 512)); - - /* Archive has 1 entry with some ACLs set on it. */ - assertA(0 == archive_read_next_header(a, &ae)); - failure("Basic ACLs should set mode to 0644, not %04o", - archive_entry_mode(ae)&0777); - assertEqualInt((archive_entry_mode(ae) & 0777), 0644); - assertEqualInt(7, archive_entry_acl_reset(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); - assertEqualInt(006, permset); - assertEqualInt(ARCHIVE_ENTRY_ACL_USER_OBJ, tag); - assertEqualInt(-1, qual); - assert(name == NULL); - - assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); - assertEqualInt(004, permset); - assertEqualInt(ARCHIVE_ENTRY_ACL_GROUP_OBJ, tag); - assertEqualInt(-1, qual); - assert(name == NULL); - - assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); - assertEqualInt(004, permset); - assertEqualInt(ARCHIVE_ENTRY_ACL_OTHER, tag); - assertEqualInt(-1, qual); - assert(name == NULL); - - assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); - assertEqualInt(001, permset); - assertEqualInt(ARCHIVE_ENTRY_ACL_USER, tag); - assertEqualInt(71, qual); - assertEqualString(name, "lp"); - - assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); - assertEqualInt(004, permset); - assertEqualInt(ARCHIVE_ENTRY_ACL_USER, tag); - assertEqualInt(666, qual); - assertEqualString(name, "666"); - - assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); - assertEqualInt(007, permset); - assertEqualInt(ARCHIVE_ENTRY_ACL_USER, tag); - assertEqualInt(1000, qual); - assertEqualString(name, "trasz"); - - assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); - assertEqualInt(004, permset); - assertEqualInt(ARCHIVE_ENTRY_ACL_MASK, tag); - assertEqualInt(-1, qual); - assertEqualString(name, NULL); - - assertEqualInt(ARCHIVE_EOF, archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - - /* Close the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} diff --git a/lib/libarchive/test/test_compat_solaris_tar_acl.tar.uu b/lib/libarchive/test/test_compat_solaris_tar_acl.tar.uu deleted file mode 100644 index 229b335..0000000 --- a/lib/libarchive/test/test_compat_solaris_tar_acl.tar.uu +++ /dev/null @@ -1,61 +0,0 @@ -$FreeBSD$ -begin 644 test_acl_solaris.tar -M9FEL92UW:71H+7!O#HW,2QU#HQ,#`P+&=R;W5P.CIR+2TL;6%S:SIR+69I;&4M=VET:"UP -M;W-I>"UA8VQS```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````P -M,#`P-C0T`#`P,#$W-3``,#`P,#`P,``P,#`P,#`P,#`P,``Q,3$W-#8P-#$U -M-P`P,#$U,30T`#`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````=7-T87(`,#!T@`````````````` -M`````````````````````')O;W0````````````````````````````````` -M````,#`P,#(Q,``P,#`P,#$P```````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -H```````````````````````````````````````````````````````` -` -end diff --git a/lib/libarchive/test/test_compat_tar_hardlink.c b/lib/libarchive/test/test_compat_tar_hardlink.c deleted file mode 100644 index c1021ef..0000000 --- a/lib/libarchive/test/test_compat_tar_hardlink.c +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Background: There are two written standards for the tar file format. - * The first is the POSIX 1988 "ustar" format, the second is the 2001 - * "pax extended" format that builds on the "ustar" format by adding - * support for generic additional attributes. Buried in the details - * is one frustrating incompatibility: The 1988 standard says that - * tar readers MUST ignore the size field on hardlink entries; the - * 2001 standard says that tar readers MUST obey the size field on - * hardlink entries. libarchive tries to navigate this particular - * minefield by using auto-detect logic to guess whether it should - * or should not obey the size field. - * - * This test tries to probe the boundaries of such handling; the test - * archives here were adapted from real archives created by real - * tar implementations that are (as of early 2008) apparently still - * in use. - */ - -static void -test_compat_tar_hardlink_1(void) -{ - char name[] = "test_compat_tar_hardlink_1.tar"; - struct archive_entry *ae; - struct archive *a; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); - - /* Read first entry, which is a regular file. */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("xmcd-3.3.2/docs_d/READMf", - archive_entry_pathname(ae)); - assertEqualString(NULL, archive_entry_hardlink(ae)); - assertEqualInt(321, archive_entry_size(ae)); - assertEqualInt(1082575645, archive_entry_mtime(ae)); - assertEqualInt(1851, archive_entry_uid(ae)); - assertEqualInt(3, archive_entry_gid(ae)); - assertEqualInt(0100444, archive_entry_mode(ae)); - - /* Read second entry, which is a hard link at the end of archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("xmcd-3.3.2/README", - archive_entry_pathname(ae)); - assertEqualString( - "xmcd-3.3.2/docs_d/READMf", - archive_entry_hardlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1082575645, archive_entry_mtime(ae)); - assertEqualInt(1851, archive_entry_uid(ae)); - assertEqualInt(3, archive_entry_gid(ae)); - assertEqualInt(0100444, archive_entry_mode(ae)); - - /* Verify the end-of-archive. */ - /* - * This failed in libarchive 2.4.12 because the tar reader - * tried to obey the size field for the hard link and ended - * up running past the end of the file. - */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - -DEFINE_TEST(test_compat_tar_hardlink) -{ - test_compat_tar_hardlink_1(); -} - - diff --git a/lib/libarchive/test/test_compat_tar_hardlink_1.tar.uu b/lib/libarchive/test/test_compat_tar_hardlink_1.tar.uu deleted file mode 100644 index f1658a2..0000000 --- a/lib/libarchive/test/test_compat_tar_hardlink_1.tar.uu +++ /dev/null @@ -1,39 +0,0 @@ -$FreeBSD$ -begin 644 test_compat_tar_hardlink_1.tar -M>&UC9"TS+C,N,B]D;V-S7V0O4D5!1$UF```````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````"`@(#0T-"``("`S-#'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'@````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````'AM8V0M,RXS+C(O -M4D5!1$U%```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````@ -M("`T-#0@`"`@,S0W,R``("`@("`S(``@("`@("`@(#4P,2`Q,#`T,34T-30S -M-2`@,3(R,#<`(#%X;6-D+3,N,RXR+V1O8W-?9"]214%$368````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -&```````` -` -end diff --git a/lib/libarchive/test/test_compat_xz.c b/lib/libarchive/test/test_compat_xz.c deleted file mode 100644 index 9041427..0000000 --- a/lib/libarchive/test/test_compat_xz.c +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2008 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Verify our ability to read sample files compatibly with unxz. - * - * In particular: - * * unxz will read multiple xz streams, concatenating the output - */ - -/* - * All of the sample files have the same contents; they're just - * compressed in different ways. - */ -static void -compat_xz(const char *name) -{ - const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; - struct archive_entry *ae; - struct archive *a; - int i, r; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); - - /* Read entries, match up names with list above. */ - for (i = 0; i < 6; ++i) { - failure("Could not read file %d (%s) from %s", i, n[i], name); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString(n[i], archive_entry_pathname(ae)); - } - - /* Verify the end-of-archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); - assertEqualString(archive_compression_name(a), "xz"); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - -DEFINE_TEST(test_compat_xz) -{ - compat_xz("test_compat_xz_1.txz"); -} diff --git a/lib/libarchive/test/test_compat_xz_1.txz.uu b/lib/libarchive/test/test_compat_xz_1.txz.uu deleted file mode 100644 index 82794fd..0000000 --- a/lib/libarchive/test/test_compat_xz_1.txz.uu +++ /dev/null @@ -1,13 +0,0 @@ -$FreeBSD$ -begin 644 test_compat_gzip_1.txz -M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`^?`(-=`#,,/!NGC#0&C6L"2_R2 -M/O9*^(7KX=WM^(=KA(RH"\09$$)!Q_+JUHQ*`]R;ITL_F3/I6:^Q0550A&)B -MHS@=K]7@K1-9FOIP#PU!I?E5&IHH&Q=N>_C&G -M-$G]+L[\,B<7%8&$NO5K31*Y>"D^*ZG,Z=H```"KU50H$1^1S``!GP&@'P`` -MLZ042+'$9_L"``````196OTW>EA:```$YM:T1@(`(0$6````="_EH^`,7P!I -M70``;IBIKOMK%/A?-TZV0266G?2,[/?\,JE6` -M__C/SA[W1?*2J9Z!O$&YKI)!H8*&L&E>0J^FIJ\7+Q<`%!+!PAHTY\490```'$```!02P,$%``(``@`"(2# -M-P````````````````D```!T;7`N8VQA"%3```%!+!P@+ -M(*8V:````'8```!02P$"%``4``@`"``(A(,W:-.?%&4```!Q````%``````` -M````````````````345402U)3D8O34%.249%4U0N34902P$"%``4``@`"``( -MA(,W"R"F-F@```!V````"0````````````````"G````=&UP+F-L87-S4$L% -J!@`````"``(`>0```$8!```7`%!R;T=U87)D+"!V97)S:6]N(#0N,"XQ -` -end diff --git a/lib/libarchive/test/test_compat_zip_2.zip.uu b/lib/libarchive/test/test_compat_zip_2.zip.uu deleted file mode 100644 index c33e9d9..0000000 --- a/lib/libarchive/test/test_compat_zip_2.zip.uu +++ /dev/null @@ -1,10 +0,0 @@ -$FreeBSD$ - -begin 644 test_compat_zip_2.zip -M4$L#!`H``````'V59CT````````````````%````9FEL93$M2E5.2RU02P,$ -M"@``````@95F/<>D!,D&````!@````4```!F:6QE,F9I;&4R"E!+`0(>`PH` -M`````'V59CT````````````````%``````````````"D@0````!F:6QE,5!+ -M`0(>`PH``````(&59CW'I`3)!@````8````%``````````````"D@2D```!F -::6QE,E!+!08``````@`"`&8```!2```````` -` -end diff --git a/lib/libarchive/test/test_empty_write.c b/lib/libarchive/test/test_empty_write.c deleted file mode 100644 index 9980e3a..0000000 --- a/lib/libarchive/test/test_empty_write.c +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_empty_write) -{ - char buff[32768]; - struct archive_entry *ae; - struct archive *a; - size_t used; - int r; - - /* - * Exercise a zero-byte write to a gzip-compressed archive. - */ - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_gzip(a); - if (r == ARCHIVE_FATAL) { - skipping("Empty write to gzip-compressed archive"); - } else { - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, sizeof(buff), &used)); - /* Write a file to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 0); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* THE TEST: write zero bytes to this entry. */ - /* This used to crash. */ - assertEqualIntA(a, 0, archive_write_data(a, "", 0)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - } - - /* - * Again, with bzip2 compression. - */ - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_bzip2(a); - if (r == ARCHIVE_FATAL) { - skipping("Empty write to bzip2-compressed archive"); - } else { - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, sizeof(buff), &used)); - /* Write a file to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 0); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* THE TEST: write zero bytes to this entry. */ - assertEqualIntA(a, 0, archive_write_data(a, "", 0)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - } - - /* - * For good measure, one more time with no compression. - */ - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - /* Write a file to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 0); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* THE TEST: write zero bytes to this entry. */ - assertEqualIntA(a, 0, archive_write_data(a, "", 0)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); -} diff --git a/lib/libarchive/test/test_entry.c b/lib/libarchive/test/test_entry.c deleted file mode 100644 index 35ca6e3..0000000 --- a/lib/libarchive/test/test_entry.c +++ /dev/null @@ -1,903 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#include - -#ifndef HAVE_WCSCPY -static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2) -{ - wchar_t *dest = s1; - while ((*s1 = *s2) != L'\0') - ++s1, ++s2; - return dest; -} -#endif - -/* - * Most of these tests are system-independent, though a few depend on - * features of the local system. Such tests are conditionalized on - * the platform name. On unsupported platforms, only the - * system-independent features will be tested. - * - * No, I don't want to use config.h in the test files because I want - * the tests to also serve as a check on the correctness of config.h. - * A mis-configured library build should cause tests to fail. - */ - -DEFINE_TEST(test_entry) -{ - char buff[128]; - wchar_t wbuff[128]; - struct stat st; - struct archive_entry *e, *e2; - const struct stat *pst; - unsigned long set, clear; /* For fflag testing. */ - int type, permset, tag, qual; /* For ACL testing. */ - const char *name; /* For ACL testing. */ - const char *xname; /* For xattr tests. */ - const void *xval; /* For xattr tests. */ - size_t xsize; /* For xattr tests. */ - wchar_t wc; - long l; - - assert((e = archive_entry_new()) != NULL); - - /* - * Verify that the AE_IF* defines match S_IF* defines - * on this platform. See comments in archive_entry.h. - */ -#ifdef S_IFREG - assertEqualInt(S_IFREG, AE_IFREG); -#endif -#ifdef S_IFLNK - assertEqualInt(S_IFLNK, AE_IFLNK); -#endif -#ifdef S_IFSOCK - assertEqualInt(S_IFSOCK, AE_IFSOCK); -#endif -#ifdef S_IFCHR - assertEqualInt(S_IFCHR, AE_IFCHR); -#endif -/* Work around MinGW, which defines S_IFBLK wrong. */ -/* sourceforge.net/tracker/?func=detail&atid=102435&aid=1942809&group_id=2435 */ -#if defined(S_IFBLK) && !defined(_WIN32) - assertEqualInt(S_IFBLK, AE_IFBLK); -#endif -#ifdef S_IFDIR - assertEqualInt(S_IFDIR, AE_IFDIR); -#endif -#ifdef S_IFIFO - assertEqualInt(S_IFIFO, AE_IFIFO); -#endif - - /* - * Basic set/read tests for all fields. - * We should be able to set any field and read - * back the same value. - * - * For methods that "copy" a string, we should be able - * to overwrite the original passed-in string without - * changing the value in the entry. - * - * The following tests are ordered alphabetically by the - * name of the field. - */ - - /* atime */ - archive_entry_set_atime(e, 13579, 24680); - assertEqualInt(archive_entry_atime(e), 13579); - assertEqualInt(archive_entry_atime_nsec(e), 24680); - archive_entry_unset_atime(e); - assertEqualInt(archive_entry_atime(e), 0); - assertEqualInt(archive_entry_atime_nsec(e), 0); - assert(!archive_entry_atime_is_set(e)); - - /* birthtime */ - archive_entry_set_birthtime(e, 17579, 24990); - assertEqualInt(archive_entry_birthtime(e), 17579); - assertEqualInt(archive_entry_birthtime_nsec(e), 24990); - archive_entry_unset_birthtime(e); - assertEqualInt(archive_entry_birthtime(e), 0); - assertEqualInt(archive_entry_birthtime_nsec(e), 0); - assert(!archive_entry_birthtime_is_set(e)); - - /* ctime */ - archive_entry_set_ctime(e, 13580, 24681); - assertEqualInt(archive_entry_ctime(e), 13580); - assertEqualInt(archive_entry_ctime_nsec(e), 24681); - archive_entry_unset_ctime(e); - assertEqualInt(archive_entry_ctime(e), 0); - assertEqualInt(archive_entry_ctime_nsec(e), 0); - assert(!archive_entry_ctime_is_set(e)); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* dev */ - archive_entry_set_dev(e, 235); - assertEqualInt(archive_entry_dev(e), 235); -#else - skipping("archive_entry_dev()"); -#endif - /* devmajor/devminor are tested specially below. */ - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* filetype */ - archive_entry_set_filetype(e, AE_IFREG); - assertEqualInt(archive_entry_filetype(e), AE_IFREG); -#else - skipping("archive_entry_filetype()"); -#endif - - /* fflags are tested specially below */ - - /* gid */ - archive_entry_set_gid(e, 204); - assertEqualInt(archive_entry_gid(e), 204); - - /* gname */ - archive_entry_set_gname(e, "group"); - assertEqualString(archive_entry_gname(e), "group"); - wcscpy(wbuff, L"wgroup"); - archive_entry_copy_gname_w(e, wbuff); - assertEqualWString(archive_entry_gname_w(e), L"wgroup"); - memset(wbuff, 0, sizeof(wbuff)); - assertEqualWString(archive_entry_gname_w(e), L"wgroup"); - - /* hardlink */ - archive_entry_set_hardlink(e, "hardlinkname"); - assertEqualString(archive_entry_hardlink(e), "hardlinkname"); - strcpy(buff, "hardlinkname2"); - archive_entry_copy_hardlink(e, buff); - assertEqualString(archive_entry_hardlink(e), "hardlinkname2"); - memset(buff, 0, sizeof(buff)); - assertEqualString(archive_entry_hardlink(e), "hardlinkname2"); - archive_entry_copy_hardlink(e, NULL); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualWString(archive_entry_hardlink_w(e), NULL); - wcscpy(wbuff, L"whardlink"); - archive_entry_copy_hardlink_w(e, wbuff); - assertEqualWString(archive_entry_hardlink_w(e), L"whardlink"); - memset(wbuff, 0, sizeof(wbuff)); - assertEqualWString(archive_entry_hardlink_w(e), L"whardlink"); - archive_entry_copy_hardlink_w(e, NULL); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualWString(archive_entry_hardlink_w(e), NULL); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* ino */ - archive_entry_set_ino(e, 8593); - assertEqualInt(archive_entry_ino(e), 8593); -#else - skipping("archive_entry_ino()"); -#endif - - /* link */ - archive_entry_set_hardlink(e, "hardlinkname"); - archive_entry_set_symlink(e, NULL); - archive_entry_set_link(e, "link"); - assertEqualString(archive_entry_hardlink(e), "link"); - assertEqualString(archive_entry_symlink(e), NULL); - archive_entry_copy_link(e, "link2"); - assertEqualString(archive_entry_hardlink(e), "link2"); - assertEqualString(archive_entry_symlink(e), NULL); - archive_entry_copy_link_w(e, L"link3"); - assertEqualString(archive_entry_hardlink(e), "link3"); - assertEqualString(archive_entry_symlink(e), NULL); - archive_entry_set_hardlink(e, NULL); - archive_entry_set_symlink(e, "symlink"); - archive_entry_set_link(e, "link"); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualString(archive_entry_symlink(e), "link"); - archive_entry_copy_link(e, "link2"); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualString(archive_entry_symlink(e), "link2"); - archive_entry_copy_link_w(e, L"link3"); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualString(archive_entry_symlink(e), "link3"); - /* Arbitrarily override symlink if both hardlink and symlink set. */ - archive_entry_set_hardlink(e, "hardlink"); - archive_entry_set_symlink(e, "symlink"); - archive_entry_set_link(e, "link"); - assertEqualString(archive_entry_hardlink(e), "hardlink"); - assertEqualString(archive_entry_symlink(e), "link"); - - /* mode */ - archive_entry_set_mode(e, 0123456); - assertEqualInt(archive_entry_mode(e), 0123456); - - /* mtime */ - archive_entry_set_mtime(e, 13581, 24682); - assertEqualInt(archive_entry_mtime(e), 13581); - assertEqualInt(archive_entry_mtime_nsec(e), 24682); - archive_entry_unset_mtime(e); - assertEqualInt(archive_entry_mtime(e), 0); - assertEqualInt(archive_entry_mtime_nsec(e), 0); - assert(!archive_entry_mtime_is_set(e)); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* nlink */ - archive_entry_set_nlink(e, 736); - assertEqualInt(archive_entry_nlink(e), 736); -#else - skipping("archive_entry_nlink()"); -#endif - - /* pathname */ - archive_entry_set_pathname(e, "path"); - assertEqualString(archive_entry_pathname(e), "path"); - archive_entry_set_pathname(e, "path"); - assertEqualString(archive_entry_pathname(e), "path"); - strcpy(buff, "path2"); - archive_entry_copy_pathname(e, buff); - assertEqualString(archive_entry_pathname(e), "path2"); - memset(buff, 0, sizeof(buff)); - assertEqualString(archive_entry_pathname(e), "path2"); - wcscpy(wbuff, L"wpath"); - archive_entry_copy_pathname_w(e, wbuff); - assertEqualWString(archive_entry_pathname_w(e), L"wpath"); - memset(wbuff, 0, sizeof(wbuff)); - assertEqualWString(archive_entry_pathname_w(e), L"wpath"); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* rdev */ - archive_entry_set_rdev(e, 532); - assertEqualInt(archive_entry_rdev(e), 532); -#else - skipping("archive_entry_rdev()"); -#endif - /* rdevmajor/rdevminor are tested specially below. */ - - /* size */ - archive_entry_set_size(e, 987654321); - assertEqualInt(archive_entry_size(e), 987654321); - archive_entry_unset_size(e); - assertEqualInt(archive_entry_size(e), 0); - assert(!archive_entry_size_is_set(e)); - - /* sourcepath */ - archive_entry_copy_sourcepath(e, "path1"); - assertEqualString(archive_entry_sourcepath(e), "path1"); - - /* symlink */ - archive_entry_set_symlink(e, "symlinkname"); - assertEqualString(archive_entry_symlink(e), "symlinkname"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - strcpy(buff, "symlinkname2"); - archive_entry_copy_symlink(e, buff); - assertEqualString(archive_entry_symlink(e), "symlinkname2"); - memset(buff, 0, sizeof(buff)); - assertEqualString(archive_entry_symlink(e), "symlinkname2"); -#endif - archive_entry_copy_symlink_w(e, NULL); - assertEqualWString(archive_entry_symlink_w(e), NULL); - assertEqualString(archive_entry_symlink(e), NULL); - archive_entry_copy_symlink_w(e, L"wsymlink"); - assertEqualWString(archive_entry_symlink_w(e), L"wsymlink"); - archive_entry_copy_symlink(e, NULL); - assertEqualWString(archive_entry_symlink_w(e), NULL); - assertEqualString(archive_entry_symlink(e), NULL); - - /* uid */ - archive_entry_set_uid(e, 83); - assertEqualInt(archive_entry_uid(e), 83); - - /* uname */ - archive_entry_set_uname(e, "user"); - assertEqualString(archive_entry_uname(e), "user"); - wcscpy(wbuff, L"wuser"); - archive_entry_copy_gname_w(e, wbuff); - assertEqualWString(archive_entry_gname_w(e), L"wuser"); - memset(wbuff, 0, sizeof(wbuff)); - assertEqualWString(archive_entry_gname_w(e), L"wuser"); - - /* Test fflags interface. */ - archive_entry_set_fflags(e, 0x55, 0xAA); - archive_entry_fflags(e, &set, &clear); - failure("Testing set/get of fflags data."); - assertEqualInt(set, 0x55); - failure("Testing set/get of fflags data."); - assertEqualInt(clear, 0xAA); -#ifdef __FreeBSD__ - /* Converting fflags bitmap to string is currently system-dependent. */ - /* TODO: Make this system-independent. */ - assertEqualString(archive_entry_fflags_text(e), - "uappnd,nouchg,nodump,noopaque,uunlnk"); - /* Test archive_entry_copy_fflags_text_w() */ - archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,uunlnk"); - archive_entry_fflags(e, &set, &clear); - assertEqualInt(16, set); - assertEqualInt(7, clear); - /* Test archive_entry_copy_fflags_text() */ - archive_entry_copy_fflags_text(e, " ,nouappnd, nouchg, dump,uunlnk"); - archive_entry_fflags(e, &set, &clear); - assertEqualInt(16, set); - assertEqualInt(7, clear); -#endif - - /* See test_acl_basic.c for tests of ACL set/get consistency. */ - - /* Test xattrs set/get consistency. */ - archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12); - assertEqualInt(1, archive_entry_xattr_reset(e)); - assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualString(xname, "xattr1"); - assertEqualString(xval, "xattrvalue1"); - assertEqualInt((int)xsize, 12); - assertEqualInt(1, archive_entry_xattr_count(e)); - assertEqualInt(ARCHIVE_WARN, - archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualString(xname, NULL); - assertEqualString(xval, NULL); - assertEqualInt((int)xsize, 0); - archive_entry_xattr_clear(e); - assertEqualInt(0, archive_entry_xattr_reset(e)); - assertEqualInt(ARCHIVE_WARN, - archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualString(xname, NULL); - assertEqualString(xval, NULL); - assertEqualInt((int)xsize, 0); - archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12); - assertEqualInt(1, archive_entry_xattr_reset(e)); - archive_entry_xattr_add_entry(e, "xattr2", "xattrvalue2", 12); - assertEqualInt(2, archive_entry_xattr_reset(e)); - assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualInt(ARCHIVE_WARN, - archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualString(xname, NULL); - assertEqualString(xval, NULL); - assertEqualInt((int)xsize, 0); - - - /* - * Test clone() implementation. - */ - - /* Set values in 'e' */ - archive_entry_clear(e); - archive_entry_set_atime(e, 13579, 24680); - archive_entry_set_birthtime(e, 13779, 24990); - archive_entry_set_ctime(e, 13580, 24681); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 235); -#endif - archive_entry_set_fflags(e, 0x55, 0xAA); - archive_entry_set_gid(e, 204); - archive_entry_set_gname(e, "group"); - archive_entry_set_hardlink(e, "hardlinkname"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_ino(e, 8593); -#endif - archive_entry_set_mode(e, 0123456); - archive_entry_set_mtime(e, 13581, 24682); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_nlink(e, 736); -#endif - archive_entry_set_pathname(e, "path"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_rdev(e, 532); -#endif - archive_entry_set_size(e, 987654321); - archive_entry_copy_sourcepath(e, "source"); - archive_entry_set_symlink(e, "symlinkname"); - archive_entry_set_uid(e, 83); - archive_entry_set_uname(e, "user"); - /* Add an ACL entry. */ - archive_entry_acl_add_entry(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_READ, ARCHIVE_ENTRY_ACL_USER, 77, "user77"); - /* Add an extended attribute. */ - archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue", 11); - - /* Make a clone. */ - e2 = archive_entry_clone(e); - - /* Clone should have same contents. */ - assertEqualInt(archive_entry_atime(e2), 13579); - assertEqualInt(archive_entry_atime_nsec(e2), 24680); - assertEqualInt(archive_entry_birthtime(e2), 13779); - assertEqualInt(archive_entry_birthtime_nsec(e2), 24990); - assertEqualInt(archive_entry_ctime(e2), 13580); - assertEqualInt(archive_entry_ctime_nsec(e2), 24681); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_dev(e2), 235); -#endif - archive_entry_fflags(e, &set, &clear); - assertEqualInt(clear, 0xAA); - assertEqualInt(set, 0x55); - assertEqualInt(archive_entry_gid(e2), 204); - assertEqualString(archive_entry_gname(e2), "group"); - assertEqualString(archive_entry_hardlink(e2), "hardlinkname"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_ino(e2), 8593); -#endif - assertEqualInt(archive_entry_mode(e2), 0123456); - assertEqualInt(archive_entry_mtime(e2), 13581); - assertEqualInt(archive_entry_mtime_nsec(e2), 24682); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_nlink(e2), 736); -#endif - assertEqualString(archive_entry_pathname(e2), "path"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_rdev(e2), 532); -#endif - assertEqualInt(archive_entry_size(e2), 987654321); - assertEqualString(archive_entry_sourcepath(e2), "source"); - assertEqualString(archive_entry_symlink(e2), "symlinkname"); - assertEqualInt(archive_entry_uid(e2), 83); - assertEqualString(archive_entry_uname(e2), "user"); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("ACL preserved by archive_entry_clone()"); -#else - /* Verify ACL was copied. */ - assertEqualInt(4, archive_entry_acl_reset(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - /* First three are standard permission bits. */ - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 4); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 5); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 6); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - /* Fourth is custom one. */ - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER); - assertEqualInt(qual, 77); - assertEqualString(name, "user77"); -#endif -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("xattr data preserved by archive_entry_clone"); -#else - /* Verify xattr was copied. */ - assertEqualInt(1, archive_entry_xattr_reset(e2)); - assertEqualInt(0, archive_entry_xattr_next(e2, &xname, &xval, &xsize)); - assertEqualString(xname, "xattr1"); - assertEqualString(xval, "xattrvalue"); - assertEqualInt((int)xsize, 11); - assertEqualInt(ARCHIVE_WARN, - archive_entry_xattr_next(e2, &xname, &xval, &xsize)); - assertEqualString(xname, NULL); - assertEqualString(xval, NULL); - assertEqualInt((int)xsize, 0); -#endif - - /* Change the original */ - archive_entry_set_atime(e, 13580, 24690); - archive_entry_set_birthtime(e, 13980, 24999); - archive_entry_set_ctime(e, 13590, 24691); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 245); -#endif - archive_entry_set_fflags(e, 0x85, 0xDA); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_filetype(e, AE_IFLNK); -#endif - archive_entry_set_gid(e, 214); - archive_entry_set_gname(e, "grouper"); - archive_entry_set_hardlink(e, "hardlinkpath"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_ino(e, 8763); -#endif - archive_entry_set_mode(e, 0123654); - archive_entry_set_mtime(e, 18351, 28642); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_nlink(e, 73); -#endif - archive_entry_set_pathname(e, "pathest"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_rdev(e, 132); -#endif - archive_entry_set_size(e, 987456321); - archive_entry_copy_sourcepath(e, "source2"); - archive_entry_set_symlink(e, "symlinkpath"); - archive_entry_set_uid(e, 93); - archive_entry_set_uname(e, "username"); - archive_entry_acl_clear(e); - archive_entry_xattr_clear(e); - - /* Clone should still have same contents. */ - assertEqualInt(archive_entry_atime(e2), 13579); - assertEqualInt(archive_entry_atime_nsec(e2), 24680); - assertEqualInt(archive_entry_birthtime(e2), 13779); - assertEqualInt(archive_entry_birthtime_nsec(e2), 24990); - assertEqualInt(archive_entry_ctime(e2), 13580); - assertEqualInt(archive_entry_ctime_nsec(e2), 24681); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_dev(e2), 235); -#endif - archive_entry_fflags(e2, &set, &clear); - assertEqualInt(clear, 0xAA); - assertEqualInt(set, 0x55); - assertEqualInt(archive_entry_gid(e2), 204); - assertEqualString(archive_entry_gname(e2), "group"); - assertEqualString(archive_entry_hardlink(e2), "hardlinkname"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_ino(e2), 8593); -#endif - assertEqualInt(archive_entry_mode(e2), 0123456); - assertEqualInt(archive_entry_mtime(e2), 13581); - assertEqualInt(archive_entry_mtime_nsec(e2), 24682); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_nlink(e2), 736); -#endif - assertEqualString(archive_entry_pathname(e2), "path"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_rdev(e2), 532); -#endif - assertEqualInt(archive_entry_size(e2), 987654321); - assertEqualString(archive_entry_sourcepath(e2), "source"); - assertEqualString(archive_entry_symlink(e2), "symlinkname"); - assertEqualInt(archive_entry_uid(e2), 83); - assertEqualString(archive_entry_uname(e2), "user"); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("ACL held by clone of archive_entry"); -#else - /* Verify ACL was unchanged. */ - assertEqualInt(4, archive_entry_acl_reset(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - /* First three are standard permission bits. */ - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 4); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 5); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 6); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - /* Fourth is custom one. */ - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER); - assertEqualInt(qual, 77); - assertEqualString(name, "user77"); - assertEqualInt(1, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, 0); - assertEqualInt(permset, 0); - assertEqualInt(tag, 0); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); -#endif -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("xattr preserved in archive_entry copy"); -#else - /* Verify xattr was unchanged. */ - assertEqualInt(1, archive_entry_xattr_reset(e2)); -#endif - - /* Release clone. */ - archive_entry_free(e2); - - /* - * Test clear() implementation. - */ - archive_entry_clear(e); - assertEqualInt(archive_entry_atime(e), 0); - assertEqualInt(archive_entry_atime_nsec(e), 0); - assertEqualInt(archive_entry_birthtime(e), 0); - assertEqualInt(archive_entry_birthtime_nsec(e), 0); - assertEqualInt(archive_entry_ctime(e), 0); - assertEqualInt(archive_entry_ctime_nsec(e), 0); - assertEqualInt(archive_entry_dev(e), 0); - archive_entry_fflags(e, &set, &clear); - assertEqualInt(clear, 0); - assertEqualInt(set, 0); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_filetype(e), 0); -#endif - assertEqualInt(archive_entry_gid(e), 0); - assertEqualString(archive_entry_gname(e), NULL); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualInt(archive_entry_ino(e), 0); - assertEqualInt(archive_entry_mode(e), 0); - assertEqualInt(archive_entry_mtime(e), 0); - assertEqualInt(archive_entry_mtime_nsec(e), 0); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_nlink(e), 0); -#endif - assertEqualString(archive_entry_pathname(e), NULL); - assertEqualInt(archive_entry_rdev(e), 0); - assertEqualInt(archive_entry_size(e), 0); - assertEqualString(archive_entry_symlink(e), NULL); - assertEqualInt(archive_entry_uid(e), 0); - assertEqualString(archive_entry_uname(e), NULL); - /* ACLs should be cleared. */ - assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS), 0); - assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT), 0); - /* Extended attributes should be cleared. */ - assertEqualInt(archive_entry_xattr_count(e), 0); - - /* - * Test archive_entry_copy_stat(). - */ - memset(&st, 0, sizeof(st)); - /* Set all of the standard 'struct stat' fields. */ - st.st_atime = 456789; - st.st_ctime = 345678; - st.st_dev = 123; - st.st_gid = 34; - st.st_ino = 234; - st.st_mode = 077777; - st.st_mtime = 234567; - st.st_nlink = 345; - st.st_size = 123456789; - st.st_uid = 23; -#ifdef __FreeBSD__ - /* On FreeBSD, high-res timestamp data should come through. */ - st.st_atimespec.tv_nsec = 6543210; - st.st_ctimespec.tv_nsec = 5432109; - st.st_mtimespec.tv_nsec = 3210987; - st.st_birthtimespec.tv_nsec = 7459386; -#endif - /* Copy them into the entry. */ - archive_entry_copy_stat(e, &st); - /* Read each one back separately and compare. */ - assertEqualInt(archive_entry_atime(e), 456789); - assertEqualInt(archive_entry_ctime(e), 345678); - assertEqualInt(archive_entry_dev(e), 123); - assertEqualInt(archive_entry_gid(e), 34); - assertEqualInt(archive_entry_ino(e), 234); - assertEqualInt(archive_entry_mode(e), 077777); - assertEqualInt(archive_entry_mtime(e), 234567); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_nlink(e), 345); -#endif - assertEqualInt(archive_entry_size(e), 123456789); - assertEqualInt(archive_entry_uid(e), 23); -#if __FreeBSD__ - /* On FreeBSD, high-res timestamp data should come through. */ - assertEqualInt(archive_entry_atime_nsec(e), 6543210); - assertEqualInt(archive_entry_ctime_nsec(e), 5432109); - assertEqualInt(archive_entry_mtime_nsec(e), 3210987); - assertEqualInt(archive_entry_birthtime_nsec(e), 7459386); -#endif - - /* - * Test archive_entry_stat(). - */ - /* First, clear out any existing stat data. */ - memset(&st, 0, sizeof(st)); - archive_entry_copy_stat(e, &st); - /* Set a bunch of fields individually. */ - archive_entry_set_atime(e, 456789, 321); - archive_entry_set_ctime(e, 345678, 432); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 123); -#endif - archive_entry_set_gid(e, 34); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_ino(e, 234); -#endif - archive_entry_set_mode(e, 012345); - archive_entry_set_mode(e, 012345); - archive_entry_set_mtime(e, 234567, 543); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_nlink(e, 345); -#endif - archive_entry_set_size(e, 123456789); - archive_entry_set_uid(e, 23); - /* Retrieve a stat structure. */ - assert((pst = archive_entry_stat(e)) != NULL); - /* Check that the values match. */ - assertEqualInt(pst->st_atime, 456789); - assertEqualInt(pst->st_ctime, 345678); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(pst->st_dev, 123); -#endif - assertEqualInt(pst->st_gid, 34); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(pst->st_ino, 234); -#endif - assertEqualInt(pst->st_mode, 012345); - assertEqualInt(pst->st_mtime, 234567); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(pst->st_nlink, 345); -#endif - assertEqualInt(pst->st_size, 123456789); - assertEqualInt(pst->st_uid, 23); -#ifdef __FreeBSD__ - /* On FreeBSD, high-res timestamp data should come through. */ - assertEqualInt(pst->st_atimespec.tv_nsec, 321); - assertEqualInt(pst->st_ctimespec.tv_nsec, 432); - assertEqualInt(pst->st_mtimespec.tv_nsec, 543); -#endif - - /* Changing any one value should update struct stat. */ - archive_entry_set_atime(e, 456788, 0); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_atime, 456788); - archive_entry_set_ctime(e, 345677, 431); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_ctime, 345677); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 122); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_dev, 122); -#endif - archive_entry_set_gid(e, 33); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_gid, 33); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_ino(e, 233); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_ino, 233); -#endif - archive_entry_set_mode(e, 012344); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_mode, 012344); - archive_entry_set_mtime(e, 234566, 542); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_mtime, 234566); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_nlink(e, 344); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_nlink, 344); -#endif - archive_entry_set_size(e, 123456788); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_size, 123456788); - archive_entry_set_uid(e, 22); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_uid, 22); - /* We don't need to check high-res fields here. */ - - /* - * Test dev/major/minor interfaces. Setting 'dev' or 'rdev' - * should change the corresponding major/minor values, and - * vice versa. - * - * The test here is system-specific because it assumes that - * makedev(), major(), and minor() are defined in sys/stat.h. - * I'm not too worried about it, though, because the code is - * simple. If it works on FreeBSD, it's unlikely to be broken - * anywhere else. Note: The functionality is present on every - * platform even if these tests only run some places; - * libarchive's more extensive configuration logic should find - * the necessary definitions on every platform. - */ -#if __FreeBSD__ -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 0x12345678); - assertEqualInt(archive_entry_devmajor(e), major(0x12345678)); - assertEqualInt(archive_entry_devminor(e), minor(0x12345678)); - assertEqualInt(archive_entry_dev(e), 0x12345678); - archive_entry_set_devmajor(e, 0xfe); - archive_entry_set_devminor(e, 0xdcba98); - assertEqualInt(archive_entry_devmajor(e), 0xfe); - assertEqualInt(archive_entry_devminor(e), 0xdcba98); - assertEqualInt(archive_entry_dev(e), makedev(0xfe, 0xdcba98)); - archive_entry_set_rdev(e, 0x12345678); - assertEqualInt(archive_entry_rdevmajor(e), major(0x12345678)); - assertEqualInt(archive_entry_rdevminor(e), minor(0x12345678)); - assertEqualInt(archive_entry_rdev(e), 0x12345678); - archive_entry_set_rdevmajor(e, 0xfe); - archive_entry_set_rdevminor(e, 0xdcba98); - assertEqualInt(archive_entry_rdevmajor(e), 0xfe); - assertEqualInt(archive_entry_rdevminor(e), 0xdcba98); - assertEqualInt(archive_entry_rdev(e), makedev(0xfe, 0xdcba98)); -#endif -#endif - - /* - * Exercise the character-conversion logic, if we can. - */ - if (NULL == LOCALE_UTF8 || NULL == setlocale(LC_ALL, LOCALE_UTF8)) { - skipping("Can't exercise charset-conversion logic without" - " a suitable locale."); - } else { - /* A filename that cannot be converted to wide characters. */ - archive_entry_copy_pathname(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_pathname_w(e)); - //failure("Converting invalid chars to UTF-8 should fail."); - //assert(NULL == archive_entry_pathname_utf8(e)); - - /* A group name that cannot be converted. */ - archive_entry_copy_gname(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_gname_w(e)); - - /* A user name that cannot be converted. */ - archive_entry_copy_uname(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_uname_w(e)); - - /* A hardlink target that cannot be converted. */ - archive_entry_copy_hardlink(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_hardlink_w(e)); - - /* A symlink target that cannot be converted. */ - archive_entry_copy_symlink(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_symlink_w(e)); - } - -#if HAVE_WCSCPY - l = 0x12345678L; - wc = (wchar_t)l; /* Wide character too big for UTF-8. */ - if (NULL == setlocale(LC_ALL, "C") || (long)wc != l) { - skipping("Testing charset conversion failure requires 32-bit wchar_t and support for \"C\" locale."); - } else { - /* - * Build the string L"xxx\U12345678yyy\u5678zzz" without - * using C99 \u#### syntax, which isn't uniformly - * supported. (GCC 3.4.6, for instance, defaults to - * "c89 plus GNU extensions.") - */ - wcscpy(wbuff, L"xxxAyyyBzzz"); - wbuff[3] = (wchar_t)0x12345678; - wbuff[7] = (wchar_t)0x5678; - /* A wide filename that cannot be converted to narrow. */ - archive_entry_copy_pathname_w(e, wbuff); - failure("Converting wide characters from Unicode should fail."); - assertEqualString(NULL, archive_entry_pathname(e)); - } -#endif - - /* Release the experimental entry. */ - archive_entry_free(e); -} diff --git a/lib/libarchive/test/test_entry_strmode.c b/lib/libarchive/test/test_entry_strmode.c deleted file mode 100644 index 70c0e75..0000000 --- a/lib/libarchive/test/test_entry_strmode.c +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_entry_strmode) -{ - struct archive_entry *entry; - - assert((entry = archive_entry_new()) != NULL); - - archive_entry_set_mode(entry, AE_IFREG | 0642); - assertEqualString(archive_entry_strmode(entry), "-rw-r---w- "); - - /* Regular file + hardlink still shows as regular file. */ - archive_entry_set_mode(entry, AE_IFREG | 0644); - archive_entry_set_hardlink(entry, "link"); - assertEqualString(archive_entry_strmode(entry), "-rw-r--r-- "); - - archive_entry_set_mode(entry, 0640); - archive_entry_set_hardlink(entry, "link"); - assertEqualString(archive_entry_strmode(entry), "hrw-r----- "); - archive_entry_set_hardlink(entry, NULL); - - archive_entry_set_mode(entry, AE_IFDIR | 0777); - assertEqualString(archive_entry_strmode(entry), "drwxrwxrwx "); - - archive_entry_set_mode(entry, AE_IFBLK | 03642); - assertEqualString(archive_entry_strmode(entry), "brw-r-S-wT "); - - archive_entry_set_mode(entry, AE_IFCHR | 05777); - assertEqualString(archive_entry_strmode(entry), "crwsrwxrwt "); - - archive_entry_set_mode(entry, AE_IFSOCK | 0222); - assertEqualString(archive_entry_strmode(entry), "s-w--w--w- "); - - archive_entry_set_mode(entry, AE_IFIFO | 0444); - assertEqualString(archive_entry_strmode(entry), "pr--r--r-- "); - - archive_entry_set_mode(entry, AE_IFLNK | 04000); - assertEqualString(archive_entry_strmode(entry), "l--S------ "); - - archive_entry_acl_add_entry(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - 0007, ARCHIVE_ENTRY_ACL_GROUP, 78, "group78"); - assertEqualString(archive_entry_strmode(entry), "l--S------+"); - - /* Release the experimental entry. */ - archive_entry_free(entry); -} diff --git a/lib/libarchive/test/test_extattr_freebsd.c b/lib/libarchive/test/test_extattr_freebsd.c deleted file mode 100644 index de3ae2a..0000000 --- a/lib/libarchive/test/test_extattr_freebsd.c +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#if defined(__FreeBSD__) && __FreeBSD__ > 4 -#include -#endif - -/* - * Verify extended attribute restore-to-disk. This test is FreeBSD-specific. - */ - -DEFINE_TEST(test_extattr_freebsd) -{ -#if !defined(__FreeBSD__) - skipping("FreeBSD-specific extattr restore test"); -#elif __FreeBSD__ < 5 - skipping("extattr restore supported only on FreeBSD 5.0 and later"); -#else - char buff[64]; - const char *xname; - const void *xval; - size_t xsize; - struct stat st; - struct archive *a; - struct archive_entry *ae; - int n, fd; - int extattr_privilege_bug = 0; - - /* - * First, do a quick manual set/read of an extended attribute - * to verify that the local filesystem does support it. If it - * doesn't, we'll simply skip the remaining tests. - */ - /* Create a test file and try to set an ACL on it. */ - fd = open("pretest", O_RDWR | O_CREAT, 0777); - failure("Could not create test file?!"); - if (!assert(fd >= 0)) - return; - - errno = 0; - n = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, "testattr", "1234", 4); - if (n != 4 && errno == EOPNOTSUPP) { - close(fd); - skipping("extattr tests require that extattr support be enabled on the filesystem"); - return; - } - failure("extattr_set_fd(): errno=%d (%s)", errno, strerror(errno)); - assertEqualInt(4, n); - close(fd); - - /* - * Repeat the above, but with file permissions set to 0000. - * This should work (extattr_set_fd() should follow fd - * permissions, not file permissions), but is known broken on - * some versions of FreeBSD. - */ - fd = open("pretest2", O_RDWR | O_CREAT, 00000); - failure("Could not create test file?!"); - if (!assert(fd >= 0)) - return; - - n = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, "testattr", "1234", 4); - if (n != 4) { - skipping("Restoring xattr to an unwritable file seems to be broken on this platform"); - extattr_privilege_bug = 1; - } - close(fd); - - /* Create a write-to-disk object. */ - assert(NULL != (a = archive_write_disk_new())); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_XATTR); - - /* Populate an archive entry with an extended attribute. */ - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_pathname(ae, "test0"); - archive_entry_set_mtime(ae, 123456, 7890); - archive_entry_set_size(ae, 0); - archive_entry_set_mode(ae, 0755); - archive_entry_xattr_add_entry(ae, "user.foo", "12345", 5); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Another entry; similar but with mode = 0. */ - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_pathname(ae, "test1"); - archive_entry_set_mtime(ae, 12345678, 7890); - archive_entry_set_size(ae, 0); - archive_entry_set_mode(ae, 0); - archive_entry_xattr_add_entry(ae, "user.bar", "123456", 6); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close the archive. */ - if (extattr_privilege_bug) - /* If the bug is here, write_close will return warning. */ - assertEqualIntA(a, ARCHIVE_WARN, archive_write_close(a)); - else - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* Verify the data on disk. */ - assertEqualInt(0, stat("test0", &st)); - assertEqualInt(st.st_mtime, 123456); - /* Verify extattr */ - n = extattr_get_file("test0", EXTATTR_NAMESPACE_USER, - "foo", buff, sizeof(buff)); - if (assertEqualInt(n, 5)) { - buff[n] = '\0'; - assertEqualString(buff, "12345"); - } - - /* Verify the data on disk. */ - assertEqualInt(0, stat("test1", &st)); - assertEqualInt(st.st_mtime, 12345678); - /* Verify extattr */ - n = extattr_get_file("test1", EXTATTR_NAMESPACE_USER, - "bar", buff, sizeof(buff)); - if (extattr_privilege_bug) { - /* If we have the bug, the extattr won't have been written. */ - assertEqualInt(n, -1); - } else { - if (assertEqualInt(n, 6)) { - buff[n] = '\0'; - assertEqualString(buff, "123456"); - } - } - - /* Use libarchive APIs to read the file back into an entry and - * verify that the extattr was read correctly. */ - assert((a = archive_read_disk_new()) != NULL); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, "test0"); - assertEqualInt(ARCHIVE_OK, - archive_read_disk_entry_from_file(a, ae, -1, NULL)); - assertEqualInt(1, archive_entry_xattr_reset(ae)); - assertEqualInt(ARCHIVE_OK, - archive_entry_xattr_next(ae, &xname, &xval, &xsize)); - assertEqualString(xname, "user.foo"); - assertEqualInt(xsize, 5); - assertEqualMem(xval, "12345", xsize); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - archive_entry_free(ae); -#endif -} diff --git a/lib/libarchive/test/test_fuzz.c b/lib/libarchive/test/test_fuzz.c deleted file mode 100644 index 8f91fca..0000000 --- a/lib/libarchive/test/test_fuzz.c +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * This was inspired by an ISO fuzz tester written by Michal Zalewski - * and posted to the "vulnwatch" mailing list on March 17, 2005: - * http://seclists.org/vulnwatch/2005/q1/0088.html - * - * This test simply reads each archive image into memory, pokes - * random values into it and runs it through libarchive. It tries - * to damage about 1% of each file and repeats the exercise 100 times - * with each file. - * - * Unlike most other tests, this test does not verify libarchive's - * responses other than to ensure that libarchive doesn't crash. - * - * Due to the deliberately random nature of this test, it may be hard - * to reproduce failures. Because this test deliberately attempts to - * induce crashes, there's little that can be done in the way of - * post-failure diagnostics. - */ - -/* Because this works for any archive, we can just re-use the archives - * developed for other tests. */ -static struct { - int uncompress; /* If 1, decompress the file before fuzzing. */ - const char *name; -} files[] = { - {0, "test_fuzz_1.iso.Z"}, /* Exercise compress decompressor. */ - {1, "test_fuzz_1.iso.Z"}, - {0, "test_compat_bzip2_1.tbz"}, /* Exercise bzip2 decompressor. */ - {1, "test_compat_bzip2_1.tbz"}, - {0, "test_compat_gtar_1.tar"}, - {0, "test_compat_gzip_1.tgz"}, /* Exercise gzip decompressor. */ - {0, "test_compat_gzip_2.tgz"}, /* Exercise gzip decompressor. */ - {0, "test_compat_tar_hardlink_1.tar"}, - {0, "test_compat_xz_1.txz"}, /* Exercise xz decompressor. */ - {0, "test_compat_zip_1.zip"}, - {0, "test_read_format_ar.ar"}, - {0, "test_read_format_cpio_bin_be.cpio"}, - {0, "test_read_format_cpio_svr4_gzip_rpm.rpm"}, /* Test RPM unwrapper */ - {0, "test_read_format_gtar_sparse_1_17_posix10_modified.tar"}, - {0, "test_read_format_mtree.mtree"}, - {0, "test_read_format_tar_empty_filename.tar"}, - {0, "test_read_format_zip.zip"}, - {1, NULL} -}; - -DEFINE_TEST(test_fuzz) -{ - const void *blk; - size_t blk_size; - off_t blk_offset; - int n; - - for (n = 0; files[n].name != NULL; ++n) { - const size_t buffsize = 30000000; - const char *filename = files[n].name; - struct archive_entry *ae; - struct archive *a; - char *rawimage, *image; - size_t size; - int i; - - extract_reference_file(filename); - if (files[n].uncompress) { - int r; - /* Use format_raw to decompress the data. */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_raw(a)); - r = archive_read_open_filename(a, filename, 16384); - if (r != ARCHIVE_OK) { - archive_read_finish(a); - skipping("Cannot uncompress %s", filename); - continue; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - rawimage = malloc(buffsize); - size = archive_read_data(a, rawimage, buffsize); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_next_header(a, &ae)); - assertEqualInt(ARCHIVE_OK, - archive_read_finish(a)); - assert(size > 0); - failure("Internal buffer is not big enough for " - "uncompressed test file: %s", filename); - if (!assert(size < buffsize)) { - free(rawimage); - continue; - } - } else { - rawimage = slurpfile(&size, filename); - if (!assert(rawimage != NULL)) - continue; - } - image = malloc(size); - assert(image != NULL); - srand((unsigned)time(NULL)); - - for (i = 0; i < 100; ++i) { - FILE *f; - int j, numbytes; - - /* Fuzz < 1% of the bytes in the archive. */ - memcpy(image, rawimage, size); - numbytes = (int)(rand() % (size / 100)); - for (j = 0; j < numbytes; ++j) - image[rand() % size] = (char)rand(); - - /* Save the messed-up image to a file. - * If we crash, that file will be useful. */ - f = fopen("after.test.failure.send.this.file." - "to.libarchive.maintainers.with.system.details", "wb"); - fwrite(image, 1, (size_t)size, f); - fclose(f); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - - if (0 == archive_read_open_memory(a, image, size)) { - while(0 == archive_read_next_header(a, &ae)) { - while (0 == archive_read_data_block(a, - &blk, &blk_size, &blk_offset)) - continue; - } - archive_read_close(a); - } - archive_read_finish(a); - } - free(image); - free(rawimage); - } -} - - diff --git a/lib/libarchive/test/test_fuzz_1.iso.Z.uu b/lib/libarchive/test/test_fuzz_1.iso.Z.uu deleted file mode 100644 index 6044296..0000000 --- a/lib/libarchive/test/test_fuzz_1.iso.Z.uu +++ /dev/null @@ -1,495 +0,0 @@ -$FreeBSD$ - -begin 644 test_fuzz_1.iso.Z -M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1GA0%`(,)$`4'QT(0``F'H@``@"(PJ)`"(A"04(6#"0" -M`!P4E..+`;'(Q@(6),!``^"$>&)`*`+0X9),-NGDDU!&*>645%9IY9589JGE -MEEQ>V<0224SQA!%3@!#F$R#D8(,-,+R`!)D@&)$$$T5,D<445!2AH1!5S$E$ -M$5*`8`((%Q8QQ!-2/"A@"U*\0(05BDI11!!4(`H""D.D`$(,.>0P`PA%N)#% -M$U4X<0010=!Y:::;=GH#"$JX`,6D4HCIQ`NQ3C$$$G,RD82I708K;+`R$(A# -M##'(4&P.R<8P`X'@%`O#L,L<,Y`&"#VP#``,`7`"!A=L(.`SPV -M$P"4G'`69%/1=\8,'UR%V`#PO7#)%CML`L,3+VQQR1-C;/'"$E/<0L5S4VP% -MQ9E/#D`074-=^M2G,QTNLN.6>VZVJU=+[K70>FO[MN`:R[JUYF(+3KKV!B_\ -M\,07;_SQR",K`QD.-`Z!A(B#`%B'0`800A3Z\(_\A4#DAM%<""0&[YR%0&3PSE8(!)D8/85` -MM(K14`BD!N_AM%*".0&[WR$0'#PSD0(I&T8'81`K(K1/@AD!^^\@T!X -M\,XX"*0'[UR#0'SP3H(%Y)<8I5M`I(I1P`6$=!A-6$`.AE&-!61B&#V"0!:& -M4=(%I&08A>V_WHG9@$@7HX`-B-TPF@*!C`VCYA"($MZ)U8"$#:/>$`C?,(H- -M@6@,H](0B!/>R0R!8`RCQA`(%-X)#(&0"*.Z$(C%,$H+@20,HZX0B.`PB@J! -M'`ZCHA#(YS#*"8&D$J.6$(A0,0H)@0`.HXH0B!;>20B!;.&=?A`(%]Z)!X&4 -M$J,,!(!/,.>2`A.&=*PZ(&-XIN("$$J/[#8A.,6JW@!`, -MHP<+2)`Q2MN`G.&=;PL(&MXIMX!T$J-L#8A-,7H.@>@6HUP-2(\Q^@V!M.&= -MV1"(&]XY#8%D$J/-$(A,,7H,@=@6H\$0B,`PN@N!S.&=M1`('=[Y"H%4$J.I -M$(A+,3H*@<@6HYT02(TQ>@F!Y.&=D1"('MZY"(%$$J.%$(A*,?H'@;@6HZ<. -M2(PQ^NB`U!JC=PX((-[YY8`T$J-'#HA),?KB@*@6HX<+2(LQBK&`Q!JC8PN( -M(=XYL8`D$J.X#8A(,0K:@)@6HX@-2(HQ"M>`M!JCZ!`((][YN(`4$J/@$(A' -M,:H-@8@6H]002(DQZ@R!I!JCR!"()-XI#($$$J.\$(A&,6H+@7@6H[`02(@Q -MJ@J!E!JCI!`()M[I"8'T$:,C#TA%,;KP@&@6H_,.2( -M@$@6HPL+2(4QRMN`9!JCI`U(QS'*V(#$$:-T#4A"K3O!NMO][GC/>WBDAZ,C -M^3T@&0P`#@7R0<%_\_`CS-E/3]3"%\9PA@.IH0`&'Q`=#@#QF/\[`(9(`-(5 -M42!)[#P3!^)$T1?H\P&9HNFM.!`LFGZ+`^FBZ;\XD#":?HP#*:/ISSB0-)I^ -MC0-IH^G?.)`XFGZ.`ZFCZ>\XD#R:?H\#Z:/I_SB00)I^D`,II.D/.9!$FGZ1 -M`VFDZ1\YD$B:?I(#J:3I+SF03)I^DP/II.D_.9!0FGZ4`RFEZ4\YD%2:?I4# -M02*F)TL#$3:FATL#43*FUTL#\4NF%TP#T3:F9TP#@4RFITP#L3FF]TP#$4VF -M-TT#44T%0'D`H$T&@'F(IWDW<@`8)1#GE``M&!#LI``Q"$\`L``U6$\,4(/Y -MU``UV$\.4(,!]0`U6%`04(,)%0$UV%`24(,1-0$U6%$44(,:50$UZ%$64(,B -M=0$U:%(84(,JE0$UZ%(:4(,RM0$U:%,<4(,ZU0$UZ%,>4(-"]0$UV#@UR#90(U*%8G4(-FA0(U2%4J4(-NM0(U*%=0,U*%HX4(.FE0,UJ%HZ4(.NM0,U*%L\4(.VU0,UJ%L^4(,$\P,U2#=` -M4(,G5H,)(P0UJ#%#4(/2A2J:1SJ3HGFP900UB%E'4(.`A00U6%Y)4(/II00U -MB%5+4(/QQ00U6%]-4(/YY00UV%]/4(,!!@4U6&!14(,))@4UV&!34(,11@4U -M6&%54(,99@4UV&%74(,AA@4U6&)94(,II@4UV&);4(,QQ@4U6&-=4(,"XP4U -MV&-?4(-!!@8U.&1A4(,K)@8U*#AC4(/[108U:#=E4(,'8P8U2%MG4(-O@P8U -M*#=I4(-LI08UV&9K4(-+4(/QQ@@U^#B-4(/YY@@UV&^/4(,!!PDU -M6'"14(,))PDUV'"34(,11PDU6'&54(,99PDUV'&74(,AAPDU6'*94(,CIPDU -MN'";4(/SQ@DUN&V=4(/#Y@DUN&J?4(.3!@HUN&>A4(-C)@HUN&2C4(,S1@HU -M^#FE4(,#9@HUN%ZG4(,+@PHUR%NI4(.DI0HUR%BK4(-TQ0ITIW<8FJ$:NJ$< -MRAL'4C,7!``A`@LH,SK#=@LEBEQ&I*(LNJ(NVJ(P^J(R&J,T.J,V6J,X>J,Z -M&@0A$@LF8B1!,&RX8"(\M*-&FJ-(>J1*FJ1,NJ0K&B*R8"*?%Z0`D`LF^J0`,`LFPDVC$R*T8"(OPJ,`4`LFPC)E"@"V8"+N]*;O($_' -M%2+P8$]W"@#QH$][*@_^M*?S(%![2@\&M:?UH%![:@\.M:?W(%%[B@\6M:?Y -ML%%[J@\?M:?[,%)[R@\GM:?]L%)[Z@\OM:?_,%-[ZG<6I*9)`@`\]:8"8"(K -M]*8#8"(=]*8$$#1[6@`F,D1O:@`F(DYJ>@`FHE9JB@`FTEYJF@`F$F=JJ@`F -M4F]JN@`F$DUOR@`F(E9OV@`F4EYOZ@`FDF9J^@`FTFYJ"@$F$G=J&@$FPDQJ -M*@$FXE5O.@$F$EYJ2@$F4F9J6@$FDFYJ:@$FTG9J>@$F@DQOB@$FHE5OF@$F -MTEUJJ@$F$F9JN@$F4FYJR@$FDG9JV@$F,DQJZ@$F8E5O^@$FHEUJ"@(FTF5J -M&@(F$FYJ*@(F4G9J.@(F\DMO2@(F(E5O6@(F8EUJ:@(FDF5J>@(FTFUJB@(F -M$G9JF@(FHDMJJ@(FXE1JN@(F(EUOR@(F4F5JV@(FDFUJZ@(FTG5J^@(F0DMJ -M"@,FHE1JZB^$\Z8R8")1IJ8S8"+5IJ8T8")9IZ8U8"*MI*8V8")&I:8W8"+* -MI:8X8")-IJ8Y8"+1IJ8Z8")5IZ8[8"*I]*8\8")"]:8]8"+&I:8^8"))IJ8_ -M8"+-IJ9`8")1IZ9!8"*E]*9"8"(^]:9#8"+"I:9$8")%IJ9%8"+)IJ9&8")- -MIZ9'8"*A]*9(8"(Z]:9)8"*^I:9*8")!]J9+8"+%IJ9,8"))IZ9-8"*=]*9. -M8"(V]:9/8"*Z]:908"(]]J918"+!IJ928")%IZ938"*9]*948"(R]:958"*V -M]:8@&#![>@4FTFMJB@4F$G1JF@4F4DEOJ@4FXE)ON@4F(EMOR@4F4F-OV@4F -MDFMJZ@4FTG-J^@4F$DEO"@8FHE)O&@8FXEIO*@8F$F-O.@8F4FMO"GD`D'-J -M6@8FTDAO:@8F8E)O>@8FHEIOB@8FTF)OF@8F$FMOJ@8F4G-JN@8FDDAOR@8F -M(E)OV@8F8EIOZ@8FDF)O^@8FTFIO"@@@@FTFEOB@@F$G)OF@@F4D=OJ@@F -MTE!ON@@F(EEOR@@F4F%OV@@FDFEOZ@@FTG%O^@@F$D=O"@DFDE!O&@DFXEAO -M*@DF$F%O.@DF4FEO2@DFDG%O6@DFTD9O:@DF4E!O>@DFHEAOB@DFTF!OF@DF -M$FEOJ@DF4G%ON@DFDD9OR@DF$E!OV@DF8EAOZ@DFDF!O^@DFTFAO"@HF$G%O -M&@HF4D9O*@HFTD]O.@HF(EAO2@HF4F!O6@HFDFAO:@HFTG!O>@HF$D9OB@HF -MDD]OF@HFXE=OJ@HF$F!ON@HF4FAOR@HFDG!OV@HFTD5OZ@HF4D]O^@HFHE=& -MU*%F?=9HG=;LP7$K=>%?=@WRMD^DW:?[1-J`^D^D/:@#1=J&>E"DG:@+1=J,^E"D_:@3 -M1=J2>E%\#0"5RE&DC:D@-=R;2E*D[:DH-=RARE*D3:HP-=RG2E.=;2(XI=@' -MPE/9'2)`I=@\1%2*741(I=C7Q%2*S4U0I=CD1%79S2)8E=TLPU79[4Y@I=CS -M1%:*?4]HI=C[5%[9_4]LE=T#!5?9?5!TE=T+A5>*_5!\I=@3!5C9/2.$I=@< -MA5C972.,E=TD!5F*#3.4I=@LA5G9+3.*+3B#IMB'H3.L'\] -M(_\!C0````4@`32`"%`!%H0&^``!0`0\"!30`G9`#0@#B<00U!D`((,0A`R" -M,^H?S\!_%P1%!($:&``2@1-H`L!J=-S``'``!T("[($0T`$.A!\X`2M@`+B` -M19`(/D$UF`$!@*3Z(`3A@S3!%[@&9>")H$,HZ)M002O8!`2:X06P4,%[()9<@6S$I>L`VHE8$P`L3@#D$'KC`,!L$S.`1K81IT?[@P%^K" -MQG`%W5@W*83`,!@*PQ&R!;N@0/B"!2$"]D`R6!!F(1I<@[9P#>[":4@-JZ$U -MO(8X(HX$3$@AOD(OK#X180!,!&9(8$X1TBQ)VX!D7B@9@T3H0@.)&46`>C -MH.E!+"Z1(L;$T#C0T02NZ2,:V'2L+'LDR.9(^/HD621/+)(9/@BT>-:5(_L\3^* -M2+@(`*A8]VF2%Q)@K,C\:!ZKY)"\DC(R2Q[)$)&Z$)79C3OY&.VDE!X).Q(YJTCTRL/3C)T_$^K&//E)* -MDDD.22C/I*%DBXA22]9(+EF_VD^C#`#O!U)&R049)!LD1_R0$+(P6I'):ITC@>QLK5?Y(E#-@OS))2OL([>2FQI*;$E5FQE00@:VDY -MH&2LG)2E,E@^2SQ)+%5E5J0E!HPXF1EUT4)"Q#T8*=$FQUR70K-=2L.E23@+I^$\G)DAR-Q- -M@7`C\B:*I)K[T&^>S+E9,PVFFI2'FZ<@0$T8(37UY@RLFANR7D+,CADX/V;/ -M0()J,R!0%<=Y"04/WQR5H?-J:L2L63DG)HA$G+@S=^K.W=D8@DSJ!`"K,VK> -MQA,A#B-G['R86)-@UDZ5>3L59T%HG,)S;)X,?6@#C^??I)D`P&9>SEO88]K+ -M0,`JK#,<1D1>Q0?/)9U$GK-3>69/RZDO;R'O?)_P,W[*S[D09+SG5?F4Q;-Z -MRLKK23G7I^V$C0#`=ZI#_$D]`P`_1)>R,SB23JTI.-M@CXDS`X&KA$^R.3Y! -M(>S,0))6$(Z@^*2"F:!O6L\BVC:/:,\8`G$S`.S,L=)$^Z@?_:.`M",$F3T: -M$*+)#P4:)U1RVE`SFD/;H,#PF@``;%9"Z2E&>=79/)Z_HZT&@E@YI,2S@@K1'SDH1^<579Y;T#0[2@F!(P>C4K*0&5)&646#:2$]GC_%6`Z&\H%(I^#K-9RM- -MGA$3EC;0TWE+NZDW_::!-,A`4X$@38VIYR2>B72.+E)FVDF%*0#0I0'AE)K3 -MQXE,4>@U39_9U'\R3P#:8]+,0&`KT]1U!E$Y2D9=*?;DI+<3G"K4A0 -M\:<"`:#.T]:93@LJ-EV@VC2+YAMQ6A#**><!=2>`LME6E*;J1;M,7%G(-`5EEI-A^@]M:('E7VV4VYZ4[NJ5_VJZR_( -M1-6YPE.3J3IEJD#5I`I5E%H05NI$#8=)59D:U!NJ56]G&EVC!\&-4E`XZE)' -M*EHMG3(U`^)1;.4R[PI8/:R(-;%FCR!36`/"Y@BH%=6G_E4L&EA/YR,M")+4 -M&W9.>HI4S2;:S*1L,ZTZ57#P20/`6`T(=*7'R*N!X%6HZD"]H))UKC+2K:I% -M%:MMO:VX-3\$F=6Z5\JJ4FV6LI6=-D\`T%B)*P$5J5DQX&0B` -MQ;62S[Z:7&FG/HVE:C*W:M?MREWM0Y!YKG_%M\K5B_I*K^LV7:N\-2"TUK=* -M-N/J60VN396V-M>X41#DAG2UH-9TJ<)7T2I?NZM__:\`UCP$F3(S$.PK>X6< -M/=6O[M?EJE8W*@``KP$ANA[8>CI>\2E&-:\:%0FFFX&`6.[K*I64"I:\9M7_ -MR34#K(D]L2BV.@29#7M8Q.M[%;%TE<3*T@%;7X]K+PVQ%K:\(E1^"BX*`F/Q -ML-15O\+8V9I04ZR1/;)(EC@$F;8S$'[LA$6GR%7(YM@1NT^YYHHM"!WVR8;4 -M&UM=-VE=!:!W=2`$`#9*$/0J$.55<12VXEBL&F.K[(PF<[K:?]M(D3`%#:R>)B+>J4;;/8]5MN43T+`/BL -MEBV;7%;*LEDBRV.[RT#`+)!NYUJK*6N5*69FKL/VVX#;<&H8@8VTW -MR[%=L]PVHU;6M5IL`P*N?;9^5ELF6_YZ.WM,N1D(H"7;LM)MVVB_K*\5MP`W -MX`I<^@D`[NUG.;>9]L)NVNQ*;@L"MH6WL7;72EMERV/3SD`@+?H6Q"9<'>MO -M.>W`_;@@-^22A2!C<4<+PN6W7E;&,MR"6Q#R+<1-L!N7RJ9:(PD`PJP&(;,# -MP5I$KM$]NDA7*009HAL0VD:?C;@_=^+26T$; -M23&KH0V;F[5U%E!%2T49;HS(&@A6)>-66*G+8$=KTGV[ -M<#?NZH0@L*MJ):_K?;VPMR0$&=,[6RZOZ)RW;;>_4MZ"D'@_[]K-O*.7YO:8 -M<#,0<$OJ1;:,=^HZWMC+?)NO\XT(08;XWA;;FT"!+^NEN;.W(*!>W[MXV6ZW -M;;!(L.P,!-YR?-'MZIVY>O7YJM_URWX'0I`1O[N%^E91ZXM^;V'T+0C&E_NJ -MWJ];?]$H`%"C8A;G"@2=FTKY*J9%N9I6\WY+.*LP!4(#;K\0.`(?W2#S@`'` -M+WFZ,!&WZ)<(_),@/A -M8$!A,CR$,^P5?L-P&-P&&30L$-0P$(ZWMS?YYM[AFOZ,2$"%MDF8_IIA`-!M -M!L+$6,.AMPWOW3C,B!NQIPTRA5@@'.([#'7SL!+6N]YV#A<$.VQ41?"6'<.) -M&`5?WR/88\+.0%@8B-@2"V(W[(A;L2M&L4'&%$^7+0Q3]S``A<0%81)WXC`Z -M@D&Q*B[#&=;F(@D!+&[9<"`1J_XFE,C6]JD)'& -M@P,#!]Y`#(P7L0?FAE@7I,):2_I9U>$JWKNE518'A(718YS*0``8J;CZ=F-O -M6XWKL3U>J$'&'0L$>$R)?;$\5L29>'`0A)+QA_'P/V;&@]AJ#03I$H_G[SP& -MO_!L+882<8?-Q0>#'N_B8]F*-3(-[K2SM,55F(-B- -MALR%E:_'G<@P.2;7TB"3D@7"2L[(H/<7`V3P6Y$+`D8.R>?T$Y/D*"QS!W&V -M&0AC@R77XN_K=F6R4W[*?33('&7S0HM_JBVVLG6C(-QDH,Q9A7)./L@;>`KK -M4`#0=0;">E'*5IDI]U>HS);;L@<-,F59O53ER;J$>3+B(`A)&0EOY+`\BF^A -M,#X1Q'BS@I`"_`F3\;Y=QGRY&=_1/`HO!4)C=LN0.3)?PR#SF`%`V-#&7]DA -M[V2W^XV_)@C6K.)XZY9C@J!).3(ZSJ-Q.2"LEQZC5`8"WT#+=!D30V3)3)MK -MS:8YS+0-`8L)DWU^6F;)N;LW.>AD'& -M.-N7W8Q[>_,M3AP%X34'9Z)<@S-LCXDR`V&_).?JO)S7\G,^S^A9_049\*Q? -MJ+,>MLY863H'!.2\G1&S%.[+8[G:#`2,,9[?*[/H3@Q#^*L,Q`&3'].T!PX_0[H#]N_/&;SJC'>N0;8YZ9H":U1X:RX-#`=.D?K:/\09&YT0"`1 -MF/GW/F3.7'4)[6>^NJ'9LV)2],-@A"PK#231I`;^DY3:?I0Y!1 -M+@/A38?I[GNEW6Z7+@A@FBMK78.LF54T^.TQ3<90XL^6>H#5='=>Q'4Z4DMJ -M]Q!D$K6$$=%Q^CKC:0>#IC-S2[[*)QD`1)N!<#C@])B6TY,Z5:OJ\!!D1K6% -MP=2G^CI;ZIK9J<6TH7:[/:;J#(3/8:IOM7E>U<`Z6&N'(*.K-0RL]M7#U54' -MA%*-HL'R?5;,6I1%!V8"3$T+T$P[(`QMJAV;%?01E-8N -M>J8>8\.L<;GSV1Z"91L!X09TV-BUT#P*5Q[.'MMO\VY._>XU3$%`7/OZ<+]L,ETX`8` -M@YMM*V?9#+&%RT"@&YF["V=7STV[:_=B"#*NV\>8;%H(,_Q8(_MM]"V?9K6K5=T%HW_5[AE9B9XVSP2_< -M-@C46J"BV6L=H>$WZ+M(?F%TK -M;I',N)`=P$T[$B[A3"#(^7"``<05NMWDW -MYDSA*WQ[^^?\S6-]RT`@&$&QR.%^0)[K`).<1..@-A -MS"CR#,W('[DI/^4V(QE!WL)+MUW]OW@5@[]HPKS! -M&[4EO]MI$,ZR2H$PS%&Y,3_F(B'(%',`T$E8^/NNX_U572?NK"N\27#C7IOH -M>D:6UE4N9I!@^!H(-F64BV4DBLS+N3G?"$'FFPN$<.[**?@E)]/+O)E+<0P] -MSD]J^1H(ND6NO]-7SHWC -MKU5&NW-@/E/_N46_Z!0AR#CT`4S0R;=!%^@!(9_/@+O*`+7P!0=`;"GDGI%]NE"_6A#L=[NIZ9 -MZ4+R+O(4" -M@,`>$/1Z8G?AH3K'*!J(/EU]^2O'Z@!TLJOV[<#]D0>9W>YH,#LIU^RN'8!MKY6B7M`Z.VX/:Z#65P>@.,V.9_;'/RT._=;"6<7 -MI:6Q[O!]@`<9]QX0*DEL+^.S_19*\R,]PX,R6W?K?1&NH_9'FT>S>T"8-#T& -M@@T$ES+=[7A\?_"V.\@H>$VSW??YZ9SO!<&^A_(KN0`%`KAD(IZ;&IW8U.!TV:[3WS9YO[GFG:NB=],^T;6\,\96 -M?-+5B/D]'[.#3)X/")'DOO]R.V]9T;IGEN'4W'Y; -M@\(&@DKY\B^9SVMZ5&_YO%[F^>>`("%#037@NF'^*9_ -M]1H[R*AZ6P/J`[*G#PB7/LOG][$,PP9"C&GUFQO6"WN,'61ZO4#X]5*>>!/V -ME3OK`P*KU_6G?BS3L(%0:X`]S1WVV%Y@!YEI+Q"J?;+'WYG=G1I[75/J!_VN -M+_)R32`,&VNOH;.]NP?602;="YM:;Y>YO:\I]^J=RD?K-S^,XWQMW:O6FLY/ -M>4+O`?-HFQ0(!__=*_P<'602/@!H)((^WQ/\?+/?$7V27O2+EDDK]D>?1^7] -M#4."0&P@F!1V7\H7OLD/T`RO((S\;U^UE[U!=_@0']J;=5(,`(C80%`M)+^B -MG_R=KZ6#C,T7"#B?Y;?MX^Y.0[Y`6/D1G,*R<="^V)'80&@Q.9^?\_RIS_`! -M@-,7"%!?Z*_N<%_E?[ZSP?=U_MR?5"8V$&)-U.>J5#_M;^@@0_8%@MG7^MR; -MZZ_5JR]MP/[`%_M/%0#4G(&P;<[^OU?[@#\]!YF]+Q#Z/MR?XG+?P;9]:V/W -ME7WBM_(`&,[K^D2RMA%_;($$L-A!$BM]?Z:`_]\/D($/[!8+M/_STW,*OU=&? -M2)9[FC;WT;[(<[&!8%INO^Y__I(YR"Q_@=#\@3])Q\J]7]PT?G"?^?,^&!L( -M*<;Y0__QSY:#S/<7".'?^COZ!3W]S0L8'0:L0_^;__,3G(S'^! -M4/_5O^O'G.>?NO'^#7WNA:.N6O_W36G.EU_VEP>]0`&!/-&CP''#`0>A0)X`@Z!$EB0\0/J&Q'@ -M<*4"LH`R'TVWT]$Q`X%H(002@53@&Q9D0('^1A)XG1V!`4$0V`0F=3L='C,0 -ME!A38!5H!N9@0888*'!H@5@9%A@02(%?H,NWT_$Q`T&J40:>@7A@^Q5DT($& -M!QOHA:F!`0$9&`?&?P!`RS$0+!QW8!ZH"#I?088AJ'#X@2L7'Q@0V(&#X`4( -M^>5R4AWEQ\MU@`(?YE<`PEDWDL.Q"(Z"D5>0$0H&!(%$"WCW@8!:5,4W`WIB -M-2#K=P.N?RH8MN((!@0+1X^!R`P$&D4B2`K^@B!7D+$+2AR0H$%W"@(`J6`E -M6``B08S,0.!9^(+`8#3X=@49S:#%40PN:,-@0-`+*H/"WWP%R0P$(08T*`V. -M@R)7D/$-:AS7(.94#08$SR`WJ.+U&)3,0%!JB(/D8#TH<`49\:#'D0Z><>=@ -M0!`.NH.#6,HQ$(P<]*`]:!#*80"`0"AR[(.:73X8$,R#`&$PQN\!9O[>2C?G -M77[81Y5()L=!Z!$&6T$&1Q@0]!&JH"?8#79-5I?%1P.*9K(@\(0#AEUY -ME$(8$(P%.Z!0F64&&4B@0,(5!86Z'E?F$*H=1B/@AA0``*C,0=!A-X5,H%L)B -M76%!`!96A>(=5B85NAQ:8?#W#@(`K,Q`$&J$A6-A7?A?!1EQH4`P%Z*%'-[* -MY14*!&=ATC>2>6H9X4G88\`R`T')01?:A8RA=A5D((8"@6+(%\)X*U=>:'.T -MA2^AJI4!YEP;(,_E`:Z"+^`:!&=-2`(!:=@8GH:X59!A&@(`>41)6!BJ>*Z@ -M6D?#Q8(9WPU'"Z9!I15DJ',@0;C,0!!1+(:H87`(3@49O:%`\!M.AOJ>@[4: -MMH81X2+68_`R`X%E`1P*A]2A315D0(<"@72('$Y\6U1Q*'1@AK?A6`;,#`09 -MQG18'9Z'^%B+4!"4A]LAWN=@88=&!WCX_Z%ZQ,Q`T&F8A^AA?MA-!1GUH4!P -M'[:'K*"#-1X*!.RA8.B5V6I68:B&S`P$(0=^J!\^B+-4D+$@"@0-(H`8&KI3 -M_:'3(1\*A3379CB`=88QFC*&_%V((>"`)!"8B!!BBFA+!1DH(@!01[B&\)\E -M&!N"9BNADE8;-GKSH2>51TV(4@<2!,T,!`V%@Z@B#HF\4Y#Q(PH$0:*%Z`1B -M3BWBB]@<,F$``#4S$$@60B*1:"6^95%B04`E*HE@(.9T)&H=&V*"N-AA,P-! -MA5$E7HEH(OP49)")`H&9R"7*@9B3E"@0;(D&(EM'&,:(RV"/P*;^/BMB06!FU@G`F(+77*(!($S`T''X2<"BI1BX11D0(H" -M@:1H*%J"@F)!4"@NBO<;GG@2>HC%F"9(U7&"&*&HJ-+!6?"10-`J5HJP8I'X -M'A4$<02,2`">A#-BNP8+LH0W8NO'(=:"`0"FJ'8@0>C,0)!03(JQ8K(85@$` -MQ:)`<"QNBLM@D/$JSHK&WYUX*[Z%[,Q`X%@@B\IBM[@+!1G9HD"P+4*+)V&0 -MT2S*'6%B6ABJP3,#083!+7J+\&+[$V2PBP*!NT@NJGC@8D$P+H**G)Q)^!;2 -M,P-!I?$NQHL$8UH39`",`H'`>"_Z>```O1@0V(O\(G/G+PYBC9!`D'$,C`5C -MQLBA!!D58T!P,2Z,(1O"&!`HC!'C\2?QN8>78'DW^9UWE5]5)R*>C`$BG,4= -M"00SH\9H,]YF`$#-F#,RA(Y4##C-77RK7Z\X"^:(&5!IU3$"`!E'CP'0#`0% -M!<9X,SZ-UD.0L30*!$TCR!CJZ8QM1+6((*J+BQU!,Q`H%DXCU"@V0A!!AMF8.6)REF-`@#DJ -MCDN?F*@93H0MVLHHY[6,J.++&#IVB<%<'H4<"03#8^IH/$X004;Q"`"D$;8B -MW(@K^HRHW^<(X#E%`AYER/%A*ZQC0%!Q]!@8S4`04)R.QV/XN!X$&=VC0/`] -MOHYDFO+(/#Z)A1Q',Q`8%N"C^"@_,$V2'BCM,:B&CY^8Z@H>AXYP4`M)%`$$2ND$2D;@4`#)%'9`?9"D*/*N&N -M:"-V71K?KX@;YE$N9$`04<:='1D0&!'\I%L'HF8]_$T`T&B,4@6DICD)#E?`34#0<-Q26:2K*1Q$&2@D@*!*OE)8DZ< -M9$#@29*2(Z(/>3J1BH+9&[5#SG$PHRD)9WE&`@$QV4H>DZP:`&!,*I-*),7' -M1+Z":QVO"$7:AD1CSU!:P9(!0 -M!]4,!`&&/$E/'I2S09`Q4`H$!:4^Z4[=DP%!/OE/_HYP(JI'U0P$A89!B5!N -ME*Y!D'%1"@09I4-9Y2V4`4%#.5'VD'YDD8?5#`0)AT;)4;Z4J4&0L5(*!"VE -M2+E6?90!04AY4DZ,$F'DU^_ICO_>165!P%<*EJKB(!9H$`2!!F*I6&Z6 -MD4&0<5D.!)DE9`D`-)8"P6-)6>:-;%K!01`4')HE9^E:,@9!AFHY$+"6HN5G -M*1"$EJ>E\ZCB\9(9G&?8"0Z6-5H>)1>U'J]E<5D;!!G#I4!`%_65N6)_UY71 -MAM,DCBA%ZHC8BFPI$!0E=IF\VR'8)52*7!<%RF5L>A7&C -M74$0V!7=Y7?I7OH%089Z.1"PEZ*E=CD0<)?L(\267Q`$^45[^5[^EWE!D+%? -M#@3]I6@I7PH$].5YN17&C7T&0=!G^)<`9H1)%P09#>9`\&"*E@.F0%!@*IAN -MX2`6$*6&.F&]!D/%A#@0AIFA980H$%R:'F1G>D#XE10A46H2\(]VV -M.*J1>%L>M14-!#LFB>EC:@9!1H^9>D"5S67JEVC9@"YA>%@TYE$GID`07$$0R!54II5I9H8%08:8 -M.1"0F:)EEBD0;)DNII)Y4M47!$%]46:>F7@F5Q!DT)D#@9TI6JJ9`@&;&6=6 -MDWE?GD$0Y!EW9IZI:%X%08:A.1`@FJ(EGRD0^)F#YG19Y/4;!$&_D6@NFIRF -M5!!D8)H#@:8I6CJ:`@&D66EBE6Y>C)D[9H(LXR9H8]:08*9HF$<%1:1'IVEK -M%@9!!JTI$`Q%S.4S*1OZ=]*D54E-6IK69!X%:@H$_4:/<4X0!.?$IGEK/IL] -M09"Q;`X$S:9HJ6L&!+SFJ6E#TGQN!4'@5CB;T&:X210$&=WF0/!MBI;3I@OR -M9>*8J%Y\01#$%^"FN"EO_@1!AKLY$,";HF6Y*1"HF7@*1`,GF4G7`D`M!D$09O1 -M>#Z>H&=&MWD6!)ZG:"EY"@249^89(")! -MJJ71SE-2T7L:7PV!4$&'#00R$%.)SWD5N9`4V=` -M$!`1FUJ4I*)#$`0ZQ#2%!PU#C)H?Q'U^G^!G^%D('4(!@#I0$)B?!L'1>#0> -MGW=E+[1!B)_P9_QI0MR8CB+[:7]F!T'&]3D09)^BI?))>*R;CJ*D<@(-!-J$ -M]@E^OD[>I_RI@"Z@\"?YR0X4!`]H^ED0K)_WYU+I?OY"#&@&"@RA33AGU:GS -M5:`@:-)9@IA`\E<'JG,Z6/JG0,!_YIX!I=$9@KZ@KL&-`*(,!#<#$":#V@P$ -M%%9!HHA9'Z.!>$.HARB*F+4^&H@'#V5CA$HV2*B3`H,NH7+!C5"G$`1U"F1U -M(\0I8I;KN"AB%7D*09"G3%,_*!/JA4H0-T(6.A!LH39H:5,01*'/%E;1IQ`$ -M?0H76M9\H7!H`W$CK*$#01M:AHJA`@$9>H4"`(`*00"HN*%]6!PJB#8/-T(? -M.A#\H64H'2H0V*%[Z*!"$`PJ@.@@*HE2#S>"(SH00*)EJ"$J$""B>ZBA0A`8 -M*I'H)"J*X@LW@B@L*HS:!S>"+SH0`*-EJ"TJ$."B>^BC0A`\*L'H,"J- -MQ@@X*H^>!S>".SH0P*-EJ#DJ$*"C>RBF0A!@*O'H/"J0B@VBH0A"$*B'I2"J33@E0*I4F -M!S>"4SH00*5EJ%$J$""E>ZCF@:9H65WH5"J6/@?BQ`CD`@F.56E!@)7NH:T* -M(A65CJ5P*7!P([2EZ)04&J+X'7\85A&KB%DAPEL:E_ZEN\&-L)=J$'UI&4J7 -M)@EYJ0\T`O$0?BE@ZIC:!C="K2)F,:9EZ&"*)!2F>^A(I$$4$8WI8^J9Q@8W -M@F:*&YE0D>EBFH,"`+R*F'5-=*:?:6O*&MP(J:D&L9J6H:*IHW2:9D$:!#?! -MFKJFO.EI<"/@IDB";EJ&QJ9(PFRZAQ(K8A8YL9OVILRI:+""C$#*:1D*G)X( -MPND>BJR(62S"=0>,T`F6G92ARJD%$IWLHLR)FL0S:*7>JGF(&-X)Y -MJD&@IV7H=:I!@*=[*+0B9KD3Z>EZJI].!C>"?:I!X*=EJ'N*),"G>RBU(F;- -M$_GI?JJ@.@8W@H&J02"H9:A_BB0`J'LHMB)FW1,)ZH*JH28&-X*%JD%@J&6H -M@XHD0*A[J"BD0>P3&>J&JJ(2!C>"B8HDH*AEJ(>*)("H>RBX(F;]$RGJBJJC -M_@4W@HVJ0>"H9:B+>B+`J'LHN2)F#10YZHZJI.H%-X*1JD$@J66HCXHD`*E[ -M*+HB9AT42>J2JJ76!3>"E:I!8*EEJ).*)$"I>RB[(F8M%%GJEJJFP@4W@IFJ -M0:"I9:B7BB2`J7LHO")F/11IZIJJIZX%-X*=JD'@J66HFXHDP*E[*+TB9DT4 -M>>J>JJB:!3>"H:I!(*IEJ)^*)`"J>RB^(F;-"(GJHJJIA@4W@J6J06"J9:BC -MBB1`JGLHOR)F<129ZJ:JJG(%-X*IJD&@JF6HIXHD@*I[*,`B9M4(J>JJJJM> -M!3>"K:I!X*IEJ*N*),"J>RC!(F:1%+GJKJJL2@4W@K&J02"K9:BOBB0`JWLH -MPB)FP0S)ZK*JK38%-X*UJD%@JV6HLXHD0*M[*,,B9K$4V>JVJJXB!3>"N:I! -MH*MEJ+>*)("K>RC$(F;)#.GJNJJO#@4W@KVJ0>"K9:B[BB3`JWLHQ2)FT13Y -MZKZJL/H$-X+!JD$@K&6HOXHD`*Q[*,8B9D6=GJ.[%I8NK!RK5W`C6*P:!,9J -M#]&``$##.@)!K'LHQR)F\10):\?JLM8$-X+*JD&PK&4HR(HDB*R,D<^)58`L -M8M8*T;*^K$`K3'`C\*P:A,]:ALJL2`+-NH>2+&)6!_&S!JU0ZTIP(S"M&H33 -M6H82K4B"T;J'HBQBEL/PM$:M8*M)<"-PK1J$UUJ&4JU(@M6ZA[(L8M;FE+%Z -M8AMKV"JW)@4W`MNJ0;BM(RLL6+(J"2.0V;J'PBQB%O3D@[ZA&O."FQB%32+F!4\#:Z!J.&JN3*LP-,(=+DRKK/AWIJX -M(@F+:]X:36(5.(N8!4-AKIMKZQH4W`BIJP:QNH*N_MW>6KEJ$)^KZ:JSPA.\CVL:R*`LIILW#`"9;*,+%*%5;PM8I:3%\LB";FL+XLB8!5WBYCE;`VSQ.PD>R-$ -MLQK$-)O*'K,:1#+KS.ZQ>XN8]6Y1L]4L('LCA+,:Q#B;RF*S2((V^\UB%7^+ -MF/5PD;/EK!M[(\2S&L0\F\JBLTB".OO.%EPCD,M%S]:S7.R-,+B(60)M*HO/ -M(@GZ[#][N(A9&-<62]`2LS?"0ZM!1+3;ZT&K022T_^SB(F;]70/M1'O#W@@> -MK08!TJ:R%BV2@-'JL5C%XR)F>5XAK4A+PMX(+JT&`=.FLB4MDG#2_K.3BYC5 -M>\6T,NT#>R/TM!K$3YO*UK1(PDW[SUXN8M;V!=0&M?CKC<#4:A!.;2I+U"() -M1NT_N[F(6?G74PO5DJ\WPE:K072UJ>Q4BR14M?_LYR)FD5\2[5<;R`(Y(Q!; -MN[V*M4@"6?O/CBYBUA'FU;JUU>N-@-=J$'IM*JO6:A!R+4O[A8U`/]A>R]<" -MKS?"Z2)F);:I[%^+)`2V_^SJ(F8]86WM8MO%0A4C$&:[O3JV&@1D^\^^+F(6 -M)W;&-K":[4AK,(Q`IJTSN[=:MAJ$9VO8SBYBEBYVVHJPJ:T->R/0MAJ$;>O: -MW@BDK0;1V@JQ&^SM(F:A8IEM;JO:&K<:!'*[O?*V2()O2]RV5UC%[B)F$63) -MK7([T_8-(Q!VN[TRMTB"B.0MQJ$>?O;,0%N9?7O?ZK8#KIA5X+ZW -M^BV2P-\&N(VLV#`"Y66*[8$+MMX(RXN81>&FLL>+@GN:/B]BUEF6W5JX8"U9 -M-@*)N-MKAJM!;+C_[/0B9@%G%2Z)&[3>""ZN!@'CIK(@K@:!XAJVUXN8I9W% -MN#+NRWHC]+@:Q(^;RM:X2,*-^\]N+V(6?0;D!KD=ZXW`Y&H03FXJ2^0B"4;N -M/_N]B%D/VI,+Y2ZL-\*6JT%TN:GLE(LD5+G_[/@B9IUH7NZ7NZ_>"&JN!L'F -MIK)B+I)`YOZSYXN89:&-N&YNZWHCY+D:Q)Z[O<:Y2,*<^\^N+V(6D,;G]KF: -MZXV`Z&H0BN[V"N@B"8*N8?N^B%F!FH'+Z`:O-\*EJT%DNN_MHXLD1+J&[?PB -M9NEI;>ZFJZW>"*:N!H'JIK*>+I(`ZD*XKFSV-`()#E^KJKNDW@CWBYB%ZY:A -MK2Z2\.K^L_N+F,6LI;JZ[JYZ(Q2[&L2QF\KVNAK$K[N'_B](`J^VZ":[%RX` -M0.V>"-;N]LKL(@G.[C\KP(A9#!NRB^VJJC?"N*M!E+NI[+8;`'2[AJT!(V:5 -M;.;NN:NIW@CRK@9![Z:RZBZ2P.[^LPJ,F,6SU;OVKJ)Z(P2\&L3`F\KFNTC" -MOOO/.C!BUM1&\!:\>NJ-`/%J$!)O*HOP(@D*[S\KP8A9:]O$2_&JJ3?"QZM! -MA+RI[,6+)&2\_ZP%(V9M;=?NR!OE8FTC$,R[O9J\2`+*^\]J,&)6ZB;RRKR[ -M+NHV`OF\J:S+JT'8O(:M!R-F`6^:+M`+M=X(2J\&P?2^MSRO!D'T_K,BC)BE -MO?V\3J^.>B-DO1K$UIO*1KU(PM1+Z_ZR)HR81;\UO5VOD`L`I+T:Q-K[WH*] -M2(+8^\^J,&(6!,?VMKTS+]ZK0>B][RWZ@1(V:UL`8!`I>A -M%C"2@`'_LUJ,F-742<`B\%]Z([3`&L0+G,J6P$C"";R'>C%BUD\7\\;`!B]/ -M-P+YP-LK#8PDV,#_K!@C9B%V,#`0/);>"$JP!L$$I[(\L`9!!!NV9HR8Y=DU -MP4[P5'HC9,$:Q!:+)/>"(:P!H$( -MI[)^,.-QFMHQ8I9TIP(61I>(HP)3Z0W -MPBBL093"J>PFC"1TPH:M'R-FN7BF\"D\D-X(LK`&00NGLJHPDL`*_[."C)@E -MY-7"MO`\>B,$PQK$,)S*YL)(PB[\SQHR8A:61PP7P^/HC0`-:Q#2<"J+#",) -MRO`_J\B(65'>-$P-3Z,WPC>L083#J>PUC"1DP_^L(R-F>7F7\#B\H-X([K`& -M`0]OK^8PDH`._[.2C)@5Z,7#\O!^>B/TPQK$/[R]UL-(PCULV%HR8E:N)PX' -MQ+/HC<`0:Q`.<2I+$",)!K%AJ\F(6<_>0PP1CZ(WPD:L073$J>Q$C"14Q/^L -M)R-F(7L>\4<\B=X(*K$&P1*GLB(QDD`2_[.BC)CE[;7$+O$@>B/DQ!K$3IS* -MQL1(PDS\SYHR8M:Z!Q#WQ-CO#3,"*<7;*U",)`C%_ZPJ(V;%?#PQ4PR'W@A6 -ML0:!%:>R2+$&`14;MJZ,F(7T[;U:\3P,`)3%&L19_-YVQ4C"5_S/RC)B5M"7 -M%:?%3.B-0!=K$'9Q*LL6(PEN<>6+5=@R8E;6=Q?CQ3#HC4`8:Q"&<2J[%R,) -M??$_J\N(66_?88P8AZ`WPF2L053&J>QBC"0TQO^L+R-F&7Z6\65<@=X(HK$& -M01JGLIHQDL`9_[/"C)A5_"W%IC$%W"6-0+/Q]IH:(PFK\3]KS(A9OU]I7!NS -MGS?";ZQ!!,>I;&RL0>3&AJTR(V95?\+Q<&Q\W@C.L08!':>RQC&2@!S_L\Z, -MF)7^1QY(W3'&L1WG,I6QTC"=?S/2C-B5O\''H?'H.>-P!YK$.YQ*DL> -M(PGF\3]KS8A9"2!M#!\_P0#`?JQ!],?;ZWR,)-3'_ZPV(V8Q@>_Q?^QWW@@* -ML@;!(*>R`C*20"`;MMZ,F.4%-L@.-@")K$"IR*@LB(PDB\C]KSHA9@N"*S"(CG3?"C:Q!Y,BI[(N,),3( -M_ZPZ(V91@CKRCAQSW@A&L@:!)*>R/C*2`"3_L^Z,F(4(^L=*\B)<"(Y`5_+V -MVB0C"4_R/RO/B%G)8)*<)5N<-\*8K$&4R:ELE:Q!=,F&K3TC9FV#9O*93'#> -M"'*R!D$GI[)J,I+`)O^S^HR8U0[6R7:RO'DC!,H:Q*"_,_Z,V+6 -M/T@H%\KAYHT`*6L0DG(JBR@C"8KR/RO0B%D0X:1,*3^;-\*GK$&$RJGLI8PD -M9,K_K$$C9A&$6/*H;`PGA",0K+R]FLI(`JK\SRHT8A9)&"O+RM4PB30"^RO+(&02P;MA*-F$45-LO.LJ)Y -M(V3+&L2VG,I&RTC"M/S/6C1B5F"(%G?+0NF-@"YK$.KR>PLN(PGB\C^KT8A9 -M>R&WS"Z?F3?"O:Q!Y,NI[+N,),3+@C$`X-&(69*AOKPO6YDWPL&L023,J:R_ -MC"0`S/^L2"-F,8<*\\+\8]X(%K,&@3&GL@XSD@`Q_[,FC9AU'&;,&C.)>2.4 -MS!K$R9S*=LQ(PL?\SZHT8I9VB#*GS!+FC4`S:Q`VR=C.2@#?_LT*-F$4G&LV",SD< -M)8Y`C_-[6S@C"8?S/VO4B%F*(N0<.0^C-\+FK$%TSN]MXZQ!5,X%LU(C9GV* -MGO/G'!$#`*JS!L$ZO[>B,Y)`.A?,3HV8I2D&SJZS8GDCY,X:Q.Z".:S!H$^O[?>,Y(`/O^S7HV8!3&FS^JS -M('HCU,\:Q/W\WK;/2,+[7#"+-6(6R8@_Y\];,0!`0&L0!O1[RS\C"?YSY8M` -MZ[Y(XPC4@Z:R,ZA`4(/NH3Z*F)4U+L\3M/UY(W30&L0'O;WNH&_-:1JEB%EM -MXP$=0C?/`,`*K4&TT.\M"8TDF-"&K9@B9B6.+O0+_8+>"#JT!L%#O[]M%JU!A-$%\Q,Z$*"AVC,; -M/4_>"$&H!C&$8M`XZ!^680PI8A;_>,86H4EH(GV$+M(QBAXM-MX(A+0&84B_ -MMWTTDO!'?[,9AI4B9D&0AS0C[4DKTJ`T;NM(%XPW@B:M07#2[VTDC21,TA+T -M*/V8`@KM0`"@`%`!P@P`E`1``5\`I\`L4`I(0!$``F`(0\`2\$LG`43`$>!+ -M_PIY@A2P*P0!IH(O#05@")7"H<`$@`#/]!-@!1#3=4+W4`5``5``HD`%Q`F6 -M0C<]!20!6$"<,"?XTG8"GJ`G=`]Z`C--!20!0\`4`#=-"E.`+WTH.`$.R1#P -M31,!8<(00$U7`4*`KS`%]-*!@A%@*N5*_]1`=5`M5`_51'51;50? -MU4AU4JU4+]5,=5/M5#_54'54+55/U51U56U57]58=5:M56_57'57[55_U6!U -M6"U6C]5D=5EM5I_5:'5:K5:OU6QU6^U6O]5P=5PM5\_5='5=;5??U7AU7JU7 -M[]5\=5_M5__5@'5@+5@/UH1U86U8']:(=6*M6"_6C'5C[5@_UI!U9"U93]:4 -M=65M65_6F'5FK5EOUIQU9^U9?]:@=6@M6H_6I'5I;5J?UJAU:JU:K]:L=6OM -M6K_6L'5L+5O/UK1U;6U;W]:X=6ZM6^_6O'5O[5O_UL!U<"U<#]?$=7%M7!_7 -MR'5RK5POU\QU<^U6U>G]?H=7JM7J_7['5[[5Z_U_!U?"U?S]?T=7UM7]_7^'5^K5_O -MU_QU?^U?_]<`=H`M8`_8!':!;6`?V`AV@JU@+]@,=H/M8#_8$':$+6%/V!1V -MA6UA7]@8=H:M86_8'':'[6%_V"!VB"UBC]@D=HEM8I_8*':*K6*OV"QVB^UB -4O]@P=HPM8\_8-':-;6/?V#BVW0$` -` -end diff --git a/lib/libarchive/test/test_link_resolver.c b/lib/libarchive/test/test_link_resolver.c deleted file mode 100644 index 032c059..0000000 --- a/lib/libarchive/test/test_link_resolver.c +++ /dev/null @@ -1,205 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static void test_linkify_tar(void) -{ - struct archive_entry *entry, *e2; - struct archive_entry_linkresolver *resolver; - - /* Initialize the resolver. */ - assert(NULL != (resolver = archive_entry_linkresolver_new())); - archive_entry_linkresolver_set_strategy(resolver, - ARCHIVE_FORMAT_TAR_USTAR); - - /* Create an entry with only 1 link and try to linkify it. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test1"); - archive_entry_set_ino(entry, 1); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 1); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Shouldn't have been changed. */ - assert(e2 == NULL); - assertEqualInt(10, archive_entry_size(entry)); - assertEqualString("test1", archive_entry_pathname(entry)); - - /* Now, try again with an entry that has 2 links. */ - archive_entry_set_pathname(entry, "test2"); - archive_entry_set_nlink(entry, 2); - archive_entry_set_ino(entry, 2); - archive_entry_linkify(resolver, &entry, &e2); - /* Shouldn't be altered, since it wasn't seen before. */ - assert(e2 == NULL); - assertEqualString("test2", archive_entry_pathname(entry)); - assertEqualString(NULL, archive_entry_hardlink(entry)); - assertEqualInt(10, archive_entry_size(entry)); - - /* Match again and make sure it does get altered. */ - archive_entry_linkify(resolver, &entry, &e2); - assert(e2 == NULL); - assertEqualString("test2", archive_entry_pathname(entry)); - assertEqualString("test2", archive_entry_hardlink(entry)); - assertEqualInt(0, archive_entry_size(entry)); - - - /* Dirs should never be matched as hardlinks, regardless. */ - archive_entry_set_pathname(entry, "test3"); - archive_entry_set_nlink(entry, 2); - archive_entry_set_filetype(entry, AE_IFDIR); - archive_entry_set_ino(entry, 3); - archive_entry_set_hardlink(entry, NULL); - archive_entry_linkify(resolver, &entry, &e2); - /* Shouldn't be altered, since it wasn't seen before. */ - assert(e2 == NULL); - assertEqualString("test3", archive_entry_pathname(entry)); - assertEqualString(NULL, archive_entry_hardlink(entry)); - - /* Dir, so it shouldn't get matched. */ - archive_entry_linkify(resolver, &entry, &e2); - assert(e2 == NULL); - assertEqualString("test3", archive_entry_pathname(entry)); - assertEqualString(NULL, archive_entry_hardlink(entry)); - - archive_entry_free(entry); - archive_entry_linkresolver_free(resolver); -} - -static void test_linkify_old_cpio(void) -{ - struct archive_entry *entry, *e2; - struct archive_entry_linkresolver *resolver; - - /* Initialize the resolver. */ - assert(NULL != (resolver = archive_entry_linkresolver_new())); - archive_entry_linkresolver_set_strategy(resolver, - ARCHIVE_FORMAT_CPIO_POSIX); - - /* Create an entry with 2 link and try to linkify it. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test1"); - archive_entry_set_ino(entry, 1); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 2); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Shouldn't have been changed. */ - assert(e2 == NULL); - assertEqualInt(10, archive_entry_size(entry)); - assertEqualString("test1", archive_entry_pathname(entry)); - - /* Still shouldn't be matched. */ - archive_entry_linkify(resolver, &entry, &e2); - assert(e2 == NULL); - assertEqualString("test1", archive_entry_pathname(entry)); - assertEqualString(NULL, archive_entry_hardlink(entry)); - assertEqualInt(10, archive_entry_size(entry)); - - archive_entry_free(entry); - archive_entry_linkresolver_free(resolver); -} - -static void test_linkify_new_cpio(void) -{ - struct archive_entry *entry, *e2; - struct archive_entry_linkresolver *resolver; - - /* Initialize the resolver. */ - assert(NULL != (resolver = archive_entry_linkresolver_new())); - archive_entry_linkresolver_set_strategy(resolver, - ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); - - /* Create an entry with only 1 link and try to linkify it. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test1"); - archive_entry_set_ino(entry, 1); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 1); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Shouldn't have been changed. */ - assert(e2 == NULL); - assertEqualInt(10, archive_entry_size(entry)); - assertEqualString("test1", archive_entry_pathname(entry)); - - /* Now, try again with an entry that has 3 links. */ - archive_entry_set_pathname(entry, "test2"); - archive_entry_set_nlink(entry, 3); - archive_entry_set_ino(entry, 2); - archive_entry_linkify(resolver, &entry, &e2); - - /* First time, it just gets swallowed. */ - assert(entry == NULL); - assert(e2 == NULL); - - /* Match again. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test3"); - archive_entry_set_ino(entry, 2); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 2); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Should get back "test2" and nothing else. */ - assertEqualString("test2", archive_entry_pathname(entry)); - assertEqualInt(0, archive_entry_size(entry)); - archive_entry_free(entry); - assert(NULL == e2); - archive_entry_free(e2); /* This should be a no-op. */ - - /* Match a third time. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test4"); - archive_entry_set_ino(entry, 2); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 3); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Should get back "test3". */ - assertEqualString("test3", archive_entry_pathname(entry)); - assertEqualInt(0, archive_entry_size(entry)); - - /* Since "test4" was the last link, should get it back also. */ - assertEqualString("test4", archive_entry_pathname(e2)); - assertEqualInt(10, archive_entry_size(e2)); - - archive_entry_free(entry); - archive_entry_free(e2); - archive_entry_linkresolver_free(resolver); -} - -DEFINE_TEST(test_link_resolver) -{ - test_linkify_tar(); - test_linkify_old_cpio(); - test_linkify_new_cpio(); -} diff --git a/lib/libarchive/test/test_open_failure.c b/lib/libarchive/test/test_open_failure.c deleted file mode 100644 index 0a7632a..0000000 --- a/lib/libarchive/test/test_open_failure.c +++ /dev/null @@ -1,198 +0,0 @@ -/*- - * Copyright (c) 2003-2010 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#define MAGIC 123456789 -struct my_data { - int magic; - int read_return; - int read_called; - int write_return; - int write_called; - int open_return; - int open_called; - int close_return; - int close_called; -}; - -static ssize_t -my_read(struct archive *a, void *_private, const void **buff) -{ - struct my_data *private = (struct my_data *)_private; - assertEqualInt(MAGIC, private->magic); - ++private->read_called; - return (private->read_return); -} - -static ssize_t -my_write(struct archive *a, void *_private, const void *buff, size_t s) -{ - struct my_data *private = (struct my_data *)_private; - assertEqualInt(MAGIC, private->magic); - ++private->write_called; - return (private->write_return); -} - -static int -my_open(struct archive *a, void *_private) -{ - struct my_data *private = (struct my_data *)_private; - assertEqualInt(MAGIC, private->magic); - ++private->open_called; - return (private->open_return); -} - -static int -my_close(struct archive *a, void *_private) -{ - struct my_data *private = (struct my_data *)_private; - assertEqualInt(MAGIC, private->magic); - ++private->close_called; - return (private->close_return); -} - - -DEFINE_TEST(test_open_failure) -{ - struct archive *a; - struct my_data private; - - memset(&private, 0, sizeof(private)); - private.magic = MAGIC; - private.open_return = ARCHIVE_FATAL; - a = archive_read_new(); - assert(a != NULL); - assertEqualInt(ARCHIVE_FATAL, - archive_read_open(a, &private, my_open, my_read, my_close)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.read_called); - assertEqualInt(1, private.close_called); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.read_called); - assertEqualInt(1, private.close_called); - - memset(&private, 0, sizeof(private)); - private.magic = MAGIC; - private.open_return = ARCHIVE_FAILED; - a = archive_read_new(); - assert(a != NULL); - assertEqualInt(ARCHIVE_FAILED, - archive_read_open(a, &private, my_open, my_read, my_close)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.read_called); - assertEqualInt(1, private.close_called); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.read_called); - assertEqualInt(1, private.close_called); - - memset(&private, 0, sizeof(private)); - private.magic = MAGIC; - private.open_return = ARCHIVE_WARN; - a = archive_read_new(); - assert(a != NULL); - assertEqualInt(ARCHIVE_WARN, - archive_read_open(a, &private, my_open, my_read, my_close)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.read_called); - assertEqualInt(1, private.close_called); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.read_called); - assertEqualInt(1, private.close_called); - - memset(&private, 0, sizeof(private)); - private.magic = MAGIC; - private.open_return = ARCHIVE_OK; - private.read_return = ARCHIVE_FATAL; - a = archive_read_new(); - assert(a != NULL); - assertEqualInt(ARCHIVE_OK, - archive_read_support_compression_compress(a)); - assertEqualInt(ARCHIVE_OK, archive_read_support_format_tar(a)); - assertEqualInt(ARCHIVE_FATAL, - archive_read_open(a, &private, my_open, my_read, my_close)); - assertEqualInt(1, private.open_called); - assertEqualInt(1, private.read_called); - assertEqualInt(1, private.close_called); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - assertEqualInt(1, private.open_called); - assertEqualInt(1, private.read_called); - assertEqualInt(1, private.close_called); - - memset(&private, 0, sizeof(private)); - private.magic = MAGIC; - private.open_return = ARCHIVE_FATAL; - a = archive_write_new(); - assert(a != NULL); - assertEqualInt(ARCHIVE_FATAL, - archive_write_open(a, &private, my_open, my_write, my_close)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.write_called); - // Broken in 2.8, fixed in 3.0 - //assertEqualInt(1, private.close_called); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.write_called); - assertEqualInt(1, private.close_called); - - memset(&private, 0, sizeof(private)); - private.magic = MAGIC; - private.open_return = ARCHIVE_FATAL; - a = archive_write_new(); - assert(a != NULL); - archive_write_set_compression_compress(a); - archive_write_set_format_zip(a); - assertEqualInt(ARCHIVE_FATAL, - archive_write_open(a, &private, my_open, my_write, my_close)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.write_called); - // Broken in 2.8, fixed in 3.0 - //assertEqualInt(1, private.close_called); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.write_called); - assertEqualInt(1, private.close_called); - - memset(&private, 0, sizeof(private)); - private.magic = MAGIC; - private.open_return = ARCHIVE_FATAL; - a = archive_write_new(); - assert(a != NULL); - archive_write_set_compression_gzip(a); - assertEqualInt(ARCHIVE_FATAL, - archive_write_open(a, &private, my_open, my_write, my_close)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.write_called); - // Broken in 2.8, fixed in 3.0 - //assertEqualInt(1, private.close_called); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - assertEqualInt(1, private.open_called); - assertEqualInt(0, private.write_called); - assertEqualInt(1, private.close_called); - -} diff --git a/lib/libarchive/test/test_open_fd.c b/lib/libarchive/test/test_open_fd.c deleted file mode 100644 index 7551dd0..0000000 --- a/lib/libarchive/test/test_open_fd.c +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define open _open -#if !defined(__BORLANDC__) -#define lseek _lseek -#endif -#define close _close -#endif - -DEFINE_TEST(test_open_fd) -{ - char buff[64]; - struct archive_entry *ae; - struct archive *a; - int fd; - -#if defined(__BORLANDC__) - fd = open("test.tar", O_RDWR | O_CREAT | O_BINARY); -#else - fd = open("test.tar", O_RDWR | O_CREAT | O_BINARY, 0777); -#endif - assert(fd >= 0); - if (fd < 0) - return; - - /* Write an archive through this fd. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_fd(a, fd)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 0); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * Write a second file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 819200); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Now, read the data back. - */ - assert(lseek(fd, 0, SEEK_SET) == 0); - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_fd(a, fd, 512)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); - assertEqualMem(buff, "12345678", 8); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(819200, archive_entry_size(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - close(fd); - - - /* - * Verify some of the error handling. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - /* FD 100 shouldn't be open. */ - assertEqualIntA(a, ARCHIVE_FATAL, - archive_read_open_fd(a, 100, 512)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} diff --git a/lib/libarchive/test/test_open_file.c b/lib/libarchive/test/test_open_file.c deleted file mode 100644 index 7e6c571..0000000 --- a/lib/libarchive/test/test_open_file.c +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_open_file) -{ - char buff[64]; - struct archive_entry *ae; - struct archive *a; - FILE *f; - - f = fopen("test.tar", "wb"); - assert(f != NULL); - if (f == NULL) - return; - - /* Write an archive through this FILE *. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_FILE(a, f)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 0); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * Write a second file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 819200); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - fclose(f); - - /* - * Now, read the data back. - */ - f = fopen("test.tar", "rb"); - assert(f != NULL); - if (f == NULL) - return; - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_FILE(a, f)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); - assertEqualMem(buff, "12345678", 8); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(819200, archive_entry_size(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - fclose(f); -} diff --git a/lib/libarchive/test/test_open_filename.c b/lib/libarchive/test/test_open_filename.c deleted file mode 100644 index b096afc..0000000 --- a/lib/libarchive/test/test_open_filename.c +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_open_filename) -{ - char buff[64]; - struct archive_entry *ae; - struct archive *a; - - /* Write an archive through this FILE *. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_filename(a, "test.tar")); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 0); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * Write a second file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 819200); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_filename(a, "test.tar", 512)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); - assertEqualMem(buff, "12345678", 8); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(819200, archive_entry_size(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Verify some of the error handling. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_FATAL, - archive_read_open_filename(a, "nonexistent.tar", 512)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - -} diff --git a/lib/libarchive/test/test_pax_filename_encoding.c b/lib/libarchive/test/test_pax_filename_encoding.c deleted file mode 100644 index af0208c..0000000 --- a/lib/libarchive/test/test_pax_filename_encoding.c +++ /dev/null @@ -1,333 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#include - -/* - * Pax interchange is supposed to encode filenames into - * UTF-8. Of course, that's not always possible. This - * test is intended to verify that filenames always get - * stored and restored correctly, regardless of the encodings. - */ - -/* - * Read a manually-created archive that has filenames that are - * stored in binary instead of UTF-8 and verify that we get - * the right filename returned and that we get a warning only - * if the header isn't marked as binary. - */ -static void -test_pax_filename_encoding_1(void) -{ - static const char testname[] = "test_pax_filename_encoding.tar"; - /* - * \314\214 is a valid 2-byte UTF-8 sequence. - * \374 is invalid in UTF-8. - */ - char filename[] = "abc\314\214mno\374xyz"; - struct archive *a; - struct archive_entry *entry; - - /* - * Read an archive that has non-UTF8 pax filenames in it. - */ - extract_reference_file(testname); - a = archive_read_new(); - assertEqualInt(ARCHIVE_OK, archive_read_support_format_tar(a)); - assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, testname, 10240)); - /* - * First entry in this test archive has an invalid UTF-8 sequence - * in it, but the header is not marked as hdrcharset=BINARY, so that - * requires a warning. - */ - failure("Invalid UTF8 in a pax archive pathname should cause a warning"); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualString(filename, archive_entry_pathname(entry)); - /* - * Second entry is identical except that it does have - * hdrcharset=BINARY, so no warning should be generated. - */ - failure("A pathname with hdrcharset=BINARY can have invalid UTF8\n" - " characters in it without generating a warning"); - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &entry)); - assertEqualString(filename, archive_entry_pathname(entry)); - archive_read_finish(a); -} - -/* - * Set the locale and write a pathname containing invalid characters. - * This should work; the underlying implementation should automatically - * fall back to storing the pathname in binary. - */ -static void -test_pax_filename_encoding_2(void) -{ - char filename[] = "abc\314\214mno\374xyz"; - struct archive *a; - struct archive_entry *entry; - char buff[65536]; - char longname[] = "abc\314\214mno\374xyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - ; - size_t used; - - /* - * We need a starting locale which has invalid sequences. - * de_DE.UTF-8 seems to be commonly supported. - */ - /* If it doesn't exist, just warn and return. */ - if (LOCALE_UTF8 == NULL - || NULL == setlocale(LC_ALL, LOCALE_UTF8)) { - skipping("invalid encoding tests require a suitable locale;" - " %s not available on this system", LOCALE_UTF8); - return; - } - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_pax(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_set_bytes_per_block(a, 0)); - assertEqualInt(0, - archive_write_open_memory(a, buff, sizeof(buff), &used)); - - assert((entry = archive_entry_new()) != NULL); - /* Set pathname, gname, uname, hardlink to nonconvertible values. */ - archive_entry_copy_pathname(entry, filename); - archive_entry_copy_gname(entry, filename); - archive_entry_copy_uname(entry, filename); - archive_entry_copy_hardlink(entry, filename); - archive_entry_set_filetype(entry, AE_IFREG); - failure("This should generate a warning for nonconvertible names."); - assertEqualInt(ARCHIVE_WARN, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - /* Set path, gname, uname, and symlink to nonconvertible values. */ - archive_entry_copy_pathname(entry, filename); - archive_entry_copy_gname(entry, filename); - archive_entry_copy_uname(entry, filename); - archive_entry_copy_symlink(entry, filename); - archive_entry_set_filetype(entry, AE_IFLNK); - failure("This should generate a warning for nonconvertible names."); - assertEqualInt(ARCHIVE_WARN, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - /* Set pathname to a very long nonconvertible value. */ - archive_entry_copy_pathname(entry, longname); - archive_entry_set_filetype(entry, AE_IFREG); - failure("This should generate a warning for nonconvertible names."); - assertEqualInt(ARCHIVE_WARN, archive_write_header(a, entry)); - archive_entry_free(entry); - - assertEqualInt(0, archive_write_close(a)); - assertEqualInt(0, archive_write_finish(a)); - - /* - * Now read the entries back. - */ - - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_format_tar(a)); - assertEqualInt(0, archive_read_open_memory(a, buff, used)); - - assertEqualInt(0, archive_read_next_header(a, &entry)); - assertEqualString(filename, archive_entry_pathname(entry)); - assertEqualString(filename, archive_entry_gname(entry)); - assertEqualString(filename, archive_entry_uname(entry)); - assertEqualString(filename, archive_entry_hardlink(entry)); - - assertEqualInt(0, archive_read_next_header(a, &entry)); - assertEqualString(filename, archive_entry_pathname(entry)); - assertEqualString(filename, archive_entry_gname(entry)); - assertEqualString(filename, archive_entry_uname(entry)); - assertEqualString(filename, archive_entry_symlink(entry)); - - assertEqualInt(0, archive_read_next_header(a, &entry)); - assertEqualString(longname, archive_entry_pathname(entry)); - - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - -/* - * Create an entry starting from a wide-character Unicode pathname, - * read it back into "C" locale, which doesn't support the name. - * TODO: Figure out the "right" behavior here. - */ -static void -test_pax_filename_encoding_3(void) -{ - wchar_t badname[] = L"xxxAyyyBzzz"; - const char badname_utf8[] = "xxx\xE1\x88\xB4yyy\xE5\x99\xB8zzz"; - struct archive *a; - struct archive_entry *entry; - char buff[65536]; - size_t used; - - badname[3] = 0x1234; - badname[7] = 0x5678; - - /* If it doesn't exist, just warn and return. */ - if (NULL == setlocale(LC_ALL, "C")) { - skipping("Can't set \"C\" locale, so can't exercise " - "certain character-conversion failures"); - return; - } - - /* If wctomb is broken, warn and return. */ - if (wctomb(buff, 0x1234) > 0) { - skipping("Cannot test conversion failures because \"C\" " - "locale on this system has no invalid characters."); - return; - } - - /* If wctomb is broken, warn and return. */ - if (wctomb(buff, 0x1234) > 0) { - skipping("Cannot test conversion failures because \"C\" " - "locale on this system has no invalid characters."); - return; - } - - /* Skip test if archive_entry_update_pathname_utf8() is broken. */ - /* In particular, this is currently broken on Win32 because - * setlocale() does not set the default encoding for CP_ACP. */ - entry = archive_entry_new(); - if (archive_entry_update_pathname_utf8(entry, badname_utf8)) { - archive_entry_free(entry); - skipping("Cannot test conversion failures."); - return; - } - archive_entry_free(entry); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_pax(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_set_bytes_per_block(a, 0)); - assertEqualInt(0, - archive_write_open_memory(a, buff, sizeof(buff), &used)); - - assert((entry = archive_entry_new()) != NULL); - /* Set pathname to non-convertible wide value. */ - archive_entry_copy_pathname_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFREG); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - archive_entry_copy_pathname_w(entry, L"abc"); - /* Set gname to non-convertible wide value. */ - archive_entry_copy_gname_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFREG); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - archive_entry_copy_pathname_w(entry, L"abc"); - /* Set uname to non-convertible wide value. */ - archive_entry_copy_uname_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFREG); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - archive_entry_copy_pathname_w(entry, L"abc"); - /* Set hardlink to non-convertible wide value. */ - archive_entry_copy_hardlink_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFREG); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - archive_entry_copy_pathname_w(entry, L"abc"); - /* Set symlink to non-convertible wide value. */ - archive_entry_copy_symlink_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFLNK); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assertEqualInt(0, archive_write_close(a)); - assertEqualInt(0, archive_write_finish(a)); - - /* - * Now read the entries back. - */ - - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_format_tar(a)); - assertEqualInt(0, archive_read_open_memory(a, buff, used)); - - failure("A non-convertible pathname should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_pathname_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_pathname(entry)); - - failure("A non-convertible gname should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_gname_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_gname(entry)); - - failure("A non-convertible uname should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_uname_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_uname(entry)); - - failure("A non-convertible hardlink should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_hardlink_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_hardlink(entry)); - - failure("A non-convertible symlink should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_symlink_w(entry)); - assertEqualWString(NULL, archive_entry_hardlink_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_symlink(entry)); - - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &entry)); - - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - -DEFINE_TEST(test_pax_filename_encoding) -{ - test_pax_filename_encoding_1(); - test_pax_filename_encoding_2(); - test_pax_filename_encoding_3(); -} diff --git a/lib/libarchive/test/test_pax_filename_encoding.tar.uu b/lib/libarchive/test/test_pax_filename_encoding.tar.uu deleted file mode 100644 index e7773fd..0000000 --- a/lib/libarchive/test/test_pax_filename_encoding.tar.uu +++ /dev/null @@ -1,118 +0,0 @@ -$FreeBSD$ -begin 644 test_pax_filename_encoding.tar -M4&%X2&5A9&5R+V%B8\R,;6YO6'AY>@`````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````#`P,#8T-"``,#`Q-S4P(``P,#$W-3`@`#`P,#`P,#`P,38V -M(#$P-S8V-C`W,#,V(#`Q-3,P-@`@>``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!U@HR,"!C=&EM -M93TQ,C`U-3,X-C@U"C(P(&%T:6UE/3$R,#4U,S@V,C8*,3<@4T-(24Q9+F1E -M=CTX.`HR,B!30TA)3%DN:6YO/30S,34T-#D*,3@@4T-(24Q9+FYL:6YK/3$* -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````&%B8\R,;6YO6'AY -M>@`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````P -M,#`V-#0@`#`P,3'EZ -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````,#`P-C0T(``P,#$W -M-3`@`#`P,3'EZ"C(P(&-T:6UE -M/3$R,#4U-#$W,S4*,C`@871I;64],3(P-34S.#8R-@HQ-R!30TA)3%DN9&5V -M/3@X"C(R(%-#2$E,62YI;F\]-#,Q-3$R-@HQ."!30TA)3%DN;FQI;FL],0H` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````86)CS(QM;F_\>'EZ```````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````#`P,#8T-"``,#`Q-S4P(``P,#$W-3`@ -M`#`P,#`P,#`P,#`U(#$P-S8V-C`W,#,V(#`Q,S4W,0`@,``````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!U -M7ET='1S ${TMPRPM}/BUILD/file1 -echo "hello" > ${TMPRPM}/BUILD/file2 -echo "hello" > ${TMPRPM}/BUILD/file3 -cat > ${TMPRPM}/SPECS/${NAME}.spec < ${F}.uu - -rm -rf ${TMPRPM} -exit 1 -*/ - -DEFINE_TEST(test_read_format_cpio_svr4_bzip2_rpm) -{ - struct archive_entry *ae; - struct archive *a; - const char *name = "test_read_format_cpio_svr4_bzip2_rpm.rpm"; - int r; - - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r == ARCHIVE_WARN) { - skipping("bzip2 reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_rpm(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("./etc/file1", archive_entry_pathname(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("./etc/file2", archive_entry_pathname(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("./etc/file3", archive_entry_pathname(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - - /* Verify the end-of-archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualString(archive_compression_name(a), "bzip2"); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - diff --git a/lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu b/lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu deleted file mode 100644 index 3e85150..0000000 --- a/lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu +++ /dev/null @@ -1,49 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_cpio_svr4_bzip2_rpm.rpm -M[:ONVP,``````7)P;7-A;7!L92TQ+C`N,"TQ```````````````````````` -M```````````````````````````````````````````!``4````````````` -M````````CJWH`0`````````%````5````#X````'````1````!````$-```` -M!@`````````!```#Z`````0````L`````0```^P````'````,````!````/O -M````!````$`````!,F4X-3)F-39E,#,W83EE.61A9C`````$```1F````!@```GX````!```$;``` -M``8```*``````0``!'0````$```"E`````,```1U````!````J`````#```$ -M=@````@```*L`````P``!'<````$```"Q`````,```1X````!````M`````# -M0P!R<&US86UP;&4`,2XP+C``,0!386UP;&4@9&%T82!O9B!24$T@9FEL=&5R -M(&]F(&QI8F%R8VAI=F4`4V%M<&QE(&1A=&$N`````$L)MWQC=64M9&5S:W1O -M<``````20E-$`%5NFEP,@`Y`&YO87)C:"UR<&TM;&EN=7@````````````````````````` -M`0````$````!`$%30TE)('1E>'0`9&ER96-T;W)Y```````````````````` -M````````````````````/P````?___SP````$$)::#DQ05DF4UFX89DX``!= -M?X!,$`@`*`'_X"(D%``[9(0`(`"2B/50T#0#0`](9!%(C1,0&GJ`R`M@PQRG -M ${TMPRPM}/BUILD/file1 -echo "hello" > ${TMPRPM}/BUILD/file2 -echo "hello" > ${TMPRPM}/BUILD/file3 -cat > ${TMPRPM}/SPECS/${NAME}.spec < ${F}.uu - -rm -rf ${TMPRPM} -exit 1 -*/ - -DEFINE_TEST(test_read_format_cpio_svr4_gzip_rpm) -{ - struct archive_entry *ae; - struct archive *a; - const char *name = "test_read_format_cpio_svr4_gzip_rpm.rpm"; - int r; - - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_rpm(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("./etc/file1", archive_entry_pathname(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("./etc/file2", archive_entry_pathname(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("./etc/file3", archive_entry_pathname(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - - /* Verify the end-of-archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_GZIP); - assertEqualString(archive_compression_name(a), "gzip"); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - diff --git a/lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu b/lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu deleted file mode 100644 index ac29865..0000000 --- a/lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu +++ /dev/null @@ -1,48 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_cpio_svr4_gzip_rpm.rpm -M[:ONVP,``````7)P;7-A;7!L92TQ+C`N,"TQ```````````````````````` -M```````````````````````````````````````````!``4````````````` -M````````CJWH`0`````````%````5````#X````'````1````!````$-```` -M!@`````````!```#Z`````0````L`````0```^P````'````,````!````/O -M````!````$`````!9&9E8V,W,#4T,C@X,V1D-&8P-6%E.#4Y,S6QO861&:6QE -MFEP`#D`;F]A``````````````` -M```````!`````0````$`05-#24D@=&5X=`!D:7)E8W1O@$!@"1O'?9"`(````` -` -end diff --git a/lib/libarchive/test/test_read_format_cpio_svr4c_Z.c b/lib/libarchive/test/test_read_format_cpio_svr4c_Z.c deleted file mode 100644 index 11ac091..0000000 --- a/lib/libarchive/test/test_read_format_cpio_svr4c_Z.c +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { -31,157,144,'0','n',4,132,'!',3,6,140,26,'8','n',228,16,19,195,160,'A',26, -'1',202,144,'q','h','p','F',25,28,20,'a','X',196,152,145,' ',141,25,2,'k', -192,160,'A',163,163,201,135,29,'c',136,'<',201,'2','c','A',147,'.',0,12,20, -248,178,165,205,155,20,27,226,220,201,243,166,152,147,'T',164,4,'I',194,164, -136,148,16,'H',1,'(',']',202,180,169,211,167,'P',163,'J',157,'J',181,170, -213,171,'X',179,'j',221,202,181,171,215,175,'L',1}; - -DEFINE_TEST(test_read_format_cpio_svr4c_Z) -{ - struct archive_entry *ae; - struct archive *a; -/* printf("Archive address: start=%X, end=%X\n", archive, archive+sizeof(archive)); */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - failure("archive_compression_name(a)=\"%s\"", - archive_compression_name(a)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - failure("archive_format_name(a)=\"%s\"", archive_format_name(a)); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_CRC); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - - diff --git a/lib/libarchive/test/test_read_format_empty.c b/lib/libarchive/test/test_read_format_empty.c deleted file mode 100644 index e0fa9a5..0000000 --- a/lib/libarchive/test/test_read_format_empty.c +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { 0 }; - -DEFINE_TEST(test_read_format_empty) -{ - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, archive, 0)); - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); - assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE); - assertA(archive_format(a) == ARCHIVE_FORMAT_EMPTY); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} diff --git a/lib/libarchive/test/test_read_format_gtar_gz.c b/lib/libarchive/test/test_read_format_gtar_gz.c deleted file mode 100644 index 8f12a65..0000000 --- a/lib/libarchive/test/test_read_format_gtar_gz.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { -31,139,8,0,'+','e',217,'D',0,3,211,211,'g',160,'9','0',0,2,'s','S','S',16, -'m','h','n','j',128,'L',195,0,131,161,129,177,177,137,129,137,185,185,161, -'!',131,129,161,129,153,161,'9',131,130,')',237,157,198,192,'P','Z','\\', -146,'X',164,160,192,'P',146,153,139,'W',29,'!','y',152,'G','`',244,'(',24, -5,163,'`',20,12,'r',0,0,226,234,'6',162,0,6,0,0}; - -DEFINE_TEST(test_read_format_gtar_gz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_GZIP); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - diff --git a/lib/libarchive/test/test_read_format_gtar_lzma.c b/lib/libarchive/test/test_read_format_gtar_lzma.c deleted file mode 100644 index f19d0b8..0000000 --- a/lib/libarchive/test/test_read_format_gtar_lzma.c +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * Copyright (c) 2008 Miklos Vajna - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { -0x5d, 0x0, 0x0, 0x80, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, -0x17, 0xb, 0xbc, 0x1c, 0x7d, 0x1, 0x95, 0xc0, 0x1d, 0x4a, 0x46, 0x9c, -0x1c, 0xc5, 0x8, 0x82, 0x10, 0xed, 0x84, 0xf6, 0xea, 0x7a, 0xfe, 0x63, -0x5a, 0x34, 0x5e, 0xf7, 0xc, 0x60, 0xd6, 0x8b, 0xc1, 0x47, 0xaf, 0x11, -0x6f, 0x18, 0x94, 0x81, 0x74, 0x8a, 0xf8, 0x47, 0xcc, 0xdd, 0xc0, 0xd9, -0x40, 0xa, 0xc3, 0xac, 0x43, 0x47, 0xb5, 0xac, 0x2b, 0x31, 0xd3, 0x6, -0xa4, 0x2c, 0x44, 0x80, 0x24, 0x4b, 0xfe, 0x43, 0x22, 0x4e, 0x14, 0x30, -0x7a, 0xef, 0x99, 0x6e, 0xf, 0x8b, 0xc1, 0x79, 0x93, 0x88, 0x54, 0x73, -0x59, 0x3f, 0xc, 0xfb, 0xee, 0x9c, 0x83, 0x49, 0x93, 0x33, 0xad, 0x44, -0xbe, 0x0}; - -DEFINE_TEST(test_read_format_gtar_lzma) -{ - int r; - - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - r = archive_read_open_memory2(a, archive, sizeof(archive), 3); - if (r != ARCHIVE_OK) { - skipping("Skipping LZMA compression check: %s", - archive_error_string(a)); - goto finish; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_LZMA); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - - diff --git a/lib/libarchive/test/test_read_format_gtar_sparse.c b/lib/libarchive/test/test_read_format_gtar_sparse.c deleted file mode 100644 index f6c9d42..0000000 --- a/lib/libarchive/test/test_read_format_gtar_sparse.c +++ /dev/null @@ -1,318 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - - -struct contents { - off_t o; - size_t s; - const char *d; -}; - -struct contents archive_contents_sparse[] = { - { 1000000, 1, "a" }, - { 2000000, 1, "a" }, - { 3145728, 0, NULL } -}; - -struct contents archive_contents_sparse2[] = { - { 1000000, 1, "a" }, - { 2000000, 1, "a" }, - { 3000000, 1, "a" }, - { 4000000, 1, "a" }, - { 5000000, 1, "a" }, - { 6000000, 1, "a" }, - { 7000000, 1, "a" }, - { 8000000, 1, "a" }, - { 9000000, 1, "a" }, - { 10000000, 1, "a" }, - { 11000000, 1, "a" }, - { 12000000, 1, "a" }, - { 13000000, 1, "a" }, - { 14000000, 1, "a" }, - { 15000000, 1, "a" }, - { 16000000, 1, "a" }, - { 17000000, 1, "a" }, - { 18000000, 1, "a" }, - { 19000000, 1, "a" }, - { 20000000, 1, "a" }, - { 21000000, 1, "a" }, - { 22000000, 1, "a" }, - { 23000000, 1, "a" }, - { 24000000, 1, "a" }, - { 25000000, 1, "a" }, - { 26000000, 1, "a" }, - { 27000000, 1, "a" }, - { 28000000, 1, "a" }, - { 29000000, 1, "a" }, - { 30000000, 1, "a" }, - { 31000000, 1, "a" }, - { 32000000, 1, "a" }, - { 33000000, 1, "a" }, - { 34000000, 1, "a" }, - { 35000000, 1, "a" }, - { 36000000, 1, "a" }, - { 37000000, 1, "a" }, - { 38000000, 1, "a" }, - { 39000000, 1, "a" }, - { 40000000, 1, "a" }, - { 41000000, 1, "a" }, - { 42000000, 1, "a" }, - { 43000000, 1, "a" }, - { 44000000, 1, "a" }, - { 45000000, 1, "a" }, - { 46000000, 1, "a" }, - { 47000000, 1, "a" }, - { 48000000, 1, "a" }, - { 49000000, 1, "a" }, - { 50000000, 1, "a" }, - { 51000000, 1, "a" }, - { 52000000, 1, "a" }, - { 53000000, 1, "a" }, - { 54000000, 1, "a" }, - { 55000000, 1, "a" }, - { 56000000, 1, "a" }, - { 57000000, 1, "a" }, - { 58000000, 1, "a" }, - { 59000000, 1, "a" }, - { 60000000, 1, "a" }, - { 61000000, 1, "a" }, - { 62000000, 1, "a" }, - { 63000000, 1, "a" }, - { 64000000, 1, "a" }, - { 65000000, 1, "a" }, - { 66000000, 1, "a" }, - { 67000000, 1, "a" }, - { 68000000, 1, "a" }, - { 69000000, 1, "a" }, - { 70000000, 1, "a" }, - { 71000000, 1, "a" }, - { 72000000, 1, "a" }, - { 73000000, 1, "a" }, - { 74000000, 1, "a" }, - { 75000000, 1, "a" }, - { 76000000, 1, "a" }, - { 77000000, 1, "a" }, - { 78000000, 1, "a" }, - { 79000000, 1, "a" }, - { 80000000, 1, "a" }, - { 81000000, 1, "a" }, - { 82000000, 1, "a" }, - { 83000000, 1, "a" }, - { 84000000, 1, "a" }, - { 85000000, 1, "a" }, - { 86000000, 1, "a" }, - { 87000000, 1, "a" }, - { 88000000, 1, "a" }, - { 89000000, 1, "a" }, - { 90000000, 1, "a" }, - { 91000000, 1, "a" }, - { 92000000, 1, "a" }, - { 93000000, 1, "a" }, - { 94000000, 1, "a" }, - { 95000000, 1, "a" }, - { 96000000, 1, "a" }, - { 97000000, 1, "a" }, - { 98000000, 1, "a" }, - { 99000000, 1, "a" }, - { 99000001, 0, NULL } -}; - -struct contents archive_contents_nonsparse[] = { - { 0, 1, "a" }, - { 1, 0, NULL } -}; - -/* - * Describe an archive with three entries: - * - * File 1: named "sparse" - * * a length of 3145728 bytes (3MiB) - * * a single 'a' byte at offset 1000000 - * * a single 'a' byte at offset 2000000 - * File 2: named "sparse2" - * * a single 'a' byte at offset 1,000,000, 2,000,000, ..., 99,000,000 - * * length of 99,000,001 - * File 3: named 'non-sparse' - * * length of 1 byte - * * contains a single byte 'a' - */ - -struct archive_contents { - const char *filename; - struct contents *contents; -} files[] = { - { "sparse", archive_contents_sparse }, - { "sparse2", archive_contents_sparse2 }, - { "non-sparse", archive_contents_nonsparse }, - { NULL, NULL } -}; - -static void -verify_archive_file(const char *name, struct archive_contents *ac) -{ - struct archive_entry *ae; - int err; - /* data, size, offset of next expected block. */ - struct contents expect; - /* data, size, offset of block read from archive. */ - struct contents actual; - const void *p; - struct archive *a; - - extract_reference_file(name); - - assert((a = archive_read_new()) != NULL); - assert(0 == archive_read_support_compression_all(a)); - assert(0 == archive_read_support_format_tar(a)); - failure("Can't open %s", name); - assert(0 == archive_read_open_filename(a, name, 3)); - - while (ac->filename != NULL) { - struct contents *cts = ac->contents; - - if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) { - assert(0 == archive_read_finish(a)); - return; - } - failure("Name mismatch in archive %s", name); - assertEqualString(ac->filename, archive_entry_pathname(ae)); - - expect = *cts++; - while (0 == (err = archive_read_data_block(a, - &p, &actual.s, &actual.o))) { - actual.d = p; - while (actual.s > 0) { - char c = *actual.d; - if(actual.o < expect.o) { - /* - * Any byte before the expected - * data must be NULL. - */ - failure("%s: pad at offset %d " - "should be zero", name, actual.o); - assertEqualInt(c, 0); - } else if (actual.o == expect.o) { - /* - * Data at matching offsets must match. - */ - assertEqualInt(c, *expect.d); - expect.d++; - expect.o++; - expect.s--; - /* End of expected? step to next expected. */ - if (expect.s <= 0) - expect = *cts++; - } else { - /* - * We found data beyond that expected. - */ - failure("%s: Unexpected trailing data", - name); - assert(actual.o <= expect.o); - archive_read_finish(a); - return; - } - actual.d++; - actual.o++; - actual.s--; - } - } - failure("%s: should be end of entry", name); - assertEqualIntA(a, err, ARCHIVE_EOF); - failure("%s: Size returned at EOF must be zero", name); - assertEqualInt((int)actual.s, 0); -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* libarchive < 1.9 doesn't get this right */ - skipping("offset of final sparse chunk"); -#else - failure("%s: Offset of final empty chunk must be same as file size", name); - assertEqualInt(actual.o, expect.o); -#endif - /* Step to next file description. */ - ++ac; - } - - err = archive_read_next_header(a, &ae); - assertEqualIntA(a, ARCHIVE_EOF, err); - - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} - - -DEFINE_TEST(test_read_format_gtar_sparse) -{ - /* Two archives that use the "GNU tar sparse format". */ - verify_archive_file("test_read_format_gtar_sparse_1_13.tar", files); - verify_archive_file("test_read_format_gtar_sparse_1_17.tar", files); - - /* - * libarchive < 1.9 doesn't support the newer --posix sparse formats - * from GNU tar 1.15 and later. - */ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("read support for GNUtar --posix sparse formats"); -#else - /* - * An archive created by GNU tar 1.17 using --posix --sparse-format=0.1 - */ - verify_archive_file( - "test_read_format_gtar_sparse_1_17_posix00.tar", - files); - /* - * An archive created by GNU tar 1.17 using --posix --sparse-format=0.1 - */ - verify_archive_file( - "test_read_format_gtar_sparse_1_17_posix01.tar", - files); - /* - * An archive created by GNU tar 1.17 using --posix --sparse-format=1.0 - */ - verify_archive_file( - "test_read_format_gtar_sparse_1_17_posix10.tar", - files); - /* - * The last test archive here is a little odd. First, it's - * uncompressed, because that exercises some of the block - * reassembly code a little harder. Second, it includes some - * leading comments prior to the sparse block description. - * GNU tar doesn't do this, but I think it should, so I want - * to ensure that libarchive correctly ignores such comments. - * Dump the file, looking for "#!gnu-sparse-format" starting - * at byte 0x600. - */ - verify_archive_file( - "test_read_format_gtar_sparse_1_17_posix10_modified.tar", - files); -#endif -} - - diff --git a/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu b/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu deleted file mode 100644 index 7b19d67..0000000 --- a/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu +++ /dev/null @@ -1,1370 +0,0 @@ -$FreeBSD$ -begin 644 test_read_format_gtar_sparse_1_13.tar -M``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!UF4],S$T-371E71E71E71E$AE861E``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!UF4],S$T-3$AE861E``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!U``````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!U -MF4].3DP,#`P,#$*,C`@ -M871I;64],3$Y.#(Y,S8P,PHR,"!C=&EM93TQ,3DX,CDS-C`Q"@`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`"XO1TY54W!A``````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````!U``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!U``````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!U -MF4].3DP,#`P,#$*,C`@ -M871I;64],3$Y.#(Y,S8P,PHR,"!C=&EM93TQ,3DX,CDS-C`Q"@`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`"XO1TY54W!A``````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````!U/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1G@0#`6!Z-&!``1`XH$((`"``@4I,$%"%0PD`@`7%%2C -MB@*IF,8"!UR``0O@"!#0B0=V:.212":IY)),-NGDDU!&*>645%9IY952-K%$ -M$E,\8<04('#Y!`@YV&`##"\@\24(1B3!1!%39#$%%45H*$05;A)1A!0@F`#" -MA44,\804#PK8@A0O$&%%H5(4$005@X*`PA`I@!!##CG,`$(1+F3Q1!5.'$%$ -M$&]*2JFEF-X`@A(N0.&H%%TZ\0*K4PR!A)M,)!$JEKSVRJL,!-800PPPW"## -M##+04,,-!((#+`S"$FLLLLHR"P,X!&:K[;8$`O!LM,4>F^RRS1;IZ[GHIJON -MNNRVZ^Z[\,8K+Y/_U;O8/P(2:*"]_/;K[[\`!UR=EDF`T,0;;H#@Q!MV0*CJ -ML3HDJ\.R('RK0!MKI#''&V;,4;$+,+B@:0MO@$!'&7/0T8*"89#QA1EOR-%& -M&'2XH'')80BL\\X\]^SSSV<=6..00!=M]-%()ZWTTDPW[?334$?=&XD!U4BU -MU%AGK?767'?M]==@ARWVV%K/./1`-PZD(X\^`BEDB4,>:+:-`.`8T-H]_A@D -MT26:2/;?@`N^>:<=^[Y -MYZ"'+OKHI)=N^NFHIZ[ZZJRW[OKKL,O_/+,-^_\\]!'+_WTU%=O_?789Z_]]MQW[_WWX(BGK_[Z[+?O_OOPQR___/37;__]^.>O__[\]^___P`,H``'2,`"&O"`]`,` -` -end diff --git a/lib/libarchive/test/test_read_format_iso_2.iso.Z.uu b/lib/libarchive/test/test_read_format_iso_2.iso.Z.uu deleted file mode 100644 index 6851f31..0000000 --- a/lib/libarchive/test/test_read_format_iso_2.iso.Z.uu +++ /dev/null @@ -1,37 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_iso_2.iso.Z -M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$Z408<04Q`!PH,01BCA -MA!16:.&%$!Z404$;>G0@``%\>"`""`#@04$>2)#0!`.)```%!<%8HD`EEF+C -MC:4($)"(!V+HXX]`!BGDD$06:>212":IY)),-NGDDU!&*>645%9II8\R%!@# -M##C$0(,,,6Q)PPP$DI-EF%QZ"::89,)`#H%PQBDGG&=NV>67:(Y9YH?_]>GG -MGX7](R"!!@)JZ*&()JKHHL<="...`AU80:0`!`$B`!=0.@2CG';JZ:>@A@H8 -MGR]>:FI`DP9@*:F9!BCJJ[#&*NNLM#[EXJ,#R3A0C3C:J*.I(0)P:XP`S!@0 -MK[W^RF,`+DY*T*3&%@O`&P@X4($"!I"C[(ZJNI@I09E&6R*UUBJP@+:0@NAJ -MK>RVZ^Z[\$;7;$'0[CIMM==FNZVZPI9*D*XT`M"KK^F&&(`)`%A0D`4&%&0` -MN?F20RF(!`CAP@XQQ*OQQAQW['%S:)3!!AMO*/#QR2BGK/+*G7I;4+CV0FPN -MNL`>..R_T@8\<(X%AX@P!@5AT#!!#^,[\\0!$$#$Q1FS[/334$M]MILM^WVVW#'+??<=-=M]]UXYZWW -MWGSW[???@`N^>:<=^[Y -MYZ"'+OKHI)=N^NFHIZ[ZZJRW[OKKL,O_/+,-^_\\]!'+_WTU%=O_?789Z_]]MQW[_WWX(BGK_[Z[+?O_OOPQR___/37;__]^.>O__[\]^___P`,H``'2,`"&O"`"$R@ -M`A?(P`8Z\($0C*`$)TC!"EKP@AC,H`8WR,$.>O"#(`RA"$=(PA*:\(0H3*$* -M5\C"%KKPA3",H0QG2,,:VO"&.,RA#G?(PQ[Z\(=`#*(0ATC$(AKQB$A,HA*7 -MR,0F.O&)4(RB%*=(Q2I:\8I8S*(6M\C%+GKQBV`,HQC'2,8RFO&,:$RC&M?( -MQC:Z\8UPC*,O.;X`RG.,=)SG*:\YSH3*^,RG/O?)SW[Z\Y\`#:A`!TK0@AKTH`A-J$(7RM"&.O2A -M$(VH1"=*T8I:]*(8S:A&-\K1CGKTHR`-J4A'2M*2FO2D*$VI2E?*TI:Z]*4P -MC:E,9TK3FMKTICC-J4YWRM.>^O2G0`VJ4(=*U*(:]:A(3:I2E\K4ICKUJ5"- -MJE2G2M6J6O6J6,VJ5K?*U:YZ]:M@#:M8QTK6LIKUK&A-JUK7RM:VNO6M<`TG -` -end diff --git a/lib/libarchive/test/test_read_format_iso_Z.c b/lib/libarchive/test/test_read_format_iso_Z.c deleted file mode 100644 index 2d60d41..0000000 --- a/lib/libarchive/test/test_read_format_iso_Z.c +++ /dev/null @@ -1,99 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static void -test1(void) -{ - struct archive_entry *ae; - struct archive *a; - const char *name = "test_read_format_iso.iso.Z"; - - extract_reference_file(name); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_filename(a, name, 512)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); -} - -static -void test2(void) -{ - struct archive_entry *ae; - struct archive *a; - const char *name = "test_read_format_iso_2.iso.Z"; - - extract_reference_file(name); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_filename(a, name, 512)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString(".", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString("A", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString("A/B", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString("C", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString("C/D", archive_entry_pathname(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); -} - -DEFINE_TEST(test_read_format_iso_Z) -{ - test1(); - test2(); -} - - diff --git a/lib/libarchive/test/test_read_format_iso_joliet.iso.Z.uu b/lib/libarchive/test/test_read_format_iso_joliet.iso.Z.uu deleted file mode 100644 index b6ac252..0000000 --- a/lib/libarchive/test/test_read_format_iso_joliet.iso.Z.uu +++ /dev/null @@ -1,66 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_iso_joliet.iso.Z -M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$PDX4056(#@X(,01BBA -MA`)*\403$V:HX8,'X5*0AQX="$``(AZ(``(`6%"0!10DI*)`(@#`04$SHB@0 -MBD8$(,"!`1`@0$`E'KCAD$06:>212":IY)),-NGDDU!&*>645#YY1!%.)#'% -M$TDT$<25(&CY!`@YV&`##"\@8<04(!B1!!-%3)'%%%04@>$04A01!!5/2`$" -M"D.D`$(,.>0P`PA%N)#%$U4X<0010<#Y9Z"#%GI#"S(0:`,(2K@`A9Y2;.G$ -M"YU.,002;R;HZ*2"9@J##9@2>`,(%2Z1!!4@U!D$AE7VZJN3KN8`0Z8TR!!# -M#3+,0`.!!`0[+`S%'IOLLC`00."UV&9+(`#.$FLLLLHR*^2OY)9K[KGHIJON -MNNRVZ^Z[2?XG[V(""$B@@0$Q`4`2`#@!0!4`8`$`"`,73/#!!B=,\!``$`&` -M%``\`4`3"E>,\,4=?EC""T5P%"20`)P(``8%84`R0AH,%*,'!;%L8T`XZLBC -MCR"/*"+&.%NL<\X\[^QSST#_+'301`]M=-%('ZUTTDPO[7334#\M-<9'`-"Q -MO_Q.$?&^$P,0!`!5=TQPUEL3G`,`-J`-``P`?`$`$@`8`8#6!,O-K[X=:YW% -MW`!08777"S_\]]=^2PPQP2@`P'`*!<<`P-EGSU!PQRX`L+?$`/M;M<-?XSVU -MT9\7';K0W4+[[;3,EAXMN-1:J^WKVZI^>KC5C@OO[;CGKOONO/?N^^]'SBO\ -M8?_86Z"(PR>O_/+,-^_\\]!'+_WTU%=O?50'SE@S``,`T(%`!Q*1!,37EV_^ -M^>BGK_[Z[+?O_OOPQT\8\C*.&%#W`GT?@/CDR^___P`,H``'2,`"&O"`"$Q@ -M>P[$LNT9```?`%]`R`"`-`!`#@K,H`8WR,$.>O"#(`RA"$=(PJ'0CV4B>J!` -M(G@@"EH0@R6,H0QG2,,:VO"&.,RA#G<('D34CR`U&DC,=C0BFMG/9G.#P@$" -MX(MW/$P*!0A`(*"`!1($H!U?$T@0VH&_@0R`?D#Z$4$$0`4C:"``#L@1$7ND -MQIFU00`$J``-1$"`(12!`P$@&$'T6)!V]-$,/QQ($&\4-YD548Q!"H`4H"A% -M*EH1BP/98A<%\L6"Z*@@9#0C&MM81$[VZ(UQG",!```'[Q7D>R\+62'7:,02 -M#8!_BXQB(IS0!`2T,`UR<.05LQB0+8IQ($0DR"7'6,8SIM&0;$0F`4`I1SH" -M@`\`"$%!0J#"@1@@1Y6$HP1'M``D!$$*1%#5$ERP@QC$,@"S;$(##H2&,,B! -M#&Q(@QO6H$M2!&(@@2#%+P42S($,$YC%W&0`LDD`;!X(CLP4I26B.L_^"+H$<5EG<6O=`"0N@@2)8"J'^%F*/M"%%^060PE"S8)`E*#;#``$`(`& -M`(0AO11D0P4!X`8`K`$`7ECO0-I+D/=*-+X\`(!^W\!?`)P!`"T`@!H`P&#] -M6K`,`*`#A&6[7_UB.,+]O6\;`(#ARFD8PWC(,(V2NTOD*EOY -MREB67A&DT(X`*(`*A]AM$J#P!4+E(`9[0D(10&"A(2R!S4D@`I@45"J9"$(4P!"G`*PA36[&^F0406&&C56C" -MFI5M*FE#@4^S=G2I3YWJ9]/:2YR^:.6RS.YVN_O=2D%#&=A@4@7`^][XSK>^ -M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W -MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U -MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ -M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ -M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ -MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` -M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ -M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ -MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: -MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X -MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 -M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT -M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 -M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P -(&(_R.(_T:!4` -` -end diff --git a/lib/libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu b/lib/libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu deleted file mode 100644 index 9babf69..0000000 --- a/lib/libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu +++ /dev/null @@ -1,71 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_iso_joliet_long.iso.Z -M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1GA0+@6!Z-&!``1`XH$((`"`!@5I0$%"%@PD`@`<%%2C -MB@*I:$0``B10(@D"!'3B@1T6:>212":IY)),-NGDDU!&*>645%9I991-+)'$ -M%$\8,04(6SX!0@XVV`##"TAX"8(123!1Q!193$%%$1H*446;1!0A!0@F@'!A -M$4,\(<6#`K8@Q0M$6$&H%$4$086@(*`P1`H@Q)!##C.`4(0+63Q1A1-'$!&$ -MFY%.6NFE-X"@A`M0-"H%ETZ\L.H40R#1)A-)@'KEKKSN*@.!.<1`(`XPX!!# -M##7D0"`)O\(0[+#%'IOLL@16:^VU!`+0[+/%1HNLLC"00&2OY)9K[KGHIJON -MNNRVZ^Z[2_XG[V(""$B@@0$9`8`<`)31+P!"`#`%`$0``(+!"!^L<,((#T$P -M`%(`\`0`33"\\,46(VR0B`/E4L(+17`TI)``I`@`.`6!@T%"+`HTXP<%P8QC -M0#KRZ&,`0))<(HD8]YRQST#_+'301`]M=-%('ZUTTDPO[7334#\M==143VUU -MU557O`0`20@L,8)>']SUP!,?G`,`-J`-``P`?`$`$F`/?+"^73,!0,@#9^$U -M%7=3C'#`57`-@-T%AQSQP28T_'#$(3L\<<0%'^QPP2U`W/;#5CPLN>4A!W&U -MU)\W';K3VPK;K;'?+ELZM*A/&RZVL%>K+;"F$]LZN.(:#._NO/?N^^_`!R_\ -M\$K.:_QA_]A;((G'-^_\\]!'+WUQ628!`A5HU`'"$V/0`2$.(!2KP[$Z)`O" -MM@K(X$*!Z\<0A@V9MJ`$""VH\08;:91!1PMLO.'&&?2K0QK(4"GZG6&`YP.! -M"Q;X@C3,X0W3BZ`$)TC!"EK0*;B8P8%JI+.2`<`#`CE0#&0P`QK4P`8WP,$% -M5\C"%KKPA3",H0QG2,,:VO"&CF$>C4I$LX&`,``C+.$)4XC#(AKQB$A,HA*7 -MR,0F.O&)4+S/@6#606=HC(<`B(&V`#`#`-```#50VPT`H,*SL4V+,N"B%\$H -M1C("P(Q9W&(7OQC&M(VQC&N+8QKGR$8[NA&.:%0C'=N(QS/*<8UU!,`=WYC' -M0/(QD8L$Y"$'Z<="ZE&0?53D'QLYR4Q&,H]D`$`:]A7%4IKRE*A,I2I7R%[4@SE"D,WLJ3,3!4`*`1UH00^:T($PU*$$@6A!>%20BMHHHQOM -MZ$Y!*E($D-2D5;TJ`'#QP8*`<&8>].C-M=\RK$M/)UKG@MD%[]*MB^TK6P@/WK7A&[6#*D00XJ96D' -M"C)9@^B+(/K2!0!F1!`1&*`@!A#KCT(HI`78-:TNV$$,UAJ`MKXUKH8-[&D/ -M.UO9#I:VM[5M;!5+V-KR%K>[+6QD`U#9@73@L@,Q`G(%HB]";+8@G@6M:'%& -MVA(M``E!&!2NG+"$U*XVJ*YMP('0$`8YD`%_;EC#4`-`BD`,)!"DF*A`!!#1 -M$LDW(`+@K(R@RM'IDL"_)[5J2=M)X`*+<[U%76@[[@L`^BZ5P0(`(4$\P%^I -M?O2_4\4J2DFPWO:^-[Y-K2]3"9)?Z%;8OP#.ZH`-S.(6N_C%\JJIA'V(TQ[Z -M]YXC8RU!#8I0A0:$H1`6,81G+!`*:[2_&0[P594\X)I:5"#RS.F->VHB'2/8 -MQP`XZD.%W-0G!P2C1[;P6)FL80&3`,9H3K.:UYR9E\6LQF'-,(Z%="`W$T1F -M\]3IA>>\LP#`X[F=_2Q!0IOAZ@;`BMNL)C2I.4QM1O.8S!2F-(.I3$A/4]*6 -MIC0VNWE-;EHST8V.=*6S*6H`_/E@!#D86.DY5CX?NM.*=C2C)PWK4%]ZU)P& -M-:UUG>E:[_K1I+[UIC\-;$Y_DY1IU*_+!#T00E_8T!```!H`$`92AI(-H@1` -M3=?`YFY[^]M!"("YFI,4:A4$4!T<"AAZ5*"8 -M``*,/\$*#7\3"*90!2A`05!46!.D3CZ%)&!A36TZ.)SD1*>1TZGB5$C"$*8` -M!3<%80H'#Y03J!"$(:2<"%L:0L>K(`1<3<'@>S("I'@.J"2P:0B.2L(3G#!R -M3TU\4Q`"^L69[G2H@RE/0[=Z$O0$)JYC/`E-R&X60&"%)S"A"DTX>)YH]6\H -M/"KJD!(ZT8W>=JE+(>XYW[H+[,WXQCO^\4%!0QG8T#\%0/[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ -M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ -MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` -M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ -M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ -MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: -MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X -MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 -M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT -M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 -M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P -M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. -M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L -MV9(N^9(P&9,R.9,T69,V>9,XF9,ZN9,\V9,^^9-`&91".91$691&>91(F91* -MN91,V91.^910&952.9546956>958F95:N95^95@&99B.99D699F>99H -MF99JN99LV99N^99P&9=R.9=T69=V>9=XF9=ZN9=\V9=^^9>`&9B".9B$69B& -4>9B(F9B*N9B,V9B.^9B0&9F2J90` -` -end diff --git a/lib/libarchive/test/test_read_format_iso_joliet_rockridge.iso.Z.uu b/lib/libarchive/test/test_read_format_iso_joliet_rockridge.iso.Z.uu deleted file mode 100644 index fdccb0c..0000000 --- a/lib/libarchive/test/test_read_format_iso_joliet_rockridge.iso.Z.uu +++ /dev/null @@ -1,68 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_iso_joliet_rockridge.iso.Z -M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1G@0+@6!Z-&!``1`XH$((`"`!0590$%"+`HD`@`<%%2C -MB@*I:$0``B10(@D"!'3B@1T6:>212":IY)),-NGDDU!&*>645%9I991-+)'$ -M%$\8,04(6SX!0@XVV`##"TAX"8(123!1Q!193$%%$1H*446;1!0A!0@F@'!A -M$4,\(<6#`K8@Q0M$6$&H%$4$086@(*`P1`H@Q)!##C.`4(0+63Q1A1-'$!&$ -MFY%.6NFE-X"@A`M0-"H%ETZ\L.H40R#1)A-)@'KEKKSN*@.!.<1`(`XQU""# -M##340"`)O\(0[+#%'IOLL@16:^VU!`+0[+,P$&LLLLK"0`*1O99K[KGHIJON -MNNRVZ^Z[\"[YW[R+"2`@@08&9`0`<@!0AK\`"`'`%``0`0`(!R>,\,(*)SQ$ -MP0!(`<`3`#31,,,87YRP02(.A$L)+Q3!T9!"`I`B`!@4A$'*"&DPT(P>%!0S -MC@'IR*./`0!927BQP$ -MUE.#[K3H3V\K;+?1@KNLZ=!^.ZVXV,9>K;;`GNZMM.&.>W"\O/?N^^_`!R_\ -M\,0K2>_QA_US;X$D(N_\\]!'+_WTQ669!`A4H%$'"$^,00>$.%1:@P['ZI`L -M"-LJ((,+!;(?0Q@V9-J"$B"T4$<:9%1:_QGXHP^""P!\01KF\`;J&?"`"$R@ -M`A>X%5QHX$`UVAD`!@"`#@CD0$1(@L08R,$.>O"#(`RA"$=(PA*:\(0HE$SS -M:%2B@%!0(!8,0`8WF,(:VO"&.,RA#G?(PQ[Z\(=`U,^!8B9!`P#@`Q<,"!D` -MD`9^!?&)4(RB%*=(Q2I:\8I8S*(6H;+"F)'(B`)!XH&6V,1^;?&,:$RC&M?( -MQC:Z\8UPC"-[(,%"@MQH(#;KT8^"U$*>#0P*!PB`+]X1,2D4(`"!@`(66!"` -M=GQ.($%HQPL',H`5"HF/`Q%`!`?"`2H8X8$.V)$><]8&!2#@`19H`0E*>!``!!&$%H6I!VW=$,=.6DR/"+H9GO1)4(H29ZLT)2I5R*A@02Q(LUY>,YA]#,``9EC,0R;" -M"4U`P!C3(`=D-O*1`8DD)@4B`$N6:)\!$8`%"=*!:@8@E,#,V3E)J4U7`H`0 -M``A!04(`QH$88*'?%.8"D!"$0>'*"4MPP0YBT,X`O+,)#3@0&L(@!S*P(0UN -M6(,]21&(@02"%``%0#^AF5,!2)0@(3`H0D=)`HQVTY6>B.A$*RJ0BR8TH^ET -M`!.>`*HO*.$)3'#!G+`PTD*Z$YXC.!`;WN"&,[1`#6]X:1GHT`(SI($-96B! -M&\+0AC*X@`YEP`,=W`K7F=94(#?MJ3^C21"?3E2HJ0U6)"@#`XQ^0C2P\ -M#H+1))9(`7!JPD=#VM62-@*>##C0'/+0AI?&U)[M",5`0M&.P0ZVIX^-+&3A -M,04FE(!$'AAK6<^:UC2LM:UOC>M2A.[,$PN48_*S<5^4Y>;%,@=<_1+ -MHG972";Z+FKQ"0!F%N29!"%L)N,;D$Y^\J"*C2YTO5G=!COXP1!N#8!YHP06:VW:?>EV6N]S$+[/-L;*=+66?6F,'`&`. -M`,@#`,A\92`#0,@1#K2@!TWHHPJ"`%74TCUGHP`J6\#*@EL&H*C -MDD!58WO*UIN"T+AU[6YXRQM,>3(WOI.@)S`Y`=BB;D)'LP`"*V"U"DU0=9YH -M)6HH/&K>D"KWN=/M<'I+0>+I8S[K6M\[U -MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ -M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ -M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ -MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` -M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ -M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ -MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: -MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X -MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 -M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT -M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 -M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P -M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. -M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L -.V9(N^9(P&9,R.9,T^8(` -` -end diff --git a/lib/libarchive/test/test_read_format_iso_multi_extent.c b/lib/libarchive/test/test_read_format_iso_multi_extent.c deleted file mode 100644 index 9697a4b..0000000 --- a/lib/libarchive/test/test_read_format_iso_multi_extent.c +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_read_format_iso_multi_extent) -{ - const char *refname = "test_read_format_iso_multi_extent.iso.Z"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_all(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* Retrieve each of the 2 files on the ISO image and - * verify that each one is what we expect. */ - for (i = 0; i < 2; ++i) { - assertEqualInt(0, archive_read_next_header(a, &ae)); - - if (strcmp(".", archive_entry_pathname(ae)) == 0) { - /* '.' root directory. */ - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(262280, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "head--head--head", 16); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else { - failure("Saw a file that shouldn't have been there"); - assertEqualString(archive_entry_pathname(ae), ""); - } - } - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - - diff --git a/lib/libarchive/test/test_read_format_iso_multi_extent.iso.Z.uu b/lib/libarchive/test/test_read_format_iso_multi_extent.iso.Z.uu deleted file mode 100644 index 3ce33dc..0000000 --- a/lib/libarchive/test/test_read_format_iso_multi_extent.iso.Z.uu +++ /dev/null @@ -1,67 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_iso_multi_extent.iso.Z -M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1GB0#0<*%(`-'X48@(D`((````H4I``%"5DPD`@`<%"0 -MC2L*M*(1`0B0```!D"!`0"8>V.&12":IY)),-NGDDU!&*>645%9IY9583LE$ -M$D($(<402"1A11$@)#'%$R#D8(,-,(!@1!),%#%%%E-0482&5TB1A)U29.GG -MGX`&*FB2,A"80PP%WD!@#&PJ"@,)A<)P:**+-DH@"01FJNFF!`(0Z:0Q.,HH -M#(Z28.2@J*:JZJJLMNKJJ[#&*FN5_]6ZF``"+AJB$0#(`4`9OP(@!`!3`$`$ -M`"`@JVRRS"ZK[!#&`B`%`$\`T(2SS6:+K;(&@3C0B"6\4`1'11*9XHHM$J0` -M!@EI,",`'104;XX![=CCCT$."221(6KK[[;_!@SPP`(73/#!!B>,\,(*-\SP -MPPY'#/'$$E=,\<466\P$`$D("T`0T@(`+1(<`V`%`.,FVW&QU2:;`P`DD@B# -MLKQVO/&XQ69!+`!4H&RMLE>$W''/XTZ;,<9('ZUMT@\SK?"GB(9:*:F70DUI -M@98^RNG6F7IJ:-2B9FTJLK.6;?;9:*>M]MILIVWKVX?]DVN!(<)M]]UXYZWW -MWL4EX801:$X1!AT@/#$&X:&"0*`.C.I`*@B?*L!&&F*$(<<8:*1A1QF0NW"# -M"SD0&`8(:O_/+,-^_\\]"#5G>-^T9O_?789Z_]]MQW[_WWX(>O]X'Q#B_^ -M^>BGK_[Z[+?O_OOPQR__5]/'._W\^.>O__[\]^___P`,H`#S`PGJ$01'`[&7 -MCX`DI.&=B%A0.$``?/$.:4FA``$(!!2PP((`M`%D`@E"&_0U$`'<#T@D%(@` -MA#<0#E#!"!H(@`-XM,`@T1!?)&B#`B(```@<@`1#*`('`N"!@A31(.TH2#O< -M8,`6IBB!"+H7`_55I`!(X8(9W&`'/S@0$:8P("8L2(\*LL(;O3"&,Y2B#=68 -MPQWV\(<`X`,`/E`0.N+#1/B(8@U)``@''N!-<7+!#F)P10PFP@E-2,"!S)"& -MU&DQ2($82"#&1I`'5O*+`!``'0GR@3/*\(8,!&60=,A#'Y)`CEXH2"KO2*0\ -MBI*/?@1D$01)2"P>,I&+;&09'DF"2`IDDB>TY+> -M$@"=*$@G$`&!@4``$:\4$9'^"*=9#K*0`;BE(@'`2$=R$)*2I.2W@DG,:!*D -M$\E\)3/=:,H!VO.>^'P+C,(0GL`$KV+("DD@@IQ`,(4J0`$*3Y`" -M%=P45Z\^80I)P(*;NLE6.ME)0U.XTU:ID(0A3`$*<0I"8$$P5B=0(0A#F"L1 -MS#0$KU9!"%N:@E/[!+@^';8(0TC"FX;`U"0\P0EL?4(5OC1+"`663%"X;&8W -M6R:U.E:T2?!IF5#[U20TP4M9`($5R%J%)I!)K5,8@E'#RMFZ-O:QD=UM9W]+ -MV-.Z@*?8S:YVM]L7-)0A#&1H00N\"U[QDC>\X_TN>L]K7O6&X;WPC:]\YTO? -M^7+WOOC-KW[WR]_^^O>_``ZP@`=,X`(;^,`(3K""%\S@!COXP1".L(0G3.$* -M6_C"&,ZPAC?,X0Y[^,,@#K&(1TSB$IOXQ"A.L8I7S.(6N_C%,(ZQC&=,XQK; -M^,8XSK&.=\SC'OOXQT`.LI"'3.0B&_G(2$ZRDI?,Y"8[^_G+8`ZSF,=,YC*;^,ZSGO?,YS[[^<^`#K2@!TWH0AOZT(A.M*(7S>A&._K1D(ZTI"=-Z4I;^M*8 -MSK2F-\WI3GOZTZ`.M:A'3>I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. -MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV -MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ -M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W -MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U -MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ -M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ -M]\`/?FOJ2_SBTY<.86BD>)&O_!8PGPW+3S[TG2_]Z#=2^-C/OO:WS_WN>__[ -MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` -M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ -M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ -MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: -MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X -MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 -M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT -M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 -M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P -M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. -0^9`0&9$2.9$469$6>9%O"``` -` -end diff --git a/lib/libarchive/test/test_read_format_iso_rockridge.iso.Z.uu b/lib/libarchive/test/test_read_format_iso_rockridge.iso.Z.uu deleted file mode 100644 index 218631c..0000000 --- a/lib/libarchive/test/test_read_format_iso_rockridge.iso.Z.uu +++ /dev/null @@ -1,206 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_iso_rockridge.iso.Z -M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1GA0#Q@,A$$/'QT(0``F'H@``@!84)`%$R14P4`B`'!! -M03>R*!"+1@0@0`(GDB!`0"D>V.&12":IY)),-NGDDU!&*>645%9IY9583MG$ -M$DE,\8014X#0Y1,@Y&"##3"\@`28(!B1!!-%3)'%%%04H:$05;Q)1!%2@&`" -M"!<6,<034CPH8`M2O$"$%89*44005!`*`@I#I`!"##GD,`,(1;B0Q1-5.'$$ -M$4'`.6FEEV9Z`PA*N`#%HU)XZ<0+K4XQ!!)O,I&$J%GVZFNO,A"8`PPYR'`# -MIC'4,$.P,)#`[+#%'IM#LLL22`*!V&:K+8$`/$NLL<@JRRP)1OYJ[KGHIJON -MNNRVZ^Z[\,;;Y'_T+O:/@`0:6.^^_/;K[[\`5[=E$B!,48<;!9-B(TX`J!C0#SZ"&0`0NY\XH%30'%` -M`+Z\`X`44A000"!08$%N.T$,%$0[5P\TP-0"^5B0`%08H4$`#O3X8Y!M)+#! -M!`^`0$+GGX=.PA!%2)1*((N."$&QX` -MXHHS7M#C!4E.$.668Z[YW*-[#KKHI$]/`@!P^%Q0B&^[C:#<0>Z>X@!;_QY` -M(DXT@<"!9*0A1^&')R[0XKL/)`#D1-8O$/.79PX^W<_CG/1,!P`Z`$`#!=$` -M%<+`BX#P(@R5^]_U[!:``[@)3B[800S,A[XF).!`9D@#&\H`OP"0(A`#"00I -M]!>0^R6/A0#@G_,D&$"Z5<]T?#A@`A?80``\,(*YFR#O3K0`)`2A4+IRPA(R -MN,'`G2]]#3@0&L(@!S*P(0UN6$,)3YC"%4X.?R>"H0S]%\0:1J]THC,$`$ZA -M,ZJ=XB!FC!R1%""G)B1QB1K\FQ,;D3X&'&@.>6C#%;-8PG:$8B"A:`<84?3" -MR4V!"0LP$0%".,+*]:]'`P"2`$B`24V>T7IK8^-`+O!&@]Q0='(D8AWO*`,F -MFH^/38@B```I2"RN00:%/*1`$KG(18KQD7[T'@`&0(X3B'P,YR#7,()>(5&3R?.E()CA` -M10$AIC$)``!D.D"9^!R@Z!CQS%%*DR#*3&4`MID%.W:3!N`4'"QE20Z#G,8AZS>??4YS*I)U)']%,@I(2C!`5*4(,JL08) -M#`&8'3:KAU7MFY.O= -M`F"^X,6O>(WC65D-"U(S)I:``(3JM`$V^[)5JZ%0J3Z*ZGWQG>^&?:O%#I\W@.[ -MP+0XSK&.=QPS-)2!#6QX@P)X3.0B&_G(2$ZRDI?,Y"8[^_G+8`ZSF,=,YC*;^,ZSGO?,YS[[^<^`#K2@!TWH0AOZT(A.M*(7S>A&._K1D(ZTI"=-Z4I;^M*8 -MSK2F-\WI3GOZTZ`.M:A'3>I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. -MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV -MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ -M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W -MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U -MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ -M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ -M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ -MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` -M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ -M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ -MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: -MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X -MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 -M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT -M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 -M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P -M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. -M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L -MV9(N^9(P&9,R.9,T69,V>9,XF9,ZN9,\V9,^^9-`&91".91$691&>91(F91* -MN91,V91.^910&952.9546956>958F95:N95^95@&99B.99D699F>99H -MF99JN99LV99N^99P&9=R.9=T69=V>9=XF9=ZN9=\V9=^^9>`&9B".9B$69B& -M>9B(F9B*N9B,V9B.^9B0&9F2.9F469F6>9F8F9F:N9F^9F@&9JB.9JD -M69JF>9JHF9JJN9JLV9JN^9JP&9NR.9NT69NV>9NXF9NZN9N\V9N^^9O`&9S" -M.9S$69S&>9S(F9S*N9S,V9S.^9S0&9W2.9W469W6>9W8F9W:N9W^9W@ -M&9[B.9[D69[F>9[HF9[JN9[LV9[N^9[P&9_R.9_T69_V>9_XF9_ZN9_\V9_^ -M^9\`&J`".J`$6J`&>J`(FJ`*NJ`,VJ`.^J`0&J$2.J$46J$6>J$8FJ$:NJ$< -MVJ$>^J$@&J(B.J(D6J(F>J(HFJ(JNJ(LVJ(N^J(P&J,R.J,T6J,V>J,XFJ,Z -MNJ,\VJ,^^J-`&J1".J1$6J1&>J1(FJ1*NJ1,VJ1.^J10&J52.J546J56>J58 -MFJ5:NJ5^J5@&J9B.J9D6J9F>J9HFJ9JNJ9LVJ9N^J9P&J=R.J=T6J=V -M>J=XFJ=ZNJ=\VJ=^^J>`&JB".JB$6JB&>JB(FJB*NJB,VJB.^JB0&JF2.JF4 -M6JF6>JF8FJF:NJF^JF@&JJB.JJD6JJF>JJHFJJJNJJLVJJN^JJP&JNR -M.JNT6JNV>JNXFJNZNJN\VJN^^JO`&JS".JS$6JS&>JS(FJS*NJS,VJS.^JS0 -M&JW2.JW46JW6>JW8FJW:NJW^JW@&J[B.J[D6J[F>J[HFJ[JNJ[LVJ[N -M^J[P&J_R.J_T6J_V>J_XFJ_ZNJ_\VJ_^^J\`&[`".[`$6[`&>[`(F[`*N[`, -MV[`.^[`0&[$2.[$46[$6>[$8F[$:N[$^[$@&[(B.[(D6[(F>[(HF[(J -MN[(LV[(N^[(P&[,R.[,T6[,V>[,XF[,ZN[,\V[,^^[-`&[1".[1$6[1&>[1( -MF[1*N[1,V[1.^[10&[52.[546[56>[58F[5:N[5^[5@&[9B.[9D6[9F -M>[9HF[9JN[9LV[9N^[9P&[=R.[=T6[=V>[=XF[=ZN[=\V[=^^[>`&[B".[B$ -M6[B&>[B(F[B*N[B,V[B.^[B0&[F2.[F46[F6>[F8F[F:N[F^[F@&[JB -M.[JD6[JF>[JHF[JJN[JLV[JN^[JP&[NR.[NT6[NV>[NXF[NZN[N\V[N^^[O` -M&[S".[S$6[S&>[S(F[S*N[S,V[S.^[S0&[W2.[W46[W6>[W8F[W:N[W -M^[W@&[[B.[[D6[[F>[[HF[[JN[[LV[[N^[[P&[_R.[_T6[_V>[_XF[_ZN[_\ -MV[_^^[\`',`"/,`$7,`&?,`(G,`*O,`,W,`._,`0',$2/,$47,$6?,$8G,$: -MO,$_,$@',(B/,(D7,(F?,(HG,(JO,(LW,(N_,(P',,R/,,T7,,V?,,X -MG,,ZO,,\W,,^_,-`',1"/,1$7,1&?,1(G,1*O,1,W,1._,10',52/,547,56 -M?,58G,5:O,5_,5@',9B/,9D7,9F?,9HG,9JO,9LW,9N_,9P',=R/,=T -M7,=V?,=XG,=ZO,=\W,=^_,>`',B"/,B$7,B&?,B(G,B*O,B,W,B._,B0',F2 -M/,F47,F6?,F8G,F:O,F_,F@',JB/,JD7,JF?,JHG,JJO,JLW,JN_,JP -M',NR/,NT7,NV?,NXG,NZO,N\W,N^_,O`',S"/,S$7,S&?,S(G,S*O,S,W,S. -M_,S0',W2/,W47,W6?,W8G,W:O,W_,W@',[B/,[D7,[F?,[HG,[JO,[L -MW,[N_,[P',_R/,_T7,_V?,_XG,_ZO,_\W,_^_,\`'=`"/=`$7=`&?=`(G=`* -MO=`,W=`._=`0'=$2/=$47=$6?=$8G=$:O=$_=$@'=(B/=(D7=(F?=(H -MG=(JO=(LW=(N_=(P'=,R/=,T7=,V?=,XG=,ZO=,\W=,^_=-`'=1"/=1$7=1& -M?=1(G=1*O=1,W=1._=10'=52/=547=56?=58G=5:O=5_=5@'=9B/=9D -M7=9F?=9HG=9JO=9LW=9N_=9P'==R/==T7==V?==XG==ZO==\W==^_=>`'=B" -M/=B$7=B&?=B(G=B*O=B,W=B._=B0'=F2/=F47=F6?=F8G=F:O=F_=F@ -M'=JB/=JD7=JF?=JHG=JJO=JLW=JN_=JP'=NR/=NT7=NV?=NXG=NZO=N\W=N^ -M_=O`'=S"/=S$7=S&?=S(G=S*O=S,W=S._=S0'=W2/=W47=W6?=W8G=W:O=W< -MW=W>_=W@'=[B/=[D7=[F?=[HG=[JO=[LW=[N_=[P'=_R/=_T7=_V?=_XG=_Z -MO=_\W=_^_=\`'N`"/N`$7N`&?N`(GN`*ON`,WN`._N`0'N$2/N$47N$6?N$8 -MGN$:ON$_N$@'N(B/N(D7N(F?N(HGN(JON(LWN(N_N(P'N,R/N,T7N,V -M?N,XGN,ZON,\WN,^_N-`'N1"/N1$7N1&?N1(GN1*ON1,WN1._N10'N52/N54 -M7N56?N58GN5:ON5_N5@'N9B/N9D7N9F?N9HGN9JON9LWN9N_N9P'N=R -M/N=T7N=V?N=XGN=ZON=\WN=^_N>`'NB"/NB$7NB&?NB(GNB*ONB,WNB._NB0 -M'NF2/NF47NF6?NF8GNF:ONF_NF@'NJB/NJD7NJF?NJHGNJJONJLWNJN -M_NJP'NNR/NNT7NNV?NNXGNNZONN\WNN^_NO`'NS"/NS$7NS&?NS(GNS*ONS, -MWNS._NS0'NW2/NW47NW6?NW8GNW:ONW_NW@'N[B/N[D7N[F?N[HGN[J -MON[LWN[N_N[P'N_R/N_T7N_V?N_XGN_ZON_\WN_^_N\`'_`"/_`$7_`&?_`( -MG_`*O_`,W_`.__`0'_$2/_$47_$6?_$8G_$:O_$__$@'_(B/_(D7_(F -M?_(HG_(JO_(LW_(N__(P'_,R/_,T7_,V?_,XG_,ZO_,\W_,^__-`'_1"/_1$ -M7_1&?_1(G_1*O_1,W_1.__10'_52/_547_56?_58G_5:O_5__5@'_9B -M/_9D7_9F?_9HG_9JO_9LW_9N__9P'_=R/_=T7_=V?_=XG_=ZO_=\W_=^__>` -M'_B"/_B$7_B&?_B(G_B*O_B,W_B.__B0'_F2/_F47_F6?_F8G_F:O_F -M__F@'_JB/_JD7_JF?_JHG_JJO_JLW_JN__JP'_NR/_NT7_NV?_NXG_NZO_N\ -MW_N^__O`'_S"/_S$7_S&?_S(G_S*O_S,W_S.__S0'_W2/_W47_W6?_W8G_W: -MO_W__W@'_[B/_[D7_[F?_[HG_[JO_[LW_[N__[P'__R/__T7__V?__X -MG__ZO__\W__^__\`,``*P`%(``N@`3R`"#`!*L`%R``;H`-\@!`P`DK`"4@! -M*Z`%O(`8,`-JP`W(`3N@!_R`(#`$BL`12`)+H`D\@2@P!:K`%<@"6Z`+?($P -M,`;*P!E(`VN@#;R!.#`'ZL`=R`-[H`_\@4`P"`K!(4@$BZ`1/()(,`DJP27( -M!)N@$WR"4#`*2L$I2`6KH!6\@E@P"VK!+<@%NZ`7_()@,`R*P3%(!LN@&3R# -M:#`-JL$UR`;;H!M\@W`P#LK!.4@'ZZ`=O(-X,`_JP3W(!_N@'_R#@#`0"L)! -M2`@+H2$\A(@P$2K"1<@(&Z$C?(20,!)*PDE("2NA);R$F#`3:L)-R`D[H2?\ -MA*`P%(K"44@*2Z$I/(6H,!6JPE7("ENA*WR%L#`6RL)92`MKH2V\A;@P%^K" -M7<@+>Z$O_(7`,!@*PV%(#(NA,3R&R#`9*L-ER`R;H3-\AM`P&DK#:4@-JZ$U -MO(;8,!MJPVW(#;NA-_R&X#`3R/Z#$]JL?U -MR![;HWM\C_`Q/LK'^4@?ZZ-]O(_X,3_JQ_W('_NC?_R/`#)`"L@!22`+I($\ -MD`@R02K(!Z2/ -M_)%`,D@*R2%))(NDD3R22#))*LDER22;I)-\DE`R2DK)*4DEJZ25O))8,DMJ -MR2W));NDE_R28#),BLDQ22;+I)D\DV@R3:K)-#)/ZLD]R2?[I)_\DX`R4`K*04DH"Z6A/)2(,E$JRD7)*!NEHWR4D#)2 -M2LI)22DKI:6\E)@R4VK*3RLMY22_KI;V\E_@R7^K+?Z?O_)W`,W@* -MS^%)/(NG\3R>R#-Y*L_ER3R;I_-\GM`S>DK/Z4D]JZ?UO)[8,WMJS^W)/;NG -M]_R>X#-\BL_Q23[+I_D\G^@S?:K/]4I/ZZD]O:?X-)_JTWW*3_NI/_VG`#6@"M2!2E`+JD$]J`@UH2K4AZI/_:E`-:@*U:%*5(NJ -M43VJ2#6I*M6ERE2;JE-]JE`UJDK5J4I5JZI5O:I8-:MJU:W*5;NJ5_VJ8#6L -MBM6Q2E;+JED]JV@UK:K5M#6OZM6]RE?[ -MJE_]JX`UL`K6P4I8"ZMA/:R(-;$JUL7*6!NK8WVLD#6R2M;)2EDKJV6]K)@U -MLVK6SRZMY/:_H-;VJU_7* -M7MNK>WVO\#6^RM?Y2E_KJWV]K_@UO^K7_ZVO_;7`-M@*VV%+;(NML3VVR#;9 -M*MMERVR;K;-]MM`VVDK;:4MMJZVUO;;8-MMJVVW+;;NMM_VVX#;`NOX3V\B#?Q*M[% -MRW@;K^-]O)`W\DK>R4MY*Z_EO;R8-_-JWLW+>3NOY_V\H#?TBM[12WI+K^D] -MO:@W]:K>UVNO[;V]N#?WZM[=RWM[K^_]O<`W^`K? -MX4M\BZ_Q/;[(-_DJW^7+?)NO\WV^T#?Z2M_I2WVKK_6]OM@W^VK?[[`/_L%`.`@+X2%,A(NP$3["2#@)*^$ES(2; -ML!-^PE`X"DOA*4R%J[`5OL)8.`MKX2W,A;NP%_["8#@,B^$Q3(;+L!D^PV@X -M#:OA-#@/Z^$]S(?[L!_^PX`X$`OB04R( -M"[$A/L2(.!$KXD7,B!NQ(W[$D#@22^))3(DKL26^Q)@X$VOB3/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1GC0+06!Z-&!``1`XH$((`"`!059,$%"%0PD`@`7%%2C -MB@*I:$0``B10(@D"!'3B@1T6:>212":IY)),-NGDDU!&*>645%9I991-+)'$ -M%$\8,04(6SX!0@XVV`##"TAX"8(123!1Q!193$%%$1H*446;1!0A!0@F@'!A -M$4,\(<6#`K8@Q0M$6$&H%$4$086@(*`P1`H@Q)!##C.`4(0+63Q1A1-'$!&$ -MFY%.6NFE-X"@A`M0-"H%ETZ\L.H40R#1)A-)@'KEKKSN*@.!.<10H`PQR%## -MKV;"0,*O,`0[;+''PI`L"016:^VU!`+`K+/%0HLL@200V>NXY)9K[KGHIJON -MNNRVZ^Z2_\6[V#\"$FB@O/CFJ^^^_/9;799)@-#$&VZ`\,08=%0J@\(Z'*N# -MM"!LJX`,+A18<0QAV)"IH2"T4$<:9%3:\1D@1PR""RB_D,8<;_CK\LLPQRSS -MS&G=0L^!-0HIT```9"#0@40D(07-1!=M]-%()ZWTTDPW[?334+]&8D`UDLBS -M0#X'$/3047?M]==@ARWVV&27;?;9:"<-"8TV`H!C0#KRZ&,`0.I,&VP3=.%#EQSHAT0^3IKJL!'X2\"!YI"'-L3`CH@+Q4!"T0X_ -MFJ@@/"J(`"(Y24G"8PI,$(.)`K`%*_KREV'`(@3I41!Z=*$@77CD.VHI2;\9 -MY)+KTV06FD"Q^=4/E$T0)0!(V089H+(=JA0(*UWI2D`"0`#+9.8[<*E+$_42 -MF/"4HC`)@L/(!<\+!?'"(]W!S'^XPY)IQ*0TFS`#3PH.F]KDY@R^&!``40E*0(QD$"0@IRP -M-*<`P$>0#1B2>KTC@2*UISK\+0"E_U,I2P7B4I@2)):4NR!!.G!31>Z4D:8# -M`/X4`-3^";6E+X5H3&4)1()\H*EI?&KJ3(?+(9"(!QJ5(5@'X",!+'*L;]T> -M`'!)!!+U(*UJU=PA`\#6<\95=3PEJYM(Y`.\YG5Z.^JK6P/[UZB2]+&0C:QD -M$W*[00ZDC+M#8TY_)Z0#U8]X=SQ>0!@GTXA2SK)8`VM.&*B1A"'ES4Q"FP-U` -M.8$*01B"?X-&*_E600BXFL)V]V0$2.4-4$E@TQ`+ISB).@)3"]N;Q*:$`0I9`$$5G@"$ZK0!.[FB592J.ZC2`PI"V-8 -MPT`NL12([&`7NZ"Y8`ZSF,>L'S24@0UL>$.E:C`#!9#YS7".LYSG3.,[S>\R,9C7'X%ANUK.@!TWH0AOZT(A.M*(7S6BO\#G-:XY!H!M-Z4I;^M*8 -MSK2F-\WI3GOZTZ`.M:A'3>I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. -MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV -MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ -M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W -MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U -MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ -M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ -M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ -MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` -M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ -M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ -MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: -MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X -MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 -(>(F8F(F:^!,` -` -end diff --git a/lib/libarchive/test/test_read_format_iso_rockridge_new.iso.Z.uu b/lib/libarchive/test/test_read_format_iso_rockridge_new.iso.Z.uu deleted file mode 100644 index dd013ff..0000000 --- a/lib/libarchive/test/test_read_format_iso_rockridge_new.iso.Z.uu +++ /dev/null @@ -1,208 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_iso_rockridge_new.iso.Z -M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1GA0#Q@,A$$/'QT(0``F'H@``@!84)`%$R14P4`B`'!! -M03>R*!"+1@0@0`(GDB!`0"D>V.&12":IY)),-NGDDU!&*>645%9IY9583MG$ -M$DE,\8014X#0Y1,@Y&"##3"\@`28(!B1!!-%3)'%%%04H:$05;Q)1!%2@&`" -M"!<6,<034CPH8`M2O$"$%89*44005!`*`@I#I`!"##GD,`,(1;B0Q1-5.'$$ -M$4'`.6FEEV9Z`PA*N`#%HU)XZ<0+K4XQ!!)O,I&$J%GVZFNO,A"8`PPYR'"# -M##/$,,.R!)(0++'$&HNLLLS"0`*!V&:K+8$`/#MLL<M]MI,0V(CC@#H&!"//@(9@)`^GWC@ -M%%`<$(`O[P`@A10%!!`(%%BP$$`[00P41#M:#S2`U0+Y6)``/0]T`15&:!"` -M`SW^&&0;"6QP00,AD$"ZZ:B3,$01'`2004&S&]1.0>VX\39!.0Y$M^AW#WDB -MD2@.7OCAB2_>N$"/1_XSY40*/Q#F.'+N.>AUCU[ZZ:FOSCT)`.`1=$$ARATW -M@MD'GW<``WAM?`").-$$`@>2D88B1:`A"`42E=.6`()34@X^,FO`0="0QCD0`8VI,$-:X"A#&EH -MP\L%<(?3\^%`@'@](C+0@T9,G2,``(]_^/&/\#B('2M')`7(J0E8U&()!=?% -M1LB/`0>:0Q[:8$8TPK`=H1A(*-KQQC?>4`!]_*,?X3$%)BS`1`1@H0L1B+T! -M`$D`=W0E#E6WO=9)`@#O$*4?`V<0(X(@BBE:P"$3B;$2OL^130`C`"1)R3.N -M00:7S*1`-ME)'7XRE[I\1RD=H**`#(`.;8!#0%B91UH^T)S?HP0`W*'+?[CC -M(*3#@`,*<`)@$DF864#DKI8P@RT>\XN1G&0EUS"#:&J2DSKTY.78J4MWE!(" -MW03`-\-)`(&0LY;=PR@Z6V<)`+2CG;?K92U_2<@I#G.?-/!G(P&Z3($ZDP8& -MG29""8(B:U[NH[IL1RDE<*"*#JFB$@6G.`%PT7.6LYP=94<[V2%(#Y8T`/C4 -M9Q9KH-+"(5.9S!QH#6(:$&HFU*8\5*HNV5'*"!SHAJEL81E8V2-9PK*MK]PH -M!#NZCG:N`YX)D"<][6G2?";2!E4-P%4#VDPTVH"K`/`J317*P[KJA$ -MAPI4H@;1`4?5:#G9AA[=&7!KY]L1^J`HO"(Q\GB77%Y`'O=)QD[OLP'!`%OQ -MJ%F-`D!WF1-([T1KQ](2+P#O0Y[^5`N`YA5DHVA$^<5``5#@%<*20!"E_`5`YB`"DD%`$$&!K"$M";!"(>5$YWL9#`[ -MU9<*21@"W^`4A"F<=U!.H$(0AH!@HMFJOU40@JZF8-X^&4%2?!-4$MPT!$@E -MX0E.,!BHYMLI"'GXOBE><8O%M*<0SS@)?!)3CO&;A"98,0L@L,(3F%"%)IQW -M3[;R+A0BY6))@5C$)%;RBZ7@9`SCV`763;.:U\SFFZ&A#&Q@PQL4T.8ZV_G. -M>,ZSGO?,YS[[^<^`#K2@!TWH0AOZT(A.M*(7S>A&._K1D(ZTI"=-Z4I;^M*8 -MSK2F-\WI3GOZTZ`.M:A'3>I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. -MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV -MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ -M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W -MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U -MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ -M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ -M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ -MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` -M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ -M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ -MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: -MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X -MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 -M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT -M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 -M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P -M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. -M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L -MV9(N^9(P&9,R.9,T69,V>9,XF9,ZN9,\V9,^^9-`&91".91$691&>91(F91* -MN91,V91.^910&952.9546956>958F95:N95^95@&99B.99D699F>99H -MF99JN99LV99N^99P&9=R.9=T69=V>9=XF9=ZN9=\V9=^^9>`&9B".9B$69B& -M>9B(F9B*N9B,V9B.^9B0&9F2.9F469F6>9F8F9F:N9F^9F@&9JB.9JD -M69JF>9JHF9JJN9JLV9JN^9JP&9NR.9NT69NV>9NXF9NZN9N\V9N^^9O`&9S" -M.9S$69S&>9S(F9S*N9S,V9S.^9S0&9W2.9W469W6>9W8F9W:N9W^9W@ -M&9[B.9[D69[F>9[HF9[JN9[LV9[N^9[P&9_R.9_T69_V>9_XF9_ZN9_\V9_^ -M^9\`&J`".J`$6J`&>J`(FJ`*NJ`,VJ`.^J`0&J$2.J$46J$6>J$8FJ$:NJ$< -MVJ$>^J$@&J(B.J(D6J(F>J(HFJ(JNJ(LVJ(N^J(P&J,R.J,T6J,V>J,XFJ,Z -MNJ,\VJ,^^J-`&J1".J1$6J1&>J1(FJ1*NJ1,VJ1.^J10&J52.J546J56>J58 -MFJ5:NJ5^J5@&J9B.J9D6J9F>J9HFJ9JNJ9LVJ9N^J9P&J=R.J=T6J=V -M>J=XFJ=ZNJ=\VJ=^^J>`&JB".JB$6JB&>JB(FJB*NJB,VJB.^JB0&JF2.JF4 -M6JF6>JF8FJF:NJF^JF@&JJB.JJD6JJF>JJHFJJJNJJLVJJN^JJP&JNR -M.JNT6JNV>JNXFJNZNJN\VJN^^JO`&JS".JS$6JS&>JS(FJS*NJS,VJS.^JS0 -M&JW2.JW46JW6>JW8FJW:NJW^JW@&J[B.J[D6J[F>J[HFJ[JNJ[LVJ[N -M^J[P&J_R.J_T6J_V>J_XFJ_ZNJ_\VJ_^^J\`&[`".[`$6[`&>[`(F[`*N[`, -MV[`.^[`0&[$2.[$46[$6>[$8F[$:N[$^[$@&[(B.[(D6[(F>[(HF[(J -MN[(LV[(N^[(P&[,R.[,T6[,V>[,XF[,ZN[,\V[,^^[-`&[1".[1$6[1&>[1( -MF[1*N[1,V[1.^[10&[52.[546[56>[58F[5:N[5^[5@&[9B.[9D6[9F -M>[9HF[9JN[9LV[9N^[9P&[=R.[=T6[=V>[=XF[=ZN[=\V[=^^[>`&[B".[B$ -M6[B&>[B(F[B*N[B,V[B.^[B0&[F2.[F46[F6>[F8F[F:N[F^[F@&[JB -M.[JD6[JF>[JHF[JJN[JLV[JN^[JP&[NR.[NT6[NV>[NXF[NZN[N\V[N^^[O` -M&[S".[S$6[S&>[S(F[S*N[S,V[S.^[S0&[W2.[W46[W6>[W8F[W:N[W -M^[W@&[[B.[[D6[[F>[[HF[[JN[[LV[[N^[[P&[_R.[_T6[_V>[_XF[_ZN[_\ -MV[_^^[\`',`"/,`$7,`&?,`(G,`*O,`,W,`._,`0',$2/,$47,$6?,$8G,$: -MO,$_,$@',(B/,(D7,(F?,(HG,(JO,(LW,(N_,(P',,R/,,T7,,V?,,X -MG,,ZO,,\W,,^_,-`',1"/,1$7,1&?,1(G,1*O,1,W,1._,10',52/,547,56 -M?,58G,5:O,5_,5@',9B/,9D7,9F?,9HG,9JO,9LW,9N_,9P',=R/,=T -M7,=V?,=XG,=ZO,=\W,=^_,>`',B"/,B$7,B&?,B(G,B*O,B,W,B._,B0',F2 -M/,F47,F6?,F8G,F:O,F_,F@',JB/,JD7,JF?,JHG,JJO,JLW,JN_,JP -M',NR/,NT7,NV?,NXG,NZO,N\W,N^_,O`',S"/,S$7,S&?,S(G,S*O,S,W,S. -M_,S0',W2/,W47,W6?,W8G,W:O,W_,W@',[B/,[D7,[F?,[HG,[JO,[L -MW,[N_,[P',_R/,_T7,_V?,_XG,_ZO,_\W,_^_,\`'=`"/=`$7=`&?=`(G=`* -MO=`,W=`._=`0'=$2/=$47=$6?=$8G=$:O=$_=$@'=(B/=(D7=(F?=(H -MG=(JO=(LW=(N_=(P'=,R/=,T7=,V?=,XG=,ZO=,\W=,^_=-`'=1"/=1$7=1& -M?=1(G=1*O=1,W=1._=10'=52/=547=56?=58G=5:O=5_=5@'=9B/=9D -M7=9F?=9HG=9JO=9LW=9N_=9P'==R/==T7==V?==XG==ZO==\W==^_=>`'=B" -M/=B$7=B&?=B(G=B*O=B,W=B._=B0'=F2/=F47=F6?=F8G=F:O=F_=F@ -M'=JB/=JD7=JF?=JHG=JJO=JLW=JN_=JP'=NR/=NT7=NV?=NXG=NZO=N\W=N^ -M_=O`'=S"/=S$7=S&?=S(G=S*O=S,W=S._=S0'=W2/=W47=W6?=W8G=W:O=W< -MW=W>_=W@'=[B/=[D7=[F?=[HG=[JO=[LW=[N_=[P'=_R/=_T7=_V?=_XG=_Z -MO=_\W=_^_=\`'N`"/N`$7N`&?N`(GN`*ON`,WN`._N`0'N$2/N$47N$6?N$8 -MGN$:ON$_N$@'N(B/N(D7N(F?N(HGN(JON(LWN(N_N(P'N,R/N,T7N,V -M?N,XGN,ZON,\WN,^_N-`'N1"/N1$7N1&?N1(GN1*ON1,WN1._N10'N52/N54 -M7N56?N58GN5:ON5_N5@'N9B/N9D7N9F?N9HGN9JON9LWN9N_N9P'N=R -M/N=T7N=V?N=XGN=ZON=\WN=^_N>`'NB"/NB$7NB&?NB(GNB*ONB,WNB._NB0 -M'NF2/NF47NF6?NF8GNF:ONF_NF@'NJB/NJD7NJF?NJHGNJJONJLWNJN -M_NJP'NNR/NNT7NNV?NNXGNNZONN\WNN^_NO`'NS"/NS$7NS&?NS(GNS*ONS, -MWNS._NS0'NW2/NW47NW6?NW8GNW:ONW_NW@'N[B/N[D7N[F?N[HGN[J -MON[LWN[N_N[P'N_R/N_T7N_V?N_XGN_ZON_\WN_^_N\`'_`"/_`$7_`&?_`( -MG_`*O_`,W_`.__`0'_$2/_$47_$6?_$8G_$:O_$__$@'_(B/_(D7_(F -M?_(HG_(JO_(LW_(N__(P'_,R/_,T7_,V?_,XG_,ZO_,\W_,^__-`'_1"/_1$ -M7_1&?_1(G_1*O_1,W_1.__10'_52/_547_56?_58G_5:O_5__5@'_9B -M/_9D7_9F?_9HG_9JO_9LW_9N__9P'_=R/_=T7_=V?_=XG_=ZO_=\W_=^__>` -M'_B"/_B$7_B&?_B(G_B*O_B,W_B.__B0'_F2/_F47_F6?_F8G_F:O_F -M__F@'_JB/_JD7_JF?_JHG_JJO_JLW_JN__JP'_NR/_NT7_NV?_NXG_NZO_N\ -MW_N^__O`'_S"/_S$7_S&?_S(G_S*O_S,W_S.__S0'_W2/_W47_W6?_W8G_W: -MO_W__W@'_[B/_[D7_[F?_[HG_[JO_[LW_[N__[P'__R/__T7__V?__X -MG__ZO__\W__^__\`,``*P`%(``N@`3R`"#`!*L`%R``;H`-\@!`P`DK`"4@! -M*Z`%O(`8,`-JP`W(`3N@!_R`(#`$BL`12`)+H`D\@2@P!:K`%<@"6Z`+?($P -M,`;*P!E(`VN@#;R!.#`'ZL`=R`-[H`_\@4`P"`K!(4@$BZ`1/()(,`DJP27( -M!)N@$WR"4#`*2L$I2`6KH!6\@E@P"VK!+<@%NZ`7_()@,`R*P3%(!LN@&3R# -M:#`-JL$UR`;;H!M\@W`P#LK!.4@'ZZ`=O(-X,`_JP3W(!_N@'_R#@#`0"L)! -M2`@+H2$\A(@P$2K"1<@(&Z$C?(20,!)*PDE("2NA);R$F#`3:L)-R`D[H2?\ -MA*`P%(K"44@*2Z$I/(6H,!6JPE7("ENA*WR%L#`6RL)92`MKH2V\A;@P%^K" -M7<@+>Z$O_(7`,!@*PV%(#(NA,3R&R#`9*L-ER`R;H3-\AM`P&DK#:4@-JZ$U -MO(;8,!MJPVW(#;NA-_R&X#`3R/Z#$]JL?U -MR![;HWM\C_`Q/LK'^4@?ZZ-]O(_X,3_JQ_W('_NC?_R/`#)`"L@!22`+I($\ -MD`@R02K(!Z2/ -M_)%`,D@*R2%))(NDD3R22#))*LDER22;I)-\DE`R2DK)*4DEJZ25O))8,DMJ -MR2W));NDE_R28#),BLDQ22;+I)D\DV@R3:K)-#)/ZLD]R2?[I)_\DX`R4`K*04DH"Z6A/)2(,E$JRD7)*!NEHWR4D#)2 -M2LI)22DKI:6\E)@R4VK*3RLMY22_KI;V\E_@R7^K+?Z?O_)W`,W@* -MS^%)/(NG\3R>R#-Y*L_ER3R;I_-\GM`S>DK/Z4D]JZ?UO)[8,WMJS^W)/;NG -M]_R>X#-\BL_Q23[+I_D\G^@S?:K/]4I/ZZD]O:?X-)_JTWW*3_NI/_VG`#6@"M2!2E`+JD$]J`@UH2K4AZI/_:E`-:@*U:%*5(NJ -M43VJ2#6I*M6ERE2;JE-]JE`UJDK5J4I5JZI5O:I8-:MJU:W*5;NJ5_VJ8#6L -MBM6Q2E;+JED]JV@UK:K5M#6OZM6]RE?[ -MJE_]JX`UL`K6P4I8"ZMA/:R(-;$JUL7*6!NK8WVLD#6R2M;)2EDKJV6]K)@U -MLVK6SRZMY/:_H-;VJU_7* -M7MNK>WVO\#6^RM?Y2E_KJWV]K_@UO^K7_ZVO_;7`-M@*VV%+;(NML3VVR#;9 -M*MMERVR;K;-]MM`VVDK;:4MMJZVUO;;8-MMJVVW+;;NMM_VVX#;`NOX3V\B#?Q*M[% -MRW@;K^-]O)`W\DK>R4MY*Z_EO;R8-_-JWLW+>3NOY_V\H#?TBM[12WI+K^D] -MO:@W]:K>UVNO[;V]N#?WZM[=RWM[K^_]O<`W^`K? -MX4M\BZ_Q/;[(-_DJW^7+?)NO\WV^T#?Z2M_I2WVKK_6]OM@W^VK?[[`/_L%`.`@+X2%,A(NP$3["2#@)*^$ES(2; -ML!-^PE`X"DOA*4R%J[`5OL)8.`MKX2W,A;NP%_["8#@,B^$Q3(;+L!D^PV@X -M#:OA-#@/Z^$]S(?[L!_^PX`X$`OB04R( -M"[$A/L2(.!$KXD7,B!NQ(W[$D#@22^))3(DKL26^Q)@X$VOB3/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1G@0-2\,]`(U'QT(0``F'H@``@!04A`E$R14P4`B`'!! -M03>R*!"+1@0@0`(GDB!`0"D>V.&12":IY)),-NGDDU!&*>645%9IY9583MG$ -M$DE,\8014X#0Y1,@Y&"##3"\@`28(!B1!!-%3)'%%%04H:$05;Q)1!%2@&`" -M"!<6,<034CPH8`M2O$"$%89*44005!`*`@I#I`!"##GD,`,(1;B0Q1-5.'$$ -M$4'`.6FEEV9Z`PA*N`#%HU)XZ<0+K4XQ!!)O,I&$J%GVZFNO,A"80PP%RA`# -M#C/0(`,-!)(0+`S#%GMLLLLV2^"UV&9+(`#/1AN#L<@JRRP,)!CYZ[GHIJON -MNNRVZ^Z[\,8K;Y/_U;O8/P(2:*"]_/;K[[\`!US=EDF`T,0;;H#PQ!AT7"K# -MI3CHD*P.RX+0K0(RN%"@QC&$8<.FB(+00AUID'&IR&>4;#$(+K3\0AISO"'P -MS#37;//-.*>5BR8'WDBD0`0`P(%`!Q*1A!0QL(@!T0!((<4733QA11%$!-V! -M0$,:+84,06<@T```:(U#T!X`'?;1,P2M@4`%G"U%#D%_()`!;M/0]@8"'>`V -ML0`$#<*.;M<0=`@"*>"V#4'7&-`";M^0\^.01R[YY)17;OGEF&>N^>8PF1C0 -MC28&+=#0`6B=]$!+!^`TU%)3+7I`5PN@-=<#>3V`V*\#4#8!6J<]T-H%:`WW -M0'(;H+7=`^%]@.DP]#W0WPAH+?A`A"N@->(T`K"`UHYS[OWWX(BG;QDD-N((@(X!\>@CD`$(^?.)!TX!Q0$!^/).TU(H0``"`04LL"``[0C" -M0(+0#K`19`">(]J0""(`GPWD`E0P@@8"X(`>_2A(;5```R0@`@R0((0C+"$) -MAE`$#@1@!`6!H4':49!VN*%]!,G10.3WP?I-L$BJ"^``"WC`!"ZP@06!8$%\ -M5)`*XBB#&^S@_$`H0A*:$(56)`$`]""T@@P-?N]#T!1]>+\`\.YH,0"@`!/A -MA"8DX$!D2(,<8D!$!"I0(`QTX$"42!`F4G!H!.$`%#GH0?J1H)!43*$)^0`` -M+1*$!%0(`R\"PHLP9'",CCP1D0[@)CBY8`8(^,QG.D?C`AC81I[6+ -M:2\Q.<\BK%2?6,VJ5K?ZFAM"52`Z!:A'!XJB@B;5I'ED*$N?6I`,2+6'\*3I -M.[`!OX -MREC.LI;+`V]<2V]/+H,KQEM\'KW*D3?6I?$ -M*>V;DXFKT<^QV<4TI>O5"'*U.(MYO4"5P69).5\9C#BM9Q9N$P<]D`[XM\59 -MW+*F-\WI3D/EAI062*'#'"2]/KBD9LXNFK$6:MC].8O,[6(@GQL_,E>-Y'<`8M*8E$GY;#0!+SSN1L'8M%^5&$+DI&]T_/9ZSBRQ'&D@;X-5F./&T -M/>Q,A_OC(`^YR#MR0XT+Q.'G]JDLU7UG2*M:TA0T>4`^\&IYNEEW!3&WOB$N -MRWY?G->GI2"\=5?S*RH<`'\C"/123E:@UF#B\ZW!S]L==%LF_7DW1\[U -MKGO]ZP.YX=4%LO2=JYR@N5[W=3&^:I>./2`@*'I<,UWR@J#<["&N\]1?[NZ8 -MVUWN<^4BX0A"N(>?W8S7@[IGY6B#O9L8YK88$4 -MGNECUGN9V!O_G:DTSJ,E^5WVEL^[=)6N_5Q/[ARB3U>+D)6 -M(#4R?-.YI_C/WL#QU&X[<7\?$!%0?O<>U[STIT]]V-Z0^0`(/NC3/?M_`UW@ -M3<2^\W4_=YO;&P"H1__K>7AH7(M>UVO_/BV;F'[5DU_#6A0F//[!__[#XR`> -MM6.(=S1"Q5>9P&B+)P=(-7KQ1W7@1T'[UW_\!P_/5WXF-`2-%0#<=5/5UX$> -M^(&:PR?M$``*0`6'$$1)``5?@"G#`BE(4`0@@"%#L`0QF`1$<`0PN"MU(@6W -M$@2B`H-0@"&1,BA,``)!*#4V&"<@,`55``500"A4T":2\H13D`18T"9O`H-R -M0B=VLH1VXH-4D`1#H#]P$@13`(.#X@14$`1#$(5&8RM&6`5"H"M3\()]8@22 -MHC^"D@1N,@20D@1/X`1+""H\V"D0V(@4I&"EW*"EIN(9M.(EX*`67&(:!Z`(@.(NT -M6(NVF!%H4`9LP`9O8#BW^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 -M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P -M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. -M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L -MV9(N^9(P&9,R.9,T69,V>9,XF9,ZN9,\V9,^^9-`&91".91$691&>91(F91* -MN91,V91.^910&952.9546956>958F95:N95^95@&99B.99D699F>99H -MF99JN99LV99N^99P&9=R.9=T69=V>9=XF9=ZN9=\V9=^^9>`&9B".9B$69B& -M>9B(F9B*N9B,V9B.^9B0&9F2.9F469F6>9F8F9F:N9F^9F@&9JB.9JD -M69JF>9JHF9JJN9JLV9JN^9JP&9NR.9NT69NV>9NXF9NZN9N\V9N^^9O`&9S" -M.9S$69S&>9S(F9S*N9S,V9S.^9S0&9W2.9W469W6>9W8F9W:N9W^9W@ -M&9[B.9[D69[F>9[HF9[JN9[LV9[N^9[P&9_R.9_T69_V>9_XF9_ZN9_\V9_^ -M^9\`&J`".J`$6J`&>J`(FJ`*NJ`,VJ`.^J`0&J$2.J$46J$6>J$8FJ$:NJ$< -MVJ$>^J$@&J(B.J(D6J(F>J(HFJ(JNJ(LVJ(N^J(P&J,R.J,T6J,V>J,XFJ,Z -MNJ,\VJ,^^J-`&J1".J1$6J1&>J1(FJ1*NJ1,VJ1.^J10&J52.J546J56>J58 -MFJ5:NJ5^J5@&J9B.J9D6J9F>J9HFJ9JNJ9LVJ9N^J9P&J=R.J=T6J=V -M>J=XFJ=ZNJ=\VJ=^^J>`&JB".JB$6JB&>JB(FJB*NJB,VJB.^JB0&JF2.JF4 -M6JF6>JF8FJF:NJF^JF@&JJB.JJD6JJF>JJHFJJJNJJLVJJN^JJP&JNR -M.JNT6JNV>JNXFJNZNJN\VJN^^JO`&JS".JS$6JS&>JS(FJS*NJS,VJS.^JS0 -M&JW2.JW46JW6>JW8FJW:NJW^JW@&J[B.J[D6J[F>J[HFJ[JNJ[LVJ[N -M^J[P&J_R.J_T6J_V>J_XFJ_ZNJ_\VJ_^^J\`&[`".[`$6[`&>[`(F[`*N[`, -MV[`.^[`0&[$2.[$46[$6>[$8F[$:N[$^[$@&[(B.[(D6[(F>[(HF[(J -MN[(LV[(N^[(P&[,R.[,T6[,V>[,XF[,ZN[,\V[,^^[-`&[1".[1$6[1&>[1( -MF[1*N[1,V[1.^[10&[52.[546[56>[58F[5:N[5^[5@&[9B.[9D6[9F -M>[9HF[9JN[9LV[9N^[9P&[=R.[=T6[=V>[=XF[=ZN[=\V[=^^[>`&[B".[B$ -M6[B&>[B(F[B*N[B,V[B.^[B0&[F2.[F46[F6>[F8F[F:N[F^[F@&[JB -M.[JD6[JF>[JHF[JJN[JLV[JN^[JP&[NR.[NT6[NV>[NXF[NZN[N\V[N^^[O` -M&[S".[S$6[S&>[S(F[S*N[S,V[S.^[S0&[W2.[W46[W6>[W8F[W:N[W -M^[W@&[[B.[[D6[[F>[[HF[[JN[[LV[[N^[[P&[_R.[_T6[_V>[_XF[_ZN[_\ -MV[_^^[\`',`"/,`$7,`&?,`(G,`*O,`,W,`._,`0',$2/,$47,$6?,$8G,$: -MO,$_,$@',(B/,(D7,(F?,(HG,(JO,(LW,(N_,(P',,R/,,T7,,V?,,X -MG,,ZO,,\W,,^_,-`',1"/,1$7,1&?,1(G,1*O,1,W,1._,10',52/,547,56 -M?,58G,5:O,5_,5@',9B/,9D7,9F?,9HG,9JO,9LW,9N_,9P',=R/,=T -M7,=V?,=XG,=ZO,=\W,=^_,>`',B"/,B$7,B&?,B(G,B*O,B,W,B._,B0',F2 -M/,F47,F6?,F8G,F:O,F_,F@',JB/,JD7,JF?,JHG,JJO,JLW,JN_,JP -M',NR/,NT7,NV?,NXG,NZO,N\W,N^_,O`',S"/,S$7,S&?,S(G,S*O,S,W,S. -M_,S0',W2/,W47,W6?,W8G,W:O,W_,W@',[B/,[D7,[F?,[HG,[JO,[L -MW,[N_,[P',_R/,_T7,_V?,_XG,_ZO,_\W,_^_,\`'=`"/=`$7=`&?=`(G=`* -MO=`,W=`._=`0'=$2/=$47=$6?=$8G=$:O=$_=$@'=(B/=(D7=(F?=(H -MG=(JO=(LW=(N_=(P'=,R/=,T7=,V?=,XG=,ZO=,\W=,^_=-`'=1"/=1$7=1& -M?=1(G=1*O=1,W=1._=10'=52/=547=56?=58G=5:O=5_=5@'=9B/=9D -M7=9F?=9HG=9JO=9LW=9N_=9P'==R/==T7==V?==XG==ZO==\W==^_=>`'=B" -M/=B$7=B&?=B(G=B*O=B,W=B._=B0'=F2/=F47=F6?=F8G=F:O=F_=F@ -M'=JB/=JD7=JF?=JHG=JJO=JLW=JN_=JP'=NR/=NT7=NV?=NXG=NZO=N\W=N^ -M_=O`'=S"/=S$7=S&?=S(G=S*O=S,W=S._=S0'=W2/=W47=W6?=W8G=W:O=W< -MW=W>_=W@'=[B/=[D7=[F?=[HG=[JO=[LW=[N_=[P'=_R/=_T7=_V?=_XG=_Z -MO=_\W=_^_=\`'N`"/N`$7N`&?N`(GN`*ON`,WN`._N`0'N$2/N$47N$6?N$8 -MGN$:ON$_N$@'N(B/N(D7N(F?N(HGN(JON(LWN(N_N(P'N,R/N,T7N,V -M?N,XGN,ZON,\WN,^_N-`'N1"/N1$7N1&?N1(GN1*ON1,WN1._N10'N52/N54 -M7N56?N58GN5:ON5_N5@'N9B/N9D7N9F?N9HGN9JON9LWN9N_N9P'N=R -M/N=T7N=V?N=XGN=ZON=\WN=^_N>`'NB"/NB$7NB&?NB(GNB*ONB,WNB._NB0 -M'NF2/NF47NF6?NF8GNF:ONF_NF@'NJB/NJD7NJF?NJHGNJJONJLWNJN -M_NJP'NNR/NNT7NNV?NNXGNNZONN\WNN^_NO`'NS"/NS$7NS&?NS(GNS*ONS, -MWNS._NS0'NW2/NW47NW6?NW8GNW:ONW_NW@'N[B/N[D7N[F?N[HGN[J -MON[LWN[N_N[P'N_R/N_T7N_V?N_XGN_ZON_\WN_^_N\`'_`"/_`$7_`&?_`( -MG_`*O_`,W_`.__`0'_$2/_$47_$6?_$8G_$:O_$__$@'_(B/_(D7_(F -M?_(HG_(JO_(LW_(N__(P'_,R/_,T7_,V?_,XG_,ZO_,\W_,^__-`'_1"/_1$ -M7_1&?_1(G_1*O_1,W_1.__10'_52/_547_56?_58G_5:O_5__5@'_9B -M/_9D7_9F?_9HG_9JO_9LW_9N__9P'_=R/_=T7_=V?_=XG_=ZO_=\W_=^__>` -M'_B"/_B$7_B&?_B(G_B*O_B,W_B.__B0'_F2/_F47_F6?_F8G_F:O_F -M__F@'_JB/_JD7_JF?_JHG_JJO_JLW_JN__JP'_NR/_NT7_NV?_NXG_NZO_N\ -MW_N^__O`'_S"/_S$7_S&?_S(G_S*O_S,W_S.__S0'_W2/_W47_W6?_W8G_W: -MO_W__W@'_[B/_[D7_[F?_[HG_[JO_[LW_[N__[P'__R/__T7__V?__X -MG__ZO__\W__^__\`,``*P`%(``N@`3R`"#`!*L`%R``;H`-\@!`P`DK`"4@! -M*Z`%O(`8,`-JP`W(`3N@!_R`(#`$BL`12`)+H`D\@2@P!:K`%<@"6Z`+?($P -M,`;*P!E(`VN@#;R!.#`'ZL`=R`-[H`_\@4`P"`K!(4@$BZ`1/()(,`DJP27( -M!)N@$WR"4#`*2L$I2`6KH!6\@E@P"VK!+<@%NZ`7_()@,`R*P3%(!LN@&3R# -M:#`-JL$UR`;;H!M\@W`P#LK!.4@'ZZ`=O(-X,`_JP3W(!_N@'_R#@#`0"L)! -M2`@+H2$\A(@P$2K"1<@(&Z$C?(20,!)*PDE("2NA);R$F#`3:L)-R`D[H2?\ -MA*`P%(K"44@*2Z$I/(6H,!6JPE7("ENA*WR%L#`6RL)92`MKH2V\A;@P%^K" -M7<@+>Z$O_(7`,!@*PV%(#(NA,3R&R#`9*L-ER`R;H3-\AM`P&DK#:4@-JZ$U -MO(;8,!MJPVW(#;NA-_R&X#`3R/Z#$]JL?U -MR![;HWM\C_`Q/LK'^4@?ZZ-]O(_X,3_JQ_W('_NC?_R/`#)`"L@!22`+I($\ -MD`@R02K(!Z2/ -M_)%`,D@*R2%))(NDD3R22#))*LDER22;I)-\DE`R2DK)*4DEJZ25O))8,DMJ -MR2W));NDE_R28#),BLDQ22;+I)D\DV@R3:K)-#)/ZLD]R2?[I)_\DX`R4`K*04DH"Z6A/)2(,E$JRD7)*!NEHWR4D#)2 -M2LI)22DKI:6\E)@R4VK*3RLMY22_KI;V\E_@R7^K+?Z?O_)W`,W@* -MS^%)/(NG\3R>R#-Y*L_ER3R;I_-\GM`S>DK/Z4D]JZ?UO)[8,WMJS^W)/;NG -M]_R>X#-\BL_Q23[+I_D\G^@S?:K/]4I/ZZD]O:?X-)_JTWW*3_NI/_VG`#6@"M2!2E`+JD$]J`@UH2K4AZI/_:E`-:@*U:%*5(NJ -M43VJ2#6I*M6ERE2;JE-]JE`UJDK5J4I5JZI5O:I8-:MJU:W*5;NJ5_VJ8#6L -MBM6Q2E;+JED]JV@UK:K5M#6OZM6]RE?[ -MJE_]JX`UL`K6P4I8"ZMA/:R(-;$JUL7*6!NK8WVLD#6R2M;)2EDKJV6]K)@U -MLVK6SRZMY/:_H-;VJU_7* -M7MNK>WVO\#6^RM?Y2E_KJWV]K_@UO^K7_ZVO_;7`-M@*VV%+;(NML3VVR#;9 -M*MMERVR;K;-]MM`VVDK;:4MMJZVUO;;8-MMJVVW+;;NMM_VVX#;`NOX3V\B#?Q*M[% -MRW@;K^-]O)`W\DK>R4MY*Z_EO;R8-_-JWLW+>3NOY_V\H#?TBM[12WI+K^D] -MO:@W]:K>UVNO[;V]N#?WZM[=RWM[K^_]O<`W^`K? -MX4M\BZ_Q/;[(-_DJW^7+?)NO\WV^T#?Z2M_I2WVKK_6]OM@W^VK?[[`/_L%`.`@+X2%,A(NP$3["2#@)*^$ES(2; -ML!-^PE`X"DOA*4R%J[`5OL)8.`MKX2W,A;NP%_["8#@,B^$Q3(;+L!D^PV@X -M#:OA-#@/Z^$]S(?[L!_^PX`X$`OB04R( -M"[$A/L2(.!$KXD7,B!NQ(W[$D#@22^))3(DKL26^Q)@X$VOB3R^-Y -M3(_KL3V^Q_@X'^OC?[-O_LW`.3@+Y^%,G(NS<3[.R#DY*^?ES)R;LW-^SM`Y -M.DOGZ4R=J[-UOL[8.3MKY^W,G;NS=_[.X#D\B^?Q3)[+LWD^S^@Y/:OG] -MV[-[?L_P.3[+Y_E,G^NS?;[/^#D_Z^?]S)_[LW_^SP`Z0`OH`4V@"[2!/M`( -M.D$KZ`7-H!NT@W[0$#I"2^@)3:$KM(6^T!@Z0VOH#4VOZ[6]OM?X.E_KZWW-K_NUO_[7`#M@ -M"^R!3;`+ML$^V`@[82OLA[;/_ME`.V@+[:%-M(NVT3[:2#MI*^VES;2;MM-^VE`[:DOMJ4VU -MJ[;5OMI8.VMK[:W-M;NVU_[:8#MLB^VQ3;;+MMD^VV@[;:OMM#MOZ^V]S;?[MM_^VX`[<`ONP4VX"[?A/MR(.W$K[L7- -MN!NWXW[2OOYV#M[:^_MS;V[M_?^ -MWN`[?(OO\4V^R[?Y/M_H.WVK[_7-OMNW^W[?\#M^R^_Y3;_KM_V^W_@[?^OO -M_[DO_^7`/)@+\V%.S(NY,3_FR#R9*_-ESLR;N3-_YM`\FDOS:4[-J[DUO^;8 -M/)MK\VW.S;NY-__FX#R3_OZ#V]J_?USM[; -MNWM_[_`]OLOW^4[?Z[M]O^_X/;_K]_W.W_N[?__O`#[`"_@!3^`+O($_\`@^ -MP2OX!<_@&[R#?_`0/L)+^`E/X2N\A;_P&#[#:_@-S^$[O(?_\"`^Q(OX$4_B -M2[R)/_$H/L6K^!7/XEN\BW_Q,#[&R_@93^-KO(V_\3@^Q^OX'<_C>[R/__%` -M/L@+^2%/Y(N\D3_R2#[)*_DES^2;O)-_\E`^RDOY*4_EJ[R5O_)8/LMK^2W/ -MY;N\E__R8#[,B_DQ3^;+O)D_\V@^S:OY-<_FV[R;?_-P/L[+^3E/Y^N\G;_S -M>#[/Z_D]S^?[O)__\X`^T`OZ04_H"[VA/_2(/M$K^D7/Z!N]HW_TD#[22_I) -M3^DKO:6_])@^TVOZ3<_I.[VG__2@/M2+^E%/ZDN]J3_UJ#[5J_I5S^I;O:M_ -M];`^ULOZ64_K:[VMO_6X/M?K^EW/ZWN]K__UP#[8"_MA3^R+O;$_]L@^V2O[ -M9<_LF[VS?_;0/MI+^VE/[:N]M;_VV#[;:_MMS^V[O;?_]N`^W(O[<4_NR[VY -M/_?H/MVK^W7/[MN]NW_W\#[>R_MY3^_KO;V_]_@^W^O[?<_O^[V___<`/^`+ -M_(%/\`N^P3_X"#_A*_R%S_`;OL-_^!`_XDO\B4_Q*[[%O_@8/^-K_(W/\3N^ -MQ__X(#_DB_R13_)+OLD_^2@_Y:O\E<_R6[[+?_DP/^;+_)E/\VN^S;_Y.#_G -MZ_R=S_-[OL__^4`_Z`O]H4_TB[[1/_I(/^DK_:7/])N^TW_Z4#_J2_VI3_6K -MOM6_^E@_ZVO]K<_UN[[7__I@/^R+_;%/]LN^V3_[:#_MJ_VUS_;;OMM_^W`_ -M[LO]N4_WZ[[=O_MX/^_K_;W/]_N^W__[@#_P"_[!3_@+O^$__(@_\2O^Q<_X -M&[_C?_R0/_)+_LE/^2N_Y;_\F#_S:_[-S_D[O^?__*`_](O^T4_Z2[_I/_VH -M/_6K_M7/^EN_ZW_]L#_VR_[93_MKO^V__;@_]^O^W<_[>[_O__W`/_@+_^%/ -M_(N_\3_^R#_Y*__ES_R;O_-__M`_^DO_Z4_]J[_UO_[8/_MK_^W/_;N_]__^ -MX#_\B__Q3_[+O_D__^@__:O_]<_^V[_[?__P/_[+__E/_^N__;__^#__Z__] -MS__[O____P!@`"@`#H`$8`%H`!Z`"&`"J``N@`Q@`^@`/H`08`0H`4Z`%&`% -M:`%>@!A@!J@!;H`<8`?H`7Z`(&`(*`*.@"1@"6@"GH`H8`JH`JZ`+&`+Z`*^ -M@#!@#"@#SH`T8`UH`]Z`.&`.J`/N@#Q@#^@#_H!`8!`H!`Z!1&`1:`0>@4A@ -M$J@$+H%,8!/H!#Z!4&`4*`5.@51@%6@%7H%88!:H!6Z!7&`7Z`5^@6!@&"@& -MCH%D8!EH!IZ!:&`:J`:N@6Q@&^@&OH%P8!PH!\Z!=&`=:`?>@7A@'J@'[H%\ -M8!_H!_Z!@&`@*`@.@H1@(6@('H*(8"*H""Z"C&`CZ`@^@I!@)"@)3H*48"5H -M"5Z"F&`FJ`EN@IQ@)^@)?H*@8"@H"HZ"I&`I:`J>@JA@*J@*KH*L8"OH"KZ" -ML&`L*`O.@K1@+6@+WH*X8"ZH"^Z"O&`OZ`O^@L!@,"@,#H/$8#%H#!Z#R&`R -MJ`PN@\Q@,^@,/H/08#0H#4Z#U&`U:`U>@]A@-J@-;H/<8#?H#7Z#X&`X*`Z. -M@^1@.6@.GH/H8#JH#JZ#[&`[Z`Z^@_!@/"@/SH/T8#UH#]Z#^&`^J`_N@_Q@ -M/^@/_H,`84`H$`Z$!&%!:!`>A`AA0J@0+H0,84/H$#Z$$&%$*!%.A!1A16@1 -M7H0884:H$6Z$'&%'Z!%^A"!A2"@2CH0D84EH$IZ$*&%*J!*NA"QA2^@2OH0P -M84PH$\Z$-&%-:!/>A#AA3J@3[H0\84_H$_Z$0&%0*!0.A41A46@4'H5(85*H -M%"Z%3&%3Z!0^A5!A5"@53H54855H%5Z%6&%6J!5NA5QA5^@5?H5@85@H%HZ% -M9&%9:!:>A6AA6J@6KH5L85OH%KZ%<&%<*!?.A71A76@7WH5X85ZH%^Z%?&%? -MZ!?^A8!A8"@8#H:$86%H&!Z&B&%BJ!@NAHQA8^@8/H:0860H&4Z&E&%E:!E> -MAIAA9J@9;H:<86?H&7Z&H&%H*!J.AJ1A:6@:GH:H86JH&JZ&K&%KZ!J^AK!A -M;"@;SH:T86UH&]Z&N&%NJ!ONAKQA;^@;_H;`87`H'`Z'Q&%Q:!P>A\AA"@>CH?D -M87EH'IZ'Z&%ZJ!ZNA^QA>^@>OH?P87PH'\Z']&%]:!_>A_AA?J@?[H?\87_H -M'_Z'`&*`*"`.B`1B@6@@'H@(8H*H("Z(#&*#Z"`^B!!BA"@A3H@48H5H(5Z( -M&&*&J"%NB!QBA^@A?H@@8H@H(HZ()&*):"*>B"ABBJ@BKH@L8HOH(KZ(,&*, -M*"/.B#1BC6@CWH@X8HZH(^Z(/&*/Z"/^B$!BD"@D#HE$8I%H)!Z)2&*2J"0N -MB4QBD^@D/HE08I0H)4Z)5&*5:"5>B5ABEJ@E;HE<8I?H)7Z)8&*8*":.B61B -MF6@FGHEH8IJH)JZ);&*;Z":^B7!BG"@GSHET8IUH)]Z)>&*>J"?NB7QBG^@G -M_HF`8J`H*`Z*A&*A:"@>BHABHJ@H+HJ,8J/H*#Z*D&*D*"E.BI1BI6@I7HJ8 -M8J:H*6Z*G&*GZ"E^BJ!BJ"@JCHJD8JEH*IZ*J&*JJ"JNBJQBJ^@JOHJP8JPH -M*\Z*M&*M:"O>BKABKJ@K[HJ\8J_H*_Z*P&*P*"P.B\1BL6@L'HO(8K*H+"Z+ -MS&*SZ"P^B]!BM"@M3HO48K5H+5Z+V&*VJ"UNB]QBM^@M?HO@8K@H+HZ+Y&*Y -M:"Z>B^ABNJ@NKHOL8KOH+KZ+\&*\*"_.B_1BO6@OWHOX8KZH+^Z+_&*_Z"_^ -'BP!CP+@7`0`` -` -end diff --git a/lib/libarchive/test/test_read_format_iso_zisofs.iso.Z.uu b/lib/libarchive/test/test_read_format_iso_zisofs.iso.Z.uu deleted file mode 100644 index 00896e1..0000000 --- a/lib/libarchive/test/test_read_format_iso_zisofs.iso.Z.uu +++ /dev/null @@ -1,63 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_iso_zisofs.iso.Z -M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR -MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY -ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ -MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ -MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA -MA!1***`43S11X88<1GA0+`6!Z-&!``1`XH$((`"`!059,$%"%0PD`@`7%%2C -MB@*I:$0``B10(@D"!'3B@1T6:>212":IY)),-NGDDU!&*>645%9I991-+)'$ -M%$\8,04(6SX!0@XVV`##"TAX"8(123!1Q!193$%%$1H*446;1!0A!0@F@'!A -M$4,\(<6#`K8@Q0M$6$&H%$4$086@(*`P1`H@Q)!##C.`4(0+63Q1A1-'$!&$ -MFY%.6NFE-X"@A`M0-"H%ETZ\L.H40R#1)A-)@'KEKKSN*@.!.<`0K`PRQ$!# -M#300"`,)OPKK++'&(JLL"NXY)9K[KGHIJON -MNNRVZ^Z2_\6[V#\"$FB@O/CFJ^^^_/9;799)@'!%&62`,$49<$`H`PC%ZG"L -MPS`P#*P";:R1QAQOF#$'PRX4"(*A']>11L$Q?'S&R`Q_K`<(+K3\@AX7O^'O -MS#37;//-.)=U8(U""C0``!@(="`124B1\]%()ZWTTDPW[?334$M]MI,(T*CC0#@&)".//H8`)`]EWC@ -M%%`<$(`O[P`@A10%!!`(%%B$VTX0`P71CM8##6"UT$$2)``51F@0@`,[]OAC -M&PD(4$$+*)``NNBDDS!$$1P$D$%!KQO43D'MF/$V03<.1+?G=U<^9`"#%WYX -MX@$LWOCC!4E>$(\%79[YYIW;;7KHHY=^>O4D```'T`4%+7?<"-;]H^]"#N!U -M\`$DXD03"!Q(1AIR(*XXXP(Y7OE``DPNY/T".:\YY^*[6_0^1[W4`8`0`-!` -M031@`P,,Q``V&.#=A":D`[#)32[800S0I[XF).!`9D@#&\H@OP"0(A`#"00I -M^!>0_"V/A0#P'_0"2`()3@]UI=."$2`0`#CH@0`/H$(8>!$07H2!"HQ(X`(; -M^,`(TI"")5H`$H(P*%PY80D9W"#ATK>^!AP(#6&0`QG8D`8WK*&$)TSA"ING -MOQ+!4(8`Y-T-L7>]U.F0ASX$HA")"``C4L$0`-A`001I$!M",0`*@%,3K(A% -M#0INBXU8'P,.-(<\M(&,9BPA,$(QD%``HXTF>F'SIL"$!9"(`"$<(>;^MZ,! -M^$@`-0R`*V,XQ]2YC9`#P25!ZEBZ0RY`D8R401;1%\DF>!$`E;QD&=<@`TUR -M4B">!"4HWTC*28(/``.@0QO@L,K-\;*6UBM@Z101R$$>Y'0%^%GV\A:`7V9A -MD;E:P@R&"%HA4`^+TK&A-JUK7:A$]M0.15#B$ -M5I,`A2]8*@C``IO@$J"6P:@J.2\`0G&,Q3B-T4A&;+ -M6-\"5[A@RI-MD9L$/8')N8U-0A.HF`406.$)3*A"$_B:)UI)@:Z/&BZD:GO; -MW'Z7N%(8;VN;ZP*V^O>_``[PS&Y`CBE8(AG;L,8!]JC2!P0$'P4("!,!,.$* -M.Y#"%[:PA#/,X0U[&,,?UC"(1RSB$G>8Q"9 -MRE>VQG+7]8RF,I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. -MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV -MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ -M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W -MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U -MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ -M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ -M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ -MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` -M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ -M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ -MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: -MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X -MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 -@>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN'`` -` -end diff --git a/lib/libarchive/test/test_read_format_isojoliet_bz2.c b/lib/libarchive/test/test_read_format_isojoliet_bz2.c deleted file mode 100644 index ca2da83..0000000 --- a/lib/libarchive/test/test_read_format_isojoliet_bz2.c +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Based on libarchive/test/test_read_format_isorr_bz2.c with - * bugs introduced by Andreas Henriksson for - * testing ISO9660 image with Joliet extension. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* -Execute the following to rebuild the data for this program: - tail -n +35 test_read_format_isojoliet_bz2.c | /bin/sh - -rm -rf /tmp/iso -mkdir /tmp/iso -mkdir /tmp/iso/dir -echo "hello" >/tmp/iso/long-joliet-file-name.textfile -ln /tmp/iso/long-joliet-file-name.textfile /tmp/iso/hardlink -(cd /tmp/iso; ln -s long-joliet-file-name.textfile symlink) -if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h -TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir -TZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink -else -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink -fi -F=test_read_format_iso_joliet.iso.Z -mkhybrid -J -uid 1 -gid 2 /tmp/iso | compress > $F -uuencode $F $F > $F.uu -exit 1 - */ - -DEFINE_TEST(test_read_format_isojoliet_bz2) -{ - const char *refname = "test_read_format_iso_joliet.iso.Z"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_all(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_set_options(a, "iso9660:!rockridge")); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* First entry is '.' root directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(".", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(86401, archive_entry_ctime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(0, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - - /* A directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - - /* A regular file with two names ("hardlink" gets returned - * first, so it's not marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("hardlink", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(6, archive_entry_size(ae)); - assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(6, (int)size); - assertEqualInt(0, offset); - assertEqualInt(0, memcmp(p, "hello\n", 6)); - - /* Second name for the same regular file (this happens to be - * returned second, so does get marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("long-joliet-file-name.textfile", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("hardlink", - archive_entry_hardlink(ae)); - assert(!archive_entry_size_is_set(ae)); - - /* A symlink to the regular file. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("symlink", archive_entry_pathname(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - diff --git a/lib/libarchive/test/test_read_format_isojoliet_long.c b/lib/libarchive/test/test_read_format_isojoliet_long.c deleted file mode 100644 index d1d38d7..0000000 --- a/lib/libarchive/test/test_read_format_isojoliet_long.c +++ /dev/null @@ -1,141 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* -Execute the following to rebuild the data for this program: - tail -n +35 test_read_format_isojoliet_long.c | /bin/sh - -rm -rf /tmp/iso -mkdir /tmp/iso -num=0 -file=""; -while [ $num -lt 100 ] -do - num=$((num+10)) - file="${file}1234567890" -done -dir="${file}dir" -mkdir /tmp/iso/${dir} -file="${file}123" -echo "hello" > /tmp/iso/${file} -ln /tmp/iso/${file} /tmp/iso/hardlink -if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h -TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir} -else -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir} -fi -F=test_read_format_iso_joliet_long.iso.Z -mkhybrid -J -joliet-long -uid 1 -gid 2 /tmp/iso | compress > $F -uuencode $F $F > $F.uu -rm -rf /tmp/iso -exit 1 - */ - -DEFINE_TEST(test_read_format_isojoliet_long) -{ - const char *refname = "test_read_format_iso_joliet_long.iso.Z"; - char pathname[104]; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - - for (i = 0; i < 100; i++) - pathname[i] = '0' + ((i+1) % 10); - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_all(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_set_options(a, "iso9660:!rockridge")); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* First entry is '.' root directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(".", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(86401, archive_entry_ctime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(0, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - - /* A directory. */ - pathname[100] = 'd'; - pathname[101] = 'i'; - pathname[102] = 'r'; - pathname[103] = '\0'; - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(pathname, archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - - /* A regular file with two names (pathname gets returned - * first, so it's not marked as a hardlink). */ - pathname[100] = '1'; - pathname[101] = '2'; - pathname[102] = '3'; - pathname[103] = '\0'; - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(6, archive_entry_size(ae)); - assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(6, (int)size); - assertEqualInt(0, offset); - assertEqualInt(0, memcmp(p, "hello\n", 6)); - - /* Second name for the same regular file (this happens to be - * returned second, so does get marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(pathname, archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("hardlink", archive_entry_hardlink(ae)); - assert(!archive_entry_size_is_set(ae)); - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - diff --git a/lib/libarchive/test/test_read_format_isojoliet_rr.c b/lib/libarchive/test/test_read_format_isojoliet_rr.c deleted file mode 100644 index b971272..0000000 --- a/lib/libarchive/test/test_read_format_isojoliet_rr.c +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Based on libarchive/test/test_read_format_isorr_bz2.c with - * bugs introduced by Andreas Henriksson for - * testing ISO9660 image with Joliet extension. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* -Execute the following to rebuild the data for this program: - tail -n +35 test_read_format_isojoliet_rr.c | /bin/sh - -rm -rf /tmp/iso -mkdir /tmp/iso -mkdir /tmp/iso/dir -file="long-joliet-file-name.textfile" -echo "hello" >/tmp/iso/$file -ln /tmp/iso/$file /tmp/iso/hardlink -(cd /tmp/iso; ln -s $file symlink) -if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h -TZ=utc touch -afm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir -TZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink -TZ=utc touch -afm -t 197001020000.01 /tmp/iso -else -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso -fi -F=test_read_format_iso_joliet_rockridge.iso.Z -mkhybrid -J -uid 1 -gid 2 /tmp/iso | compress > $F -uuencode $F $F > $F.uu -exit 1 - */ - -DEFINE_TEST(test_read_format_isojoliet_rr) -{ - const char *refname = "test_read_format_iso_joliet_rockridge.iso.Z"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_all(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* First entry is '.' root directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(".", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - - /* A directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - - /* A regular file with two names ("hardlink" gets returned - * first, so it's not marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("hardlink", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(6, archive_entry_size(ae)); - assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(6, (int)size); - assertEqualInt(0, offset); - assertEqualInt(0, memcmp(p, "hello\n", 6)); - assertEqualInt(86401, archive_entry_mtime(ae)); - /* mkisofs records their access time. */ - /*assertEqualInt(86401, archive_entry_atime(ae));*/ - /* TODO: Actually, libarchive should be able to - * compute nlinks correctly even without RR - * extensions. See comments in libarchive source. */ - assertEqualInt(2, archive_entry_nlink(ae)); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - - /* Second name for the same regular file (this happens to be - * returned second, so does get marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("long-joliet-file-name.textfile", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("hardlink", - archive_entry_hardlink(ae)); - assert(!archive_entry_size_is_set(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - /* TODO: See above. */ - assertEqualInt(2, archive_entry_nlink(ae)); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - - /* A symlink to the regular file. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("symlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("long-joliet-file-name.textfile", - archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_nlink(ae)); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - diff --git a/lib/libarchive/test/test_read_format_isorr_bz2.c b/lib/libarchive/test/test_read_format_isorr_bz2.c deleted file mode 100644 index b7cd704..0000000 --- a/lib/libarchive/test/test_read_format_isorr_bz2.c +++ /dev/null @@ -1,203 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* -PLEASE use old cdrtools; mkisofs verion is 2.01. -This version mkisofs made wrong "SL" System Use Entry of RRIP. - -Execute the following command to rebuild the data for this program: - tail -n +34 test_read_format_isorr_bz2.c | /bin/sh - -rm -rf /tmp/iso -mkdir /tmp/iso -mkdir /tmp/iso/dir -echo "hello" >/tmp/iso/file -dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file -ln /tmp/iso/file /tmp/iso/hardlink -(cd /tmp/iso; ln -s file symlink) -(cd /tmp/iso; ln -s /tmp/ symlink2) -(cd /tmp/iso; ln -s /tmp/../ symlink3) -(cd /tmp/iso; ln -s .././../tmp/ symlink4) -(cd /tmp/iso; ln -s .///file symlink5) -(cd /tmp/iso; ln -s /tmp//../ symlink6) -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink /tmp/iso/symlink5 -F=test_read_format_iso_rockridge.iso.Z -mkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F -uuencode $F $F > $F.uu -exit 1 - */ - -DEFINE_TEST(test_read_format_isorr_bz2) -{ - const char *refname = "test_read_format_iso_rockridge.iso.Z"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_all(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* Retrieve each of the 8 files on the ISO image and - * verify that each one is what we expect. */ - for (i = 0; i < 10; ++i) { - assertEqualInt(0, archive_read_next_header(a, &ae)); - - if (strcmp(".", archive_entry_pathname(ae)) == 0) { - /* '.' root directory. */ - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - /* Now, we read timestamp recorded by RRIP "TF". */ - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - /* Now, we read links recorded by RRIP "PX". */ - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(12345684, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello\n", 6); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { - /* A hardlink to the regular file. */ - /* Note: If "hardlink" gets returned before "file", - * then "hardlink" will get returned as a regular file - * and "file" will get returned as the hardlink. - * This test should tolerate that, since it's a - * perfectly permissible thing for libarchive to do. */ - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_hardlink(ae)); - assertEqualInt(0, archive_entry_size_is_set(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp (an absolute path) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp/.. (with a ".." component) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp/..", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { - /* A symlink to a path with ".." and "." components */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".././../tmp", - archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file with "/" components. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".///file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp//.. - * (with "/" and ".." components) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp//..", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else { - failure("Saw a file that shouldn't have been there"); - assertEqualString(archive_entry_pathname(ae), ""); - } - } - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - - diff --git a/lib/libarchive/test/test_read_format_isorr_ce.c b/lib/libarchive/test/test_read_format_isorr_ce.c deleted file mode 100644 index c9cd059..0000000 --- a/lib/libarchive/test/test_read_format_isorr_ce.c +++ /dev/null @@ -1,223 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* -Execute the following command to rebuild the data for this program: - tail -n +32 test_read_format_isorr_ce.c | /bin/sh - -dirname=/tmp/iso -# -rm -rf $dirname -mkdir $dirname -# -num=0 -file="" -while [ $num -lt 150 ] -do - num=$((num+1)) - file="a$file" -done -# -num=0 -while [ $num -lt 3 ] -do - num=$((num+1)) - file="a$file" - echo "hello $((num+150))" > $dirname/$file - dd if=/dev/zero count=1 bs=4080 >> $dirname/$file - (cd $dirname; ln -s $file sym$num) -done -# -mkdir $dirname/dir -# -time1="197001020000.01" -time2="197001030000.02" -TZ=utc touch -afhm -t $time1 $dirname/dir $dirname/aaaa* -TZ=utc touch -afhm -t $time2 $dirname/sym* -TZ=utc touch -afhm -t $time1 $dirname -# -F=test_read_format_iso_rockridge_ce.iso.Z -mkisofs -R -uid 1 -gid 2 $dirname | compress > $F -uuencode $F $F > $F.uu -rm -rf $dirname -exit 1 - */ - -/* - * Test reading SUSP "CE" extension is works fine. - */ - -static void -mkpath(char *p, int len) -{ - int i; - - for (i = 0; i < len; i++) - p[i] = 'a'; - p[len] = '\0'; -} - -DEFINE_TEST(test_read_format_isorr_ce) -{ - const char *refname = "test_read_format_iso_rockridge_ce.iso.Z"; - char path1[160]; - char path2[160]; - char path3[160]; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - - mkpath(path1, 151); - mkpath(path2, 152); - mkpath(path3, 153); - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_all(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* Retrieve each of the 8 files on the ISO image and - * verify that each one is what we expect. */ - for (i = 0; i < 8; ++i) { - assertEqualInt(0, archive_read_next_header(a, &ae)); - - if (strcmp(".", archive_entry_pathname(ae)) == 0) { - /* '.' root directory. */ - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - /* Now, we read timestamp recorded by RRIP "TF". */ - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - /* Now, we read links recorded by RRIP "PX". */ - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp(path1, archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString(path1, archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(4090, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello 151\n", 10); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp(path2, archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString(path2, archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(4090, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello 152\n", 10); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp(path3, archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString(path3, archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(4090, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello 153\n", 10); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("sym1", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(path1, archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("sym2", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(path2, archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("sym3", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(path3, archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else { - failure("Saw a file that shouldn't have been there"); - assertEqualString(archive_entry_pathname(ae), ""); - } - } - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - - diff --git a/lib/libarchive/test/test_read_format_isorr_new_bz2.c b/lib/libarchive/test/test_read_format_isorr_new_bz2.c deleted file mode 100644 index c8554a0..0000000 --- a/lib/libarchive/test/test_read_format_isorr_new_bz2.c +++ /dev/null @@ -1,204 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - - -/* -PLEASE use latest cdrtools at least mkisofs version is 2.01.01a63 or later. -Old version mkisofs made wrong "SL" System Use Entry of RRIP. - -Execute the following command to rebuild the data for this program: - tail -n +34 test_read_format_isorr_new_bz2.c | /bin/sh - -rm -rf /tmp/iso -mkdir /tmp/iso -mkdir /tmp/iso/dir -echo "hello" >/tmp/iso/file -dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file -ln /tmp/iso/file /tmp/iso/hardlink -(cd /tmp/iso; ln -s file symlink) -(cd /tmp/iso; ln -s /tmp/ symlink2) -(cd /tmp/iso; ln -s /tmp/../ symlink3) -(cd /tmp/iso; ln -s .././../tmp/ symlink4) -(cd /tmp/iso; ln -s .///file symlink5) -(cd /tmp/iso; ln -s /tmp//../ symlink6) -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink -F=test_read_format_iso_rockridge_new.iso.Z -mkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F -uuencode $F $F > $F.uu -exit 1 - */ - -DEFINE_TEST(test_read_format_isorr_new_bz2) -{ - const char *refname = "test_read_format_iso_rockridge_new.iso.Z"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_all(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* Retrieve each of the 8 files on the ISO image and - * verify that each one is what we expect. */ - for (i = 0; i < 10; ++i) { - assertEqualInt(0, archive_read_next_header(a, &ae)); - - if (strcmp(".", archive_entry_pathname(ae)) == 0) { - /* '.' root directory. */ - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - /* Now, we read timestamp recorded by RRIP "TF". */ - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - /* Now, we read links recorded by RRIP "PX". */ - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(12345684, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello\n", 6); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { - /* A hardlink to the regular file. */ - /* Note: If "hardlink" gets returned before "file", - * then "hardlink" will get returned as a regular file - * and "file" will get returned as the hardlink. - * This test should tolerate that, since it's a - * perfectly permissible thing for libarchive to do. */ - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_hardlink(ae)); - assertEqualInt(0, archive_entry_size_is_set(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp/ (an absolute path) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp/", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp/../ (with a ".." component) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp/../", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { - /* A symlink to a path with ".." and "." components */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".././../tmp/", - archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file with "/" components. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".///file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp//../ - * (with "/" and ".." components) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp//../", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else { - failure("Saw a file that shouldn't have been there"); - assertEqualString(archive_entry_pathname(ae), ""); - } - } - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - - diff --git a/lib/libarchive/test/test_read_format_isorr_rr_moved.c b/lib/libarchive/test/test_read_format_isorr_rr_moved.c deleted file mode 100644 index 0aeb226..0000000 --- a/lib/libarchive/test/test_read_format_isorr_rr_moved.c +++ /dev/null @@ -1,270 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* -Execute the following command to rebuild the data for this program: - tail -n +32 test_read_format_isorr_rr_moved.c | /bin/sh - -dirname=/tmp/iso -rm -rf $dirname -mkdir -p $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10 -echo "hello" >$dirname/file -dd if=/dev/zero count=1 bs=12345678 >>$dirname/file -deepfile=$dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/deep -echo "hello" >$deepfile -dd if=/dev/zero count=1 bs=12345678 >>$deepfile -time="197001020000.01" -TZ=utc touch -afhm -t $time $deepfile -TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10 -TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9 -TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8 -TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7 -TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6 -TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5 -TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4 -TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3 -TZ=utc touch -afhm -t $time $dirname/dir1/dir2 -TZ=utc touch -afhm -t $time $dirname/dir1 -TZ=utc touch -afhm -t $time $dirname/file -TZ=utc touch -afhm -t $time $dirname -F=test_read_format_isorr_rockridge_moved.iso.Z -mkhybrid -R -uid 1 -gid 2 $dirname | compress > $F -uuencode $F $F > $F.uu -exit 1 - */ - -DEFINE_TEST(test_read_format_isorr_rr_moved) -{ - const char *refname = "test_read_format_iso_rockridge_rr_moved.iso.Z"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_all(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* Retrieve each of the 8 files on the ISO image and - * verify that each one is what we expect. */ - for (i = 0; i < 13; ++i) { - assertEqualInt(0, archive_read_next_header(a, &ae)); - - if (strcmp(".", archive_entry_pathname(ae)) == 0) { - /* '.' root directory. */ - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - /* Now, we read timestamp recorded by RRIP "TF". */ - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - /* Now, we read links recorded by RRIP "PX". */ - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - } else if (strcmp("dir1", archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2", - archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1/dir2", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2/dir3", - archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1/dir2/dir3", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2/dir3/dir4", - archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1/dir2/dir3/dir4", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2/dir3/dir4/dir5", - archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1/dir2/dir3/dir4/dir5", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6", - archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7", - archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7" - "/dir8", - archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7" - "/dir8", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7" - "/dir8/dir9", - archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7" - "/dir8/dir9", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7" - "/dir8/dir9/dir10", - archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7" - "/dir8/dir9/dir10", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(12345684, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello\n", 6); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7" - "/dir8/dir9/dir10/deep", - archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7" - "/dir8/dir9/dir10/deep", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(12345684, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello\n", 6); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else { - failure("Saw a file that shouldn't have been there"); - assertEqualString(archive_entry_pathname(ae), ""); - } - } - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - - diff --git a/lib/libarchive/test/test_read_format_isozisofs_bz2.c b/lib/libarchive/test/test_read_format_isozisofs_bz2.c deleted file mode 100644 index a4f392e..0000000 --- a/lib/libarchive/test/test_read_format_isozisofs_bz2.c +++ /dev/null @@ -1,187 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* -Execute the following command to rebuild the data for this program: - tail -n +32 test_read_format_isozisofs_bz2.c | /bin/sh - -rm -rf /tmp/iso /tmp/ziso -mkdir /tmp/iso -mkdir /tmp/iso/dir -echo "hello" >/tmp/iso/file -dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file -ln /tmp/iso/file /tmp/iso/hardlink -(cd /tmp/iso; ln -s file symlink) -(cd /tmp/iso; ln -s /tmp/ symlink2) -(cd /tmp/iso; ln -s /tmp/../ symlink3) -(cd /tmp/iso; ln -s .././../tmp/ symlink4) -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink -mkzftree /tmp/iso /tmp/ziso -TZ=utc touch -afhm -t 197001020000.01 /tmp/ziso /tmp/ziso/file /tmp/ziso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/ziso/symlink -F=test_read_format_iso_zisofs.iso.Z -mkhybrid -R -uid 1 -gid 2 -z /tmp/ziso | compress > $F -uuencode $F $F > $F.uu -exit 1 - - */ - -DEFINE_TEST(test_read_format_isozisofs_bz2) -{ - const char *refname = "test_read_format_iso_zisofs.iso.Z"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_all(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* Retrieve each of the 8 files on the ISO image and - * verify that each one is what we expect. */ - for (i = 0; i < 8; ++i) { - assertEqualInt(0, archive_read_next_header(a, &ae)); - - if (strcmp(".", archive_entry_pathname(ae)) == 0) { - /* '.' root directory. */ - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - /* Now, we read timestamp recorded by RRIP "TF". */ - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - /* Now, we read links recorded by RRIP "PX". */ - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { - int r; - /* A regular file. */ - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(12345684, archive_entry_size(ae)); - r = archive_read_data_block(a, &p, &size, &offset); - if (r == ARCHIVE_FAILED) { - skipping("Can't read body of ZISOFS entry."); - } else { - assertEqualInt(ARCHIVE_OK, r); - assertEqualInt(0, offset); - assertEqualMem(p, "hello\n", 6); - } - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { - /* A hardlink to the regular file. */ - /* Note: If "hardlink" gets returned before "file", - * then "hardlink" will get returned as a regular file - * and "file" will get returned as the hardlink. - * This test should tolerate that, since it's a - * perfectly permissible thing for libarchive to do. */ - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_hardlink(ae)); - assertEqualInt(0, archive_entry_size_is_set(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp (an absolute path) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp/.. (with a ".." component) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp/..", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { - /* A symlink to a path with ".." and "." components */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".././../tmp", - archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else { - failure("Saw a file that shouldn't have been there"); - assertEqualString(archive_entry_pathname(ae), ""); - } - } - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - - diff --git a/lib/libarchive/test/test_read_format_mtree.c b/lib/libarchive/test/test_read_format_mtree.c deleted file mode 100644 index 93e658f..0000000 --- a/lib/libarchive/test/test_read_format_mtree.c +++ /dev/null @@ -1,186 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static void -test_read_format_mtree1(void) -{ - const char reffile[] = "test_read_format_mtree.mtree"; - char buff[16]; - struct archive_entry *ae; - struct archive *a; - FILE *f; - - extract_reference_file(reffile); - - /* - * An access error occurred on some platform when mtree - * format handling open a directory. It is for through - * the routine which open a directory that we create - * "dir" and "dir2" directories. - */ - assertMakeDir("dir", 0775); - assertMakeDir("dir2", 0775); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_file(a, reffile, 11)); - - /* - * Read "file", whose data is available on disk. - */ - f = fopen("file", "wb"); - assert(f != NULL); - assertEqualInt(3, fwrite("hi\n", 1, 3, f)); - fclose(f); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); - assertEqualString(archive_entry_pathname(ae), "file"); - assertEqualInt(archive_entry_uid(ae), 18); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123); - assertEqualInt(archive_entry_size(ae), 3); - assertEqualInt(3, archive_read_data(a, buff, 3)); - assertEqualMem(buff, "hi\n", 3); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir"); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir/file with space"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "file with space"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/dir3a"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/fullindir2"); - assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/indir2"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/dir3b"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "notindir"); - - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - -static void -test_read_format_mtree2(void) -{ - static char archive[] = - "#mtree\n" - "d type=dir content=.\n"; - struct archive_entry *ae; - struct archive *a; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); - assertEqualString(archive_entry_pathname(ae), "d"); - assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - -/* - * Reported to libarchive.googlecode.com as Issue 121. - */ -static void -test_read_format_mtree3(void) -{ - static char archive[] = - "#mtree\n" - "a type=file contents=file\n" - "b type=link link=a\n" - "c type=file contents=file\n"; - struct archive_entry *ae; - struct archive *a; - - assertMakeDir("mtree3", 0777); - assertChdir("mtree3"); - assertMakeFile("file", 0644, "file contents"); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "a"); - assertEqualInt(archive_entry_filetype(ae), AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "b"); - assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "c"); - assertEqualInt(archive_entry_filetype(ae), AE_IFREG); - - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - assertChdir(".."); -} - - - -DEFINE_TEST(test_read_format_mtree) -{ - test_read_format_mtree1(); - test_read_format_mtree2(); - test_read_format_mtree3(); -} diff --git a/lib/libarchive/test/test_read_format_mtree.mtree.uu b/lib/libarchive/test/test_read_format_mtree.mtree.uu deleted file mode 100644 index 9fa0d9b..0000000 --- a/lib/libarchive/test/test_read_format_mtree.mtree.uu +++ /dev/null @@ -1,13 +0,0 @@ -$FreeBSD$ - -begin 644 test_read_format_mtree.mtree -M(VUT7!E/61I<@H@9FEL95PP-#!W:71H7#`T,'-P86-E('1Y<&4]9FEL -M92!U:60],3@*("XN"F9I;&5<,#0P=VET:%PP-#!S<&%C92!T>7!E/69I;&4* -M9&ER,B!T>7!E/61I<@H@9&ER,V$@='EP93UD:7(*("!I;F1I7!E/61I<@H@(&EN9&ER,V(@ -M='EP93UF:6QE"B`@+BX*("XN"FYO=&EN9&ER('1Y<&4]9FEL90ID:7(R+V9U -3;&QI;F1I',205,'f',29,170,227,'[',179,139, -'\'','L','o',211,':',178,'0',162,134,'*','>','8',24,153,230,147,'R','?',23, -'r','E','8','P',144,237,7,140,'W'}; - -DEFINE_TEST(test_read_format_tbz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r != ARCHIVE_OK) { - skipping("Bzip2 support"); - archive_read_finish(a); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - diff --git a/lib/libarchive/test/test_read_format_tgz.c b/lib/libarchive/test/test_read_format_tgz.c deleted file mode 100644 index 6b27d3c..0000000 --- a/lib/libarchive/test/test_read_format_tgz.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { -31,139,8,0,222,'C','p','C',0,3,211,'c',160,'=','0','0','0','0','7','5','U', -0,210,134,230,166,6,200,'4',28,'(',24,26,24,27,155,24,152,24,154,27,155,')', -24,24,26,152,154,25,'2','(',152,210,193,'m',12,165,197,'%',137,'E','@',167, -148,'d',230,226,'U','G','H',30,234,15,'8','=',10,'F',193,'(',24,5,131,28, -0,0,29,172,5,240,0,6,0,0}; - -DEFINE_TEST(test_read_format_tgz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_GZIP); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK,archive_read_finish(a)); -} - - diff --git a/lib/libarchive/test/test_read_format_tlz.c b/lib/libarchive/test/test_read_format_tlz.c deleted file mode 100644 index 652d1cd..0000000 --- a/lib/libarchive/test/test_read_format_tlz.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { - 93, 0, 0,128, 0,255,255,255,255,255,255,255,255, 0, 23, 0, - 51, 80, 24,164,204,238, 45, 77, 28,191, 13,144, 8, 10, 70, 5, -173,215, 47,132,237,145,162, 96, 6,131,168,152, 8,135,161,189, - 73,110,132, 27,195, 52,109,203, 22, 17,168,211, 18,181, 76, 93, -120, 88,154,155,244,141,193,206,170,224, 80,137,134, 67, 1, 9, -123,121,189, 74,137,197, 63,255,214, 55,119, 0 -}; - -DEFINE_TEST(test_read_format_tlz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_LZMA); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} diff --git a/lib/libarchive/test/test_read_format_txz.c b/lib/libarchive/test/test_read_format_txz.c deleted file mode 100644 index 4d088b2..0000000 --- a/lib/libarchive/test/test_read_format_txz.c +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { -253, 55,122, 88, 90, 0, 0, 4,230,214,180, 70, 2, 0, 33, 1, - 22, 0, 0, 0,116, 47,229,163,224, 5,255, 0, 73, 93, 0, 23, - 0, 51, 80, 24,164,204,238, 45, 77, 28,191, 13,144, 8, 10, 70, - 5,173,215, 47,132,237,145,162, 96, 6,131,168,152, 8,135,161, -189, 73,110,132, 27,195, 52,109,203, 22, 17,168,211, 18,181, 76, - 93,120, 88,154,155,244,141,193,206,170,224, 80,137,134, 67, 1, - 9,123,121,188,247, 28,139, 0, 0, 0, 0, 0,112,184, 17, 5, -103, 16, 8, 73, 0, 1,101,128, 12, 0, 0, 0, 30, 69, 92, 96, -177,196,103,251, 2, 0, 0, 0, 0, 4, 89, 90 -}; - -DEFINE_TEST(test_read_format_txz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} diff --git a/lib/libarchive/test/test_read_format_tz.c b/lib/libarchive/test/test_read_format_tz.c deleted file mode 100644 index 3dd001f..0000000 --- a/lib/libarchive/test/test_read_format_tz.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { -31,157,144,'.',0,8,28,'H',176,160,193,131,8,19,'*','\\',200,176,'!','B',24, -16,'o',212,168,1,2,0,196,24,18,'a','T',188,152,'q','#',196,143,' ','5',198, -128,'1','c',6,13,24,'4','0',206,176,1,2,198,200,26,'6','b',0,0,'Q',195,161, -205,155,'8','s',234,4,'P','g',14,157,'0','r',',',194,160,147,166,205,206, -132,'D',141,30,'=',24,'R',163,'P',144,21,151,'J',157,'J',181,170,213,171, -'X',179,'j',221,202,181,171,215,175,'`',195,138,29,'K',182,172,217,179,'h', -211,170,']',203,182,173,219,183,'g',1}; - -DEFINE_TEST(test_read_format_tz) -{ - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - failure("archive_compression_name(a)=\"%s\"", - archive_compression_name(a)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - failure("archive_format_name(a)=\"%s\"", archive_format_name(a)); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - - diff --git a/lib/libarchive/test/test_read_format_xar.c b/lib/libarchive/test/test_read_format_xar.c deleted file mode 100644 index a696677..0000000 --- a/lib/libarchive/test/test_read_format_xar.c +++ /dev/null @@ -1,697 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#define UID 1001 -#define UNAME "cue" -#define GID 1001 -#define GNAME "cue" - -/* Verify that a file records with hardlink. -#How to make -echo "hellohellohello" > f1 -chown $UNAME:$GNAME f1 -chmod 0644 f1 -ln f1 hardlink -chown $UNAME:$GNAME hardlink -chmod 0644 hardlink -env TZ=utc touch -afm -t 197001020000.01 f1 hardlink -xar -cf archive1.xar f1 hardlink -od -t x1 archive1.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive1.xar.txt -*/ -static unsigned char archive1[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xc6, -0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x70,0x00,0x00,0x00,0x01,0x78,0xda,0xc4,0x54, -0xc9,0x6e,0xdb,0x30,0x14,0xbc,0xe7,0x2b,0x08,0xdd,0x55,0xae,0xb6,0x45,0x83,0x56, -0xd0,0x4b,0xd1,0x7b,0xd3,0x4b,0x6f,0x34,0x17,0x89,0x88,0x36,0x48,0x54,0xe0,0xe4, -0xeb,0x4b,0x52,0x52,0x0c,0xa7,0x71,0x6f,0x45,0x01,0x01,0x1a,0x0e,0x87,0xa3,0xa7, -0xf7,0x06,0x14,0x8f,0x97,0xb6,0x01,0x2f,0x66,0x9c,0x5c,0xdf,0x9d,0x32,0xfc,0x05, -0x65,0xc0,0x74,0xaa,0xd7,0xae,0xab,0x4e,0xd9,0xcf,0xa7,0x6f,0x79,0x91,0x3d,0x96, -0x0f,0xe2,0x22,0xc7,0xf2,0x01,0x08,0xdf,0xab,0xf0,0x02,0x42,0x8d,0x46,0xfa,0x70, -0x22,0xf7,0xae,0x35,0x25,0x41,0x88,0xe7,0x98,0xe4,0x88,0x3c,0x61,0x7a,0xa4,0xe8, -0x48,0xb9,0x80,0xb7,0x92,0x74,0xa8,0x36,0xea,0x79,0x9a,0x5b,0x30,0xf9,0xd7,0xc6, -0x9c,0xb2,0xa9,0x96,0x38,0x8b,0x3b,0x40,0xf4,0xd6,0x4e,0xc6,0x97,0x48,0xc0,0x15, -0x25,0x76,0x72,0x6f,0xd1,0x5c,0xc0,0x04,0xa2,0x05,0xdc,0x3c,0xd2,0xca,0xba,0xc6, -0x00,0xa7,0x4f,0x19,0x59,0x6d,0xd4,0x9d,0x72,0xd8,0xaf,0x70,0x72,0xab,0x03,0x88, -0x36,0x41,0xcc,0x0f,0x28,0x47,0x38,0xca,0x10,0x3a,0xc6,0x07,0x07,0x59,0x7b,0x95, -0xc9,0x7b,0x3f,0x17,0x64,0xf2,0x2a,0xab,0xc6,0x7e,0x1e,0x4a,0x35,0x1b,0x01,0x17, -0xb8,0xb0,0x4e,0x97,0x18,0x21,0x1c,0xc8,0x80,0x12,0x35,0x4f,0x66,0x5c,0x74,0x09, -0x2d,0xdc,0xbb,0x6c,0xde,0x64,0x6d,0xaf,0x4d,0x89,0xf6,0x8c,0x85,0x62,0x22,0x4c, -0xa4,0x7f,0x1d,0x0c,0x68,0x5c,0xf7,0x1c,0x66,0x94,0x95,0xb5,0x1c,0x75,0x5c,0x08, -0x18,0xf9,0x45,0xd1,0xc9,0x50,0xd0,0x75,0x23,0x2d,0x53,0xcb,0x62,0x97,0x6e,0xdb, -0xb5,0x75,0x5d,0x4b,0x2f,0x13,0x02,0xa2,0x31,0x5d,0xe5,0xeb,0x92,0x50,0x01,0x57, -0xb8,0xf0,0xeb,0x38,0xc8,0xed,0x64,0xd6,0xd1,0xe0,0xfd,0x75,0x34,0x81,0xdb,0x72, -0xb3,0xcd,0x57,0x0e,0x43,0xe3,0x54,0x0a,0x01,0xbc,0xe4,0xd5,0x9b,0x1b,0x32,0xb8, -0x4a,0xe5,0xa8,0x6a,0xf7,0x62,0x74,0xfe,0x31,0x13,0x3f,0xbe,0x7f,0x0d,0xd5,0xd9, -0x82,0x52,0x4d,0xac,0x56,0x98,0x53,0xc6,0xa9,0x3c,0xb3,0x82,0x4b,0x2d,0x09,0xb5, -0x85,0x3d,0x70,0x6c,0xf7,0xc4,0x2a,0xba,0xe7,0x45,0x98,0xc3,0x47,0xa3,0xad,0x96, -0x8b,0x1f,0xa5,0xf2,0x77,0xbf,0xb0,0xd3,0x07,0x76,0x56,0x67,0x75,0xe0,0x9a,0x5a, -0x7e,0xb6,0x4c,0xda,0xe0,0xcd,0x8a,0xa2,0x40,0x86,0xed,0xc8,0x7e,0xc7,0xac,0x41, -0x8a,0x87,0x1c,0xff,0xe9,0xb4,0x34,0x0f,0xbe,0x77,0xef,0x9f,0xc4,0xee,0x73,0xd9, -0x7f,0x8c,0x5d,0x3f,0xba,0xca,0x75,0xb2,0xf9,0x4b,0xfa,0x2c,0xfe,0x24,0x77,0x41, -0x15,0x2f,0x0d,0x01,0xd3,0x15,0xf2,0x1b,0x00,0x00,0xff,0xff,0x03,0x00,0x88,0x32, -0x49,0x7b,0x67,0xbf,0xc6,0x01,0x29,0xf2,0x1c,0x40,0x05,0x3c,0x49,0x25,0x9f,0xab, -0x7c,0x8e,0xc5,0xa5,0x79,0xe0,0x78,0xda,0xca,0x48,0xcd,0xc9,0xc9,0xcf,0x80,0x13, -0x5c,0x00,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7,0x06,0x47 -}; - -static void verify0(struct archive *a, struct archive_entry *ae) -{ - const void *p; - size_t size; - off_t offset; - - assert(archive_entry_filetype(ae) == AE_IFREG); - assertEqualInt(archive_entry_mode(ae) & 0777, 0644); - assertEqualInt(archive_entry_uid(ae), UID); - assertEqualInt(archive_entry_gid(ae), GID); - assertEqualString(archive_entry_uname(ae), UNAME); - assertEqualString(archive_entry_gname(ae), GNAME); - assertEqualString(archive_entry_pathname(ae), "f1"); - assert(archive_entry_hardlink(ae) == NULL); - assert(archive_entry_symlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 86401); - assertEqualInt(archive_entry_size(ae), 16); - assertEqualInt(archive_read_data_block(a, &p, &size, &offset), 0); - assertEqualInt((int)size, 16); - assertEqualInt((int)offset, 0); - assertEqualInt(memcmp(p, "hellohellohello\n", 16), 0); -} - -static void verify1(struct archive *a, struct archive_entry *ae) -{ - (void)a; /* UNUSED */ - /* A hardlink is not a symlink. */ - assert(archive_entry_filetype(ae) != AE_IFLNK); - /* Nor is it a directory. */ - assert(archive_entry_filetype(ae) != AE_IFDIR); - assertEqualInt(archive_entry_mode(ae) & 0777, 0644); - assertEqualInt(archive_entry_uid(ae), UID); - assertEqualInt(archive_entry_gid(ae), GID); - assertEqualString(archive_entry_uname(ae), UNAME); - assertEqualString(archive_entry_gname(ae), GNAME); - assertEqualString(archive_entry_pathname(ae), "hardlink"); - assertEqualString(archive_entry_hardlink(ae), "f1"); - assert(archive_entry_symlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 86401); - assertEqualInt(archive_entry_nlink(ae), 2); -} - -/* Verify that symlinks are read correctly. -#How to make -echo "hellohellohello" > f1 -chown $UNAME:$GNAME f1 -chmod 0644 f1 -ln -s f1 symlink -chown $UNAME:$GNAME symlink -chmod 0644 symlink -env TZ=utc touch -afm -t 197001020000.01 f1 symlink -xar -cf archive2.xar f1 symlink -od -t x1 archive2.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive2.xar.txt -*/ -static unsigned char archive2[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xe8, -0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x84,0x00,0x00,0x00,0x01,0x78,0xda,0xb4,0x54, -0xcb,0x6e,0xa3,0x30,0x14,0xdd,0xf7,0x2b,0x90,0xf7,0x8c,0x1f,0x40,0x82,0x23,0xe3, -0xaa,0x9b,0x6a,0xf6,0xd3,0xd9,0xcc,0xce,0xf1,0x83,0x58,0xe5,0x25,0x70,0xaa,0xa4, -0x5f,0x3f,0xb6,0x09,0x4d,0xd3,0x30,0xdd,0x8d,0x84,0xc4,0xf5,0xf1,0xb9,0xc7,0x97, -0x7b,0x0f,0x66,0x8f,0xa7,0xb6,0x49,0xde,0xf4,0x38,0xd9,0xbe,0xab,0x00,0xfe,0x81, -0x40,0xa2,0x3b,0xd9,0x2b,0xdb,0xd5,0x15,0xf8,0xfd,0xf2,0x9c,0x96,0xe0,0x91,0x3f, -0xb0,0x93,0x18,0xf9,0x43,0xc2,0x5c,0x2f,0xfd,0x2b,0x61,0x72,0xd4,0xc2,0xf9,0x8c, -0xd4,0xd9,0x56,0x73,0x82,0x10,0x4d,0x31,0x49,0x11,0x79,0xc1,0xd9,0x2e,0x2b,0x76, -0xb8,0x60,0xf0,0x96,0x12,0x93,0x0e,0x5a,0xbe,0x4e,0xc7,0x36,0x99,0xdc,0xb9,0xd1, -0x15,0x98,0x0e,0x02,0x83,0xb0,0x93,0xb0,0xde,0x98,0x49,0x3b,0x8e,0x18,0xbc,0x44, -0x11,0x9d,0xec,0x7b,0x10,0x67,0x30,0x06,0x41,0x02,0x2e,0x1a,0x71,0x65,0x6c,0xa3, -0x13,0xab,0x2a,0x40,0x2e,0x32,0xf2,0xae,0x1c,0xb4,0xcb,0xd1,0x0e,0xd1,0x3f,0x3e, -0x73,0xa9,0x23,0x61,0xed,0x37,0xb4,0xf6,0x4a,0x13,0xdf,0xd0,0xc4,0x95,0x56,0x8f, -0xfd,0x71,0xe0,0xf2,0xa8,0x19,0x9c,0xc3,0x19,0xb5,0x8a,0x63,0x84,0xb0,0x07,0x7d, -0x14,0xa1,0xe3,0xa4,0xc7,0x99,0x17,0xa3,0x19,0xfb,0xa0,0x1d,0x17,0x5a,0xdb,0x2b, -0xcd,0xd1,0xb6,0xf0,0x3d,0x8c,0x61,0x04,0x1b,0xdb,0xbd,0x26,0xee,0x3c,0xf8,0xb6, -0x85,0xaf,0x06,0xdc,0xf8,0x94,0x00,0xce,0xdb,0x61,0x87,0x4f,0xe7,0x36,0x20,0x0c, -0xc6,0x55,0xc4,0x3b,0xd1,0x7e,0xc2,0xe3,0x2a,0xb6,0x31,0x68,0xdc,0xb6,0x70,0x99, -0x84,0x12,0x4e,0xc4,0xc8,0x9f,0xa9,0xbb,0xda,0x1d,0x38,0xc9,0xfc,0x49,0x73,0x38, -0xe3,0x97,0x11,0x91,0xdb,0x69,0x5d,0xc6,0x85,0x37,0xd7,0x71,0x79,0x6c,0xf1,0xd2, -0x32,0x73,0x31,0x0c,0x8d,0x95,0xd1,0x18,0xf0,0x94,0xd6,0xef,0x76,0x00,0xf0,0x42, -0x15,0xa3,0x3c,0xd8,0x37,0xad,0xd2,0xaf,0x3e,0xf9,0xf5,0xf3,0xc9,0x57,0x67,0xca, -0x2c,0x53,0xc4,0x28,0x89,0x69,0x96,0xd3,0x4c,0xec,0xf3,0x92,0x0a,0x25,0x48,0x66, -0x4a,0xb3,0xa5,0xd8,0x6c,0x88,0x91,0xd9,0x86,0x96,0x7e,0x36,0x5f,0x85,0x96,0x5a, -0x4e,0x6e,0x14,0xd2,0xfd,0xf3,0x84,0x42,0x6d,0xf3,0xbd,0xdc,0xcb,0x2d,0x55,0x99, -0xa1,0x7b,0x93,0x0b,0xe3,0xb5,0xf3,0xb2,0x2c,0x91,0xce,0x0b,0xb2,0x29,0x72,0xa3, -0x91,0xa4,0x94,0xc1,0x7b,0xa5,0xb9,0x79,0xf0,0xa3,0x7b,0x2b,0x56,0x9c,0xff,0x0c, -0xb2,0x66,0x45,0x4c,0xb7,0x28,0x45,0x38,0xd0,0x90,0x37,0x98,0x7f,0xf0,0x9a,0x15, -0xd7,0x69,0xff,0xdd,0x8a,0x9b,0x3c,0xff,0x6c,0xc5,0xe0,0xae,0x24,0x18,0xaa,0x02, -0xfd,0x68,0x6b,0xdb,0x89,0x06,0xf0,0x83,0x18,0xd5,0xaa,0xf9,0x82,0x4f,0xef,0x7c, -0xe7,0x59,0xe1,0x22,0x61,0x30,0x5e,0x2b,0x7f,0x01,0x00,0x00,0xff,0xff,0x03,0x00, -0x2b,0xab,0x4f,0xf9,0xbb,0xf7,0x90,0xb5,0x34,0x8f,0x7c,0xae,0x72,0xa0,0x80,0xd2, -0x69,0xc7,0xa2,0xe7,0x44,0x53,0xeb,0x75,0x78,0xda,0xca,0x48,0xcd,0xc9,0xc9,0xcf, -0x80,0x13,0x5c,0x00,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7,0x06,0x47 -}; - -static void verify2(struct archive *a, struct archive_entry *ae) -{ - (void)a; /* UNUSED */ - assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), UID); - assertEqualInt(archive_entry_gid(ae), GID); - assertEqualString(archive_entry_uname(ae), UNAME); - assertEqualString(archive_entry_gname(ae), GNAME); - assertEqualString(archive_entry_pathname(ae), "symlink"); - assertEqualString(archive_entry_symlink(ae), "f1"); - assert(archive_entry_hardlink(ae) == NULL); -} - -/* Character device node. -#How to make -mknod devchar c 0 30 -chown $UNAME:$GNAME devchar -chmod 0644 devchar -env TZ=utc touch -afm -t 197001020000.01 devchar -xar -cf archive3.xar devchar -od -t x1 archive3.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive3.xar.txt -*/ -static unsigned char archive3[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x38, -0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x3b,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x92, -0x4d,0x6e,0xc3,0x20,0x10,0x85,0xf7,0x39,0x05,0xf2,0xde,0x05,0x9c,0x9f,0x36,0xd6, -0x84,0xec,0x7a,0x82,0x74,0xd3,0x1d,0xc2,0x93,0x98,0xd4,0x36,0x11,0xe0,0x28,0xe9, -0xe9,0x0b,0xe3,0xa4,0x69,0xa5,0xaa,0x92,0x25,0x1e,0x8f,0xef,0x8d,0x86,0xc1,0xb0, -0xbd,0xf4,0x1d,0x3b,0xa3,0x0f,0xd6,0x0d,0x9b,0x42,0x3e,0x89,0x82,0xe1,0x60,0x5c, -0x63,0x87,0xc3,0xa6,0x78,0xdb,0xbd,0x96,0x2f,0xc5,0x56,0xcd,0xe0,0xa2,0xbd,0x9a, -0x31,0x88,0xce,0xa4,0x85,0x81,0xf1,0xa8,0x63,0x4a,0x94,0xd1,0xf6,0xa8,0x2a,0x21, -0xd6,0xa5,0xac,0x4a,0x51,0xed,0xa4,0xa8,0xab,0x79,0x2d,0x57,0xc0,0x7f,0x23,0x14, -0x6a,0xd1,0x7c,0x84,0xb1,0x67,0x21,0x5e,0x3b,0xdc,0x14,0xa1,0xd5,0xb2,0xc8,0x27, -0x0c,0xdc,0x7e,0x1f,0x30,0x2a,0x01,0xfc,0xa6,0xc8,0x0d,0xf6,0x33,0x17,0x07,0x4e, -0x22,0x97,0xe0,0xf7,0x1a,0xb4,0xdb,0xdb,0x0e,0x99,0x6d,0x52,0xdb,0xb7,0x32,0xe6, -0xaf,0x76,0xaa,0x7a,0xb9,0x7c,0x4f,0xc9,0x7b,0x1f,0x0c,0x7a,0x92,0x72,0xfd,0x2c, -0x4a,0x21,0x33,0x26,0x44,0x9d,0x3f,0x99,0xb0,0xfe,0x81,0xe9,0x7f,0x30,0xfd,0xc0, -0x0e,0xde,0x8d,0x27,0x65,0x46,0x04,0x3e,0xc9,0xc9,0xb5,0x8d,0x92,0x42,0xc8,0x64, -0x26,0x45,0xd6,0x18,0xd0,0x4f,0x1c,0xa9,0xc9,0xfb,0xc6,0xc6,0x3b,0xd6,0xbb,0x06, -0x95,0x58,0x2d,0x16,0xa9,0x99,0x2c,0xc9,0x6c,0xf0,0x6c,0xcd,0xa4,0x13,0x61,0x07, -0xe7,0xd5,0x3c,0x0d,0x66,0x52,0x37,0x57,0x1f,0x93,0xce,0x26,0x09,0x8a,0xf1,0x1f, -0x39,0x88,0xd7,0x13,0x2a,0xd3,0x6a,0xaf,0x4d,0x44,0xcf,0xc2,0x09,0x8d,0xd5,0x1d, -0x70,0xf2,0x89,0x18,0x74,0xba,0x54,0x8a,0x64,0x08,0x38,0xed,0x68,0xea,0x79,0xd0, -0xf9,0xf9,0x39,0xbd,0x3f,0x70,0xfa,0x1b,0xbe,0x00,0x00,0x00,0xff,0xff,0x03,0x00, -0xab,0x43,0xa3,0xac,0x76,0x40,0x1e,0x8b,0x95,0x0d,0x28,0x79,0x79,0x43,0x49,0x4e, -0x16,0xa1,0x56,0x99,0x1f,0x83,0x77,0x41 -}; - -static void verify3(struct archive *a, struct archive_entry *ae) -{ - (void)a; /* UNUSED */ - assertEqualInt(archive_entry_filetype(ae), AE_IFCHR); - assertEqualInt(archive_entry_mode(ae) & 0777, 0644); - assertEqualInt(archive_entry_uid(ae), UID); - assertEqualInt(archive_entry_gid(ae), GID); - assertEqualString(archive_entry_uname(ae), UNAME); - assertEqualString(archive_entry_gname(ae), GNAME); - assertEqualString(archive_entry_pathname(ae), "devchar"); - assert(archive_entry_symlink(ae) == NULL); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 86401); -} - -/* Block device node. -#How to make -mknod devblock b 0 30 -chown $UNAME:$GNAME devblock -chmod 0644 devblock -env TZ=utc touch -afm -t 197001020000.01 devblock -xar -cf archive4.xar devblock -od -t x1 archive4.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive4.xar.txt -*/ -static unsigned char archive4[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x34, -0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x38,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x92, -0xc1,0x6e,0xc2,0x30,0x0c,0x86,0xef,0x3c,0x45,0xd4,0x7b,0x17,0x07,0xd0,0x0a,0x95, -0x09,0xb7,0x3d,0x01,0xbb,0xec,0x96,0xa5,0x06,0x32,0xda,0xa6,0x6a,0x5a,0x04,0x7b, -0xfa,0x25,0x2e,0x8c,0x4d,0x9a,0x26,0x55,0xea,0x97,0x3f,0x9f,0x2d,0x37,0x29,0x6e, -0x2f,0x4d,0x2d,0xce,0xd4,0x07,0xe7,0xdb,0x4d,0xa6,0x9e,0x20,0x13,0xd4,0x5a,0x5f, -0xb9,0xf6,0xb0,0xc9,0x5e,0x77,0x2f,0xf9,0x2a,0xdb,0xea,0x19,0x5e,0x4c,0xaf,0x67, -0x02,0x07,0x6f,0xe3,0x4b,0xa0,0xed,0xc9,0x0c,0xb1,0x22,0x1f,0x5c,0x43,0x7a,0x0e, -0xb0,0xce,0xd5,0x3c,0x87,0xf9,0x4e,0x41,0xb9,0x58,0x95,0xaa,0x40,0xf9,0x5b,0xe1, -0xa2,0x23,0xd9,0x53,0x18,0x1b,0x11,0x86,0x6b,0x4d,0x9b,0x2c,0x1c,0x8d,0xca,0xd2, -0x8e,0x40,0xbf,0xdf,0x07,0x1a,0x34,0xa0,0xbc,0x11,0xa7,0xc1,0x7d,0xa6,0xe6,0x28, -0x19,0x52,0x0b,0x79,0xef,0xc1,0xab,0xbd,0xab,0x49,0xb8,0x2a,0x8e,0x7d,0x6b,0x63, -0xff,0x1e,0x07,0x8a,0xb7,0x58,0x79,0x9f,0x43,0x60,0xc3,0xa8,0xd6,0x05,0xe4,0xa0, -0x92,0x06,0x50,0xa6,0x47,0x45,0xad,0x79,0x68,0xe6,0x1f,0xcd,0x3c,0xb4,0x43,0xef, -0xc7,0x4e,0xdb,0x91,0x50,0x4e,0x38,0xa5,0xae,0xd2,0x0a,0x40,0xc5,0x30,0x12,0x47, -0x63,0xa0,0x7e,0xf2,0x98,0xa6,0xec,0x5b,0x1b,0xef,0x5a,0xe3,0x2b,0xd2,0xf0,0xbc, -0x5c,0xc6,0x61,0x12,0x72,0x58,0xd1,0xd9,0xd9,0x89,0xa3,0xe1,0x5a,0xdf,0xeb,0x45, -0x3c,0x98,0x89,0x6e,0xa9,0xf9,0x88,0x9c,0x42,0x06,0x2e,0x93,0x3f,0xea,0x70,0xb8, -0x76,0xa4,0xdf,0x6b,0x6f,0x4f,0x22,0x74,0x64,0x9d,0xa9,0x51,0x72,0xc6,0xbb,0xad, -0x89,0x1f,0x14,0x75,0x16,0x50,0xf2,0x92,0x8f,0x3c,0x9d,0x72,0xba,0x7b,0xc9,0x97, -0x8f,0x92,0x7f,0x85,0x2f,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0xbe,0x66,0xa2,0x82, -0x3a,0x54,0xd3,0x61,0xaa,0x8e,0x30,0x4c,0xc8,0x36,0x3b,0x7a,0xa4,0xb9,0xef,0xfc, -0x7a,0x5d,0x21,0xde -}; - -static void verify4(struct archive *a, struct archive_entry *ae) -{ - (void)a; /* UNUSED */ - assertEqualInt(archive_entry_filetype(ae), AE_IFBLK); - assertEqualInt(archive_entry_mode(ae) & 0777, 0644); - assertEqualInt(archive_entry_uid(ae), UID); - assertEqualInt(archive_entry_gid(ae), GID); - assertEqualString(archive_entry_uname(ae), UNAME); - assertEqualString(archive_entry_gname(ae), GNAME); - assertEqualString(archive_entry_pathname(ae), "devblock"); - assert(archive_entry_symlink(ae) == NULL); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 86401); -} - -/* Directory. -#How to make -mkdir dir1 -chown $UNAME:$GNAME dir1 -chmod 0755 dir1 -env TZ=utc touch -afm -t 197001020000.01 dir1 -xar -cf archive5.xar dir1 -od -t x1 archive5.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive5.xar.txt -*/ -static unsigned char archive5[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x16, -0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xec,0x00,0x00,0x00,0x01,0x78,0xda,0x74,0x91, -0xc1,0x6e,0xc2,0x30,0x0c,0x86,0xef,0x3c,0x45,0xd4,0x7b,0x17,0xa7,0x83,0x31,0xaa, -0x34,0xdc,0xf6,0x04,0xec,0xb2,0x5b,0x95,0x1a,0x88,0x68,0x1a,0x94,0xa4,0x13,0xdd, -0xd3,0x2f,0x71,0xe9,0xd0,0xa4,0x4d,0xaa,0xd4,0x3f,0xbf,0x3f,0xff,0xb2,0x6c,0xb9, -0xbf,0xd9,0x9e,0x7d,0xa2,0x0f,0xc6,0x0d,0x4d,0x21,0x9e,0xa0,0x60,0x38,0x68,0xd7, -0x99,0xe1,0xd4,0x14,0xef,0x87,0xb7,0xf2,0xb5,0xd8,0xab,0x95,0xbc,0xb5,0x5e,0xad, -0x98,0x8c,0x4e,0xa7,0x1f,0x93,0xda,0x63,0x1b,0x53,0x47,0x19,0x8d,0x45,0x55,0x01, -0xec,0x4a,0x51,0x95,0x50,0x1d,0x04,0xd4,0x6b,0x51,0xaf,0x37,0x92,0xff,0x46,0xa8, -0xe9,0x8c,0xfa,0x12,0x46,0xcb,0x42,0x9c,0x7a,0x6c,0x8a,0x70,0x6e,0x45,0x91,0x2b, -0x4c,0xba,0xe3,0x31,0x60,0x54,0x20,0xf9,0x5d,0x91,0x1b,0xcc,0x57,0x0e,0x97,0x9c, -0x44,0x8e,0xe0,0x4b,0x06,0xbd,0x8e,0xa6,0x47,0x66,0xba,0x34,0xf6,0x3d,0x46,0xff, -0x3d,0xce,0x33,0x7c,0xa4,0xce,0x65,0x0e,0x26,0x2d,0x49,0xb1,0xdb,0x42,0x09,0x22, -0x63,0x00,0x75,0xfe,0x44,0xc2,0xec,0x03,0x6b,0xff,0x49,0x7b,0x49,0x58,0xfb,0xc0, -0x4e,0xde,0x8d,0x57,0xa5,0x47,0x94,0x7c,0x96,0xb3,0x6b,0x3a,0x25,0x00,0x44,0x32, -0x93,0x22,0x6b,0x0c,0xe8,0x67,0x8e,0xd4,0xec,0xfd,0x60,0xe3,0x82,0x59,0xd7,0xa1, -0x82,0xed,0x26,0xed,0x90,0x24,0x99,0x71,0xba,0xa2,0xea,0x8c,0x47,0x1d,0x9d,0x9f, -0x24,0xa7,0x37,0x55,0x86,0xd6,0x52,0x25,0x45,0x90,0xa4,0x35,0xe5,0xcd,0xe4,0x7b, -0x71,0x3a,0x98,0xe4,0x74,0xbe,0x6f,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x23,0x7a, -0x8c,0x2f,0x78,0xe9,0x69,0x28,0x93,0x14,0x72,0x68,0x8d,0xeb,0x42,0x7b,0xf6,0x0f, -0x70,0x64,0xa3,0xff,0xb9,0x35 -}; - -static void verify5(struct archive *a, struct archive_entry *ae) -{ - (void)a; /* UNUSED */ - assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); - assertEqualInt(archive_entry_mtime(ae), 86401); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), UID); - assertEqualInt(archive_entry_gid(ae), GID); - assertEqualString(archive_entry_uname(ae), UNAME); - assertEqualString(archive_entry_gname(ae), GNAME); -} - -/* fifo -#How to make -mkfifo -m 0755 fifo -chown $UNAME:$GNAME fifo -env TZ=utc touch -afm -t 197001020000.01 fifo -xar -cf archive6.xar fifo -od -t x1 archive6.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive6.xar.txt -*/ -static unsigned char archive6[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0e, -0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xe7,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x91, -0xc1,0x6e,0xc3,0x20,0x0c,0x86,0xef,0x7d,0x0a,0xc4,0x3d,0xc3,0x64,0xab,0xda,0x46, -0x94,0xde,0xf6,0x04,0xdd,0x65,0x37,0x44,0x9c,0x16,0x2d,0x84,0x2a,0x90,0xa9,0xdd, -0xd3,0x0f,0x9c,0x66,0xd5,0xa4,0x69,0x12,0x52,0xbe,0xfc,0x7c,0xb6,0x2c,0xac,0x0e, -0x57,0xdf,0xb3,0x4f,0x1c,0xa3,0x0b,0xc3,0x9e,0xcb,0x27,0xe0,0x0c,0x07,0x1b,0x5a, -0x37,0x9c,0xf6,0xfc,0xed,0xf8,0x5a,0x6d,0xf9,0x41,0xaf,0xd4,0xd5,0x8c,0x7a,0xc5, -0x54,0x0a,0x36,0x7f,0x98,0xb2,0x23,0x9a,0x94,0x2b,0xaa,0xe4,0x3c,0xea,0x1a,0x60, -0x57,0xc9,0xba,0x82,0xfa,0x28,0x65,0xf3,0x02,0x4d,0xbd,0x55,0xe2,0xb7,0x42,0x45, -0x67,0xb4,0x1f,0x71,0xf2,0x2c,0xa6,0x5b,0x8f,0x7b,0x1e,0xcf,0x46,0xf2,0x72,0xc3, -0x54,0xe8,0xba,0x88,0x49,0x83,0x12,0x77,0xa2,0x34,0xba,0xaf,0xd2,0x5c,0x09,0x82, -0xd2,0x42,0x2c,0x3d,0xe8,0xaf,0x73,0x3d,0x32,0xd7,0xe6,0xb1,0xef,0x6d,0xec,0xdf, -0xe3,0xc8,0xe7,0xf7,0x5c,0xb9,0xcc,0xc1,0x94,0x27,0x94,0xbb,0x0d,0x54,0x20,0x8b, -0x06,0xd0,0x94,0x23,0xb3,0xe6,0x1f,0x9a,0xf9,0x47,0x33,0x0f,0xed,0x34,0x86,0xe9, -0xa2,0xed,0x84,0x4a,0xcc,0x38,0xa7,0xae,0xd5,0x12,0x40,0xe6,0x30,0x13,0x45,0x53, -0xc4,0x71,0xf6,0x88,0xe6,0xec,0x47,0x9b,0x16,0xcd,0x87,0x16,0x35,0x6c,0xd6,0xeb, -0x3c,0x4c,0x41,0x0a,0xd3,0xed,0x82,0xba,0x73,0x5d,0x50,0x82,0x90,0xc2,0xc1,0xf8, -0x25,0x24,0xa4,0x17,0x2a,0x8f,0x52,0x56,0x25,0x68,0x57,0x4a,0xd0,0xe6,0xbe,0x01, -0x00,0x00,0xff,0xff,0x03,0x00,0x44,0x19,0x8a,0x2a,0x82,0xbc,0x8c,0xae,0x97,0xa7, -0x7d,0x65,0xa5,0x82,0xdb,0xaa,0xc2,0xcb,0xbe,0xf0,0x1f,0xd1,0xf9,0x56 -}; - -static void verify6(struct archive *a, struct archive_entry *ae) -{ - (void)a; /* UNUSED */ - assertEqualInt(archive_entry_filetype(ae), AE_IFIFO); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), UID); - assertEqualInt(archive_entry_gid(ae), GID); - assertEqualString(archive_entry_uname(ae), UNAME); - assertEqualString(archive_entry_gname(ae), GNAME); - assertEqualString(archive_entry_pathname(ae), "fifo"); - assert(archive_entry_symlink(ae) == NULL); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 86401); -} - -/* Verify that a file records with directory name. -#How to make -mkdir dir1 -echo "hellohellohello" > dir1/f1 -chown $UNAME:$GNAME dir1/f1 -chmod 0644 dir1/f1 -env TZ=utc touch -afm -t 197001020000.01 dir1/f1 -xar -cf archive7.xar dir1/f1 -od -t x1 archive7.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive7.xar.txt -*/ - -static unsigned char archive7[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xbb, -0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x8a,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x53, -0xc9,0x6e,0xdb,0x30,0x14,0xbc,0xe7,0x2b,0x04,0xdd,0x55,0x2e,0xa2,0x16,0x1a,0xb4, -0x82,0x5e,0x8a,0xdc,0x93,0x5e,0x7a,0xa3,0xb9,0xd8,0x44,0xb5,0x41,0xa2,0x02,0x3b, -0x5f,0x5f,0x92,0xa2,0x1c,0xbb,0x59,0x00,0x01,0x1a,0x3e,0xce,0x1b,0x0d,0x9f,0x86, -0xec,0xf1,0xdc,0xb5,0xc9,0xab,0x9a,0x66,0x33,0xf4,0xfb,0x14,0xfd,0x80,0x69,0xa2, -0x7a,0x31,0x48,0xd3,0x1f,0xf7,0xe9,0xef,0x97,0x5f,0x59,0x9d,0x3e,0x36,0x0f,0xec, -0xcc,0xa7,0xe6,0x21,0x61,0x76,0x10,0xee,0x95,0x30,0x31,0x29,0x6e,0x5d,0x47,0x66, -0x4d,0xa7,0x1a,0x0c,0x21,0xcd,0x10,0xce,0x20,0x7e,0x41,0x68,0x57,0xe0,0x5d,0x51, -0x31,0x70,0x4f,0x09,0x4d,0x27,0x25,0xfe,0xce,0x4b,0x97,0xcc,0xf6,0xd2,0xaa,0x7d, -0x3a,0x9f,0x38,0x4a,0xfd,0x4e,0xc2,0x06,0xad,0x67,0x65,0x1b,0xc8,0x40,0x44,0xa1, -0x3a,0x9b,0x37,0x2f,0xce,0x40,0x00,0x5e,0x02,0x6c,0x1a,0x61,0xa5,0x4d,0xab,0x12, -0x23,0x9d,0xed,0x28,0x63,0x2f,0xa3,0x6a,0xa4,0x99,0x94,0xb0,0xc3,0x74,0x61,0x20, -0xac,0xc3,0x4e,0xcf,0xbb,0xb0,0x83,0x18,0x08,0x30,0x14,0xaf,0xfd,0x78,0xed,0x4f, -0x98,0xe4,0x96,0xaf,0x30,0x61,0xad,0xea,0x8f,0xf6,0xd4,0xe0,0x9c,0x81,0x08,0xe3, -0x46,0xb4,0x88,0xef,0xdd,0x6e,0x7e,0x51,0xf9,0xee,0xd7,0x17,0xb7,0x69,0x6e,0xa7, -0xe6,0xe3,0xd8,0x1a,0x11,0x46,0x03,0xce,0xd9,0xf1,0xcd,0x8c,0x29,0xd8,0xb8,0x7c, -0x12,0x27,0xf3,0xaa,0x64,0xf6,0xff,0xa8,0x9e,0x9f,0x7e,0xba,0x33,0xea,0x3a,0xcf, -0x25,0xd6,0x52,0x20,0x9a,0x13,0x9a,0xf3,0x03,0xa9,0x29,0x97,0x1c,0xe7,0xba,0xd6, -0x15,0x45,0xba,0xc4,0x5a,0xe4,0x25,0xad,0x19,0xf8,0x20,0x74,0x75,0x73,0xb6,0x13, -0x17,0xf6,0xcb,0x4f,0x14,0xb2,0x22,0x07,0x71,0x10,0x15,0x95,0xb9,0xa6,0x07,0x4d, -0xb8,0x76,0xe2,0xa4,0xae,0x6b,0xa8,0x48,0x81,0xcb,0x82,0x68,0x05,0x05,0xa5,0x0c, -0x7c,0x54,0x8a,0x33,0x04,0xef,0x43,0x64,0xe2,0xf3,0x7c,0x90,0xfa,0x8f,0xfb,0x95, -0x5b,0x30,0x1c,0xaf,0x0b,0x18,0xd1,0x0a,0x66,0x10,0x79,0x1e,0x84,0x3b,0xff,0x20, -0xc7,0xeb,0x6e,0x78,0xfc,0x1b,0x1e,0xbf,0xe1,0x1d,0xa7,0x61,0x19,0x1b,0xb1,0x28, -0x06,0x56,0x18,0xcb,0x46,0x36,0x08,0x42,0x17,0x02,0x8f,0xd6,0xda,0x32,0xab,0x69, -0x65,0x06,0x14,0x8b,0x57,0xe2,0x72,0x25,0x76,0x83,0x54,0x0d,0x2c,0x09,0x71,0x96, -0x3c,0x5c,0xab,0x21,0x62,0x3e,0x48,0x37,0x69,0x8b,0x71,0xd3,0x77,0x61,0x03,0x9e, -0xb4,0x86,0x38,0x22,0xd7,0xe1,0xaf,0x13,0x03,0xe1,0x72,0xfd,0x03,0x00,0x00,0xff, -0xff,0x03,0x00,0x8d,0xb1,0x06,0x76,0xa6,0x7a,0xc3,0xbb,0x13,0x3d,0x45,0xe2,0x2b, -0x3b,0xd0,0x88,0xc7,0x58,0x7b,0xbd,0x30,0x9d,0x01,0x44,0x78,0xda,0xca,0x48,0xcd, -0xc9,0xc9,0xcf,0x80,0x13,0x5c,0x00,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7, -0x06,0x47 -}; - -static void verify7(struct archive *a, struct archive_entry *ae) -{ - (void)a; /* UNUSED */ - assert(archive_entry_filetype(ae) == AE_IFREG); - assertEqualInt(archive_entry_mode(ae) & 0777, 0644); - assertEqualInt(archive_entry_uid(ae), UID); - assertEqualInt(archive_entry_gid(ae), GID); - assertEqualString(archive_entry_uname(ae), UNAME); - assertEqualString(archive_entry_gname(ae), GNAME); - assertEqualString(archive_entry_pathname(ae), "dir1/f1"); - assert(archive_entry_hardlink(ae) == NULL); - assert(archive_entry_symlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 86401); -} - -/* Verify that a file records with bzip2 compression -#How to make -echo "hellohellohello" > f1 -chown $UNAME:$GNAME f1 -chmod 0644 f1 -env TZ=utc touch -afm -t 197001020000.01 f1 -xar --compression bzip2 -cf archive8.xar f1 -od -t x1 archive8.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive8.xar.txt -*/ - -static unsigned char archive8[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xb1, -0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x42,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x53, -0xcb,0x6e,0xdc,0x20,0x14,0xdd,0xe7,0x2b,0x90,0xf7,0x0e,0x60,0xe3,0x07,0x23,0x86, -0xa8,0x9b,0xa8,0xfb,0x4e,0x37,0xdd,0x61,0x1e,0x63,0x14,0xbf,0x64,0xe3,0x68,0x92, -0xaf,0x2f,0x60,0x3b,0xa3,0x34,0x6d,0x25,0x4b,0x3e,0x1c,0x0e,0xe7,0x5e,0xee,0xe5, -0xb2,0xa7,0x5b,0xdf,0x81,0x57,0x3d,0x2f,0x76,0x1c,0xce,0x09,0x7e,0x44,0x09,0xd0, -0x83,0x1c,0x95,0x1d,0xae,0xe7,0xe4,0xe7,0xe5,0x39,0xad,0x93,0x27,0xfe,0xc0,0x6e, -0x62,0xe6,0x0f,0x80,0xb9,0x51,0xfa,0x1f,0x60,0x72,0xd6,0xc2,0xf9,0x13,0xa9,0xb3, -0xbd,0xe6,0x19,0x42,0x34,0xc5,0x59,0x8a,0xc8,0x05,0xd1,0x13,0xc6,0x27,0x9c,0x33, -0xf8,0x59,0x12,0x0f,0xb5,0x5a,0xbe,0x2c,0x6b,0x0f,0x16,0xf7,0xd6,0xe9,0x73,0xb2, -0xb4,0x02,0x27,0x61,0x07,0xb0,0xd1,0x98,0x45,0x3b,0x8e,0x18,0xdc,0x51,0x64,0x17, -0xfb,0x1e,0xcc,0x19,0x8c,0x20,0x58,0xc0,0xc3,0x23,0xae,0x8c,0xed,0x34,0xb0,0xca, -0xa7,0xbd,0xdb,0x28,0xe1,0x44,0x44,0x80,0x75,0x7a,0xb8,0xba,0x96,0x13,0xc2,0xe0, -0x0e,0x37,0x7e,0xf7,0xcf,0x3e,0x87,0xda,0x63,0xe1,0xf2,0x1e,0xcb,0x73,0x47,0x21, -0x8e,0x84,0xc5,0x34,0x75,0x56,0xc6,0x5b,0xc1,0x5b,0xda,0xbc,0xdb,0x29,0x4b,0xe0, -0xae,0x15,0xb3,0x6c,0xed,0xab,0x56,0xe9,0x9f,0xb7,0xfc,0xf1,0xfd,0x9b,0x4f,0xcf, -0xe4,0xa4,0x28,0x4a,0x94,0xcb,0x3a,0xcf,0x9b,0x26,0x93,0xaa,0x92,0xba,0x29,0xa8, -0x2a,0x89,0x29,0xa8,0x50,0x22,0x97,0x45,0xa1,0x71,0xe5,0xeb,0xf6,0xc5,0xe8,0x48, -0xe6,0xe6,0x66,0x21,0xdd,0x3f,0x23,0x14,0xaa,0x22,0x8d,0x6c,0x64,0x45,0x55,0x6e, -0x68,0x63,0x88,0x30,0xa6,0x36,0xa4,0xae,0x6b,0xa4,0x49,0x91,0x95,0x05,0x31,0x1a, -0x49,0x4a,0x19,0xfc,0xea,0xb4,0x55,0x0f,0x7e,0x94,0x8f,0xc9,0xbf,0xf7,0x15,0xd5, -0xbf,0x7c,0x0b,0x8e,0x86,0x02,0xd6,0x47,0x88,0x69,0x85,0x52,0x84,0x53,0x94,0x5d, -0x10,0x3a,0x85,0x0f,0x7b,0x59,0x7f,0x97,0x89,0xff,0xc8,0xc4,0x5d,0x76,0x9d,0xc7, -0x75,0xe2,0x72,0xd5,0x0c,0x6e,0x70,0x63,0xad,0xe2,0x18,0x21,0xec,0x49,0x8f,0x22, -0xb5,0x2e,0x7a,0xde,0x74,0x11,0x6d,0xdc,0x87,0x6c,0x3d,0x64,0xfd,0xa8,0x34,0x47, -0x65,0x78,0x02,0x11,0x46,0xd2,0xbd,0x4d,0x1a,0x74,0x76,0x78,0x39,0x27,0xe3,0x6c, -0xaf,0x76,0x10,0x5d,0xc2,0x5b,0x31,0xab,0xc0,0x31,0x18,0xb6,0x37,0xe1,0x20,0x7c, -0x5e,0xc6,0xfb,0x45,0x10,0x1f,0x5f,0x78,0x6f,0x61,0x0a,0x60,0x1c,0x03,0x06,0xe3, -0x50,0xfc,0x06,0x00,0x00,0xff,0xff,0x03,0x00,0x19,0xcf,0xf5,0xc0,0xf9,0x65,0xe8, -0x78,0xc3,0xfa,0x5f,0x0a,0xf6,0x09,0x17,0xd8,0xb0,0x54,0xb9,0x02,0x8d,0x91,0x31, -0x9c,0x42,0x5a,0x68,0x39,0x31,0x41,0x59,0x26,0x53,0x59,0xc1,0x52,0x36,0xf7,0x00, -0x00,0x03,0x41,0x00,0x00,0x10,0x02,0x44,0xa0,0x00,0x21,0xb4,0x01,0x9a,0x0d,0x46, -0xa5,0x32,0x38,0xbb,0x92,0x29,0xc2,0x84,0x86,0x0a,0x91,0xb7,0xb8 -}; - -/* Verify that a file records with no compression -#How to make -echo "hellohellohello" > f1 -chown $UNAME:$GNAME f1 -chmod 0644 f1 -env TZ=utc touch -afm -t 197001020000.01 f1 -xar --compression none -cf archive9.xar f1 -od -t x1 archive9.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive9.xar.txt -*/ - -static unsigned char archive9[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x98, -0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x47,0x00,0x00,0x00,0x01,0x78,0xda,0xa4,0x53, -0x4d,0x6f,0xe3,0x20,0x14,0xbc,0xf7,0x57,0x20,0xee,0x5e,0xc0,0x25,0x89,0x1d,0x11, -0xaa,0x5e,0xaa,0xbd,0x6f,0xf6,0xb2,0x37,0x02,0x8f,0x18,0xc5,0x1f,0x11,0xc6,0x55, -0xba,0xbf,0x7e,0x01,0xdb,0xad,0xba,0x55,0x7b,0xa9,0x64,0xc9,0xe3,0x61,0xde,0x78, -0x78,0xf0,0xc4,0xc3,0xad,0x6b,0xd1,0x33,0xf8,0xd1,0x0d,0xfd,0x01,0xb3,0x1f,0x14, -0x23,0xe8,0xf5,0x60,0x5c,0x7f,0x3e,0xe0,0xdf,0xc7,0xa7,0xa2,0xc2,0x0f,0xf2,0x4e, -0xdc,0x94,0x97,0x77,0x48,0x84,0x41,0xc7,0x17,0x12,0xda,0x83,0x0a,0xb1,0xa2,0x08, -0xae,0x03,0x59,0x52,0x5a,0x17,0xac,0x2c,0x28,0x3f,0xd2,0x7a,0xcf,0xaa,0x3d,0xaf, -0x05,0x79,0x2f,0xc9,0x45,0x0d,0xe8,0xcb,0x38,0x75,0x68,0x0c,0x2f,0x2d,0x1c,0xf0, -0xd8,0x28,0x86,0xd3,0x0a,0x12,0x83,0xb5,0x23,0x04,0x49,0x05,0x59,0x50,0x66,0x47, -0xf7,0x37,0x99,0x0b,0x92,0x41,0xb2,0x20,0xab,0x47,0xfe,0xb2,0xae,0x05,0xe4,0x4c, -0x8c,0xbd,0xd8,0x18,0x15,0x54,0x46,0x48,0xb4,0xd0,0x9f,0x43,0x23,0xd9,0x56,0x90, -0x05,0xce,0xfc,0xba,0xb9,0x35,0x84,0xba,0x5e,0x5b,0xa7,0x73,0x52,0x32,0xe8,0x00, -0xa1,0x18,0x43,0x4c,0xde,0x61,0xb2,0x14,0x2c,0x81,0xca,0xf7,0xd9,0x96,0x70,0xc9, -0x7e,0x0d,0x17,0x39,0xe5,0x75,0xe3,0x9e,0xc1,0x14,0xff,0x6f,0xf5,0xd7,0xcf,0xc7, -0x98,0x71,0x63,0x76,0xfc,0xa4,0x4f,0x7a,0x57,0x9b,0x7b,0x5b,0x9f,0x2c,0x57,0xd6, -0x56,0x96,0x57,0x55,0x45,0x81,0x6f,0xca,0xed,0x86,0x5b,0xa0,0xba,0x8e,0xcd,0xfb, -0x60,0xb4,0xa6,0xbf,0x05,0xaf,0x62,0xca,0xef,0xff,0xe1,0xa3,0xd3,0xdc,0x42,0xf2, -0xda,0x43,0xa1,0x3f,0x39,0xdc,0xed,0x9f,0x78,0x0e,0xeb,0xa9,0x22,0xd1,0x65,0xc8, -0xea,0x1d,0x2d,0x28,0x2b,0x68,0x79,0xa4,0x74,0x9f,0x1e,0x16,0x65,0xdd,0x9b,0x4c, -0x7d,0x21,0x53,0x6f,0xb2,0xb3,0x1f,0xa6,0xab,0xd4,0x13,0x08,0x32,0xc3,0x99,0x75, -0x46,0x32,0x4a,0x59,0x24,0x23,0xca,0xd4,0x34,0x82,0x9f,0x75,0x19,0xcd,0xdc,0xab, -0x6c,0x5a,0x65,0xdd,0x60,0x40,0xd2,0x2d,0xe7,0x31,0x4c,0x82,0x99,0x0c,0x2f,0x57, -0x40,0xad,0xeb,0x2f,0x07,0x3c,0x78,0x77,0x76,0xbd,0x6a,0xb1,0x6c,0x94,0x37,0x89, -0x13,0x24,0x2d,0xcf,0xc2,0x5e,0xc5,0x5c,0x36,0xfa,0x65,0x90,0x6f,0x60,0xba,0x74, -0x69,0x14,0x48,0x9e,0x05,0x41,0xf2,0x64,0xfc,0x03,0x00,0x00,0xff,0xff,0x03,0x00, -0xee,0x8e,0xf8,0x75,0xa1,0xaf,0x74,0x71,0x3f,0x40,0x08,0xab,0x13,0x7d,0xc0,0x82, -0x3a,0x56,0xeb,0x4e,0x35,0xf1,0x35,0xb7,0x68,0x65,0x6c,0x6c,0x6f,0x68,0x65,0x6c, -0x6c,0x6f,0x68,0x65,0x6c,0x6c,0x6f,0x0a -}; - -/* Verify that a file records with md5 hashing algorithm -#How to make -echo "hellohellohello" > f1 -chown $UNAME:$GNAME f1 -chmod 0644 f1 -env TZ=utc touch -afm -t 197001020000.01 f1 -xar --toc-cksum md5 -cf archive10.xar f1 -od -t x1 archive10.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive10.xar.txt -*/ - -static unsigned char archive10[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xaf, -0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x40,0x00,0x00,0x00,0x02,0x78,0xda,0x7c,0x53, -0x4d,0x6f,0xdc,0x20,0x10,0xbd,0xe7,0x57,0x20,0xee,0x0e,0x60,0xb3,0xb6,0x59,0xb1, -0x44,0xbd,0x44,0xbd,0x77,0x7b,0xe9,0x8d,0xe5,0xc3,0x8b,0xe2,0x2f,0x61,0x1c,0x6d, -0xf2,0xeb,0x8b,0xb1,0x9d,0xb4,0x4d,0x52,0xc9,0x92,0x1f,0x8f,0xc7,0x9b,0x61,0x86, -0xe1,0x0f,0xb7,0xae,0x05,0xcf,0xc6,0x4f,0x6e,0xe8,0x4f,0x90,0xdc,0x63,0x08,0x4c, -0xaf,0x06,0xed,0xfa,0xe6,0x04,0x7f,0x9e,0x1f,0xb3,0x1a,0x3e,0x88,0x3b,0x7e,0x93, -0x5e,0xdc,0x01,0x1e,0x06,0x15,0x7f,0x80,0x2b,0x6f,0x64,0x88,0x27,0xb2,0xe0,0x3a, -0x23,0x72,0x8c,0x59,0x46,0xf2,0x0c,0xd3,0x33,0x66,0xc7,0x02,0x1f,0x69,0xcd,0xd1, -0xdf,0x92,0x74,0xe8,0x6a,0xd4,0xd3,0x34,0x77,0x60,0x0a,0x2f,0xad,0x39,0xc1,0x4e, -0x1f,0xe0,0xb2,0x01,0xf8,0x60,0xed,0x64,0x82,0xc0,0x1c,0x6d,0x28,0xb1,0x93,0x7b, -0x35,0x82,0x94,0x1c,0x25,0xb0,0x38,0xa0,0xdd,0x22,0xad,0xac,0x6b,0x0d,0x70,0x3a, -0x66,0xbd,0xd9,0x68,0x19,0x64,0x42,0x80,0xb7,0xa6,0x6f,0xc2,0x55,0xe4,0x05,0x47, -0x1b,0x5c,0xf9,0xcd,0x7f,0x71,0xfd,0x23,0xd4,0x27,0xb1,0x22,0xb7,0xd7,0x61,0xcf, -0x57,0x8e,0x63,0xeb,0x54,0xba,0x14,0xba,0x65,0xcd,0xab,0x1b,0x21,0xda,0xa4,0xd2, -0xab,0xab,0x7b,0x36,0x3a,0xfb,0xf7,0x8e,0x3f,0xbe,0x7f,0x8b,0xd9,0xd9,0xba,0x28, -0x74,0x6e,0xb5,0x22,0xac,0xa0,0xac,0x90,0x17,0x5a,0x33,0xa9,0x65,0x5e,0xd8,0xda, -0x56,0x8c,0xd8,0x32,0xb7,0xaa,0x28,0x59,0xac,0xda,0x07,0xa3,0x3d,0x97,0x5b,0xf0, -0x52,0x85,0x2f,0x23,0x1c,0x74,0x45,0x2f,0xea,0xa2,0x2a,0xa6,0x0b,0xcb,0x2e,0x96, -0x4a,0x1b,0xbd,0x69,0x5d,0xd7,0xd8,0xd0,0x43,0x5e,0x1e,0xa8,0x35,0x58,0x31,0xc6, -0xd1,0x47,0xa7,0xb5,0x78,0xe8,0xad,0x7a,0x5c,0x7d,0xd1,0xd5,0xea,0x57,0xec,0xc0, -0xde,0x4e,0xc0,0xbb,0x04,0x09,0xab,0x70,0x86,0x49,0x86,0xf3,0x33,0xc6,0xc7,0xe5, -0x23,0x51,0xd6,0xbd,0xcb,0xe4,0x7f,0x64,0xf2,0x5d,0xd6,0xf8,0x61,0x1e,0x85,0x9a, -0x0d,0x47,0x2b,0x5c,0x59,0xa7,0x05,0xc1,0x98,0x44,0x32,0xa2,0x44,0xcd,0x93,0xf1, -0xab,0x2e,0xa1,0x95,0x7b,0x93,0xcd,0xbb,0xac,0x1b,0xb4,0x11,0xb8,0xa4,0x34,0x26, -0xb3,0xc0,0x44,0x86,0x97,0xd1,0x80,0xd6,0xf5,0x4f,0x27,0x38,0x78,0xd7,0xb8,0x5e, -0xb6,0x50,0x5c,0xa5,0xd7,0x0b,0xc7,0xd1,0xb2,0xbd,0x0a,0x7b,0x19,0xf3,0xb2,0xd1, -0x2f,0x81,0xf4,0xf6,0x96,0xe7,0xb6,0xcc,0x00,0x4a,0x43,0xc0,0x51,0x1a,0x89,0xdf, -0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x27,0xf8,0xf5,0x28,0x87,0x01,0xb1,0xb7,0x18, -0xe8,0x34,0x20,0x06,0x5c,0x66,0x9a,0x43,0x26,0xe7,0x94,0x78,0xda,0xca,0x48,0xcd, -0xc9,0xc9,0xcf,0x80,0x13,0x5c,0x00,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7, -0x06,0x47 -}; - -/* Verify that a file records with no hashing algorithm -#How to make -echo "hellohellohello" > f1 -chown $UNAME:$GNAME f1 -chmod 0644 f1 -env TZ=utc touch -afm -t 197001020000.01 f1 -xar --toc-cksum none -cf archive11.xar f1 -od -t x1 archive11.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive11.xar.txt -*/ - -static unsigned char archive11[] = { -0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x98, -0x00,0x00,0x00,0x00,0x00,0x00,0x02,0xef,0x00,0x00,0x00,0x00,0x78,0xda,0x7c,0x52, -0xcb,0x6e,0xeb,0x20,0x14,0xdc,0xf7,0x2b,0x10,0x7b,0x17,0xb0,0x89,0x63,0x22,0x42, -0x75,0x37,0x55,0xf7,0xcd,0xdd,0x74,0x47,0x78,0x38,0xa8,0x7e,0xc9,0xc6,0x55,0xda, -0xaf,0xbf,0x3c,0xe2,0x56,0x55,0xd5,0x2b,0x21,0x79,0x3c,0xcc,0x39,0x67,0x74,0x18, -0xfe,0x70,0xed,0x3b,0xf0,0x66,0xe6,0xc5,0x8d,0xc3,0x11,0x92,0x7b,0x0c,0x81,0x19, -0xd4,0xa8,0xdd,0xd0,0x1e,0xe1,0xdf,0xd3,0x63,0xd1,0xc0,0x07,0x71,0xc7,0xaf,0x72, -0x16,0x77,0x80,0xfb,0x51,0x85,0x0f,0xe0,0x6a,0x36,0xd2,0x87,0x8a,0xc2,0xbb,0xde, -0x88,0x12,0x63,0x56,0x90,0xb2,0xc0,0xf4,0x44,0xf0,0x81,0x54,0x07,0x5a,0x73,0xf4, -0x5d,0x12,0x8b,0xac,0xeb,0x0c,0x70,0x3a,0x4c,0x81,0xf1,0x1f,0x70,0x2d,0xbd,0x4c, -0x08,0xf0,0xce,0x0c,0xad,0xbf,0x88,0xb2,0xe2,0xe8,0x06,0x33,0x3f,0x5a,0xbb,0x18, -0x2f,0x30,0x47,0x37,0x94,0xe9,0xc5,0x7d,0x18,0x41,0xc2,0x94,0x04,0x32,0xb7,0xd9, -0x06,0x8b,0x7f,0xef,0xcc,0x11,0xca,0x69,0xea,0x9c,0x4a,0x1e,0xd0,0xb5,0x68,0x3f, -0xdc,0x04,0xd1,0x4d,0x2a,0x67,0x75,0x71,0x6f,0x46,0x17,0xea,0x62,0xd4,0xeb,0xb2, -0xf6,0x5b,0xcd,0xf3,0xd3,0x9f,0x60,0xce,0x36,0x55,0xa5,0x4b,0xab,0x15,0x61,0x15, -0x65,0x95,0x3c,0xd3,0x86,0x49,0x2d,0xcb,0xca,0x36,0x76,0xcf,0x88,0xad,0x4b,0xab, -0xaa,0x9a,0x35,0x1c,0xfd,0x68,0xb4,0x79,0xb9,0xfa,0x59,0x2a,0xff,0xeb,0x84,0x9d, -0xde,0xd3,0xb3,0x3a,0xab,0x3d,0xd3,0x95,0x65,0x67,0x4b,0xa5,0x0d,0xbd,0x69,0xd3, -0x34,0xd8,0xd0,0x5d,0x59,0xef,0xa8,0x35,0x58,0x31,0xc6,0xd1,0xcf,0x4e,0x79,0x77, -0xe8,0x73,0x79,0x5c,0xfd,0xf2,0x08,0xe4,0x25,0xbc,0xc2,0xb6,0x7d,0xc0,0xfb,0x04, -0x09,0xdb,0xe3,0x02,0x93,0x02,0x97,0x27,0x8c,0x0f,0xf1,0x44,0x59,0xff,0x25,0x93, -0xff,0x91,0xc9,0x2f,0x59,0x3b,0x8f,0xeb,0x24,0xd4,0x6a,0x38,0xca,0x30,0xb3,0x4e, -0x0b,0x82,0x31,0x09,0x64,0x40,0x89,0x5a,0x17,0x33,0x67,0x5d,0x42,0x99,0xfb,0x94, -0xad,0x9b,0xac,0x1f,0xb5,0x11,0xb8,0xa6,0x34,0x98,0x89,0x30,0x91,0xfe,0x7d,0x32, -0xa0,0x73,0xc3,0xeb,0x11,0x8e,0xb3,0x6b,0xdd,0x20,0x3b,0x28,0x2e,0x72,0xd6,0x91, -0xe3,0x28,0x5e,0x67,0xe1,0x20,0x83,0x2f,0x1b,0xfa,0x25,0x10,0xc3,0x86,0x62,0xda, -0x62,0x64,0x51,0xca,0x2c,0x47,0x29,0xc1,0xff,0x00,0x00,0x00,0xff,0xff,0x03,0x00, -0xf1,0x18,0xdc,0x71,0x78,0xda,0xca,0x48,0xcd,0xc9,0xc9,0xcf,0x80,0x13,0x5c,0x00, -0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7,0x06,0x47 -}; - -enum enc { - GZIP, - BZIP2 -}; - -static void verify(unsigned char *d, size_t s, - void (*f1)(struct archive *, struct archive_entry *), - void (*f2)(struct archive *, struct archive_entry *), - enum enc etype) -{ - struct archive_entry *ae; - struct archive *a; - unsigned char *buff; - int r; - - assert((a = archive_read_new()) != NULL); - switch (etype) { - case BZIP2: - /* This is only check whether bzip is supported or not. - * This filter won't be used this test. */ - if (ARCHIVE_OK != archive_read_support_compression_bzip2(a)) { - skipping("Unsupported bzip2"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - break; - case GZIP: - /* This gzip must be needed. archive_read_support_format_xar() - * will return a warning if gzip is unsupported. */ - break; - } - assertA(0 == archive_read_support_compression_all(a)); - r = archive_read_support_format_xar(a); - if (r == ARCHIVE_WARN) { - skipping("xar reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assert((buff = malloc(100000)) != NULL); - if (buff == NULL) - return; - memcpy(buff, d, s); - memset(buff + s, 0, 2048); - - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, buff, s + 1024)); - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_XAR); - /* Verify the only entry. */ - f1(a, ae); - if (f2) { - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_XAR); - /* Verify the only entry. */ - f2(a, ae); - } - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - assertA(0 == archive_read_close(a)); - assertA(0 == archive_read_finish(a)); - free(buff); -} - -DEFINE_TEST(test_read_format_xar) -{ - verify(archive1, sizeof(archive1), verify0, verify1, GZIP); - verify(archive2, sizeof(archive2), verify0, verify2, GZIP); - verify(archive3, sizeof(archive3), verify3, NULL, GZIP); - verify(archive4, sizeof(archive4), verify4, NULL, GZIP); - verify(archive5, sizeof(archive5), verify5, NULL, GZIP); - verify(archive6, sizeof(archive6), verify6, NULL, GZIP); - verify(archive7, sizeof(archive7), verify7, NULL, GZIP); - verify(archive8, sizeof(archive8), verify0, NULL, BZIP2); - verify(archive9, sizeof(archive9), verify0, NULL, GZIP); - verify(archive10, sizeof(archive10), verify0, NULL, GZIP); - verify(archive11, sizeof(archive11), verify0, NULL, GZIP); -} - diff --git a/lib/libarchive/test/test_read_format_zip.c b/lib/libarchive/test/test_read_format_zip.c deleted file mode 100644 index 8c7059d..0000000 --- a/lib/libarchive/test/test_read_format_zip.c +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * The reference file for this has been manually tweaked so that: - * * file2 has length-at-end but file1 does not - * * file2 has an invalid CRC - */ - -DEFINE_TEST(test_read_format_zip) -{ - const char *refname = "test_read_format_zip.zip"; - struct archive_entry *ae; - struct archive *a; - char *buff[128]; - const void *pv; - size_t s; - off_t o; - int r; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_filename(a, refname, 10240)); - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("dir/", archive_entry_pathname(ae)); - assertEqualInt(1179604249, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &pv, &s, &o)); - assertEqualInt((int)s, 0); - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("file1", archive_entry_pathname(ae)); - assertEqualInt(1179604289, archive_entry_mtime(ae)); - assertEqualInt(18, archive_entry_size(ae)); - failure("archive_read_data() returns number of bytes read"); - r = archive_read_data(a, buff, 19); - if (r < ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "libarchive compiled without deflate support (no libz)") == 0) { - skipping("Skipping ZIP compression check: %s", - archive_error_string(a)); - goto finish; - } - } - assertEqualInt(18, r); - assert(0 == memcmp(buff, "hello\nhello\nhello\n", 18)); - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assertEqualInt(1179605932, archive_entry_mtime(ae)); - failure("file2 has length-at-end, so we shouldn't see a valid size"); - assertEqualInt(0, archive_entry_size_is_set(ae)); - failure("file2 has a bad CRC, so reading to end should fail"); - assertEqualInt(ARCHIVE_WARN, archive_read_data(a, buff, 19)); - assert(0 == memcmp(buff, "hello\nhello\nhello\n", 18)); - assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE); - assertA(archive_format(a) == ARCHIVE_FORMAT_ZIP); - assert(0 == archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} - - diff --git a/lib/libarchive/test/test_read_format_zip.zip.uu b/lib/libarchive/test/test_read_format_zip.zip.uu deleted file mode 100644 index 1e0cb22..0000000 --- a/lib/libarchive/test/test_read_format_zip.zip.uu +++ /dev/null @@ -1,14 +0,0 @@ -$FreeBSD$ -begin 644 test_read_format_zip.zip -M4$L#!`H`"````%EFLS8````````````````$`!4`9&ER+U54"0`#&55/1M19 -M_4A5>`0`Z`/H`U!+!P@```````````````!02P,$%`````@`;V:S-CHW9CT* -M````$@````4`%0!F:6QE,554"0`#055/1L!9_4A5>`0`Z`/H`\M(S`0`Z`/H`\M(S```4$L!`A<#%``(``@`;V:S-CHW9CT*````$@````4`#0`` -M`````0```.V!1P```&9I;&4Q550%``-!54]&57@``%!+`0(7`Q0`"``(`%IJ -MLS8Z-V8]"@```!(````%``T```````$```#M@8D```!F:6QE,E54!0`#K%M/ -;1E5X``!02P4&``````,``P"_````VP`````` -` -end diff --git a/lib/libarchive/test/test_read_large.c b/lib/libarchive/test/test_read_large.c deleted file mode 100644 index 5ff01fd..0000000 --- a/lib/libarchive/test/test_read_large.c +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char testdata[10 * 1024 * 1024]; -static unsigned char testdatacopy[10 * 1024 * 1024]; -static unsigned char buff[11 * 1024 * 1024]; - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define open _open -#define close _close -#endif - -/* Check correct behavior on large reads. */ -DEFINE_TEST(test_read_large) -{ - unsigned int i; - int tmpfilefd; - char tmpfilename[] = "test-read_large.XXXXXX"; - size_t used; - struct archive *a; - struct archive_entry *entry; - FILE *f; - - for (i = 0; i < sizeof(testdata); i++) - testdata[i] = (unsigned char)(rand()); - - assert(NULL != (a = archive_write_new())); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_size(entry, sizeof(testdata)); - archive_entry_set_mode(entry, S_IFREG | 0777); - archive_entry_set_pathname(entry, "test"); - assertA(0 == archive_write_header(a, entry)); - archive_entry_free(entry); - assertA((int)sizeof(testdata) == archive_write_data(a, testdata, sizeof(testdata))); - assertA(0 == archive_write_finish(a)); - - assert(NULL != (a = archive_read_new())); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, sizeof(buff))); - assertA(0 == archive_read_next_header(a, &entry)); - assertA(0 == archive_read_data_into_buffer(a, testdatacopy, sizeof(testdatacopy))); - assertA(0 == archive_read_finish(a)); - assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata))); - - - assert(NULL != (a = archive_read_new())); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, sizeof(buff))); - assertA(0 == archive_read_next_header(a, &entry)); -#if defined(__BORLANDC__) - tmpfilefd = open(tmpfilename, O_WRONLY | O_CREAT | O_BINARY); -#else - tmpfilefd = open(tmpfilename, O_WRONLY | O_CREAT | O_BINARY, 0755); -#endif - assert(0 < tmpfilefd); - assertA(0 == archive_read_data_into_fd(a, tmpfilefd)); - close(tmpfilefd); - assertA(0 == archive_read_finish(a)); - - f = fopen(tmpfilename, "rb"); - assertEqualInt(sizeof(testdatacopy), - fread(testdatacopy, 1, sizeof(testdatacopy), f)); - fclose(f); - assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata))); -} diff --git a/lib/libarchive/test/test_read_pax_truncated.c b/lib/libarchive/test/test_read_pax_truncated.c deleted file mode 100644 index 393fd9f..0000000 --- a/lib/libarchive/test/test_read_pax_truncated.c +++ /dev/null @@ -1,288 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_read_pax_truncated) -{ - struct archive_entry *ae; - struct archive *a; - size_t used, i, buff_size = 1000000; - size_t filedata_size = 100000; - char *buff = malloc(buff_size); - char *buff2 = malloc(buff_size); - char *filedata = malloc(filedata_size); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_pax(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, buff_size, &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - for (i = 0; i < filedata_size; i++) - filedata[i] = (unsigned char)rand(); - archive_entry_set_atime(ae, 1, 2); - archive_entry_set_ctime(ae, 3, 4); - archive_entry_set_mtime(ae, 5, 6); - archive_entry_set_size(ae, filedata_size); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA((ssize_t)filedata_size - == archive_write_data(a, filedata, filedata_size)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* Now, read back a truncated version of the archive and - * verify that we get an appropriate error. */ - for (i = 1; i < used + 100; i += 100) { - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == read_open_memory2(a, buff, i, 13)); - - if (i < 1536) { - assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); - goto wrap_up; - } else { - failure("Archive truncated to %d bytes", i); - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - } - - if (i < 1536 + filedata_size) { - assertA(ARCHIVE_FATAL == archive_read_data(a, filedata, filedata_size)); - goto wrap_up; - } else { - failure("Archive truncated to %d bytes", i); - assertEqualIntA(a, filedata_size, - archive_read_data(a, filedata, filedata_size)); - } - - /* Verify the end of the archive. */ - /* Archive must be long enough to capture a 512-byte - * block of zeroes after the entry. (POSIX requires a - * second block of zeros to be written but libarchive - * does not return an error if it can't consume - * it.) */ - if (i < 1536 + 512*((filedata_size + 511)/512) + 512) { - failure("i=%d minsize=%d", i, - 1536 + 512*((filedata_size + 511)/512) + 512); - assertEqualIntA(a, ARCHIVE_FATAL, - archive_read_next_header(a, &ae)); - } else { - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_next_header(a, &ae)); - } - wrap_up: - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } - - - - /* Same as above, except skip the body instead of reading it. */ - for (i = 1; i < used + 100; i += 100) { - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == read_open_memory(a, buff, i, 7)); - - if (i < 1536) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - goto wrap_up2; - } else { - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - } - - if (i < 1536 + 512*((filedata_size+511)/512)) { - assertA(ARCHIVE_FATAL == archive_read_data_skip(a)); - goto wrap_up2; - } else { - assertA(ARCHIVE_OK == archive_read_data_skip(a)); - } - - /* Verify the end of the archive. */ - /* Archive must be long enough to capture a 512-byte - * block of zeroes after the entry. (POSIX requires a - * second block of zeros to be written but libarchive - * does not return an error if it can't consume - * it.) */ - if (i < 1536 + 512*((filedata_size + 511)/512) + 512) { - assertEqualIntA(a, ARCHIVE_FATAL, - archive_read_next_header(a, &ae)); - } else { - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_next_header(a, &ae)); - } - wrap_up2: - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } - - /* Now, damage the archive in various ways and test the responses. */ - - /* Damage the first size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = '9'; - buff2[513] = '9'; - buff2[514] = 'A'; /* Non-digit in size. */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = 'A'; /* First character not a digit. */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - for (i = 512; i < 520; i++) /* Size over 999999. */ - buff2[i] = '9'; - buff2[i] = ' '; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = '9'; /* Valid format, but larger than attribute area. */ - buff2[513] = '9'; - buff2[514] = '9'; - buff2[515] = ' '; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = '1'; /* Too small. */ - buff2[513] = ' '; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = ' '; /* No size given. */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the ustar header. */ - memcpy(buff2, buff, buff_size); - buff2[1024]++; /* Break the checksum. */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* - * TODO: Damage the ustar header in various ways and fixup the - * checksum in order to test boundary cases in the innermost - * ustar header parsing. - */ - - free(buff); - free(buff2); - free(filedata); -} diff --git a/lib/libarchive/test/test_read_position.c b/lib/libarchive/test/test_read_position.c deleted file mode 100644 index bc7b53b..0000000 --- a/lib/libarchive/test/test_read_position.c +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char nulls[10000]; -static unsigned char buff[10000000]; - -/* Check that header_position tracks correctly on read. */ -DEFINE_TEST(test_read_position) -{ - struct archive *a; - struct archive_entry *ae; - size_t write_pos; - intmax_t read_position; - size_t i, j; - size_t data_sizes[] = {0, 5, 511, 512, 513}; - - /* Sanity test */ - assert(sizeof(nulls) + 512 + 1024 <= sizeof(buff)); - - /* Create an archive. */ - assert(NULL != (a = archive_write_new())); - assertA(0 == archive_write_set_format_pax_restricted(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 512)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &write_pos)); - - for (i = 0; i < sizeof(data_sizes)/sizeof(data_sizes[0]); ++i) { - /* Create a simple archive_entry. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, "testfile"); - archive_entry_set_mode(ae, S_IFREG); - archive_entry_set_size(ae, data_sizes[i]); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(data_sizes[i] - == (size_t)archive_write_data(a, nulls, sizeof(nulls))); - } - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - - /* Read the archive back. */ - assert(NULL != (a = archive_read_new())); - assertA(0 == archive_read_support_format_tar(a)); - assertA(0 == archive_read_open_memory2(a, buff, sizeof(buff), 512)); - - read_position = 0; - /* Initial header position is zero. */ - assert(read_position == (intmax_t)archive_read_header_position(a)); - for (j = 0; j < i; ++j) { - assertA(0 == archive_read_next_header(a, &ae)); - assert(read_position - == (intmax_t)archive_read_header_position(a)); - /* Every other entry: read, then skip */ - if (j & 1) - assertEqualInt(ARCHIVE_OK, - archive_read_data_into_buffer(a, buff, 1)); - assertA(0 == archive_read_data_skip(a)); - /* read_data_skip() doesn't change header_position */ - assert(read_position - == (intmax_t)archive_read_header_position(a)); - - read_position += 512; /* Size of header. */ - read_position += (data_sizes[j] + 511) & ~511; - } - - assertA(1 == archive_read_next_header(a, &ae)); - assert(read_position == (intmax_t)archive_read_header_position(a)); - assertA(0 == archive_read_close(a)); - assert(read_position == (intmax_t)archive_read_header_position(a)); - archive_read_finish(a); -} diff --git a/lib/libarchive/test/test_read_truncated.c b/lib/libarchive/test/test_read_truncated.c deleted file mode 100644 index 7012684..0000000 --- a/lib/libarchive/test/test_read_truncated.c +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -char buff[1000000]; -char buff2[100000]; - -DEFINE_TEST(test_read_truncated) -{ - struct archive_entry *ae; - struct archive *a; - unsigned int i; - size_t used; - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - for (i = 0; i < sizeof(buff2); i++) - buff2[i] = (unsigned char)rand(); - archive_entry_set_size(ae, sizeof(buff2)); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA((int)sizeof(buff2) == archive_write_data(a, buff2, sizeof(buff2))); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* Now, read back a truncated version of the archive and - * verify that we get an appropriate error. */ - for (i = 1; i < used + 100; i += 100) { - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, i)); - - if (i < 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - goto wrap_up; - } else { - assertA(0 == archive_read_next_header(a, &ae)); - } - - if (i < 512 + sizeof(buff2)) { - assertA(ARCHIVE_FATAL == archive_read_data(a, buff2, sizeof(buff2))); - goto wrap_up; - } else { - assertA((int)sizeof(buff2) == archive_read_data(a, buff2, sizeof(buff2))); - } - - /* Verify the end of the archive. */ - /* Archive must be long enough to capture a 512-byte - * block of zeroes after the entry. (POSIX requires a - * second block of zeros to be written but libarchive - * does not return an error if it can't consume - * it.) */ - if (i < 512 + 512*((sizeof(buff2) + 511)/512) + 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - } else { - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); - } - wrap_up: - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } - - - - /* Same as above, except skip the body instead of reading it. */ - for (i = 1; i < used + 100; i += 100) { - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, i)); - - if (i < 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - goto wrap_up2; - } else { - assertA(0 == archive_read_next_header(a, &ae)); - } - - if (i < 512 + 512*((sizeof(buff2)+511)/512)) { - assertA(ARCHIVE_FATAL == archive_read_data_skip(a)); - goto wrap_up2; - } else { - assertA(ARCHIVE_OK == archive_read_data_skip(a)); - } - - /* Verify the end of the archive. */ - /* Archive must be long enough to capture a 512-byte - * block of zeroes after the entry. (POSIX requires a - * second block of zeros to be written but libarchive - * does not return an error if it can't consume - * it.) */ - if (i < 512 + 512*((sizeof(buff2) + 511)/512) + 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - } else { - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); - } - wrap_up2: - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } -} diff --git a/lib/libarchive/test/test_read_uu.c b/lib/libarchive/test/test_read_uu.c deleted file mode 100644 index 6ad279f..0000000 --- a/lib/libarchive/test/test_read_uu.c +++ /dev/null @@ -1,134 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static const char archive[] = { -"begin 644 test_read_uu.Z\n" -"M'YV0+@`('$BPH,&#\"!,J7,BP(4(8$&_4J`$\"`,08$F%4O)AQ(\\2/(#7&@#%C\n" -"M!@T8-##.L`$\"QL@:-F(``%'#H/1A2\n" -"IHU\"0%9=*G4JUJM6K6+-JWO8,.*'4NVK-FS:-.J7\n" -"Received: from libarchive (localhost [127.0.0.1])\n" -" by libarchive (8.14.2/8.14.2) with ESMTP id m5233UT1006448\n" -" for ; Mon, 2 Jun 2008 03:03:31 GMT\n" -" (envelope-from uudecode@libarchive)\n" -"Received: (from uudecode@localhost)\n" -" by libarchive (8.14.2/8.14.2/Submit) id m5233U3e006406\n" -" for uudecode; Mon, 2 Jun 2008 03:03:30 GMT\n" -" (envelope-from root)\n" -"Date: Mon, 2 Jun 2008 03:03:30 GMT\n" -"From: Libarchive Test \n" -"Message-Id: <200806020303.m5233U3e006406@libarchive>\n" -"To: uudecode@libarchive\n" -"Subject: Libarchive uudecode test\n" -"\n" -"* Redistribution and use in source and binary forms, with or without\n" -"* modification, are permitted provided that the following conditions\n" -"* are met:\n" -"\n" -"01234567890abcdeghijklmnopqrstuvwxyz\n" -"01234567890ABCEFGHIJKLMNOPQRSTUVWXYZ\n" -"\n" -}; - -static void -test_read_uu_sub(const char *uudata, size_t uusize) -{ - struct archive_entry *ae; - struct archive *a; - char *buff; - int extra; - - assert(NULL != (buff = malloc(uusize + 64 * 1024))); - if (buff == NULL) - return; - for (extra = 0; extra <= 64; extra = extra==0?1:extra*2) { - size_t size = extra * 1024; - char *p = buff; - - /* Add extra text size of which is from 1K bytes to - * 64Kbytes before uuencoded data. */ - while (size) { - if (size > sizeof(extradata)-1) { - memcpy(p, extradata, sizeof(extradata)-1); - p += sizeof(extradata)-1; - size -= sizeof(extradata)-1; - } else { - memcpy(p, extradata, size-1); - p += size-1; - *p++ = '\n';/* the last of extra text must have - * '\n' character. */ - break; - } - } - memcpy(p, uudata, uusize); - size = extra * 1024 + uusize; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - read_open_memory(a, buff, size, 2)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - failure("archive_compression_name(a)=\"%s\"", - archive_compression_name(a)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_COMPRESS); - failure("archive_format_name(a)=\"%s\"", - archive_format_name(a)); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - } - free(buff); -} - -DEFINE_TEST(test_read_uu) -{ - /* Read the traditional uuencoded data. */ - test_read_uu_sub(archive, sizeof(archive)-1); - /* Read the Base64 uuencoded data. */ - test_read_uu_sub(archive64, sizeof(archive64)-1); -} - diff --git a/lib/libarchive/test/test_tar_filenames.c b/lib/libarchive/test/test_tar_filenames.c deleted file mode 100644 index ac6df3e..0000000 --- a/lib/libarchive/test/test_tar_filenames.c +++ /dev/null @@ -1,186 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Exercise various lengths of filenames in tar archives, - * especially around the magic sizes where ustar breaks - * filenames into prefix/suffix. - */ - -static void -test_filename(const char *prefix, int dlen, int flen) -{ - char buff[8192]; - char filename[400]; - char dirname[400]; - struct archive_entry *ae; - struct archive *a; - size_t used; - char *p; - int i; - - p = filename; - if (prefix) { - strcpy(filename, prefix); - p += strlen(p); - } - if (dlen > 0) { - for (i = 0; i < dlen; i++) - *p++ = 'a'; - *p++ = '/'; - } - for (i = 0; i < flen; i++) - *p++ = 'b'; - *p = '\0'; - - strcpy(dirname, filename); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_pax_restricted(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a,0)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, filename); - archive_entry_set_mode(ae, S_IFREG | 0755); - failure("Pathname %d/%d", dlen, flen); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* - * Write a dir to it (without trailing '/'). - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, dirname); - archive_entry_set_mode(ae, S_IFDIR | 0755); - failure("Dirname %d/%d", dlen, flen); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Tar adds a '/' to directory names. */ - strcat(dirname, "/"); - - /* - * Write a dir to it (with trailing '/'). - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, dirname); - archive_entry_set_mode(ae, S_IFDIR | 0755); - failure("Dirname %d/%d", dlen, flen); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - /* Read the file and check the filename. */ - assertA(0 == archive_read_next_header(a, &ae)); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("Leading '/' preserved on long filenames"); -#else - assertEqualString(filename, archive_entry_pathname(ae)); -#endif - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - - /* - * Read the two dirs and check the names. - * - * Both dirs should read back with the same name, since - * tar should add a trailing '/' to any dir that doesn't - * already have one. We only report the first such failure - * here. - */ - assertA(0 == archive_read_next_header(a, &ae)); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("Trailing '/' preserved on dirnames"); -#else - assertEqualString(dirname, archive_entry_pathname(ae)); -#endif - assert((S_IFDIR | 0755) == archive_entry_mode(ae)); - - assertA(0 == archive_read_next_header(a, &ae)); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("Trailing '/' added to dir names"); -#else - assertEqualString(dirname, archive_entry_pathname(ae)); -#endif - assert((S_IFDIR | 0755) == archive_entry_mode(ae)); - - /* Verify the end of the archive. */ - assert(1 == archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} - -DEFINE_TEST(test_tar_filenames) -{ - int dlen, flen; - - /* Repeat the following for a variety of dir/file lengths. */ - for (dlen = 45; dlen < 55; dlen++) { - for (flen = 45; flen < 55; flen++) { - test_filename(NULL, dlen, flen); - test_filename("/", dlen, flen); - } - } - - for (dlen = 0; dlen < 140; dlen += 10) { - for (flen = 98; flen < 102; flen++) { - test_filename(NULL, dlen, flen); - test_filename("/", dlen, flen); - } - } - - for (dlen = 140; dlen < 160; dlen++) { - for (flen = 95; flen < 105; flen++) { - test_filename(NULL, dlen, flen); - test_filename("/", dlen, flen); - } - } -} diff --git a/lib/libarchive/test/test_tar_large.c b/lib/libarchive/test/test_tar_large.c deleted file mode 100644 index 92ca839..0000000 --- a/lib/libarchive/test/test_tar_large.c +++ /dev/null @@ -1,312 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -/* - * This is a somewhat tricky test that verifies the ability to - * write and read very large entries to tar archives. It - * writes entries from 2GB up to 1TB to an archive in memory. - * The memory storage here carefully avoids actually storing - * any part of the file bodies, so it runs very quickly and requires - * very little memory. If you're willing to wait a few minutes, - * you should be able to exercise petabyte entries with this code. - */ - -/* - * Each file is built up by duplicating the following block. - */ -static size_t filedatasize; -static void *filedata; - -/* - * We store the archive as blocks of data generated by libarchive, - * each possibly followed by bytes of file data. - */ -struct memblock { - struct memblock *next; - size_t size; - void *buff; - int64_t filebytes; -}; - -/* - * The total memory store is just a list of memblocks plus - * some accounting overhead. - */ -struct memdata { - int64_t filebytes; - void *buff; - struct memblock *first; - struct memblock *last; -}; - -/* The following size definitions simplify things below. */ -#define KB ((int64_t)1024) -#define MB ((int64_t)1024 * KB) -#define GB ((int64_t)1024 * MB) -#define TB ((int64_t)1024 * GB) - -#if ARCHIVE_VERSION_NUMBER < 2000000 -static ssize_t memory_read_skip(struct archive *, void *, size_t request); -#else -static off_t memory_read_skip(struct archive *, void *, off_t request); -#endif -static ssize_t memory_read(struct archive *, void *, const void **buff); -static ssize_t memory_write(struct archive *, void *, const void *, size_t); - - -static ssize_t -memory_write(struct archive *a, void *_private, const void *buff, size_t size) -{ - struct memdata *private = _private; - struct memblock *block; - - (void)a; - - /* - * Since libarchive tries to behave in a zero-copy manner, if - * you give a pointer to filedata to the library, a pointer - * into that data will (usually) pop out here. This way, we - * can tell the difference between filedata and library header - * and metadata. - */ - if ((const char *)filedata <= (const char *)buff - && (const char *)buff < (const char *)filedata + filedatasize) { - /* We don't need to store a block of file data. */ - private->last->filebytes += (int64_t)size; - } else { - /* Yes, we're assuming the very first write is metadata. */ - /* It's header or metadata, copy and save it. */ - block = (struct memblock *)malloc(sizeof(*block)); - memset(block, 0, sizeof(*block)); - block->size = size; - block->buff = malloc(size); - memcpy(block->buff, buff, size); - if (private->last == NULL) { - private->first = private->last = block; - } else { - private->last->next = block; - private->last = block; - } - block->next = NULL; - } - return ((long)size); -} - -static ssize_t -memory_read(struct archive *a, void *_private, const void **buff) -{ - struct memdata *private = _private; - struct memblock *block; - ssize_t size; - - (void)a; - - free(private->buff); - private->buff = NULL; - if (private->first == NULL) { - private->last = NULL; - return (ARCHIVE_EOF); - } - if (private->filebytes > 0) { - /* - * We're returning file bytes, simulate it by - * passing blocks from the template data. - */ - if (private->filebytes > (int64_t)filedatasize) - size = (ssize_t)filedatasize; - else - size = (ssize_t)private->filebytes; - private->filebytes -= size; - *buff = filedata; - } else { - /* - * We need to get some real data to return. - */ - block = private->first; - private->first = block->next; - size = (ssize_t)block->size; - if (block->buff != NULL) { - private->buff = block->buff; - *buff = block->buff; - } else { - private->buff = NULL; - *buff = filedata; - } - private->filebytes = block->filebytes; - free(block); - } - return (size); -} - - -#if ARCHIVE_VERSION_NUMBER < 2000000 -static ssize_t -memory_read_skip(struct archive *a, void *private, size_t skip) -{ - (void)a; /* UNUSED */ - (void)private; /* UNUSED */ - (void)skip; /* UNUSED */ - return (0); -} -#else -static off_t -memory_read_skip(struct archive *a, void *_private, off_t skip) -{ - struct memdata *private = _private; - - (void)a; - - if (private->first == NULL) { - private->last = NULL; - return (0); - } - if (private->filebytes > 0) { - if (private->filebytes < skip) - skip = (off_t)private->filebytes; - private->filebytes -= skip; - } else { - skip = 0; - } - return (skip); -} -#endif - -DEFINE_TEST(test_tar_large) -{ - /* The sizes of the entries we're going to generate. */ - static int64_t tests[] = { - /* Test for 32-bit signed overflow. */ - 2 * GB - 1, 2 * GB, 2 * GB + 1, - /* Test for 32-bit unsigned overflow. */ - 4 * GB - 1, 4 * GB, 4 * GB + 1, - /* 8GB is the "official" max for ustar. */ - 8 * GB - 1, 8 * GB, 8 * GB + 1, - /* Bend ustar a tad and you can get 64GB (12 octal digits). */ - 64 * GB - 1, 64 * GB, - /* And larger entries that require non-ustar extensions. */ - 256 * GB, 1 * TB, 0 }; - int i; - char namebuff[64]; - struct memdata memdata; - struct archive_entry *ae; - struct archive *a; - int64_t filesize; - size_t writesize; - - filedatasize = (size_t)(1 * MB); - filedata = malloc(filedatasize); - memset(filedata, 0xAA, filedatasize); - memset(&memdata, 0, sizeof(memdata)); - - /* - * Open an archive for writing. - */ - a = archive_write_new(); - archive_write_set_format_pax_restricted(a); - archive_write_set_bytes_per_block(a, 0); /* No buffering. */ - archive_write_open(a, &memdata, NULL, memory_write, NULL); - - /* - * Write a series of large files to it. - */ - for (i = 0; tests[i] != 0; i++) { - assert((ae = archive_entry_new()) != NULL); - sprintf(namebuff, "file_%d", i); - archive_entry_copy_pathname(ae, namebuff); - archive_entry_set_mode(ae, S_IFREG | 0755); - filesize = tests[i]; - - archive_entry_set_size(ae, filesize); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* - * Write the actual data to the archive. - */ - while (filesize > 0) { - writesize = filedatasize; - if ((int64_t)writesize > filesize) - writesize = (size_t)filesize; - assertA((int)writesize - == archive_write_data(a, filedata, writesize)); - filesize -= writesize; - } - } - - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "lastfile"); - archive_entry_set_mode(ae, S_IFREG | 0755); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* - * Open the same archive for reading. - */ - a = archive_read_new(); - archive_read_support_format_tar(a); - archive_read_open2(a, &memdata, NULL, - memory_read, memory_read_skip, NULL); - - /* - * Read entries back. - */ - for (i = 0; tests[i] > 0; i++) { - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - sprintf(namebuff, "file_%d", i); - assertEqualString(namebuff, archive_entry_pathname(ae)); - assert(tests[i] == archive_entry_size(ae)); - } - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualString("lastfile", archive_entry_pathname(ae)); - - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Close out the archive. */ - assertA(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertA(0 == archive_read_finish(a)); -#endif - - free(memdata.buff); - free(filedata); -} diff --git a/lib/libarchive/test/test_ustar_filenames.c b/lib/libarchive/test/test_ustar_filenames.c deleted file mode 100644 index 130a31e..0000000 --- a/lib/libarchive/test/test_ustar_filenames.c +++ /dev/null @@ -1,191 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Exercise various lengths of filenames in ustar archives. - */ - -static void -test_filename(const char *prefix, int dlen, int flen) -{ - char buff[8192]; - char filename[400]; - char dirname[400]; - struct archive_entry *ae; - struct archive *a; - size_t used; - int separator = 0; - int i = 0; - - if (prefix != NULL) { - strcpy(filename, prefix); - i = (int)strlen(prefix); - } - if (dlen > 0) { - for (; i < dlen; i++) - filename[i] = 'a'; - filename[i++] = '/'; - separator = 1; - } - for (; i < dlen + flen + separator; i++) - filename[i] = 'b'; - filename[i] = '\0'; - - strcpy(dirname, filename); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a,0)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, filename); - archive_entry_set_mode(ae, S_IFREG | 0755); - failure("dlen=%d, flen=%d", dlen, flen); - if (flen > 100) { - assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); - } else { - assertEqualIntA(a, 0, archive_write_header(a, ae)); - } - archive_entry_free(ae); - - /* - * Write a dir to it (without trailing '/'). - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, dirname); - archive_entry_set_mode(ae, S_IFDIR | 0755); - failure("dlen=%d, flen=%d", dlen, flen); - if (flen >= 100) { - assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); - } else { - assertEqualIntA(a, 0, archive_write_header(a, ae)); - } - archive_entry_free(ae); - - /* Tar adds a '/' to directory names. */ - strcat(dirname, "/"); - - /* - * Write a dir to it (with trailing '/'). - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, dirname); - archive_entry_set_mode(ae, S_IFDIR | 0755); - failure("dlen=%d, flen=%d", dlen, flen); - if (flen >= 100) { - assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); - } else { - assertEqualIntA(a, 0, archive_write_header(a, ae)); - } - archive_entry_free(ae); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - if (flen <= 100) { - /* Read the file and check the filename. */ - assertA(0 == archive_read_next_header(a, &ae)); - failure("dlen=%d, flen=%d", dlen, flen); - assertEqualString(filename, archive_entry_pathname(ae)); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - } - - /* - * Read the two dirs and check the names. - * - * Both dirs should read back with the same name, since - * tar should add a trailing '/' to any dir that doesn't - * already have one. - */ - if (flen <= 99) { - assertA(0 == archive_read_next_header(a, &ae)); - assert((S_IFDIR | 0755) == archive_entry_mode(ae)); - failure("dlen=%d, flen=%d", dlen, flen); - assertEqualString(dirname, archive_entry_pathname(ae)); - } - - if (flen <= 99) { - assertA(0 == archive_read_next_header(a, &ae)); - assert((S_IFDIR | 0755) == archive_entry_mode(ae)); - assertEqualString(dirname, archive_entry_pathname(ae)); - } - - /* Verify the end of the archive. */ - failure("This fails if entries were written that should not have been written. dlen=%d, flen=%d", dlen, flen); - assertEqualInt(1, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif -} - -DEFINE_TEST(test_ustar_filenames) -{ - int dlen, flen; - - /* Try a bunch of different file/dir lengths that add up - * to just a little less or a little more than 100 bytes. - * This exercises the code that splits paths between ustar - * filename and prefix fields. - */ - for (dlen = 5; dlen < 70; dlen += 5) { - for (flen = 100 - dlen - 5; flen < 100 - dlen + 5; flen++) { - test_filename(NULL, dlen, flen); - test_filename("/", dlen, flen); - } - } - - /* Probe the 100-char limit for paths with no '/'. */ - for (flen = 90; flen < 110; flen++) { - test_filename(NULL, 0, flen); - test_filename("/", dlen, flen); - } - - /* XXXX TODO Probe the 100-char limit with a dir prefix. */ - /* XXXX TODO Probe the 255-char total limit. */ -} diff --git a/lib/libarchive/test/test_write_compress.c b/lib/libarchive/test/test_write_compress.c deleted file mode 100644 index e1b8f3c..0000000 --- a/lib/libarchive/test/test_write_compress.c +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * Copyright (c) 2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * A basic exercise of compress reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used; - int i; - - buffsize = 1000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_compress(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); - - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - - - archive_write_close(a); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - free(data); - free(buff); -} diff --git a/lib/libarchive/test/test_write_compress_bzip2.c b/lib/libarchive/test/test_write_compress_bzip2.c deleted file mode 100644 index 54c8a50..0000000 --- a/lib/libarchive/test/test_write_compress_bzip2.c +++ /dev/null @@ -1,228 +0,0 @@ -/*- - * Copyright (c) 2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * A basic exercise of bzip2 reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress_bzip2) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_bzip2(a); - if (r == ARCHIVE_FATAL) { - skipping("bzip2 writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); - assertEqualString("bzip2", archive_compression_name(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); - assertEqualString("bzip2", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assert(0 == archive_read_close(a)); - assert(0 == archive_read_finish(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_bzip2(a)); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "nonexistent-option=0")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=abc")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=9")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Curiously, this test fails; the test data above compresses - * better at default compression than at level 9. */ - /* - failure("compression-level=9 wrote %d bytes, default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 < used1); - */ - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assert(0 == archive_read_close(a)); - assert(0 == archive_read_finish(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_bzip2(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=1")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Level 0 really does result in larger data. */ - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assert(0 == archive_read_close(a)); - assert(0 == archive_read_finish(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/lib/libarchive/test/test_write_compress_gzip.c b/lib/libarchive/test/test_write_compress_gzip.c deleted file mode 100644 index 9e42b13..0000000 --- a/lib/libarchive/test/test_write_compress_gzip.c +++ /dev/null @@ -1,252 +0,0 @@ -/*- - * Copyright (c) 2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * A basic exercise of gzip reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress_gzip) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_gzip(a); - if (r == ARCHIVE_FATAL) { - skipping("gzip writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); - assertEqualString("gzip", archive_compression_name(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); - assertEqualString("gzip", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify gzip writing by reading back;" - " gzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_gzip(a)); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "nonexistent-option=0")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=abc")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=9")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Curiously, this test fails; the test data above compresses - * better at default compression than at level 9. */ - /* - failure("compression-level=9 wrote %d bytes, default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 < used1); - */ - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_gzip(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=0")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Level 0 really does result in larger data. */ - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/lib/libarchive/test/test_write_compress_lzma.c b/lib/libarchive/test/test_write_compress_lzma.c deleted file mode 100644 index 88b9d63..0000000 --- a/lib/libarchive/test/test_write_compress_lzma.c +++ /dev/null @@ -1,250 +0,0 @@ -/*- - * Copyright (c) 2007-2009 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * A basic exercise of lzma reading and writing. - * - */ - -DEFINE_TEST(test_write_compress_lzma) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_lzma(a); - if (r == ARCHIVE_FATAL) { - skipping("lzma writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); - assertEqualString("lzma", archive_compression_name(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); - assertEqualString("lzma", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify lzma writing by reading back;" - " lzma reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_lzma(a)); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "nonexistent-option=0")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=abc")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=9")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - failure("Trying to read %s", path); - if (!assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_lzma(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=0")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* It would be nice to assert that compression-level=0 produced - * consistently larger/smaller results than the default compression, - * but the results here vary a lot depending on the version of liblzma - * being used. */ - /* - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - */ - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/lib/libarchive/test/test_write_compress_program.c b/lib/libarchive/test/test_write_compress_program.c deleted file mode 100644 index 34d0680..0000000 --- a/lib/libarchive/test/test_write_compress_program.c +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -char buff[1000000]; -char buff2[64]; - -DEFINE_TEST(test_write_compress_program) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("archive_write_set_compress_program()"); -#else - struct archive_entry *ae; - struct archive *a; - size_t used; - int blocksize = 1024; - int r; - - if (!canGzip()) { - skipping("Cannot run 'gzip'"); - return; - } - - /* Create a new archive in memory. */ - /* Write it through an external "gzip" program. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_program(a, "gzip"); - if (r == ARCHIVE_FATAL) { - skipping("Write compression via external " - "program unsupported on this platform"); - archive_write_finish(a); - return; - } - assertA(0 == archive_write_set_bytes_per_block(a, blocksize)); - assertA(0 == archive_write_set_bytes_in_last_block(a, blocksize)); - assertA(blocksize == archive_write_get_bytes_in_last_block(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - assertA(blocksize == archive_write_get_bytes_in_last_block(a)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(8 == archive_write_data(a, "12345678", 9)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - - /* - * Now, read the data back through the built-in gzip support. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - /* The compression_gzip() handler will fall back to gunzip - * automatically, but if we know gunzip isn't available, then - * skip the rest. */ - if (r != ARCHIVE_OK && !canGunzip()) { - skipping("No libz and no gunzip program, " - "unable to verify gzip compression"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) { - archive_read_finish(a); - return; - } - - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "12345678", 8); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} diff --git a/lib/libarchive/test/test_write_compress_xz.c b/lib/libarchive/test/test_write_compress_xz.c deleted file mode 100644 index 554d163..0000000 --- a/lib/libarchive/test/test_write_compress_xz.c +++ /dev/null @@ -1,257 +0,0 @@ -/*- - * Copyright (c) 2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * A basic exercise of xz reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress_xz) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_xz(a); - if (r == ARCHIVE_FATAL) { - skipping("xz writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); - assertEqualString("xz", archive_compression_name(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); - assertEqualString("xz", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify xz writing by reading back;" - " xz reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_xz(a)); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "nonexistent-option=0")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=abc")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=9")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Curiously, this test fails; the test data above compresses - * better at default compression than at level 9. */ - /* - failure("compression-level=9 wrote %d bytes, default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 < used1); - */ - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - failure("Trying to read %s", path); - if (!assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_xz(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=0")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* I would like to assert that compression-level=0 results in - * larger data than the default compression, but that's not true - * for all versions of liblzma. */ - /* - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - */ - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/lib/libarchive/test/test_write_disk.c b/lib/libarchive/test/test_write_disk.c deleted file mode 100644 index f3f4e56..0000000 --- a/lib/libarchive/test/test_write_disk.c +++ /dev/null @@ -1,332 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - -#define UMASK 022 -/* - * When comparing mode values, ignore high-order bits - * that are set on some OSes. This should cover the bits - * we're interested in (standard mode bits + file type bits) - * while ignoring extra markers such as Haiku/BeOS index - * flags. - */ -#define MODE_MASK 0777777 - -static void create(struct archive_entry *ae, const char *msg) -{ - struct archive *ad; - struct stat st; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - failure("%s", msg); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entries on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - failure("%s", msg); - -#if !defined(_WIN32) || defined(__CYGWIN__) - /* When verifying a dir, ignore the S_ISGID bit, as some systems set - * that automatically. */ - if (archive_entry_filetype(ae) == AE_IFDIR) - st.st_mode &= ~S_ISGID; - assertEqualInt(st.st_mode & MODE_MASK, - archive_entry_mode(ae) & ~UMASK & MODE_MASK); -#endif -} - -static void create_reg_file(struct archive_entry *ae, const char *msg) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME); - failure("%s", msg); - /* - * A touchy API design issue: archive_write_data() does (as of - * 2.4.12) enforce the entry size as a limit on the data - * written to the file. This was not enforced prior to - * 2.4.12. The change was prompted by the refined - * hardlink-restore semantics introduced at that time. In - * short, libarchive needs to know whether a "hardlink entry" - * is going to overwrite the contents so that it can know - * whether or not to open the file for writing. This implies - * that there is a fundamental semantic difference between an - * entry with a zero size and one with a non-zero size in the - * case of hardlinks and treating the hardlink case - * differently from the regular file case is just asking for - * trouble. So, a zero size must always mean that no data - * will be accepted, which is consistent with the file size in - * the entry being a maximum size. - */ - archive_entry_set_size(ae, sizeof(data)); - archive_entry_set_mtime(ae, 123456789, 0); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entries on disk. */ - assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777); - assertFileSize(archive_entry_pathname(ae), sizeof(data)); - /* test_write_disk_times has more detailed tests of this area. */ - assertFileMtime(archive_entry_pathname(ae), 123456789, 0); - failure("No atime given, so atime should get set to current time"); - assertFileAtimeRecent(archive_entry_pathname(ae)); -} - -static void create_reg_file2(struct archive_entry *ae, const char *msg) -{ - const int datasize = 100000; - char *data; - struct archive *ad; - int i; - - data = malloc(datasize); - for (i = 0; i < datasize; i++) - data[i] = (char)(i % 256); - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - failure("%s", msg); - /* - * See above for an explanation why this next call - * is necessary. - */ - archive_entry_set_size(ae, datasize); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - for (i = 0; i < datasize - 999; i += 1000) { - assertEqualIntA(ad, ARCHIVE_OK, - archive_write_data_block(ad, data + i, 1000, i)); - } - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - assertEqualInt(0, archive_write_finish(ad)); - - /* Test the entries on disk. */ - assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777); - assertFileSize(archive_entry_pathname(ae), i); - assertFileContents(data, datasize, archive_entry_pathname(ae)); - free(data); -} - -static void create_reg_file3(struct archive_entry *ae, const char *msg) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct stat st; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - failure("%s", msg); - /* Set the size smaller than the data and verify the truncation. */ - archive_entry_set_size(ae, 5); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(5, archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entry on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - failure("st.st_mode=%o archive_entry_mode(ae)=%o", - st.st_mode, archive_entry_mode(ae)); -#if !defined(_WIN32) || defined(__CYGWIN__) - assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK)); -#endif - assertEqualInt(st.st_size, 5); -} - - -static void create_reg_file4(struct archive_entry *ae, const char *msg) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct stat st; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - /* Leave the size unset. The data should not be truncated. */ - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(ARCHIVE_OK, - archive_write_data_block(ad, data, sizeof(data), 0)); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entry on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - failure("st.st_mode=%o archive_entry_mode(ae)=%o", - st.st_mode, archive_entry_mode(ae)); -#if !defined(_WIN32) || defined(__CYGWIN__) - assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK)); -#endif - failure(msg); - assertEqualInt(st.st_size, sizeof(data)); -} - -#if defined(_WIN32) && !defined(__CYGWIN__) -static void create_reg_file_win(struct archive_entry *ae, const char *msg) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct stat st; - char *p, *fname; - size_t l; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME); - failure("%s", msg); - archive_entry_set_size(ae, sizeof(data)); - archive_entry_set_mtime(ae, 123456789, 0); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entries on disk. */ - l = strlen(archive_entry_pathname(ae)); - fname = malloc(l + 1); - assert(NULL != fname); - strcpy(fname, archive_entry_pathname(ae)); - /* Replace unusable characters in Windows to '_' */ - for (p = fname; *p != '\0'; p++) - if (*p == ':' || *p == '*' || *p == '?' || - *p == '"' || *p == '<' || *p == '>' || *p == '|') - *p = '_'; - assert(0 == stat(fname, &st)); - failure("st.st_mode=%o archive_entry_mode(ae)=%o", - st.st_mode, archive_entry_mode(ae)); - assertEqualInt(st.st_size, sizeof(data)); -} -#endif /* _WIN32 && !__CYGWIN__ */ -#endif - -DEFINE_TEST(test_write_disk) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("archive_write_disk interface"); -#else - struct archive_entry *ae; - - /* Force the umask to something predictable. */ - assertUmask(UMASK); - - /* A regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file(ae, "Test creating a regular file"); - archive_entry_free(ae); - - /* Another regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file2(ae, "Test creating another regular file"); - archive_entry_free(ae); - - /* A regular file with a size restriction */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file3"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file3(ae, "Regular file with size restriction"); - archive_entry_free(ae); - - /* A regular file with an unspecified size */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file3"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file4(ae, "Regular file with unspecified size"); - archive_entry_free(ae); - - /* A regular file over an existing file */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0724); - create(ae, "Test creating a file over an existing file."); - archive_entry_free(ae); - - /* A directory. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir"); - archive_entry_set_mode(ae, S_IFDIR | 0555); - create(ae, "Test creating a regular dir."); - archive_entry_free(ae); - - /* A directory over an existing file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFDIR | 0742); - create(ae, "Test creating a dir over an existing file."); - archive_entry_free(ae); - - /* A file over an existing dir. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0744); - create(ae, "Test creating a file over an existing dir."); - archive_entry_free(ae); - -#if defined(_WIN32) && !defined(__CYGWIN__) - /* A file with unusable characters in its file name. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "f:i*l?e\"fl|e"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file_win(ae, "Test creating a regular file" - " with unusable characters in its file name"); - archive_entry_free(ae); - - /* A file with unusable characters in its directory name. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "d:i*r?e\"co|ry/file1"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file_win(ae, "Test creating a regular file" - " with unusable characters in its file name"); - archive_entry_free(ae); -#endif /* _WIN32 && !__CYGWIN__ */ -#endif -} diff --git a/lib/libarchive/test/test_write_disk_failures.c b/lib/libarchive/test/test_write_disk_failures.c deleted file mode 100644 index f74c947..0000000 --- a/lib/libarchive/test/test_write_disk_failures.c +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - -#define UMASK 022 - - -#endif - -DEFINE_TEST(test_write_disk_failures) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 || (defined(_WIN32) && !defined(__CYGWIN__)) - skipping("archive_write_disk interface"); -#else - struct archive_entry *ae; - struct archive *a; - int fd; - - /* Force the umask to something predictable. */ - assertUmask(UMASK); - - /* A directory that we can't write to. */ - assertMakeDir("dir", 0555); - - /* Can we? */ - fd = open("dir/testfile", O_WRONLY | O_CREAT | O_BINARY, 0777); - if (fd >= 0) { - /* Apparently, we can, so the test below won't work. */ - close(fd); - skipping("Can't test writing to non-writable directory"); - return; - } - - /* Try to extract a regular file into the directory above. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir/file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assert((a = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_TIME); - archive_entry_set_mtime(ae, 123456789, 0); - assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - assertEqualInt(0, archive_write_finish(a)); - archive_entry_free(ae); -#endif -} diff --git a/lib/libarchive/test/test_write_disk_hardlink.c b/lib/libarchive/test/test_write_disk_hardlink.c deleted file mode 100644 index 5756602..0000000 --- a/lib/libarchive/test/test_write_disk_hardlink.c +++ /dev/null @@ -1,219 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#if defined(_WIN32) && !defined(__CYGWIN__) -/* Execution bits, Group members bits and others bits do not work. */ -#define UMASK 0177 -#define E_MASK (~0177) -#else -#define UMASK 022 -#define E_MASK (~0) -#endif - -/* - * Exercise hardlink recreation. - * - * File permissions are chosen so that the authoritive entry - * has the correct permission and the non-authoritive versions - * are just writeable files. - */ -DEFINE_TEST(test_write_disk_hardlink) -{ -#if defined(__HAIKU__) - skipping("archive_write_disk_hardlink; hardlinks are not supported on bfs"); -#else - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct archive_entry *ae; - int r; - - /* Force the umask to something predictable. */ - assertUmask(UMASK); - - /* Write entries to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - - /* - * First, use a tar-like approach; a regular file, then - * a separate "hardlink" entry. - */ - - /* Regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link1a"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Link. Size of zero means this doesn't carry data. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link1b"); - archive_entry_set_mode(ae, S_IFREG | 0642); - archive_entry_set_size(ae, 0); - archive_entry_copy_hardlink(ae, "link1a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r >= ARCHIVE_WARN) { - assertEqualInt(ARCHIVE_WARN, - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); - - /* - * Repeat tar approach test, but use unset to mark the - * hardlink as having no data. - */ - - /* Regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link2a"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Link. Unset size means this doesn't carry data. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link2b"); - archive_entry_set_mode(ae, S_IFREG | 0642); - archive_entry_unset_size(ae); - archive_entry_copy_hardlink(ae, "link2a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r >= ARCHIVE_WARN) { - assertEqualInt(ARCHIVE_WARN, - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); - - /* - * Second, try an old-cpio-like approach; a regular file, then - * another identical one (which has been marked hardlink). - */ - - /* Regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link3a"); - archive_entry_set_mode(ae, S_IFREG | 0600); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Link. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link3b"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - archive_entry_copy_hardlink(ae, "link3a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r > ARCHIVE_WARN) { - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); - - /* - * Finally, try a new-cpio-like approach, where the initial - * regular file is empty and the hardlink has the data. - */ - - /* Regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link4a"); - archive_entry_set_mode(ae, S_IFREG | 0600); - archive_entry_set_size(ae, 0); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); -#if ARCHIVE_VERSION_NUMBER < 3000000 - assertEqualInt(ARCHIVE_WARN, archive_write_data(ad, data, 1)); -#else - assertEqualInt(-1, archive_write_data(ad, data, 1)); -#endif - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Link. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link4b"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - archive_entry_copy_hardlink(ae, "link4a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r > ARCHIVE_FAILED) { - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); - assertEqualInt(0, archive_write_finish(ad)); - - /* Test the entries on disk. */ - - /* Test #1 */ - /* If the hardlink was successfully created and the archive - * doesn't carry data for it, we consider it to be - * non-authoritive for meta data as well. This is consistent - * with GNU tar and BSD pax. */ - assertIsReg("link1a", 0755 & ~UMASK); - assertFileSize("link1a", sizeof(data)); - assertFileNLinks("link1a", 2); - assertIsHardlink("link1a", "link1b"); - - /* Test #2: Should produce identical results to test #1 */ - /* Note that marking a hardlink with size = 0 is treated the - * same as having an unset size. This is partly for backwards - * compatibility (we used to not have unset tracking, so - * relied on size == 0) and partly to match the model used by - * common file formats that store a size of zero for - * hardlinks. */ - assertIsReg("link2a", 0755 & ~UMASK); - assertFileSize("link2a", sizeof(data)); - assertFileNLinks("link2a", 2); - assertIsHardlink("link2a", "link2b"); - - /* Test #3 */ - assertIsReg("link3a", 0755 & ~UMASK); - assertFileSize("link3a", sizeof(data)); - assertFileNLinks("link3a", 2); - assertIsHardlink("link3a", "link3b"); - - /* Test #4 */ - assertIsReg("link4a", 0755 & ~UMASK); - assertFileNLinks("link4a", 2); - assertFileSize("link4a", sizeof(data)); - assertIsHardlink("link4a", "link4b"); -#endif -} diff --git a/lib/libarchive/test/test_write_disk_perms.c b/lib/libarchive/test/test_write_disk_perms.c deleted file mode 100644 index f53ce19..0000000 --- a/lib/libarchive/test/test_write_disk_perms.c +++ /dev/null @@ -1,457 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 && (!defined(_WIN32) || defined(__CYGWIN__)) - -#define UMASK 022 - -static long _default_gid = -1; -static long _invalid_gid = -1; -static long _alt_gid = -1; - -/* - * To fully test SGID restores, we need three distinct GIDs to work - * with: - * * the GID that files are created with by default (for the - * current user in the current directory) - * * An "alt gid" that this user can create files with - * * An "invalid gid" that this user is not permitted to create - * files with. - * The second fails if this user doesn't belong to at least two groups; - * the third fails if the current user is root. - */ -static void -searchgid(void) -{ - static int _searched = 0; - uid_t uid = getuid(); - gid_t gid = 0; - unsigned int n; - struct stat st; - int fd; - - /* If we've already looked this up, we're done. */ - if (_searched) - return; - _searched = 1; - - /* Create a file on disk in the current default dir. */ - fd = open("test_gid", O_CREAT | O_BINARY, 0664); - failure("Couldn't create a file for gid testing."); - assert(fd > 0); - - /* See what GID it ended up with. This is our "valid" GID. */ - assert(fstat(fd, &st) == 0); - _default_gid = st.st_gid; - - /* Find a GID for which fchown() fails. This is our "invalid" GID. */ - _invalid_gid = -1; - /* This loop stops when we wrap the gid or examine 10,000 gids. */ - for (gid = 1, n = 1; gid == n && n < 10000 ; n++, gid++) { - if (fchown(fd, uid, gid) != 0) { - _invalid_gid = gid; - break; - } - } - - /* - * Find a GID for which fchown() succeeds, but which isn't the - * default. This is the "alternate" gid. - */ - _alt_gid = -1; - for (gid = 0, n = 0; gid == n && n < 10000 ; n++, gid++) { - /* _alt_gid must be different than _default_gid */ - if (gid == (gid_t)_default_gid) - continue; - if (fchown(fd, uid, gid) == 0) { - _alt_gid = gid; - break; - } - } - close(fd); -} - -static int -altgid(void) -{ - searchgid(); - return (_alt_gid); -} - -static int -invalidgid(void) -{ - searchgid(); - return (_invalid_gid); -} - -static int -defaultgid(void) -{ - searchgid(); - return (_default_gid); -} -#endif - -/* - * Exercise permission and ownership restores. - * In particular, try to exercise a bunch of border cases related - * to files/dirs that already exist, SUID/SGID bits, etc. - */ - -DEFINE_TEST(test_write_disk_perms) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 || (defined(_WIN32) && !defined(__CYGWIN__)) - skipping("archive_write_disk interface"); -#else - struct archive *a; - struct archive_entry *ae; - struct stat st; - - assertUmask(UMASK); - - /* - * Set ownership of the current directory to the group of this - * process. Otherwise, the SGID tests below fail if the - * /tmp directory is owned by a group to which we don't belong - * and we're on a system where group ownership is inherited. - * (Because we're not allowed to SGID files with defaultgid().) - */ - assertEqualInt(0, chown(".", getuid(), getgid())); - - /* Create an archive_write_disk object. */ - assert((a = archive_write_disk_new()) != NULL); - - /* Write a regular file to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file_0755"); - archive_entry_set_mode(ae, S_IFREG | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - archive_entry_free(ae); - - /* Write a regular file, then write over it. */ - /* For files, the perms should get updated. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file_overwrite_0144"); - archive_entry_set_mode(ae, S_IFREG | 0777); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - /* Check that file was created with different perms. */ - assert(0 == stat("file_overwrite_0144", &st)); - failure("file_overwrite_0144: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) != 0144); - /* Overwrite, this should change the perms. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file_overwrite_0144"); - archive_entry_set_mode(ae, S_IFREG | 0144); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* Write a regular dir. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir_0514"); - archive_entry_set_mode(ae, S_IFDIR | 0514); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* Overwrite an existing dir. */ - /* For dir, the first perms should get left. */ - assertMakeDir("dir_overwrite_0744", 0744); - /* Check original perms. */ - assert(0 == stat("dir_overwrite_0744", &st)); - failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0744); - /* Overwrite shouldn't edit perms. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir_overwrite_0744"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - /* Make sure they're unchanged. */ - assert(0 == stat("dir_overwrite_0744", &st)); - failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0744); - - /* Write a regular file with SUID bit, but don't use _EXTRACT_PERM. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file_no_suid"); - archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0777); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* Write a regular file with ARCHIVE_EXTRACT_PERM. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_0777"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* Write a regular file with ARCHIVE_EXTRACT_PERM & SUID bit */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_4742"); - archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0742); - archive_entry_set_uid(ae, getuid()); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* - * Write a regular file with ARCHIVE_EXTRACT_PERM & SUID bit, - * but wrong uid. POSIX says you shouldn't restore SUID bit - * unless the UID could be restored. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_suid"); - archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0742); - archive_entry_set_uid(ae, getuid() + 1); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assertA(0 == archive_write_header(a, ae)); - /* - * Because we didn't ask for owner, the failure to - * restore SUID shouldn't return a failure. - * We check below to make sure SUID really wasn't set. - * See more detailed comments below. - */ - failure("Opportunistic SUID failure shouldn't return error."); - assertEqualInt(0, archive_write_finish_entry(a)); - - if (getuid() != 0) { - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_suid2"); - archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0742); - archive_entry_set_uid(ae, getuid() + 1); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_OWNER); - assertA(0 == archive_write_header(a, ae)); - /* Owner change should fail here. */ - failure("Non-opportunistic SUID failure should return error."); - assertEqualInt(ARCHIVE_WARN, archive_write_finish_entry(a)); - } - - /* Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_perm_sgid"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_gid(ae, defaultgid()); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assert(0 == archive_write_header(a, ae)); - failure("Setting SGID bit should succeed here."); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - if (altgid() == -1) { - /* - * Current user must belong to at least two groups or - * else we can't test setting the GID to another group. - */ - skipping("Current user can't test gid restore: must belong to more than one group."); - } else { - /* - * Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit - * but without ARCHIVE_EXTRACT_OWNER. - */ - /* - * This is a weird case: The user has asked for permissions to - * be restored but not asked for ownership to be restored. As - * a result, the default file creation will create a file with - * the wrong group. There are several possible behaviors for - * libarchive in this scenario: - * = Set the SGID bit. It is wrong and a security hole to - * set SGID with the wrong group. Even POSIX thinks so. - * = Implicitly set the group. I don't like this. - * = drop the SGID bit and warn (the old libarchive behavior) - * = drop the SGID bit and don't warn (the current libarchive - * behavior). - * The current behavior sees SGID/SUID restore when you - * don't ask for owner restore as an "opportunistic" - * action. That is, libarchive should do it if it can, - * but if it can't, it's not an error. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_alt_sgid"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_uid(ae, getuid()); - archive_entry_set_gid(ae, altgid()); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assert(0 == archive_write_header(a, ae)); - failure("Setting SGID bit should fail because of group mismatch but the failure should be silent because we didn't ask for the group to be set."); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - /* - * As above, but add _EXTRACT_OWNER to verify that it - * does succeed. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_alt_sgid_owner"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_uid(ae, getuid()); - archive_entry_set_gid(ae, altgid()); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_OWNER); - assert(0 == archive_write_header(a, ae)); - failure("Setting SGID bit should succeed here."); - assertEqualIntA(a, ARCHIVE_OK, archive_write_finish_entry(a)); - } - - /* - * Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit, - * but wrong GID. POSIX says you shouldn't restore SGID bit - * unless the GID could be restored. - */ - if (invalidgid() == -1) { - /* This test always fails for root. */ - printf("Running as root: Can't test SGID failures.\n"); - } else { - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_sgid"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_gid(ae, invalidgid()); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assertA(0 == archive_write_header(a, ae)); - failure("This SGID restore should fail without an error."); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_sgid2"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_gid(ae, invalidgid()); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_OWNER); - assertA(0 == archive_write_header(a, ae)); - failure("This SGID restore should fail with an error."); - assertEqualIntA(a, ARCHIVE_WARN, archive_write_finish_entry(a)); - } - - /* Set ownership should fail if we're not root. */ - if (getuid() == 0) { - printf("Running as root: Can't test setuid failures.\n"); - } else { - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_owner"); - archive_entry_set_mode(ae, S_IFREG | 0744); - archive_entry_set_uid(ae, getuid() + 1); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_OWNER); - assertA(0 == archive_write_header(a, ae)); - assertEqualIntA(a,ARCHIVE_WARN,archive_write_finish_entry(a)); - } - -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - archive_entry_free(ae); - - /* Test the entries on disk. */ - assert(0 == stat("file_0755", &st)); - failure("file_0755: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); - - assert(0 == stat("file_overwrite_0144", &st)); - failure("file_overwrite_0144: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0144); - - assert(0 == stat("dir_0514", &st)); - failure("dir_0514: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0514); - - assert(0 == stat("dir_overwrite_0744", &st)); - failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0744); - - assert(0 == stat("file_no_suid", &st)); - failure("file_0755: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); - - assert(0 == stat("file_0777", &st)); - failure("file_0777: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0777); - - /* SUID bit should get set here. */ - assert(0 == stat("file_4742", &st)); - failure("file_4742: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (S_ISUID | 0742)); - - /* SUID bit should NOT have been set here. */ - assert(0 == stat("file_bad_suid", &st)); - failure("file_bad_suid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - - /* Some things don't fail if you're root, so suppress this. */ - if (getuid() != 0) { - /* SUID bit should NOT have been set here. */ - assert(0 == stat("file_bad_suid2", &st)); - failure("file_bad_suid2: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - } - - /* SGID should be set here. */ - assert(0 == stat("file_perm_sgid", &st)); - failure("file_perm_sgid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (S_ISGID | 0742)); - - if (altgid() != -1) { - /* SGID should not be set here. */ - assert(0 == stat("file_alt_sgid", &st)); - failure("file_alt_sgid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - - /* SGID should be set here. */ - assert(0 == stat("file_alt_sgid_owner", &st)); - failure("file_alt_sgid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (S_ISGID | 0742)); - } - - if (invalidgid() != -1) { - /* SGID should NOT be set here. */ - assert(0 == stat("file_bad_sgid", &st)); - failure("file_bad_sgid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - /* SGID should NOT be set here. */ - assert(0 == stat("file_bad_sgid2", &st)); - failure("file_bad_sgid2: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - } - - if (getuid() != 0) { - assert(0 == stat("file_bad_owner", &st)); - failure("file_bad_owner: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0744)); - failure("file_bad_owner: st.st_uid=%d getuid()=%d", - st.st_uid, getuid()); - /* The entry had getuid()+1, but because we're - * not root, we should not have been able to set that. */ - assert(st.st_uid == getuid()); - } -#endif -} diff --git a/lib/libarchive/test/test_write_disk_secure.c b/lib/libarchive/test/test_write_disk_secure.c deleted file mode 100644 index 74506f1..0000000 --- a/lib/libarchive/test/test_write_disk_secure.c +++ /dev/null @@ -1,215 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -#define UMASK 022 - -/* - * Exercise security checks that should prevent certain - * writes. - */ - -DEFINE_TEST(test_write_disk_secure) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("archive_write_disk interface"); -#elif !defined(_WIN32) || defined(__CYGWIN__) - struct archive *a; - struct archive_entry *ae; - struct stat st; - - /* Start with a known umask. */ - assertUmask(UMASK); - - /* Create an archive_write_disk object. */ - assert((a = archive_write_disk_new()) != NULL); - - /* Write a regular dir to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* Write a symlink to the dir above. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* - * Without security checks, we should be able to - * extract a file through the link. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir/filea"); - archive_entry_set_mode(ae, S_IFREG | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* But with security checks enabled, this should fail. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir/fileb"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_SYMLINKS); - failure("Extracting a file through a symlink should fail here."); - assertEqualInt(ARCHIVE_FAILED, archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* Create another link. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir2"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* - * With symlink check and unlink option, it should remove - * the link and create the dir. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir2/filec"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_SYMLINKS | ARCHIVE_EXTRACT_UNLINK); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* - * Without security checks, extracting a dir over a link to a - * dir should follow the link. - */ - /* Create a symlink to a dir. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir3"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Extract a dir whose name matches the symlink. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir3"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Verify link was followed. */ - assertEqualInt(0, lstat("link_to_dir3", &st)); - assert(S_ISLNK(st.st_mode)); - archive_entry_free(ae); - - /* - * As above, but a broken link, so the link should get replaced. - */ - /* Create a symlink to a dir. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir4"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "nonexistent_dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Extract a dir whose name matches the symlink. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir4"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Verify link was replaced. */ - assertEqualInt(0, lstat("link_to_dir4", &st)); - assert(S_ISDIR(st.st_mode)); - archive_entry_free(ae); - - /* - * As above, but a link to a non-dir, so the link should get replaced. - */ - /* Create a regular file and a symlink to it */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "non_dir"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Create symlink to the file. */ - archive_entry_copy_pathname(ae, "link_to_dir5"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "non_dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Extract a dir whose name matches the symlink. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir5"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Verify link was replaced. */ - assertEqualInt(0, lstat("link_to_dir5", &st)); - assert(S_ISDIR(st.st_mode)); - archive_entry_free(ae); - - assert(0 == archive_write_finish(a)); - - /* Test the entries on disk. */ - assert(0 == lstat("dir", &st)); - failure("dir: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0755); - - assert(0 == lstat("link_to_dir", &st)); - failure("link_to_dir: st.st_mode=%o", st.st_mode); - assert(S_ISLNK(st.st_mode)); -#if HAVE_LCHMOD - /* Systems that lack lchmod() can't set symlink perms, so skip this. */ - failure("link_to_dir: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); -#endif - - assert(0 == lstat("dir/filea", &st)); - failure("dir/filea: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); - - failure("dir/fileb: This file should not have been created"); - assert(0 != lstat("dir/fileb", &st)); - - assert(0 == lstat("link_to_dir2", &st)); - failure("link_to_dir2 should have been re-created as a true dir"); - assert(S_ISDIR(st.st_mode)); - failure("link_to_dir2: Implicit dir creation should obey umask, but st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0755); - - assert(0 == lstat("link_to_dir2/filec", &st)); - assert(S_ISREG(st.st_mode)); - failure("link_to_dir2/filec: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); -#endif -} diff --git a/lib/libarchive/test/test_write_disk_sparse.c b/lib/libarchive/test/test_write_disk_sparse.c deleted file mode 100644 index b613f56..0000000 --- a/lib/libarchive/test/test_write_disk_sparse.c +++ /dev/null @@ -1,280 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Write a file using archive_write_data call, read the file - * back and verify the contents. The data written includes large - * blocks of nulls, so it should exercise the sparsification logic - * if ARCHIVE_EXTRACT_SPARSE is enabled. - */ -static void -verify_write_data(struct archive *a, int sparse) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct stat st; - struct archive_entry *ae; - size_t buff_size = 64 * 1024; - char *buff, *p; - const char *msg = sparse ? "sparse" : "non-sparse"; - FILE *f; - - buff = malloc(buff_size); - assert(buff != NULL); - - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_size(ae, 8 * buff_size); - archive_entry_set_pathname(ae, "test_write_data"); - archive_entry_set_mode(ae, AE_IFREG | 0755); - assertEqualIntA(a, 0, archive_write_header(a, ae)); - - /* Use archive_write_data() to write three relatively sparse blocks. */ - - /* First has non-null data at beginning. */ - memset(buff, 0, buff_size); - memcpy(buff, data, sizeof(data)); - failure("%s", msg); - assertEqualInt(buff_size, archive_write_data(a, buff, buff_size)); - - /* Second has non-null data in the middle. */ - memset(buff, 0, buff_size); - memcpy(buff + buff_size / 2 - 3, data, sizeof(data)); - failure("%s", msg); - assertEqualInt(buff_size, archive_write_data(a, buff, buff_size)); - - /* Third has non-null data at the end. */ - memset(buff, 0, buff_size); - memcpy(buff + buff_size - sizeof(data), data, sizeof(data)); - failure("%s", msg); - assertEqualInt(buff_size, archive_write_data(a, buff, buff_size)); - - failure("%s", msg); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - /* Test the entry on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - assertEqualInt(st.st_size, 8 * buff_size); - f = fopen(archive_entry_pathname(ae), "rb"); - if (!assert(f != NULL)) - return; - - /* Check first block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - failure("%s", msg); - assertEqualMem(buff, data, sizeof(data)); - for (p = buff + sizeof(data); p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check second block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - for (p = buff; p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (p == buff + buff_size / 2 - 3) { - assertEqualMem(p, data, sizeof(data)); - p += sizeof(data); - } else if (!assertEqualInt(0, *p)) - break; - } - - /* Check third block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - for (p = buff; p < buff + buff_size - sizeof(data); ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - failure("%s", msg); - assertEqualMem(buff + buff_size - sizeof(data), data, sizeof(data)); - - /* XXX more XXX */ - - assertEqualInt(0, fclose(f)); - archive_entry_free(ae); - free(buff); -} - -/* - * As above, but using the archive_write_data_block() call. - */ -static void -verify_write_data_block(struct archive *a, int sparse) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct stat st; - struct archive_entry *ae; - size_t buff_size = 64 * 1024; - char *buff, *p; - const char *msg = sparse ? "sparse" : "non-sparse"; - FILE *f; - - buff = malloc(buff_size); - assert(buff != NULL); - - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_size(ae, 8 * buff_size); - archive_entry_set_pathname(ae, "test_write_data_block"); - archive_entry_set_mode(ae, AE_IFREG | 0755); - assertEqualIntA(a, 0, archive_write_header(a, ae)); - - /* Use archive_write_data_block() to write three - relatively sparse blocks. */ - - /* First has non-null data at beginning. */ - memset(buff, 0, buff_size); - memcpy(buff, data, sizeof(data)); - failure("%s", msg); - assertEqualInt(ARCHIVE_OK, - archive_write_data_block(a, buff, buff_size, 100)); - - /* Second has non-null data in the middle. */ - memset(buff, 0, buff_size); - memcpy(buff + buff_size / 2 - 3, data, sizeof(data)); - failure("%s", msg); - assertEqualInt(ARCHIVE_OK, - archive_write_data_block(a, buff, buff_size, buff_size + 200)); - - /* Third has non-null data at the end. */ - memset(buff, 0, buff_size); - memcpy(buff + buff_size - sizeof(data), data, sizeof(data)); - failure("%s", msg); - assertEqualInt(ARCHIVE_OK, - archive_write_data_block(a, buff, buff_size, buff_size * 2 + 300)); - - failure("%s", msg); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - /* Test the entry on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - assertEqualInt(st.st_size, 8 * buff_size); - f = fopen(archive_entry_pathname(ae), "rb"); - if (!assert(f != NULL)) - return; - - /* Check 100-byte gap at beginning */ - assertEqualInt(100, fread(buff, 1, 100, f)); - failure("%s", msg); - for (p = buff; p < buff + 100; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check first block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - failure("%s", msg); - assertEqualMem(buff, data, sizeof(data)); - for (p = buff + sizeof(data); p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check 100-byte gap */ - assertEqualInt(100, fread(buff, 1, 100, f)); - failure("%s", msg); - for (p = buff; p < buff + 100; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check second block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - for (p = buff; p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (p == buff + buff_size / 2 - 3) { - assertEqualMem(p, data, sizeof(data)); - p += sizeof(data); - } else if (!assertEqualInt(0, *p)) - break; - } - - /* Check 100-byte gap */ - assertEqualInt(100, fread(buff, 1, 100, f)); - failure("%s", msg); - for (p = buff; p < buff + 100; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check third block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - for (p = buff; p < buff + buff_size - sizeof(data); ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - failure("%s", msg); - assertEqualMem(buff + buff_size - sizeof(data), data, sizeof(data)); - - /* Check another block size beyond last we wrote. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - failure("%s", msg); - for (p = buff; p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - - /* XXX more XXX */ - - assertEqualInt(0, fclose(f)); - free(buff); - archive_entry_free(ae); -} - -DEFINE_TEST(test_write_disk_sparse) -{ - struct archive *ad; - - - /* - * The return values, etc, of the write data functions - * shouldn't change regardless of whether we've requested - * sparsification. (The performance and pattern of actual - * write calls to the disk should vary, of course, but the - * client program shouldn't see any difference.) - */ - assert((ad = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(ad, 0); - verify_write_data(ad, 0); - verify_write_data_block(ad, 0); - assertEqualInt(0, archive_write_finish(ad)); - - assert((ad = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_SPARSE); - verify_write_data(ad, 1); - verify_write_data_block(ad, 1); - assertEqualInt(0, archive_write_finish(ad)); - -} diff --git a/lib/libarchive/test/test_write_disk_symlink.c b/lib/libarchive/test/test_write_disk_symlink.c deleted file mode 100644 index 861f3bf..0000000 --- a/lib/libarchive/test/test_write_disk_symlink.c +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Exercise symlink recreation. - */ -DEFINE_TEST(test_write_disk_symlink) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct archive_entry *ae; - int r; - - if (!canSymlink()) { - skipping("Symlinks not supported"); - return; - } - - /* Write entries to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - - /* - * First, create a regular file then a symlink to that file. - */ - - /* Regular file: link1a */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link1a"); - archive_entry_set_mode(ae, AE_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Symbolic Link: link1b -> link1a */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link1b"); - archive_entry_set_mode(ae, AE_IFLNK | 0642); - archive_entry_set_size(ae, 0); - archive_entry_copy_symlink(ae, "link1a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r >= ARCHIVE_WARN) - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* - * We should be able to do this in the other order as well, - * of course. - */ - - /* Symbolic link: link2b -> link2a */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link2b"); - archive_entry_set_mode(ae, AE_IFLNK | 0642); - archive_entry_unset_size(ae); - archive_entry_copy_symlink(ae, "link2a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r >= ARCHIVE_WARN) { - assertEqualInt(ARCHIVE_WARN, - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); - - /* File: link2a */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link2a"); - archive_entry_set_mode(ae, AE_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - assertEqualInt(ARCHIVE_OK, archive_write_finish(ad)); - - /* Test the entries on disk. */ - - /* Test #1 */ - assertIsReg("link1a", -1); - assertFileSize("link1a", sizeof(data)); - assertFileNLinks("link1a", 1); - assertIsSymlink("link1b", "link1a"); - - /* Test #2: Should produce identical results to test #1 */ - assertIsReg("link2a", -1); - assertFileSize("link2a", sizeof(data)); - assertFileNLinks("link2a", 1); - assertIsSymlink("link2b", "link2a"); -} diff --git a/lib/libarchive/test/test_write_disk_times.c b/lib/libarchive/test/test_write_disk_times.c deleted file mode 100644 index 13841cf..0000000 --- a/lib/libarchive/test/test_write_disk_times.c +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Exercise time restores in archive_write_disk(), including - * correct handling of omitted time values. - * On FreeBSD, we also test birthtime and high-res time restores. - */ - -DEFINE_TEST(test_write_disk_times) -{ - struct archive *a; - struct archive_entry *ae; - - /* Create an archive_write_disk object. */ - assert((a = archive_write_disk_new()) != NULL); - assertEqualInt(ARCHIVE_OK, - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_TIME)); - - /* - * Easy case: mtime and atime both specified. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file1"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_atime(ae, 123456, 0); - archive_entry_set_mtime(ae, 234567, 0); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileAtime("file1", 123456, 0); - assertFileMtime("file1", 234567, 0); - - /* - * mtime specified, but not atime - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_mtime(ae, 234567, 0); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - assertFileMtime("file2", 234567, 0); - assertFileAtimeRecent("file2"); - - /* - * atime specified, but not mtime - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file3"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_atime(ae, 345678, 0); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify: Current mtime and atime as specified. */ - assertFileAtime("file3", 345678, 0); - assertFileMtimeRecent("file3"); - - /* - * Neither atime nor mtime specified. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file4"); - archive_entry_set_mode(ae, S_IFREG | 0777); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify: Current mtime and atime. */ - assertFileAtimeRecent("file4"); - assertFileMtimeRecent("file4"); - -#if defined(__FreeBSD__) - /* - * High-res mtime and atime on FreeBSD. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file10"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_atime(ae, 1234567, 23456); - archive_entry_set_mtime(ae, 2345678, 4567); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileMtime("file10", 2345678, 4567); - assertFileAtime("file10", 1234567, 23456); - - /* - * Birthtime, mtime and atime on FreeBSD - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file11"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_atime(ae, 1234567, 23456); - archive_entry_set_birthtime(ae, 3456789, 12345); - /* mtime must be later than birthtime! */ - archive_entry_set_mtime(ae, 12345678, 4567); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileAtime("file11", 1234567, 23456); - assertFileBirthtime("file11", 3456789, 12345); - assertFileMtime("file11", 12345678, 4567); - - /* - * Birthtime only on FreeBSD. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file12"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_birthtime(ae, 3456789, 12345); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileAtimeRecent("file12"); - assertFileBirthtime("file12", 3456789, 12345); - assertFileMtimeRecent("file12"); - - /* - * mtime only on FreeBSD. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file13"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_mtime(ae, 4567890, 23456); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileAtimeRecent("file13"); - assertFileBirthtime("file13", 4567890, 23456); - assertFileMtime("file13", 4567890, 23456); -#else - skipping("Platform-specific time restore tests"); -#endif - - archive_write_finish(a); -} diff --git a/lib/libarchive/test/test_write_format_ar.c b/lib/libarchive/test/test_write_format_ar.c deleted file mode 100644 index 81224b3..0000000 --- a/lib/libarchive/test/test_write_format_ar.c +++ /dev/null @@ -1,209 +0,0 @@ -/*- - * Copyright (c) 2007 Kai Wang - * Copyright (c) 2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -char buff[4096]; -char buff2[64]; -static char strtab[] = "abcdefghijklmn.o/\nggghhhjjjrrrttt.o/\niiijjjdddsssppp.o/\n"; - -DEFINE_TEST(test_write_format_ar) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("ar write support"); -#else - struct archive_entry *ae; - struct archive* a; - size_t used; - - /* - * First we try to create a SVR4/GNU format archive. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ar_svr4(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* write the filename table */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "//"); - archive_entry_set_size(ae, strlen(strtab)); - assertA(0 == archive_write_header(a, ae)); - assertA(strlen(strtab) == (size_t)archive_write_data(a, strtab, strlen(strtab))); - archive_entry_free(ae); - - /* write entries */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 0); - assert(1 == archive_entry_mtime(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - archive_entry_copy_pathname(ae, "abcdefghijklmn.o"); - archive_entry_set_size(ae, 8); - assertA(0 == archive_write_header(a, ae)); - assertA(8 == archive_write_data(a, "87654321", 15)); - archive_entry_free(ae); - - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "ggghhhjjjrrrttt.o"); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, 7); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualIntA(a, 7, archive_write_data(a, "7777777", 7)); - archive_entry_free(ae); - - /* test full pathname */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "/usr/home/xx/iiijjjdddsssppp.o"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualIntA(a, 8, archive_write_data(a, "88877766", 8)); - archive_entry_free(ae); - - /* trailing "/" should be rejected */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "/usr/home/xx/iiijjj/"); - archive_entry_set_size(ae, 8); - assertA(0 != archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Non regular file should be rejected */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "gfgh.o"); - archive_entry_set_mode(ae, S_IFDIR | 0755); - archive_entry_set_size(ae, 6); - assertA(0 != archive_write_header(a, ae)); - archive_entry_free(ae); - - archive_write_close(a); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(0, archive_entry_mtime(ae)); - assertEqualString("//", archive_entry_pathname(ae)); - assertEqualInt(0, archive_entry_size(ae)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualString("abcdefghijklmn.o", archive_entry_pathname(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "87654321", 8); - - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("ggghhhjjjrrrttt.o", archive_entry_pathname(ae)); - assertEqualInt(7, archive_entry_size(ae)); - assertEqualIntA(a, 7, archive_read_data(a, buff2, 11)); - assertEqualMem(buff2, "7777777", 7); - - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualString("iiijjjdddsssppp.o", archive_entry_pathname(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 17)); - assertEqualMem(buff2, "88877766", 8); - - assertEqualIntA(a, 0, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif - - /* - * Then, we try to create a BSD format archive. - */ - memset(buff, 0, sizeof(buff)); - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ar_bsd(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* write a entry need long name extension */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "ttttyyyyuuuuiiii.o"); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, 5); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(5, archive_entry_size(ae)); - assertEqualIntA(a, 5, archive_write_data(a, "12345", 7)); - archive_entry_free(ae); - - /* write a entry with a short name */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "ttyy.o"); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, 6); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualIntA(a, 6, archive_write_data(a, "555555", 7)); - archive_entry_free(ae); - archive_write_close(a); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - - /* Now, Read the data back */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualString("ttttyyyyuuuuiiii.o", archive_entry_pathname(ae)); - assertEqualInt(5, archive_entry_size(ae)); - assertEqualIntA(a, 5, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "12345", 5); - - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualString("ttyy.o", archive_entry_pathname(ae)); - assertEqualInt(6, archive_entry_size(ae)); - assertEqualIntA(a, 6, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "555555", 6); - - /* Test EOF */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, 0, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif -#endif -} diff --git a/lib/libarchive/test/test_write_format_cpio.c b/lib/libarchive/test/test_write_format_cpio.c deleted file mode 100644 index 5c7141f..0000000 --- a/lib/libarchive/test/test_write_format_cpio.c +++ /dev/null @@ -1,194 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* The version stamp macro was introduced after cpio write support. */ -#if ARCHIVE_VERSION_NUMBER >= 1009000 -static void -test_format(int (*set_format)(struct archive *)) -{ - char filedata[64]; - struct archive_entry *ae; - struct archive *a; - char *p; - size_t used; - size_t buffsize = 1000000; - char *buff; - int damaged = 0; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == (*set_format)(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assert(1 == archive_entry_mtime(ae)); - assert(10 == archive_entry_mtime_nsec(ae)); - p = strdup("file"); - archive_entry_copy_pathname(ae, p); - strcpy(p, "XXXX"); - free(p); - assertEqualString("file", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - archive_entry_set_size(ae, 8); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(8 == archive_write_data(a, "12345678", 9)); - - /* - * Write another file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assert(1 == archive_entry_mtime(ae)); - assert(10 == archive_entry_mtime_nsec(ae)); - p = strdup("file2"); - archive_entry_copy_pathname(ae, p); - strcpy(p, "XXXX"); - free(p); - assertEqualString("file2", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - archive_entry_set_size(ae, 4); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(4 == archive_write_data(a, "1234", 5)); - - /* - * Write a directory to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 11, 110); - archive_entry_copy_pathname(ae, "dir"); - archive_entry_set_mode(ae, S_IFDIR | 0755); - archive_entry_set_size(ae, 512); - - assertA(0 == archive_write_header(a, ae)); - assertEqualInt(0, archive_entry_size(ae)); - archive_entry_free(ae); - assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9)); - - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* - * Damage the second entry to test the search-ahead recovery. - * TODO: Move the damage-recovery checking to a separate test; - * it doesn't really belong in this write test. - */ - { - int i; - for (i = 80; i < 150; i++) { - if (memcmp(buff + i, "07070", 5) == 0) { - damaged = 1; - buff[i] = 'X'; - break; - } - } - } - failure("Unable to locate the second header for damage-recovery test."); - assert(damaged == 1); - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) { - archive_read_finish(a); - return; - } - - assertEqualInt(1, archive_entry_mtime(ae)); - /* Not the same as above: cpio doesn't store hi-res times. */ - assert(0 == archive_entry_mtime_nsec(ae)); - assert(0 == archive_entry_atime(ae)); - assert(0 == archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertA(8 == archive_read_data(a, filedata, 10)); - assert(0 == memcmp(filedata, "12345678", 8)); - - /* - * The second file can't be read because we damaged its header. - */ - - /* - * Read the dir entry back. - * ARCHIVE_WARN here because the damaged entry was skipped. - */ - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assertEqualInt(11, archive_entry_mtime(ae)); - assert(0 == archive_entry_mtime_nsec(ae)); - assert(0 == archive_entry_atime(ae)); - assert(0 == archive_entry_ctime(ae)); - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt((S_IFDIR | 0755), archive_entry_mode(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, 0, archive_read_data(a, filedata, 10)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, 1, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - free(buff); -} -#endif - -DEFINE_TEST(test_write_format_cpio) -{ -#if ARCHIVE_VERSION_NUMBER >= 1009000 - test_format(archive_write_set_format_cpio); - test_format(archive_write_set_format_cpio_newc); -#else - skipping("cpio write support"); -#endif -} diff --git a/lib/libarchive/test/test_write_format_cpio_empty.c b/lib/libarchive/test/test_write_format_cpio_empty.c deleted file mode 100644 index fed26ec0..0000000 --- a/lib/libarchive/test/test_write_format_cpio_empty.c +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Check that an "empty" cpio archive is correctly created. - */ - -/* Here's what an empty cpio archive should look like. */ -static char ref[] = -"070707" /* Magic number */ -"000000" /* Dev = 0 */ -"000000" /* ino = 0 */ -"000000" /* mode = 0 */ -"000000" /* uid = 0 */ -"000000" /* gid = 0 */ -"000001" /* nlink = 1 */ -"000000" /* rdev = 0 */ -"00000000000" /* mtime = 0 */ -"000013" /* Namesize = 11 */ -"00000000000" /* filesize = 0 */ -"TRAILER!!!\0"; /* Name */ - -DEFINE_TEST(test_write_format_cpio_empty) -{ - struct archive *a; - char buff[2048]; - size_t used; - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_cpio(a)); - assertA(0 == archive_write_set_compression_none(a)); - /* 1-byte block size ensures we see only the required bytes. */ - /* We're not testing the padding here. */ - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - failure("Empty cpio archive should be exactly 87 bytes, was %d.", used); - assert(used == 87); - failure("Empty cpio archive is incorrectly formatted."); - assertEqualMem(buff, ref, 87); -} diff --git a/lib/libarchive/test/test_write_format_cpio_newc.c b/lib/libarchive/test/test_write_format_cpio_newc.c deleted file mode 100644 index 447d111..0000000 --- a/lib/libarchive/test/test_write_format_cpio_newc.c +++ /dev/null @@ -1,214 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - - -static int -is_hex(const char *p, size_t l) -{ - while (l > 0) { - if (*p >= 0 && *p <= '9') { - /* Ascii digit */ - } else if (*p >= 'a' && *p <= 'f') { - /* lowercase letter a-f */ - } else { - /* Not hex. */ - return (0); - } - --l; - ++p; - } - return (1); -} - -/* - * Detailed verification that cpio 'newc' archives are written with - * the correct format. - */ -DEFINE_TEST(test_write_format_cpio_newc) -{ - struct archive *a; - struct archive_entry *entry; - char *buff, *e, *file; - size_t buffsize = 100000; - size_t used; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_cpio_newc(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Add various files to it. - * TODO: Extend this to cover more filetypes. - */ - - /* Regular file */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "file"); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 10); - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); - - /* Directory */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 2, 20); - archive_entry_set_pathname(entry, "dir"); - archive_entry_set_mode(entry, S_IFDIR | 0775); - archive_entry_set_size(entry, 10); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* Symlink */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 3, 30); - archive_entry_set_pathname(entry, "lnk"); - archive_entry_set_mode(entry, 0664); - archive_entry_set_filetype(entry, AE_IFLNK); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 83); - archive_entry_set_gid(entry, 93); - archive_entry_set_dev(entry, 13); - archive_entry_set_ino(entry, 88); - archive_entry_set_nlink(entry, 1); - archive_entry_set_symlink(entry,"a"); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - - -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - - /* - * Verify the archive format. - */ - e = buff; - - /* First entry is "file" */ - file = e; - assert(is_hex(e, 110)); /* Entire header is hex digits. */ - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assert(memcmp(e + 6, "00000000", 8) != 0); /* ino != 0 */ - assertEqualMem(e + 14, "000081b4", 8); /* Mode */ - assertEqualMem(e + 22, "00000050", 8); /* uid */ - assertEqualMem(e + 30, "0000005a", 8); /* gid */ - assertEqualMem(e + 38, "00000001", 8); /* nlink */ - assertEqualMem(e + 46, "00000001", 8); /* mtime */ - assertEqualMem(e + 54, "0000000a", 8); /* File size */ - assertEqualMem(e + 62, "00000000", 8); /* devmajor */ - assertEqualMem(e + 70, "0000000c", 8); /* devminor */ - assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ - assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ - assertEqualMem(e + 94, "00000005", 8); /* Name size */ - assertEqualMem(e + 102, "00000000", 8); /* CRC */ - assertEqualMem(e + 110, "file\0\0", 6); /* Name contents */ - assertEqualMem(e + 116, "1234567890", 10); /* File body */ - assertEqualMem(e + 126, "\0\0", 2); /* Pad to multiple of 4 */ - e += 128; /* Must be multiple of four here! */ - - /* Second entry is "dir" */ - assert(is_hex(e, 110)); - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assertEqualMem(e + 6, "00000000", 8); /* ino */ - assertEqualMem(e + 14, "000041fd", 8); /* Mode */ - assertEqualMem(e + 22, "00000000", 8); /* uid */ - assertEqualMem(e + 30, "00000000", 8); /* gid */ - assertEqualMem(e + 38, "00000002", 8); /* nlink */ - assertEqualMem(e + 46, "00000002", 8); /* mtime */ - assertEqualMem(e + 54, "00000000", 8); /* File size */ - assertEqualMem(e + 62, "00000000", 8); /* devmajor */ - assertEqualMem(e + 70, "00000000", 8); /* devminor */ - assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ - assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ - assertEqualMem(e + 94, "00000004", 8); /* Name size */ - assertEqualMem(e + 102, "00000000", 8); /* CRC */ - assertEqualMem(e + 110, "dir\0", 4); /* name */ - assertEqualMem(e + 114, "\0\0", 2); /* Pad to multiple of 4 */ - e += 116; /* Must be multiple of four here! */ - - /* Third entry is "lnk" */ - assert(is_hex(e, 110)); /* Entire header is hex digits. */ - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assert(memcmp(e + 6, file + 6, 8) != 0); /* ino != file ino */ - assert(memcmp(e + 6, "00000000", 8) != 0); /* ino != 0 */ - assertEqualMem(e + 14, "0000a1b4", 8); /* Mode */ - assertEqualMem(e + 22, "00000053", 8); /* uid */ - assertEqualMem(e + 30, "0000005d", 8); /* gid */ - assertEqualMem(e + 38, "00000001", 8); /* nlink */ - assertEqualMem(e + 46, "00000003", 8); /* mtime */ - assertEqualMem(e + 54, "00000001", 8); /* File size */ - assertEqualMem(e + 62, "00000000", 8); /* devmajor */ - assertEqualMem(e + 70, "0000000d", 8); /* devminor */ - assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ - assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ - assertEqualMem(e + 94, "00000004", 8); /* Name size */ - assertEqualMem(e + 102, "00000000", 8); /* CRC */ - assertEqualMem(e + 110, "lnk\0\0\0", 6); /* Name contents */ - assertEqualMem(e + 116, "a\0\0\0", 4); /* File body + pad */ - e += 120; /* Must be multiple of four here! */ - - /* TODO: Verify other types of entries. */ - - /* Last entry is end-of-archive marker. */ - assert(is_hex(e, 76)); - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assertEqualMem(e + 6, "00000000", 8); /* ino */ - assertEqualMem(e + 14, "00000000", 8); /* Mode */ - assertEqualMem(e + 22, "00000000", 8); /* uid */ - assertEqualMem(e + 30, "00000000", 8); /* gid */ - assertEqualMem(e + 38, "00000001", 8); /* nlink */ - assertEqualMem(e + 46, "00000000", 8); /* mtime */ - assertEqualMem(e + 54, "00000000", 8); /* File size */ - assertEqualMem(e + 62, "00000000", 8); /* devmajor */ - assertEqualMem(e + 70, "00000000", 8); /* devminor */ - assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ - assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ - assertEqualMem(e + 94, "0000000b", 8); /* Name size */ - assertEqualMem(e + 102, "00000000", 8); /* CRC */ - assertEqualMem(e + 110, "TRAILER!!!\0", 11); /* Name */ - assertEqualMem(e + 121, "\0\0\0", 3); /* Pad to multiple of 4 bytes */ - e += 124; /* Must be multiple of four here! */ - - assertEqualInt((int)used, e - buff); - - free(buff); -} diff --git a/lib/libarchive/test/test_write_format_cpio_odc.c b/lib/libarchive/test/test_write_format_cpio_odc.c deleted file mode 100644 index 309e003..0000000 --- a/lib/libarchive/test/test_write_format_cpio_odc.c +++ /dev/null @@ -1,241 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - - -static int -is_octal(const char *p, size_t l) -{ - while (l > 0) { - if (*p < '0' || *p > '7') - return (0); - --l; - ++p; - } - return (1); -} - -/* - * Detailed verification that cpio 'odc' archives are written with - * the correct format. - */ -DEFINE_TEST(test_write_format_cpio_odc) -{ - struct archive *a; - struct archive_entry *entry; - char *buff, *e, *file; - size_t buffsize = 100000; - size_t used; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_cpio(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Add various files to it. - * TODO: Extend this to cover more filetypes. - */ - - /* "file" with 10 bytes of content */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "file"); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 10); - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); - - /* Hardlink to "file" with 10 bytes of content */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "linkfile"); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 10); - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); - - /* "dir" */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 2, 20); - archive_entry_set_pathname(entry, "dir"); - archive_entry_set_mode(entry, S_IFDIR | 0775); - archive_entry_set_size(entry, 10); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to dir should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* "symlink" pointing to "file" */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 3, 30); - archive_entry_set_pathname(entry, "symlink"); - archive_entry_set_mode(entry, 0664); - archive_entry_set_filetype(entry, AE_IFLNK); - archive_entry_set_symlink(entry,"file"); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 88); - archive_entry_set_gid(entry, 98); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 90); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to symlink should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - - /* - * Verify the archive format. - * - * Notes on the ino validation: cpio does not actually require - * that the ino values written to the archive match those read - * from disk. It really requires that: - * * matching non-zero ino values be written as matching - * non-zero values - * * non-matching non-zero ino values be written as non-matching - * non-zero values - * Libarchive further ensures that zero ino values get written - * as zeroes. This allows the cpio writer to generate - * synthetic ino values for the archive that may be different - * than those on disk in order to avoid problems due to truncation. - * This is especially needed for odc (POSIX format) that - * only supports 18-bit ino values. - */ - e = buff; - - /* "file" */ - file = e; /* Remember where this starts... */ - assert(is_octal(e, 76)); /* Entire header is octal digits. */ - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000014", 6); /* dev */ - assert(memcmp(e + 12, "000000", 6) != 0); /* ino must be != 0 */ - assertEqualMem(e + 18, "100664", 6); /* Mode */ - assertEqualMem(e + 24, "000120", 6); /* uid */ - assertEqualMem(e + 30, "000132", 6); /* gid */ - assertEqualMem(e + 36, "000002", 6); /* nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000001", 11); /* mtime */ - assertEqualMem(e + 59, "000005", 6); /* Name size */ - assertEqualMem(e + 65, "00000000012", 11); /* File size */ - assertEqualMem(e + 76, "file\0", 5); /* Name contents */ - assertEqualMem(e + 81, "1234567890", 10); /* File contents */ - e += 91; - - /* hardlink to "file" */ - assert(is_octal(e, 76)); /* Entire header is octal digits. */ - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000014", 6); /* dev */ - assertEqualMem(e + 12, file + 12, 6); /* ino must match above */ - assertEqualMem(e + 18, "100664", 6); /* Mode */ - assertEqualMem(e + 24, "000120", 6); /* uid */ - assertEqualMem(e + 30, "000132", 6); /* gid */ - assertEqualMem(e + 36, "000002", 6); /* nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000001", 11); /* mtime */ - assertEqualMem(e + 59, "000011", 6); /* Name size */ - assertEqualMem(e + 65, "00000000012", 11); /* File size */ - assertEqualMem(e + 76, "linkfile\0", 9); /* Name contents */ - assertEqualMem(e + 85, "1234567890", 10); /* File contents */ - e += 95; - - /* "dir" */ - assert(is_octal(e, 76)); - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000000", 6); /* dev */ - assertEqualMem(e + 12, "000000", 6); /* ino */ - assertEqualMem(e + 18, "040775", 6); /* Mode */ - assertEqualMem(e + 24, "000000", 6); /* uid */ - assertEqualMem(e + 30, "000000", 6); /* gid */ - assertEqualMem(e + 36, "000002", 6); /* Nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000002", 11); /* mtime */ - assertEqualMem(e + 59, "000004", 6); /* Name size */ - assertEqualMem(e + 65, "00000000000", 11); /* File size */ - assertEqualMem(e + 76, "dir\0", 4); /* name */ - e += 80; - - /* "symlink" pointing to "file" */ - assert(is_octal(e, 76)); /* Entire header is octal digits. */ - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000014", 6); /* dev */ - assert(memcmp(e + 12, file + 12, 6) != 0); /* ino must != file ino */ - assert(memcmp(e + 12, "000000", 6) != 0); /* ino must != 0 */ - assertEqualMem(e + 18, "120664", 6); /* Mode */ - assertEqualMem(e + 24, "000130", 6); /* uid */ - assertEqualMem(e + 30, "000142", 6); /* gid */ - assertEqualMem(e + 36, "000001", 6); /* nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000003", 11); /* mtime */ - assertEqualMem(e + 59, "000010", 6); /* Name size */ - assertEqualMem(e + 65, "00000000004", 11); /* File size */ - assertEqualMem(e + 76, "symlink\0", 8); /* Name contents */ - assertEqualMem(e + 84, "file", 4); /* File contents == link target */ - e += 88; - - /* TODO: Verify other types of entries. */ - - /* Last entry is end-of-archive marker. */ - assert(is_octal(e, 76)); - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000000", 6); /* dev */ - assertEqualMem(e + 12, "000000", 6); /* ino */ - assertEqualMem(e + 18, "000000", 6); /* Mode */ - assertEqualMem(e + 24, "000000", 6); /* uid */ - assertEqualMem(e + 30, "000000", 6); /* gid */ - assertEqualMem(e + 36, "000001", 6); /* Nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000000", 11); /* mtime */ - assertEqualMem(e + 59, "000013", 6); /* Name size */ - assertEqualMem(e + 65, "00000000000", 11); /* File size */ - assertEqualMem(e + 76, "TRAILER!!!\0", 11); /* Name */ - e += 87; - - assertEqualInt((int)used, e - buff); - - free(buff); -} diff --git a/lib/libarchive/test/test_write_format_mtree.c b/lib/libarchive/test/test_write_format_mtree.c deleted file mode 100644 index b9de422..0000000 --- a/lib/libarchive/test/test_write_format_mtree.c +++ /dev/null @@ -1,155 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -static char buff[4096]; -static struct { - const char *path; - mode_t mode; - time_t mtime; - uid_t uid; - gid_t gid; -} entries[] = { - { "./Makefile", S_IFREG | 0644, 1233041050, 1001, 1001 }, - { "./NEWS", S_IFREG | 0644, 1231975636, 1001, 1001 }, - { "./PROJECTS", S_IFREG | 0644, 1231975636, 1001, 1001 }, - { "./README", S_IFREG | 0644, 1231975636, 1001, 1001 }, - { "./COPYING", S_IFREG | 0644, 1231975636, 1001, 1001 }, - { "./subdir", S_IFDIR | 0755, 1233504586, 1001, 1001 }, - { "./subdir/README", S_IFREG | 0664, 1231975636, 1002, 1001 }, - { "./subdir/config", S_IFREG | 0664, 1232266273, 1003, 1003 }, - { "./subdir2", S_IFDIR | 0755, 1233504586, 1001, 1001 }, - { "./subdir3", S_IFDIR | 0755, 1233504586, 1001, 1001 }, - { "./subdir3/mtree", S_IFREG | 0664, 1232266273, 1003, 1003 }, - { NULL, 0, 0, 0, 0 } -}; - -static void -test_write_format_mtree_sub(int use_set, int dironly) -{ - struct archive_entry *ae; - struct archive* a; - size_t used; - int i; - - /* Create a mtree format archive. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_mtree(a)); - if (use_set) - assertA(0 == archive_write_set_options(a, "use-set")); - if (dironly) - assertA(0 == archive_write_set_options(a, "dironly")); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff)-1, &used)); - - /* Write entries */ - for (i = 0; entries[i].path != NULL; i++) { - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, entries[i].mtime, 0); - assert(entries[i].mtime == archive_entry_mtime(ae)); - archive_entry_set_mode(ae, entries[i].mode); - assert(entries[i].mode == archive_entry_mode(ae)); - archive_entry_set_uid(ae, entries[i].uid); - assert(entries[i].uid == archive_entry_uid(ae)); - archive_entry_set_gid(ae, entries[i].gid); - assert(entries[i].gid == archive_entry_gid(ae)); - archive_entry_copy_pathname(ae, entries[i].path); - if ((entries[i].mode & AE_IFMT) != S_IFDIR) - archive_entry_set_size(ae, 8); - assertA(0 == archive_write_header(a, ae)); - if ((entries[i].mode & AE_IFMT) != S_IFDIR) - assertA(8 == archive_write_data(a, "Hello012", 15)); - archive_entry_free(ae); - } - archive_write_close(a); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - if (use_set) { - const char *p; - - buff[used] = '\0'; - assert(NULL != (p = strstr(buff, "\n/set "))); - if (p != NULL) { - char *r; - const char *o; - p++; - r = strchr(p, '\n'); - if (r != NULL) - *r = '\0'; - if (dironly) - o = "/set type=dir uid=1001 gid=1001 mode=755"; - else - o = "/set type=file uid=1001 gid=1001 mode=644"; - assertEqualString(o, p); - if (r != NULL) - *r = '\n'; - } - } - - /* - * Read the data and check it. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - /* Read entries */ - for (i = 0; entries[i].path != NULL; i++) { - if (dironly && (entries[i].mode & AE_IFMT) != S_IFDIR) - continue; - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(entries[i].mtime, archive_entry_mtime(ae)); - assertEqualInt(entries[i].mode, archive_entry_mode(ae)); - assertEqualInt(entries[i].uid, archive_entry_uid(ae)); - assertEqualInt(entries[i].gid, archive_entry_gid(ae)); - assertEqualString(entries[i].path, archive_entry_pathname(ae)); - if ((entries[i].mode & AE_IFMT) != S_IFDIR) - assertEqualInt(8, archive_entry_size(ae)); - } - assertEqualIntA(a, 0, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif -} - -DEFINE_TEST(test_write_format_mtree) -{ - /* Default setting */ - test_write_format_mtree_sub(0, 0); - /* Directory only */ - test_write_format_mtree_sub(0, 1); - /* Use /set keyword */ - test_write_format_mtree_sub(1, 0); - /* Use /set keyword with directory only */ - test_write_format_mtree_sub(1, 1); -} diff --git a/lib/libarchive/test/test_write_format_pax.c b/lib/libarchive/test/test_write_format_pax.c deleted file mode 100644 index 06cfca6..0000000 --- a/lib/libarchive/test/test_write_format_pax.c +++ /dev/null @@ -1,146 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -char buff2[64]; - -DEFINE_TEST(test_write_format_pax) -{ - size_t buffsize = 1000000; - char *buff; - struct archive_entry *ae; - struct archive *a; - size_t used; - - buff = malloc(buffsize); /* million bytes of work area */ - assert(buff != NULL); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_pax(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * "file" has a bunch of attributes and 8 bytes of data. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_atime(ae, 2, 20); - archive_entry_set_birthtime(ae, 3, 30); - archive_entry_set_ctime(ae, 4, 40); - archive_entry_set_mtime(ae, 5, 50); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * "file2" is similar but has birthtime later than mtime. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_atime(ae, 2, 20); - archive_entry_set_birthtime(ae, 8, 80); - archive_entry_set_ctime(ae, 4, 40); - archive_entry_set_mtime(ae, 5, 50); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * XXX TODO XXX Archive directory, other file types. - * Archive extended attributes, ACLs, other metadata. - * Verify they get read back correctly. - */ - - /* Close out the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_finish(a)); - - /* - * - * Now, read the data back. - * - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, 0, archive_read_support_format_all(a)); - assertEqualIntA(a, 0, archive_read_support_compression_all(a)); - assertEqualIntA(a, 0, archive_read_open_memory(a, buff, used)); - - /* - * Read "file" - */ - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualInt(2, archive_entry_atime(ae)); - assertEqualInt(20, archive_entry_atime_nsec(ae)); - assertEqualInt(3, archive_entry_birthtime(ae)); - assertEqualInt(30, archive_entry_birthtime_nsec(ae)); - assertEqualInt(4, archive_entry_ctime(ae)); - assertEqualInt(40, archive_entry_ctime_nsec(ae)); - assertEqualInt(5, archive_entry_mtime(ae)); - assertEqualInt(50, archive_entry_mtime_nsec(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "12345678", 8); - - /* - * Read "file2" - */ - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assert(archive_entry_atime_is_set(ae)); - assertEqualInt(2, archive_entry_atime(ae)); - assertEqualInt(20, archive_entry_atime_nsec(ae)); - /* Birthtime > mtime above, so it doesn't get stored at all. */ - assert(!archive_entry_birthtime_is_set(ae)); - assertEqualInt(0, archive_entry_birthtime(ae)); - assertEqualInt(0, archive_entry_birthtime_nsec(ae)); - assert(archive_entry_ctime_is_set(ae)); - assertEqualInt(4, archive_entry_ctime(ae)); - assertEqualInt(40, archive_entry_ctime_nsec(ae)); - assert(archive_entry_mtime_is_set(ae)); - assertEqualInt(5, archive_entry_mtime(ae)); - assertEqualInt(50, archive_entry_mtime_nsec(ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "12345678", 8); - - /* - * Verify the end of the archive. - */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_finish(a)); - - free(buff); -} diff --git a/lib/libarchive/test/test_write_format_shar_empty.c b/lib/libarchive/test/test_write_format_shar_empty.c deleted file mode 100644 index 173791b..0000000 --- a/lib/libarchive/test/test_write_format_shar_empty.c +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Check that an "empty" shar archive is correctly created as an empty file. - */ - -DEFINE_TEST(test_write_format_shar_empty) -{ - struct archive *a; - char buff[2048]; - size_t used; - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_shar(a)); - assertA(0 == archive_write_set_compression_none(a)); - /* 1-byte block size ensures we see only the required bytes. */ - /* We're not testing the padding here. */ - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - failure("Empty shar archive should be exactly 0 bytes, was %d.", used); - assert(used == 0); -} diff --git a/lib/libarchive/test/test_write_format_tar.c b/lib/libarchive/test/test_write_format_tar.c deleted file mode 100644 index ef210e6..0000000 --- a/lib/libarchive/test/test_write_format_tar.c +++ /dev/null @@ -1,114 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -char buff[1000000]; -char buff2[64]; - -DEFINE_TEST(test_write_format_tar) -{ - struct archive_entry *ae; - struct archive *a; - char *p; - size_t used; - size_t blocksize; - - /* Repeat the following for a variety of odd blocksizes. */ - for (blocksize = 1; blocksize < 100000; blocksize += blocksize + 3) { - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, (int)blocksize)); - assertA(0 == archive_write_set_bytes_in_last_block(a, (int)blocksize)); - assertA(blocksize == (size_t)archive_write_get_bytes_in_last_block(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - assertA(blocksize == (size_t)archive_write_get_bytes_in_last_block(a)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assert(1 == archive_entry_mtime(ae)); -#if !defined(__INTERIX) - assert(10 == archive_entry_mtime_nsec(ae)); -#endif - p = strdup("file"); - archive_entry_copy_pathname(ae, p); - strcpy(p, "XXXX"); - free(p); - assertEqualString("file", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - archive_entry_set_size(ae, 8); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(8 == archive_write_data(a, "12345678", 9)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - /* This calculation gives "the smallest multiple of - * the block size that is at least 2048 bytes". */ - assert(((2048 - 1)/blocksize+1)*blocksize == used); - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - assertA(0 == archive_read_next_header(a, &ae)); - - assert(1 == archive_entry_mtime(ae)); - /* Not the same as above: ustar doesn't store hi-res times. */ - assert(0 == archive_entry_mtime_nsec(ae)); - assert(0 == archive_entry_atime(ae)); - assert(0 == archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assert(8 == archive_entry_size(ae)); - assertA(8 == archive_read_data(a, buff2, 10)); - assert(0 == memcmp(buff2, "12345678", 8)); - - /* Verify the end of the archive. */ - assert(1 == archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } -} diff --git a/lib/libarchive/test/test_write_format_tar_empty.c b/lib/libarchive/test/test_write_format_tar_empty.c deleted file mode 100644 index 5703253..0000000 --- a/lib/libarchive/test/test_write_format_tar_empty.c +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Check that an "empty" tar archive is correctly created. - */ - -DEFINE_TEST(test_write_format_tar_empty) -{ - struct archive *a; - char buff[2048]; - size_t used; - unsigned int i; - - /* USTAR format: Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 512)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 512)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* Earlier versions wrote 0-length files for empty tar archives. */ - skipping("empty tar archive size"); -#else - assert(used == 1024); -#endif - for (i = 0; i < used; i++) { - failure("Empty tar archive should be all nulls."); - assert(buff[i] == 0); - } - - /* PAX format: Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_pax(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 512)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 512)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* Earlier versions wrote 0-length files for empty tar archives. */ - skipping("empty tar archive size"); -#else - assertEqualInt((int)used, 1024); -#endif - for (i = 0; i < used; i++) { - failure("Empty tar archive should be all nulls."); - assert(buff[i] == 0); - } -} diff --git a/lib/libarchive/test/test_write_format_tar_ustar.c b/lib/libarchive/test/test_write_format_tar_ustar.c deleted file mode 100644 index f66fd7a..0000000 --- a/lib/libarchive/test/test_write_format_tar_ustar.c +++ /dev/null @@ -1,347 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -static int -is_null(const char *p, size_t l) -{ - while (l > 0) { - if (*p != '\0') - return (0); - --l; - ++p; - } - return (1); -} - -/* Verify the contents, then erase them to NUL bytes. */ -/* Tar requires all "unused" bytes be set to NUL; this allows us - * to easily verify that by invoking is_null() over the entire header - * after verifying each field. */ -#define myAssertEqualMem(a,b,s) assertEqualMem(a, b, s); memset(a, 0, s) - -/* - * Detailed verification that 'ustar' archives are written with - * the correct format. - */ -DEFINE_TEST(test_write_format_tar_ustar) -{ - struct archive *a; - struct archive_entry *entry; - char *buff, *e; - size_t buffsize = 100000; - size_t used; - int i; - char f99[100]; - char f100[101]; - char f256[257]; - - for (i = 0; i < 99; ++i) - f99[i] = 'a' + i % 26; - f99[99] = '\0'; - - for (i = 0; i < 100; ++i) - f100[i] = 'A' + i % 26; - f100[100] = '\0'; - - for (i = 0; i < 256; ++i) - f256[i] = 'A' + i % 26; - f256[155] = '/'; - f256[256] = '\0'; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_ustar(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Add various files to it. - * TODO: Extend this to cover more filetypes. - */ - - /* "file" with 10 bytes of content */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "file"); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 10); - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); - - /* Hardlink to "file" with 10 bytes of content */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "linkfile"); - archive_entry_set_mode(entry, S_IFREG | 0664); - /* TODO: Put this back and fix the bug. */ - /* archive_entry_set_size(entry, 10); */ - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to dir should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* "dir" */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 2, 20); - archive_entry_set_pathname(entry, "dir"); - archive_entry_set_mode(entry, S_IFDIR | 0775); - archive_entry_set_size(entry, 10); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to dir should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* "symlink" pointing to "file" */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 3, 30); - archive_entry_set_pathname(entry, "symlink"); - archive_entry_set_mode(entry, 0664); - archive_entry_set_filetype(entry, AE_IFLNK); - archive_entry_set_symlink(entry,"file"); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 88); - archive_entry_set_gid(entry, 98); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 90); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to symlink should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* file with 99-char filename. */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, f99); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 82); - archive_entry_set_gid(entry, 93); - archive_entry_set_dev(entry, 102); - archive_entry_set_ino(entry, 7); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - - /* file with 100-char filename. */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, f100); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 82); - archive_entry_set_gid(entry, 93); - archive_entry_set_dev(entry, 102); - archive_entry_set_ino(entry, 7); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - - /* file with 256-char filename. */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, f256); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 82); - archive_entry_set_gid(entry, 93); - archive_entry_set_dev(entry, 102); - archive_entry_set_ino(entry, 7); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - - /* - * Verify the archive format. - */ - e = buff; - - /* "file" */ - myAssertEqualMem(e + 0, "file", 5); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000120 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000132 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000012 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "010034\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - myAssertEqualMem(e + 512, "1234567890", 10); - assert(is_null(e + 512, 512)); - e += 1024; - - /* hardlink to "file" */ - myAssertEqualMem(e + 0, "linkfile", 9); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000120 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000132 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "010707\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* "dir" */ - myAssertEqualMem(e + 0, "dir/", 4); /* Filename */ - myAssertEqualMem(e + 100, "000775 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000000 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000000 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000002 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "007747\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "5", 1); /* typeflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* "symlink" pointing to "file" */ - myAssertEqualMem(e + 0, "symlink", 8); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000130 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000142 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000003 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "011446\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "2", 1); /* linkflag */ - myAssertEqualMem(e + 157, "file", 5); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* File with 99-char filename */ - myAssertEqualMem(e + 0, f99, 100); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000122 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000135 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "034242\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* File with 100-char filename */ - myAssertEqualMem(e + 0, f100, 100); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000122 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000135 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "026230\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* File with 256-char filename */ - myAssertEqualMem(e + 0, f256 + 156, 100); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000122 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000135 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "055570\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, f256, 155); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* TODO: Verify other types of entries. */ - - /* Last entry is end-of-archive marker. */ - assert(is_null(e, 1024)); - e += 1024; - - assertEqualInt((int)used, e - buff); - - free(buff); -} diff --git a/lib/libarchive/test/test_write_format_zip.c b/lib/libarchive/test/test_write_format_zip.c deleted file mode 100644 index f4c51f3..0000000 --- a/lib/libarchive/test/test_write_format_zip.c +++ /dev/null @@ -1,180 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * Copyright (c) 2008 Anselm Strauss - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Development supported by Google Summer of Code 2008. - */ - -/* TODO: reader does not yet restore permissions. */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_write_format_zip) -{ - char filedata[64]; - struct archive_entry *ae; - struct archive *a; - size_t used; - size_t buffsize = 1000000; - char *buff; - const char *compression_type; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_zip(a)); -#ifdef HAVE_ZLIB_H - compression_type = "zip:compression=deflate"; -#else - compression_type = "zip:compression=store"; -#endif - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_format_options(a, compression_type)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(10, archive_entry_mtime_nsec(ae)); - archive_entry_copy_pathname(ae, "file"); - assertEqualString("file", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - archive_entry_set_size(ae, 8); - - assertEqualInt(0, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualInt(8, archive_write_data(a, "12345678", 9)); - assertEqualInt(0, archive_write_data(a, "1", 1)); - - /* - * Write another file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(10, archive_entry_mtime_nsec(ae)); - archive_entry_copy_pathname(ae, "file2"); - assertEqualString("file2", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - archive_entry_set_size(ae, 4); - - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualInt(4, archive_write_data(a, "1234", 5)); - - /* - * Write a directory to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 11, 110); - archive_entry_copy_pathname(ae, "dir"); - archive_entry_set_mode(ae, S_IFDIR | 0755); - archive_entry_set_size(ae, 512); - - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - failure("size should be zero so that applications know not to write"); - assertEqualInt(0, archive_entry_size(ae)); - archive_entry_free(ae); - assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9)); - - /* Close out the archive. */ - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Now, read the data back. - */ - ae = NULL; - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used)); - - /* - * Read and verify first file. - */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - /* Zip doesn't store high-resolution mtime. */ - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - //assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, 8, - archive_read_data(a, filedata, sizeof(filedata))); - assertEqualMem(filedata, "12345678", 8); - - - /* - * Read the second file back. - */ - if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))){ - free(buff); - return; - } - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - //assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, 4, - archive_read_data(a, filedata, sizeof(filedata))); - assertEqualMem(filedata, "1234", 4); - - /* - * Read the dir entry back. - */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(11, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("dir/", archive_entry_pathname(ae)); - //assertEqualInt((S_IFDIR | 0755), archive_entry_mode(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, 0, archive_read_data(a, filedata, 10)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - free(buff); -} diff --git a/lib/libarchive/test/test_write_format_zip_empty.c b/lib/libarchive/test/test_write_format_zip_empty.c deleted file mode 100644 index ef90b8d..0000000 --- a/lib/libarchive/test/test_write_format_zip_empty.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2008 Anselm Strauss - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Development supported by Google Summer of Code 2008. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_write_format_zip_empty) -{ - struct archive *a; - char buff[256]; - size_t used; - - /* Zip format: Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_zip(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive without writing anything. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - - /* Verify the correct format for an empy Zip archive. */ - assertEqualInt(used, 22); - assertEqualMem(buff, - "PK\005\006\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", - 22); -} diff --git a/lib/libarchive/test/test_write_format_zip_no_compression.c b/lib/libarchive/test/test_write_format_zip_no_compression.c deleted file mode 100644 index 63e76b6..0000000 --- a/lib/libarchive/test/test_write_format_zip_no_compression.c +++ /dev/null @@ -1,304 +0,0 @@ -/*- - * Copyright (c) 2008 Anselm Strauss - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Development supported by Google Summer of Code 2008. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned long -bitcrc32(unsigned long c, void *_p, size_t s) -{ - /* This is a drop-in replacement for crc32() from zlib. - * Libarchive should be able to correctly generate - * uncompressed zip archives (including correct CRCs) even - * when zlib is unavailable, and this function helps us verify - * that. Yes, this is very, very slow and unsuitable for - * production use, but it's correct, compact, and works well - * enough for this particular usage. Libarchive internally - * uses a much more efficient implementation. */ - const unsigned char *p = _p; - int bitctr; - - if (p == NULL) - return (0); - - for (; s > 0; --s) { - c ^= *p++; - for (bitctr = 8; bitctr > 0; --bitctr) { - if (c & 1) c = (c >> 1); - else c = (c >> 1) ^ 0xedb88320; - c ^= 0x80000000; - } - } - return (c); -} - -/* Quick and dirty: Read 2-byte and 4-byte integers from Zip file. */ -static int i2(const char *p) { return ((p[0] & 0xff) | ((p[1] & 0xff) << 8)); } -static int i4(const char *p) { return (i2(p) | (i2(p + 2) << 16)); } - -DEFINE_TEST(test_write_format_zip_no_compression) -{ - /* Buffer data */ - struct archive *a; - struct archive_entry *entry; - char buff[100000]; - const char *buffend; - /* p is the pointer to walk over the central directory, - * q walks over the local headers, the data and the data descriptors. */ - const char *p, *q; - size_t used; - - /* File data */ - char file_name[] = "file"; - char file_data1[] = {'1', '2', '3', '4', '5'}; - char file_data2[] = {'6', '7', '8', '9', '0'}; - int file_perm = 00644; - short file_uid = 10; - short file_gid = 20; - - /* Folder data */ - char folder_name[] = "folder/"; - int folder_perm = 00755; - short folder_uid = 30; - short folder_gid = 40; - - /* Time data */ - time_t t = time(NULL); - struct tm *tm = localtime(&t); - - /* Misc variables */ - unsigned long crc; - - /* Create new ZIP archive in memory without padding. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_zip(a)); - assertA(0 == archive_write_set_format_options(a, "zip:compression=store")); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Write entries. */ - - /* Regular file */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_pathname(entry, file_name); - archive_entry_set_mode(entry, S_IFREG | 0644); - archive_entry_set_size(entry, sizeof(file_data1) + sizeof(file_data2)); - archive_entry_set_uid(entry, file_uid); - archive_entry_set_gid(entry, file_gid); - archive_entry_set_mtime(entry, t, 0); - archive_entry_set_atime(entry, t, 0); - archive_entry_set_ctime(entry, t, 0); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - assertEqualIntA(a, sizeof(file_data1), archive_write_data(a, file_data1, sizeof(file_data1))); - assertEqualIntA(a, sizeof(file_data2), archive_write_data(a, file_data2, sizeof(file_data2))); - archive_entry_free(entry); - - /* Folder */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_pathname(entry, folder_name); - archive_entry_set_mode(entry, S_IFDIR | folder_perm); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, folder_uid); - archive_entry_set_gid(entry, folder_gid); - archive_entry_set_mtime(entry, t, 0); - archive_entry_set_atime(entry, t, 0); - archive_entry_set_ctime(entry, t, 0); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - - /* Close the archive . */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - - /* Remember the end of the archive in memory. */ - buffend = buff + used; - - /* Verify "End of Central Directory" record. */ - /* Get address of end-of-central-directory record. */ - p = buffend - 22; /* Assumes there is no zip comment field. */ - failure("End-of-central-directory begins with PK\\005\\006 signature"); - assertEqualMem(p, "PK\005\006", 4); - failure("This must be disk 0"); - assertEqualInt(i2(p + 4), 0); - failure("Central dir must start on disk 0"); - assertEqualInt(i2(p + 6), 0); - failure("All central dir entries are on this disk"); - assertEqualInt(i2(p + 8), i2(p + 10)); - failure("CD start (%d) + CD length (%d) should == archive size - 22", - i4(p + 12), i4(p + 16)); - assertEqualInt(i4(p + 12) + i4(p + 16), used - 22); - failure("no zip comment"); - assertEqualInt(i2(p + 20), 0); - - /* Get address of first entry in central directory. */ - p = buff + i4(buffend - 6); - failure("Central file record at offset %d should begin with" - " PK\\001\\002 signature", - i4(buffend - 10)); - - /* Verify file entry in central directory. */ - assertEqualMem(p, "PK\001\002", 4); /* Signature */ - assertEqualInt(i2(p + 4), 3 * 256 + 20); /* Version made by */ - assertEqualInt(i2(p + 6), 20); /* Version needed to extract */ - assertEqualInt(i2(p + 8), 8); /* Flags */ - assertEqualInt(i2(p + 10), 0); /* Compression method */ - assertEqualInt(i2(p + 12), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ - assertEqualInt(i2(p + 14), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ - crc = bitcrc32(0, file_data1, sizeof(file_data1)); - crc = bitcrc32(crc, file_data2, sizeof(file_data2)); - assertEqualInt(i4(p + 16), crc); /* CRC-32 */ - assertEqualInt(i4(p + 20), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ - assertEqualInt(i4(p + 24), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ - assertEqualInt(i2(p + 28), strlen(file_name)); /* Pathname length */ - assertEqualInt(i2(p + 30), 13); /* Extra field length */ - assertEqualInt(i2(p + 32), 0); /* File comment length */ - assertEqualInt(i2(p + 34), 0); /* Disk number start */ - assertEqualInt(i2(p + 36), 0); /* Internal file attrs */ - assertEqualInt(i4(p + 38) >> 16 & 01777, file_perm); /* External file attrs */ - assertEqualInt(i4(p + 42), 0); /* Offset of local header */ - assertEqualMem(p + 46, file_name, strlen(file_name)); /* Pathname */ - p = p + 46 + strlen(file_name); - assertEqualInt(i2(p), 0x5455); /* 'UT' extension header */ - assertEqualInt(i2(p + 2), 5); /* 'UT' size */ - assertEqualInt(p[4], 7); /* 'UT' flags */ - assertEqualInt(i4(p + 5), t); /* 'UT' mtime */ - p = p + 9; - assertEqualInt(i2(p), 0x7855); /* 'Ux' extension header */ - assertEqualInt(i2(p + 2), 0); /* 'Ux' size */ - p = p + 4; - - /* Verify local header of file entry. */ - q = buff; - assertEqualMem(q, "PK\003\004", 4); /* Signature */ - assertEqualInt(i2(q + 4), 20); /* Version needed to extract */ - assertEqualInt(i2(q + 6), 8); /* Flags */ - assertEqualInt(i2(q + 8), 0); /* Compression method */ - assertEqualInt(i2(q + 10), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ - assertEqualInt(i2(q + 12), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ - assertEqualInt(i4(q + 14), 0); /* CRC-32 */ - assertEqualInt(i4(q + 18), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ - assertEqualInt(i4(q + 22), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ - assertEqualInt(i2(q + 26), strlen(file_name)); /* Pathname length */ - assertEqualInt(i2(q + 28), 25); /* Extra field length */ - assertEqualMem(q + 30, file_name, strlen(file_name)); /* Pathname */ - q = q + 30 + strlen(file_name); - assertEqualInt(i2(q), 0x5455); /* 'UT' extension header */ - assertEqualInt(i2(q + 2), 13); /* 'UT' size */ - assertEqualInt(q[4], 7); /* 'UT' flags */ - assertEqualInt(i4(q + 5), t); /* 'UT' mtime */ - assertEqualInt(i4(q + 9), t); /* 'UT' atime */ - assertEqualInt(i4(q + 13), t); /* 'UT' ctime */ - q = q + 17; - assertEqualInt(i2(q), 0x7855); /* 'Ux' extension header */ - assertEqualInt(i2(q + 2), 4); /* 'Ux' size */ - assertEqualInt(i2(q + 4), file_uid); /* 'Ux' UID */ - assertEqualInt(i2(q + 6), file_gid); /* 'Ux' GID */ - q = q + 8; - - /* Verify data of file entry. */ - assertEqualMem(q, file_data1, sizeof(file_data1)); - assertEqualMem(q + sizeof(file_data1), file_data2, sizeof(file_data2)); - q = q + sizeof(file_data1) + sizeof(file_data2); - - /* Verify data descriptor of file entry. */ - assertEqualMem(q, "PK\007\010", 4); /* Signature */ - assertEqualInt(i4(q + 4), crc); /* CRC-32 */ - assertEqualInt(i4(q + 8), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ - assertEqualInt(i4(q + 12), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ - q = q + 16; - - /* Verify folder entry in central directory. */ - assertEqualMem(p, "PK\001\002", 4); /* Signature */ - assertEqualInt(i2(p + 4), 3 * 256 + 20); /* Version made by */ - assertEqualInt(i2(p + 6), 20); /* Version needed to extract */ - assertEqualInt(i2(p + 8), 8); /* Flags */ - assertEqualInt(i2(p + 10), 0); /* Compression method */ - assertEqualInt(i2(p + 12), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ - assertEqualInt(i2(p + 14), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ - crc = 0; - assertEqualInt(i4(p + 16), crc); /* CRC-32 */ - assertEqualInt(i4(p + 20), 0); /* Compressed size */ - assertEqualInt(i4(p + 24), 0); /* Uncompressed size */ - assertEqualInt(i2(p + 28), strlen(folder_name)); /* Pathname length */ - assertEqualInt(i2(p + 30), 13); /* Extra field length */ - assertEqualInt(i2(p + 32), 0); /* File comment length */ - assertEqualInt(i2(p + 34), 0); /* Disk number start */ - assertEqualInt(i2(p + 36), 0); /* Internal file attrs */ - assertEqualInt(i4(p + 38) >> 16 & 01777, folder_perm); /* External file attrs */ - assertEqualInt(i4(p + 42), q - buff); /* Offset of local header */ - assertEqualMem(p + 46, folder_name, strlen(folder_name)); /* Pathname */ - p = p + 46 + strlen(folder_name); - assertEqualInt(i2(p), 0x5455); /* 'UT' extension header */ - assertEqualInt(i2(p + 2), 5); /* 'UT' size */ - assertEqualInt(p[4], 7); /* 'UT' flags */ - assertEqualInt(i4(p + 5), t); /* 'UT' mtime */ - p = p + 9; - assertEqualInt(i2(p), 0x7855); /* 'Ux' extension header */ - assertEqualInt(i2(p + 2), 0); /* 'Ux' size */ - p = p + 4; - - /* Verify local header of folder entry. */ - assertEqualMem(q, "PK\003\004", 4); /* Signature */ - assertEqualInt(i2(q + 4), 20); /* Version needed to extract */ - assertEqualInt(i2(q + 6), 8); /* Flags */ - assertEqualInt(i2(q + 8), 0); /* Compression method */ - assertEqualInt(i2(q + 10), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ - assertEqualInt(i2(q + 12), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ - assertEqualInt(i4(q + 14), 0); /* CRC-32 */ - assertEqualInt(i4(q + 18), 0); /* Compressed size */ - assertEqualInt(i4(q + 22), 0); /* Uncompressed size */ - assertEqualInt(i2(q + 26), strlen(folder_name)); /* Pathname length */ - assertEqualInt(i2(q + 28), 25); /* Extra field length */ - assertEqualMem(q + 30, folder_name, strlen(folder_name)); /* Pathname */ - q = q + 30 + strlen(folder_name); - assertEqualInt(i2(q), 0x5455); /* 'UT' extension header */ - assertEqualInt(i2(q + 2), 13); /* 'UT' size */ - assertEqualInt(q[4], 7); /* 'UT' flags */ - assertEqualInt(i4(q + 5), t); /* 'UT' mtime */ - assertEqualInt(i4(q + 9), t); /* 'UT' atime */ - assertEqualInt(i4(q + 13), t); /* 'UT' ctime */ - q = q + 17; - assertEqualInt(i2(q), 0x7855); /* 'Ux' extension header */ - assertEqualInt(i2(q + 2), 4); /* 'Ux' size */ - assertEqualInt(i2(q + 4), folder_uid); /* 'Ux' UID */ - assertEqualInt(i2(q + 6), folder_gid); /* 'Ux' GID */ - q = q + 8; - - /* There should not be any data in the folder entry, - * meaning next is the data descriptor header. */ - - /* Verify data descriptor of folder entry. */ - assertEqualMem(q, "PK\007\010", 4); /* Signature */ - assertEqualInt(i4(q + 4), crc); /* CRC-32 */ - assertEqualInt(i4(q + 8), 0); /* Compressed size */ - assertEqualInt(i4(q + 12), 0); /* Uncompressed size */ - q = q + 16; -} diff --git a/lib/libarchive/test/test_write_open_memory.c b/lib/libarchive/test/test_write_open_memory.c deleted file mode 100644 index 14ce6e9..0000000 --- a/lib/libarchive/test/test_write_open_memory.c +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "test.h" -__FBSDID("$FreeBSD$"); - -/* Try to force archive_write_open_memory.c to write past the end of an array. */ -static unsigned char buff[16384]; - -DEFINE_TEST(test_write_open_memory) -{ - unsigned int i; - struct archive *a; - struct archive_entry *ae; - const char *name="/tmp/test"; - - /* Create a simple archive_entry. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, name); - archive_entry_set_mode(ae, S_IFREG); - assertEqualString(archive_entry_pathname(ae), name); - - /* Try writing with different buffer sizes. */ - /* Make sure that we get failure on too-small buffers, success on - * large enough ones. */ - for (i = 100; i < 1600; i++) { - size_t s; - size_t blocksize = 94; - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_set_bytes_per_block(a, (int)blocksize)); - buff[i] = 0xAE; - assertA(0 == archive_write_open_memory(a, buff, i, &s)); - /* If buffer is smaller than a tar header, this should fail. */ - if (i < (511/blocksize)*blocksize) - assertA(ARCHIVE_FATAL == archive_write_header(a,ae)); - else - assertA(0 == archive_write_header(a, ae)); - /* If buffer is smaller than a tar header plus 1024 byte - * end-of-archive marker, then this should fail. */ - if (i < 1536) - assertA(ARCHIVE_FATAL == archive_write_close(a)); - else - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - assert(buff[i] == 0xAE); - assert(s <= i); - } - archive_entry_free(ae); -} -- cgit v1.1 From 0441bd2fad88678678a39538fcb9d5b32b959995 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 22 Dec 2011 09:36:37 +0000 Subject: Add placeholder code for prepending pathnames to tftp. At work we have a single tftp server that provides installation data for a variety of operating systems. I'd rather place our FreeBSD-related files in a subdirectory, instead of the root. It would be nice if this setting could be run-time configurable, but at least in our specific case, this is not possible, as pxeboot is chainloaded through pxelinux. Sponsored by: Kumina bv --- lib/libstand/tftp.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/libstand/tftp.c b/lib/libstand/tftp.c index bf92c04..aa331b3 100644 --- a/lib/libstand/tftp.c +++ b/lib/libstand/tftp.c @@ -292,8 +292,15 @@ tftp_makereq(struct tftp_handle *h) wbuf.t.th_opcode = htons((u_short) RRQ); wtail = wbuf.t.th_stuff; l = strlen(h->path); +#ifdef TFTP_PREPEND_PATH + if (l > FNAME_SIZE - (sizeof(TFTP_PREPEND_PATH) - 1)) + return (ENAMETOOLONG); + bcopy(TFTP_PREPEND_PATH, wtail, sizeof(TFTP_PREPEND_PATH) - 1); + wtail += sizeof(TFTP_PREPEND_PATH) - 1; +#else if (l > FNAME_SIZE) return (ENAMETOOLONG); +#endif bcopy(h->path, wtail, l + 1); wtail += l + 1; bcopy("octet", wtail, 6); -- cgit v1.1 From 077423507056d0dc87787828a5c7ef69ab8d13dc Mon Sep 17 00:00:00 2001 From: ghelmer Date: Fri, 23 Dec 2011 01:56:25 +0000 Subject: Handle failures to malloc memory to hold key or val copies. PR: bin/83348 --- lib/libc/yp/xdryp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib') diff --git a/lib/libc/yp/xdryp.c b/lib/libc/yp/xdryp.c index ec2f71a..bb9096b 100644 --- a/lib/libc/yp/xdryp.c +++ b/lib/libc/yp/xdryp.c @@ -82,10 +82,21 @@ xdr_ypresp_all_seq(XDR *xdrs, u_long *objp) switch (status) { case YP_TRUE: key = (char *)malloc(out.ypresp_all_u.val.key.keydat_len + 1); + if (key == NULL) { + xdr_free((xdrproc_t)xdr_ypresp_all, &out); + *objp = YP_YPERR; + return (FALSE); + } bcopy(out.ypresp_all_u.val.key.keydat_val, key, out.ypresp_all_u.val.key.keydat_len); key[out.ypresp_all_u.val.key.keydat_len] = '\0'; val = (char *)malloc(out.ypresp_all_u.val.val.valdat_len + 1); + if (val == NULL) { + free(key); + xdr_free((xdrproc_t)xdr_ypresp_all, &out); + *objp = YP_YPERR; + return (FALSE); + } bcopy(out.ypresp_all_u.val.val.valdat_val, val, out.ypresp_all_u.val.val.valdat_len); val[out.ypresp_all_u.val.val.valdat_len] = '\0'; -- cgit v1.1 From 00828ba3e880be4944d23cef25a0e662a9bc73db Mon Sep 17 00:00:00 2001 From: ghelmer Date: Fri, 23 Dec 2011 02:13:42 +0000 Subject: Handle malloc failures in yplib.c. PR: bin/83349 --- lib/libc/yp/yplib.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'lib') diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c index 87d16dd..3dfc0aa 100644 --- a/lib/libc/yp/yplib.c +++ b/lib/libc/yp/yplib.c @@ -331,6 +331,8 @@ _yp_dobind(char *dom, struct dom_binding **ypdb) if (ysd == NULL) { ysd = (struct dom_binding *)malloc(sizeof *ysd); + if (ysd == NULL) + return (YPERR_RESRC); bzero((char *)ysd, sizeof *ysd); ysd->dom_socket = -1; ysd->dom_vers = 0; @@ -683,11 +685,18 @@ yp_match(char *indomain, char *inmap, const char *inkey, int inkeylen, */ *outvallen = yprv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); + if (*outval == NULL) { + _yp_unbind(ysd); + *outvallen = 0; + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; YPUNLOCK(); return (0); } + _yp_unbind(ysd); #endif again: @@ -713,6 +722,13 @@ again: if (!(r = ypprot_err(yprv.stat))) { *outvallen = yprv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); + if (*outval == NULL) { + _yp_unbind(ysd); + *outvallen = 0; + xdr_free((xdrproc_t)xdr_ypresp_val, &yprv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; #ifdef YPMATCHCACHE @@ -791,10 +807,25 @@ again: if (!(r = ypprot_err(yprkv.stat))) { *outkeylen = yprkv.key.keydat_len; *outkey = (char *)malloc(*outkeylen+1); + if (*outkey == NULL) { + _yp_unbind(ysd); + *outkeylen = 0; + xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprkv.key.keydat_val, *outkey, *outkeylen); (*outkey)[*outkeylen] = '\0'; *outvallen = yprkv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); + if (*outval == NULL) { + free(*outkey); + _yp_unbind(ysd); + *outkeylen = *outvallen = 0; + xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprkv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; } @@ -851,10 +882,25 @@ again: if (!(r = ypprot_err(yprkv.stat))) { *outkeylen = yprkv.key.keydat_len; *outkey = (char *)malloc(*outkeylen+1); + if (*outkey == NULL) { + _yp_unbind(ysd); + *outkeylen = 0; + xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprkv.key.keydat_val, *outkey, *outkeylen); (*outkey)[*outkeylen] = '\0'; *outvallen = yprkv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); + if (*outval == NULL) { + free(*outkey); + _yp_unbind(ysd); + *outkeylen = *outvallen = 0; + xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprkv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; } -- cgit v1.1 From 6d6844d3db7a60700aba1a03b565183435faab20 Mon Sep 17 00:00:00 2001 From: cperciva Date: Fri, 23 Dec 2011 15:00:37 +0000 Subject: Fix a problem whereby a corrupt DNS record can cause named to crash. [11:06] Add an API for alerting internal libc routines to the presence of "unsafe" paths post-chroot, and use it in ftpd. [11:07] Fix a buffer overflow in telnetd. [11:08] Make pam_ssh ignore unpassphrased keys unless the "nullok" option is specified. [11:09] Add sanity checking of service names in pam_start. [11:10] Approved by: so (cperciva) Approved by: re (bz) Security: FreeBSD-SA-11:06.bind Security: FreeBSD-SA-11:07.chroot Security: FreeBSD-SA-11:08.telnetd Security: FreeBSD-SA-11:09.pam_ssh Security: FreeBSD-SA-11:10.pam --- lib/libc/gen/Makefile.inc | 1 + lib/libc/gen/Symbol.map | 4 +++ lib/libc/gen/libc_dlopen.c | 61 +++++++++++++++++++++++++++++++++++++++++ lib/libc/iconv/citrus_module.c | 3 +- lib/libc/include/libc_private.h | 11 ++++++++ lib/libc/net/nsdispatch.c | 4 +-- 6 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 lib/libc/gen/libc_dlopen.c (limited to 'lib') diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index d3ccf0a..1e068a5 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -20,6 +20,7 @@ SRCS+= __getosreldate.c __xuname.c \ getpeereid.c getprogname.c getpwent.c getttyent.c \ getusershell.c getutxent.c getvfsbyname.c glob.c \ initgroups.c isatty.c isinf.c isnan.c jrand48.c lcong48.c \ + libc_dlopen.c \ lockf.c lrand48.c mrand48.c nftw.c nice.c \ nlist.c nrand48.c opendir.c \ pause.c pmadvise.c popen.c posix_spawn.c \ diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index c62e016..adc5964 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -381,6 +381,10 @@ FBSD_1.2 { setutxent; }; +FBSD_1.3 { + __FreeBSD_libc_enter_restricted_mode; +}; + FBSDprivate_1.0 { /* needed by thread libraries */ __thr_jtable; diff --git a/lib/libc/gen/libc_dlopen.c b/lib/libc/gen/libc_dlopen.c new file mode 100644 index 0000000..2b1aa9e --- /dev/null +++ b/lib/libc/gen/libc_dlopen.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2011 Xin Li + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include "libc_private.h" + +/* + * Whether we want to restrict dlopen()s. + */ +static int __libc_restricted_mode = 0; + +void * +libc_dlopen(const char *path, int mode) +{ + + if (__libc_restricted_mode) { + _rtld_error("Service unavailable -- libc in restricted mode"); + return (NULL); + } else + return (dlopen(path, mode)); +} + +void +__FreeBSD_libc_enter_restricted_mode(void) +{ + + __libc_restricted_mode = 1; + return; +} + diff --git a/lib/libc/iconv/citrus_module.c b/lib/libc/iconv/citrus_module.c index aa96aba..32b7e6e 100644 --- a/lib/libc/iconv/citrus_module.c +++ b/lib/libc/iconv/citrus_module.c @@ -109,6 +109,7 @@ #include "citrus_namespace.h" #include "citrus_bcs.h" #include "citrus_module.h" +#include "libc_private.h" static int _getdewey(int[], char *); static int _cmpndewey(int[], int, int[], int); @@ -294,7 +295,7 @@ _citrus_load_module(_citrus_module_t *rhandle, const char *encname) p = _findshlib(path, &maj, &min); if (!p) return (EINVAL); - handle = dlopen(p, RTLD_LAZY); + handle = libc_dlopen(p, RTLD_LAZY); if (!handle) { printf("%s", dlerror()); return (EINVAL); diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index a4737fe..c7284cc 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -44,6 +44,17 @@ extern int __isthreaded; /* + * libc should use libc_dlopen internally, which respects a global + * flag where loading of new shared objects can be restricted. + */ +void *libc_dlopen(const char *, int); + +/* + * For dynamic linker. + */ +void _rtld_error(const char *fmt, ...); + +/* * File lock contention is difficult to diagnose without knowing * where locks were set. Allow a debug library to be built which * records the source file and line number of each lock call. diff --git a/lib/libc/net/nsdispatch.c b/lib/libc/net/nsdispatch.c index 6b7bd02..f9d787a 100644 --- a/lib/libc/net/nsdispatch.c +++ b/lib/libc/net/nsdispatch.c @@ -384,7 +384,7 @@ nss_configure(void) confmod = statbuf.st_mtime; #ifdef NS_CACHING - handle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); + handle = libc_dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); if (handle != NULL) { nss_cache_cycle_prevention_func = dlsym(handle, "_nss_cache_cycle_prevention_function"); @@ -497,7 +497,7 @@ nss_load_module(const char *source, nss_module_register_fn reg_fn) if (snprintf(buf, sizeof(buf), "nss_%s.so.%d", mod.name, NSS_MODULE_INTERFACE_VERSION) >= (int)sizeof(buf)) goto fin; - mod.handle = dlopen(buf, RTLD_LOCAL|RTLD_LAZY); + mod.handle = libc_dlopen(buf, RTLD_LOCAL|RTLD_LAZY); if (mod.handle == NULL) { #ifdef _NSS_DEBUG /* This gets pretty annoying since the built-in -- cgit v1.1 From 8eb9e6b5487506b4d0f3e50d440fac3e93baf702 Mon Sep 17 00:00:00 2001 From: jhibbits Date: Sat, 24 Dec 2011 19:34:52 +0000 Subject: Implement hwpmc counting PMC support for PowerPC G4+ (MPC745x/MPC744x). Sampling is in progress. Approved by: nwhitehorn (mentor) MFC after: 9.0-RELEASE --- lib/libpmc/libpmc.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'lib') diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c index efdabc8..ba63ace 100644 --- a/lib/libpmc/libpmc.c +++ b/lib/libpmc/libpmc.c @@ -83,6 +83,10 @@ static int mips24k_allocate_pmc(enum pmc_event _pe, char* ctrspec, struct pmc_op_pmcallocate *_pmc_config); #endif /* __mips__ */ +#if defined(__powerpc__) +static int ppc7450_allocate_pmc(enum pmc_event _pe, char* ctrspec, + struct pmc_op_pmcallocate *_pmc_config); +#endif /* __powerpc__ */ #define PMC_CALL(cmd, params) \ syscall(pmc_syscall, PMC_OP_##cmd, (params)) @@ -149,6 +153,7 @@ PMC_CLASSDEP_TABLE(p6, P6); PMC_CLASSDEP_TABLE(xscale, XSCALE); PMC_CLASSDEP_TABLE(mips24k, MIPS24K); PMC_CLASSDEP_TABLE(ucf, UCF); +PMC_CLASSDEP_TABLE(ppc7450, PPC7450); #undef __PMC_EV_ALIAS #define __PMC_EV_ALIAS(N,CODE) { N, PMC_EV_##CODE }, @@ -211,6 +216,7 @@ PMC_MDEP_TABLE(p5, P5, PMC_CLASS_TSC); PMC_MDEP_TABLE(p6, P6, PMC_CLASS_TSC); PMC_MDEP_TABLE(xscale, XSCALE, PMC_CLASS_XSCALE); PMC_MDEP_TABLE(mips24k, MIPS24K, PMC_CLASS_MIPS24K); +PMC_MDEP_TABLE(ppc7450, PPC7450, PMC_CLASS_PPC7450); static const struct pmc_event_descr tsc_event_table[] = { @@ -263,6 +269,10 @@ PMC_CLASS_TABLE_DESC(xscale, XSCALE, xscale, xscale); PMC_CLASS_TABLE_DESC(mips24k, MIPS24K, mips24k, mips24k); #endif /* __mips__ */ +#if defined(__powerpc__) +PMC_CLASS_TABLE_DESC(ppc7450, PPC7450, ppc7450, ppc7450); +#endif + #undef PMC_CLASS_TABLE_DESC static const struct pmc_class_descr **pmc_class_table; @@ -2212,6 +2222,44 @@ mips24k_allocate_pmc(enum pmc_event pe, char *ctrspec __unused, } #endif /* __mips__ */ +#if defined(__powerpc__) + +static struct pmc_event_alias ppc7450_aliases[] = { + EV_ALIAS("instructions", "INSTR_COMPLETED"), + EV_ALIAS("branches", "BRANCHES_COMPLETED"), + EV_ALIAS("branch-mispredicts", "MISPREDICTED_BRANCHES"), + EV_ALIAS(NULL, NULL) +}; + +#define PPC7450_KW_OS "os" +#define PPC7450_KW_USR "usr" +#define PPC7450_KW_ANYTHREAD "anythread" + +static int +ppc7450_allocate_pmc(enum pmc_event pe, char *ctrspec __unused, + struct pmc_op_pmcallocate *pmc_config __unused) +{ + char *p; + + (void) pe; + + pmc_config->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE); + + while ((p = strsep(&ctrspec, ",")) != NULL) { + if (KWMATCH(p, PPC7450_KW_OS)) + pmc_config->pm_caps |= PMC_CAP_SYSTEM; + else if (KWMATCH(p, PPC7450_KW_USR)) + pmc_config->pm_caps |= PMC_CAP_USER; + else if (KWMATCH(p, PPC7450_KW_ANYTHREAD)) + pmc_config->pm_caps |= (PMC_CAP_USER | PMC_CAP_SYSTEM); + else + return (-1); + } + + return (0); +} +#endif /* __powerpc__ */ + /* * Match an event name `name' with its canonical form. @@ -2573,6 +2621,10 @@ pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames, ev = mips24k_event_table; count = PMC_EVENT_TABLE_SIZE(mips24k); break; + case PMC_CLASS_PPC7450: + ev = ppc7450_event_table; + count = PMC_EVENT_TABLE_SIZE(ppc7450); + break; default: errno = EINVAL; return (-1); @@ -2784,6 +2836,12 @@ pmc_init(void) pmc_class_table[n] = &mips24k_class_table_descr; break; #endif /* __mips__ */ +#if defined(__powerpc__) + case PMC_CPU_PPC_7450: + PMC_MDEP_INIT(ppc7450); + pmc_class_table[n] = &ppc7450_class_table_descr; + break; +#endif default: /* * Some kind of CPU this version of the library knows nothing @@ -2924,6 +2982,10 @@ _pmc_name_of_event(enum pmc_event pe, enum pmc_cputype cpu) ev = mips24k_event_table; evfence = mips24k_event_table + PMC_EVENT_TABLE_SIZE(mips24k ); + } else if (pe >= PMC_EV_PPC7450_FIRST && pe <= PMC_EV_PPC7450_LAST) { + ev = ppc7450_event_table; + evfence = ppc7450_event_table + PMC_EVENT_TABLE_SIZE(ppc7450 +); } else if (pe == PMC_EV_TSC_TSC) { ev = tsc_event_table; evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc); -- cgit v1.1 From 263706572b8dee06f63b68e467a20c8c3db31717 Mon Sep 17 00:00:00 2001 From: gjb Date: Mon, 26 Dec 2011 03:14:37 +0000 Subject: Add missing opening and closing brackets in getopt_long.3 and getsubopt.3 to make the examples reflect reality more closely. MFC after: 1 week X-MFC-After: 9.0-RELEASE --- lib/libc/stdlib/getopt_long.3 | 5 +++-- lib/libc/stdlib/getsubopt.3 | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/libc/stdlib/getopt_long.3 b/lib/libc/stdlib/getopt_long.3 index 72f6534..06eadca 100644 --- a/lib/libc/stdlib/getopt_long.3 +++ b/lib/libc/stdlib/getopt_long.3 @@ -31,7 +31,7 @@ .\" @(#)getopt.3 8.5 (Berkeley) 4/27/95 .\" $FreeBSD$ .\" -.Dd April 1, 2000 +.Dd December 25, 2011 .Dt GETOPT_LONG 3 .Os .Sh NAME @@ -239,7 +239,7 @@ static struct option longopts[] = { }; bflag = 0; -while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) +while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) { switch (ch) { case 'b': bflag = 1; @@ -256,6 +256,7 @@ while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) break; default: usage(); + } } argc -= optind; argv += optind; diff --git a/lib/libc/stdlib/getsubopt.3 b/lib/libc/stdlib/getsubopt.3 index b624eff..86894eb 100644 --- a/lib/libc/stdlib/getsubopt.3 +++ b/lib/libc/stdlib/getsubopt.3 @@ -28,7 +28,7 @@ .\" @(#)getsubopt.3 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd June 9, 1993 +.Dd December 25, 2011 .Dt GETSUBOPT 3 .Os .Sh NAME @@ -131,9 +131,11 @@ while ((ch = getopt(argc, argv, "ab:")) != \-1) { else error("missing sub option"); break; + } } break; } +} .Ed .Sh SEE ALSO .Xr getopt 3 , -- cgit v1.1 From 6f5f2f5fd7ad53b95e3fef6977942edeb70fc1e4 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 26 Dec 2011 21:51:53 +0000 Subject: Add libstdthreads. This library implements the C11 threads interface on top of the pthreads library. As discussed on the lists, the preferred way to implement this, is as a separate library. It is unlikely that these functions will be used a lot in the future. It would have been easier if the C11 working group standardized (a subset of) pthreads and clock_nanosleep(). Having it as a separate library allows the embedded people to omit it from their system. Discussed on: arch@, threads@ --- lib/Makefile | 1 + lib/libstdthreads/Makefile | 41 +++++++ lib/libstdthreads/Symbol.map | 31 +++++ lib/libstdthreads/call_once.c | 44 +++++++ lib/libstdthreads/cnd.c | 98 +++++++++++++++ lib/libstdthreads/mtx.c | 116 ++++++++++++++++++ lib/libstdthreads/thrd.c | 127 ++++++++++++++++++++ lib/libstdthreads/thrd_create.3 | 260 ++++++++++++++++++++++++++++++++++++++++ lib/libstdthreads/threads.h | 106 ++++++++++++++++ lib/libstdthreads/tss.c | 69 +++++++++++ 10 files changed, 893 insertions(+) create mode 100644 lib/libstdthreads/Makefile create mode 100644 lib/libstdthreads/Symbol.map create mode 100644 lib/libstdthreads/call_once.c create mode 100644 lib/libstdthreads/cnd.c create mode 100644 lib/libstdthreads/mtx.c create mode 100644 lib/libstdthreads/thrd.c create mode 100644 lib/libstdthreads/thrd_create.3 create mode 100644 lib/libstdthreads/threads.h create mode 100644 lib/libstdthreads/tss.c (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index ad647ec..d01fa47 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -101,6 +101,7 @@ SUBDIR= ${SUBDIR_ORDERED} \ ${_libsmdb} \ ${_libsmutil} \ libstand \ + libstdthreads \ ${_libtelnet} \ ${_libthr} \ libthread_db \ diff --git a/lib/libstdthreads/Makefile b/lib/libstdthreads/Makefile new file mode 100644 index 0000000..544eeb0 --- /dev/null +++ b/lib/libstdthreads/Makefile @@ -0,0 +1,41 @@ +# $FreeBSD$ + +LIB= stdthreads +SHLIB_MAJOR= 0 + +INCS= threads.h +SRCS= threads.h call_once.c cnd.c mtx.c thrd.c tss.c + +MAN= thrd_create.3 +MLINKS= thrd_create.3 call_once.3 \ + thrd_create.3 cnd_broadcast.3 \ + thrd_create.3 cnd_destroy.3 \ + thrd_create.3 cnd_init.3 \ + thrd_create.3 cnd_signal.3 \ + thrd_create.3 cnd_timedwait.3 \ + thrd_create.3 cnd_wait.3 \ + thrd_create.3 mtx_destroy.3 \ + thrd_create.3 mtx_init.3 \ + thrd_create.3 mtx_lock.3 \ + thrd_create.3 mtx_timedlock.3 \ + thrd_create.3 mtx_trylock.3 \ + thrd_create.3 mtx_unlock.3 \ + thrd_create.3 thrd_current.3 \ + thrd_create.3 thrd_detach.3 \ + thrd_create.3 thrd_equal.3 \ + thrd_create.3 thrd_exit.3 \ + thrd_create.3 thrd_join.3 \ + thrd_create.3 thrd_sleep.3 \ + thrd_create.3 thrd_yield.3 \ + thrd_create.3 tss_create.3 \ + thrd_create.3 tss_delete.3 \ + thrd_create.3 tss_get.3 \ + thrd_create.3 tss_set.3 + +DPADD= ${LIBPTHREAD} +LDADD= -lpthread + +VERSION_DEF= ${.CURDIR}/../libc/Versions.def +SYMBOL_MAPS= ${.CURDIR}/Symbol.map + +.include diff --git a/lib/libstdthreads/Symbol.map b/lib/libstdthreads/Symbol.map new file mode 100644 index 0000000..0fe6eac --- /dev/null +++ b/lib/libstdthreads/Symbol.map @@ -0,0 +1,31 @@ +/* + * $FreeBSD$ + */ + +FBSD_1.3 { + call_once; + cnd_broadcast; + cnd_destroy; + cnd_init; + cnd_signal; + cnd_timedwait; + cnd_wait; + mtx_destroy; + mtx_init; + mtx_lock; + mtx_timedlock; + mtx_trylock; + mtx_unlock; + thrd_create; + thrd_current; + thrd_detach; + thrd_equal; + thrd_exit; + thrd_join; + thrd_sleep; + thrd_yield; + tss_create; + tss_delete; + tss_get; + tss_set; +}; diff --git a/lib/libstdthreads/call_once.c b/lib/libstdthreads/call_once.c new file mode 100644 index 0000000..70ce8de --- /dev/null +++ b/lib/libstdthreads/call_once.c @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +#include "threads.h" + +void +call_once(once_flag *flag, void (*func)(void)) +{ + + (void)pthread_once((pthread_once_t *)flag, func); +} + +_Static_assert(sizeof(once_flag) == sizeof(pthread_once_t), + "once_flag must be of the same size as pthread_once_t"); diff --git a/lib/libstdthreads/cnd.c b/lib/libstdthreads/cnd.c new file mode 100644 index 0000000..145960d --- /dev/null +++ b/lib/libstdthreads/cnd.c @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +#include "threads.h" + +int +cnd_broadcast(cnd_t *cond) +{ + + if (pthread_cond_broadcast(cond) != 0) + return (thrd_error); + return (thrd_success); +} + +void +cnd_destroy(cnd_t *cond) +{ + + (void)pthread_cond_destroy(cond); +} + +int +cnd_init(cnd_t *cond) +{ + + switch (pthread_cond_init(cond, NULL)) { + case 0: + return (thrd_success); + case ENOMEM: + return (thrd_nomem); + default: + return (thrd_error); + } +} + +int +cnd_signal(cnd_t *cond) +{ + + if (pthread_cond_signal(cond) != 0) + return (thrd_error); + return (thrd_success); +} + +int +cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx, + const struct timespec *restrict ts) +{ + + switch (pthread_cond_timedwait(cond, mtx, ts)) { + case 0: + return (thrd_success); + case ETIMEDOUT: + return (thrd_timedout); + default: + return (thrd_error); + } +} + +int +cnd_wait(cnd_t *cond, mtx_t *mtx) +{ + + if (pthread_cond_wait(cond, mtx) != 0) + return (thrd_error); + return (thrd_success); +} diff --git a/lib/libstdthreads/mtx.c b/lib/libstdthreads/mtx.c new file mode 100644 index 0000000..6c9166d --- /dev/null +++ b/lib/libstdthreads/mtx.c @@ -0,0 +1,116 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +#include "threads.h" + +void +mtx_destroy(mtx_t *mtx) +{ + + (void)pthread_mutex_destroy(mtx); +} + +int +mtx_init(mtx_t *mtx, int type) +{ + pthread_mutexattr_t attr; + int mt; + + switch (type) { + case mtx_plain: + case mtx_timed: + mt = PTHREAD_MUTEX_NORMAL; + break; + case mtx_plain | mtx_recursive: + case mtx_timed | mtx_recursive: + mt = PTHREAD_MUTEX_RECURSIVE; + break; + default: + return (thrd_error); + } + + if (pthread_mutexattr_init(&attr) != 0) + return (thrd_error); + if (pthread_mutexattr_settype(&attr, mt) != 0) + return (thrd_error); + if (pthread_mutex_init(mtx, &attr) != 0) + return (thrd_error); + return (thrd_success); +} + +int +mtx_lock(mtx_t *mtx) +{ + + if (pthread_mutex_lock(mtx) != 0) + return (thrd_error); + return (thrd_success); +} + +int +mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts) +{ + + switch (pthread_mutex_timedlock(mtx, ts)) { + case 0: + return (thrd_success); + case ETIMEDOUT: + return (thrd_timedout); + default: + return (thrd_error); + } +} + +int +mtx_trylock(mtx_t *mtx) +{ + + switch (pthread_mutex_lock(mtx)) { + case 0: + return (thrd_success); + case EBUSY: + return (thrd_busy); + default: + return (thrd_error); + } +} + +int +mtx_unlock(mtx_t *mtx) +{ + + if (pthread_mutex_unlock(mtx) != 0) + return (thrd_error); + return (thrd_success); +} diff --git a/lib/libstdthreads/thrd.c b/lib/libstdthreads/thrd.c new file mode 100644 index 0000000..f0ce55a --- /dev/null +++ b/lib/libstdthreads/thrd.c @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include "threads.h" + +struct thrd_param { + thrd_start_t func; + void *arg; +}; + +static void * +thrd_entry(void *arg) +{ + struct thrd_param tp; + + tp = *(struct thrd_param *)arg; + free(arg); + return ((void *)(intptr_t)tp.func(tp.arg)); +} + +int +thrd_create(thrd_t *thr, thrd_start_t func, void *arg) +{ + struct thrd_param *tp; + + /* + * Work around return type inconsistency. Wrap execution using + * a function conforming to pthread_create()'s start_routine. + */ + tp = malloc(sizeof(*tp)); + if (tp == NULL) + return (thrd_nomem); + tp->func = func; + tp->arg = arg; + if (pthread_create(thr, NULL, thrd_entry, tp) != 0) { + free(tp); + return (thrd_error); + } + return (thrd_success); +} + +thrd_t +thrd_current(void) +{ + + return (pthread_self()); +} + +int +thrd_detach(thrd_t thr) +{ + + if (pthread_detach(thr) != 0) + return (thrd_error); + return (thrd_success); +} + +int +thrd_equal(thrd_t thr0, thrd_t thr1) +{ + + return (pthread_equal(thr0, thr1)); +} + +_Noreturn void +thrd_exit(int res) +{ + + pthread_exit((void *)(intptr_t)res); +} + +int +thrd_join(thrd_t thr, int *res) +{ + void *value_ptr; + + if (pthread_join(thr, &value_ptr) != 0) + return (thrd_error); + *res = (intptr_t)value_ptr; + return (thrd_success); +} + +int +thrd_sleep(const struct timespec *duration, struct timespec *remaining) +{ + + return (nanosleep(duration, remaining)); +} + +void +thrd_yield(void) +{ + + pthread_yield(); +} diff --git a/lib/libstdthreads/thrd_create.3 b/lib/libstdthreads/thrd_create.3 new file mode 100644 index 0000000..ede0d7f --- /dev/null +++ b/lib/libstdthreads/thrd_create.3 @@ -0,0 +1,260 @@ +.\" Copyright (c) 2011 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd December 26, 2011 +.Dt THRD_CREATE 3 +.Os +.Sh NAME +.Nm call_once , +.Nm cnd_broadcast , +.Nm cnd_destroy , +.Nm cnd_init , +.Nm cnd_signal , +.Nm cnd_timedwait , +.Nm cnd_wait , +.Nm mtx_destroy , +.Nm mtx_init , +.Nm mtx_lock , +.Nm mtx_timedlock , +.Nm mtx_trylock , +.Nm mtx_unlock , +.Nm thrd_create , +.Nm thrd_current , +.Nm thrd_detach , +.Nm thrd_equal , +.Nm thrd_exit , +.Nm thrd_join , +.Nm thrd_sleep , +.Nm thrd_yield , +.Nm tss_create , +.Nm tss_delete , +.Nm tss_get , +.Nm tss_set +.Nd C11 threads interface +.Sh LIBRARY +.Lb libstdthreads +.Sh SYNOPSIS +.In threads.h +.Ft void +.Fn call_once "once_flag *flag" "void (*func)(void)" +.Ft int +.Fn cnd_broadcast "cnd_t *cond" +.Ft void +.Fn cnd_destroy "cnd_t *cond" +.Ft int +.Fn cnd_init "cnd_t *cond" +.Ft int +.Fn cnd_signal "cnd_t *cond" +.Ft int +.Fn cnd_timedwait "cnd_t * restrict cond" "mtx_t * restrict mtx" "const struct timespec * restrict ts" +.Ft int +.Fn cnd_wait "cnd_t *cond" "mtx_t *mtx" +.Ft void +.Fn mtx_destroy "mtx_t *mtx" +.Ft int +.Fn mtx_init "mtx_t *mtx" "int type" +.Ft int +.Fn mtx_lock "mtx_t *mtx" +.Ft int +.Fn mtx_timedlock "mtx_t * restrict mtx" "const struct timespec * restrict ts" +.Ft int +.Fn mtx_trylock "mtx_t *mtx" +.Ft int +.Fn mtx_unlock "mtx_t *mtx" +.Ft int +.Fn thrd_create "thrd_t *thr" "int (*func)(void *)" "void *arg" +.Ft thrd_t +.Fn thrd_current "void" +.Ft int +.Fn thrd_detach "thrd_t thr" +.Ft int +.Fn thrd_equal "thrd_t thr0" "thrd_t thr1" +.Ft _Noreturn void +.Fn thrd_exit "int res" +.Ft int +.Fn thrd_join "thrd_t thr" "int *res" +.Ft int +.Fn thrd_sleep "const struct timespec *duration" "struct timespec *remaining" +.Ft void +.Fn thrd_yield "void" +.Ft int +.Fn tss_create "tss_t *key" "void (*dtor)(void *)" +.Ft void +.Fn tss_delete "tss_t key" +.Ft void * +.Fn tss_get "tss_t key" +.Ft int +.Fn tss_set "tss_t key" "void *val" +.Sh DESCRIPTION +As of +.St -isoC-11 , +the C standard includes an API for writing multithreaded applications. +Since POSIX.1 already includes a threading API that is used by virtually +any multithreaded application, the interface provided by the C standard +can be considered superfluous. +.Pp +In this implementation, the threading interface is therefore implemented +as a light-weight layer on top of existing interfaces. +The functions to which these routines are mapped, are listed in the +following table. +Please refer to the documentation of the POSIX equivalent functions for +more information. +.Bl -column ".Fn mtx_timedlock" ".Xr pthread_mutex_timedlock 3" -offset indent +.It Em Function Ta Em POSIX equivalent +.It Fn call_once Ta Xr pthread_once 3 +.It Fn cnd_broadcast Ta Xr pthread_cond_broadcast 3 +.It Fn cnd_destroy Ta Xr pthread_cond_destroy 3 +.It Fn cnd_init Ta Xr pthread_cond_init 3 +.It Fn cnd_signal Ta Xr pthread_cond_signal 3 +.It Fn cnd_timedwait Ta Xr pthread_cond_timedwait 3 +.It Fn cnd_wait Ta Xr pthread_cond_wait 3 +.It Fn mtx_destroy Ta Xr pthread_mutex_destroy 3 +.It Fn mtx_init Ta Xr pthread_mutex_init 3 +.It Fn mtx_lock Ta Xr pthread_mutex_lock 3 +.It Fn mtx_timedlock Ta Xr pthread_mutex_timedlock 3 +.It Fn mtx_trylock Ta Xr pthread_mutex_trylock 3 +.It Fn mtx_unlock Ta Xr pthread_mutex_unlock 3 +.It Fn thrd_create Ta Xr pthread_create 3 +.It Fn thrd_current Ta Xr pthread_self 3 +.It Fn thrd_detach Ta Xr pthread_detach 3 +.It Fn thrd_equal Ta Xr pthread_equal 3 +.It Fn thrd_exit Ta Xr pthread_exit 3 +.It Fn thrd_join Ta Xr pthread_join 3 +.It Fn thrd_sleep Ta Xr nanosleep 2 +.It Fn thrd_yield Ta Xr pthread_yield 3 +.It Fn tss_create Ta Xr pthread_key_create 3 +.It Fn tss_delete Ta Xr pthread_key_delete 3 +.It Fn tss_get Ta Xr pthread_getspecific 3 +.It Fn tss_set Ta Xr pthread_setspecific 3 +.El +.Sh DIFFERENCES WITH POSIX EQUIVALENTS +The +.Fn thrd_exit +function returns an integer value to the thread calling +.Fn thrd_join , +whereas the +.Fn pthread_exit +function uses a pointer. +.Pp +The mutex created by +.Fn mtx_init +can be of +.Fa type +.Dv mtx_plain +or +.Dv mtx_timed +to distinguish between a mutex that supports +.Fn mtx_timedlock . +This type can be +.Em or'd +with +.Dv mtx_recursive +to create a mutex that allows recursive acquisition. +These properties are normally set using +.Fn pthread_mutex_init Ns 's +.Fa attr +parameter. +.Sh RETURN VALUES +If successful, the +.Fn cnd_broadcast , +.Fn cnd_init , +.Fn cnd_signal , +.Fn cnd_timedwait , +.Fn cnd_wait , +.Fn mtx_init , +.Fn mtx_lock , +.Fn mtx_timedlock , +.Fn mtx_trylock , +.Fn mtx_unlock , +.Fn thrd_create , +.Fn thrd_detach , +.Fn thrd_equal , +.Fn thrd_join , +.Fn thrd_sleep , +.Fn tss_create +and +.Fn tss_set +functions return +.Dv thrd_success . +Otherwise an error code will be returned to indicate the error. +.Pp +The +.Fn thrd_current +function returns the thread ID of the calling thread. +.Pp +The +.Fn tss_get +function returns the thread-specific data value associated with the +given +.Fa key . +If no thread-specific data value is associated with +.Fa key , +then the value NULL is returned. +.Sh ERRORS +The +.Fn cnd_init +and +.Fn thrd_create +functions will fail if: +.Bl -tag -width thrd_timedout +.It Dv thrd_nomem +The system has insufficient memory. +.El +.Pp +The +.Fn cnd_timedwait +and +.Fn mtx_timedlock +functions will fail if: +.Bl -tag -width thrd_timedout +.It Dv thrd_timedout +The system time has reached or exceeded the time specified in +.Fa ts +before the operation could be completed. +.El +.Pp +The +.Fn mtx_trylock +function will fail if: +.Bl -tag -width thrd_timedout +.It Dv thrd_busy +The mutex is already locked. +.El +.Pp +In all other cases, these functions may fail by returning general error +code +.Dv thrd_error . +.Sh SEE ALSO +.Xr nanosleep 2 , +.Xr pthread 3 +.Sh STANDARDS +These functions are expected to conform to +.St -isoC-11 . +.Sh HISTORY +These functions appeared in +.Fx 10.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libstdthreads/threads.h b/lib/libstdthreads/threads.h new file mode 100644 index 0000000..aba9ca1 --- /dev/null +++ b/lib/libstdthreads/threads.h @@ -0,0 +1,106 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _THREADS_H_ +#define _THREADS_H_ + +#include + +/* + * The C11 threads interface. + * + * This interface is implemented as a light-weight wrapper around + * . To prevent namespace pollution, the once_flag object, + * its corresponding ONCE_FLAG_INIT and TSS_DTOR_ITERATIONS have been + * copied from this header file. They must be kept in sync. + */ + +typedef struct pthread_cond *cnd_t; +typedef struct pthread_mutex *mtx_t; +typedef struct pthread *thrd_t; +typedef int tss_t; + +typedef struct { + int __state; + mtx_t __mutex; +} once_flag; + +typedef void (*tss_dtor_t)(void *); +typedef int (*thrd_start_t)(void *); + +enum { + mtx_plain = 0x1, + mtx_recursive = 0x2, + mtx_timed = 0x4 +}; + +enum { + thrd_busy = 1, + thrd_error = 2, + thrd_nomem = 3, + thrd_success = 4, + thrd_timedout = 5 +}; + +#if !defined(__cplusplus) || __cplusplus < 201103L +#define thread_local _Thread_local +#endif +#define ONCE_FLAG_INIT { 0, NULL } +#define TSS_DTOR_ITERATIONS 4 + +__BEGIN_DECLS +void call_once(once_flag *, void (*)(void)); +int cnd_broadcast(cnd_t *); +void cnd_destroy(cnd_t *); +int cnd_init(cnd_t *); +int cnd_signal(cnd_t *); +int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, + const struct timespec *__restrict); +int cnd_wait(cnd_t *, mtx_t *); +void mtx_destroy(mtx_t *); +int mtx_init(mtx_t *, int); +int mtx_lock(mtx_t *); +int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict); +int mtx_trylock(mtx_t *); +int mtx_unlock(mtx_t *); +int thrd_create(thrd_t *, thrd_start_t, void *); +thrd_t thrd_current(void); +int thrd_detach(thrd_t); +int thrd_equal(thrd_t, thrd_t); +_Noreturn void + thrd_exit(int); +int thrd_join(thrd_t, int *); +int thrd_sleep(const struct timespec *, struct timespec *); +void thrd_yield(void); +int tss_create(tss_t *, tss_dtor_t); +void tss_delete(tss_t); +void * tss_get(tss_t); +int tss_set(tss_t, void *); +__END_DECLS + +#endif /* !_THREADS_H_ */ diff --git a/lib/libstdthreads/tss.c b/lib/libstdthreads/tss.c new file mode 100644 index 0000000..ef78b4b --- /dev/null +++ b/lib/libstdthreads/tss.c @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +#include "threads.h" + +int +tss_create(tss_t *key, tss_dtor_t dtor) +{ + + if (pthread_key_create(key, dtor) != 0) + return (thrd_error); + return (thrd_success); +} + +void +tss_delete(tss_t key) +{ + + (void)pthread_key_delete(key); +} + +void * +tss_get(tss_t key) +{ + + return (pthread_getspecific(key)); +} + +int +tss_set(tss_t key, void *val) +{ + + if (pthread_setspecific(key, val) != 0) + return (thrd_error); + return (thrd_success); +} + +_Static_assert(TSS_DTOR_ITERATIONS == PTHREAD_DESTRUCTOR_ITERATIONS, + "TSS_DTOR_ITERATIONS must be identical to PTHREAD_DESTRUCTOR_ITERATIONS"); -- cgit v1.1 From d6760e1d0df40d7f2b590f408ab0cbc8fd812bb9 Mon Sep 17 00:00:00 2001 From: delphij Date: Tue, 27 Dec 2011 10:34:00 +0000 Subject: Update rtprio(2) manual page to reflect the latest changes in -CURRENT as well as provide documentation for rtprio_thread(2) system call. MFC after: 1 month X-MFC-after: r228470 --- lib/libc/sys/Makefile.inc | 1 + lib/libc/sys/rtprio.2 | 98 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 82 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index ea38b51..073220e 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -188,6 +188,7 @@ MLINKS+=read.2 pread.2 read.2 preadv.2 read.2 readv.2 MLINKS+=readlink.2 readlinkat.2 MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 MLINKS+=rename.2 renameat.2 +MLINKS+=rtprio.2 rtprio_thread.2 .if !defined(NO_P1003_1B) MLINKS+=sched_get_priority_max.2 sched_get_priority_min.2 \ sched_get_priority_max.2 sched_rr_get_interval.2 diff --git a/lib/libc/sys/rtprio.2 b/lib/libc/sys/rtprio.2 index afed81e..faad941 100644 --- a/lib/libc/sys/rtprio.2 +++ b/lib/libc/sys/rtprio.2 @@ -1,3 +1,4 @@ +.\"- .\" Copyright (c) 1994, Henrik Vestergaard Draboel .\" All rights reserved. .\" @@ -26,15 +27,40 @@ .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. +.\"- +.\" Copyright (c) 2011 Xin LI +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd July 23, 1994 +.Dd December 27, 2011 .Dt RTPRIO 2 .Os .Sh NAME -.Nm rtprio -.Nd examine or modify a process realtime or idle priority +.Nm rtprio , +.Nm rtprio_thread +.Nd examine or modify realtime or idle priority .Sh LIBRARY .Lb libc .Sh SYNOPSIS @@ -42,11 +68,18 @@ .In sys/rtprio.h .Ft int .Fn rtprio "int function" "pid_t pid" "struct rtprio *rtp" +.Ft int +.Fn rtprio_thread "int function" "lwpid_t lwpid" "struct rtprio *rtp" .Sh DESCRIPTION The .Fn rtprio system call -is used to lookup or change the realtime or idle priority of a process. +is used to lookup or change the realtime or idle priority of a process, +or the calling thread. +The +.Fn rtprio_thread +system call +is used to lookup or change the realtime or idle priority of a thread. .Pp The .Fa function @@ -54,10 +87,31 @@ argument specifies the operation to be performed. RTP_LOOKUP to lookup the current priority, and RTP_SET to set the priority. -The +.Pp +For the +.Fn rtprio +system call, +the .Fa pid argument -specifies the process to be used, 0 for the current process. +specifies the process to operate on, +0 for the calling thread. +When +.Fa pid +is non-zero, +the system call reports the highest priority in the process, +or sets all threads' priority in the process, +depending on value of the +.Fa function +argument. +.Pp +For the +.Fn rtprio_thread +system call, +the +.Fa lwpid +specifies the thread to operate on, +0 for the calling thread. .Pp The .Fa *rtp @@ -83,12 +137,12 @@ field ranges between 0 and .Pp Realtime and idle priority is inherited through fork() and exec(). .Pp -A realtime process can only be preempted by a process of equal or -higher priority, or by an interrupt; idle priority processes will run only -when no other real/normal priority process is runnable. -Higher real/idle priority processes -preempt lower real/idle priority processes. -Processes of equal real/idle priority are run round-robin. +A realtime thread can only be preempted by a thread of equal or +higher priority, or by an interrupt; idle priority threads will run only +when no other real/normal priority thread is runnable. +Higher real/idle priority threads +preempt lower real/idle priority threads. +Threads of equal real/idle priority are run round-robin. .Sh RETURN VALUES .Rv -std rtprio .Sh ERRORS @@ -102,12 +156,17 @@ The specified .Fa prio was out of range. .It Bq Er EPERM -The calling process is not allowed to set the realtime priority. +The calling thread is not allowed to set the realtime priority. Only -root is allowed to change the realtime priority of any process, and non-root -may only change the idle priority of the current process. +root is allowed to change the realtime priority of any thread, and non-root +may only change the idle priority of threads the user owns, +when the +.Xr sysctl 8 +variable +.Va security.bsd.unprivileged_idprio +is set to non-zero. .It Bq Er ESRCH -The specified process was not found. +The specified process or thread was not found or visible. .El .Sh SEE ALSO .Xr nice 1 , @@ -115,7 +174,8 @@ The specified process was not found. .Xr rtprio 1 , .Xr setpriority 2 , .Xr nice 3 , -.Xr renice 8 +.Xr renice 8 , +.Xr p_cansee 9 . .Sh AUTHORS .An -nosplit The original author was @@ -124,3 +184,7 @@ This implementation in .Fx was substantially rewritten by .An David Greenman . +The +.Fn rtprio_thread +system call was implemented by +.An David Xu . -- cgit v1.1 From 52306b41a65349c9fb64a1e03d2b593af6927dbd Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 27 Dec 2011 22:13:51 +0000 Subject: Add locally implemented atomic intrinsics to libcompiler_rt. The built-in atomic operations are not implemented in our version of GCC 4.2 for the ARM and MIPS architectures. Instead of emitting locked instructions, they generate calls to functions that can be implemented in the C runtime. Only implement the atomic operations that are used by for datatype sizes that are supported by atomic(9). This means that on these architectures, we can only use atomic operations on 32-bits and 64-bits variables, which is typically sufficient. This makes work on all architectures except MIPS, since MIPS and SPARC64 still use libgcc. Converting these architectures to libcompiler_rt is on my todo list. --- lib/libcompiler_rt/Makefile | 20 +++++++++ lib/libcompiler_rt/__sync_fetch_and_add_4.c | 6 +++ lib/libcompiler_rt/__sync_fetch_and_add_8.c | 6 +++ lib/libcompiler_rt/__sync_fetch_and_and_4.c | 7 ++++ lib/libcompiler_rt/__sync_fetch_and_and_8.c | 7 ++++ lib/libcompiler_rt/__sync_fetch_and_op_n.h | 47 ++++++++++++++++++++++ lib/libcompiler_rt/__sync_fetch_and_or_4.c | 7 ++++ lib/libcompiler_rt/__sync_fetch_and_or_8.c | 7 ++++ lib/libcompiler_rt/__sync_fetch_and_sub_4.c | 6 +++ lib/libcompiler_rt/__sync_fetch_and_sub_8.c | 6 +++ lib/libcompiler_rt/__sync_fetch_and_xor_4.c | 7 ++++ lib/libcompiler_rt/__sync_fetch_and_xor_8.c | 7 ++++ lib/libcompiler_rt/__sync_lock_test_and_set_4.c | 7 ++++ lib/libcompiler_rt/__sync_lock_test_and_set_8.c | 7 ++++ lib/libcompiler_rt/__sync_val_compare_and_swap_4.c | 6 +++ lib/libcompiler_rt/__sync_val_compare_and_swap_8.c | 6 +++ lib/libcompiler_rt/__sync_val_compare_and_swap_n.h | 45 +++++++++++++++++++++ 17 files changed, 204 insertions(+) create mode 100644 lib/libcompiler_rt/__sync_fetch_and_add_4.c create mode 100644 lib/libcompiler_rt/__sync_fetch_and_add_8.c create mode 100644 lib/libcompiler_rt/__sync_fetch_and_and_4.c create mode 100644 lib/libcompiler_rt/__sync_fetch_and_and_8.c create mode 100644 lib/libcompiler_rt/__sync_fetch_and_op_n.h create mode 100644 lib/libcompiler_rt/__sync_fetch_and_or_4.c create mode 100644 lib/libcompiler_rt/__sync_fetch_and_or_8.c create mode 100644 lib/libcompiler_rt/__sync_fetch_and_sub_4.c create mode 100644 lib/libcompiler_rt/__sync_fetch_and_sub_8.c create mode 100644 lib/libcompiler_rt/__sync_fetch_and_xor_4.c create mode 100644 lib/libcompiler_rt/__sync_fetch_and_xor_8.c create mode 100644 lib/libcompiler_rt/__sync_lock_test_and_set_4.c create mode 100644 lib/libcompiler_rt/__sync_lock_test_and_set_8.c create mode 100644 lib/libcompiler_rt/__sync_val_compare_and_swap_4.c create mode 100644 lib/libcompiler_rt/__sync_val_compare_and_swap_8.c create mode 100644 lib/libcompiler_rt/__sync_val_compare_and_swap_n.h (limited to 'lib') diff --git a/lib/libcompiler_rt/Makefile b/lib/libcompiler_rt/Makefile index 3a501f5..ce091da 100644 --- a/lib/libcompiler_rt/Makefile +++ b/lib/libcompiler_rt/Makefile @@ -144,6 +144,26 @@ SRCF+= adddf3 \ umodsi3 .endif +# FreeBSD-specific atomic intrinsics. +.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips" +SRCF+= __sync_fetch_and_add_4 \ + __sync_fetch_and_and_4 \ + __sync_fetch_and_or_4 \ + __sync_fetch_and_sub_4 \ + __sync_fetch_and_xor_4 \ + __sync_lock_test_and_set_4 \ + __sync_val_compare_and_swap_4 +.endif +.if ${MACHINE_ARCH:Mmips64*} != "" +SRCF+= __sync_fetch_and_add_8 \ + __sync_fetch_and_and_8 \ + __sync_fetch_and_or_8 \ + __sync_fetch_and_sub_8 \ + __sync_fetch_and_xor_8 \ + __sync_lock_test_and_set_8 \ + __sync_val_compare_and_swap_8 +.endif + .for file in ${SRCF} . if ${MACHINE_CPUARCH} != "arm" && exists(${CRTSRC}/${CRTARCH}/${file}.S) SRCS+= ${file}.S diff --git a/lib/libcompiler_rt/__sync_fetch_and_add_4.c b/lib/libcompiler_rt/__sync_fetch_and_add_4.c new file mode 100644 index 0000000..3c11a3b --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_add_4.c @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_add_4 +#define TYPE uint32_t +#define FETCHADD(x, y) atomic_fetchadd_32(x, y) + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_fetch_and_add_8.c b/lib/libcompiler_rt/__sync_fetch_and_add_8.c new file mode 100644 index 0000000..6157c15 --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_add_8.c @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_add_8 +#define TYPE uint64_t +#define FETCHADD(x, y) atomic_fetchadd_64(x, y) + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_fetch_and_and_4.c b/lib/libcompiler_rt/__sync_fetch_and_and_4.c new file mode 100644 index 0000000..1a488ec --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_and_4.c @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_and_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 +#define EXPRESSION t & value + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_fetch_and_and_8.c b/lib/libcompiler_rt/__sync_fetch_and_and_8.c new file mode 100644 index 0000000..9923e31 --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_and_8.c @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_and_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 +#define EXPRESSION t & value + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_fetch_and_op_n.h b/lib/libcompiler_rt/__sync_fetch_and_op_n.h new file mode 100644 index 0000000..f7f0e06 --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_op_n.h @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +TYPE +NAME(volatile TYPE *ptr, TYPE value) +{ + TYPE t; + +#ifdef FETCHADD + t = FETCHADD(ptr, value); +#else + do { + t = *ptr; + } while (!CMPSET(ptr, t, EXPRESSION)); +#endif + + return (t); +} diff --git a/lib/libcompiler_rt/__sync_fetch_and_or_4.c b/lib/libcompiler_rt/__sync_fetch_and_or_4.c new file mode 100644 index 0000000..1feeeb1 --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_or_4.c @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_or_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 +#define EXPRESSION t | value + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_fetch_and_or_8.c b/lib/libcompiler_rt/__sync_fetch_and_or_8.c new file mode 100644 index 0000000..7cb9403 --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_or_8.c @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_or_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 +#define EXPRESSION t | value + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_fetch_and_sub_4.c b/lib/libcompiler_rt/__sync_fetch_and_sub_4.c new file mode 100644 index 0000000..a251add --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_sub_4.c @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_sub_4 +#define TYPE uint32_t +#define FETCHADD(x, y) atomic_fetchadd_32(x, -(y)) + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_fetch_and_sub_8.c b/lib/libcompiler_rt/__sync_fetch_and_sub_8.c new file mode 100644 index 0000000..5a93f97 --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_sub_8.c @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_sub_8 +#define TYPE uint64_t +#define FETCHADD(x, y) atomic_fetchadd_64(x, -(y)) + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_fetch_and_xor_4.c b/lib/libcompiler_rt/__sync_fetch_and_xor_4.c new file mode 100644 index 0000000..d5f732d --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_xor_4.c @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_xor_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 +#define EXPRESSION t ^ value + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_fetch_and_xor_8.c b/lib/libcompiler_rt/__sync_fetch_and_xor_8.c new file mode 100644 index 0000000..610037e --- /dev/null +++ b/lib/libcompiler_rt/__sync_fetch_and_xor_8.c @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_xor_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 +#define EXPRESSION t ^ value + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_lock_test_and_set_4.c b/lib/libcompiler_rt/__sync_lock_test_and_set_4.c new file mode 100644 index 0000000..d4965f9 --- /dev/null +++ b/lib/libcompiler_rt/__sync_lock_test_and_set_4.c @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_lock_test_and_set_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 +#define EXPRESSION value + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_lock_test_and_set_8.c b/lib/libcompiler_rt/__sync_lock_test_and_set_8.c new file mode 100644 index 0000000..1e02203 --- /dev/null +++ b/lib/libcompiler_rt/__sync_lock_test_and_set_8.c @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_lock_test_and_set_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 +#define EXPRESSION value + +#include "__sync_fetch_and_op_n.h" diff --git a/lib/libcompiler_rt/__sync_val_compare_and_swap_4.c b/lib/libcompiler_rt/__sync_val_compare_and_swap_4.c new file mode 100644 index 0000000..e0ab115 --- /dev/null +++ b/lib/libcompiler_rt/__sync_val_compare_and_swap_4.c @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_val_compare_and_swap_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 + +#include "__sync_val_compare_and_swap_n.h" diff --git a/lib/libcompiler_rt/__sync_val_compare_and_swap_8.c b/lib/libcompiler_rt/__sync_val_compare_and_swap_8.c new file mode 100644 index 0000000..c6f1101 --- /dev/null +++ b/lib/libcompiler_rt/__sync_val_compare_and_swap_8.c @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_val_compare_and_swap_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 + +#include "__sync_val_compare_and_swap_n.h" diff --git a/lib/libcompiler_rt/__sync_val_compare_and_swap_n.h b/lib/libcompiler_rt/__sync_val_compare_and_swap_n.h new file mode 100644 index 0000000..cd4c9a3 --- /dev/null +++ b/lib/libcompiler_rt/__sync_val_compare_and_swap_n.h @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +TYPE +NAME(volatile TYPE *ptr, TYPE oldval, TYPE newval) +{ + TYPE t; + + while (!CMPSET(ptr, oldval, newval)) { + t = *ptr; + if (t != oldval) + return (t); + } + + return (oldval); +} -- cgit v1.1 From 38173b70a257713ea47722d34867959945a22098 Mon Sep 17 00:00:00 2001 From: jilles Date: Tue, 27 Dec 2011 23:28:01 +0000 Subject: libc: Eliminate some relative relocations in setlocale(). --- lib/libc/locale/setlocale.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 8cf8fd4..0322af2 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -57,7 +57,7 @@ __FBSDID("$FreeBSD$"); /* * Category names for getenv() */ -static char *categories[_LC_LAST] = { +static const char categories[_LC_LAST][12] = { "LC_ALL", "LC_COLLATE", "LC_CTYPE", -- cgit v1.1 From 15457970de153acce9c3dc4ad0f50260cdf38b88 Mon Sep 17 00:00:00 2001 From: jilles Date: Tue, 27 Dec 2011 23:35:10 +0000 Subject: libc: Eliminate some relative relocations in getusershell(). --- lib/libc/gen/getusershell.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c index d09b50c..ce50069 100644 --- a/lib/libc/gen/getusershell.c +++ b/lib/libc/gen/getusershell.c @@ -58,12 +58,6 @@ __FBSDID("$FreeBSD$"); #endif #include "un-namespace.h" -/* - * Local shells should NOT be added here. They should be added in - * /etc/shells. - */ - -static const char *const okshells[] = { _PATH_BSHELL, _PATH_CSHELL, NULL }; static const char *const *curshell; static StringList *sl; @@ -261,8 +255,13 @@ initshells() != NS_SUCCESS) { if (sl) sl_free(sl, 1); - sl = NULL; - return (okshells); + sl = sl_init(); + /* + * Local shells should NOT be added here. They should be + * added in /etc/shells. + */ + sl_add(sl, strdup(_PATH_BSHELL)); + sl_add(sl, strdup(_PATH_CSHELL)); } sl_add(sl, NULL); -- cgit v1.1 From 644e38ede6762623e61236040a3c14d308da8145 Mon Sep 17 00:00:00 2001 From: pluknet Date: Thu, 29 Dec 2011 21:12:22 +0000 Subject: Fix manual section for acl_get(3) and mac_get(3) family functions. Reviewed by: rwatson MFC after: 1 week --- lib/libc/sys/cap_new.2 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/libc/sys/cap_new.2 b/lib/libc/sys/cap_new.2 index c15cc46..362be5c 100644 --- a/lib/libc/sys/cap_new.2 +++ b/lib/libc/sys/cap_new.2 @@ -107,17 +107,17 @@ Permit checking of an ACL on a file descriptor; there is no cross-reference for this system call. .It Dv CAP_ACL_DELETE Permit -.Xr acl_delete_fd_np 2 . +.Xr acl_delete_fd_np 3 . .It Dv CAP_ACL_GET Permit -.Xr acl_get_fd 2 +.Xr acl_get_fd 3 and -.Xr acl_get_fd_np 2 . +.Xr acl_get_fd_np 3 . .It Dv CAP_ACL_SET Permit -.Xr acl_set_fd 2 +.Xr acl_set_fd 3 and -.Xr acl_set_fd_np 2 . +.Xr acl_set_fd_np 3 . .It Dv CAP_BIND Permit .Xr bind 2 . @@ -240,10 +240,10 @@ a global name space; see for details. .It Dv CAP_MAC_GET Permit -.Xr mac_get_fd 2 . +.Xr mac_get_fd 3 . .It Dv CAP_MAC_SET Permit -.Xr mac_set_fd 2 . +.Xr mac_set_fd 3 . .It Dv CAP_MMAP Permit .Xr mmap 2 ; @@ -385,12 +385,8 @@ argument is not a capability. .El .Sh SEE ALSO .Xr accept 2 , -.Xr acl_delete_fd_np 2 , -.Xr acl_get_fd 2 , -.Xr acl_get_fd_np 2 , -.Xr acl_set_fd_np 2 , -.Xr aio_read 2 , .Xr aio_fsync 2 , +.Xr aio_read 2 , .Xr aio_write 2 , .Xr bind 2 , .Xr cap_enter 2 , @@ -421,8 +417,6 @@ argument is not a capability. .Xr kqueue 2 , .Xr linkat 2 , .Xr listen 2 , -.Xr mac_get_fd 2 , -.Xr mac_set_fd 2 , .Xr mmap 2 , .Xr mq_open 2 , .Xr open 2 , @@ -450,8 +444,14 @@ argument is not a capability. .Xr socketpair 2 , .Xr unlinkat 2 , .Xr write 2 , +.Xr acl_delete_fd_np 3 , +.Xr acl_get_fd 3 , +.Xr acl_get_fd_np 3 , +.Xr acl_set_fd_np 3 , .Xr cap_limitfd 3 , .Xr libcapsicum 3 , +.Xr mac_get_fd 3 , +.Xr mac_set_fd 3 , .Xr sem_getvalue 3 , .Xr sem_post 3 , .Xr sem_trywait 3 , -- cgit v1.1 From 792fdc63c101fa0058ae95c852d3f279ae782302 Mon Sep 17 00:00:00 2001 From: jilles Date: Thu, 29 Dec 2011 22:15:18 +0000 Subject: libc: Eliminate some relative relocations in file flags table. --- lib/libc/gen/strtofflags.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/libc/gen/strtofflags.c b/lib/libc/gen/strtofflags.c index 12db2b4..596ef7b 100644 --- a/lib/libc/gen/strtofflags.c +++ b/lib/libc/gen/strtofflags.c @@ -41,35 +41,35 @@ __FBSDID("$FreeBSD$"); #include #include +#define longestflaglen 12 static struct { - char *name; + char name[longestflaglen + 1]; + char invert; u_long flag; - int invert; -} mapping[] = { +} const mapping[] = { /* shorter names per flag first, all prefixed by "no" */ - { "nosappnd", SF_APPEND, 0 }, - { "nosappend", SF_APPEND, 0 }, - { "noarch", SF_ARCHIVED, 0 }, - { "noarchived", SF_ARCHIVED, 0 }, - { "noschg", SF_IMMUTABLE, 0 }, - { "noschange", SF_IMMUTABLE, 0 }, - { "nosimmutable", SF_IMMUTABLE, 0 }, - { "nosunlnk", SF_NOUNLINK, 0 }, - { "nosunlink", SF_NOUNLINK, 0 }, + { "nosappnd", 0, SF_APPEND }, + { "nosappend", 0, SF_APPEND }, + { "noarch", 0, SF_ARCHIVED }, + { "noarchived", 0, SF_ARCHIVED }, + { "noschg", 0, SF_IMMUTABLE }, + { "noschange", 0, SF_IMMUTABLE }, + { "nosimmutable", 0, SF_IMMUTABLE }, + { "nosunlnk", 0, SF_NOUNLINK }, + { "nosunlink", 0, SF_NOUNLINK }, #ifdef SF_SNAPSHOT - { "nosnapshot", SF_SNAPSHOT, 0 }, + { "nosnapshot", 0, SF_SNAPSHOT }, #endif - { "nouappnd", UF_APPEND, 0 }, - { "nouappend", UF_APPEND, 0 }, - { "nouchg", UF_IMMUTABLE, 0 }, - { "nouchange", UF_IMMUTABLE, 0 }, - { "nouimmutable", UF_IMMUTABLE, 0 }, - { "nodump", UF_NODUMP, 1 }, - { "noopaque", UF_OPAQUE, 0 }, - { "nouunlnk", UF_NOUNLINK, 0 }, - { "nouunlink", UF_NOUNLINK, 0 } + { "nouappnd", 0, UF_APPEND }, + { "nouappend", 0, UF_APPEND }, + { "nouchg", 0, UF_IMMUTABLE }, + { "nouchange", 0, UF_IMMUTABLE }, + { "nouimmutable", 0, UF_IMMUTABLE }, + { "nodump", 1, UF_NODUMP }, + { "noopaque", 0, UF_OPAQUE }, + { "nouunlnk", 0, UF_NOUNLINK }, + { "nouunlink", 0, UF_NOUNLINK } }; -#define longestflaglen 12 #define nmappings (sizeof(mapping) / sizeof(mapping[0])) /* -- cgit v1.1 From c12910138c122eb89614cb32832cc1e81e4c23a7 Mon Sep 17 00:00:00 2001 From: rwatson Date: Fri, 30 Dec 2011 10:45:00 +0000 Subject: Fix typo in Makefile comment. MFC after: 3 days --- lib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index d01fa47..ba2f905 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -8,7 +8,7 @@ # # csu must be built before all shared libaries for ELF. # libc must be built before all other shared libraries. -# libbsm must be built before ibauditd. +# libbsm must be built before libauditd. # libcom_err must be built before libpam. # libcrypt must be built before libpam. # libkvm must be built before libdevstat. -- cgit v1.1 From 320e3c42d97756708b2d723c0577368cac0ccb70 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 30 Dec 2011 20:41:24 +0000 Subject: Add some additional const poison after r228972. The 'mapping' array in lib/libc/gen/strtofflags.c became const, but gcc did not warn about assigning its members to non-const pointers. Clang warned about this with: lib/libc/gen/strtofflags.c:98:12: error: assigning to 'char *' from 'const char *' discards qualifiers [-Werror,-Wincompatible-pointer-types] for (sp = mapping[i].invert ? mapping[i].name : ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Reviewed by: jilles --- lib/libc/gen/strtofflags.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libc/gen/strtofflags.c b/lib/libc/gen/strtofflags.c index 596ef7b..1edaa5a 100644 --- a/lib/libc/gen/strtofflags.c +++ b/lib/libc/gen/strtofflags.c @@ -82,7 +82,8 @@ fflagstostr(flags) u_long flags; { char *string; - char *sp, *dp; + const char *sp; + char *dp; u_long setflags; int i; -- cgit v1.1 From 6a5f9bc9ae3205be8bb5570b86a509fcd01a9db6 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 31 Dec 2011 14:55:23 +0000 Subject: Import compiler-rt r147390. --- lib/Makefile.mk | 11 +- lib/abi.h | 23 - lib/absvdi2.c | 2 - lib/absvsi2.c | 2 - lib/absvti2.c | 1 - lib/adddf3.c | 2 - lib/addsf3.c | 2 - lib/addvdi3.c | 2 - lib/addvsi3.c | 2 - lib/addvti3.c | 1 - lib/arm/Makefile.mk | 1 + lib/arm/adddf3vfp.S | 9 +- lib/arm/addsf3vfp.S | 9 +- lib/arm/divdf3vfp.S | 9 +- lib/arm/divsf3vfp.S | 9 +- lib/arm/eqdf2vfp.S | 9 +- lib/arm/eqsf2vfp.S | 9 +- lib/arm/extendsfdf2vfp.S | 7 +- lib/arm/fixdfsivfp.S | 7 +- lib/arm/fixsfsivfp.S | 7 +- lib/arm/fixunsdfsivfp.S | 7 +- lib/arm/fixunssfsivfp.S | 7 +- lib/arm/floatsidfvfp.S | 7 +- lib/arm/floatsisfvfp.S | 7 +- lib/arm/floatunssidfvfp.S | 7 +- lib/arm/floatunssisfvfp.S | 7 +- lib/arm/gedf2vfp.S | 9 +- lib/arm/gesf2vfp.S | 9 +- lib/arm/gtdf2vfp.S | 9 +- lib/arm/gtsf2vfp.S | 9 +- lib/arm/ledf2vfp.S | 9 +- lib/arm/lesf2vfp.S | 9 +- lib/arm/ltdf2vfp.S | 9 +- lib/arm/ltsf2vfp.S | 9 +- lib/arm/muldf3vfp.S | 9 +- lib/arm/mulsf3vfp.S | 9 +- lib/arm/nedf2vfp.S | 9 +- lib/arm/negdf2vfp.S | 1 + lib/arm/negsf2vfp.S | 1 + lib/arm/nesf2vfp.S | 9 +- lib/arm/subdf3vfp.S | 9 +- lib/arm/subsf3vfp.S | 9 +- lib/arm/truncdfsf2vfp.S | 7 +- lib/arm/unorddf2vfp.S | 9 +- lib/arm/unordsf2vfp.S | 9 +- lib/asan/Makefile.mk | 22 + lib/asan/Makefile.old | 352 +++++ lib/asan/README.txt | 26 + lib/asan/asan_allocator.cc | 1020 ++++++++++++ lib/asan/asan_allocator.h | 157 ++ lib/asan/asan_globals.cc | 171 ++ lib/asan/asan_interceptors.cc | 391 +++++ lib/asan/asan_interceptors.h | 134 ++ lib/asan/asan_interface.h | 135 ++ lib/asan/asan_internal.h | 239 +++ lib/asan/asan_linux.cc | 101 ++ lib/asan/asan_lock.h | 100 ++ lib/asan/asan_mac.cc | 311 ++++ lib/asan/asan_mac.h | 87 + lib/asan/asan_malloc_linux.cc | 142 ++ lib/asan/asan_malloc_mac.cc | 390 +++++ lib/asan/asan_mapping.h | 100 ++ lib/asan/asan_poisoning.cc | 159 ++ lib/asan/asan_printf.cc | 181 +++ lib/asan/asan_rtl.cc | 810 ++++++++++ lib/asan/asan_stack.cc | 280 ++++ lib/asan/asan_stack.h | 94 ++ lib/asan/asan_stats.cc | 88 ++ lib/asan/asan_stats.h | 59 + lib/asan/asan_thread.cc | 178 +++ lib/asan/asan_thread.h | 108 ++ lib/asan/asan_thread_registry.cc | 227 +++ lib/asan/asan_thread_registry.h | 88 ++ lib/asan/mach_override/LICENSE.TXT | 3 + lib/asan/mach_override/Makefile.mk | 22 + lib/asan/mach_override/README.txt | 9 + lib/asan/mach_override/mach_override.c | 862 ++++++++++ lib/asan/mach_override/mach_override.h | 127 ++ lib/asan/scripts/asan_symbolize.py | 101 ++ lib/asan/sysinfo/LICENSE.TXT | 29 + lib/asan/sysinfo/Makefile.mk | 22 + lib/asan/sysinfo/basictypes.h | 321 ++++ lib/asan/sysinfo/sysinfo.cc | 617 ++++++++ lib/asan/sysinfo/sysinfo.h | 234 +++ lib/asan/tests/asan_benchmarks_test.cc | 86 + lib/asan/tests/asan_break_optimization.cc | 18 + lib/asan/tests/asan_exceptions_test.cc | 27 + lib/asan/tests/asan_globals_test.cc | 24 + lib/asan/tests/asan_interface_test.cc | 334 ++++ lib/asan/tests/asan_mac_test.h | 16 + lib/asan/tests/asan_mac_test.mm | 203 +++ lib/asan/tests/asan_noinst_test.cc | 329 ++++ lib/asan/tests/asan_test.cc | 2022 ++++++++++++++++++++++++ lib/asan/tests/asan_test.ignore | 2 + lib/asan/tests/asan_test_config.h | 44 + lib/asan/tests/asan_test_utils.h | 30 + lib/asan/tests/dlclose-test-so.cc | 33 + lib/asan/tests/dlclose-test.cc | 73 + lib/asan/tests/dlclose-test.tmpl | 1 + lib/asan/tests/global-overflow.cc | 12 + lib/asan/tests/global-overflow.tmpl | 3 + lib/asan/tests/heap-overflow.cc | 9 + lib/asan/tests/heap-overflow.tmpl | 6 + lib/asan/tests/heap-overflow.tmpl.Darwin | 8 + lib/asan/tests/large_func_test.cc | 33 + lib/asan/tests/large_func_test.tmpl | 8 + lib/asan/tests/match_output.py | 35 + lib/asan/tests/null_deref.cc | 7 + lib/asan/tests/null_deref.tmpl | 4 + lib/asan/tests/shared-lib-test-so.cc | 21 + lib/asan/tests/shared-lib-test.cc | 37 + lib/asan/tests/shared-lib-test.tmpl | 7 + lib/asan/tests/stack-overflow.cc | 7 + lib/asan/tests/stack-overflow.tmpl | 3 + lib/asan/tests/stack-use-after-return.cc | 24 + lib/asan/tests/stack-use-after-return.disabled | 3 + lib/asan/tests/strncpy-overflow.cc | 9 + lib/asan/tests/strncpy-overflow.tmpl | 7 + lib/asan/tests/test_output.sh | 47 + lib/asan/tests/use-after-free.c | 6 + lib/asan/tests/use-after-free.cc | 6 + lib/asan/tests/use-after-free.tmpl | 10 + lib/ashldi3.c | 1 - lib/ashrdi3.c | 1 - lib/assembly.h | 11 +- lib/clear_cache.c | 2 - lib/clzdi2.c | 1 - lib/clzsi2.c | 1 - lib/cmpdi2.c | 1 - lib/ctzdi2.c | 1 - lib/ctzsi2.c | 1 - lib/divdc3.c | 41 +- lib/divdf3.c | 1 - lib/divdi3.c | 1 - lib/divmoddi4.c | 1 - lib/divmodsi4.c | 1 - lib/divsc3.c | 41 +- lib/divsf3.c | 1 - lib/divsi3.c | 1 - lib/divxc3.c | 41 +- lib/enable_execute_stack.c | 3 +- lib/endianness.h | 94 -- lib/eprintf.c | 1 - lib/extendsfdf2.c | 5 +- lib/ffsdi2.c | 1 - lib/fixdfdi.c | 1 - lib/fixdfsi.c | 1 - lib/fixsfdi.c | 1 - lib/fixsfsi.c | 1 - lib/fixunsdfdi.c | 1 - lib/fixunsdfsi.c | 1 - lib/fixunssfdi.c | 1 - lib/fixunssfsi.c | 1 - lib/floatdidf.c | 3 - lib/floatdisf.c | 3 - lib/floatsidf.c | 1 - lib/floatsisf.c | 1 - lib/floattidf.c | 1 - lib/floattisf.c | 1 - lib/floattixf.c | 1 - lib/floatundidf.c | 4 - lib/floatundisf.c | 3 - lib/floatunsidf.c | 1 - lib/floatunsisf.c | 1 - lib/floatuntidf.c | 1 - lib/floatuntisf.c | 1 - lib/floatuntixf.c | 1 - lib/fp_lib.h | 1 + lib/gcc_personality_v0.c | 6 +- lib/i386/Makefile.mk | 1 + lib/int_endianness.h | 89 ++ lib/int_lib.h | 148 +- lib/int_math.h | 67 + lib/int_types.h | 140 ++ lib/int_util.c | 43 + lib/int_util.h | 32 + lib/lshrdi3.c | 1 - lib/moddi3.c | 1 - lib/modsi3.c | 1 - lib/muldc3.c | 57 +- lib/muldf3.c | 1 - lib/muldi3.c | 1 - lib/mulodi4.c | 58 + lib/mulosi4.c | 58 + lib/muloti4.c | 62 + lib/mulsc3.c | 57 +- lib/mulsf3.c | 1 - lib/mulvdi3.c | 1 - lib/mulvsi3.c | 1 - lib/mulvti3.c | 1 - lib/mulxc3.c | 57 +- lib/negdf2.c | 1 - lib/negsf2.c | 1 - lib/negvdi2.c | 2 - lib/negvsi2.c | 2 - lib/negvti2.c | 1 - lib/paritydi2.c | 1 - lib/paritysi2.c | 1 - lib/popcountdi2.c | 1 - lib/popcountsi2.c | 1 - lib/powidf2.c | 1 - lib/powisf2.c | 1 - lib/ppc/DD.h | 2 +- lib/ppc/Makefile.mk | 1 + lib/ppc/divtc3.c | 59 +- lib/ppc/fixtfdi.c | 4 +- lib/ppc/fixunstfdi.c | 1 - lib/ppc/floatditf.c | 1 - lib/ppc/floatunditf.c | 1 - lib/ppc/multc3.c | 39 +- lib/profile/GCDAProfiling.c | 200 +++ lib/profile/Makefile.mk | 18 + lib/subdf3.c | 1 - lib/subsf3.c | 1 - lib/subvdi3.c | 2 - lib/subvsi3.c | 2 - lib/subvti3.c | 1 - lib/trampoline_setup.c | 3 - lib/truncdfsf2.c | 6 +- lib/ucmpdi2.c | 1 - lib/udivdi3.c | 1 - lib/udivmoddi4.c | 3 +- lib/udivmodsi4.c | 1 - lib/udivmodti4.c | 2 +- lib/udivsi3.c | 1 - lib/umoddi3.c | 1 - lib/umodsi3.c | 1 - lib/x86_64/Makefile.mk | 1 + lib/x86_64/floatdidf.c | 2 +- lib/x86_64/floatdisf.c | 2 +- lib/x86_64/floatdixf.c | 2 +- 231 files changed, 13219 insertions(+), 693 deletions(-) delete mode 100644 lib/abi.h create mode 100644 lib/asan/Makefile.mk create mode 100644 lib/asan/Makefile.old create mode 100644 lib/asan/README.txt create mode 100644 lib/asan/asan_allocator.cc create mode 100644 lib/asan/asan_allocator.h create mode 100644 lib/asan/asan_globals.cc create mode 100644 lib/asan/asan_interceptors.cc create mode 100644 lib/asan/asan_interceptors.h create mode 100644 lib/asan/asan_interface.h create mode 100644 lib/asan/asan_internal.h create mode 100644 lib/asan/asan_linux.cc create mode 100644 lib/asan/asan_lock.h create mode 100644 lib/asan/asan_mac.cc create mode 100644 lib/asan/asan_mac.h create mode 100644 lib/asan/asan_malloc_linux.cc create mode 100644 lib/asan/asan_malloc_mac.cc create mode 100644 lib/asan/asan_mapping.h create mode 100644 lib/asan/asan_poisoning.cc create mode 100644 lib/asan/asan_printf.cc create mode 100644 lib/asan/asan_rtl.cc create mode 100644 lib/asan/asan_stack.cc create mode 100644 lib/asan/asan_stack.h create mode 100644 lib/asan/asan_stats.cc create mode 100644 lib/asan/asan_stats.h create mode 100644 lib/asan/asan_thread.cc create mode 100644 lib/asan/asan_thread.h create mode 100644 lib/asan/asan_thread_registry.cc create mode 100644 lib/asan/asan_thread_registry.h create mode 100644 lib/asan/mach_override/LICENSE.TXT create mode 100644 lib/asan/mach_override/Makefile.mk create mode 100644 lib/asan/mach_override/README.txt create mode 100644 lib/asan/mach_override/mach_override.c create mode 100644 lib/asan/mach_override/mach_override.h create mode 100755 lib/asan/scripts/asan_symbolize.py create mode 100644 lib/asan/sysinfo/LICENSE.TXT create mode 100644 lib/asan/sysinfo/Makefile.mk create mode 100644 lib/asan/sysinfo/basictypes.h create mode 100644 lib/asan/sysinfo/sysinfo.cc create mode 100644 lib/asan/sysinfo/sysinfo.h create mode 100644 lib/asan/tests/asan_benchmarks_test.cc create mode 100644 lib/asan/tests/asan_break_optimization.cc create mode 100644 lib/asan/tests/asan_exceptions_test.cc create mode 100644 lib/asan/tests/asan_globals_test.cc create mode 100644 lib/asan/tests/asan_interface_test.cc create mode 100644 lib/asan/tests/asan_mac_test.h create mode 100644 lib/asan/tests/asan_mac_test.mm create mode 100644 lib/asan/tests/asan_noinst_test.cc create mode 100644 lib/asan/tests/asan_test.cc create mode 100644 lib/asan/tests/asan_test.ignore create mode 100644 lib/asan/tests/asan_test_config.h create mode 100644 lib/asan/tests/asan_test_utils.h create mode 100644 lib/asan/tests/dlclose-test-so.cc create mode 100644 lib/asan/tests/dlclose-test.cc create mode 100644 lib/asan/tests/dlclose-test.tmpl create mode 100644 lib/asan/tests/global-overflow.cc create mode 100644 lib/asan/tests/global-overflow.tmpl create mode 100644 lib/asan/tests/heap-overflow.cc create mode 100644 lib/asan/tests/heap-overflow.tmpl create mode 100644 lib/asan/tests/heap-overflow.tmpl.Darwin create mode 100644 lib/asan/tests/large_func_test.cc create mode 100644 lib/asan/tests/large_func_test.tmpl create mode 100755 lib/asan/tests/match_output.py create mode 100644 lib/asan/tests/null_deref.cc create mode 100644 lib/asan/tests/null_deref.tmpl create mode 100644 lib/asan/tests/shared-lib-test-so.cc create mode 100644 lib/asan/tests/shared-lib-test.cc create mode 100644 lib/asan/tests/shared-lib-test.tmpl create mode 100644 lib/asan/tests/stack-overflow.cc create mode 100644 lib/asan/tests/stack-overflow.tmpl create mode 100644 lib/asan/tests/stack-use-after-return.cc create mode 100644 lib/asan/tests/stack-use-after-return.disabled create mode 100644 lib/asan/tests/strncpy-overflow.cc create mode 100644 lib/asan/tests/strncpy-overflow.tmpl create mode 100755 lib/asan/tests/test_output.sh create mode 100644 lib/asan/tests/use-after-free.c create mode 100644 lib/asan/tests/use-after-free.cc create mode 100644 lib/asan/tests/use-after-free.tmpl delete mode 100644 lib/endianness.h create mode 100644 lib/int_endianness.h create mode 100644 lib/int_math.h create mode 100644 lib/int_types.h create mode 100644 lib/int_util.c create mode 100644 lib/int_util.h create mode 100644 lib/mulodi4.c create mode 100644 lib/mulosi4.c create mode 100644 lib/muloti4.c create mode 100644 lib/profile/GCDAProfiling.c create mode 100644 lib/profile/Makefile.mk (limited to 'lib') diff --git a/lib/Makefile.mk b/lib/Makefile.mk index 1ed8c11..8394af3 100644 --- a/lib/Makefile.mk +++ b/lib/Makefile.mk @@ -7,8 +7,17 @@ # #===------------------------------------------------------------------------===# -SubDirs := i386 ppc x86_64 arm +ModuleName := builtins +SubDirs := +# Add arch specific optimized implementations. +SubDirs += i386 ppc x86_64 arm + +# Add other submodules. +SubDirs += asan +SubDirs += profile + +# Define the variables for this specific directory. Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file))) ObjNames := $(Sources:%.c=%.o) Implementation := Generic diff --git a/lib/abi.h b/lib/abi.h deleted file mode 100644 index 2534317..0000000 --- a/lib/abi.h +++ /dev/null @@ -1,23 +0,0 @@ -/* ===------ abi.h - configuration header for compiler-rt -----------------=== - * - * The LLVM Compiler Infrastructure - * - * This file is dual licensed under the MIT and the University of Illinois Open - * Source Licenses. See LICENSE.TXT for details. - * - * ===----------------------------------------------------------------------=== - * - * This file is a configuration header for compiler-rt. - * This file is not part of the interface of this library. - * - * ===----------------------------------------------------------------------=== - */ - -#if __ARM_EABI__ -# define ARM_EABI_FNALIAS(aeabi_name, name) \ - void __aeabi_##aeabi_name() __attribute__((alias("__" #name))); -# define COMPILER_RT_ABI __attribute__((pcs("aapcs"))) -#else -# define ARM_EABI_FNALIAS(aeabi_name, name) -# define COMPILER_RT_ABI -#endif diff --git a/lib/absvdi2.c b/lib/absvdi2.c index 9c5d4a2..682c235 100644 --- a/lib/absvdi2.c +++ b/lib/absvdi2.c @@ -11,10 +11,8 @@ * *===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: absolute value */ diff --git a/lib/absvsi2.c b/lib/absvsi2.c index 80a1a78..4812af8 100644 --- a/lib/absvsi2.c +++ b/lib/absvsi2.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: absolute value */ diff --git a/lib/absvti2.c b/lib/absvti2.c index 9e73a26..8f2bddc 100644 --- a/lib/absvti2.c +++ b/lib/absvti2.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: absolute value */ diff --git a/lib/adddf3.c b/lib/adddf3.c index 3cc997b..7eb40a1 100644 --- a/lib/adddf3.c +++ b/lib/adddf3.c @@ -12,8 +12,6 @@ // //===----------------------------------------------------------------------===// -#include "abi.h" - #define DOUBLE_PRECISION #include "fp_lib.h" diff --git a/lib/addsf3.c b/lib/addsf3.c index 20610ef..e57270a 100644 --- a/lib/addsf3.c +++ b/lib/addsf3.c @@ -12,8 +12,6 @@ // //===----------------------------------------------------------------------===// -#include "abi.h" - #define SINGLE_PRECISION #include "fp_lib.h" diff --git a/lib/addvdi3.c b/lib/addvdi3.c index 51ad397..db45a27 100644 --- a/lib/addvdi3.c +++ b/lib/addvdi3.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: a + b */ diff --git a/lib/addvsi3.c b/lib/addvsi3.c index c18f7bd..81f515c 100644 --- a/lib/addvsi3.c +++ b/lib/addvsi3.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: a + b */ diff --git a/lib/addvti3.c b/lib/addvti3.c index ba220f5..9105c17 100644 --- a/lib/addvti3.c +++ b/lib/addvti3.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: a + b */ diff --git a/lib/arm/Makefile.mk b/lib/arm/Makefile.mk index cde97c3..e7bbd7b 100644 --- a/lib/arm/Makefile.mk +++ b/lib/arm/Makefile.mk @@ -7,6 +7,7 @@ # #===------------------------------------------------------------------------===# +ModuleName := builtins SubDirs := OnlyArchs := armv5 armv6 armv7 diff --git a/lib/arm/adddf3vfp.S b/lib/arm/adddf3vfp.S index cced1e0..c90b0c2 100644 --- a/lib/arm/adddf3vfp.S +++ b/lib/arm/adddf3vfp.S @@ -15,10 +15,11 @@ // Adds two double precision floating point numbers using the Darwin // calling convention where double arguments are passsed in GPR pairs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__adddf3vfp) - fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6 - fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7 - faddd d6, d6, d7 - fmrrd r0, r1, d6 // move result back to r0/r1 pair + vmov d6, r0, r1 // move first param from r0/r1 pair into d6 + vmov d7, r2, r3 // move second param from r2/r3 pair into d7 + vadd.f64 d6, d6, d7 + vmov r0, r1, d6 // move result back to r0/r1 pair bx lr diff --git a/lib/arm/addsf3vfp.S b/lib/arm/addsf3vfp.S index b747528..43653d5 100644 --- a/lib/arm/addsf3vfp.S +++ b/lib/arm/addsf3vfp.S @@ -15,10 +15,11 @@ // Adds two single precision floating point numbers using the Darwin // calling convention where single arguments are passsed in GPRs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__addsf3vfp) - fmsr s14, r0 // move first param from r0 into float register - fmsr s15, r1 // move second param from r1 into float register - fadds s14, s14, s15 - fmrs r0, s14 // move result back to r0 + vmov s14, r0 // move first param from r0 into float register + vmov s15, r1 // move second param from r1 into float register + vadd.f32 s14, s14, s15 + vmov r0, s14 // move result back to r0 bx lr diff --git a/lib/arm/divdf3vfp.S b/lib/arm/divdf3vfp.S index 74ef0ea..52de67f 100644 --- a/lib/arm/divdf3vfp.S +++ b/lib/arm/divdf3vfp.S @@ -15,10 +15,11 @@ // Divides two double precision floating point numbers using the Darwin // calling convention where double arguments are passsed in GPR pairs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__divdf3vfp) - fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6 - fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7 - fdivd d5, d6, d7 - fmrrd r0, r1, d5 // move result back to r0/r1 pair + vmov d6, r0, r1 // move first param from r0/r1 pair into d6 + vmov d7, r2, r3 // move second param from r2/r3 pair into d7 + vdiv.f64 d5, d6, d7 + vmov r0, r1, d5 // move result back to r0/r1 pair bx lr diff --git a/lib/arm/divsf3vfp.S b/lib/arm/divsf3vfp.S index 9eefcf31e..81ba903 100644 --- a/lib/arm/divsf3vfp.S +++ b/lib/arm/divsf3vfp.S @@ -15,10 +15,11 @@ // Divides two single precision floating point numbers using the Darwin // calling convention where single arguments are passsed like 32-bit ints. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__divsf3vfp) - fmsr s14, r0 // move first param from r0 into float register - fmsr s15, r1 // move second param from r1 into float register - fdivs s13, s14, s15 - fmrs r0, s13 // move result back to r0 + vmov s14, r0 // move first param from r0 into float register + vmov s15, r1 // move second param from r1 into float register + vdiv.f32 s13, s14, s15 + vmov r0, s13 // move result back to r0 bx lr diff --git a/lib/arm/eqdf2vfp.S b/lib/arm/eqdf2vfp.S index 2998a76..c41e55a 100644 --- a/lib/arm/eqdf2vfp.S +++ b/lib/arm/eqdf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__eqdf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr moveq r0, #1 // set result register to 1 if equal movne r0, #0 bx lr diff --git a/lib/arm/eqsf2vfp.S b/lib/arm/eqsf2vfp.S index 927566e..730ef88 100644 --- a/lib/arm/eqsf2vfp.S +++ b/lib/arm/eqsf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__eqsf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr moveq r0, #1 // set result register to 1 if equal movne r0, #0 bx lr diff --git a/lib/arm/extendsfdf2vfp.S b/lib/arm/extendsfdf2vfp.S index b1aa88e..17a146e 100644 --- a/lib/arm/extendsfdf2vfp.S +++ b/lib/arm/extendsfdf2vfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a single precision parameter is // passed in a GPR and a double precision result is returned in R0/R1 pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__extendsfdf2vfp) - fmsr s15, r0 // load float register from R0 - fcvtds d7, s15 // convert single to double - fmrrd r0, r1, d7 // return result in r0/r1 pair + vmov s15, r0 // load float register from R0 + vcvt.f64.f32 d7, s15 // convert single to double + vmov r0, r1, d7 // return result in r0/r1 pair bx lr diff --git a/lib/arm/fixdfsivfp.S b/lib/arm/fixdfsivfp.S index 0285a17..b7c3299 100644 --- a/lib/arm/fixdfsivfp.S +++ b/lib/arm/fixdfsivfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a double precision parameter is // passed in GPR register pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__fixdfsivfp) - fmdrr d7, r0, r1 // load double register from R0/R1 - ftosizd s15, d7 // convert double to 32-bit int into s15 - fmrs r0, s15 // move s15 to result register + vmov d7, r0, r1 // load double register from R0/R1 + vcvt.s32.f64 s15, d7 // convert double to 32-bit int into s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/lib/arm/fixsfsivfp.S b/lib/arm/fixsfsivfp.S index d05ba74..1cea6a4 100644 --- a/lib/arm/fixsfsivfp.S +++ b/lib/arm/fixsfsivfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a single precision parameter is // passed in a GPR.. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__fixsfsivfp) - fmsr s15, r0 // load float register from R0 - ftosizs s15, s15 // convert single to 32-bit int into s15 - fmrs r0, s15 // move s15 to result register + vmov s15, r0 // load float register from R0 + vcvt.s32.f32 s15, s15 // convert single to 32-bit int into s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/lib/arm/fixunsdfsivfp.S b/lib/arm/fixunsdfsivfp.S index ddb703c..54b0359 100644 --- a/lib/arm/fixunsdfsivfp.S +++ b/lib/arm/fixunsdfsivfp.S @@ -17,9 +17,10 @@ // Uses Darwin calling convention where a double precision parameter is // passed in GPR register pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__fixunsdfsivfp) - fmdrr d7, r0, r1 // load double register from R0/R1 - ftouizd s15, d7 // convert double to 32-bit int into s15 - fmrs r0, s15 // move s15 to result register + vmov d7, r0, r1 // load double register from R0/R1 + vcvt.u32.f64 s15, d7 // convert double to 32-bit int into s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/lib/arm/fixunssfsivfp.S b/lib/arm/fixunssfsivfp.S index afbb64f..12adb52 100644 --- a/lib/arm/fixunssfsivfp.S +++ b/lib/arm/fixunssfsivfp.S @@ -17,9 +17,10 @@ // Uses Darwin calling convention where a single precision parameter is // passed in a GPR.. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__fixunssfsivfp) - fmsr s15, r0 // load float register from R0 - ftouizs s15, s15 // convert single to 32-bit unsigned into s15 - fmrs r0, s15 // move s15 to result register + vmov s15, r0 // load float register from R0 + vcvt.u32.f32 s15, s15 // convert single to 32-bit unsigned into s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/lib/arm/floatsidfvfp.S b/lib/arm/floatsidfvfp.S index fe3366a..e6a1eb3 100644 --- a/lib/arm/floatsidfvfp.S +++ b/lib/arm/floatsidfvfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a double precision result is // return in GPR register pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__floatsidfvfp) - fmsr s15, r0 // move int to float register s15 - fsitod d7, s15 // convert 32-bit int in s15 to double in d7 - fmrrd r0, r1, d7 // move d7 to result register pair r0/r1 + vmov s15, r0 // move int to float register s15 + vcvt.f64.s32 d7, s15 // convert 32-bit int in s15 to double in d7 + vmov r0, r1, d7 // move d7 to result register pair r0/r1 bx lr diff --git a/lib/arm/floatsisfvfp.S b/lib/arm/floatsisfvfp.S index 5b41610..0d3a24f 100644 --- a/lib/arm/floatsisfvfp.S +++ b/lib/arm/floatsisfvfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a single precision result is // return in a GPR.. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__floatsisfvfp) - fmsr s15, r0 // move int to float register s15 - fsitos s15, s15 // convert 32-bit int in s15 to float in s15 - fmrs r0, s15 // move s15 to result register + vmov s15, r0 // move int to float register s15 + vcvt.f32.s32 s15, s15 // convert 32-bit int in s15 to float in s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/lib/arm/floatunssidfvfp.S b/lib/arm/floatunssidfvfp.S index 9b22a6f..770b202 100644 --- a/lib/arm/floatunssidfvfp.S +++ b/lib/arm/floatunssidfvfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a double precision result is // return in GPR register pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__floatunssidfvfp) - fmsr s15, r0 // move int to float register s15 - fuitod d7, s15 // convert 32-bit int in s15 to double in d7 - fmrrd r0, r1, d7 // move d7 to result register pair r0/r1 + vmov s15, r0 // move int to float register s15 + vcvt.f64.u32 d7, s15 // convert 32-bit int in s15 to double in d7 + vmov r0, r1, d7 // move d7 to result register pair r0/r1 bx lr diff --git a/lib/arm/floatunssisfvfp.S b/lib/arm/floatunssisfvfp.S index 44d5e93..16b3ffb 100644 --- a/lib/arm/floatunssisfvfp.S +++ b/lib/arm/floatunssisfvfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a single precision result is // return in a GPR.. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__floatunssisfvfp) - fmsr s15, r0 // move int to float register s15 - fuitos s15, s15 // convert 32-bit int in s15 to float in s15 - fmrs r0, s15 // move s15 to result register + vmov s15, r0 // move int to float register s15 + vcvt.f32.u32 s15, s15 // convert 32-bit int in s15 to float in s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/lib/arm/gedf2vfp.S b/lib/arm/gedf2vfp.S index 9993f52..55603b8 100644 --- a/lib/arm/gedf2vfp.S +++ b/lib/arm/gedf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__gedf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movge r0, #1 // set result register to 1 if greater than or equal movlt r0, #0 bx lr diff --git a/lib/arm/gesf2vfp.S b/lib/arm/gesf2vfp.S index 9ce1682..02da35c 100644 --- a/lib/arm/gesf2vfp.S +++ b/lib/arm/gesf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__gesf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movge r0, #1 // set result register to 1 if greater than or equal movlt r0, #0 bx lr diff --git a/lib/arm/gtdf2vfp.S b/lib/arm/gtdf2vfp.S index 8a049c8..b5b1e14 100644 --- a/lib/arm/gtdf2vfp.S +++ b/lib/arm/gtdf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__gtdf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movgt r0, #1 // set result register to 1 if equal movle r0, #0 bx lr diff --git a/lib/arm/gtsf2vfp.S b/lib/arm/gtsf2vfp.S index 1ffe1ec..685a9ce 100644 --- a/lib/arm/gtsf2vfp.S +++ b/lib/arm/gtsf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__gtsf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movgt r0, #1 // set result register to 1 if equal movle r0, #0 bx lr diff --git a/lib/arm/ledf2vfp.S b/lib/arm/ledf2vfp.S index a04d0f2..6e140dd 100644 --- a/lib/arm/ledf2vfp.S +++ b/lib/arm/ledf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__ledf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movls r0, #1 // set result register to 1 if equal movhi r0, #0 bx lr diff --git a/lib/arm/lesf2vfp.S b/lib/arm/lesf2vfp.S index 3011200..7b28250 100644 --- a/lib/arm/lesf2vfp.S +++ b/lib/arm/lesf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__lesf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movls r0, #1 // set result register to 1 if equal movhi r0, #0 bx lr diff --git a/lib/arm/ltdf2vfp.S b/lib/arm/ltdf2vfp.S index 87144a8..a09e67a 100644 --- a/lib/arm/ltdf2vfp.S +++ b/lib/arm/ltdf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__ltdf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movmi r0, #1 // set result register to 1 if equal movpl r0, #0 bx lr diff --git a/lib/arm/ltsf2vfp.S b/lib/arm/ltsf2vfp.S index ca06ae2..8c7f9a8 100644 --- a/lib/arm/ltsf2vfp.S +++ b/lib/arm/ltsf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__ltsf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movmi r0, #1 // set result register to 1 if equal movpl r0, #0 bx lr diff --git a/lib/arm/muldf3vfp.S b/lib/arm/muldf3vfp.S index 96bba06..838581e 100644 --- a/lib/arm/muldf3vfp.S +++ b/lib/arm/muldf3vfp.S @@ -15,10 +15,11 @@ // Multiplies two double precision floating point numbers using the Darwin // calling convention where double arguments are passsed in GPR pairs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__muldf3vfp) - fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6 - fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7 - fmuld d6, d6, d7 - fmrrd r0, r1, d6 // move result back to r0/r1 pair + vmov d6, r0, r1 // move first param from r0/r1 pair into d6 + vmov d7, r2, r3 // move second param from r2/r3 pair into d7 + vmul.f64 d6, d6, d7 + vmov r0, r1, d6 // move result back to r0/r1 pair bx lr diff --git a/lib/arm/mulsf3vfp.S b/lib/arm/mulsf3vfp.S index c56991d..ea25913 100644 --- a/lib/arm/mulsf3vfp.S +++ b/lib/arm/mulsf3vfp.S @@ -15,10 +15,11 @@ // Multiplies two single precision floating point numbers using the Darwin // calling convention where single arguments are passsed like 32-bit ints. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__mulsf3vfp) - fmsr s14, r0 // move first param from r0 into float register - fmsr s15, r1 // move second param from r1 into float register - fmuls s13, s14, s15 - fmrs r0, s13 // move result back to r0 + vmov s14, r0 // move first param from r0 into float register + vmov s15, r1 // move second param from r1 into float register + vmul.f32 s13, s14, s15 + vmov r0, s13 // move result back to r0 bx lr diff --git a/lib/arm/nedf2vfp.S b/lib/arm/nedf2vfp.S index a02b09c..2167081 100644 --- a/lib/arm/nedf2vfp.S +++ b/lib/arm/nedf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__nedf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movne r0, #1 // set result register to 0 if unequal moveq r0, #0 bx lr diff --git a/lib/arm/negdf2vfp.S b/lib/arm/negdf2vfp.S index 100f4fd..64c9b69 100644 --- a/lib/arm/negdf2vfp.S +++ b/lib/arm/negdf2vfp.S @@ -15,6 +15,7 @@ // Returns the negation a double precision floating point numbers using the // Darwin calling convention where double arguments are passsed in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__negdf2vfp) eor r1, r1, #-2147483648 // flip sign bit on double in r0/r1 pair diff --git a/lib/arm/negsf2vfp.S b/lib/arm/negsf2vfp.S index f96c8ad..b883b73 100644 --- a/lib/arm/negsf2vfp.S +++ b/lib/arm/negsf2vfp.S @@ -15,6 +15,7 @@ // Returns the negation of a single precision floating point numbers using the // Darwin calling convention where single arguments are passsed like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__negsf2vfp) eor r0, r0, #-2147483648 // flip sign bit on float in r0 diff --git a/lib/arm/nesf2vfp.S b/lib/arm/nesf2vfp.S index d620549..fa7aa80 100644 --- a/lib/arm/nesf2vfp.S +++ b/lib/arm/nesf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__nesf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movne r0, #1 // set result register to 1 if unequal moveq r0, #0 bx lr diff --git a/lib/arm/subdf3vfp.S b/lib/arm/subdf3vfp.S index ff53b30..3f88baa 100644 --- a/lib/arm/subdf3vfp.S +++ b/lib/arm/subdf3vfp.S @@ -15,10 +15,11 @@ // Returns difference between two double precision floating point numbers using // the Darwin calling convention where double arguments are passsed in GPR pairs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__subdf3vfp) - fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6 - fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7 - fsubd d6, d6, d7 - fmrrd r0, r1, d6 // move result back to r0/r1 pair + vmov d6, r0, r1 // move first param from r0/r1 pair into d6 + vmov d7, r2, r3 // move second param from r2/r3 pair into d7 + vsub.f64 d6, d6, d7 + vmov r0, r1, d6 // move result back to r0/r1 pair bx lr diff --git a/lib/arm/subsf3vfp.S b/lib/arm/subsf3vfp.S index 238f3f0..ed02ba9 100644 --- a/lib/arm/subsf3vfp.S +++ b/lib/arm/subsf3vfp.S @@ -16,10 +16,11 @@ // using the Darwin calling convention where single arguments are passsed // like 32-bit ints. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__subsf3vfp) - fmsr s14, r0 // move first param from r0 into float register - fmsr s15, r1 // move second param from r1 into float register - fsubs s14, s14, s15 - fmrs r0, s14 // move result back to r0 + vmov s14, r0 // move first param from r0 into float register + vmov s15, r1 // move second param from r1 into float register + vsub.f32 s14, s14, s15 + vmov r0, s14 // move result back to r0 bx lr diff --git a/lib/arm/truncdfsf2vfp.S b/lib/arm/truncdfsf2vfp.S index 6e55c7f..371aee94 100644 --- a/lib/arm/truncdfsf2vfp.S +++ b/lib/arm/truncdfsf2vfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a double precision parameter is // passed in a R0/R1 pair and a signle precision result is returned in R0. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__truncdfsf2vfp) - fmdrr d7, r0, r1 // load double from r0/r1 pair - fcvtsd s15, d7 // convert double to single (trucate precision) - fmrs r0, s15 // return result in r0 + vmov d7, r0, r1 // load double from r0/r1 pair + vcvt.f32.f64 s15, d7 // convert double to single (trucate precision) + vmov r0, s15 // return result in r0 bx lr diff --git a/lib/arm/unorddf2vfp.S b/lib/arm/unorddf2vfp.S index 9b52131..c49e55f 100644 --- a/lib/arm/unorddf2vfp.S +++ b/lib/arm/unorddf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__unorddf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movvs r0, #1 // set result register to 1 if "overflow" (any NaNs) movvc r0, #0 bx lr diff --git a/lib/arm/unordsf2vfp.S b/lib/arm/unordsf2vfp.S index e486533..0ab27ed 100644 --- a/lib/arm/unordsf2vfp.S +++ b/lib/arm/unordsf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__unordsf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movvs r0, #1 // set result register to 1 if "overflow" (any NaNs) movvc r0, #0 bx lr diff --git a/lib/asan/Makefile.mk b/lib/asan/Makefile.mk new file mode 100644 index 0000000..4d9e58d --- /dev/null +++ b/lib/asan/Makefile.mk @@ -0,0 +1,22 @@ +#===- lib/asan/Makefile.mk ---------------------------------*- Makefile -*--===# +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# + +ModuleName := asan +SubDirs := mach_override sysinfo + +Sources := $(foreach file,$(wildcard $(Dir)/*.cc),$(notdir $(file))) +ObjNames := $(Sources:%.cc=%.o) + +Implementation := Generic + +# FIXME: use automatic dependencies? +Dependencies := $(wildcard $(Dir)/*.h) + +# Define a convenience variable for all the asan functions. +AsanFunctions := $(Sources:%.cc=%) diff --git a/lib/asan/Makefile.old b/lib/asan/Makefile.old new file mode 100644 index 0000000..a96ff42 --- /dev/null +++ b/lib/asan/Makefile.old @@ -0,0 +1,352 @@ +#===- lib/asan/Makefile.old --------------------------------*- Makefile -*--===# +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# + +OS=$(shell uname | tr '[A-Z]' '[a-z]') +ROOT=$(shell pwd) +MAKEFILE=Makefile.old # this file. + +ifeq ($(ARCH), android) + ANDROID_CFLAGS= \ + -DANDROID \ + -D__WORDSIZE=32 \ + -I$(ANDROID_BUILD_TOP)/external/stlport/stlport \ + -I$(ANDROID_BUILD_TOP)/bionic \ + -I$(ANDROID_BUILD_TOP)/bionic/libstdc++/include \ + -I$(ANDROID_BUILD_TOP)/bionic/libc/arch-arm/include \ + -I$(ANDROID_BUILD_TOP)/bionic/libc/include \ + -I$(ANDROID_BUILD_TOP)/bionic/libc/kernel/common \ + -I$(ANDROID_BUILD_TOP)/bionic/libc/kernel/arch-arm \ + -I$(ANDROID_BUILD_TOP)/bionic/libm/include \ + -I$(ANDROID_BUILD_TOP)/bionic/libm/include/arm \ + -I$(ANDROID_BUILD_TOP)/bionic/libthread_db/include \ + -L$(ANDROID_PRODUCT_OUT)/obj/lib + CLANG_FLAGS= \ + -ccc-host-triple arm-linux-androideabi \ + -D__compiler_offsetof=__builtin_offsetof \ + -D__ELF__=1 \ + -ccc-gcc-name arm-linux-androideabi-g++ \ + $(ANDROID_CFLAGS) + CC=$(ANDROID_EABI_TOOLCHAIN)/arm-linux-androideabi-gcc $(ANDROID_CFLAGS) + CXX=$(ANDROID_EABI_TOOLCHAIN)/arm-linux-androideabi-g++ $(ANDROID_CFLAGS) +endif + +ifeq ($(ARCH), arm) + # Example make command line: + # CROSSTOOL=$HOME/x-tools/arm-unknown-linux-gnueabi/ PATH=$CROSSTOOL/bin:$PATH make ARCH=arm asan_test + CLANG_FLAGS= \ + -ccc-host-triple arm-unknown-linux-gnueabi \ + -march=armv7-a -mfloat-abi=softfp -mfp=neon \ + -ccc-gcc-name arm-unknown-linux-gnueabi-g++ \ + -B$(CROSSTOOL)/lib/gcc/arm-unknown-linux-gnueabi/4.4.4 \ + -B$(CROSSTOOL)/arm-unknown-linux-gnueabi/sys-root/usr/lib \ + -I$(CROSSTOOL)/lib/gcc/arm-unknown-linux-gnueabi/4.4.4/include \ + -I$(CROSSTOOL)/arm-unknown-linux-gnueabi/include/c++/4.4.4 \ + -I$(CROSSTOOL)/arm-unknown-linux-gnueabi/include/c++/4.4.4/arm-unknown-linux-gnueabi \ + -I$(CROSSTOOL)/arm-unknown-linux-gnueabi/sys-root/include \ + -I$(CROSSTOOL)/arm-unknown-linux-gnueabi/sys-root/usr/include \ + -L$(CROSSTOOL)/lib/gcc/arm-unknown-linux-gnueabi/4.4.4 \ + -L$(CROSSTOOL)/arm-unknown-linux-gnueabi/sys-root/lib \ + -L$(CROSSTOOL)/arm-unknown-linux-gnueabi/sys-root/usr/lib + CC=$(CROSSTOOL)/bin/arm-unknown-linux-gnueabi-gcc + CXX=$(CROSSTOOL)/bin/arm-unknown-linux-gnueabi-g++ +endif + +CLANG_FLAGS= +CLANG_BUILD=$(ROOT)/../../../../build/Release+Asserts +CLANG_CC=$(CLANG_BUILD)/bin/clang $(CLANG_FLAGS) +CLANG_CXX=$(CLANG_BUILD)/bin/clang++ $(CLANG_FLAGS) + +CC=$(CLANG_CC) +CXX=$(CLANG_CXX) + +CFLAGS:=-Wall -fvisibility=hidden + +CLEANROOM_CXX=$(CXX) -Wall + +INSTALL_DIR=../asan_clang_$(OS) +BIN=bin_$(OS) + +LIBS=#-lpthread -ldl +ARCH=x86_64 + +ASAN_STACK=1 +ASAN_GLOBALS=1 +ASAN_USE_CALL=1 +ASAN_SCALE=0 # default will be used +ASAN_OFFSET=-1 #default will be used +ASAN_UAR=0 +ASAN_HAS_EXCEPTIONS=1 +ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 +ASAN_HAS_BLACKLIST=1 +ASAN_NEEDS_SEGV=1 +ASAN_PIE=0 + +ifeq ($(ARCH), i386) +BITS=32 +SUFF=$(BITS) +CFLAGS:=$(CFLAGS) -m$(BITS) +endif + +ifeq ($(ARCH), x86_64) +BITS=64 +SUFF=$(BITS) +CFLAGS:=$(CFLAGS) -m$(BITS) +endif + +ifeq ($(ARCH), arm) +BITS=32 +SUFF=_arm +CFLAGS:=$(CFLAGS) -march=armv7-a +ASAN_HAS_EXCEPTIONS=0 +endif + +ifeq ($(ARCH), android) +BITS=32 +SUFF=_android +CFLAGS:=$(CFLAGS) +ASAN_HAS_EXCEPTIONS=0 +endif + +PIE= +ifeq ($(ASAN_PIE), 1) + PIE=-fPIE -pie +endif + +# This will build libasan on linux for both x86_64 and i386 in the +# desired location. The Mac library is already build by the clang's make. +# $(CLANG_BUILD)/lib/clang/3.1/lib/$(OS)/libclang_rt.asan-$(ARCH).a +LIBASAN_INST_DIR=$(CLANG_BUILD)/lib/clang/3.1/lib/$(OS) +LIBASAN_A=$(LIBASAN_INST_DIR)/libclang_rt.asan-$(ARCH).a + +BLACKLIST= +ifeq ($(ASAN_HAS_BLACKLIST), 1) + BLACKLIST=-mllvm -asan-blacklist=$(ROOT)/tests/asan_test.ignore +endif + +COMMON_ASAN_DEFINES=\ + -DASAN_UAR=$(ASAN_UAR) \ + -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ + -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ + -DASAN_HAS_BLACKLIST=$(ASAN_HAS_BLACKLIST) + +CLANG_ASAN_CXX=$(CLANG_CXX) \ + -faddress-sanitizer \ + $(BLACKLIST) \ + -mllvm -asan-stack=$(ASAN_STACK) \ + -mllvm -asan-globals=$(ASAN_GLOBALS) \ + -mllvm -asan-use-call=$(ASAN_USE_CALL) \ + -mllvm -asan-mapping-scale=$(ASAN_SCALE) \ + -mllvm -asan-mapping-offset-log=$(ASAN_OFFSET) \ + -mllvm -asan-use-after-return=$(ASAN_UAR) \ + $(COMMON_ASAN_DEFINES) + +CLANG_ASAN_LD=$(CLANG_CXX) -faddress-sanitizer + +GCC_ASAN_PATH=SET_FROM_COMMAND_LINE +GCC_ASAN_CXX=$(GCC_ASAN_PATH)/g++ \ + -faddress-sanitizer \ + $(COMMON_ASAN_DEFINES) + +GCC_ASAN_LD=$(GCC_ASAN_PATH)/g++ -ldl -lpthread + +ASAN_COMPILER=clang + +ifeq ($(ASAN_COMPILER), clang) + ASAN_CXX=$(CLANG_ASAN_CXX) + ASAN_LD=$(CLANG_ASAN_LD) + ASAN_LD_TAIL= +endif + +ifeq ($(ASAN_COMPILER), gcc) + ASAN_CXX=$(GCC_ASAN_CXX) + ASAN_LD=$(GCC_ASAN_LD) + ASAN_LD_TAIL=$(LIBASAN_A) +endif + +RTL_HDR=asan_allocator.h \ + asan_internal.h \ + asan_interceptors.h \ + asan_interface.h \ + asan_lock.h \ + asan_mac.h \ + asan_mapping.h \ + asan_stack.h \ + asan_stats.h \ + asan_thread.h \ + asan_thread_registry.h \ + mach_override/mach_override.h \ + sysinfo/basictypes.h \ + sysinfo/sysinfo.h + +LIBASAN_OBJ=$(BIN)/asan_rtl$(SUFF).o \ + $(BIN)/asan_allocator$(SUFF).o \ + $(BIN)/asan_globals$(SUFF).o \ + $(BIN)/asan_interceptors$(SUFF).o \ + $(BIN)/asan_linux$(SUFF).o \ + $(BIN)/asan_mac$(SUFF).o \ + $(BIN)/asan_malloc_linux$(SUFF).o \ + $(BIN)/asan_malloc_mac$(SUFF).o \ + $(BIN)/asan_poisoning$(SUFF).o \ + $(BIN)/asan_printf$(SUFF).o \ + $(BIN)/asan_stack$(SUFF).o \ + $(BIN)/asan_stats$(SUFF).o \ + $(BIN)/asan_thread$(SUFF).o \ + $(BIN)/asan_thread_registry$(SUFF).o \ + $(BIN)/mach_override/mach_override$(SUFF).o \ + $(BIN)/sysinfo/sysinfo$(SUFF).o + +GTEST_ROOT=third_party/googletest +GTEST_INCLUDE=-I$(GTEST_ROOT)/include +GTEST_MAKE_DIR=$(GTEST_ROOT)/make-$(OS)$(SUFF) +GTEST_LIB=$(GTEST_MAKE_DIR)/gtest-all.o + +all: b64 b32 + +test: t64 t32 output_tests lint + +output_tests: b32 b64 + cd tests && ./test_output.sh $(CLANG_CXX) $(CLANG_CC) + +t64: b64 + $(BIN)/asan_test64 +t32: b32 + $(BIN)/asan_test32 + +b64: | $(BIN) + $(MAKE) -f $(MAKEFILE) ARCH=x86_64 asan_test asan_benchmarks +b32: | $(BIN) + $(MAKE) -f $(MAKEFILE) ARCH=i386 asan_test asan_benchmarks + +lib64: + $(MAKE) $(MAKEFILE) ARCH=x86_64 lib +lib32: + $(MAKE) $(MAKEFILE) ARCH=i386 lib + +$(BIN): + mkdir -p $(BIN) + mkdir -p $(BIN)/sysinfo + mkdir -p $(BIN)/mach_override + +clang: + cd ../ && llvm/rebuild_clang_and_asan.sh > /dev/null + +install: install_clang + +$(INSTALL_DIR): + mkdir -p $(INSTALL_DIR) $(INSTALL_DIR)/bin $(INSTALL_DIR)/lib + +install_clang: | $(INSTALL_DIR) + cp -v $(CLANG_BUILD)/bin/clang $(INSTALL_DIR)/bin + cp -rv $(CLANG_BUILD)/lib/clang $(INSTALL_DIR)/lib + (cd $(INSTALL_DIR)/bin; ln -sf clang clang++) + +#install_lib: | $(INSTALL_DIR) +# cp -v $(CLANG_BUILD)/lib/libasan*.a $(INSTALL_DIR)/lib + +$(BIN)/asan_noinst_test$(SUFF).o: tests/asan_noinst_test.cc $(RTL_HDR) $(MAKEFILE) + $(CLEANROOM_CXX) $(PIE) $(CFLAGS) $(GTEST_INCLUDE) -I. -g -c $< -O2 -o $@ + +$(BIN)/asan_break_optimization$(SUFF).o: tests/asan_break_optimization.cc $(MAKEFILE) + $(CLEANROOM_CXX) $(PIE) $(CFLAGS) -c $< -O0 -o $@ + +$(BIN)/%_test$(SUFF).o: tests/%_test.cc $(RTL_HDR) $(MAKEFILE) + $(ASAN_CXX) $(GTEST_INCLUDE) -I. -g -c $< -O2 -o $@ $(PIE) $(CFLAGS) + +$(BIN)/%_test$(SUFF).o: tests/%_test.mm $(RTL_HDR) $(MAKEFILE) + $(ASAN_CXX) $(GTEST_INCLUDE) -I. -g -c $< -O2 -o $@ -ObjC $(PIE) $(CFLAGS) + +$(BIN)/%$(SUFF).o: %.cc $(RTL_HDR) $(MAKEFILE) + $(CXX) $(PIE) $(CFLAGS) -fPIC -c -O2 -fno-exceptions -funwind-tables \ + -o $@ -g $< -Ithird_party \ + -DASAN_USE_SYSINFO=1 \ + -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ + -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ + -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=$(ASAN_FLEXIBLE_MAPPING_AND_OFFSET) \ + $(ASAN_FLAGS) + +$(BIN)/%$(SUFF).o: %.c $(RTL_HDR) $(MAKEFILE) + $(CC) $(PIE) $(CFLAGS) -fPIC -c -O2 -o $@ -g $< -Ithird_party \ + -DASAN_USE_SYSINFO=1 \ + $(ASAN_FLAGS) + +ifeq ($(OS),darwin) +LD_FLAGS=-framework Foundation +else +LD_FLAGS= +endif + +lib: $(LIBASAN_A) + +$(LIBASAN_A): $(BIN) $(LIBASAN_OBJ) $(MAKEFILE) + mkdir -p $(LIBASAN_INST_DIR) + ar ru $@ $(LIBASAN_OBJ) + $(CXX) -shared $(CFLAGS) $(LIBASAN_OBJ) $(LD_FLAGS) -o $(BIN)/libasan$(SUFF).so + +TEST_OBJECTS_COMMON=\ + $(BIN)/asan_test$(SUFF).o \ + $(BIN)/asan_globals_test$(SUFF).o \ + $(BIN)/asan_break_optimization$(SUFF).o \ + $(BIN)/asan_noinst_test$(SUFF).o \ + $(BIN)/asan_interface_test$(SUFF).o + +BENCHMARK_OBJECTS=\ + $(BIN)/asan_benchmarks_test$(SUFF).o \ + $(BIN)/asan_break_optimization$(SUFF).o + +ifeq ($(OS),darwin) +TEST_OBJECTS=$(TEST_OBJECTS_COMMON) \ + $(BIN)/asan_mac_test$(SUFF).o +else +TEST_OBJECTS=$(TEST_OBJECTS_COMMON) +endif + +$(BIN)/asan_test$(SUFF): $(TEST_OBJECTS) $(LIBASAN_A) $(MAKEFILE) tests/asan_test.ignore $(GTEST_LIB) + $(ASAN_LD) $(PIE) $(CFLAGS) -g -O3 $(TEST_OBJECTS) \ + $(LD_FLAGS) -o $@ $(LIBS) $(GTEST_LIB) $(ASAN_LD_TAIL) + +$(BIN)/asan_benchmarks$(SUFF): $(BENCHMARK_OBJECTS) $(LIBASAN_A) $(MAKEFILE) $(GTEST_LIB) + $(ASAN_LD) $(PIE) $(CFLAGS) -g -O3 $(BENCHMARK_OBJECTS) \ + $(LD_FLAGS) -o $@ $(LIBS) $(GTEST_LIB) $(ASAN_LD_TAIL) + +asan_test: $(BIN)/asan_test$(SUFF) + +asan_benchmarks: $(BIN)/asan_benchmarks$(SUFF) + +# for now, build gtest with clang/asan even if we use a different compiler. +$(GTEST_LIB): + mkdir -p $(GTEST_MAKE_DIR) && \ + cd $(GTEST_MAKE_DIR) && \ + $(MAKE) -f ../make/Makefile CXXFLAGS="$(PIE) $(CFLAGS) -g -w" \ + CXX="$(CLANG_ASAN_CXX)" + +RTL_LINT_FITLER=-readability/casting,-readability/check,-build/include,-build/header_guard,-build/class,-legal/copyright +# TODO(kcc): remove these filters one by one +TEST_LINT_FITLER=-readability/casting,-build/include,-legal/copyright,-whitespace/newline,-runtime/sizeof,-runtime/int,-runtime/printf + +LLVM_LINT_FILTER=-,+whitespace + +ADDRESS_SANITIZER_CPP=../../../../lib/Transforms/Instrumentation/AddressSanitizer.cpp + +lint: + third_party/cpplint/cpplint.py --filter=$(LLVM_LINT_FILTER) $(ADDRESS_SANITIZER_CPP) + third_party/cpplint/cpplint.py --filter=$(RTL_LINT_FITLER) asan_*.cc asan_*.h + third_party/cpplint/cpplint.py --filter=$(TEST_LINT_FITLER) tests/*.cc + +get_third_party: + rm -rf third_party + mkdir third_party + (cd third_party && \ + svn co -r375 http://googletest.googlecode.com/svn/trunk googletest && \ + svn co -r69 http://google-styleguide.googlecode.com/svn/trunk/cpplint cpplint \ + ) + +clean: + rm -f *.o *.ll *.S *.a *.log asan_test64* asan_test32* a.out perf.data log + rm -rf $(BIN) + rm -rf $(GTEST_ROOT)/make-* diff --git a/lib/asan/README.txt b/lib/asan/README.txt new file mode 100644 index 0000000..00ae3c4 --- /dev/null +++ b/lib/asan/README.txt @@ -0,0 +1,26 @@ +AddressSanitizer RT +================================ +This directory contains sources of the AddressSanitizer (asan) run-time library. +We are in the process of integrating AddressSanitizer with LLVM, stay tuned. + +Directory structre: + +README.txt : This file. +Makefile.mk : Currently a stub for a proper makefile. not usable. +Makefile.old : Old out-of-tree makefile, the only usable one so far. +asan_*.{cc,h} : Sources of the asan run-time lirbary. +mach_override/* : Utility to override functions on Darwin (MIT License). +sysinfo/* : Portable utility to iterate over /proc/maps (BSD License). +scripts/* : Helper scripts. + +Temporary build instructions (verified on linux): + +cd lib/asan +make -f Makefile.old get_third_party # gets googletest and cpplint +make -f Makefile.old test -j 8 CLANG_BUILD=/path/to/Release+Asserts +# Optional: +# make -f Makefile.old install # installs clang and rt to lib/asan_clang_linux + +For more info see http://code.google.com/p/address-sanitizer/ + + diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cc new file mode 100644 index 0000000..f86dc0b --- /dev/null +++ b/lib/asan/asan_allocator.cc @@ -0,0 +1,1020 @@ +//===-- asan_allocator.cc ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Implementation of ASan's memory allocator. +// Evey piece of memory (AsanChunk) allocated by the allocator +// has a left redzone of REDZONE bytes and +// a right redzone such that the end of the chunk is aligned by REDZONE +// (i.e. the right redzone is between 0 and REDZONE-1). +// The left redzone is always poisoned. +// The right redzone is poisoned on malloc, the body is poisoned on free. +// Once freed, a chunk is moved to a quarantine (fifo list). +// After quarantine, a chunk is returned to freelists. +// +// The left redzone contains ASan's internal data and the stack trace of +// the malloc call. +// Once freed, the body of the chunk contains the stack trace of the free call. +// +//===----------------------------------------------------------------------===// + +#include "asan_allocator.h" +#include "asan_interceptors.h" +#include "asan_interface.h" +#include "asan_internal.h" +#include "asan_lock.h" +#include "asan_mapping.h" +#include "asan_stats.h" +#include "asan_thread.h" +#include "asan_thread_registry.h" + +#include +#include +#include + +namespace __asan { + +#define REDZONE FLAG_redzone +static const size_t kMinAllocSize = REDZONE * 2; +static const size_t kMinMmapSize = 4UL << 20; // 4M +static const uint64_t kMaxAvailableRam = 128ULL << 30; // 128G +static const size_t kMaxThreadLocalQuarantine = 1 << 20; // 1M +static const size_t kMaxSizeForThreadLocalFreeList = 1 << 17; + +// Size classes less than kMallocSizeClassStep are powers of two. +// All other size classes are multiples of kMallocSizeClassStep. +static const size_t kMallocSizeClassStepLog = 26; +static const size_t kMallocSizeClassStep = 1UL << kMallocSizeClassStepLog; + +#if __WORDSIZE == 32 +static const size_t kMaxAllowedMallocSize = 3UL << 30; // 3G +#else +static const size_t kMaxAllowedMallocSize = 8UL << 30; // 8G +#endif + +static inline bool IsAligned(uintptr_t a, uintptr_t alignment) { + return (a & (alignment - 1)) == 0; +} + +static inline size_t Log2(size_t x) { + CHECK(IsPowerOfTwo(x)); + return __builtin_ctzl(x); +} + +static inline size_t RoundUpToPowerOfTwo(size_t size) { + CHECK(size); + if (IsPowerOfTwo(size)) return size; + size_t up = __WORDSIZE - __builtin_clzl(size); + CHECK(size < (1ULL << up)); + CHECK(size > (1ULL << (up - 1))); + return 1UL << up; +} + +static inline size_t SizeClassToSize(uint8_t size_class) { + CHECK(size_class < kNumberOfSizeClasses); + if (size_class <= kMallocSizeClassStepLog) { + return 1UL << size_class; + } else { + return (size_class - kMallocSizeClassStepLog) * kMallocSizeClassStep; + } +} + +static inline uint8_t SizeToSizeClass(size_t size) { + uint8_t res = 0; + if (size <= kMallocSizeClassStep) { + size_t rounded = RoundUpToPowerOfTwo(size); + res = Log2(rounded); + } else { + res = ((size + kMallocSizeClassStep - 1) / kMallocSizeClassStep) + + kMallocSizeClassStepLog; + } + CHECK(res < kNumberOfSizeClasses); + CHECK(size <= SizeClassToSize(res)); + return res; +} + +// Given REDZONE bytes, we need to mark first size bytes +// as addressable and the rest REDZONE-size bytes as unaddressable. +static void PoisonHeapPartialRightRedzone(uintptr_t mem, size_t size) { + CHECK(size <= REDZONE); + CHECK(IsAligned(mem, REDZONE)); + CHECK(IsPowerOfTwo(SHADOW_GRANULARITY)); + CHECK(IsPowerOfTwo(REDZONE)); + CHECK(REDZONE >= SHADOW_GRANULARITY); + PoisonShadowPartialRightRedzone(mem, size, REDZONE, + kAsanHeapRightRedzoneMagic); +} + +static uint8_t *MmapNewPagesAndPoisonShadow(size_t size) { + CHECK(IsAligned(size, kPageSize)); + uint8_t *res = (uint8_t*)AsanMmapSomewhereOrDie(size, __FUNCTION__); + PoisonShadow((uintptr_t)res, size, kAsanHeapLeftRedzoneMagic); + if (FLAG_debug) { + Printf("ASAN_MMAP: [%p, %p)\n", res, res + size); + } + return res; +} + +// Every chunk of memory allocated by this allocator can be in one of 3 states: +// CHUNK_AVAILABLE: the chunk is in the free list and ready to be allocated. +// CHUNK_ALLOCATED: the chunk is allocated and not yet freed. +// CHUNK_QUARANTINE: the chunk was freed and put into quarantine zone. +// +// The pseudo state CHUNK_MEMALIGN is used to mark that the address is not +// the beginning of a AsanChunk (in which case 'next' contains the address +// of the AsanChunk). +// +// The magic numbers for the enum values are taken randomly. +enum { + CHUNK_AVAILABLE = 0x573B, + CHUNK_ALLOCATED = 0x3204, + CHUNK_QUARANTINE = 0x1978, + CHUNK_MEMALIGN = 0xDC68, +}; + +struct ChunkBase { + uint16_t chunk_state; + uint8_t size_class; + uint32_t offset; // User-visible memory starts at this+offset (beg()). + int32_t alloc_tid; + int32_t free_tid; + size_t used_size; // Size requested by the user. + AsanChunk *next; + + uintptr_t beg() { return (uintptr_t)this + offset; } + size_t Size() { return SizeClassToSize(size_class); } + uint8_t SizeClass() { return size_class; } +}; + +struct AsanChunk: public ChunkBase { + uint32_t *compressed_alloc_stack() { + CHECK(REDZONE >= sizeof(ChunkBase)); + return (uint32_t*)((uintptr_t)this + sizeof(ChunkBase)); + } + uint32_t *compressed_free_stack() { + CHECK(REDZONE >= sizeof(ChunkBase)); + return (uint32_t*)((uintptr_t)this + REDZONE); + } + + // The left redzone after the ChunkBase is given to the alloc stack trace. + size_t compressed_alloc_stack_size() { + return (REDZONE - sizeof(ChunkBase)) / sizeof(uint32_t); + } + size_t compressed_free_stack_size() { + return (REDZONE) / sizeof(uint32_t); + } + + bool AddrIsInside(uintptr_t addr, size_t access_size, size_t *offset) { + if (addr >= beg() && (addr + access_size) <= (beg() + used_size)) { + *offset = addr - beg(); + return true; + } + return false; + } + + bool AddrIsAtLeft(uintptr_t addr, size_t access_size, size_t *offset) { + if (addr < beg()) { + *offset = beg() - addr; + return true; + } + return false; + } + + bool AddrIsAtRight(uintptr_t addr, size_t access_size, size_t *offset) { + if (addr + access_size >= beg() + used_size) { + if (addr <= beg() + used_size) + *offset = 0; + else + *offset = addr - (beg() + used_size); + return true; + } + return false; + } + + void DescribeAddress(uintptr_t addr, size_t access_size) { + size_t offset; + Printf("%p is located ", addr); + if (AddrIsInside(addr, access_size, &offset)) { + Printf("%ld bytes inside of", offset); + } else if (AddrIsAtLeft(addr, access_size, &offset)) { + Printf("%ld bytes to the left of", offset); + } else if (AddrIsAtRight(addr, access_size, &offset)) { + Printf("%ld bytes to the right of", offset); + } else { + Printf(" somewhere around (this is AddressSanitizer bug!)"); + } + Printf(" %lu-byte region [%p,%p)\n", + used_size, beg(), beg() + used_size); + } +}; + +static AsanChunk *PtrToChunk(uintptr_t ptr) { + AsanChunk *m = (AsanChunk*)(ptr - REDZONE); + if (m->chunk_state == CHUNK_MEMALIGN) { + m = m->next; + } + return m; +} + + +void AsanChunkFifoList::PushList(AsanChunkFifoList *q) { + if (last_) { + CHECK(first_); + CHECK(!last_->next); + last_->next = q->first_; + last_ = q->last_; + } else { + CHECK(!first_); + last_ = q->last_; + first_ = q->first_; + } + size_ += q->size(); + q->clear(); +} + +void AsanChunkFifoList::Push(AsanChunk *n) { + CHECK(n->next == NULL); + if (last_) { + CHECK(first_); + CHECK(!last_->next); + last_->next = n; + last_ = n; + } else { + CHECK(!first_); + last_ = first_ = n; + } + size_ += n->Size(); +} + +// Interesting performance observation: this function takes up to 15% of overal +// allocator time. That's because *first_ has been evicted from cache long time +// ago. Not sure if we can or want to do anything with this. +AsanChunk *AsanChunkFifoList::Pop() { + CHECK(first_); + AsanChunk *res = first_; + first_ = first_->next; + if (first_ == NULL) + last_ = NULL; + CHECK(size_ >= res->Size()); + size_ -= res->Size(); + if (last_) { + CHECK(!last_->next); + } + return res; +} + +// All pages we ever allocated. +struct PageGroup { + uintptr_t beg; + uintptr_t end; + size_t size_of_chunk; + uintptr_t last_chunk; + bool InRange(uintptr_t addr) { + return addr >= beg && addr < end; + } +}; + +class MallocInfo { + public: + + explicit MallocInfo(LinkerInitialized x) : mu_(x) { } + + AsanChunk *AllocateChunks(uint8_t size_class, size_t n_chunks) { + AsanChunk *m = NULL; + AsanChunk **fl = &free_lists_[size_class]; + { + ScopedLock lock(&mu_); + for (size_t i = 0; i < n_chunks; i++) { + if (!(*fl)) { + *fl = GetNewChunks(size_class); + } + AsanChunk *t = *fl; + *fl = t->next; + t->next = m; + CHECK(t->chunk_state == CHUNK_AVAILABLE); + m = t; + } + } + return m; + } + + void SwallowThreadLocalMallocStorage(AsanThreadLocalMallocStorage *x, + bool eat_free_lists) { + CHECK(FLAG_quarantine_size > 0); + ScopedLock lock(&mu_); + AsanChunkFifoList *q = &x->quarantine_; + if (q->size() > 0) { + quarantine_.PushList(q); + while (quarantine_.size() > FLAG_quarantine_size) { + QuarantinePop(); + } + } + if (eat_free_lists) { + for (size_t size_class = 0; size_class < kNumberOfSizeClasses; + size_class++) { + AsanChunk *m = x->free_lists_[size_class]; + while (m) { + AsanChunk *t = m->next; + m->next = free_lists_[size_class]; + free_lists_[size_class] = m; + m = t; + } + x->free_lists_[size_class] = 0; + } + } + } + + void BypassThreadLocalQuarantine(AsanChunk *chunk) { + ScopedLock lock(&mu_); + quarantine_.Push(chunk); + } + + AsanChunk *FindMallocedOrFreed(uintptr_t addr, size_t access_size) { + ScopedLock lock(&mu_); + return FindChunkByAddr(addr); + } + + // TODO(glider): AllocationSize() may become very slow if the size of + // page_groups_ grows. This can be fixed by increasing kMinMmapSize, + // but a better solution is to speed up the search somehow. + size_t AllocationSize(uintptr_t ptr) { + ScopedLock lock(&mu_); + + // first, check if this is our memory + PageGroup *g = FindPageGroupUnlocked(ptr); + if (!g) return 0; + AsanChunk *m = PtrToChunk(ptr); + if (m->chunk_state == CHUNK_ALLOCATED) { + return m->used_size; + } else { + return 0; + } + } + + void ForceLock() { + mu_.Lock(); + } + + void ForceUnlock() { + mu_.Unlock(); + } + + void PrintStatus() { + ScopedLock lock(&mu_); + size_t malloced = 0; + + Printf(" MallocInfo: in quarantine: %ld malloced: %ld; ", + quarantine_.size() >> 20, malloced >> 20); + for (size_t j = 1; j < kNumberOfSizeClasses; j++) { + AsanChunk *i = free_lists_[j]; + if (!i) continue; + size_t t = 0; + for (; i; i = i->next) { + t += i->Size(); + } + Printf("%ld:%ld ", j, t >> 20); + } + Printf("\n"); + } + + PageGroup *FindPageGroup(uintptr_t addr) { + ScopedLock lock(&mu_); + return FindPageGroupUnlocked(addr); + } + + private: + PageGroup *FindPageGroupUnlocked(uintptr_t addr) { + for (int i = 0; i < n_page_groups_; i++) { + PageGroup *g = page_groups_[i]; + if (g->InRange(addr)) { + return g; + } + } + return NULL; + } + + // We have an address between two chunks, and we want to report just one. + AsanChunk *ChooseChunk(uintptr_t addr, + AsanChunk *left_chunk, AsanChunk *right_chunk) { + // Prefer an allocated chunk or a chunk from quarantine. + if (left_chunk->chunk_state == CHUNK_AVAILABLE && + right_chunk->chunk_state != CHUNK_AVAILABLE) + return right_chunk; + if (right_chunk->chunk_state == CHUNK_AVAILABLE && + left_chunk->chunk_state != CHUNK_AVAILABLE) + return left_chunk; + // Choose based on offset. + size_t l_offset = 0, r_offset = 0; + CHECK(left_chunk->AddrIsAtRight(addr, 1, &l_offset)); + CHECK(right_chunk->AddrIsAtLeft(addr, 1, &r_offset)); + if (l_offset < r_offset) + return left_chunk; + return right_chunk; + } + + AsanChunk *FindChunkByAddr(uintptr_t addr) { + PageGroup *g = FindPageGroupUnlocked(addr); + if (!g) return 0; + CHECK(g->size_of_chunk); + uintptr_t offset_from_beg = addr - g->beg; + uintptr_t this_chunk_addr = g->beg + + (offset_from_beg / g->size_of_chunk) * g->size_of_chunk; + CHECK(g->InRange(this_chunk_addr)); + AsanChunk *m = (AsanChunk*)this_chunk_addr; + CHECK(m->chunk_state == CHUNK_ALLOCATED || + m->chunk_state == CHUNK_AVAILABLE || + m->chunk_state == CHUNK_QUARANTINE); + size_t offset = 0; + if (m->AddrIsInside(addr, 1, &offset)) + return m; + + if (m->AddrIsAtRight(addr, 1, &offset)) { + if (this_chunk_addr == g->last_chunk) // rightmost chunk + return m; + uintptr_t right_chunk_addr = this_chunk_addr + g->size_of_chunk; + CHECK(g->InRange(right_chunk_addr)); + return ChooseChunk(addr, m, (AsanChunk*)right_chunk_addr); + } else { + CHECK(m->AddrIsAtLeft(addr, 1, &offset)); + if (this_chunk_addr == g->beg) // leftmost chunk + return m; + uintptr_t left_chunk_addr = this_chunk_addr - g->size_of_chunk; + CHECK(g->InRange(left_chunk_addr)); + return ChooseChunk(addr, (AsanChunk*)left_chunk_addr, m); + } + } + + void QuarantinePop() { + CHECK(quarantine_.size() > 0); + AsanChunk *m = quarantine_.Pop(); + CHECK(m); + // if (F_v >= 2) Printf("MallocInfo::pop %p\n", m); + + CHECK(m->chunk_state == CHUNK_QUARANTINE); + m->chunk_state = CHUNK_AVAILABLE; + CHECK(m->alloc_tid >= 0); + CHECK(m->free_tid >= 0); + + size_t size_class = m->SizeClass(); + m->next = free_lists_[size_class]; + free_lists_[size_class] = m; + + // Statistics. + AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats(); + thread_stats.real_frees++; + thread_stats.really_freed += m->used_size; + thread_stats.really_freed_redzones += m->Size() - m->used_size; + thread_stats.really_freed_by_size[m->SizeClass()]++; + } + + // Get a list of newly allocated chunks. + AsanChunk *GetNewChunks(uint8_t size_class) { + size_t size = SizeClassToSize(size_class); + CHECK(IsPowerOfTwo(kMinMmapSize)); + CHECK(size < kMinMmapSize || (size % kMinMmapSize) == 0); + size_t mmap_size = Max(size, kMinMmapSize); + size_t n_chunks = mmap_size / size; + CHECK(n_chunks * size == mmap_size); + if (size < kPageSize) { + // Size is small, just poison the last chunk. + n_chunks--; + } else { + // Size is large, allocate an extra page at right and poison it. + mmap_size += kPageSize; + } + CHECK(n_chunks > 0); + uint8_t *mem = MmapNewPagesAndPoisonShadow(mmap_size); + + // Statistics. + AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats(); + thread_stats.mmaps++; + thread_stats.mmaped += mmap_size; + thread_stats.mmaped_by_size[size_class] += n_chunks; + + AsanChunk *res = NULL; + for (size_t i = 0; i < n_chunks; i++) { + AsanChunk *m = (AsanChunk*)(mem + i * size); + m->chunk_state = CHUNK_AVAILABLE; + m->size_class = size_class; + m->next = res; + res = m; + } + PageGroup *pg = (PageGroup*)(mem + n_chunks * size); + // This memory is already poisoned, no need to poison it again. + pg->beg = (uintptr_t)mem; + pg->end = pg->beg + mmap_size; + pg->size_of_chunk = size; + pg->last_chunk = (uintptr_t)(mem + size * (n_chunks - 1)); + int page_group_idx = AtomicInc(&n_page_groups_) - 1; + CHECK(page_group_idx < (int)ASAN_ARRAY_SIZE(page_groups_)); + page_groups_[page_group_idx] = pg; + return res; + } + + AsanChunk *free_lists_[kNumberOfSizeClasses]; + AsanChunkFifoList quarantine_; + AsanLock mu_; + + PageGroup *page_groups_[kMaxAvailableRam / kMinMmapSize]; + int n_page_groups_; // atomic +}; + +static MallocInfo malloc_info(LINKER_INITIALIZED); + +void AsanThreadLocalMallocStorage::CommitBack() { + malloc_info.SwallowThreadLocalMallocStorage(this, true); +} + +static void Describe(uintptr_t addr, size_t access_size) { + AsanChunk *m = malloc_info.FindMallocedOrFreed(addr, access_size); + if (!m) return; + m->DescribeAddress(addr, access_size); + CHECK(m->alloc_tid >= 0); + AsanThreadSummary *alloc_thread = + asanThreadRegistry().FindByTid(m->alloc_tid); + AsanStackTrace alloc_stack; + AsanStackTrace::UncompressStack(&alloc_stack, m->compressed_alloc_stack(), + m->compressed_alloc_stack_size()); + AsanThread *t = asanThreadRegistry().GetCurrent(); + CHECK(t); + if (m->free_tid >= 0) { + AsanThreadSummary *free_thread = + asanThreadRegistry().FindByTid(m->free_tid); + Printf("freed by thread T%d here:\n", free_thread->tid()); + AsanStackTrace free_stack; + AsanStackTrace::UncompressStack(&free_stack, m->compressed_free_stack(), + m->compressed_free_stack_size()); + free_stack.PrintStack(); + Printf("previously allocated by thread T%d here:\n", + alloc_thread->tid()); + + alloc_stack.PrintStack(); + t->summary()->Announce(); + free_thread->Announce(); + alloc_thread->Announce(); + } else { + Printf("allocated by thread T%d here:\n", alloc_thread->tid()); + alloc_stack.PrintStack(); + t->summary()->Announce(); + alloc_thread->Announce(); + } +} + +static uint8_t *Allocate(size_t alignment, size_t size, AsanStackTrace *stack) { + __asan_init(); + CHECK(stack); + if (size == 0) { + size = 1; // TODO(kcc): do something smarter + } + CHECK(IsPowerOfTwo(alignment)); + size_t rounded_size = RoundUpTo(size, REDZONE); + size_t needed_size = rounded_size + REDZONE; + if (alignment > REDZONE) { + needed_size += alignment; + } + CHECK(IsAligned(needed_size, REDZONE)); + if (size > kMaxAllowedMallocSize || needed_size > kMaxAllowedMallocSize) { + Report("WARNING: AddressSanitizer failed to allocate %p bytes\n", size); + return 0; + } + + uint8_t size_class = SizeToSizeClass(needed_size); + size_t size_to_allocate = SizeClassToSize(size_class); + CHECK(size_to_allocate >= kMinAllocSize); + CHECK(size_to_allocate >= needed_size); + CHECK(IsAligned(size_to_allocate, REDZONE)); + + if (FLAG_v >= 2) { + Printf("Allocate align: %ld size: %ld class: %d real: %ld\n", + alignment, size, size_class, size_to_allocate); + } + + AsanThread *t = asanThreadRegistry().GetCurrent(); + AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats(); + // Statistics + thread_stats.mallocs++; + thread_stats.malloced += size; + thread_stats.malloced_redzones += size_to_allocate - size; + thread_stats.malloced_by_size[size_class]++; + + AsanChunk *m = NULL; + if (!t || size_to_allocate >= kMaxSizeForThreadLocalFreeList) { + // get directly from global storage. + m = malloc_info.AllocateChunks(size_class, 1); + thread_stats.malloc_large++; + } else { + // get from the thread-local storage. + AsanChunk **fl = &t->malloc_storage().free_lists_[size_class]; + if (!*fl) { + size_t n_new_chunks = kMaxSizeForThreadLocalFreeList / size_to_allocate; + *fl = malloc_info.AllocateChunks(size_class, n_new_chunks); + thread_stats.malloc_small_slow++; + } + m = *fl; + *fl = (*fl)->next; + } + CHECK(m); + CHECK(m->chunk_state == CHUNK_AVAILABLE); + m->chunk_state = CHUNK_ALLOCATED; + m->next = NULL; + CHECK(m->Size() == size_to_allocate); + uintptr_t addr = (uintptr_t)m + REDZONE; + CHECK(addr == (uintptr_t)m->compressed_free_stack()); + + if (alignment > REDZONE && (addr & (alignment - 1))) { + addr = RoundUpTo(addr, alignment); + CHECK((addr & (alignment - 1)) == 0); + AsanChunk *p = (AsanChunk*)(addr - REDZONE); + p->chunk_state = CHUNK_MEMALIGN; + p->next = m; + } + CHECK(m == PtrToChunk(addr)); + m->used_size = size; + m->offset = addr - (uintptr_t)m; + CHECK(m->beg() == addr); + m->alloc_tid = t ? t->tid() : 0; + m->free_tid = AsanThread::kInvalidTid; + AsanStackTrace::CompressStack(stack, m->compressed_alloc_stack(), + m->compressed_alloc_stack_size()); + PoisonShadow(addr, rounded_size, 0); + if (size < rounded_size) { + PoisonHeapPartialRightRedzone(addr + rounded_size - REDZONE, + size & (REDZONE - 1)); + } + if (size <= FLAG_max_malloc_fill_size) { + real_memset((void*)addr, 0, rounded_size); + } + return (uint8_t*)addr; +} + +static void Deallocate(uint8_t *ptr, AsanStackTrace *stack) { + if (!ptr) return; + CHECK(stack); + + if (FLAG_debug) { + CHECK(malloc_info.FindPageGroup((uintptr_t)ptr)); + } + + // Printf("Deallocate %p\n", ptr); + AsanChunk *m = PtrToChunk((uintptr_t)ptr); + if (m->chunk_state == CHUNK_QUARANTINE) { + Report("ERROR: AddressSanitizer attempting double-free on %p:\n", ptr); + stack->PrintStack(); + m->DescribeAddress((uintptr_t)ptr, 1); + ShowStatsAndAbort(); + } else if (m->chunk_state != CHUNK_ALLOCATED) { + Report("ERROR: AddressSanitizer attempting free on address which was not" + " malloc()-ed: %p\n", ptr); + stack->PrintStack(); + ShowStatsAndAbort(); + } + CHECK(m->chunk_state == CHUNK_ALLOCATED); + CHECK(m->free_tid == AsanThread::kInvalidTid); + CHECK(m->alloc_tid >= 0); + AsanThread *t = asanThreadRegistry().GetCurrent(); + m->free_tid = t ? t->tid() : 0; + AsanStackTrace::CompressStack(stack, m->compressed_free_stack(), + m->compressed_free_stack_size()); + size_t rounded_size = RoundUpTo(m->used_size, REDZONE); + PoisonShadow((uintptr_t)ptr, rounded_size, kAsanHeapFreeMagic); + + // Statistics. + AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats(); + thread_stats.frees++; + thread_stats.freed += m->used_size; + thread_stats.freed_by_size[m->SizeClass()]++; + + m->chunk_state = CHUNK_QUARANTINE; + if (t) { + AsanThreadLocalMallocStorage *ms = &t->malloc_storage(); + CHECK(!m->next); + ms->quarantine_.Push(m); + + if (ms->quarantine_.size() > kMaxThreadLocalQuarantine) { + malloc_info.SwallowThreadLocalMallocStorage(ms, false); + } + } else { + CHECK(!m->next); + malloc_info.BypassThreadLocalQuarantine(m); + } +} + +static uint8_t *Reallocate(uint8_t *old_ptr, size_t new_size, + AsanStackTrace *stack) { + CHECK(old_ptr && new_size); + + // Statistics. + AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats(); + thread_stats.reallocs++; + thread_stats.realloced += new_size; + + AsanChunk *m = PtrToChunk((uintptr_t)old_ptr); + CHECK(m->chunk_state == CHUNK_ALLOCATED); + size_t old_size = m->used_size; + size_t memcpy_size = Min(new_size, old_size); + uint8_t *new_ptr = Allocate(0, new_size, stack); + if (new_ptr) { + real_memcpy(new_ptr, old_ptr, memcpy_size); + Deallocate(old_ptr, stack); + } + return new_ptr; +} + +} // namespace __asan + +// Malloc hooks declaration. +// ASAN_NEW_HOOK(ptr, size) is called immediately after +// allocation of "size" bytes, which returned "ptr". +// ASAN_DELETE_HOOK(ptr) is called immediately before +// deallocation of "ptr". +// If ASAN_NEW_HOOK or ASAN_DELETE_HOOK is defined, user +// program must provide implementation of this hook. +// If macro is undefined, the hook is no-op. +#ifdef ASAN_NEW_HOOK +extern "C" void ASAN_NEW_HOOK(void *ptr, size_t size); +#else +static inline void ASAN_NEW_HOOK(void *ptr, size_t size) { } +#endif + +#ifdef ASAN_DELETE_HOOK +extern "C" void ASAN_DELETE_HOOK(void *ptr); +#else +static inline void ASAN_DELETE_HOOK(void *ptr) { } +#endif + +namespace __asan { + +void *asan_memalign(size_t alignment, size_t size, AsanStackTrace *stack) { + void *ptr = (void*)Allocate(alignment, size, stack); + ASAN_NEW_HOOK(ptr, size); + return ptr; +} + +void asan_free(void *ptr, AsanStackTrace *stack) { + ASAN_DELETE_HOOK(ptr); + Deallocate((uint8_t*)ptr, stack); +} + +void *asan_malloc(size_t size, AsanStackTrace *stack) { + void *ptr = (void*)Allocate(0, size, stack); + ASAN_NEW_HOOK(ptr, size); + return ptr; +} + +void *asan_calloc(size_t nmemb, size_t size, AsanStackTrace *stack) { + void *ptr = (void*)Allocate(0, nmemb * size, stack); + if (ptr) + real_memset(ptr, 0, nmemb * size); + ASAN_NEW_HOOK(ptr, nmemb * size); + return ptr; +} + +void *asan_realloc(void *p, size_t size, AsanStackTrace *stack) { + if (p == NULL) { + void *ptr = (void*)Allocate(0, size, stack); + ASAN_NEW_HOOK(ptr, size); + return ptr; + } else if (size == 0) { + ASAN_DELETE_HOOK(p); + Deallocate((uint8_t*)p, stack); + return NULL; + } + return Reallocate((uint8_t*)p, size, stack); +} + +void *asan_valloc(size_t size, AsanStackTrace *stack) { + void *ptr = (void*)Allocate(kPageSize, size, stack); + ASAN_NEW_HOOK(ptr, size); + return ptr; +} + +void *asan_pvalloc(size_t size, AsanStackTrace *stack) { + size = RoundUpTo(size, kPageSize); + if (size == 0) { + // pvalloc(0) should allocate one page. + size = kPageSize; + } + void *ptr = (void*)Allocate(kPageSize, size, stack); + ASAN_NEW_HOOK(ptr, size); + return ptr; +} + +int asan_posix_memalign(void **memptr, size_t alignment, size_t size, + AsanStackTrace *stack) { + void *ptr = Allocate(alignment, size, stack); + CHECK(IsAligned((uintptr_t)ptr, alignment)); + ASAN_NEW_HOOK(ptr, size); + *memptr = ptr; + return 0; +} + +size_t __asan_mz_size(const void *ptr) { + return malloc_info.AllocationSize((uintptr_t)ptr); +} + +void DescribeHeapAddress(uintptr_t addr, uintptr_t access_size) { + Describe(addr, access_size); +} + +void __asan_mz_force_lock() { + malloc_info.ForceLock(); +} + +void __asan_mz_force_unlock() { + malloc_info.ForceUnlock(); +} + +// ---------------------- Fake stack-------------------- {{{1 +FakeStack::FakeStack() { + CHECK(real_memset); + real_memset(this, 0, sizeof(*this)); +} + +bool FakeStack::AddrIsInSizeClass(uintptr_t addr, size_t size_class) { + uintptr_t mem = allocated_size_classes_[size_class]; + uintptr_t size = ClassMmapSize(size_class); + bool res = mem && addr >= mem && addr < mem + size; + return res; +} + +uintptr_t FakeStack::AddrIsInFakeStack(uintptr_t addr) { + for (size_t i = 0; i < kNumberOfSizeClasses; i++) { + if (AddrIsInSizeClass(addr, i)) return allocated_size_classes_[i]; + } + return 0; +} + +// We may want to compute this during compilation. +inline size_t FakeStack::ComputeSizeClass(size_t alloc_size) { + size_t rounded_size = RoundUpToPowerOfTwo(alloc_size); + size_t log = Log2(rounded_size); + CHECK(alloc_size <= (1UL << log)); + if (!(alloc_size > (1UL << (log-1)))) { + Printf("alloc_size %ld log %ld\n", alloc_size, log); + } + CHECK(alloc_size > (1UL << (log-1))); + size_t res = log < kMinStackFrameSizeLog ? 0 : log - kMinStackFrameSizeLog; + CHECK(res < kNumberOfSizeClasses); + CHECK(ClassSize(res) >= rounded_size); + return res; +} + +void FakeFrameFifo::FifoPush(FakeFrame *node) { + CHECK(node); + node->next = 0; + if (first_ == 0 && last_ == 0) { + first_ = last_ = node; + } else { + CHECK(first_); + CHECK(last_); + last_->next = node; + last_ = node; + } +} + +FakeFrame *FakeFrameFifo::FifoPop() { + CHECK(first_ && last_ && "Exhausted fake stack"); + FakeFrame *res = 0; + if (first_ == last_) { + res = first_; + first_ = last_ = 0; + } else { + res = first_; + first_ = first_->next; + } + return res; +} + +void FakeStack::Init(size_t stack_size) { + stack_size_ = stack_size; + alive_ = true; +} + +void FakeStack::Cleanup() { + alive_ = false; + for (size_t i = 0; i < kNumberOfSizeClasses; i++) { + uintptr_t mem = allocated_size_classes_[i]; + if (mem) { + PoisonShadow(mem, ClassMmapSize(i), 0); + allocated_size_classes_[i] = 0; + AsanUnmapOrDie((void*)mem, ClassMmapSize(i)); + } + } +} + +size_t FakeStack::ClassMmapSize(size_t size_class) { + return RoundUpToPowerOfTwo(stack_size_); +} + +void FakeStack::AllocateOneSizeClass(size_t size_class) { + CHECK(ClassMmapSize(size_class) >= kPageSize); + uintptr_t new_mem = (uintptr_t)AsanMmapSomewhereOrDie( + ClassMmapSize(size_class), __FUNCTION__); + // Printf("T%d new_mem[%ld]: %p-%p mmap %ld\n", + // asanThreadRegistry().GetCurrent()->tid(), + // size_class, new_mem, new_mem + ClassMmapSize(size_class), + // ClassMmapSize(size_class)); + size_t i; + for (i = 0; i < ClassMmapSize(size_class); + i += ClassSize(size_class)) { + size_classes_[size_class].FifoPush((FakeFrame*)(new_mem + i)); + } + CHECK(i == ClassMmapSize(size_class)); + allocated_size_classes_[size_class] = new_mem; +} + +uintptr_t FakeStack::AllocateStack(size_t size, size_t real_stack) { + if (!alive_) return real_stack; + CHECK(size <= kMaxStackMallocSize && size > 1); + size_t size_class = ComputeSizeClass(size); + if (!allocated_size_classes_[size_class]) { + AllocateOneSizeClass(size_class); + } + FakeFrame *fake_frame = size_classes_[size_class].FifoPop(); + CHECK(fake_frame); + fake_frame->size_minus_one = size - 1; + fake_frame->real_stack = real_stack; + while (FakeFrame *top = call_stack_.top()) { + if (top->real_stack > real_stack) break; + call_stack_.LifoPop(); + DeallocateFrame(top); + } + call_stack_.LifoPush(fake_frame); + uintptr_t ptr = (uintptr_t)fake_frame; + PoisonShadow(ptr, size, 0); + return ptr; +} + +void FakeStack::DeallocateFrame(FakeFrame *fake_frame) { + CHECK(alive_); + size_t size = fake_frame->size_minus_one + 1; + size_t size_class = ComputeSizeClass(size); + CHECK(allocated_size_classes_[size_class]); + uintptr_t ptr = (uintptr_t)fake_frame; + CHECK(AddrIsInSizeClass(ptr, size_class)); + CHECK(AddrIsInSizeClass(ptr + size - 1, size_class)); + size_classes_[size_class].FifoPush(fake_frame); +} + +void FakeStack::OnFree(size_t ptr, size_t size, size_t real_stack) { + FakeFrame *fake_frame = (FakeFrame*)ptr; + CHECK(fake_frame->magic = kRetiredStackFrameMagic); + CHECK(fake_frame->descr != 0); + CHECK(fake_frame->size_minus_one == size - 1); + PoisonShadow(ptr, size, kAsanStackAfterReturnMagic); +} + +} // namespace __asan + +// ---------------------- Interface ---------------- {{{1 +using namespace __asan; // NOLINT + +size_t __asan_stack_malloc(size_t size, size_t real_stack) { + if (!FLAG_use_fake_stack) return real_stack; + AsanThread *t = asanThreadRegistry().GetCurrent(); + if (!t) { + // TSD is gone, use the real stack. + return real_stack; + } + size_t ptr = t->fake_stack().AllocateStack(size, real_stack); + // Printf("__asan_stack_malloc %p %ld %p\n", ptr, size, real_stack); + return ptr; +} + +void __asan_stack_free(size_t ptr, size_t size, size_t real_stack) { + if (!FLAG_use_fake_stack) return; + if (ptr != real_stack) { + FakeStack::OnFree(ptr, size, real_stack); + } +} + +// ASan allocator doesn't reserve extra bytes, so normally we would +// just return "size". +size_t __asan_get_estimated_allocated_size(size_t size) { + if (size == 0) return 1; + return Min(size, kMaxAllowedMallocSize); +} + +bool __asan_get_ownership(const void *p) { + return (p == NULL) || + (malloc_info.AllocationSize((uintptr_t)p) > 0); +} + +size_t __asan_get_allocated_size(const void *p) { + if (p == NULL) return 0; + size_t allocated_size = malloc_info.AllocationSize((uintptr_t)p); + // Die if p is not malloced or if it is already freed. + if (allocated_size == 0) { + Printf("__asan_get_allocated_size failed, ptr=%p is not owned\n", p); + PRINT_CURRENT_STACK(); + ShowStatsAndAbort(); + } + return allocated_size; +} diff --git a/lib/asan/asan_allocator.h b/lib/asan/asan_allocator.h new file mode 100644 index 0000000..9b691e0 --- /dev/null +++ b/lib/asan/asan_allocator.h @@ -0,0 +1,157 @@ +//===-- asan_allocator.h ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header for asan_allocator.cc. +//===----------------------------------------------------------------------===// + +#ifndef ASAN_ALLOCATOR_H +#define ASAN_ALLOCATOR_H + +#include "asan_internal.h" +#include "asan_interceptors.h" + +namespace __asan { + +static const size_t kNumberOfSizeClasses = 255; +struct AsanChunk; + +class AsanChunkFifoList { + public: + explicit AsanChunkFifoList(LinkerInitialized) { } + AsanChunkFifoList() { clear(); } + void Push(AsanChunk *n); + void PushList(AsanChunkFifoList *q); + AsanChunk *Pop(); + size_t size() { return size_; } + void clear() { + first_ = last_ = NULL; + size_ = 0; + } + private: + AsanChunk *first_; + AsanChunk *last_; + size_t size_; +}; + +struct AsanThreadLocalMallocStorage { + explicit AsanThreadLocalMallocStorage(LinkerInitialized x) + : quarantine_(x) { } + AsanThreadLocalMallocStorage() { + CHECK(real_memset); + real_memset(this, 0, sizeof(AsanThreadLocalMallocStorage)); + } + + AsanChunkFifoList quarantine_; + AsanChunk *free_lists_[kNumberOfSizeClasses]; + void CommitBack(); +}; + +// Fake stack frame contains local variables of one function. +// This struct should fit into a stack redzone (32 bytes). +struct FakeFrame { + uintptr_t magic; // Modified by the instrumented code. + uintptr_t descr; // Modified by the instrumented code. + FakeFrame *next; + uint64_t real_stack : 48; + uint64_t size_minus_one : 16; +}; + +struct FakeFrameFifo { + public: + void FifoPush(FakeFrame *node); + FakeFrame *FifoPop(); + private: + FakeFrame *first_, *last_; +}; + +class FakeFrameLifo { + public: + void LifoPush(FakeFrame *node) { + node->next = top_; + top_ = node; + } + void LifoPop() { + CHECK(top_); + top_ = top_->next; + } + FakeFrame *top() { return top_; } + private: + FakeFrame *top_; +}; + +// For each thread we create a fake stack and place stack objects on this fake +// stack instead of the real stack. The fake stack is not really a stack but +// a fast malloc-like allocator so that when a function exits the fake stack +// is not poped but remains there for quite some time until gets used again. +// So, we poison the objects on the fake stack when function returns. +// It helps us find use-after-return bugs. +// We can not rely on __asan_stack_free being called on every function exit, +// so we maintain a lifo list of all current fake frames and update it on every +// call to __asan_stack_malloc. +class FakeStack { + public: + FakeStack(); + explicit FakeStack(LinkerInitialized) {} + void Init(size_t stack_size); + void StopUsingFakeStack() { alive_ = false; } + void Cleanup(); + uintptr_t AllocateStack(size_t size, size_t real_stack); + static void OnFree(size_t ptr, size_t size, size_t real_stack); + // Return the bottom of the maped region. + uintptr_t AddrIsInFakeStack(uintptr_t addr); + private: + static const size_t kMinStackFrameSizeLog = 9; // Min frame is 512B. + static const size_t kMaxStackFrameSizeLog = 16; // Max stack frame is 64K. + static const size_t kMaxStackMallocSize = 1 << kMaxStackFrameSizeLog; + static const size_t kNumberOfSizeClasses = + kMaxStackFrameSizeLog - kMinStackFrameSizeLog + 1; + + bool AddrIsInSizeClass(uintptr_t addr, size_t size_class); + + // Each size class should be large enough to hold all frames. + size_t ClassMmapSize(size_t size_class); + + size_t ClassSize(size_t size_class) { + return 1UL << (size_class + kMinStackFrameSizeLog); + } + + void DeallocateFrame(FakeFrame *fake_frame); + + size_t ComputeSizeClass(size_t alloc_size); + void AllocateOneSizeClass(size_t size_class); + + size_t stack_size_; + bool alive_; + + uintptr_t allocated_size_classes_[kNumberOfSizeClasses]; + FakeFrameFifo size_classes_[kNumberOfSizeClasses]; + FakeFrameLifo call_stack_; +}; + +void *asan_memalign(size_t alignment, size_t size, AsanStackTrace *stack); +void asan_free(void *ptr, AsanStackTrace *stack); + +void *asan_malloc(size_t size, AsanStackTrace *stack); +void *asan_calloc(size_t nmemb, size_t size, AsanStackTrace *stack); +void *asan_realloc(void *p, size_t size, AsanStackTrace *stack); +void *asan_valloc(size_t size, AsanStackTrace *stack); +void *asan_pvalloc(size_t size, AsanStackTrace *stack); + +int asan_posix_memalign(void **memptr, size_t alignment, size_t size, + AsanStackTrace *stack); + +size_t __asan_mz_size(const void *ptr); +void __asan_mz_force_lock(); +void __asan_mz_force_unlock(); +void DescribeHeapAddress(uintptr_t addr, size_t access_size); + +} // namespace __asan +#endif // ASAN_ALLOCATOR_H diff --git a/lib/asan/asan_globals.cc b/lib/asan/asan_globals.cc new file mode 100644 index 0000000..f53bf38 --- /dev/null +++ b/lib/asan/asan_globals.cc @@ -0,0 +1,171 @@ +//===-- asan_globals.cc -----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Handle globals. +//===----------------------------------------------------------------------===// +#include "asan_interceptors.h" +#include "asan_interface.h" +#include "asan_internal.h" +#include "asan_lock.h" +#include "asan_mapping.h" +#include "asan_stack.h" +#include "asan_stats.h" +#include "asan_thread.h" + +#include + +namespace __asan { + +typedef __asan_global Global; + +struct ListOfGlobals { + const Global *g; + ListOfGlobals *next; +}; + +static AsanLock mu_for_globals(LINKER_INITIALIZED); +static ListOfGlobals *list_of_globals; +static LowLevelAllocator allocator_for_globals(LINKER_INITIALIZED); + +void PoisonRedZones(const Global &g) { + size_t shadow_rz_size = kGlobalAndStackRedzone >> SHADOW_SCALE; + CHECK(shadow_rz_size == 1 || shadow_rz_size == 2 || shadow_rz_size == 4); + // full right redzone + size_t g_aligned_size = kGlobalAndStackRedzone * + ((g.size + kGlobalAndStackRedzone - 1) / kGlobalAndStackRedzone); + PoisonShadow(g.beg + g_aligned_size, + kGlobalAndStackRedzone, kAsanGlobalRedzoneMagic); + if ((g.size % kGlobalAndStackRedzone) != 0) { + // partial right redzone + uint64_t g_aligned_down_size = kGlobalAndStackRedzone * + (g.size / kGlobalAndStackRedzone); + CHECK(g_aligned_down_size == g_aligned_size - kGlobalAndStackRedzone); + PoisonShadowPartialRightRedzone(g.beg + g_aligned_down_size, + g.size % kGlobalAndStackRedzone, + kGlobalAndStackRedzone, + kAsanGlobalRedzoneMagic); + } +} + +static size_t GetAlignedSize(size_t size) { + return ((size + kGlobalAndStackRedzone - 1) / kGlobalAndStackRedzone) + * kGlobalAndStackRedzone; +} + + // Check if the global is a zero-terminated ASCII string. If so, print it. +void PrintIfASCII(const Global &g) { + for (size_t p = g.beg; p < g.beg + g.size - 1; p++) { + if (!isascii(*(char*)p)) return; + } + if (*(char*)(g.beg + g.size - 1) != 0) return; + Printf(" '%s' is ascii string '%s'\n", g.name, g.beg); +} + +bool DescribeAddrIfMyRedZone(const Global &g, uintptr_t addr) { + if (addr < g.beg - kGlobalAndStackRedzone) return false; + if (addr >= g.beg + g.size_with_redzone) return false; + Printf("%p is located ", addr); + if (addr < g.beg) { + Printf("%d bytes to the left", g.beg - addr); + } else if (addr >= g.beg + g.size) { + Printf("%d bytes to the right", addr - (g.beg + g.size)); + } else { + Printf("%d bytes inside", addr - g.beg); // Can it happen? + } + Printf(" of global variable '%s' (0x%lx) of size %ld\n", + g.name, g.beg, g.size); + PrintIfASCII(g); + return true; +} + + +bool DescribeAddrIfGlobal(uintptr_t addr) { + if (!FLAG_report_globals) return false; + ScopedLock lock(&mu_for_globals); + bool res = false; + for (ListOfGlobals *l = list_of_globals; l; l = l->next) { + const Global &g = *l->g; + if (FLAG_report_globals >= 2) + Printf("Search Global: beg=%p size=%ld name=%s\n", + g.beg, g.size, g.name); + res |= DescribeAddrIfMyRedZone(g, addr); + } + return res; +} + +// Register a global variable. +// This function may be called more than once for every global +// so we store the globals in a map. +static void RegisterGlobal(const Global *g) { + CHECK(asan_inited); + CHECK(FLAG_report_globals); + CHECK(AddrIsInMem(g->beg)); + CHECK(AddrIsAlignedByGranularity(g->beg)); + CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); + PoisonRedZones(*g); + ListOfGlobals *l = + (ListOfGlobals*)allocator_for_globals.Allocate(sizeof(ListOfGlobals)); + l->g = g; + l->next = list_of_globals; + list_of_globals = l; + if (FLAG_report_globals >= 2) + Report("Added Global: beg=%p size=%ld name=%s\n", + g->beg, g->size, g->name); +} + +static void UnregisterGlobal(const Global *g) { + CHECK(asan_inited); + CHECK(FLAG_report_globals); + CHECK(AddrIsInMem(g->beg)); + CHECK(AddrIsAlignedByGranularity(g->beg)); + CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); + PoisonShadow(g->beg, g->size_with_redzone, 0); + // We unpoison the shadow memory for the global but we do not remove it from + // the list because that would require O(n^2) time with the current list + // implementation. It might not be worth doing anyway. +} + +} // namespace __asan + +// ---------------------- Interface ---------------- {{{1 +using namespace __asan; // NOLINT + +// Register one global with a default redzone. +void __asan_register_global(uintptr_t addr, size_t size, + const char *name) { + if (!FLAG_report_globals) return; + ScopedLock lock(&mu_for_globals); + Global *g = (Global *)allocator_for_globals.Allocate(sizeof(Global)); + g->beg = addr; + g->size = size; + g->size_with_redzone = GetAlignedSize(size) + kGlobalAndStackRedzone; + g->name = name; + RegisterGlobal(g); +} + +// Register an array of globals. +void __asan_register_globals(__asan_global *globals, size_t n) { + if (!FLAG_report_globals) return; + ScopedLock lock(&mu_for_globals); + for (size_t i = 0; i < n; i++) { + RegisterGlobal(&globals[i]); + } +} + +// Unregister an array of globals. +// We must do it when a shared objects gets dlclosed. +void __asan_unregister_globals(__asan_global *globals, size_t n) { + if (!FLAG_report_globals) return; + ScopedLock lock(&mu_for_globals); + for (size_t i = 0; i < n; i++) { + UnregisterGlobal(&globals[i]); + } +} diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc new file mode 100644 index 0000000..53ef91a --- /dev/null +++ b/lib/asan/asan_interceptors.cc @@ -0,0 +1,391 @@ +//===-- asan_interceptors.cc ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Intercept various libc functions to catch buggy memory accesses there. +//===----------------------------------------------------------------------===// +#include "asan_interceptors.h" + +#include "asan_allocator.h" +#include "asan_interface.h" +#include "asan_internal.h" +#include "asan_mapping.h" +#include "asan_stack.h" +#include "asan_stats.h" + +#include +#include +#include +#include + +namespace __asan { + +index_f real_index; +memcmp_f real_memcmp; +memcpy_f real_memcpy; +memmove_f real_memmove; +memset_f real_memset; +strcasecmp_f real_strcasecmp; +strcat_f real_strcat; +strchr_f real_strchr; +strcmp_f real_strcmp; +strcpy_f real_strcpy; +strdup_f real_strdup; +strlen_f real_strlen; +strncasecmp_f real_strncasecmp; +strncmp_f real_strncmp; +strncpy_f real_strncpy; +strnlen_f real_strnlen; + +// Instruments read/write access to a single byte in memory. +// On error calls __asan_report_error, which aborts the program. +__attribute__((noinline)) +static void AccessAddress(uintptr_t address, bool isWrite) { + if (__asan_address_is_poisoned((void*)address)) { + GET_BP_PC_SP; + __asan_report_error(pc, bp, sp, address, isWrite, /* access_size */ 1); + } +} + +// We implement ACCESS_MEMORY_RANGE, ASAN_READ_RANGE, +// and ASAN_WRITE_RANGE as macro instead of function so +// that no extra frames are created, and stack trace contains +// relevant information only. + +// Instruments read/write access to a memory range. +// More complex implementation is possible, for now just +// checking the first and the last byte of a range. +#define ACCESS_MEMORY_RANGE(offset, size, isWrite) do { \ + if (size > 0) { \ + uintptr_t ptr = (uintptr_t)(offset); \ + AccessAddress(ptr, isWrite); \ + AccessAddress(ptr + (size) - 1, isWrite); \ + } \ +} while (0) + +#define ASAN_READ_RANGE(offset, size) do { \ + ACCESS_MEMORY_RANGE(offset, size, false); \ +} while (0) + +#define ASAN_WRITE_RANGE(offset, size) do { \ + ACCESS_MEMORY_RANGE(offset, size, true); \ +} while (0) + +// Behavior of functions like "memcpy" or "strcpy" is undefined +// if memory intervals overlap. We report error in this case. +// Macro is used to avoid creation of new frames. +static inline bool RangesOverlap(const char *offset1, size_t length1, + const char *offset2, size_t length2) { + return !((offset1 + length1 <= offset2) || (offset2 + length2 <= offset1)); +} +#define CHECK_RANGES_OVERLAP(name, _offset1, length1, _offset2, length2) do { \ + const char *offset1 = (const char*)_offset1; \ + const char *offset2 = (const char*)_offset2; \ + if (RangesOverlap(offset1, length1, offset2, length2)) { \ + Report("ERROR: AddressSanitizer %s-param-overlap: " \ + "memory ranges [%p,%p) and [%p, %p) overlap\n", \ + name, offset1, offset1 + length1, offset2, offset2 + length2); \ + PRINT_CURRENT_STACK(); \ + ShowStatsAndAbort(); \ + } \ +} while (0) + +#define ENSURE_ASAN_INITED() do { \ + CHECK(!asan_init_is_running); \ + if (!asan_inited) { \ + __asan_init(); \ + } \ +} while (0) + +size_t internal_strlen(const char *s) { + size_t i = 0; + while (s[i]) i++; + return i; +} + +size_t internal_strnlen(const char *s, size_t maxlen) { + if (real_strnlen != NULL) { + return real_strnlen(s, maxlen); + } + size_t i = 0; + while (i < maxlen && s[i]) i++; + return i; +} + +void* internal_memchr(const void* s, int c, size_t n) { + const char* t = (char*)s; + for (size_t i = 0; i < n; ++i, ++t) + if (*t == c) + return (void*)t; + return NULL; +} + +int internal_memcmp(const void* s1, const void* s2, size_t n) { + const char* t1 = (char*)s1; + const char* t2 = (char*)s2; + for (size_t i = 0; i < n; ++i, ++t1, ++t2) + if (*t1 != *t2) + return *t1 < *t2 ? -1 : 1; + return 0; +} + +void InitializeAsanInterceptors() { +#ifndef __APPLE__ + INTERCEPT_FUNCTION(index); +#else + OVERRIDE_FUNCTION(index, WRAP(strchr)); +#endif + INTERCEPT_FUNCTION(memcmp); + INTERCEPT_FUNCTION(memcpy); + INTERCEPT_FUNCTION(memmove); + INTERCEPT_FUNCTION(memset); + INTERCEPT_FUNCTION(strcasecmp); + INTERCEPT_FUNCTION(strcat); // NOLINT + INTERCEPT_FUNCTION(strchr); + INTERCEPT_FUNCTION(strcmp); + INTERCEPT_FUNCTION(strcpy); // NOLINT + INTERCEPT_FUNCTION(strdup); + INTERCEPT_FUNCTION(strlen); + INTERCEPT_FUNCTION(strncasecmp); + INTERCEPT_FUNCTION(strncmp); + INTERCEPT_FUNCTION(strncpy); +#ifndef __APPLE__ + INTERCEPT_FUNCTION(strnlen); +#endif + if (FLAG_v > 0) { + Printf("AddressSanitizer: libc interceptors initialized\n"); + } +} + +} // namespace __asan + +// ---------------------- Wrappers ---------------- {{{1 +using namespace __asan; // NOLINT + +static inline int CharCmp(unsigned char c1, unsigned char c2) { + return (c1 == c2) ? 0 : (c1 < c2) ? -1 : 1; +} + +static inline int CharCaseCmp(unsigned char c1, unsigned char c2) { + int c1_low = tolower(c1); + int c2_low = tolower(c2); + return c1_low - c2_low; +} + +int WRAP(memcmp)(const void *a1, const void *a2, size_t size) { + ENSURE_ASAN_INITED(); + unsigned char c1 = 0, c2 = 0; + const unsigned char *s1 = (const unsigned char*)a1; + const unsigned char *s2 = (const unsigned char*)a2; + size_t i; + for (i = 0; i < size; i++) { + c1 = s1[i]; + c2 = s2[i]; + if (c1 != c2) break; + } + ASAN_READ_RANGE(s1, Min(i + 1, size)); + ASAN_READ_RANGE(s2, Min(i + 1, size)); + return CharCmp(c1, c2); +} + +void *WRAP(memcpy)(void *to, const void *from, size_t size) { + // memcpy is called during __asan_init() from the internals + // of printf(...). + if (asan_init_is_running) { + return real_memcpy(to, from, size); + } + ENSURE_ASAN_INITED(); + if (FLAG_replace_intrin) { + CHECK_RANGES_OVERLAP("memcpy", to, size, from, size); + ASAN_WRITE_RANGE(from, size); + ASAN_READ_RANGE(to, size); + } + return real_memcpy(to, from, size); +} + +void *WRAP(memmove)(void *to, const void *from, size_t size) { + ENSURE_ASAN_INITED(); + if (FLAG_replace_intrin) { + ASAN_WRITE_RANGE(from, size); + ASAN_READ_RANGE(to, size); + } + return real_memmove(to, from, size); +} + +void *WRAP(memset)(void *block, int c, size_t size) { + // memset is called inside INTERCEPT_FUNCTION on Mac. + if (asan_init_is_running) { + return real_memset(block, c, size); + } + ENSURE_ASAN_INITED(); + if (FLAG_replace_intrin) { + ASAN_WRITE_RANGE(block, size); + } + return real_memset(block, c, size); +} + +// Note that on Linux index and strchr are definined differently depending on +// the compiler (gcc vs clang). +// see __CORRECT_ISO_CPP_STRING_H_PROTO in /usr/include/string.h + +#ifndef __APPLE__ +char *WRAP(index)(const char *str, int c) + __attribute__((alias(WRAPPER_NAME(strchr)))); +#endif + +char *WRAP(strchr)(const char *str, int c) { + ENSURE_ASAN_INITED(); + char *result = real_strchr(str, c); + if (FLAG_replace_str) { + size_t bytes_read = (result ? result - str : real_strlen(str)) + 1; + ASAN_READ_RANGE(str, bytes_read); + } + return result; +} + +int WRAP(strcasecmp)(const char *s1, const char *s2) { + ENSURE_ASAN_INITED(); + unsigned char c1, c2; + size_t i; + for (i = 0; ; i++) { + c1 = (unsigned char)s1[i]; + c2 = (unsigned char)s2[i]; + if (CharCaseCmp(c1, c2) != 0 || c1 == '\0') break; + } + ASAN_READ_RANGE(s1, i + 1); + ASAN_READ_RANGE(s2, i + 1); + return CharCaseCmp(c1, c2); +} + +char *WRAP(strcat)(char *to, const char *from) { // NOLINT + ENSURE_ASAN_INITED(); + if (FLAG_replace_str) { + size_t from_length = real_strlen(from); + ASAN_READ_RANGE(from, from_length + 1); + if (from_length > 0) { + size_t to_length = real_strlen(to); + ASAN_READ_RANGE(to, to_length); + ASAN_WRITE_RANGE(to + to_length, from_length + 1); + CHECK_RANGES_OVERLAP("strcat", to, to_length + 1, from, from_length + 1); + } + } + return real_strcat(to, from); +} + +int WRAP(strcmp)(const char *s1, const char *s2) { + // strcmp is called from malloc_default_purgeable_zone() + // in __asan::ReplaceSystemAlloc() on Mac. + if (asan_init_is_running) { + return real_strcmp(s1, s2); + } + unsigned char c1, c2; + size_t i; + for (i = 0; ; i++) { + c1 = (unsigned char)s1[i]; + c2 = (unsigned char)s2[i]; + if (c1 != c2 || c1 == '\0') break; + } + ASAN_READ_RANGE(s1, i + 1); + ASAN_READ_RANGE(s2, i + 1); + return CharCmp(c1, c2); +} + +char *WRAP(strcpy)(char *to, const char *from) { // NOLINT + // strcpy is called from malloc_default_purgeable_zone() + // in __asan::ReplaceSystemAlloc() on Mac. + if (asan_init_is_running) { + return real_strcpy(to, from); + } + ENSURE_ASAN_INITED(); + if (FLAG_replace_str) { + size_t from_size = real_strlen(from) + 1; + CHECK_RANGES_OVERLAP("strcpy", to, from_size, from, from_size); + ASAN_READ_RANGE(from, from_size); + ASAN_WRITE_RANGE(to, from_size); + } + return real_strcpy(to, from); +} + +char *WRAP(strdup)(const char *s) { + ENSURE_ASAN_INITED(); + if (FLAG_replace_str) { + size_t length = real_strlen(s); + ASAN_READ_RANGE(s, length + 1); + } + return real_strdup(s); +} + +size_t WRAP(strlen)(const char *s) { + // strlen is called from malloc_default_purgeable_zone() + // in __asan::ReplaceSystemAlloc() on Mac. + if (asan_init_is_running) { + return real_strlen(s); + } + ENSURE_ASAN_INITED(); + size_t length = real_strlen(s); + if (FLAG_replace_str) { + ASAN_READ_RANGE(s, length + 1); + } + return length; +} + +int WRAP(strncasecmp)(const char *s1, const char *s2, size_t size) { + ENSURE_ASAN_INITED(); + unsigned char c1 = 0, c2 = 0; + size_t i; + for (i = 0; i < size; i++) { + c1 = (unsigned char)s1[i]; + c2 = (unsigned char)s2[i]; + if (CharCaseCmp(c1, c2) != 0 || c1 == '\0') break; + } + ASAN_READ_RANGE(s1, Min(i + 1, size)); + ASAN_READ_RANGE(s2, Min(i + 1, size)); + return CharCaseCmp(c1, c2); +} + +int WRAP(strncmp)(const char *s1, const char *s2, size_t size) { + // strncmp is called from malloc_default_purgeable_zone() + // in __asan::ReplaceSystemAlloc() on Mac. + if (asan_init_is_running) { + return real_strncmp(s1, s2, size); + } + unsigned char c1 = 0, c2 = 0; + size_t i; + for (i = 0; i < size; i++) { + c1 = (unsigned char)s1[i]; + c2 = (unsigned char)s2[i]; + if (c1 != c2 || c1 == '\0') break; + } + ASAN_READ_RANGE(s1, Min(i + 1, size)); + ASAN_READ_RANGE(s2, Min(i + 1, size)); + return CharCmp(c1, c2); +} + +char *WRAP(strncpy)(char *to, const char *from, size_t size) { + ENSURE_ASAN_INITED(); + if (FLAG_replace_str) { + size_t from_size = Min(size, internal_strnlen(from, size) + 1); + CHECK_RANGES_OVERLAP("strncpy", to, from_size, from, from_size); + ASAN_READ_RANGE(from, from_size); + ASAN_WRITE_RANGE(to, size); + } + return real_strncpy(to, from, size); +} + +#ifndef __APPLE__ +size_t WRAP(strnlen)(const char *s, size_t maxlen) { + ENSURE_ASAN_INITED(); + size_t length = real_strnlen(s, maxlen); + if (FLAG_replace_str) { + ASAN_READ_RANGE(s, Min(length + 1, maxlen)); + } + return length; +} +#endif diff --git a/lib/asan/asan_interceptors.h b/lib/asan/asan_interceptors.h new file mode 100644 index 0000000..07b9420 --- /dev/null +++ b/lib/asan/asan_interceptors.h @@ -0,0 +1,134 @@ +//===-- asan_interceptors.h -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header for asan_interceptors.cc +//===----------------------------------------------------------------------===// +#ifndef ASAN_INTERCEPTORS_H +#define ASAN_INTERCEPTORS_H + +#include "asan_internal.h" + +// To replace weak system functions on Linux we just need to declare functions +// with same names in our library and then obtain the real function pointers +// using dlsym(). This is not so on Mac OS, where the two-level namespace makes +// our replacement functions invisible to other libraries. This may be overcomed +// using the DYLD_FORCE_FLAT_NAMESPACE, but some errors loading the shared +// libraries in Chromium were noticed when doing so. +// Instead we use mach_override, a handy framework for patching functions at +// runtime. To avoid possible name clashes, our replacement functions have +// the "wrap_" prefix on Mac. +// +// After interception, the calls to system functions will be substituted by +// calls to our interceptors. We store pointers to system function f() +// in __asan::real_f(). +// +// TODO(glider): mach_override_ptr() tends to spend too much time +// in allocateBranchIsland(). This should be ok for real-word +// application, but slows down our tests which fork too many children. +#ifdef __APPLE__ +#include "mach_override/mach_override.h" +#define WRAP(x) wrap_##x +#define WRAPPER_NAME(x) "wrap_"#x + +#define OVERRIDE_FUNCTION(oldfunc, newfunc) \ + CHECK(0 == __asan_mach_override_ptr((void*)(oldfunc), \ + (void*)(newfunc), \ + (void**)&real_##oldfunc)); \ + CHECK(real_##oldfunc != NULL); + +#define OVERRIDE_FUNCTION_IF_EXISTS(oldfunc, newfunc) \ + do { __asan_mach_override_ptr((void*)(oldfunc), \ + (void*)(newfunc), \ + (void**)&real_##oldfunc); } while (0) + +#define INTERCEPT_FUNCTION(func) \ + OVERRIDE_FUNCTION(func, WRAP(func)) + +#define INTERCEPT_FUNCTION_IF_EXISTS(func) \ + OVERRIDE_FUNCTION_IF_EXISTS(func, WRAP(func)) + +#else // __linux__ +#define WRAP(x) x +#define WRAPPER_NAME(x) #x + +#define INTERCEPT_FUNCTION(func) \ + CHECK((real_##func = (func##_f)dlsym(RTLD_NEXT, #func))); + +#define INTERCEPT_FUNCTION_IF_EXISTS(func) \ + do { real_##func = (func##_f)dlsym(RTLD_NEXT, #func); } while (0) +#endif + +#ifdef __APPLE__ +int WRAP(memcmp)(const void *a1, const void *a2, size_t size); +void *WRAP(memcpy)(void *to, const void *from, size_t size); +void *WRAP(memmove)(void *to, const void *from, size_t size); +void *WRAP(memset)(void *block, int c, size_t size); +int WRAP(strcasecmp)(const char *s1, const char *s2); +char *WRAP(strcat)(char *to, const char *from); // NOLINT +char *WRAP(strchr)(const char *string, int c); +int WRAP(strcmp)(const char *s1, const char *s2); +char *WRAP(strcpy)(char *to, const char *from); // NOLINT +char *WRAP(strdup)(const char *s); +size_t WRAP(strlen)(const char *s); +int WRAP(strncasecmp)(const char *s1, const char *s2, size_t n); +int WRAP(strncmp)(const char *s1, const char *s2, size_t size); +char *WRAP(strncpy)(char *to, const char *from, size_t size); +#endif + +namespace __asan { + +typedef void* (*index_f)(const char *string, int c); +typedef int (*memcmp_f)(const void *a1, const void *a2, size_t size); +typedef void* (*memcpy_f)(void *to, const void *from, size_t size); +typedef void* (*memmove_f)(void *to, const void *from, size_t size); +typedef void* (*memset_f)(void *block, int c, size_t size); +typedef int (*strcasecmp_f)(const char *s1, const char *s2); +typedef char* (*strcat_f)(char *to, const char *from); +typedef char* (*strchr_f)(const char *str, int c); +typedef int (*strcmp_f)(const char *s1, const char *s2); +typedef char* (*strcpy_f)(char *to, const char *from); +typedef char* (*strdup_f)(const char *s); +typedef size_t (*strlen_f)(const char *s); +typedef int (*strncasecmp_f)(const char *s1, const char *s2, size_t n); +typedef int (*strncmp_f)(const char *s1, const char *s2, size_t size); +typedef char* (*strncpy_f)(char *to, const char *from, size_t size); +typedef size_t (*strnlen_f)(const char *s, size_t maxlen); + +// __asan::real_X() holds pointer to library implementation of X(). +extern index_f real_index; +extern memcmp_f real_memcmp; +extern memcpy_f real_memcpy; +extern memmove_f real_memmove; +extern memset_f real_memset; +extern strcasecmp_f real_strcasecmp; +extern strcat_f real_strcat; +extern strchr_f real_strchr; +extern strcmp_f real_strcmp; +extern strcpy_f real_strcpy; +extern strdup_f real_strdup; +extern strlen_f real_strlen; +extern strncasecmp_f real_strncasecmp; +extern strncmp_f real_strncmp; +extern strncpy_f real_strncpy; +extern strnlen_f real_strnlen; + +// __asan::internal_X() is the implementation of X() for use in RTL. +size_t internal_strlen(const char *s); +size_t internal_strnlen(const char *s, size_t maxlen); +void* internal_memchr(const void* s, int c, size_t n); +int internal_memcmp(const void* s1, const void* s2, size_t n); + +// Initializes pointers to str*/mem* functions. +void InitializeAsanInterceptors(); + +} // namespace __asan + +#endif // ASAN_INTERCEPTORS_H diff --git a/lib/asan/asan_interface.h b/lib/asan/asan_interface.h new file mode 100644 index 0000000..7506586 --- /dev/null +++ b/lib/asan/asan_interface.h @@ -0,0 +1,135 @@ +//===-- asan_interface.h ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// This header can be included by the instrumented program to fetch +// data (mostly allocator statistics) from ASan runtime library. +//===----------------------------------------------------------------------===// +#ifndef ASAN_INTERFACE_H +#define ASAN_INTERFACE_H + +#include // for __WORDSIZE +#include // for size_t + +// This header should NOT include any other headers from ASan runtime. +// All functions in this header are extern "C" and start with __asan_. + +extern "C" { + // This function should be called at the very beginning of the process, + // before any instrumented code is executed and before any call to malloc. + void __asan_init() + __attribute__((visibility("default"))); + + // This function should be called by the instrumented code. + // 'addr' is the address of a global variable called 'name' of 'size' bytes. + void __asan_register_global(uintptr_t addr, size_t size, const char *name) + __attribute__((visibility("default"))); + + // This structure describes an instrumented global variable. + struct __asan_global { + size_t beg; // The address of the global. + size_t size; // The original size of the global. + size_t size_with_redzone; // The size with the redzone. + const char *name; // Name as a C string. + }; + + // These two functions should be called by the instrumented code. + // 'globals' is an array of structures describing 'n' globals. + void __asan_register_globals(__asan_global *globals, size_t n) + __attribute__((visibility("default"))); + void __asan_unregister_globals(__asan_global *globals, size_t n) + __attribute__((visibility("default"))); + + // These two functions are used by the instrumented code in the + // use-after-return mode. __asan_stack_malloc allocates size bytes of + // fake stack and __asan_stack_free poisons it. real_stack is a pointer to + // the real stack region. + size_t __asan_stack_malloc(size_t size, size_t real_stack) + __attribute__((visibility("default"))); + void __asan_stack_free(size_t ptr, size_t size, size_t real_stack) + __attribute__((visibility("default"))); + + // Marks memory region [addr, addr+size) as unaddressable. + // This memory must be previously allocated by the user program. Accessing + // addresses in this region from instrumented code is forbidden until + // this region is unpoisoned. This function is not guaranteed to poison + // the whole region - it may poison only subregion of [addr, addr+size) due + // to ASan alignment restrictions. + // Method is NOT thread-safe in the sense that no two threads can + // (un)poison memory in the same memory region simultaneously. + void __asan_poison_memory_region(void const volatile *addr, size_t size); + // Marks memory region [addr, addr+size) as addressable. + // This memory must be previously allocated by the user program. Accessing + // addresses in this region is allowed until this region is poisoned again. + // This function may unpoison a superregion of [addr, addr+size) due to + // ASan alignment restrictions. + // Method is NOT thread-safe in the sense that no two threads can + // (un)poison memory in the same memory region simultaneously. + void __asan_unpoison_memory_region(void const volatile *addr, size_t size); + +// User code should use macro instead of functions. +#if defined(__has_feature) && __has_feature(address_sanitizer) +#define ASAN_POISON_MEMORY_REGION(addr, size) \ + __asan_poison_memory_region((addr), (size)) +#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \ + __asan_unpoison_memory_region((addr), (size)) +#else +#define ASAN_POISON_MEMORY_REGION(addr, size) \ + ((void)(addr), (void)(size)) +#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \ + ((void)(addr), (void)(size)) +#endif + + // Returns true iff addr is poisoned (i.e. 1-byte read/write access to this + // address will result in error report from AddressSanitizer). + bool __asan_address_is_poisoned(void const volatile *addr); + + // This is an internal function that is called to report an error. + // However it is still a part of the interface because users may want to + // set a breakpoint on this function in a debugger. + void __asan_report_error(uintptr_t pc, uintptr_t bp, uintptr_t sp, + uintptr_t addr, bool is_write, size_t access_size) + __attribute__((visibility("default"))); + + // Sets the exit code to use when reporting an error. + // Returns the old value. + int __asan_set_error_exit_code(int exit_code); + + // Returns the estimated number of bytes that will be reserved by allocator + // for request of "size" bytes. If ASan allocator can't allocate that much + // memory, returns the maximal possible allocation size, otherwise returns + // "size". + size_t __asan_get_estimated_allocated_size(size_t size); + // Returns true if p is NULL or if p was returned by the ASan allocator and + // is not yet freed. + bool __asan_get_ownership(const void *p); + // Returns the number of bytes reserved for the pointer p. + // Requires (get_ownership(p) == true). + size_t __asan_get_allocated_size(const void *p); + // Number of bytes, allocated and not yet freed by the application. + size_t __asan_get_current_allocated_bytes(); + // Number of bytes, mmaped by asan allocator to fulfill allocation requests. + // Generally, for request of X bytes, allocator can reserve and add to free + // lists a large number of chunks of size X to use them for future requests. + // All these chunks count toward the heap size. Currently, allocator never + // releases memory to OS (instead, it just puts freed chunks to free lists). + size_t __asan_get_heap_size(); + // Number of bytes, mmaped by asan allocator, which can be used to fulfill + // allocation requests. When a user program frees memory chunk, it can first + // fall into quarantine and will count toward __asan_get_free_bytes() later. + size_t __asan_get_free_bytes(); + // Number of bytes in unmapped pages, that are released to OS. Currently, + // always returns 0. + size_t __asan_get_unmapped_bytes(); + // Prints accumulated stats to stderr. Used for debugging. + void __asan_print_accumulated_stats(); +} // namespace + +#endif // ASAN_INTERFACE_H diff --git a/lib/asan/asan_internal.h b/lib/asan/asan_internal.h new file mode 100644 index 0000000..d0790a7 --- /dev/null +++ b/lib/asan/asan_internal.h @@ -0,0 +1,239 @@ +//===-- asan_internal.h -----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header which defines various general utilities. +//===----------------------------------------------------------------------===// +#ifndef ASAN_INTERNAL_H +#define ASAN_INTERNAL_H + +#if !defined(__linux__) && !defined(__APPLE__) +# error "This operating system is not supported by AddressSanitizer" +#endif + +#include // for __WORDSIZE +#include // for size_t +#include // for _exit + +// If __WORDSIZE was undefined by the platform, define it in terms of the +// compiler built-in __LP64__. +#ifndef __WORDSIZE +#if __LP64__ +#define __WORDSIZE 64 +#else +#define __WORDSIZE 32 +#endif +#endif + +#ifdef ANDROID +#include +#endif + +#if defined(__has_feature) && __has_feature(address_sanitizer) +# error "The AddressSanitizer run-time should not be" + " instrumented by AddressSanitizer" +#endif + +// Build-time configuration options. + +// If set, sysinfo/sysinfo.h will be used to iterate over /proc/maps. +#ifndef ASAN_USE_SYSINFO +# define ASAN_USE_SYSINFO 1 +#endif + +// If set, asan will install its own SEGV signal handler. +#ifndef ASAN_NEEDS_SEGV +# define ASAN_NEEDS_SEGV 1 +#endif + +// If set, asan will intercept C++ exception api call(s). +#ifndef ASAN_HAS_EXCEPTIONS +# define ASAN_HAS_EXCEPTIONS 1 +#endif + +// If set, asan uses the values of SHADOW_SCALE and SHADOW_OFFSET +// provided by the instrumented objects. Otherwise constants are used. +#ifndef ASAN_FLEXIBLE_MAPPING_AND_OFFSET +# define ASAN_FLEXIBLE_MAPPING_AND_OFFSET 0 +#endif + +// All internal functions in asan reside inside the __asan namespace +// to avoid namespace collisions with the user programs. +// Seperate namespace also makes it simpler to distinguish the asan run-time +// functions from the instrumented user code in a profile. +namespace __asan { + +class AsanThread; +struct AsanStackTrace; + +// asan_rtl.cc +void CheckFailed(const char *cond, const char *file, int line); +void ShowStatsAndAbort(); + +// asan_globals.cc +bool DescribeAddrIfGlobal(uintptr_t addr); + +// asan_malloc_linux.cc / asan_malloc_mac.cc +void ReplaceSystemMalloc(); + +void OutOfMemoryMessageAndDie(const char *mem_type, size_t size); + +// asan_linux.cc / asan_mac.cc +void *AsanDoesNotSupportStaticLinkage(); +int AsanOpenReadonly(const char* filename); + +void *AsanMmapFixedNoReserve(uintptr_t fixed_addr, size_t size); +void *AsanMmapFixedReserve(uintptr_t fixed_addr, size_t size); +void *AsanMprotect(uintptr_t fixed_addr, size_t size); +void *AsanMmapSomewhereOrDie(size_t size, const char *where); +void AsanUnmapOrDie(void *ptr, size_t size); + +ssize_t AsanRead(int fd, void *buf, size_t count); +ssize_t AsanWrite(int fd, const void *buf, size_t count); +int AsanClose(int fd); + +// asan_printf.cc +void RawWrite(const char *buffer); +int SNPrint(char *buffer, size_t length, const char *format, ...); +void Printf(const char *format, ...); +void Report(const char *format, ...); + +// Don't use std::min and std::max, to minimize dependency on libstdc++. +template T Min(T a, T b) { return a < b ? a : b; } +template T Max(T a, T b) { return a > b ? a : b; } + +// asan_poisoning.cc +// Poisons the shadow memory for "size" bytes starting from "addr". +void PoisonShadow(uintptr_t addr, size_t size, uint8_t value); +// Poisons the shadow memory for "redzone_size" bytes starting from +// "addr + size". +void PoisonShadowPartialRightRedzone(uintptr_t addr, + uintptr_t size, + uintptr_t redzone_size, + uint8_t value); + +extern size_t FLAG_quarantine_size; +extern int FLAG_demangle; +extern bool FLAG_symbolize; +extern int FLAG_v; +extern size_t FLAG_redzone; +extern int FLAG_debug; +extern bool FLAG_poison_shadow; +extern int FLAG_report_globals; +extern size_t FLAG_malloc_context_size; +extern bool FLAG_replace_str; +extern bool FLAG_replace_intrin; +extern bool FLAG_replace_cfallocator; +extern bool FLAG_fast_unwind; +extern bool FLAG_use_fake_stack; +extern size_t FLAG_max_malloc_fill_size; +extern int FLAG_exitcode; +extern bool FLAG_allow_user_poisoning; + +extern int asan_inited; +// Used to avoid infinite recursion in __asan_init(). +extern bool asan_init_is_running; + +enum LinkerInitialized { LINKER_INITIALIZED = 0 }; + +#ifndef ASAN_DIE +#define ASAN_DIE _exit(FLAG_exitcode) +#endif // ASAN_DIE + +#define CHECK(cond) do { if (!(cond)) { \ + CheckFailed(#cond, __FILE__, __LINE__); \ +}}while(0) + +#define RAW_CHECK_MSG(expr, msg) do { \ + if (!(expr)) { \ + RawWrite(msg); \ + ASAN_DIE; \ + } \ +} while (0) + +#define RAW_CHECK(expr) RAW_CHECK_MSG(expr, #expr) + +#define UNIMPLEMENTED() CHECK("unimplemented" && 0) + +#define ASAN_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + +const size_t kWordSize = __WORDSIZE / 8; +const size_t kWordSizeInBits = 8 * kWordSize; +const size_t kPageSizeBits = 12; +const size_t kPageSize = 1UL << kPageSizeBits; + +#define GET_CALLER_PC() (uintptr_t)__builtin_return_address(0) +#define GET_CURRENT_FRAME() (uintptr_t)__builtin_frame_address(0) + +#define GET_BP_PC_SP \ + uintptr_t bp = GET_CURRENT_FRAME(); \ + uintptr_t pc = GET_CALLER_PC(); \ + uintptr_t local_stack; \ + uintptr_t sp = (uintptr_t)&local_stack; + +// These magic values are written to shadow for better error reporting. +const int kAsanHeapLeftRedzoneMagic = 0xfa; +const int kAsanHeapRightRedzoneMagic = 0xfb; +const int kAsanHeapFreeMagic = 0xfd; +const int kAsanStackLeftRedzoneMagic = 0xf1; +const int kAsanStackMidRedzoneMagic = 0xf2; +const int kAsanStackRightRedzoneMagic = 0xf3; +const int kAsanStackPartialRedzoneMagic = 0xf4; +const int kAsanStackAfterReturnMagic = 0xf5; +const int kAsanUserPoisonedMemoryMagic = 0xf7; +const int kAsanGlobalRedzoneMagic = 0xf9; +const int kAsanInternalHeapMagic = 0xfe; + +static const uintptr_t kCurrentStackFrameMagic = 0x41B58AB3; +static const uintptr_t kRetiredStackFrameMagic = 0x45E0360E; + +// --------------------------- Bit twiddling ------- {{{1 +inline bool IsPowerOfTwo(size_t x) { + return (x & (x - 1)) == 0; +} + +inline size_t RoundUpTo(size_t size, size_t boundary) { + CHECK(IsPowerOfTwo(boundary)); + return (size + boundary - 1) & ~(boundary - 1); +} + +// -------------------------- LowLevelAllocator ----- {{{1 +// A simple low-level memory allocator for internal use. +class LowLevelAllocator { + public: + explicit LowLevelAllocator(LinkerInitialized) {} + // 'size' must be a power of two. + // Requires an external lock. + void *Allocate(size_t size); + private: + char *allocated_end_; + char *allocated_current_; +}; + +// -------------------------- Atomic ---------------- {{{1 +static inline int AtomicInc(int *a) { +#ifdef ANDROID + return __atomic_inc(a) + 1; +#else + return __sync_add_and_fetch(a, 1); +#endif +} + +static inline int AtomicDec(int *a) { +#ifdef ANDROID + return __atomic_dec(a) - 1; +#else + return __sync_add_and_fetch(a, -1); +#endif +} + +} // namespace __asan + +#endif // ASAN_INTERNAL_H diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc new file mode 100644 index 0000000..26a08ae --- /dev/null +++ b/lib/asan/asan_linux.cc @@ -0,0 +1,101 @@ +//===-- asan_linux.cc -----------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Linux-specific details. +//===----------------------------------------------------------------------===// +#ifdef __linux__ + +#include "asan_internal.h" + +#include +#include +#include +#include +#include + +extern char _DYNAMIC[]; + +namespace __asan { + +void *AsanDoesNotSupportStaticLinkage() { + // This will fail to link with -static. + return &_DYNAMIC; +} + +static void *asan_mmap(void *addr, size_t length, int prot, int flags, + int fd, uint64_t offset) { +# if __WORDSIZE == 64 + return (void *)syscall(__NR_mmap, addr, length, prot, flags, fd, offset); +# else + return (void *)syscall(__NR_mmap2, addr, length, prot, flags, fd, offset); +# endif +} + +void *AsanMmapSomewhereOrDie(size_t size, const char *mem_type) { + size = RoundUpTo(size, kPageSize); + void *res = asan_mmap(0, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (res == (void*)-1) { + OutOfMemoryMessageAndDie(mem_type, size); + } + return res; +} + +void *AsanMmapFixedNoReserve(uintptr_t fixed_addr, size_t size) { + return asan_mmap((void*)fixed_addr, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE, + 0, 0); +} + +void *AsanMmapFixedReserve(uintptr_t fixed_addr, size_t size) { + return asan_mmap((void*)fixed_addr, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON | MAP_FIXED, + 0, 0); +} + +void *AsanMprotect(uintptr_t fixed_addr, size_t size) { + return asan_mmap((void*)fixed_addr, size, + PROT_NONE, + MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE, + 0, 0); +} + +void AsanUnmapOrDie(void *addr, size_t size) { + if (!addr || !size) return; + int res = syscall(__NR_munmap, addr, size); + if (res != 0) { + Report("Failed to unmap\n"); + ASAN_DIE; + } +} + +ssize_t AsanWrite(int fd, const void *buf, size_t count) { + return (ssize_t)syscall(__NR_write, fd, buf, count); +} + +int AsanOpenReadonly(const char* filename) { + return open(filename, O_RDONLY); +} + +ssize_t AsanRead(int fd, void *buf, size_t count) { + return (ssize_t)syscall(__NR_read, fd, buf, count); +} + +int AsanClose(int fd) { + return close(fd); +} + +} // namespace __asan + +#endif // __linux__ diff --git a/lib/asan/asan_lock.h b/lib/asan/asan_lock.h new file mode 100644 index 0000000..030fae6 --- /dev/null +++ b/lib/asan/asan_lock.h @@ -0,0 +1,100 @@ +//===-- asan_lock.h ---------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// A wrapper for a simple lock. +//===----------------------------------------------------------------------===// +#ifndef ASAN_LOCK_H +#define ASAN_LOCK_H + +#include "asan_internal.h" + +// The locks in ASan are global objects and they are never destroyed to avoid +// at-exit races (that is, a lock is being used by other threads while the main +// thread is doing atexit destructors). + +#ifdef __APPLE__ +#include + +#include +namespace __asan { +class AsanLock { + public: + explicit AsanLock(LinkerInitialized) : + mu_(OS_SPINLOCK_INIT), + owner_(0), + is_locked_(false) {} + + void Lock() { + CHECK(owner_ != pthread_self()); + OSSpinLockLock(&mu_); + is_locked_ = true; + owner_ = pthread_self(); + } + void Unlock() { + owner_ = 0; + is_locked_ = false; + OSSpinLockUnlock(&mu_); + } + + bool IsLocked() { + // This is not atomic, e.g. one thread may get different values if another + // one is about to release the lock. + return is_locked_; + } + private: + OSSpinLock mu_; + volatile pthread_t owner_; // for debugging purposes + bool is_locked_; // for silly malloc_introspection_t interface +}; +} // namespace __asan + +#else // assume linux +#include +namespace __asan { +class AsanLock { + public: + explicit AsanLock(LinkerInitialized) { + // We assume that pthread_mutex_t initialized to all zeroes is a valid + // unlocked mutex. We can not use PTHREAD_MUTEX_INITIALIZER as it triggers + // a gcc warning: + // extended initializer lists only available with -std=c++0x or -std=gnu++0x + } + void Lock() { + pthread_mutex_lock(&mu_); + // pthread_spin_lock(&mu_); + } + void Unlock() { + pthread_mutex_unlock(&mu_); + // pthread_spin_unlock(&mu_); + } + private: + pthread_mutex_t mu_; + // pthread_spinlock_t mu_; +}; +} // namespace __asan +#endif + +namespace __asan { +class ScopedLock { + public: + explicit ScopedLock(AsanLock *mu) : mu_(mu) { + mu_->Lock(); + } + ~ScopedLock() { + mu_->Unlock(); + } + private: + AsanLock *mu_; +}; + +} // namespace __asan + +#endif // ASAN_LOCK_H diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc new file mode 100644 index 0000000..b202e63 --- /dev/null +++ b/lib/asan/asan_mac.cc @@ -0,0 +1,311 @@ +//===-- asan_mac.cc -------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Mac-specific details. +//===----------------------------------------------------------------------===// + +#ifdef __APPLE__ + +#include "asan_mac.h" + +#include "asan_internal.h" +#include "asan_stack.h" +#include "asan_thread.h" +#include "asan_thread_registry.h" + +#include +#include +#include + +#include + +namespace __asan { + +extern dispatch_async_f_f real_dispatch_async_f; +extern dispatch_sync_f_f real_dispatch_sync_f; +extern dispatch_after_f_f real_dispatch_after_f; +extern dispatch_barrier_async_f_f real_dispatch_barrier_async_f; +extern dispatch_group_async_f_f real_dispatch_group_async_f; +extern pthread_workqueue_additem_np_f real_pthread_workqueue_additem_np; + +// No-op. Mac does not support static linkage anyway. +void *AsanDoesNotSupportStaticLinkage() { + return NULL; +} + +static void *asan_mmap(void *addr, size_t length, int prot, int flags, + int fd, uint64_t offset) { + return mmap(addr, length, prot, flags, fd, offset); +} + +ssize_t AsanWrite(int fd, const void *buf, size_t count) { + return write(fd, buf, count); +} + +void *AsanMmapSomewhereOrDie(size_t size, const char *mem_type) { + size = RoundUpTo(size, kPageSize); + void *res = asan_mmap(0, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (res == (void*)-1) { + OutOfMemoryMessageAndDie(mem_type, size); + } + return res; +} + +void *AsanMmapFixedNoReserve(uintptr_t fixed_addr, size_t size) { + return asan_mmap((void*)fixed_addr, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE, + 0, 0); +} + +void *AsanMmapFixedReserve(uintptr_t fixed_addr, size_t size) { + return asan_mmap((void*)fixed_addr, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON | MAP_FIXED, + 0, 0); +} + +void *AsanMprotect(uintptr_t fixed_addr, size_t size) { + return asan_mmap((void*)fixed_addr, size, + PROT_NONE, + MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE, + 0, 0); +} + +void AsanUnmapOrDie(void *addr, size_t size) { + if (!addr || !size) return; + int res = munmap(addr, size); + if (res != 0) { + Report("Failed to unmap\n"); + ASAN_DIE; + } +} + +int AsanOpenReadonly(const char* filename) { + return open(filename, O_RDONLY); +} + +ssize_t AsanRead(int fd, void *buf, size_t count) { + return read(fd, buf, count); +} + +int AsanClose(int fd) { + return close(fd); +} + +// Support for the following functions from libdispatch on Mac OS: +// dispatch_async_f() +// dispatch_async() +// dispatch_sync_f() +// dispatch_sync() +// dispatch_after_f() +// dispatch_after() +// dispatch_group_async_f() +// dispatch_group_async() +// TODO(glider): libdispatch API contains other functions that we don't support +// yet. +// +// dispatch_sync() and dispatch_sync_f() are synchronous, although chances are +// they can cause jobs to run on a thread different from the current one. +// TODO(glider): if so, we need a test for this (otherwise we should remove +// them). +// +// The following functions use dispatch_barrier_async_f() (which isn't a library +// function but is exported) and are thus supported: +// dispatch_source_set_cancel_handler_f() +// dispatch_source_set_cancel_handler() +// dispatch_source_set_event_handler_f() +// dispatch_source_set_event_handler() +// +// The reference manual for Grand Central Dispatch is available at +// http://developer.apple.com/library/mac/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html +// The implementation details are at +// http://libdispatch.macosforge.org/trac/browser/trunk/src/queue.c + +extern "C" +void asan_dispatch_call_block_and_release(void *block) { + GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false); + asan_block_context_t *context = (asan_block_context_t*)block; + if (FLAG_v >= 2) { + Report("asan_dispatch_call_block_and_release(): " + "context: %p, pthread_self: %p\n", + block, pthread_self()); + } + AsanThread *t = asanThreadRegistry().GetCurrent(); + if (t) { + // We've already executed a job on this worker thread. Let's reuse the + // AsanThread object. + if (t != asanThreadRegistry().GetMain()) { + // Flush the statistics and update the current thread's tid. + asanThreadRegistry().UnregisterThread(t); + asanThreadRegistry().RegisterThread(t, context->parent_tid, &stack); + } + // Otherwise the worker is being executed on the main thread -- we are + // draining the dispatch queue. + // TODO(glider): any checks for that? + } else { + // It's incorrect to assert that the current thread is not dying: at least + // the callbacks from dispatch_sync() are sometimes called after the TSD is + // destroyed. + t = (AsanThread*)asan_malloc(sizeof(AsanThread), &stack); + new(t) AsanThread(context->parent_tid, + /*start_routine*/NULL, /*arg*/NULL, &stack); + t->Init(); + asanThreadRegistry().SetCurrent(t); + } + // Call the original dispatcher for the block. + context->func(context->block); + asan_free(context, &stack); +} + +} // namespace __asan + +using namespace __asan; // NOLINT + +// Wrap |ctxt| and |func| into an asan_block_context_t. +// The caller retains control of the allocated context. +extern "C" +asan_block_context_t *alloc_asan_context(void *ctxt, dispatch_function_t func, + AsanStackTrace *stack) { + asan_block_context_t *asan_ctxt = + (asan_block_context_t*) asan_malloc(sizeof(asan_block_context_t), stack); + asan_ctxt->block = ctxt; + asan_ctxt->func = func; + AsanThread *curr_thread = asanThreadRegistry().GetCurrent(); + if (FLAG_debug) { + // Sometimes at Chromium teardown this assertion is violated: + // -- a task is created via dispatch_async() on the "CFMachPort" + // thread while doing _dispatch_queue_drain(); + // -- a task is created via dispatch_async_f() on the + // "com.apple.root.default-overcommit-priority" thread while doing + // _dispatch_dispose(). + // TODO(glider): find out what's going on. + CHECK(curr_thread || asanThreadRegistry().IsCurrentThreadDying()); + } + asan_ctxt->parent_tid = asanThreadRegistry().GetCurrentTidOrMinusOne(); + return asan_ctxt; +} + +// TODO(glider): can we reduce code duplication by introducing a macro? +extern "C" +int WRAP(dispatch_async_f)(dispatch_queue_t dq, + void *ctxt, + dispatch_function_t func) { + GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false); + asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); + if (FLAG_v >= 2) { + Report("dispatch_async_f(): context: %p, pthread_self: %p\n", + asan_ctxt, pthread_self()); + PRINT_CURRENT_STACK(); + } + return real_dispatch_async_f(dq, (void*)asan_ctxt, + asan_dispatch_call_block_and_release); +} + +extern "C" +int WRAP(dispatch_sync_f)(dispatch_queue_t dq, + void *ctxt, + dispatch_function_t func) { + GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false); + asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); + if (FLAG_v >= 2) { + Report("dispatch_sync_f(): context: %p, pthread_self: %p\n", + asan_ctxt, pthread_self()); + PRINT_CURRENT_STACK(); + } + return real_dispatch_sync_f(dq, (void*)asan_ctxt, + asan_dispatch_call_block_and_release); +} + +extern "C" +int WRAP(dispatch_after_f)(dispatch_time_t when, + dispatch_queue_t dq, + void *ctxt, + dispatch_function_t func) { + GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false); + asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); + if (FLAG_v >= 2) { + Report("dispatch_after_f: %p\n", asan_ctxt); + PRINT_CURRENT_STACK(); + } + return real_dispatch_after_f(when, dq, (void*)asan_ctxt, + asan_dispatch_call_block_and_release); +} + +extern "C" +void WRAP(dispatch_barrier_async_f)(dispatch_queue_t dq, + void *ctxt, dispatch_function_t func) { + GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false); + asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); + if (FLAG_v >= 2) { + Report("dispatch_barrier_async_f(): context: %p, pthread_self: %p\n", + asan_ctxt, pthread_self()); + PRINT_CURRENT_STACK(); + } + real_dispatch_barrier_async_f(dq, (void*)asan_ctxt, + asan_dispatch_call_block_and_release); +} + +extern "C" +void WRAP(dispatch_group_async_f)(dispatch_group_t group, + dispatch_queue_t dq, + void *ctxt, dispatch_function_t func) { + GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false); + asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); + if (FLAG_v >= 2) { + Report("dispatch_group_async_f(): context: %p, pthread_self: %p\n", + asan_ctxt, pthread_self()); + PRINT_CURRENT_STACK(); + } + real_dispatch_group_async_f(group, dq, (void*)asan_ctxt, + asan_dispatch_call_block_and_release); +} + +// The following stuff has been extremely helpful while looking for the +// unhandled functions that spawned jobs on Chromium shutdown. If the verbosity +// level is 2 or greater, we wrap pthread_workqueue_additem_np() in order to +// find the points of worker thread creation (each of such threads may be used +// to run several tasks, that's why this is not enough to support the whole +// libdispatch API. +extern "C" +void *wrap_workitem_func(void *arg) { + if (FLAG_v >= 2) { + Report("wrap_workitem_func: %p, pthread_self: %p\n", arg, pthread_self()); + } + asan_block_context_t *ctxt = (asan_block_context_t*)arg; + worker_t fn = (worker_t)(ctxt->func); + void *result = fn(ctxt->block); + GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false); + asan_free(arg, &stack); + return result; +} + +extern "C" +int WRAP(pthread_workqueue_additem_np)(pthread_workqueue_t workq, + void *(*workitem_func)(void *), void * workitem_arg, + pthread_workitem_handle_t * itemhandlep, unsigned int *gencountp) { + GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false); + asan_block_context_t *asan_ctxt = + (asan_block_context_t*) asan_malloc(sizeof(asan_block_context_t), &stack); + asan_ctxt->block = workitem_arg; + asan_ctxt->func = (dispatch_function_t)workitem_func; + asan_ctxt->parent_tid = asanThreadRegistry().GetCurrentTidOrMinusOne(); + if (FLAG_v >= 2) { + Report("pthread_workqueue_additem_np: %p\n", asan_ctxt); + PRINT_CURRENT_STACK(); + } + return real_pthread_workqueue_additem_np(workq, wrap_workitem_func, asan_ctxt, + itemhandlep, gencountp); +} + +#endif // __APPLE__ diff --git a/lib/asan/asan_mac.h b/lib/asan/asan_mac.h new file mode 100644 index 0000000..32739e7 --- /dev/null +++ b/lib/asan/asan_mac.h @@ -0,0 +1,87 @@ +//===-- asan_mac.h ----------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header for asan_mac.cc +//===----------------------------------------------------------------------===// +#ifdef __APPLE__ + +#ifndef ASAN_MAC_H +#define ASAN_MAC_H + +#include "asan_interceptors.h" + +// TODO(glider): need to check if the OS X version is 10.6 or greater. +#include +#include + +typedef void* pthread_workqueue_t; +typedef void* pthread_workitem_handle_t; + +typedef void (*dispatch_function_t)(void *block); +typedef void* (*worker_t)(void *block); +typedef int (*dispatch_async_f_f)(dispatch_queue_t dq, void *ctxt, + dispatch_function_t func); +typedef int (*dispatch_sync_f_f)(dispatch_queue_t dq, void *ctxt, + dispatch_function_t func); +typedef int (*dispatch_after_f_f)(dispatch_time_t when, + dispatch_queue_t dq, void *ctxt, + dispatch_function_t func); +typedef void (*dispatch_barrier_async_f_f)(dispatch_queue_t dq, + void *ctxt, + dispatch_function_t func); +typedef void (*dispatch_group_async_f_f)(dispatch_group_t group, + dispatch_queue_t dq, + void *ctxt, dispatch_function_t func); +typedef int (*pthread_workqueue_additem_np_f)(pthread_workqueue_t workq, + void *(*workitem_func)(void *), void * workitem_arg, + pthread_workitem_handle_t * itemhandlep, unsigned int *gencountp); + + +// A wrapper for the ObjC blocks used to support libdispatch. +typedef struct { + void *block; + dispatch_function_t func; + int parent_tid; +} asan_block_context_t; + + +extern "C" { +// dispatch_barrier_async_f() is not declared in . +void dispatch_barrier_async_f(dispatch_queue_t dq, + void *ctxt, dispatch_function_t func); +// Neither is pthread_workqueue_additem_np(). +int pthread_workqueue_additem_np(pthread_workqueue_t workq, + void *(*workitem_func)(void *), void * workitem_arg, + pthread_workitem_handle_t * itemhandlep, unsigned int *gencountp); + +int WRAP(dispatch_async_f)(dispatch_queue_t dq, + void *ctxt, + dispatch_function_t func); +int WRAP(dispatch_sync_f)(dispatch_queue_t dq, + void *ctxt, + dispatch_function_t func); +int WRAP(dispatch_after_f)(dispatch_time_t when, + dispatch_queue_t dq, + void *ctxt, + dispatch_function_t func); +void WRAP(dispatch_barrier_async_f)(dispatch_queue_t dq, + void *ctxt, dispatch_function_t func); +void WRAP(dispatch_group_async_f)(dispatch_group_t group, + dispatch_queue_t dq, + void *ctxt, dispatch_function_t func); +int WRAP(pthread_workqueue_additem_np)(pthread_workqueue_t workq, + void *(*workitem_func)(void *), void * workitem_arg, + pthread_workitem_handle_t * itemhandlep, unsigned int *gencountp); +} + +#endif // ASAN_MAC_H + +#endif // __APPLE__ diff --git a/lib/asan/asan_malloc_linux.cc b/lib/asan/asan_malloc_linux.cc new file mode 100644 index 0000000..9dbc7a1 --- /dev/null +++ b/lib/asan/asan_malloc_linux.cc @@ -0,0 +1,142 @@ +//===-- asan_malloc_linux.cc ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Linux-specific malloc interception. +// We simply define functions like malloc, free, realloc, etc. +// They will replace the corresponding libc functions automagically. +//===----------------------------------------------------------------------===// +#ifdef __linux__ + +#include "asan_allocator.h" +#include "asan_interceptors.h" +#include "asan_internal.h" +#include "asan_stack.h" + +#include + +#define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default"))) + +#ifdef ANDROID +struct MallocDebug { + void* (*malloc)(size_t bytes); + void (*free)(void* mem); + void* (*calloc)(size_t n_elements, size_t elem_size); + void* (*realloc)(void* oldMem, size_t bytes); + void* (*memalign)(size_t alignment, size_t bytes); +}; + +const MallocDebug asan_malloc_dispatch __attribute__((aligned(32))) = { + malloc, free, calloc, realloc, memalign +}; + +extern "C" const MallocDebug* __libc_malloc_dispatch; + +namespace __asan { +void ReplaceSystemMalloc() { + __libc_malloc_dispatch = &asan_malloc_dispatch; +} +} // namespace __asan + +#else // ANDROID + +namespace __asan { +void ReplaceSystemMalloc() { +} +} // namespace __asan +#endif // ANDROID + +// ---------------------- Replacement functions ---------------- {{{1 +using namespace __asan; // NOLINT + +extern "C" { +INTERCEPTOR_ATTRIBUTE +void free(void *ptr) { + GET_STACK_TRACE_HERE_FOR_FREE(ptr); + asan_free(ptr, &stack); +} + +INTERCEPTOR_ATTRIBUTE +void cfree(void *ptr) { + GET_STACK_TRACE_HERE_FOR_FREE(ptr); + asan_free(ptr, &stack); +} + +INTERCEPTOR_ATTRIBUTE +void *malloc(size_t size) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_malloc(size, &stack); +} + +INTERCEPTOR_ATTRIBUTE +void *calloc(size_t nmemb, size_t size) { + if (!asan_inited) { + // Hack: dlsym calls calloc before real_calloc is retrieved from dlsym. + const size_t kCallocPoolSize = 1024; + static uintptr_t calloc_memory_for_dlsym[kCallocPoolSize]; + static size_t allocated; + size_t size_in_words = ((nmemb * size) + kWordSize - 1) / kWordSize; + void *mem = (void*)&calloc_memory_for_dlsym[allocated]; + allocated += size_in_words; + CHECK(allocated < kCallocPoolSize); + return mem; + } + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_calloc(nmemb, size, &stack); +} + +INTERCEPTOR_ATTRIBUTE +void *realloc(void *ptr, size_t size) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_realloc(ptr, size, &stack); +} + +INTERCEPTOR_ATTRIBUTE +void *memalign(size_t boundary, size_t size) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_memalign(boundary, size, &stack); +} + +void* __libc_memalign(size_t align, size_t s) + __attribute__((alias("memalign"))); + +INTERCEPTOR_ATTRIBUTE +struct mallinfo mallinfo() { + struct mallinfo res; + real_memset(&res, 0, sizeof(res)); + return res; +} + +INTERCEPTOR_ATTRIBUTE +int mallopt(int cmd, int value) { + return -1; +} + +INTERCEPTOR_ATTRIBUTE +int posix_memalign(void **memptr, size_t alignment, size_t size) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + // Printf("posix_memalign: %lx %ld\n", alignment, size); + return asan_posix_memalign(memptr, alignment, size, &stack); +} + +INTERCEPTOR_ATTRIBUTE +void *valloc(size_t size) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_valloc(size, &stack); +} + +INTERCEPTOR_ATTRIBUTE +void *pvalloc(size_t size) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_pvalloc(size, &stack); +} +} // extern "C" + +#endif // __linux__ diff --git a/lib/asan/asan_malloc_mac.cc b/lib/asan/asan_malloc_mac.cc new file mode 100644 index 0000000..8a6f1bc --- /dev/null +++ b/lib/asan/asan_malloc_mac.cc @@ -0,0 +1,390 @@ +//===-- asan_rtl.cc ---------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Mac-specific malloc interception. +//===----------------------------------------------------------------------===// + +#ifdef __APPLE__ + +#include +#include +#include +#include + +#include "asan_allocator.h" +#include "asan_interceptors.h" +#include "asan_internal.h" +#include "asan_stack.h" + +// Similar code is used in Google Perftools, +// http://code.google.com/p/google-perftools. + +// ---------------------- Replacement functions ---------------- {{{1 +using namespace __asan; // NOLINT + +// The free() implementation provided by OS X calls malloc_zone_from_ptr() +// to find the owner of |ptr|. If the result is NULL, an invalid free() is +// reported. Our implementation falls back to asan_free() in this case +// in order to print an ASan-style report. +extern "C" +void free(void *ptr) { + malloc_zone_t *zone = malloc_zone_from_ptr(ptr); + if (zone) { +#if defined(MAC_OS_X_VERSION_10_6) && \ + MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 + if ((zone->version >= 6) && (zone->free_definite_size)) { + zone->free_definite_size(zone, ptr, malloc_size(ptr)); + } else { + malloc_zone_free(zone, ptr); + } +#else + malloc_zone_free(zone, ptr); +#endif + } else { + GET_STACK_TRACE_HERE_FOR_FREE(ptr); + asan_free(ptr, &stack); + } +} + +// TODO(glider): do we need both zones? +static malloc_zone_t *system_malloc_zone = NULL; +static malloc_zone_t *system_purgeable_zone = NULL; + +// We need to provide wrappers around all the libc functions. +namespace { +// TODO(glider): the mz_* functions should be united with the Linux wrappers, +// as they are basically copied from there. +size_t mz_size(malloc_zone_t* zone, const void* ptr) { + // Fast path: check whether this pointer belongs to the original malloc zone. + // We cannot just call malloc_zone_from_ptr(), because it in turn + // calls our mz_size(). + if (system_malloc_zone) { + if ((system_malloc_zone->size)(system_malloc_zone, ptr)) return 0; + } + return __asan_mz_size(ptr); +} + +void *mz_malloc(malloc_zone_t *zone, size_t size) { + if (!asan_inited) { + CHECK(system_malloc_zone); + return malloc_zone_malloc(system_malloc_zone, size); + } + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_malloc(size, &stack); +} + +void *cf_malloc(CFIndex size, CFOptionFlags hint, void *info) { + if (!asan_inited) { + CHECK(system_malloc_zone); + return malloc_zone_malloc(system_malloc_zone, size); + } + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_malloc(size, &stack); +} + +void *mz_calloc(malloc_zone_t *zone, size_t nmemb, size_t size) { + if (!asan_inited) { + // Hack: dlsym calls calloc before real_calloc is retrieved from dlsym. + const size_t kCallocPoolSize = 1024; + static uintptr_t calloc_memory_for_dlsym[kCallocPoolSize]; + static size_t allocated; + size_t size_in_words = ((nmemb * size) + kWordSize - 1) / kWordSize; + void *mem = (void*)&calloc_memory_for_dlsym[allocated]; + allocated += size_in_words; + CHECK(allocated < kCallocPoolSize); + return mem; + } + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_calloc(nmemb, size, &stack); +} + +void *mz_valloc(malloc_zone_t *zone, size_t size) { + if (!asan_inited) { + CHECK(system_malloc_zone); + return malloc_zone_valloc(system_malloc_zone, size); + } + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_memalign(kPageSize, size, &stack); +} + +void print_zone_for_ptr(void *ptr) { + malloc_zone_t *orig_zone = malloc_zone_from_ptr(ptr); + if (orig_zone) { + if (orig_zone->zone_name) { + Printf("malloc_zone_from_ptr(%p) = %p, which is %s\n", + ptr, orig_zone, orig_zone->zone_name); + } else { + Printf("malloc_zone_from_ptr(%p) = %p, which doesn't have a name\n", + ptr, orig_zone); + } + } else { + Printf("malloc_zone_from_ptr(%p) = NULL\n", ptr); + } +} + +// TODO(glider): the allocation callbacks need to be refactored. +void mz_free(malloc_zone_t *zone, void *ptr) { + if (!ptr) return; + malloc_zone_t *orig_zone = malloc_zone_from_ptr(ptr); + // For some reason Chromium calls mz_free() for pointers that belong to + // DefaultPurgeableMallocZone instead of asan_zone. We might want to + // fix this someday. + if (orig_zone == system_purgeable_zone) { + system_purgeable_zone->free(system_purgeable_zone, ptr); + return; + } + if (__asan_mz_size(ptr)) { + GET_STACK_TRACE_HERE_FOR_FREE(ptr); + asan_free(ptr, &stack); + } else { + // Let us just leak this memory for now. + Printf("mz_free(%p) -- attempting to free unallocated memory.\n" + "AddressSanitizer is ignoring this error on Mac OS now.\n", ptr); + print_zone_for_ptr(ptr); + GET_STACK_TRACE_HERE_FOR_FREE(ptr); + stack.PrintStack(); + return; + } +} + +void cf_free(void *ptr, void *info) { + if (!ptr) return; + malloc_zone_t *orig_zone = malloc_zone_from_ptr(ptr); + // For some reason Chromium calls mz_free() for pointers that belong to + // DefaultPurgeableMallocZone instead of asan_zone. We might want to + // fix this someday. + if (orig_zone == system_purgeable_zone) { + system_purgeable_zone->free(system_purgeable_zone, ptr); + return; + } + if (__asan_mz_size(ptr)) { + GET_STACK_TRACE_HERE_FOR_FREE(ptr); + asan_free(ptr, &stack); + } else { + // Let us just leak this memory for now. + Printf("cf_free(%p) -- attempting to free unallocated memory.\n" + "AddressSanitizer is ignoring this error on Mac OS now.\n", ptr); + print_zone_for_ptr(ptr); + GET_STACK_TRACE_HERE_FOR_FREE(ptr); + stack.PrintStack(); + return; + } +} + +void *mz_realloc(malloc_zone_t *zone, void *ptr, size_t size) { + if (!ptr) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_malloc(size, &stack); + } else { + if (__asan_mz_size(ptr)) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_realloc(ptr, size, &stack); + } else { + // We can't recover from reallocating an unknown address, because + // this would require reading at most |size| bytes from + // potentially unaccessible memory. + Printf("mz_realloc(%p) -- attempting to realloc unallocated memory.\n" + "This is an unrecoverable problem, exiting now.\n", ptr); + print_zone_for_ptr(ptr); + GET_STACK_TRACE_HERE_FOR_FREE(ptr); + stack.PrintStack(); + ShowStatsAndAbort(); + return NULL; // unreachable + } + } +} + +void *cf_realloc(void *ptr, CFIndex size, CFOptionFlags hint, void *info) { + if (!ptr) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_malloc(size, &stack); + } else { + if (__asan_mz_size(ptr)) { + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_realloc(ptr, size, &stack); + } else { + // We can't recover from reallocating an unknown address, because + // this would require reading at most |size| bytes from + // potentially unaccessible memory. + Printf("cf_realloc(%p) -- attempting to realloc unallocated memory.\n" + "This is an unrecoverable problem, exiting now.\n", ptr); + print_zone_for_ptr(ptr); + GET_STACK_TRACE_HERE_FOR_FREE(ptr); + stack.PrintStack(); + ShowStatsAndAbort(); + return NULL; // unreachable + } + } +} + +void mz_destroy(malloc_zone_t* zone) { + // A no-op -- we will not be destroyed! + Printf("mz_destroy() called -- ignoring\n"); +} + // from AvailabilityMacros.h +#if defined(MAC_OS_X_VERSION_10_6) && \ + MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 +void *mz_memalign(malloc_zone_t *zone, size_t align, size_t size) { + if (!asan_inited) { + CHECK(system_malloc_zone); + return malloc_zone_memalign(system_malloc_zone, align, size); + } + GET_STACK_TRACE_HERE_FOR_MALLOC; + return asan_memalign(align, size, &stack); +} + +// This function is currently unused, and we build with -Werror. +#if 0 +void mz_free_definite_size(malloc_zone_t* zone, void *ptr, size_t size) { + // TODO(glider): check that |size| is valid. + UNIMPLEMENTED(); +} +#endif +#endif + +// malloc_introspection callbacks. I'm not clear on what all of these do. +kern_return_t mi_enumerator(task_t task, void *, + unsigned type_mask, vm_address_t zone_address, + memory_reader_t reader, + vm_range_recorder_t recorder) { + // Should enumerate all the pointers we have. Seems like a lot of work. + return KERN_FAILURE; +} + +size_t mi_good_size(malloc_zone_t *zone, size_t size) { + // I think it's always safe to return size, but we maybe could do better. + return size; +} + +boolean_t mi_check(malloc_zone_t *zone) { + UNIMPLEMENTED(); + return true; +} + +void mi_print(malloc_zone_t *zone, boolean_t verbose) { + UNIMPLEMENTED(); + return; +} + +void mi_log(malloc_zone_t *zone, void *address) { + // I don't think we support anything like this +} + +void mi_force_lock(malloc_zone_t *zone) { + __asan_mz_force_lock(); +} + +void mi_force_unlock(malloc_zone_t *zone) { + __asan_mz_force_unlock(); +} + +// This function is currently unused, and we build with -Werror. +#if 0 +void mi_statistics(malloc_zone_t *zone, malloc_statistics_t *stats) { + // TODO(csilvers): figure out how to fill these out + // TODO(glider): port this from tcmalloc when ready. + stats->blocks_in_use = 0; + stats->size_in_use = 0; + stats->max_size_in_use = 0; + stats->size_allocated = 0; +} +#endif + +boolean_t mi_zone_locked(malloc_zone_t *zone) { + // UNIMPLEMENTED(); + return false; +} + +} // unnamed namespace + +extern bool kCFUseCollectableAllocator; // is GC on? + +namespace __asan { +void ReplaceSystemMalloc() { + static malloc_introspection_t asan_introspection; + __asan::real_memset(&asan_introspection, 0, sizeof(asan_introspection)); + + asan_introspection.enumerator = &mi_enumerator; + asan_introspection.good_size = &mi_good_size; + asan_introspection.check = &mi_check; + asan_introspection.print = &mi_print; + asan_introspection.log = &mi_log; + asan_introspection.force_lock = &mi_force_lock; + asan_introspection.force_unlock = &mi_force_unlock; + + static malloc_zone_t asan_zone; + __asan::real_memset(&asan_zone, 0, sizeof(malloc_zone_t)); + + // Start with a version 4 zone which is used for OS X 10.4 and 10.5. + asan_zone.version = 4; + asan_zone.zone_name = "asan"; + asan_zone.size = &mz_size; + asan_zone.malloc = &mz_malloc; + asan_zone.calloc = &mz_calloc; + asan_zone.valloc = &mz_valloc; + asan_zone.free = &mz_free; + asan_zone.realloc = &mz_realloc; + asan_zone.destroy = &mz_destroy; + asan_zone.batch_malloc = NULL; + asan_zone.batch_free = NULL; + asan_zone.introspect = &asan_introspection; + + // from AvailabilityMacros.h +#if defined(MAC_OS_X_VERSION_10_6) && \ + MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 + // Switch to version 6 on OSX 10.6 to support memalign. + asan_zone.version = 6; + asan_zone.free_definite_size = 0; + asan_zone.memalign = &mz_memalign; + asan_introspection.zone_locked = &mi_zone_locked; + + // Request the default purgable zone to force its creation. The + // current default zone is registered with the purgable zone for + // doing tiny and small allocs. Sadly, it assumes that the default + // zone is the szone implementation from OS X and will crash if it + // isn't. By creating the zone now, this will be true and changing + // the default zone won't cause a problem. (OS X 10.6 and higher.) + system_purgeable_zone = malloc_default_purgeable_zone(); +#endif + + // Register the ASan zone. At this point, it will not be the + // default zone. + malloc_zone_register(&asan_zone); + + // Unregister and reregister the default zone. Unregistering swaps + // the specified zone with the last one registered which for the + // default zone makes the more recently registered zone the default + // zone. The default zone is then re-registered to ensure that + // allocations made from it earlier will be handled correctly. + // Things are not guaranteed to work that way, but it's how they work now. + system_malloc_zone = malloc_default_zone(); + malloc_zone_unregister(system_malloc_zone); + malloc_zone_register(system_malloc_zone); + // Make sure the default allocator was replaced. + CHECK(malloc_default_zone() == &asan_zone); + + if (FLAG_replace_cfallocator) { + static CFAllocatorContext asan_context = + { /*version*/ 0, /*info*/ &asan_zone, + /*retain*/ NULL, /*release*/ NULL, + /*copyDescription*/NULL, + /*allocate*/ &cf_malloc, + /*reallocate*/ &cf_realloc, + /*deallocate*/ &cf_free, + /*preferredSize*/ NULL }; + CFAllocatorRef cf_asan = + CFAllocatorCreate(kCFAllocatorUseContext, &asan_context); + CFAllocatorSetDefault(cf_asan); + } +} +} // namespace __asan + +#endif // __APPLE__ diff --git a/lib/asan/asan_mapping.h b/lib/asan/asan_mapping.h new file mode 100644 index 0000000..63aba10 --- /dev/null +++ b/lib/asan/asan_mapping.h @@ -0,0 +1,100 @@ +//===-- asan_mapping.h ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Defines ASan memory mapping. +//===----------------------------------------------------------------------===// +#ifndef ASAN_MAPPING_H +#define ASAN_MAPPING_H + +#include "asan_internal.h" + +// The full explanation of the memory mapping could be found here: +// http://code.google.com/p/address-sanitizer/wiki/AddressSanitizerAlgorithm + +#if ASAN_FLEXIBLE_MAPPING_AND_OFFSET == 1 +extern __attribute__((visibility("default"))) uintptr_t __asan_mapping_scale; +extern __attribute__((visibility("default"))) uintptr_t __asan_mapping_offset; +#define SHADOW_SCALE (__asan_mapping_scale) +#define SHADOW_OFFSET (__asan_mapping_offset) +#else +#define SHADOW_SCALE (3) +#if __WORDSIZE == 32 +#define SHADOW_OFFSET (1 << 29) +#else +#define SHADOW_OFFSET (1ULL << 44) +#endif +#endif // ASAN_FLEXIBLE_MAPPING_AND_OFFSET + +#define SHADOW_GRANULARITY (1ULL << SHADOW_SCALE) +#define MEM_TO_SHADOW(mem) (((mem) >> SHADOW_SCALE) | (SHADOW_OFFSET)) + +#if __WORDSIZE == 64 + static const size_t kHighMemEnd = 0x00007fffffffffffUL; +#else // __WORDSIZE == 32 + static const size_t kHighMemEnd = 0xffffffff; +#endif // __WORDSIZE + + +#define kLowMemBeg 0 +#define kLowMemEnd (SHADOW_OFFSET ? SHADOW_OFFSET - 1 : 0) + +#define kLowShadowBeg SHADOW_OFFSET +#define kLowShadowEnd MEM_TO_SHADOW(kLowMemEnd) + +#define kHighMemBeg (MEM_TO_SHADOW(kHighMemEnd) + 1) + +#define kHighShadowBeg MEM_TO_SHADOW(kHighMemBeg) +#define kHighShadowEnd MEM_TO_SHADOW(kHighMemEnd) + +#define kShadowGapBeg (kLowShadowEnd ? kLowShadowEnd + 1 : 16 * kPageSize) +#define kShadowGapEnd (kHighShadowBeg - 1) + +#define kGlobalAndStackRedzone \ + (SHADOW_GRANULARITY < 32 ? 32 : SHADOW_GRANULARITY) + +namespace __asan { + +static inline bool AddrIsInLowMem(uintptr_t a) { + return a < kLowMemEnd; +} + +static inline bool AddrIsInLowShadow(uintptr_t a) { + return a >= kLowShadowBeg && a <= kLowShadowEnd; +} + +static inline bool AddrIsInHighMem(uintptr_t a) { + return a >= kHighMemBeg && a <= kHighMemEnd; +} + +static inline bool AddrIsInMem(uintptr_t a) { + return AddrIsInLowMem(a) || AddrIsInHighMem(a); +} + +static inline uintptr_t MemToShadow(uintptr_t p) { + CHECK(AddrIsInMem(p)); + return MEM_TO_SHADOW(p); +} + +static inline bool AddrIsInHighShadow(uintptr_t a) { + return a >= kHighShadowBeg && a <= kHighMemEnd; +} + +static inline bool AddrIsInShadow(uintptr_t a) { + return AddrIsInLowShadow(a) || AddrIsInHighShadow(a); +} + +static inline bool AddrIsAlignedByGranularity(uintptr_t a) { + return (a & (SHADOW_GRANULARITY - 1)) == 0; +} + +} // namespace __asan + +#endif // ASAN_MAPPING_H diff --git a/lib/asan/asan_poisoning.cc b/lib/asan/asan_poisoning.cc new file mode 100644 index 0000000..daa1ad6 --- /dev/null +++ b/lib/asan/asan_poisoning.cc @@ -0,0 +1,159 @@ +//===-- asan_poisoning.cc ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Shadow memory poisoning by ASan RTL and by user application. +//===----------------------------------------------------------------------===// + +#include "asan_interceptors.h" +#include "asan_interface.h" +#include "asan_internal.h" +#include "asan_mapping.h" + +namespace __asan { + +void PoisonShadow(uintptr_t addr, size_t size, uint8_t value) { + CHECK(AddrIsAlignedByGranularity(addr)); + CHECK(AddrIsAlignedByGranularity(addr + size)); + uintptr_t shadow_beg = MemToShadow(addr); + uintptr_t shadow_end = MemToShadow(addr + size); + real_memset((void*)shadow_beg, value, shadow_end - shadow_beg); +} + +void PoisonShadowPartialRightRedzone(uintptr_t addr, + uintptr_t size, + uintptr_t redzone_size, + uint8_t value) { + CHECK(AddrIsAlignedByGranularity(addr)); + uint8_t *shadow = (uint8_t*)MemToShadow(addr); + for (uintptr_t i = 0; i < redzone_size; + i += SHADOW_GRANULARITY, shadow++) { + if (i + SHADOW_GRANULARITY <= size) { + *shadow = 0; // fully addressable + } else if (i >= size) { + *shadow = (SHADOW_GRANULARITY == 128) ? 0xff : value; // unaddressable + } else { + *shadow = size - i; // first size-i bytes are addressable + } + } +} + + +struct ShadowSegmentEndpoint { + uint8_t *chunk; + int8_t offset; // in [0, SHADOW_GRANULARITY) + int8_t value; // = *chunk; + + explicit ShadowSegmentEndpoint(uintptr_t address) { + chunk = (uint8_t*)MemToShadow(address); + offset = address & (SHADOW_GRANULARITY - 1); + value = *chunk; + } +}; + +} // namespace __asan + +// ---------------------- Interface ---------------- {{{1 +using namespace __asan; // NOLINT + +// Current implementation of __asan_(un)poison_memory_region doesn't check +// that user program (un)poisons the memory it owns. It poisons memory +// conservatively, and unpoisons progressively to make sure asan shadow +// mapping invariant is preserved (see detailed mapping description here: +// http://code.google.com/p/address-sanitizer/wiki/AddressSanitizerAlgorithm). +// +// * if user asks to poison region [left, right), the program poisons +// at least [left, AlignDown(right)). +// * if user asks to unpoison region [left, right), the program unpoisons +// at most [AlignDown(left), right). +void __asan_poison_memory_region(void const volatile *addr, size_t size) { + if (!FLAG_allow_user_poisoning || size == 0) return; + uintptr_t beg_addr = (uintptr_t)addr; + uintptr_t end_addr = beg_addr + size; + if (FLAG_v >= 1) { + Printf("Trying to poison memory region [%p, %p)\n", beg_addr, end_addr); + } + ShadowSegmentEndpoint beg(beg_addr); + ShadowSegmentEndpoint end(end_addr); + if (beg.chunk == end.chunk) { + CHECK(beg.offset < end.offset); + int8_t value = beg.value; + CHECK(value == end.value); + // We can only poison memory if the byte in end.offset is unaddressable. + // No need to re-poison memory if it is poisoned already. + if (value > 0 && value <= end.offset) { + if (beg.offset > 0) { + *beg.chunk = Min(value, beg.offset); + } else { + *beg.chunk = kAsanUserPoisonedMemoryMagic; + } + } + return; + } + CHECK(beg.chunk < end.chunk); + if (beg.offset > 0) { + // Mark bytes from beg.offset as unaddressable. + if (beg.value == 0) { + *beg.chunk = beg.offset; + } else { + *beg.chunk = Min(beg.value, beg.offset); + } + beg.chunk++; + } + real_memset(beg.chunk, kAsanUserPoisonedMemoryMagic, end.chunk - beg.chunk); + // Poison if byte in end.offset is unaddressable. + if (end.value > 0 && end.value <= end.offset) { + *end.chunk = kAsanUserPoisonedMemoryMagic; + } +} + +void __asan_unpoison_memory_region(void const volatile *addr, size_t size) { + if (!FLAG_allow_user_poisoning || size == 0) return; + uintptr_t beg_addr = (uintptr_t)addr; + uintptr_t end_addr = beg_addr + size; + if (FLAG_v >= 1) { + Printf("Trying to unpoison memory region [%p, %p)\n", beg_addr, end_addr); + } + ShadowSegmentEndpoint beg(beg_addr); + ShadowSegmentEndpoint end(end_addr); + if (beg.chunk == end.chunk) { + CHECK(beg.offset < end.offset); + int8_t value = beg.value; + CHECK(value == end.value); + // We unpoison memory bytes up to enbytes up to end.offset if it is not + // unpoisoned already. + if (value != 0) { + *beg.chunk = Max(value, end.offset); + } + return; + } + CHECK(beg.chunk < end.chunk); + if (beg.offset > 0) { + *beg.chunk = 0; + beg.chunk++; + } + real_memset(beg.chunk, 0, end.chunk - beg.chunk); + if (end.offset > 0 && end.value != 0) { + *end.chunk = Max(end.value, end.offset); + } +} + +bool __asan_address_is_poisoned(void const volatile *addr) { + const size_t kAccessSize = 1; + uintptr_t address = (uintptr_t)addr; + uint8_t *shadow_address = (uint8_t*)MemToShadow(address); + int8_t shadow_value = *shadow_address; + if (shadow_value) { + uint8_t last_accessed_byte = (address & (SHADOW_GRANULARITY - 1)) + + kAccessSize - 1; + return (last_accessed_byte >= shadow_value); + } + return false; +} diff --git a/lib/asan/asan_printf.cc b/lib/asan/asan_printf.cc new file mode 100644 index 0000000..a3d06ff --- /dev/null +++ b/lib/asan/asan_printf.cc @@ -0,0 +1,181 @@ +//===-- asan_printf.cc ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Internal printf function, used inside ASan run-time library. +// We can't use libc printf because we intercept some of the functions used +// inside it. +//===----------------------------------------------------------------------===// + +#include "asan_internal.h" +#include "asan_interceptors.h" + +#include + +namespace __asan { + +void RawWrite(const char *buffer) { + static const char *kRawWriteError = "RawWrite can't output requested buffer!"; + ssize_t length = (ssize_t)internal_strlen(buffer); + if (length != AsanWrite(2, buffer, length)) { + AsanWrite(2, kRawWriteError, internal_strlen(kRawWriteError)); + ASAN_DIE; + } +} + +static inline int AppendChar(char **buff, const char *buff_end, char c) { + if (*buff < buff_end) { + **buff = c; + (*buff)++; + } + return 1; +} + +// Appends number in a given base to buffer. If its length is less than +// "minimal_num_length", it is padded with leading zeroes. +static int AppendUnsigned(char **buff, const char *buff_end, uint64_t num, + uint8_t base, uint8_t minimal_num_length) { + size_t const kMaxLen = 30; + RAW_CHECK(base == 10 || base == 16); + RAW_CHECK(minimal_num_length < kMaxLen); + size_t num_buffer[kMaxLen]; + size_t pos = 0; + do { + RAW_CHECK_MSG(pos < kMaxLen, "appendNumber buffer overflow"); + num_buffer[pos++] = num % base; + num /= base; + } while (num > 0); + while (pos < minimal_num_length) num_buffer[pos++] = 0; + int result = 0; + while (pos-- > 0) { + size_t digit = num_buffer[pos]; + result += AppendChar(buff, buff_end, (digit < 10) ? '0' + digit + : 'a' + digit - 10); + } + return result; +} + +static inline int AppendSignedDecimal(char **buff, const char *buff_end, + int64_t num) { + int result = 0; + if (num < 0) { + result += AppendChar(buff, buff_end, '-'); + num = -num; + } + result += AppendUnsigned(buff, buff_end, (uint64_t)num, 10, 0); + return result; +} + +static inline int AppendString(char **buff, const char *buff_end, + const char *s) { + // Avoid library functions like stpcpy here. + RAW_CHECK(s); + int result = 0; + for (; *s; s++) { + result += AppendChar(buff, buff_end, *s); + } + return result; +} + +static inline int AppendPointer(char **buff, const char *buff_end, + uint64_t ptr_value) { + int result = 0; + result += AppendString(buff, buff_end, "0x"); + result += AppendUnsigned(buff, buff_end, ptr_value, 16, + (__WORDSIZE == 64) ? 12 : 8); + return result; +} + +static int VSNPrintf(char *buff, int buff_length, + const char *format, va_list args) { + static const char *kPrintfFormatsHelp = "Supported Printf formats: " + "%%[l]{d,u,x}; %%p; %%s"; + RAW_CHECK(format); + RAW_CHECK(buff_length > 0); + const char *buff_end = &buff[buff_length - 1]; + const char *cur = format; + int result = 0; + for (; *cur; cur++) { + if (*cur == '%') { + cur++; + bool have_l = (*cur == 'l'); + cur += have_l; + int64_t dval; + uint64_t uval, xval; + switch (*cur) { + case 'd': dval = have_l ? va_arg(args, intptr_t) + : va_arg(args, int); + result += AppendSignedDecimal(&buff, buff_end, dval); + break; + case 'u': uval = have_l ? va_arg(args, uintptr_t) + : va_arg(args, unsigned int); + result += AppendUnsigned(&buff, buff_end, uval, 10, 0); + break; + case 'x': xval = have_l ? va_arg(args, uintptr_t) + : va_arg(args, unsigned int); + result += AppendUnsigned(&buff, buff_end, xval, 16, 0); + break; + case 'p': RAW_CHECK_MSG(!have_l, kPrintfFormatsHelp); + result += AppendPointer(&buff, buff_end, + va_arg(args, uintptr_t)); + break; + case 's': RAW_CHECK_MSG(!have_l, kPrintfFormatsHelp); + result += AppendString(&buff, buff_end, va_arg(args, char*)); + break; + default: RAW_CHECK_MSG(false, kPrintfFormatsHelp); + } + } else { + result += AppendChar(&buff, buff_end, *cur); + } + } + RAW_CHECK(buff <= buff_end); + AppendChar(&buff, buff_end + 1, '\0'); + return result; +} + +void Printf(const char *format, ...) { + const int kLen = 1024 * 4; + char buffer[kLen]; + va_list args; + va_start(args, format); + int needed_length = VSNPrintf(buffer, kLen, format, args); + va_end(args); + RAW_CHECK_MSG(needed_length < kLen, "Buffer in Printf is too short!\n"); + RawWrite(buffer); +} + +// Writes at most "length" symbols to "buffer" (including trailing '\0'). +// Returns the number of symbols that should have been written to buffer +// (not including trailing '\0'). Thus, the string is truncated +// iff return value is not less than "length". +int SNPrintf(char *buffer, size_t length, const char *format, ...) { + va_list args; + va_start(args, format); + int needed_length = VSNPrintf(buffer, length, format, args); + va_end(args); + return needed_length; +} + +// Like Printf, but prints the current PID before the output string. +void Report(const char *format, ...) { + const int kLen = 1024 * 4; + char buffer[kLen]; + int needed_length = SNPrintf(buffer, kLen, "==%d== ", getpid()); + RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n"); + va_list args; + va_start(args, format); + needed_length += VSNPrintf(buffer + needed_length, kLen - needed_length, + format, args); + va_end(args); + RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n"); + RawWrite(buffer); +} + +} // namespace __asan diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc new file mode 100644 index 0000000..c876f6d --- /dev/null +++ b/lib/asan/asan_rtl.cc @@ -0,0 +1,810 @@ +//===-- asan_rtl.cc ---------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Main file of the ASan run-time library. +//===----------------------------------------------------------------------===// +#include "asan_allocator.h" +#include "asan_interceptors.h" +#include "asan_interface.h" +#include "asan_internal.h" +#include "asan_lock.h" +#include "asan_mac.h" +#include "asan_mapping.h" +#include "asan_stack.h" +#include "asan_stats.h" +#include "asan_thread.h" +#include "asan_thread_registry.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef ANDROID +#include +#endif +#include +#include +#include +// must not include on Linux + +namespace __asan { + +// -------------------------- Flags ------------------------- {{{1 +static const size_t kMallocContextSize = 30; +static int FLAG_atexit; +bool FLAG_fast_unwind = true; + +size_t FLAG_redzone; // power of two, >= 32 +size_t FLAG_quarantine_size; +int FLAG_demangle; +bool FLAG_symbolize; +int FLAG_v; +int FLAG_debug; +bool FLAG_poison_shadow; +int FLAG_report_globals; +size_t FLAG_malloc_context_size = kMallocContextSize; +uintptr_t FLAG_large_malloc; +bool FLAG_lazy_shadow; +bool FLAG_handle_segv; +bool FLAG_handle_sigill; +bool FLAG_replace_str; +bool FLAG_replace_intrin; +bool FLAG_replace_cfallocator; // Used on Mac only. +size_t FLAG_max_malloc_fill_size = 0; +bool FLAG_use_fake_stack; +int FLAG_exitcode = EXIT_FAILURE; +bool FLAG_allow_user_poisoning; + +// -------------------------- Globals --------------------- {{{1 +int asan_inited; +bool asan_init_is_running; + +// -------------------------- Interceptors ---------------- {{{1 +typedef int (*sigaction_f)(int signum, const struct sigaction *act, + struct sigaction *oldact); +typedef sig_t (*signal_f)(int signum, sig_t handler); +typedef void (*longjmp_f)(void *env, int val); +typedef longjmp_f _longjmp_f; +typedef longjmp_f siglongjmp_f; +typedef void (*__cxa_throw_f)(void *, void *, void *); +typedef int (*pthread_create_f)(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg); +#ifdef __APPLE__ +dispatch_async_f_f real_dispatch_async_f; +dispatch_sync_f_f real_dispatch_sync_f; +dispatch_after_f_f real_dispatch_after_f; +dispatch_barrier_async_f_f real_dispatch_barrier_async_f; +dispatch_group_async_f_f real_dispatch_group_async_f; +pthread_workqueue_additem_np_f real_pthread_workqueue_additem_np; +#endif + +sigaction_f real_sigaction; +signal_f real_signal; +longjmp_f real_longjmp; +_longjmp_f real__longjmp; +siglongjmp_f real_siglongjmp; +__cxa_throw_f real___cxa_throw; +pthread_create_f real_pthread_create; + +// -------------------------- Misc ---------------- {{{1 +void ShowStatsAndAbort() { + __asan_print_accumulated_stats(); + ASAN_DIE; +} + +static void PrintBytes(const char *before, uintptr_t *a) { + uint8_t *bytes = (uint8_t*)a; + size_t byte_num = (__WORDSIZE) / 8; + Printf("%s%p:", before, (uintptr_t)a); + for (size_t i = 0; i < byte_num; i++) { + Printf(" %lx%lx", bytes[i] >> 4, bytes[i] & 15); + } + Printf("\n"); +} + +// Opens the file 'file_name" and reads up to 'max_len' bytes. +// The resulting buffer is mmaped and stored in '*buff'. +// Returns the number of read bytes or -1 if file can not be opened. +static ssize_t ReadFileToBuffer(const char *file_name, char **buff, + size_t max_len) { + const size_t kMinFileLen = kPageSize; + ssize_t read_len = -1; + *buff = 0; + size_t maped_size = 0; + // The files we usually open are not seekable, so try different buffer sizes. + for (size_t size = kMinFileLen; size <= max_len; size *= 2) { + int fd = AsanOpenReadonly(file_name); + if (fd < 0) return -1; + AsanUnmapOrDie(*buff, maped_size); + maped_size = size; + *buff = (char*)AsanMmapSomewhereOrDie(size, __FUNCTION__); + read_len = AsanRead(fd, *buff, size); + AsanClose(fd); + if (read_len < size) // We've read the whole file. + break; + } + return read_len; +} + +// Like getenv, but reads env directly from /proc and does not use libc. +// This function should be called first inside __asan_init. +static const char* GetEnvFromProcSelfEnviron(const char* name) { + static char *environ; + static ssize_t len; + static bool inited; + if (!inited) { + inited = true; + len = ReadFileToBuffer("/proc/self/environ", &environ, 1 << 20); + } + if (!environ || len <= 0) return NULL; + size_t namelen = internal_strlen(name); + const char *p = environ; + while (*p != '\0') { // will happen at the \0\0 that terminates the buffer + // proc file has the format NAME=value\0NAME=value\0NAME=value\0... + const char* endp = + (char*)internal_memchr(p, '\0', len - (p - environ)); + if (endp == NULL) // this entry isn't NUL terminated + return NULL; + else if (!internal_memcmp(p, name, namelen) && p[namelen] == '=') // Match. + return p + namelen + 1; // point after = + p = endp + 1; + } + return NULL; // Not found. +} + +// ---------------------- Thread ------------------------- {{{1 +static void *asan_thread_start(void *arg) { + AsanThread *t= (AsanThread*)arg; + asanThreadRegistry().SetCurrent(t); + return t->ThreadStart(); +} + +// ---------------------- mmap -------------------- {{{1 +void OutOfMemoryMessageAndDie(const char *mem_type, size_t size) { + Report("ERROR: AddressSanitizer failed to allocate " + "0x%lx (%ld) bytes of %s\n", + size, size, mem_type); + PRINT_CURRENT_STACK(); + ShowStatsAndAbort(); +} + +// Reserve memory range [beg, end]. +static void ReserveShadowMemoryRange(uintptr_t beg, uintptr_t end) { + CHECK((beg % kPageSize) == 0); + CHECK(((end + 1) % kPageSize) == 0); + size_t size = end - beg + 1; + void *res = AsanMmapFixedNoReserve(beg, size); + CHECK(res == (void*)beg && "ReserveShadowMemoryRange failed"); +} + +// ---------------------- LowLevelAllocator ------------- {{{1 +void *LowLevelAllocator::Allocate(size_t size) { + CHECK((size & (size - 1)) == 0 && "size must be a power of two"); + if (allocated_end_ - allocated_current_ < size) { + size_t size_to_allocate = Max(size, kPageSize); + allocated_current_ = + (char*)AsanMmapSomewhereOrDie(size_to_allocate, __FUNCTION__); + allocated_end_ = allocated_current_ + size_to_allocate; + PoisonShadow((uintptr_t)allocated_current_, size_to_allocate, + kAsanInternalHeapMagic); + } + CHECK(allocated_end_ - allocated_current_ >= size); + void *res = allocated_current_; + allocated_current_ += size; + return res; +} + +// ---------------------- DescribeAddress -------------------- {{{1 +static bool DescribeStackAddress(uintptr_t addr, uintptr_t access_size) { + AsanThread *t = asanThreadRegistry().FindThreadByStackAddress(addr); + if (!t) return false; + const intptr_t kBufSize = 4095; + char buf[kBufSize]; + uintptr_t offset = 0; + const char *frame_descr = t->GetFrameNameByAddr(addr, &offset); + // This string is created by the compiler and has the following form: + // "FunctioName n alloc_1 alloc_2 ... alloc_n" + // where alloc_i looks like "offset size len ObjectName ". + CHECK(frame_descr); + // Report the function name and the offset. + const char *name_end = real_strchr(frame_descr, ' '); + CHECK(name_end); + buf[0] = 0; + strncat(buf, frame_descr, + Min(kBufSize, static_cast(name_end - frame_descr))); + Printf("Address %p is located at offset %ld " + "in frame <%s> of T%d's stack:\n", + addr, offset, buf, t->tid()); + // Report the number of stack objects. + char *p; + size_t n_objects = strtol(name_end, &p, 10); + CHECK(n_objects > 0); + Printf(" This frame has %ld object(s):\n", n_objects); + // Report all objects in this frame. + for (size_t i = 0; i < n_objects; i++) { + size_t beg, size; + intptr_t len; + beg = strtol(p, &p, 10); + size = strtol(p, &p, 10); + len = strtol(p, &p, 10); + if (beg <= 0 || size <= 0 || len < 0 || *p != ' ') { + Printf("AddressSanitizer can't parse the stack frame descriptor: |%s|\n", + frame_descr); + break; + } + p++; + buf[0] = 0; + strncat(buf, p, Min(kBufSize, len)); + p += len; + Printf(" [%ld, %ld) '%s'\n", beg, beg + size, buf); + } + Printf("HINT: this may be a false positive if your program uses " + "some custom stack unwind mechanism\n" + " (longjmp and C++ exceptions *are* supported)\n"); + t->summary()->Announce(); + return true; +} + +__attribute__((noinline)) +static void DescribeAddress(uintptr_t addr, uintptr_t access_size) { + // Check if this is a global. + if (DescribeAddrIfGlobal(addr)) + return; + + if (DescribeStackAddress(addr, access_size)) + return; + + // finally, check if this is a heap. + DescribeHeapAddress(addr, access_size); +} + +// -------------------------- Run-time entry ------------------- {{{1 +void GetPcSpBpAx(void *context, + uintptr_t *pc, uintptr_t *sp, uintptr_t *bp, uintptr_t *ax) { +#ifndef ANDROID + ucontext_t *ucontext = (ucontext_t*)context; +#endif +#ifdef __APPLE__ +# if __WORDSIZE == 64 + *pc = ucontext->uc_mcontext->__ss.__rip; + *bp = ucontext->uc_mcontext->__ss.__rbp; + *sp = ucontext->uc_mcontext->__ss.__rsp; + *ax = ucontext->uc_mcontext->__ss.__rax; +# else + *pc = ucontext->uc_mcontext->__ss.__eip; + *bp = ucontext->uc_mcontext->__ss.__ebp; + *sp = ucontext->uc_mcontext->__ss.__esp; + *ax = ucontext->uc_mcontext->__ss.__eax; +# endif // __WORDSIZE +#else // assume linux +# if defined (ANDROID) + *pc = *sp = *bp = *ax = 0; +# elif defined(__arm__) + *pc = ucontext->uc_mcontext.arm_pc; + *bp = ucontext->uc_mcontext.arm_fp; + *sp = ucontext->uc_mcontext.arm_sp; + *ax = ucontext->uc_mcontext.arm_r0; +# elif __WORDSIZE == 64 + *pc = ucontext->uc_mcontext.gregs[REG_RIP]; + *bp = ucontext->uc_mcontext.gregs[REG_RBP]; + *sp = ucontext->uc_mcontext.gregs[REG_RSP]; + *ax = ucontext->uc_mcontext.gregs[REG_RAX]; +# else + *pc = ucontext->uc_mcontext.gregs[REG_EIP]; + *bp = ucontext->uc_mcontext.gregs[REG_EBP]; + *sp = ucontext->uc_mcontext.gregs[REG_ESP]; + *ax = ucontext->uc_mcontext.gregs[REG_EAX]; +# endif // __WORDSIZE +#endif +} + +static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) { + uintptr_t addr = (uintptr_t)siginfo->si_addr; + if (AddrIsInShadow(addr) && FLAG_lazy_shadow) { + // We traped on access to a shadow address. Just map a large chunk around + // this address. + const uintptr_t chunk_size = kPageSize << 10; // 4M + uintptr_t chunk = addr & ~(chunk_size - 1); + AsanMmapFixedReserve(chunk, chunk_size); + return; + } + // Write the first message using the bullet-proof write. + if (13 != AsanWrite(2, "ASAN:SIGSEGV\n", 13)) ASAN_DIE; + uintptr_t pc, sp, bp, ax; + GetPcSpBpAx(context, &pc, &sp, &bp, &ax); + Report("ERROR: AddressSanitizer crashed on unknown address %p" + " (pc %p sp %p bp %p ax %p T%d)\n", + addr, pc, sp, bp, ax, + asanThreadRegistry().GetCurrentTidOrMinusOne()); + Printf("AddressSanitizer can not provide additional info. ABORTING\n"); + GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, false, pc, bp); + stack.PrintStack(); + ShowStatsAndAbort(); +} + +static void ASAN_OnSIGILL(int, siginfo_t *siginfo, void *context) { + // Write the first message using the bullet-proof write. + if (12 != AsanWrite(2, "ASAN:SIGILL\n", 12)) ASAN_DIE; + uintptr_t pc, sp, bp, ax; + GetPcSpBpAx(context, &pc, &sp, &bp, &ax); + + uintptr_t addr = ax; + + uint8_t *insn = (uint8_t*)pc; + CHECK(insn[0] == 0x0f && insn[1] == 0x0b); // ud2 + unsigned access_size_and_type = insn[2] - 0x50; + CHECK(access_size_and_type < 16); + bool is_write = access_size_and_type & 8; + int access_size = 1 << (access_size_and_type & 7); + __asan_report_error(pc, bp, sp, addr, is_write, access_size); +} + +// exported functions +#define ASAN_REPORT_ERROR(type, is_write, size) \ +extern "C" void __asan_report_ ## type ## size(uintptr_t addr) \ + __attribute__((visibility("default"))) __attribute__((noinline)); \ +extern "C" void __asan_report_ ## type ## size(uintptr_t addr) { \ + GET_BP_PC_SP; \ + __asan_report_error(pc, bp, sp, addr, is_write, size); \ +} + +ASAN_REPORT_ERROR(load, false, 1) +ASAN_REPORT_ERROR(load, false, 2) +ASAN_REPORT_ERROR(load, false, 4) +ASAN_REPORT_ERROR(load, false, 8) +ASAN_REPORT_ERROR(load, false, 16) +ASAN_REPORT_ERROR(store, true, 1) +ASAN_REPORT_ERROR(store, true, 2) +ASAN_REPORT_ERROR(store, true, 4) +ASAN_REPORT_ERROR(store, true, 8) +ASAN_REPORT_ERROR(store, true, 16) + +// Force the linker to keep the symbols for various ASan interface functions. +// We want to keep those in the executable in order to let the instrumented +// dynamic libraries access the symbol even if it is not used by the executable +// itself. This should help if the build system is removing dead code at link +// time. +static void force_interface_symbols() { + volatile int fake_condition = 0; // prevent dead condition elimination. + if (fake_condition) { + __asan_report_load1(NULL); + __asan_report_load2(NULL); + __asan_report_load4(NULL); + __asan_report_load8(NULL); + __asan_report_load16(NULL); + __asan_report_store1(NULL); + __asan_report_store2(NULL); + __asan_report_store4(NULL); + __asan_report_store8(NULL); + __asan_report_store16(NULL); + __asan_register_global(0, 0, NULL); + __asan_register_globals(NULL, 0); + __asan_unregister_globals(NULL, 0); + } +} + +// -------------------------- Init ------------------- {{{1 +static int64_t IntFlagValue(const char *flags, const char *flag, + int64_t default_val) { + if (!flags) return default_val; + const char *str = strstr(flags, flag); + if (!str) return default_val; + return atoll(str + internal_strlen(flag)); +} + +static void asan_atexit() { + Printf("AddressSanitizer exit stats:\n"); + __asan_print_accumulated_stats(); +} + +void CheckFailed(const char *cond, const char *file, int line) { + Report("CHECK failed: %s at %s:%d, pthread_self=%p\n", + cond, file, line, pthread_self()); + PRINT_CURRENT_STACK(); + ShowStatsAndAbort(); +} + +} // namespace __asan + +// -------------------------- Interceptors ------------------- {{{1 +using namespace __asan; // NOLINT + +#define OPERATOR_NEW_BODY \ + GET_STACK_TRACE_HERE_FOR_MALLOC;\ + return asan_memalign(0, size, &stack); + +#ifdef ANDROID +void *operator new(size_t size) { OPERATOR_NEW_BODY; } +void *operator new[](size_t size) { OPERATOR_NEW_BODY; } +#else +void *operator new(size_t size) throw(std::bad_alloc) { OPERATOR_NEW_BODY; } +void *operator new[](size_t size) throw(std::bad_alloc) { OPERATOR_NEW_BODY; } +void *operator new(size_t size, std::nothrow_t const&) throw() +{ OPERATOR_NEW_BODY; } +void *operator new[](size_t size, std::nothrow_t const&) throw() +{ OPERATOR_NEW_BODY; } +#endif + +#define OPERATOR_DELETE_BODY \ + GET_STACK_TRACE_HERE_FOR_FREE(ptr);\ + asan_free(ptr, &stack); + +void operator delete(void *ptr) throw() { OPERATOR_DELETE_BODY; } +void operator delete[](void *ptr) throw() { OPERATOR_DELETE_BODY; } +void operator delete(void *ptr, std::nothrow_t const&) throw() +{ OPERATOR_DELETE_BODY; } +void operator delete[](void *ptr, std::nothrow_t const&) throw() +{ OPERATOR_DELETE_BODY;} + +extern "C" +#ifndef __APPLE__ +__attribute__((visibility("default"))) +#endif +int WRAP(pthread_create)(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg) { + GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false); + AsanThread *t = (AsanThread*)asan_malloc(sizeof(AsanThread), &stack); + AsanThread *curr_thread = asanThreadRegistry().GetCurrent(); + CHECK(curr_thread || asanThreadRegistry().IsCurrentThreadDying()); + new(t) AsanThread(asanThreadRegistry().GetCurrentTidOrMinusOne(), + start_routine, arg, &stack); + return real_pthread_create(thread, attr, asan_thread_start, t); +} + +static bool MySignal(int signum) { + if (FLAG_handle_sigill && signum == SIGILL) return true; + if (FLAG_handle_segv && signum == SIGSEGV) return true; +#ifdef __APPLE__ + if (FLAG_handle_segv && signum == SIGBUS) return true; +#endif + return false; +} + +static void MaybeInstallSigaction(int signum, + void (*handler)(int, siginfo_t *, void *)) { + if (!MySignal(signum)) + return; + struct sigaction sigact; + real_memset(&sigact, 0, sizeof(sigact)); + sigact.sa_sigaction = handler; + sigact.sa_flags = SA_SIGINFO; + CHECK(0 == real_sigaction(signum, &sigact, 0)); +} + +extern "C" +sig_t WRAP(signal)(int signum, sig_t handler) { + if (!MySignal(signum)) { + return real_signal(signum, handler); + } + return NULL; +} + +extern "C" +int WRAP(sigaction)(int signum, const struct sigaction *act, + struct sigaction *oldact) { + if (!MySignal(signum)) { + return real_sigaction(signum, act, oldact); + } + return 0; +} + + +static void UnpoisonStackFromHereToTop() { + int local_stack; + AsanThread *curr_thread = asanThreadRegistry().GetCurrent(); + CHECK(curr_thread); + uintptr_t top = curr_thread->stack_top(); + uintptr_t bottom = ((uintptr_t)&local_stack - kPageSize) & ~(kPageSize-1); + PoisonShadow(bottom, top - bottom, 0); +} + +extern "C" void WRAP(longjmp)(void *env, int val) { + UnpoisonStackFromHereToTop(); + real_longjmp(env, val); +} + +extern "C" void WRAP(_longjmp)(void *env, int val) { + UnpoisonStackFromHereToTop(); + real__longjmp(env, val); +} + +extern "C" void WRAP(siglongjmp)(void *env, int val) { + UnpoisonStackFromHereToTop(); + real_siglongjmp(env, val); +} + +extern "C" void __cxa_throw(void *a, void *b, void *c); + +#if ASAN_HAS_EXCEPTIONS == 1 +extern "C" void WRAP(__cxa_throw)(void *a, void *b, void *c) { + CHECK(&real___cxa_throw); + UnpoisonStackFromHereToTop(); + real___cxa_throw(a, b, c); +} +#endif + +extern "C" { +// intercept mlock and friends. +// Since asan maps 16T of RAM, mlock is completely unfriendly to asan. +// All functions return 0 (success). +static void MlockIsUnsupported() { + static bool printed = 0; + if (printed) return; + printed = true; + Printf("INFO: AddressSanitizer ignores mlock/mlockall/munlock/munlockall\n"); +} +int mlock(const void *addr, size_t len) { + MlockIsUnsupported(); + return 0; +} +int munlock(const void *addr, size_t len) { + MlockIsUnsupported(); + return 0; +} +int mlockall(int flags) { + MlockIsUnsupported(); + return 0; +} +int munlockall(void) { + MlockIsUnsupported(); + return 0; +} +} // extern "C" + +// ---------------------- Interface ---------------- {{{1 +int __asan_set_error_exit_code(int exit_code) { + int old = FLAG_exitcode; + FLAG_exitcode = exit_code; + return old; +} + +void __asan_report_error(uintptr_t pc, uintptr_t bp, uintptr_t sp, + uintptr_t addr, bool is_write, size_t access_size) { + // Do not print more than one report, otherwise they will mix up. + static int num_calls = 0; + if (AtomicInc(&num_calls) > 1) return; + + Printf("=================================================================\n"); + const char *bug_descr = "unknown-crash"; + if (AddrIsInMem(addr)) { + uint8_t *shadow_addr = (uint8_t*)MemToShadow(addr); + // If we are accessing 16 bytes, look at the second shadow byte. + if (*shadow_addr == 0 && access_size > SHADOW_GRANULARITY) + shadow_addr++; + // If we are in the partial right redzone, look at the next shadow byte. + if (*shadow_addr > 0 && *shadow_addr < 128) + shadow_addr++; + switch (*shadow_addr) { + case kAsanHeapLeftRedzoneMagic: + case kAsanHeapRightRedzoneMagic: + bug_descr = "heap-buffer-overflow"; + break; + case kAsanHeapFreeMagic: + bug_descr = "heap-use-after-free"; + break; + case kAsanStackLeftRedzoneMagic: + bug_descr = "stack-buffer-underflow"; + break; + case kAsanStackMidRedzoneMagic: + case kAsanStackRightRedzoneMagic: + case kAsanStackPartialRedzoneMagic: + bug_descr = "stack-buffer-overflow"; + break; + case kAsanStackAfterReturnMagic: + bug_descr = "stack-use-after-return"; + break; + case kAsanUserPoisonedMemoryMagic: + bug_descr = "use-after-poison"; + break; + case kAsanGlobalRedzoneMagic: + bug_descr = "global-buffer-overflow"; + break; + } + } + + AsanThread *curr_thread = asanThreadRegistry().GetCurrent(); + int curr_tid = asanThreadRegistry().GetCurrentTidOrMinusOne(); + + if (curr_thread) { + // We started reporting an error message. Stop using the fake stack + // in case we will call an instrumented function from a symbolizer. + curr_thread->fake_stack().StopUsingFakeStack(); + } + + Report("ERROR: AddressSanitizer %s on address " + "%p at pc 0x%lx bp 0x%lx sp 0x%lx\n", + bug_descr, addr, pc, bp, sp); + + Printf("%s of size %d at %p thread T%d\n", + access_size ? (is_write ? "WRITE" : "READ") : "ACCESS", + access_size, addr, curr_tid); + + if (FLAG_debug) { + PrintBytes("PC: ", (uintptr_t*)pc); + } + + GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, + false, // FLAG_fast_unwind, + pc, bp); + stack.PrintStack(); + + CHECK(AddrIsInMem(addr)); + + DescribeAddress(addr, access_size); + + uintptr_t shadow_addr = MemToShadow(addr); + Report("ABORTING\n"); + __asan_print_accumulated_stats(); + Printf("Shadow byte and word:\n"); + Printf(" %p: %x\n", shadow_addr, *(unsigned char*)shadow_addr); + uintptr_t aligned_shadow = shadow_addr & ~(kWordSize - 1); + PrintBytes(" ", (uintptr_t*)(aligned_shadow)); + Printf("More shadow bytes:\n"); + PrintBytes(" ", (uintptr_t*)(aligned_shadow-4*kWordSize)); + PrintBytes(" ", (uintptr_t*)(aligned_shadow-3*kWordSize)); + PrintBytes(" ", (uintptr_t*)(aligned_shadow-2*kWordSize)); + PrintBytes(" ", (uintptr_t*)(aligned_shadow-1*kWordSize)); + PrintBytes("=>", (uintptr_t*)(aligned_shadow+0*kWordSize)); + PrintBytes(" ", (uintptr_t*)(aligned_shadow+1*kWordSize)); + PrintBytes(" ", (uintptr_t*)(aligned_shadow+2*kWordSize)); + PrintBytes(" ", (uintptr_t*)(aligned_shadow+3*kWordSize)); + PrintBytes(" ", (uintptr_t*)(aligned_shadow+4*kWordSize)); + ASAN_DIE; +} + +void __asan_init() { + if (asan_inited) return; + asan_init_is_running = true; + + // Make sure we are not statically linked. + AsanDoesNotSupportStaticLinkage(); + + // flags + const char *options = GetEnvFromProcSelfEnviron("ASAN_OPTIONS"); + FLAG_malloc_context_size = + IntFlagValue(options, "malloc_context_size=", kMallocContextSize); + CHECK(FLAG_malloc_context_size <= kMallocContextSize); + + FLAG_max_malloc_fill_size = + IntFlagValue(options, "max_malloc_fill_size=", 0); + + FLAG_v = IntFlagValue(options, "verbosity=", 0); + + FLAG_redzone = IntFlagValue(options, "redzone=", 128); + CHECK(FLAG_redzone >= 32); + CHECK((FLAG_redzone & (FLAG_redzone - 1)) == 0); + + FLAG_atexit = IntFlagValue(options, "atexit=", 0); + FLAG_poison_shadow = IntFlagValue(options, "poison_shadow=", 1); + FLAG_report_globals = IntFlagValue(options, "report_globals=", 1); + FLAG_lazy_shadow = IntFlagValue(options, "lazy_shadow=", 0); + FLAG_handle_segv = IntFlagValue(options, "handle_segv=", ASAN_NEEDS_SEGV); + FLAG_handle_sigill = IntFlagValue(options, "handle_sigill=", 0); + FLAG_symbolize = IntFlagValue(options, "symbolize=", 1); + FLAG_demangle = IntFlagValue(options, "demangle=", 1); + FLAG_debug = IntFlagValue(options, "debug=", 0); + FLAG_replace_cfallocator = IntFlagValue(options, "replace_cfallocator=", 1); + FLAG_fast_unwind = IntFlagValue(options, "fast_unwind=", 1); + FLAG_replace_str = IntFlagValue(options, "replace_str=", 1); + FLAG_replace_intrin = IntFlagValue(options, "replace_intrin=", 1); + FLAG_use_fake_stack = IntFlagValue(options, "use_fake_stack=", 1); + FLAG_exitcode = IntFlagValue(options, "exitcode=", EXIT_FAILURE); + FLAG_allow_user_poisoning = IntFlagValue(options, + "allow_user_poisoning=", 1); + + if (FLAG_atexit) { + atexit(asan_atexit); + } + + FLAG_quarantine_size = + IntFlagValue(options, "quarantine_size=", 1UL << 28); + + // interceptors + InitializeAsanInterceptors(); + + ReplaceSystemMalloc(); + + INTERCEPT_FUNCTION(sigaction); + INTERCEPT_FUNCTION(signal); + INTERCEPT_FUNCTION(longjmp); + INTERCEPT_FUNCTION(_longjmp); + INTERCEPT_FUNCTION_IF_EXISTS(__cxa_throw); + INTERCEPT_FUNCTION(pthread_create); +#ifdef __APPLE__ + INTERCEPT_FUNCTION(dispatch_async_f); + INTERCEPT_FUNCTION(dispatch_sync_f); + INTERCEPT_FUNCTION(dispatch_after_f); + INTERCEPT_FUNCTION(dispatch_barrier_async_f); + INTERCEPT_FUNCTION(dispatch_group_async_f); + // We don't need to intercept pthread_workqueue_additem_np() to support the + // libdispatch API, but it helps us to debug the unsupported functions. Let's + // intercept it only during verbose runs. + if (FLAG_v >= 2) { + INTERCEPT_FUNCTION(pthread_workqueue_additem_np); + } +#else + // On Darwin siglongjmp tailcalls longjmp, so we don't want to intercept it + // there. + INTERCEPT_FUNCTION(siglongjmp); +#endif + + MaybeInstallSigaction(SIGSEGV, ASAN_OnSIGSEGV); + MaybeInstallSigaction(SIGBUS, ASAN_OnSIGSEGV); + MaybeInstallSigaction(SIGILL, ASAN_OnSIGILL); + + if (FLAG_v) { + Printf("|| `[%p, %p]` || HighMem ||\n", kHighMemBeg, kHighMemEnd); + Printf("|| `[%p, %p]` || HighShadow ||\n", + kHighShadowBeg, kHighShadowEnd); + Printf("|| `[%p, %p]` || ShadowGap ||\n", + kShadowGapBeg, kShadowGapEnd); + Printf("|| `[%p, %p]` || LowShadow ||\n", + kLowShadowBeg, kLowShadowEnd); + Printf("|| `[%p, %p]` || LowMem ||\n", kLowMemBeg, kLowMemEnd); + Printf("MemToShadow(shadow): %p %p %p %p\n", + MEM_TO_SHADOW(kLowShadowBeg), + MEM_TO_SHADOW(kLowShadowEnd), + MEM_TO_SHADOW(kHighShadowBeg), + MEM_TO_SHADOW(kHighShadowEnd)); + Printf("red_zone=%ld\n", FLAG_redzone); + Printf("malloc_context_size=%ld\n", (int)FLAG_malloc_context_size); + Printf("fast_unwind=%d\n", (int)FLAG_fast_unwind); + + Printf("SHADOW_SCALE: %lx\n", SHADOW_SCALE); + Printf("SHADOW_GRANULARITY: %lx\n", SHADOW_GRANULARITY); + Printf("SHADOW_OFFSET: %lx\n", SHADOW_OFFSET); + CHECK(SHADOW_SCALE >= 3 && SHADOW_SCALE <= 7); + } + + if (__WORDSIZE == 64) { + // Disable core dumper -- it makes little sense to dump 16T+ core. + struct rlimit nocore; + nocore.rlim_cur = 0; + nocore.rlim_max = 0; + setrlimit(RLIMIT_CORE, &nocore); + } + + { + if (!FLAG_lazy_shadow) { + if (kLowShadowBeg != kLowShadowEnd) { + // mmap the low shadow plus one page. + ReserveShadowMemoryRange(kLowShadowBeg - kPageSize, kLowShadowEnd); + } + // mmap the high shadow. + ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd); + } + // protect the gap + void *prot = AsanMprotect(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1); + CHECK(prot == (void*)kShadowGapBeg); + } + + // On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited + // should be set to 1 prior to initializing the threads. + asan_inited = 1; + asan_init_is_running = false; + + asanThreadRegistry().Init(); + asanThreadRegistry().GetMain()->ThreadStart(); + force_interface_symbols(); // no-op. + + if (FLAG_v) { + Report("AddressSanitizer Init done\n"); + } +} diff --git a/lib/asan/asan_stack.cc b/lib/asan/asan_stack.cc new file mode 100644 index 0000000..8163983 --- /dev/null +++ b/lib/asan/asan_stack.cc @@ -0,0 +1,280 @@ +//===-- asan_stack.cc -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Code for ASan stack trace. +//===----------------------------------------------------------------------===// +#include "asan_interceptors.h" +#include "asan_lock.h" +#include "asan_stack.h" +#include "asan_thread.h" +#include "asan_thread_registry.h" + +#include + +#if ASAN_USE_SYSINFO == 1 +#include "sysinfo/sysinfo.h" +#endif + +#ifdef ASAN_USE_EXTERNAL_SYMBOLIZER +extern bool +ASAN_USE_EXTERNAL_SYMBOLIZER(const void *pc, char *out, int out_size); +#endif + +namespace __asan { + +// ----------------------- ProcSelfMaps ----------------------------- {{{1 +#if ASAN_USE_SYSINFO == 1 +class ProcSelfMaps { + public: + void Init() { + ScopedLock lock(&mu_); + if (map_size_ != 0) return; // already inited + if (FLAG_v >= 2) { + Printf("ProcSelfMaps::Init()\n"); + } + ProcMapsIterator it(0, &proc_self_maps_); // 0 means "current pid" + + uint64 start, end, offset; + int64 inode; + char *flags, *filename; + CHECK(map_size_ == 0); + while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { + CHECK(map_size_ < kMaxProcSelfMapsSize); + Mapping &mapping = memory_map[map_size_]; + mapping.beg = start; + mapping.end = end; + mapping.offset = offset; + real_strncpy(mapping.name, + filename, ASAN_ARRAY_SIZE(mapping.name)); + mapping.name[ASAN_ARRAY_SIZE(mapping.name) - 1] = 0; + if (FLAG_v >= 2) { + Printf("[%ld] [%p,%p] off %p %s\n", map_size_, + mapping.beg, mapping.end, mapping.offset, mapping.name); + } + map_size_++; + } + } + + void Print() { + Printf("%s\n", proc_self_maps_); + } + + void PrintPc(uintptr_t pc, int idx) { + for (size_t i = 0; i < map_size_; i++) { + Mapping &m = memory_map[i]; + if (pc >= m.beg && pc < m.end) { + uintptr_t offset = pc - m.beg; + if (i == 0) offset = pc; + Printf(" #%d 0x%lx (%s+0x%lx)\n", idx, pc, m.name, offset); + return; + } + } + Printf(" #%d 0x%lx\n", idx, pc); + } + + private: + void copy_until_new_line(const char *str, char *dest, size_t max_size) { + size_t i = 0; + for (; str[i] && str[i] != '\n' && i < max_size - 1; i++) { + dest[i] = str[i]; + } + dest[i] = 0; + } + + + struct Mapping { + uintptr_t beg, end, offset; + char name[1000]; + }; + static const size_t kMaxNumMapEntries = 4096; + static const size_t kMaxProcSelfMapsSize = 1 << 20; + ProcMapsIterator::Buffer proc_self_maps_; + size_t map_size_; + Mapping memory_map[kMaxNumMapEntries]; + + static AsanLock mu_; +}; + +static ProcSelfMaps proc_self_maps; +AsanLock ProcSelfMaps::mu_(LINKER_INITIALIZED); + + +void AsanStackTrace::PrintStack(uintptr_t *addr, size_t size) { + proc_self_maps.Init(); + for (size_t i = 0; i < size && addr[i]; i++) { + uintptr_t pc = addr[i]; + // int line; + proc_self_maps.PrintPc(pc, i); + // Printf(" #%ld 0x%lx %s\n", i, pc, rtn.c_str()); + } +} +#elif defined(ASAN_USE_EXTERNAL_SYMBOLIZER) +void AsanStackTrace::PrintStack(uintptr_t *addr, size_t size) { + for (size_t i = 0; i < size && addr[i]; i++) { + uintptr_t pc = addr[i]; + char buff[4096]; + ASAN_USE_EXTERNAL_SYMBOLIZER((void*)pc, buff, sizeof(buff)); + Printf(" #%ld 0x%lx %s\n", i, pc, buff); + } +} + +#else // ASAN_USE_SYSINFO +void AsanStackTrace::PrintStack(uintptr_t *addr, size_t size) { + for (size_t i = 0; i < size && addr[i]; i++) { + uintptr_t pc = addr[i]; + Printf(" #%ld 0x%lx\n", i, pc); + } +} +#endif // ASAN_USE_SYSINFO + +#ifdef __arm__ +#define UNWIND_STOP _URC_END_OF_STACK +#define UNWIND_CONTINUE _URC_OK +#else +#define UNWIND_STOP _URC_NORMAL_STOP +#define UNWIND_CONTINUE _URC_NO_REASON +#endif + +// ----------------------- AsanStackTrace ----------------------------- {{{1 +uintptr_t AsanStackTrace::GetCurrentPc() { + return GET_CALLER_PC(); +} + +void AsanStackTrace::FastUnwindStack(uintptr_t pc, uintptr_t bp) { + CHECK(size == 0 && trace[0] == pc); + size = 1; + if (!asan_inited) return; + AsanThread *t = asanThreadRegistry().GetCurrent(); + if (!t) return; + uintptr_t *frame = (uintptr_t*)bp; + uintptr_t *prev_frame = frame; + uintptr_t *top = (uintptr_t*)t->stack_top(); + uintptr_t *bottom = (uintptr_t*)t->stack_bottom(); + while (frame >= prev_frame && + frame < top && + frame > bottom && + size < max_size) { + uintptr_t pc1 = frame[1]; + if (pc1 != pc) { + trace[size++] = pc1; + } + prev_frame = frame; + frame = (uintptr_t*)frame[0]; + } +} + +// On 32-bits we don't compress stack traces. +// On 64-bits we compress stack traces: if a given pc differes slightly from +// the previous one, we record a 31-bit offset instead of the full pc. +size_t AsanStackTrace::CompressStack(AsanStackTrace *stack, + uint32_t *compressed, size_t size) { +#if __WORDSIZE == 32 + // Don't compress, just copy. + size_t res = 0; + for (size_t i = 0; i < stack->size && i < size; i++) { + compressed[i] = stack->trace[i]; + res++; + } + if (stack->size < size) + compressed[stack->size] = 0; +#else // 64 bits, compress. + uintptr_t prev_pc = 0; + const uintptr_t kMaxOffset = (1ULL << 30) - 1; + uintptr_t c_index = 0; + size_t res = 0; + for (size_t i = 0, n = stack->size; i < n; i++) { + uintptr_t pc = stack->trace[i]; + if (!pc) break; + if ((int64_t)pc < 0) break; + // Printf("C pc[%ld] %lx\n", i, pc); + if (prev_pc - pc < kMaxOffset || pc - prev_pc < kMaxOffset) { + uintptr_t offset = (int64_t)(pc - prev_pc); + offset |= (1U << 31); + if (c_index >= size) break; + // Printf("C co[%ld] offset %lx\n", i, offset); + compressed[c_index++] = offset; + } else { + uintptr_t hi = pc >> 32; + uintptr_t lo = (pc << 32) >> 32; + CHECK((hi & (1 << 31)) == 0); + if (c_index + 1 >= size) break; + // Printf("C co[%ld] hi/lo: %lx %lx\n", c_index, hi, lo); + compressed[c_index++] = hi; + compressed[c_index++] = lo; + } + res++; + prev_pc = pc; + } + if (c_index < size) + compressed[c_index] = 0; + if (c_index + 1 < size) + compressed[c_index + 1] = 0; +#endif // __WORDSIZE + + // debug-only code +#if 0 + AsanStackTrace check_stack; + UncompressStack(&check_stack, compressed, size); + if (res < check_stack.size) { + Printf("res %ld check_stack.size %ld; c_size %ld\n", res, + check_stack.size, size); + } + // |res| may be greater than check_stack.size, because + // UncompressStack(CompressStack(stack)) eliminates the 0x0 frames. + CHECK(res >= check_stack.size); + CHECK(0 == real_memcmp(check_stack.trace, stack->trace, + check_stack.size * sizeof(uintptr_t))); +#endif + + return res; +} + +void AsanStackTrace::UncompressStack(AsanStackTrace *stack, + uint32_t *compressed, size_t size) { +#if __WORDSIZE == 32 + // Don't uncompress, just copy. + stack->size = 0; + for (size_t i = 0; i < size && i < kStackTraceMax; i++) { + if (!compressed[i]) break; + stack->size++; + stack->trace[i] = compressed[i]; + } +#else // 64 bits, uncompress + uintptr_t prev_pc = 0; + stack->size = 0; + for (size_t i = 0; i < size && stack->size < kStackTraceMax; i++) { + uint32_t x = compressed[i]; + uintptr_t pc = 0; + if (x & (1U << 31)) { + // Printf("U co[%ld] offset: %x\n", i, x); + // this is an offset + int32_t offset = x; + offset = (offset << 1) >> 1; // remove the 31-byte and sign-extend. + pc = prev_pc + offset; + CHECK(pc); + } else { + // CHECK(i + 1 < size); + if (i + 1 >= size) break; + uintptr_t hi = x; + uintptr_t lo = compressed[i+1]; + // Printf("U co[%ld] hi/lo: %lx %lx\n", i, hi, lo); + i++; + pc = (hi << 32) | lo; + if (!pc) break; + } + // Printf("U pc[%ld] %lx\n", stack->size, pc); + stack->trace[stack->size++] = pc; + prev_pc = pc; + } +#endif // __WORDSIZE +} + +} // namespace __asan diff --git a/lib/asan/asan_stack.h b/lib/asan/asan_stack.h new file mode 100644 index 0000000..97aefd6 --- /dev/null +++ b/lib/asan/asan_stack.h @@ -0,0 +1,94 @@ +//===-- asan_stack.h --------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header for asan_stack.cc. +//===----------------------------------------------------------------------===// +#ifndef ASAN_STACK_H +#define ASAN_STACK_H + +#include "asan_internal.h" + +namespace __asan { + +static const size_t kStackTraceMax = 64; + +struct AsanStackTrace { + size_t size; + size_t max_size; + uintptr_t trace[kStackTraceMax]; + static void PrintStack(uintptr_t *addr, size_t size); + void PrintStack() { + PrintStack(this->trace, this->size); + } + void CopyTo(uintptr_t *dst, size_t dst_size) { + for (size_t i = 0; i < size && i < dst_size; i++) + dst[i] = trace[i]; + for (size_t i = size; i < dst_size; i++) + dst[i] = 0; + } + + void CopyFrom(uintptr_t *src, size_t src_size) { + size = src_size; + if (size > kStackTraceMax) size = kStackTraceMax; + for (size_t i = 0; i < size; i++) { + trace[i] = src[i]; + } + } + + void FastUnwindStack(uintptr_t pc, uintptr_t bp); +// static _Unwind_Reason_Code Unwind_Trace( +// struct _Unwind_Context *ctx, void *param); + static uintptr_t GetCurrentPc(); + + static size_t CompressStack(AsanStackTrace *stack, + uint32_t *compressed, size_t size); + static void UncompressStack(AsanStackTrace *stack, + uint32_t *compressed, size_t size); + size_t full_frame_count; +}; + +} // namespace __asan + +// Get the stack trace with the given pc and bp. +// The pc will be in the position 0 of the resulting stack trace. +// The bp may refer to the current frame or to the caller's frame. +// fast_unwind is currently unused. +#define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, fast_unwind, pc, bp) \ + AsanStackTrace stack; \ + { \ + uintptr_t saved_pc = pc; \ + uintptr_t saved_bp = bp; \ + stack.size = 0; \ + stack.full_frame_count = 0; \ + stack.trace[0] = saved_pc; \ + if ((max_s) > 1) { \ + stack.max_size = max_s; \ + stack.FastUnwindStack(saved_pc, saved_bp); \ + } \ + } \ + +#define GET_STACK_TRACE_HERE(max_size, fast_unwind) \ + GET_STACK_TRACE_WITH_PC_AND_BP(max_size, fast_unwind, \ + AsanStackTrace::GetCurrentPc(), GET_CURRENT_FRAME()) \ + +#define GET_STACK_TRACE_HERE_FOR_MALLOC \ + GET_STACK_TRACE_HERE(FLAG_malloc_context_size, FLAG_fast_unwind) + +#define GET_STACK_TRACE_HERE_FOR_FREE(ptr) \ + GET_STACK_TRACE_HERE(FLAG_malloc_context_size, FLAG_fast_unwind) + +#define PRINT_CURRENT_STACK() \ + { \ + GET_STACK_TRACE_HERE(kStackTraceMax, false); \ + stack.PrintStack(); \ + } \ + +#endif // ASAN_STACK_H diff --git a/lib/asan/asan_stats.cc b/lib/asan/asan_stats.cc new file mode 100644 index 0000000..3e4d1b4 --- /dev/null +++ b/lib/asan/asan_stats.cc @@ -0,0 +1,88 @@ +//===-- asan_stats.cc -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Code related to statistics collected by AddressSanitizer. +//===----------------------------------------------------------------------===// +#include "asan_interceptors.h" +#include "asan_interface.h" +#include "asan_internal.h" +#include "asan_lock.h" +#include "asan_stats.h" +#include "asan_thread_registry.h" + +namespace __asan { + +AsanStats::AsanStats() { + CHECK(real_memset != NULL); + real_memset(this, 0, sizeof(AsanStats)); +} + +static void PrintMallocStatsArray(const char *prefix, + size_t (&array)[kNumberOfSizeClasses]) { + Printf("%s", prefix); + for (size_t i = 0; i < kNumberOfSizeClasses; i++) { + if (!array[i]) continue; + Printf("%ld:%ld; ", i, array[i]); + } + Printf("\n"); +} + +void AsanStats::Print() { + Printf("Stats: %ldM malloced (%ldM for red zones) by %ld calls\n", + malloced>>20, malloced_redzones>>20, mallocs); + Printf("Stats: %ldM realloced by %ld calls\n", realloced>>20, reallocs); + Printf("Stats: %ldM freed by %ld calls\n", freed>>20, frees); + Printf("Stats: %ldM really freed by %ld calls\n", + really_freed>>20, real_frees); + Printf("Stats: %ldM (%ld full pages) mmaped in %ld calls\n", + mmaped>>20, mmaped / kPageSize, mmaps); + + PrintMallocStatsArray(" mmaps by size class: ", mmaped_by_size); + PrintMallocStatsArray(" mallocs by size class: ", malloced_by_size); + PrintMallocStatsArray(" frees by size class: ", freed_by_size); + PrintMallocStatsArray(" rfrees by size class: ", really_freed_by_size); + Printf("Stats: malloc large: %ld small slow: %ld\n", + malloc_large, malloc_small_slow); +} + +static AsanLock print_lock(LINKER_INITIALIZED); + +static void PrintAccumulatedStats() { + AsanStats stats = asanThreadRegistry().GetAccumulatedStats(); + // Use lock to keep reports from mixing up. + ScopedLock lock(&print_lock); + stats.Print(); +} + +} // namespace __asan + +// ---------------------- Interface ---------------- {{{1 +using namespace __asan; // NOLINT + +size_t __asan_get_current_allocated_bytes() { + return asanThreadRegistry().GetCurrentAllocatedBytes(); +} + +size_t __asan_get_heap_size() { + return asanThreadRegistry().GetHeapSize(); +} + +size_t __asan_get_free_bytes() { + return asanThreadRegistry().GetFreeBytes(); +} + +size_t __asan_get_unmapped_bytes() { + return 0; +} + +void __asan_print_accumulated_stats() { + PrintAccumulatedStats(); +} diff --git a/lib/asan/asan_stats.h b/lib/asan/asan_stats.h new file mode 100644 index 0000000..d6dd084 --- /dev/null +++ b/lib/asan/asan_stats.h @@ -0,0 +1,59 @@ +//===-- asan_stats.h --------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header for statistics. +//===----------------------------------------------------------------------===// +#ifndef ASAN_STATS_H +#define ASAN_STATS_H + +#include "asan_allocator.h" +#include "asan_internal.h" + +namespace __asan { + +// AsanStats struct is NOT thread-safe. +// Each AsanThread has its own AsanStats, which are sometimes flushed +// to the accumulated AsanStats. +struct AsanStats { + // AsanStats must be a struct consisting of size_t fields only. + // When merging two AsanStats structs, we treat them as arrays of size_t. + size_t mallocs; + size_t malloced; + size_t malloced_redzones; + size_t frees; + size_t freed; + size_t real_frees; + size_t really_freed; + size_t really_freed_redzones; + size_t reallocs; + size_t realloced; + size_t mmaps; + size_t mmaped; + size_t mmaped_by_size[kNumberOfSizeClasses]; + size_t malloced_by_size[kNumberOfSizeClasses]; + size_t freed_by_size[kNumberOfSizeClasses]; + size_t really_freed_by_size[kNumberOfSizeClasses]; + + size_t malloc_large; + size_t malloc_small_slow; + + // Ctor for global AsanStats (accumulated stats and main thread stats). + explicit AsanStats(LinkerInitialized) { } + // Default ctor for thread-local stats. + AsanStats(); + + // Prints formatted stats to stderr. + void Print(); +}; + +} // namespace __asan + +#endif // ASAN_STATS_H diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc new file mode 100644 index 0000000..329197d --- /dev/null +++ b/lib/asan/asan_thread.cc @@ -0,0 +1,178 @@ +//===-- asan_thread.cc ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Thread-related code. +//===----------------------------------------------------------------------===// +#include "asan_allocator.h" +#include "asan_interceptors.h" +#include "asan_thread.h" +#include "asan_thread_registry.h" +#include "asan_mapping.h" + +#if ASAN_USE_SYSINFO == 1 +#include "sysinfo/sysinfo.h" +#endif + +#include +#include +#include +#include +#include + +namespace __asan { + +AsanThread::AsanThread(LinkerInitialized x) + : fake_stack_(x), + malloc_storage_(x), + stats_(x) { } + +AsanThread::AsanThread(int parent_tid, void *(*start_routine) (void *), + void *arg, AsanStackTrace *stack) + : start_routine_(start_routine), + arg_(arg) { + asanThreadRegistry().RegisterThread(this, parent_tid, stack); +} + +AsanThread::~AsanThread() { + asanThreadRegistry().UnregisterThread(this); + fake_stack().Cleanup(); + // We also clear the shadow on thread destruction because + // some code may still be executing in later TSD destructors + // and we don't want it to have any poisoned stack. + ClearShadowForThreadStack(); +} + +void AsanThread::ClearShadowForThreadStack() { + uintptr_t shadow_bot = MemToShadow(stack_bottom_); + uintptr_t shadow_top = MemToShadow(stack_top_); + real_memset((void*)shadow_bot, 0, shadow_top - shadow_bot); +} + +void AsanThread::Init() { + SetThreadStackTopAndBottom(); + fake_stack_.Init(stack_size()); + if (FLAG_v >= 1) { + int local = 0; + Report("T%d: stack [%p,%p) size 0x%lx; local=%p, pthread_self=%p\n", + tid(), stack_bottom_, stack_top_, + stack_top_ - stack_bottom_, &local, pthread_self()); + } + + CHECK(AddrIsInMem(stack_bottom_)); + CHECK(AddrIsInMem(stack_top_)); + + ClearShadowForThreadStack(); +} + +void *AsanThread::ThreadStart() { + Init(); + + if (!start_routine_) { + // start_routine_ == NULL if we're on the main thread or on one of the + // OS X libdispatch worker threads. But nobody is supposed to call + // ThreadStart() for the worker threads. + CHECK(tid() == 0); + return 0; + } + + void *res = start_routine_(arg_); + malloc_storage().CommitBack(); + + if (FLAG_v >= 1) { + Report("T%d exited\n", tid()); + } + + return res; +} + +const char *AsanThread::GetFrameNameByAddr(uintptr_t addr, uintptr_t *offset) { + uintptr_t bottom = 0; + bool is_fake_stack = false; + if (AddrIsInStack(addr)) { + bottom = stack_bottom(); + } else { + bottom = fake_stack().AddrIsInFakeStack(addr); + CHECK(bottom); + is_fake_stack = true; + } + uintptr_t aligned_addr = addr & ~(__WORDSIZE/8 - 1); // align addr. + uintptr_t *ptr = (uintptr_t*)aligned_addr; + while (ptr >= (uintptr_t*)bottom) { + if (ptr[0] == kCurrentStackFrameMagic || + (is_fake_stack && ptr[0] == kRetiredStackFrameMagic)) { + *offset = addr - (uintptr_t)ptr; + return (const char*)ptr[1]; + } + ptr--; + } + *offset = 0; + return "UNKNOWN"; +} + +void AsanThread::SetThreadStackTopAndBottom() { +#ifdef __APPLE__ + size_t stacksize = pthread_get_stacksize_np(pthread_self()); + void *stackaddr = pthread_get_stackaddr_np(pthread_self()); + stack_top_ = (uintptr_t)stackaddr; + stack_bottom_ = stack_top_ - stacksize; + int local; + CHECK(AddrIsInStack((uintptr_t)&local)); +#else +#if ASAN_USE_SYSINFO == 1 + if (tid() == 0) { + // This is the main thread. Libpthread may not be initialized yet. + struct rlimit rl; + CHECK(getrlimit(RLIMIT_STACK, &rl) == 0); + + // Find the mapping that contains a stack variable. + ProcMapsIterator it(0); + uint64_t start, end; + uint64_t prev_end = 0; + while (it.Next(&start, &end, NULL, NULL, NULL, NULL)) { + if ((uintptr_t)&rl < end) + break; + prev_end = end; + } + CHECK((uintptr_t)&rl >= start && (uintptr_t)&rl < end); + + // Get stacksize from rlimit, but clip it so that it does not overlap + // with other mappings. + size_t stacksize = rl.rlim_cur; + if (stacksize > end - prev_end) + stacksize = end - prev_end; + if (stacksize > kMaxThreadStackSize) + stacksize = kMaxThreadStackSize; + stack_top_ = end; + stack_bottom_ = end - stacksize; + CHECK(AddrIsInStack((uintptr_t)&rl)); + return; + } +#endif + pthread_attr_t attr; + CHECK(pthread_getattr_np(pthread_self(), &attr) == 0); + size_t stacksize = 0; + void *stackaddr = NULL; + pthread_attr_getstack(&attr, &stackaddr, &stacksize); + pthread_attr_destroy(&attr); + + stack_top_ = (uintptr_t)stackaddr + stacksize; + stack_bottom_ = (uintptr_t)stackaddr; + // When running with unlimited stack size, we still want to set some limit. + // The unlimited stack size is caused by 'ulimit -s unlimited'. + // Also, for some reason, GNU make spawns subrocesses with unlimited stack. + if (stacksize > kMaxThreadStackSize) { + stack_bottom_ = stack_top_ - kMaxThreadStackSize; + } + CHECK(AddrIsInStack((uintptr_t)&attr)); +#endif +} + +} // namespace __asan diff --git a/lib/asan/asan_thread.h b/lib/asan/asan_thread.h new file mode 100644 index 0000000..c382c85 --- /dev/null +++ b/lib/asan/asan_thread.h @@ -0,0 +1,108 @@ +//===-- asan_thread.h -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header for asan_thread.cc. +//===----------------------------------------------------------------------===// +#ifndef ASAN_THREAD_H +#define ASAN_THREAD_H + +#include "asan_allocator.h" +#include "asan_internal.h" +#include "asan_stack.h" +#include "asan_stats.h" + +namespace __asan { + +const size_t kMaxThreadStackSize = 16 * (1 << 20); // 16M + +class AsanThread; + +// These objects are created for every thread and are never deleted, +// so we can find them by tid even if the thread is long dead. +class AsanThreadSummary { + public: + explicit AsanThreadSummary(LinkerInitialized) { } // for T0. + AsanThreadSummary(int tid, int parent_tid, AsanStackTrace *stack) + : tid_(tid), + parent_tid_(parent_tid), + announced_(false) { + if (stack) { + stack_ = *stack; + } + thread_ = 0; + } + void Announce() { + if (tid_ == 0) return; // no need to announce the main thread. + if (!announced_) { + announced_ = true; + Printf("Thread T%d created by T%d here:\n", tid_, parent_tid_); + stack_.PrintStack(); + } + } + int tid() { return tid_; } + AsanThread *thread() { return thread_; } + void set_thread(AsanThread *thread) { thread_ = thread; } + private: + int tid_; + int parent_tid_; + bool announced_; + AsanStackTrace stack_; + AsanThread *thread_; +}; + +// AsanThread are stored in TSD and destroyed when the thread dies. +class AsanThread { + public: + explicit AsanThread(LinkerInitialized); // for T0. + AsanThread(int parent_tid, void *(*start_routine) (void *), + void *arg, AsanStackTrace *stack); + ~AsanThread(); + + void Init(); // Should be called from the thread itself. + void *ThreadStart(); + + uintptr_t stack_top() { return stack_top_; } + uintptr_t stack_bottom() { return stack_bottom_; } + size_t stack_size() { return stack_top_ - stack_bottom_; } + int tid() { return summary_->tid(); } + AsanThreadSummary *summary() { return summary_; } + void set_summary(AsanThreadSummary *summary) { summary_ = summary; } + + const char *GetFrameNameByAddr(uintptr_t addr, uintptr_t *offset); + + bool AddrIsInStack(uintptr_t addr) { + return addr >= stack_bottom_ && addr < stack_top_; + } + + FakeStack &fake_stack() { return fake_stack_; } + AsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; } + AsanStats &stats() { return stats_; } + + static const int kInvalidTid = -1; + + private: + + void SetThreadStackTopAndBottom(); + void ClearShadowForThreadStack(); + AsanThreadSummary *summary_; + void *(*start_routine_) (void *param); + void *arg_; + uintptr_t stack_top_; + uintptr_t stack_bottom_; + + FakeStack fake_stack_; + AsanThreadLocalMallocStorage malloc_storage_; + AsanStats stats_; +}; + +} // namespace __asan + +#endif // ASAN_THREAD_H diff --git a/lib/asan/asan_thread_registry.cc b/lib/asan/asan_thread_registry.cc new file mode 100644 index 0000000..39fba44 --- /dev/null +++ b/lib/asan/asan_thread_registry.cc @@ -0,0 +1,227 @@ +//===-- asan_thread_registry.cc ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// AsanThreadRegistry-related code. AsanThreadRegistry is a container +// for summaries of all created threads. +//===----------------------------------------------------------------------===// + +#include "asan_stack.h" +#include "asan_thread.h" +#include "asan_thread_registry.h" + +#include + +namespace __asan { + +static AsanThreadRegistry asan_thread_registry(__asan::LINKER_INITIALIZED); + +AsanThreadRegistry &asanThreadRegistry() { + return asan_thread_registry; +} + +#ifdef ANDROID +#ifndef PTHREAD_DESTRUCTOR_ITERATIONS +#define PTHREAD_DESTRUCTOR_ITERATIONS 4 +#endif +#endif + +// Dark magic below. In order to be able to notice that we're not handling +// some thread creation routines (e.g. on Mac OS) we want to distinguish the +// thread that used to have a corresponding AsanThread object from the thread +// that never had one. That's why upon AsanThread destruction we set the +// pthread_key value to some odd number (that's not a valid pointer), instead +// of NULL. +// Because the TSD destructor for a non-NULL key value is called iteratively, +// we increase the value by two, keeping it an invalid pointer. +// Because the TSD implementations are allowed to call such a destructor +// infinitely (see +// http://pubs.opengroup.org/onlinepubs/009604499/functions/pthread_key_create.html +// ), we exit the program after a certain number of iterations. +static void DestroyAsanTsd(void *tsd) { + intptr_t iter = (intptr_t)tsd; + if (iter % 2 == 0) { + // The pointer is valid. + AsanThread *t = (AsanThread*)tsd; + if (t != asanThreadRegistry().GetMain()) { + delete t; + } + iter = 1; + } else { + // The pointer is invalid -- we've already destroyed the TSD before. + // If |iter| is too big, we're in the infinite loop. This should be + // impossible on the systems AddressSanitizer was tested on. + CHECK(iter < 4 * PTHREAD_DESTRUCTOR_ITERATIONS); + iter += 2; + } + CHECK(0 == pthread_setspecific(asanThreadRegistry().GetTlsKey(), + (void*)iter)); + if (FLAG_v >= 2) { + Report("DestroyAsanTsd: writing %p to the TSD slot of thread %p\n", + (void*)iter, pthread_self()); + } +} + +AsanThreadRegistry::AsanThreadRegistry(LinkerInitialized x) + : main_thread_(x), + main_thread_summary_(x), + accumulated_stats_(x), + mu_(x) { } + +void AsanThreadRegistry::Init() { + CHECK(0 == pthread_key_create(&tls_key_, DestroyAsanTsd)); + tls_key_created_ = true; + SetCurrent(&main_thread_); + main_thread_.set_summary(&main_thread_summary_); + main_thread_summary_.set_thread(&main_thread_); + thread_summaries_[0] = &main_thread_summary_; + n_threads_ = 1; +} + +void AsanThreadRegistry::RegisterThread(AsanThread *thread, int parent_tid, + AsanStackTrace *stack) { + ScopedLock lock(&mu_); + CHECK(n_threads_ > 0); + int tid = n_threads_; + n_threads_++; + CHECK(n_threads_ < kMaxNumberOfThreads); + AsanThreadSummary *summary = new AsanThreadSummary(tid, parent_tid, stack); + summary->set_thread(thread); + thread_summaries_[tid] = summary; + thread->set_summary(summary); +} + +void AsanThreadRegistry::UnregisterThread(AsanThread *thread) { + ScopedLock lock(&mu_); + FlushToAccumulatedStatsUnlocked(&thread->stats()); + AsanThreadSummary *summary = thread->summary(); + CHECK(summary); + summary->set_thread(NULL); +} + +AsanThread *AsanThreadRegistry::GetMain() { + return &main_thread_; +} + +AsanThread *AsanThreadRegistry::GetCurrent() { + CHECK(tls_key_created_); + AsanThread *thread = (AsanThread*)pthread_getspecific(tls_key_); + if ((!thread || (intptr_t)thread % 2) && FLAG_v >= 2) { + Report("GetCurrent: %p for thread %p\n", thread, pthread_self()); + } + if ((intptr_t)thread % 2) { + // Invalid pointer -- we've deleted the AsanThread already. Return NULL as + // if the TSD was empty. + // TODO(glider): if the code in the client TSD destructor calls + // pthread_create(), we'll set the parent tid of the spawned thread to NULL, + // although the creation stack will belong to the current thread. This may + // confuse the user, but is quite unlikely. + return NULL; + } else { + // NULL or valid pointer to AsanThread. + return thread; + } +} + +void AsanThreadRegistry::SetCurrent(AsanThread *t) { + if (FLAG_v >=2) { + Report("SetCurrent: %p for thread %p\n", t, pthread_self()); + } + // Make sure we do not reset the current AsanThread. + intptr_t old_key = (intptr_t)pthread_getspecific(tls_key_); + CHECK(!old_key || old_key % 2); + CHECK(0 == pthread_setspecific(tls_key_, t)); + CHECK(pthread_getspecific(tls_key_) == t); +} + +pthread_key_t AsanThreadRegistry::GetTlsKey() { + return tls_key_; +} + +// Returns true iff DestroyAsanTsd() was already called for this thread. +bool AsanThreadRegistry::IsCurrentThreadDying() { + CHECK(tls_key_created_); + intptr_t thread = (intptr_t)pthread_getspecific(tls_key_); + return (bool)(thread % 2); +} + +AsanStats &AsanThreadRegistry::GetCurrentThreadStats() { + AsanThread *t = GetCurrent(); + return (t) ? t->stats() : main_thread_.stats(); +} + +AsanStats AsanThreadRegistry::GetAccumulatedStats() { + ScopedLock lock(&mu_); + UpdateAccumulatedStatsUnlocked(); + return accumulated_stats_; +} + +size_t AsanThreadRegistry::GetCurrentAllocatedBytes() { + ScopedLock lock(&mu_); + UpdateAccumulatedStatsUnlocked(); + return accumulated_stats_.malloced - accumulated_stats_.freed; +} + +size_t AsanThreadRegistry::GetHeapSize() { + ScopedLock lock(&mu_); + UpdateAccumulatedStatsUnlocked(); + return accumulated_stats_.mmaped; +} + +size_t AsanThreadRegistry::GetFreeBytes() { + ScopedLock lock(&mu_); + UpdateAccumulatedStatsUnlocked(); + return accumulated_stats_.mmaped + - accumulated_stats_.malloced + - accumulated_stats_.malloced_redzones + + accumulated_stats_.really_freed + + accumulated_stats_.really_freed_redzones; +} + +AsanThreadSummary *AsanThreadRegistry::FindByTid(int tid) { + CHECK(tid >= 0); + CHECK(tid < n_threads_); + CHECK(thread_summaries_[tid]); + return thread_summaries_[tid]; +} + +AsanThread *AsanThreadRegistry::FindThreadByStackAddress(uintptr_t addr) { + ScopedLock lock(&mu_); + for (int tid = 0; tid < n_threads_; tid++) { + AsanThread *t = thread_summaries_[tid]->thread(); + if (!t) continue; + if (t->fake_stack().AddrIsInFakeStack(addr) || t->AddrIsInStack(addr)) { + return t; + } + } + return 0; +} + +void AsanThreadRegistry::UpdateAccumulatedStatsUnlocked() { + for (int tid = 0; tid < n_threads_; tid++) { + AsanThread *t = thread_summaries_[tid]->thread(); + if (t != NULL) { + FlushToAccumulatedStatsUnlocked(&t->stats()); + } + } +} + +void AsanThreadRegistry::FlushToAccumulatedStatsUnlocked(AsanStats *stats) { + // AsanStats consists of variables of type size_t only. + size_t *dst = (size_t*)&accumulated_stats_; + size_t *src = (size_t*)stats; + size_t num_fields = sizeof(AsanStats) / sizeof(size_t); + for (size_t i = 0; i < num_fields; i++) { + dst[i] += src[i]; + src[i] = 0; + } +} + +} // namespace __asan diff --git a/lib/asan/asan_thread_registry.h b/lib/asan/asan_thread_registry.h new file mode 100644 index 0000000..b80dd4d --- /dev/null +++ b/lib/asan/asan_thread_registry.h @@ -0,0 +1,88 @@ +//===-- asan_thread_registry.h ----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header for asan_thread_registry.cc +//===----------------------------------------------------------------------===// + +#ifndef ASAN_THREAD_REGISTRY_H +#define ASAN_THREAD_REGISTRY_H + +#include "asan_lock.h" +#include "asan_stack.h" +#include "asan_stats.h" +#include "asan_thread.h" + +namespace __asan { + +// Stores summaries of all created threads, returns current thread, +// thread by tid, thread by stack address. There is a single instance +// of AsanThreadRegistry for the whole program. +// AsanThreadRegistry is thread-safe. +class AsanThreadRegistry { + public: + explicit AsanThreadRegistry(LinkerInitialized); + void Init(); + void RegisterThread(AsanThread *thread, int parent_tid, + AsanStackTrace *stack); + void UnregisterThread(AsanThread *thread); + + AsanThread *GetMain(); + // Get the current thread. May return NULL. + AsanThread *GetCurrent(); + void SetCurrent(AsanThread *t); + pthread_key_t GetTlsKey(); + bool IsCurrentThreadDying(); + + int GetCurrentTidOrMinusOne() { + AsanThread *t = GetCurrent(); + return t ? t->tid() : -1; + } + + // Returns stats for GetCurrent(), or stats for + // T0 if GetCurrent() returns NULL. + AsanStats &GetCurrentThreadStats(); + // Flushes all thread-local stats to accumulated stats, and returns + // a copy of accumulated stats. + AsanStats GetAccumulatedStats(); + size_t GetCurrentAllocatedBytes(); + size_t GetHeapSize(); + size_t GetFreeBytes(); + + AsanThreadSummary *FindByTid(int tid); + AsanThread *FindThreadByStackAddress(uintptr_t addr); + + private: + void UpdateAccumulatedStatsUnlocked(); + // Adds values of all counters in "stats" to accumulated stats, + // and fills "stats" with zeroes. + void FlushToAccumulatedStatsUnlocked(AsanStats *stats); + + static const int kMaxNumberOfThreads = (1 << 22); // 4M + AsanThreadSummary *thread_summaries_[kMaxNumberOfThreads]; + AsanThread main_thread_; + AsanThreadSummary main_thread_summary_; + AsanStats accumulated_stats_; + int n_threads_; + AsanLock mu_; + // For each thread tls_key_ stores the pointer to the corresponding + // AsanThread. + pthread_key_t tls_key_; + // This flag is updated only once at program startup, and then read + // by concurrent threads. + bool tls_key_created_; +}; + +// Returns a single instance of registry. +AsanThreadRegistry &asanThreadRegistry(); + +} // namespace __asan + +#endif // ASAN_THREAD_REGISTRY_H diff --git a/lib/asan/mach_override/LICENSE.TXT b/lib/asan/mach_override/LICENSE.TXT new file mode 100644 index 0000000..9446965 --- /dev/null +++ b/lib/asan/mach_override/LICENSE.TXT @@ -0,0 +1,3 @@ +Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: +Some rights reserved: + diff --git a/lib/asan/mach_override/Makefile.mk b/lib/asan/mach_override/Makefile.mk new file mode 100644 index 0000000..78be0b3 --- /dev/null +++ b/lib/asan/mach_override/Makefile.mk @@ -0,0 +1,22 @@ +#===- lib/asan/mach_override/Makefile.mk -------------------*- Makefile -*--===# +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# + +ModuleName := asan +SubDirs := + +Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file))) +ObjNames := $(Sources:%.c=%.o) + +Implementation := Generic + +# FIXME: use automatic dependencies? +Dependencies := $(wildcard $(Dir)/*.h) + +# Define a convenience variable for all the asan functions. +AsanFunctions += $(Sources:%.c=%) diff --git a/lib/asan/mach_override/README.txt b/lib/asan/mach_override/README.txt new file mode 100644 index 0000000..5f62ad7 --- /dev/null +++ b/lib/asan/mach_override/README.txt @@ -0,0 +1,9 @@ +-- mach_override.c is taken from upstream version at + https://github.com/rentzsch/mach_star/tree/f8e0c424b5be5cb641ded67c265e616157ae4bcf +-- Added debugging code under DEBUG_DISASM. +-- The files are guarded with #ifdef __APPLE__ +-- some opcodes are added in order to parse the library functions on Lion +-- fixupInstructions() is extended to relocate relative calls, not only jumps +-- mach_override_ptr is renamed to __asan_mach_override_ptr and + other functions are marked as hidden. + diff --git a/lib/asan/mach_override/mach_override.c b/lib/asan/mach_override/mach_override.c new file mode 100644 index 0000000..640d03d5 --- /dev/null +++ b/lib/asan/mach_override/mach_override.c @@ -0,0 +1,862 @@ +/******************************************************************************* + mach_override.c + Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: + Some rights reserved: + + ***************************************************************************/ +#ifdef __APPLE__ + +#include "mach_override.h" + +#include +#include +#include +#include +#include + +#include + +//#define DEBUG_DISASM 1 +#undef DEBUG_DISASM + +/************************** +* +* Constants +* +**************************/ +#pragma mark - +#pragma mark (Constants) + +#if defined(__ppc__) || defined(__POWERPC__) + +long kIslandTemplate[] = { + 0x9001FFFC, // stw r0,-4(SP) + 0x3C00DEAD, // lis r0,0xDEAD + 0x6000BEEF, // ori r0,r0,0xBEEF + 0x7C0903A6, // mtctr r0 + 0x8001FFFC, // lwz r0,-4(SP) + 0x60000000, // nop ; optionally replaced + 0x4E800420 // bctr +}; + +#define kAddressHi 3 +#define kAddressLo 5 +#define kInstructionHi 10 +#define kInstructionLo 11 + +#elif defined(__i386__) + +#define kOriginalInstructionsSize 16 + +char kIslandTemplate[] = { + // kOriginalInstructionsSize nop instructions so that we + // should have enough space to host original instructions + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, + // Now the real jump instruction + 0xE9, 0xEF, 0xBE, 0xAD, 0xDE +}; + +#define kInstructions 0 +#define kJumpAddress kInstructions + kOriginalInstructionsSize + 1 +#elif defined(__x86_64__) + +#define kOriginalInstructionsSize 32 + +#define kJumpAddress kOriginalInstructionsSize + 6 + +char kIslandTemplate[] = { + // kOriginalInstructionsSize nop instructions so that we + // should have enough space to host original instructions + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, + 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, + // Now the real jump instruction + 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; + +#endif + +#define kAllocateHigh 1 +#define kAllocateNormal 0 + +/************************** +* +* Data Types +* +**************************/ +#pragma mark - +#pragma mark (Data Types) + +typedef struct { + char instructions[sizeof(kIslandTemplate)]; + int allocatedHigh; +} BranchIsland; + +/************************** +* +* Funky Protos +* +**************************/ +#pragma mark - +#pragma mark (Funky Protos) + + mach_error_t +allocateBranchIsland( + BranchIsland **island, + int allocateHigh, + void *originalFunctionAddress) __attribute__((visibility("hidden"))); + + mach_error_t +freeBranchIsland( + BranchIsland *island ) __attribute__((visibility("hidden"))); + +#if defined(__ppc__) || defined(__POWERPC__) + mach_error_t +setBranchIslandTarget( + BranchIsland *island, + const void *branchTo, + long instruction ) __attribute__((visibility("hidden"))); +#endif + +#if defined(__i386__) || defined(__x86_64__) +mach_error_t +setBranchIslandTarget_i386( + BranchIsland *island, + const void *branchTo, + char* instructions ) __attribute__((visibility("hidden"))); +void +atomic_mov64( + uint64_t *targetAddress, + uint64_t value ) __attribute__((visibility("hidden"))); + + static Boolean +eatKnownInstructions( + unsigned char *code, + uint64_t *newInstruction, + int *howManyEaten, + char *originalInstructions, + int *originalInstructionCount, + uint8_t *originalInstructionSizes ) __attribute__((visibility("hidden"))); + + static void +fixupInstructions( + void *originalFunction, + void *escapeIsland, + void *instructionsToFix, + int instructionCount, + uint8_t *instructionSizes ) __attribute__((visibility("hidden"))); +#endif + +/******************************************************************************* +* +* Interface +* +*******************************************************************************/ +#pragma mark - +#pragma mark (Interface) + +#if defined(__i386__) || defined(__x86_64__) +mach_error_t makeIslandExecutable(void *address) { + mach_error_t err = err_none; + vm_size_t pageSize; + host_page_size( mach_host_self(), &pageSize ); + uintptr_t page = (uintptr_t)address & ~(uintptr_t)(pageSize-1); + int e = err_none; + e |= mprotect((void *)page, pageSize, PROT_EXEC | PROT_READ | PROT_WRITE); + e |= msync((void *)page, pageSize, MS_INVALIDATE ); + if (e) { + err = err_cannot_override; + } + return err; +} +#endif + + mach_error_t +__asan_mach_override_ptr( + void *originalFunctionAddress, + const void *overrideFunctionAddress, + void **originalFunctionReentryIsland ) +{ + assert( originalFunctionAddress ); + assert( overrideFunctionAddress ); + + // this addresses overriding such functions as AudioOutputUnitStart() + // test with modified DefaultOutputUnit project +#if defined(__x86_64__) + for(;;){ + if(*(uint16_t*)originalFunctionAddress==0x25FF) // jmp qword near [rip+0x????????] + originalFunctionAddress=*(void**)((char*)originalFunctionAddress+6+*(int32_t *)((uint16_t*)originalFunctionAddress+1)); + else break; + } +#elif defined(__i386__) + for(;;){ + if(*(uint16_t*)originalFunctionAddress==0x25FF) // jmp *0x???????? + originalFunctionAddress=**(void***)((uint16_t*)originalFunctionAddress+1); + else break; + } +#endif +#ifdef DEBUG_DISASM + { + fprintf(stderr, "Replacing function at %p\n", originalFunctionAddress); + fprintf(stderr, "First 16 bytes of the function: "); + unsigned char *orig = (unsigned char *)originalFunctionAddress; + int i; + for (i = 0; i < 16; i++) { + fprintf(stderr, "%x ", (unsigned int) orig[i]); + } + fprintf(stderr, "\n"); + fprintf(stderr, + "To disassemble, save the following function as disas.c" + " and run:\n gcc -c disas.c && gobjdump -d disas.o\n" + "The first 16 bytes of the original function will start" + " after four nop instructions.\n"); + fprintf(stderr, "\nvoid foo() {\n asm volatile(\"nop;nop;nop;nop;\");\n"); + int j = 0; + for (j = 0; j < 2; j++) { + fprintf(stderr, " asm volatile(\".byte "); + for (i = 8 * j; i < 8 * (j+1) - 1; i++) { + fprintf(stderr, "0x%x, ", (unsigned int) orig[i]); + } + fprintf(stderr, "0x%x;\");\n", (unsigned int) orig[8 * (j+1) - 1]); + } + fprintf(stderr, "}\n\n"); + } +#endif + + long *originalFunctionPtr = (long*) originalFunctionAddress; + mach_error_t err = err_none; + +#if defined(__ppc__) || defined(__POWERPC__) + // Ensure first instruction isn't 'mfctr'. + #define kMFCTRMask 0xfc1fffff + #define kMFCTRInstruction 0x7c0903a6 + + long originalInstruction = *originalFunctionPtr; + if( !err && ((originalInstruction & kMFCTRMask) == kMFCTRInstruction) ) + err = err_cannot_override; +#elif defined(__i386__) || defined(__x86_64__) + int eatenCount = 0; + int originalInstructionCount = 0; + char originalInstructions[kOriginalInstructionsSize]; + uint8_t originalInstructionSizes[kOriginalInstructionsSize]; + uint64_t jumpRelativeInstruction = 0; // JMP + + Boolean overridePossible = eatKnownInstructions ((unsigned char *)originalFunctionPtr, + &jumpRelativeInstruction, &eatenCount, + originalInstructions, &originalInstructionCount, + originalInstructionSizes ); +#ifdef DEBUG_DISASM + if (!overridePossible) fprintf(stderr, "overridePossible = false @%d\n", __LINE__); +#endif + if (eatenCount > kOriginalInstructionsSize) { +#ifdef DEBUG_DISASM + fprintf(stderr, "Too many instructions eaten\n"); +#endif + overridePossible = false; + } + if (!overridePossible) err = err_cannot_override; + if (err) fprintf(stderr, "err = %x %s:%d\n", err, __FILE__, __LINE__); +#endif + + // Make the original function implementation writable. + if( !err ) { + err = vm_protect( mach_task_self(), + (vm_address_t) originalFunctionPtr, 8, false, + (VM_PROT_ALL | VM_PROT_COPY) ); + if( err ) + err = vm_protect( mach_task_self(), + (vm_address_t) originalFunctionPtr, 8, false, + (VM_PROT_DEFAULT | VM_PROT_COPY) ); + } + if (err) fprintf(stderr, "err = %x %s:%d\n", err, __FILE__, __LINE__); + + // Allocate and target the escape island to the overriding function. + BranchIsland *escapeIsland = NULL; + if( !err ) + err = allocateBranchIsland( &escapeIsland, kAllocateHigh, originalFunctionAddress ); + if (err) fprintf(stderr, "err = %x %s:%d\n", err, __FILE__, __LINE__); + + +#if defined(__ppc__) || defined(__POWERPC__) + if( !err ) + err = setBranchIslandTarget( escapeIsland, overrideFunctionAddress, 0 ); + + // Build the branch absolute instruction to the escape island. + long branchAbsoluteInstruction = 0; // Set to 0 just to silence warning. + if( !err ) { + long escapeIslandAddress = ((long) escapeIsland) & 0x3FFFFFF; + branchAbsoluteInstruction = 0x48000002 | escapeIslandAddress; + } +#elif defined(__i386__) || defined(__x86_64__) + if (err) fprintf(stderr, "err = %x %s:%d\n", err, __FILE__, __LINE__); + + if( !err ) + err = setBranchIslandTarget_i386( escapeIsland, overrideFunctionAddress, 0 ); + + if (err) fprintf(stderr, "err = %x %s:%d\n", err, __FILE__, __LINE__); + // Build the jump relative instruction to the escape island +#endif + + +#if defined(__i386__) || defined(__x86_64__) + if (!err) { + uint32_t addressOffset = ((char*)escapeIsland - (char*)originalFunctionPtr - 5); + addressOffset = OSSwapInt32(addressOffset); + + jumpRelativeInstruction |= 0xE900000000000000LL; + jumpRelativeInstruction |= ((uint64_t)addressOffset & 0xffffffff) << 24; + jumpRelativeInstruction = OSSwapInt64(jumpRelativeInstruction); + } +#endif + + // Optionally allocate & return the reentry island. This may contain relocated + // jmp instructions and so has all the same addressing reachability requirements + // the escape island has to the original function, except the escape island is + // technically our original function. + BranchIsland *reentryIsland = NULL; + if( !err && originalFunctionReentryIsland ) { + err = allocateBranchIsland( &reentryIsland, kAllocateHigh, escapeIsland); + if( !err ) + *originalFunctionReentryIsland = reentryIsland; + } + +#if defined(__ppc__) || defined(__POWERPC__) + // Atomically: + // o If the reentry island was allocated: + // o Insert the original instruction into the reentry island. + // o Target the reentry island at the 2nd instruction of the + // original function. + // o Replace the original instruction with the branch absolute. + if( !err ) { + int escapeIslandEngaged = false; + do { + if( reentryIsland ) + err = setBranchIslandTarget( reentryIsland, + (void*) (originalFunctionPtr+1), originalInstruction ); + if( !err ) { + escapeIslandEngaged = CompareAndSwap( originalInstruction, + branchAbsoluteInstruction, + (UInt32*)originalFunctionPtr ); + if( !escapeIslandEngaged ) { + // Someone replaced the instruction out from under us, + // re-read the instruction, make sure it's still not + // 'mfctr' and try again. + originalInstruction = *originalFunctionPtr; + if( (originalInstruction & kMFCTRMask) == kMFCTRInstruction) + err = err_cannot_override; + } + } + } while( !err && !escapeIslandEngaged ); + } +#elif defined(__i386__) || defined(__x86_64__) + // Atomically: + // o If the reentry island was allocated: + // o Insert the original instructions into the reentry island. + // o Target the reentry island at the first non-replaced + // instruction of the original function. + // o Replace the original first instructions with the jump relative. + // + // Note that on i386, we do not support someone else changing the code under our feet + if ( !err ) { + fixupInstructions(originalFunctionPtr, reentryIsland, originalInstructions, + originalInstructionCount, originalInstructionSizes ); + + if( reentryIsland ) + err = setBranchIslandTarget_i386( reentryIsland, + (void*) ((char *)originalFunctionPtr+eatenCount), originalInstructions ); + // try making islands executable before planting the jmp +#if defined(__x86_64__) || defined(__i386__) + if( !err ) + err = makeIslandExecutable(escapeIsland); + if( !err && reentryIsland ) + err = makeIslandExecutable(reentryIsland); +#endif + if ( !err ) + atomic_mov64((uint64_t *)originalFunctionPtr, jumpRelativeInstruction); + } +#endif + + // Clean up on error. + if( err ) { + if( reentryIsland ) + freeBranchIsland( reentryIsland ); + if( escapeIsland ) + freeBranchIsland( escapeIsland ); + } + +#ifdef DEBUG_DISASM + { + fprintf(stderr, "First 16 bytes of the function after slicing: "); + unsigned char *orig = (unsigned char *)originalFunctionAddress; + int i; + for (i = 0; i < 16; i++) { + fprintf(stderr, "%x ", (unsigned int) orig[i]); + } + fprintf(stderr, "\n"); + } +#endif + return err; +} + +/******************************************************************************* +* +* Implementation +* +*******************************************************************************/ +#pragma mark - +#pragma mark (Implementation) + +/***************************************************************************//** + Implementation: Allocates memory for a branch island. + + @param island <- The allocated island. + @param allocateHigh -> Whether to allocate the island at the end of the + address space (for use with the branch absolute + instruction). + @result <- mach_error_t + + ***************************************************************************/ + + mach_error_t +allocateBranchIsland( + BranchIsland **island, + int allocateHigh, + void *originalFunctionAddress) +{ + assert( island ); + + mach_error_t err = err_none; + + if( allocateHigh ) { + vm_size_t pageSize; + err = host_page_size( mach_host_self(), &pageSize ); + if( !err ) { + assert( sizeof( BranchIsland ) <= pageSize ); +#if defined(__ppc__) || defined(__POWERPC__) + vm_address_t first = 0xfeffffff; + vm_address_t last = 0xfe000000 + pageSize; +#elif defined(__x86_64__) + vm_address_t first = ((uint64_t)originalFunctionAddress & ~(uint64_t)(((uint64_t)1 << 31) - 1)) | ((uint64_t)1 << 31); // start in the middle of the page? + vm_address_t last = 0x0; +#else + vm_address_t first = 0xffc00000; + vm_address_t last = 0xfffe0000; +#endif + + vm_address_t page = first; + int allocated = 0; + vm_map_t task_self = mach_task_self(); + + while( !err && !allocated && page != last ) { + + err = vm_allocate( task_self, &page, pageSize, 0 ); + if( err == err_none ) + allocated = 1; + else if( err == KERN_NO_SPACE ) { +#if defined(__x86_64__) + page -= pageSize; +#else + page += pageSize; +#endif + err = err_none; + } + } + if( allocated ) + *island = (BranchIsland*) page; + else if( !allocated && !err ) + err = KERN_NO_SPACE; + } + } else { + void *block = malloc( sizeof( BranchIsland ) ); + if( block ) + *island = block; + else + err = KERN_NO_SPACE; + } + if( !err ) + (**island).allocatedHigh = allocateHigh; + + return err; +} + +/***************************************************************************//** + Implementation: Deallocates memory for a branch island. + + @param island -> The island to deallocate. + @result <- mach_error_t + + ***************************************************************************/ + + mach_error_t +freeBranchIsland( + BranchIsland *island ) +{ + assert( island ); + assert( (*(long*)&island->instructions[0]) == kIslandTemplate[0] ); + assert( island->allocatedHigh ); + + mach_error_t err = err_none; + + if( island->allocatedHigh ) { + vm_size_t pageSize; + err = host_page_size( mach_host_self(), &pageSize ); + if( !err ) { + assert( sizeof( BranchIsland ) <= pageSize ); + err = vm_deallocate( + mach_task_self(), + (vm_address_t) island, pageSize ); + } + } else { + free( island ); + } + + return err; +} + +/***************************************************************************//** + Implementation: Sets the branch island's target, with an optional + instruction. + + @param island -> The branch island to insert target into. + @param branchTo -> The address of the target. + @param instruction -> Optional instruction to execute prior to branch. Set + to zero for nop. + @result <- mach_error_t + + ***************************************************************************/ +#if defined(__ppc__) || defined(__POWERPC__) + mach_error_t +setBranchIslandTarget( + BranchIsland *island, + const void *branchTo, + long instruction ) +{ + // Copy over the template code. + bcopy( kIslandTemplate, island->instructions, sizeof( kIslandTemplate ) ); + + // Fill in the address. + ((short*)island->instructions)[kAddressLo] = ((long) branchTo) & 0x0000FFFF; + ((short*)island->instructions)[kAddressHi] + = (((long) branchTo) >> 16) & 0x0000FFFF; + + // Fill in the (optional) instuction. + if( instruction != 0 ) { + ((short*)island->instructions)[kInstructionLo] + = instruction & 0x0000FFFF; + ((short*)island->instructions)[kInstructionHi] + = (instruction >> 16) & 0x0000FFFF; + } + + //MakeDataExecutable( island->instructions, sizeof( kIslandTemplate ) ); + msync( island->instructions, sizeof( kIslandTemplate ), MS_INVALIDATE ); + + return err_none; +} +#endif + +#if defined(__i386__) + mach_error_t +setBranchIslandTarget_i386( + BranchIsland *island, + const void *branchTo, + char* instructions ) +{ + + // Copy over the template code. + bcopy( kIslandTemplate, island->instructions, sizeof( kIslandTemplate ) ); + + // copy original instructions + if (instructions) { + bcopy (instructions, island->instructions + kInstructions, kOriginalInstructionsSize); + } + + // Fill in the address. + int32_t addressOffset = (char *)branchTo - (island->instructions + kJumpAddress + 4); + *((int32_t *)(island->instructions + kJumpAddress)) = addressOffset; + + msync( island->instructions, sizeof( kIslandTemplate ), MS_INVALIDATE ); + return err_none; +} + +#elif defined(__x86_64__) +mach_error_t +setBranchIslandTarget_i386( + BranchIsland *island, + const void *branchTo, + char* instructions ) +{ + // Copy over the template code. + bcopy( kIslandTemplate, island->instructions, sizeof( kIslandTemplate ) ); + + // Copy original instructions. + if (instructions) { + bcopy (instructions, island->instructions, kOriginalInstructionsSize); + } + + // Fill in the address. + *((uint64_t *)(island->instructions + kJumpAddress)) = (uint64_t)branchTo; + msync( island->instructions, sizeof( kIslandTemplate ), MS_INVALIDATE ); + + return err_none; +} +#endif + + +#if defined(__i386__) || defined(__x86_64__) +// simplistic instruction matching +typedef struct { + unsigned int length; // max 15 + unsigned char mask[15]; // sequence of bytes in memory order + unsigned char constraint[15]; // sequence of bytes in memory order +} AsmInstructionMatch; + +#if defined(__i386__) +static AsmInstructionMatch possibleInstructions[] = { + { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0xE9, 0x00, 0x00, 0x00, 0x00} }, // jmp 0x???????? + { 0x5, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, {0x55, 0x89, 0xe5, 0xc9, 0xc3} }, // push %esp; mov %esp,%ebp; leave; ret + { 0x1, {0xFF}, {0x90} }, // nop + { 0x1, {0xF8}, {0x50} }, // push %reg + { 0x2, {0xFF, 0xFF}, {0x89, 0xE5} }, // mov %esp,%ebp + { 0x3, {0xFF, 0xFF, 0xFF}, {0x89, 0x1C, 0x24} }, // mov %ebx,(%esp) + { 0x3, {0xFF, 0xFF, 0x00}, {0x83, 0xEC, 0x00} }, // sub 0x??, %esp + { 0x6, {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00}, {0x81, 0xEC, 0x00, 0x00, 0x00, 0x00} }, // sub 0x??, %esp with 32bit immediate + { 0x2, {0xFF, 0xFF}, {0x31, 0xC0} }, // xor %eax, %eax + { 0x3, {0xFF, 0x4F, 0x00}, {0x8B, 0x45, 0x00} }, // mov $imm(%ebp), %reg + { 0x3, {0xFF, 0x4C, 0x00}, {0x8B, 0x40, 0x00} }, // mov $imm(%eax-%edx), %reg + { 0x3, {0xFF, 0xCF, 0x00}, {0x8B, 0x4D, 0x00} }, // mov $imm(%rpb), %reg + { 0x3, {0xFF, 0x4F, 0x00}, {0x8A, 0x4D, 0x00} }, // mov $imm(%ebp), %cl + { 0x4, {0xFF, 0xFF, 0xFF, 0x00}, {0x8B, 0x4C, 0x24, 0x00} }, // mov $imm(%esp), %ecx + { 0x4, {0xFF, 0x00, 0x00, 0x00}, {0x8B, 0x00, 0x00, 0x00} }, // mov r16,r/m16 or r32,r/m32 + { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0xB9, 0x00, 0x00, 0x00, 0x00} }, // mov $imm, %ecx + { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0xB8, 0x00, 0x00, 0x00, 0x00} }, // mov $imm, %eax + { 0x4, {0xFF, 0xFF, 0xFF, 0x00}, {0x66, 0x0F, 0xEF, 0x00} }, // pxor xmm2/128, xmm1 + { 0x2, {0xFF, 0xFF}, {0xDB, 0xE3} }, // fninit + { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0xE8, 0x00, 0x00, 0x00, 0x00} }, // call $imm + { 0x0 } +}; +#elif defined(__x86_64__) +// TODO(glider): disassembling the "0x48, 0x89" sequences is trickier than it's done below. +// If it stops working, refer to http://ref.x86asm.net/geek.html#modrm_byte_32_64 to do it +// more accurately. +// Note: 0x48 is in fact the REX.W prefix, but it might be wrong to treat it as a separate +// instruction. +static AsmInstructionMatch possibleInstructions[] = { + { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0xE9, 0x00, 0x00, 0x00, 0x00} }, // jmp 0x???????? + { 0x1, {0xFF}, {0x90} }, // nop + { 0x1, {0xF8}, {0x50} }, // push %rX + { 0x1, {0xFF}, {0x65} }, // GS prefix + { 0x3, {0xFF, 0xFF, 0xFF}, {0x48, 0x89, 0xE5} }, // mov %rsp,%rbp + { 0x4, {0xFF, 0xFF, 0xFF, 0x00}, {0x48, 0x83, 0xEC, 0x00} }, // sub 0x??, %rsp + { 0x4, {0xFB, 0xFF, 0x07, 0x00}, {0x48, 0x89, 0x05, 0x00} }, // move onto rbp + { 0x3, {0xFB, 0xFF, 0x00}, {0x48, 0x89, 0x00} }, // mov %reg, %reg + { 0x3, {0xFB, 0xFF, 0x00}, {0x49, 0x89, 0x00} }, // mov %reg, %reg (REX.WB) + { 0x2, {0xFF, 0x00}, {0x41, 0x00} }, // push %rXX + { 0x2, {0xFF, 0x00}, {0x85, 0x00} }, // test %rX,%rX + { 0x2, {0xFF, 0x00}, {0x77, 0x00} }, // ja $i8 + { 0x2, {0xFF, 0x00}, {0x74, 0x00} }, // je $i8 + { 0x5, {0xF8, 0x00, 0x00, 0x00, 0x00}, {0xB8, 0x00, 0x00, 0x00, 0x00} }, // mov $imm, %reg + { 0x3, {0xFF, 0xFF, 0x00}, {0xFF, 0x77, 0x00} }, // pushq $imm(%rdi) + { 0x2, {0xFF, 0xFF}, {0x31, 0xC0} }, // xor %eax, %eax + { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0x25, 0x00, 0x00, 0x00, 0x00} }, // and $imm, %eax + + { 0x8, {0xFF, 0xFF, 0xCF, 0xFF, 0x00, 0x00, 0x00, 0x00}, + {0x48, 0x8B, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00}, }, // mov $imm, %{rax,rdx,rsp,rsi} + { 0x4, {0xFF, 0xFF, 0xFF, 0x00}, {0x48, 0x83, 0xFA, 0x00}, }, // cmp $i8, %rdx + { 0x4, {0xFF, 0xFF, 0x00, 0x00}, {0x83, 0x7f, 0x00, 0x00}, }, // cmpl $imm, $imm(%rdi) + { 0xa, {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x48, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, // mov $imm, %rax + { 0x6, {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00}, + {0x81, 0xE6, 0x00, 0x00, 0x00, 0x00} }, // and $imm, %esi + { 0x6, {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00}, + {0xFF, 0x25, 0x00, 0x00, 0x00, 0x00} }, // jmpq *(%rip) + { 0x4, {0xFF, 0xFF, 0xFF, 0x00}, {0x66, 0x0F, 0xEF, 0x00} }, // pxor xmm2/128, xmm1 + { 0x2, {0xFF, 0x00}, {0x89, 0x00} }, // mov r/m32,r32 or r/m16,r16 + { 0x3, {0xFF, 0xFF, 0xFF}, {0x49, 0x89, 0xF8} }, // mov %rdi,%r8 + { 0x3, {0xFF, 0xFF, 0x00}, {0xFF, 0x77, 0x00} }, // pushq $imm(%rdi) + { 0x2, {0xFF, 0xFF}, {0xDB, 0xE3} }, // fninit + { 0x0 } +}; +#endif + +static Boolean codeMatchesInstruction(unsigned char *code, AsmInstructionMatch* instruction) +{ + Boolean match = true; + + size_t i; + assert(instruction); +#ifdef DEBUG_DISASM + fprintf(stderr, "Matching: "); +#endif + for (i=0; ilength; i++) { + unsigned char mask = instruction->mask[i]; + unsigned char constraint = instruction->constraint[i]; + unsigned char codeValue = code[i]; +#ifdef DEBUG_DISASM + fprintf(stderr, "%x ", (unsigned)codeValue); +#endif + match = ((codeValue & mask) == constraint); + if (!match) break; + } +#ifdef DEBUG_DISASM + if (match) { + fprintf(stderr, " OK\n"); + } else { + fprintf(stderr, " FAIL\n"); + } +#endif + return match; +} + +#if defined(__i386__) || defined(__x86_64__) + static Boolean +eatKnownInstructions( + unsigned char *code, + uint64_t *newInstruction, + int *howManyEaten, + char *originalInstructions, + int *originalInstructionCount, + uint8_t *originalInstructionSizes ) +{ + Boolean allInstructionsKnown = true; + int totalEaten = 0; + unsigned char* ptr = code; + int remainsToEat = 5; // a JMP instruction takes 5 bytes + int instructionIndex = 0; + + if (howManyEaten) *howManyEaten = 0; + if (originalInstructionCount) *originalInstructionCount = 0; + while (remainsToEat > 0) { + Boolean curInstructionKnown = false; + + // See if instruction matches one we know + AsmInstructionMatch* curInstr = possibleInstructions; + do { + if ((curInstructionKnown = codeMatchesInstruction(ptr, curInstr))) break; + curInstr++; + } while (curInstr->length > 0); + + // if all instruction matches failed, we don't know current instruction then, stop here + if (!curInstructionKnown) { + allInstructionsKnown = false; + fprintf(stderr, "mach_override: some instructions unknown! Need to update mach_override.c\n"); + break; + } + + // At this point, we've matched curInstr + int eaten = curInstr->length; + ptr += eaten; + remainsToEat -= eaten; + totalEaten += eaten; + + if (originalInstructionSizes) originalInstructionSizes[instructionIndex] = eaten; + instructionIndex += 1; + if (originalInstructionCount) *originalInstructionCount = instructionIndex; + } + + + if (howManyEaten) *howManyEaten = totalEaten; + + if (originalInstructions) { + Boolean enoughSpaceForOriginalInstructions = (totalEaten < kOriginalInstructionsSize); + + if (enoughSpaceForOriginalInstructions) { + memset(originalInstructions, 0x90 /* NOP */, kOriginalInstructionsSize); // fill instructions with NOP + bcopy(code, originalInstructions, totalEaten); + } else { +#ifdef DEBUG_DISASM + fprintf(stderr, "Not enough space in island to store original instructions. Adapt the island definition and kOriginalInstructionsSize\n"); +#endif + return false; + } + } + + if (allInstructionsKnown) { + // save last 3 bytes of first 64bits of codre we'll replace + uint64_t currentFirst64BitsOfCode = *((uint64_t *)code); + currentFirst64BitsOfCode = OSSwapInt64(currentFirst64BitsOfCode); // back to memory representation + currentFirst64BitsOfCode &= 0x0000000000FFFFFFLL; + + // keep only last 3 instructions bytes, first 5 will be replaced by JMP instr + *newInstruction &= 0xFFFFFFFFFF000000LL; // clear last 3 bytes + *newInstruction |= (currentFirst64BitsOfCode & 0x0000000000FFFFFFLL); // set last 3 bytes + } + + return allInstructionsKnown; +} + + static void +fixupInstructions( + void *originalFunction, + void *escapeIsland, + void *instructionsToFix, + int instructionCount, + uint8_t *instructionSizes ) +{ + int index; + for (index = 0;index < instructionCount;index += 1) + { + if ((*(uint8_t*)instructionsToFix == 0xE9) || // 32-bit jump relative + (*(uint8_t*)instructionsToFix == 0xE8)) // 32-bit call relative + { + uint32_t offset = (uintptr_t)originalFunction - (uintptr_t)escapeIsland; + uint32_t *jumpOffsetPtr = (uint32_t*)((uintptr_t)instructionsToFix + 1); + *jumpOffsetPtr += offset; + } + + + originalFunction = (void*)((uintptr_t)originalFunction + instructionSizes[index]); + escapeIsland = (void*)((uintptr_t)escapeIsland + instructionSizes[index]); + instructionsToFix = (void*)((uintptr_t)instructionsToFix + instructionSizes[index]); + } +} +#endif + +#if defined(__i386__) +__asm( + ".text;" + ".align 2, 0x90;" + "_atomic_mov64:;" + " pushl %ebp;" + " movl %esp, %ebp;" + " pushl %esi;" + " pushl %ebx;" + " pushl %ecx;" + " pushl %eax;" + " pushl %edx;" + + // atomic push of value to an address + // we use cmpxchg8b, which compares content of an address with + // edx:eax. If they are equal, it atomically puts 64bit value + // ecx:ebx in address. + // We thus put contents of address in edx:eax to force ecx:ebx + // in address + " mov 8(%ebp), %esi;" // esi contains target address + " mov 12(%ebp), %ebx;" + " mov 16(%ebp), %ecx;" // ecx:ebx now contains value to put in target address + " mov (%esi), %eax;" + " mov 4(%esi), %edx;" // edx:eax now contains value currently contained in target address + " lock; cmpxchg8b (%esi);" // atomic move. + + // restore registers + " popl %edx;" + " popl %eax;" + " popl %ecx;" + " popl %ebx;" + " popl %esi;" + " popl %ebp;" + " ret" +); +#elif defined(__x86_64__) +void atomic_mov64( + uint64_t *targetAddress, + uint64_t value ) +{ + *targetAddress = value; +} +#endif +#endif +#endif // __APPLE__ diff --git a/lib/asan/mach_override/mach_override.h b/lib/asan/mach_override/mach_override.h new file mode 100644 index 0000000..dcccbcd --- /dev/null +++ b/lib/asan/mach_override/mach_override.h @@ -0,0 +1,127 @@ +/******************************************************************************* + mach_override.h + Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: + Some rights reserved: + + ***************************************************************************/ + +/***************************************************************************//** + @mainpage mach_override + @author Jonathan 'Wolf' Rentzsch: + + This package, coded in C to the Mach API, allows you to override ("patch") + program- and system-supplied functions at runtime. You can fully replace + functions with your implementations, or merely head- or tail-patch the + original implementations. + + Use it by #include'ing mach_override.h from your .c, .m or .mm file(s). + + @todo Discontinue use of Carbon's MakeDataExecutable() and + CompareAndSwap() calls and start using the Mach equivalents, if they + exist. If they don't, write them and roll them in. That way, this + code will be pure Mach, which will make it easier to use everywhere. + Update: MakeDataExecutable() has been replaced by + msync(MS_INVALIDATE). There is an OSCompareAndSwap in libkern, but + I'm currently unsure if I can link against it. May have to roll in + my own version... + @todo Stop using an entire 4K high-allocated VM page per 28-byte escape + branch island. Done right, this will dramatically speed up escape + island allocations when they number over 250. Then again, if you're + overriding more than 250 functions, maybe speed isn't your main + concern... + @todo Add detection of: b, bl, bla, bc, bcl, bcla, bcctrl, bclrl + first-instructions. Initially, we should refuse to override + functions beginning with these instructions. Eventually, we should + dynamically rewrite them to make them position-independent. + @todo Write mach_unoverride(), which would remove an override placed on a + function. Must be multiple-override aware, which means an almost + complete rewrite under the covers, because the target address can't + be spread across two load instructions like it is now since it will + need to be atomically updatable. + @todo Add non-rentry variants of overrides to test_mach_override. + + ***************************************************************************/ + +#ifdef __APPLE__ + +#ifndef _mach_override_ +#define _mach_override_ + +#include +#include + +#ifdef __cplusplus + extern "C" { +#endif + +/** + Returned if the function to be overrided begins with a 'mfctr' instruction. +*/ +#define err_cannot_override (err_local|1) + +/************************************************************************************//** + Dynamically overrides the function implementation referenced by + originalFunctionAddress with the implentation pointed to by overrideFunctionAddress. + Optionally returns a pointer to a "reentry island" which, if jumped to, will resume + the original implementation. + + @param originalFunctionAddress -> Required address of the function to + override (with overrideFunctionAddress). + @param overrideFunctionAddress -> Required address to the overriding + function. + @param originalFunctionReentryIsland <- Optional pointer to pointer to the + reentry island. Can be NULL. + @result <- err_cannot_override if the original + function's implementation begins with + the 'mfctr' instruction. + + ************************************************************************************/ + +// We're prefixing mach_override_ptr() with "__asan_" to avoid name conflicts with other +// mach_override_ptr() implementations that may appear in the client program. + mach_error_t +__asan_mach_override_ptr( + void *originalFunctionAddress, + const void *overrideFunctionAddress, + void **originalFunctionReentryIsland ); + +/************************************************************************************//** + + + ************************************************************************************/ + +#ifdef __cplusplus + +#define MACH_OVERRIDE( ORIGINAL_FUNCTION_RETURN_TYPE, ORIGINAL_FUNCTION_NAME, ORIGINAL_FUNCTION_ARGS, ERR ) \ + { \ + static ORIGINAL_FUNCTION_RETURN_TYPE (*ORIGINAL_FUNCTION_NAME##_reenter)ORIGINAL_FUNCTION_ARGS; \ + static bool ORIGINAL_FUNCTION_NAME##_overriden = false; \ + class mach_override_class__##ORIGINAL_FUNCTION_NAME { \ + public: \ + static kern_return_t override(void *originalFunctionPtr) { \ + kern_return_t result = err_none; \ + if (!ORIGINAL_FUNCTION_NAME##_overriden) { \ + ORIGINAL_FUNCTION_NAME##_overriden = true; \ + result = mach_override_ptr( (void*)originalFunctionPtr, \ + (void*)mach_override_class__##ORIGINAL_FUNCTION_NAME::replacement, \ + (void**)&ORIGINAL_FUNCTION_NAME##_reenter ); \ + } \ + return result; \ + } \ + static ORIGINAL_FUNCTION_RETURN_TYPE replacement ORIGINAL_FUNCTION_ARGS { + +#define END_MACH_OVERRIDE( ORIGINAL_FUNCTION_NAME ) \ + } \ + }; \ + \ + err = mach_override_class__##ORIGINAL_FUNCTION_NAME::override((void*)ORIGINAL_FUNCTION_NAME); \ + } + +#endif + +#ifdef __cplusplus + } +#endif +#endif // _mach_override_ + +#endif // __APPLE__ diff --git a/lib/asan/scripts/asan_symbolize.py b/lib/asan/scripts/asan_symbolize.py new file mode 100755 index 0000000..80b5927 --- /dev/null +++ b/lib/asan/scripts/asan_symbolize.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python +#===- lib/asan/scripts/asan_symbolize.py -----------------------------------===# +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# +import os +import re +import sys +import string +import subprocess + +pipes = {} + +def patch_address(frameno, addr_s): + ''' Subtracts 1 or 2 from the top frame's address. + Top frame is normally the return address from asan_report* + call, which is not expected to return at all. Because of that, this + address often belongs to the next source code line, or even to a different + function. ''' + if frameno == '0': + addr = int(addr_s, 16) + if os.uname()[4].startswith('arm'): + # Cancel the Thumb bit + addr = addr & (~1) + addr -= 1 + return hex(addr) + return addr_s + +# TODO(glider): need some refactoring here +def symbolize_addr2line(line): + #0 0x7f6e35cf2e45 (/blah/foo.so+0x11fe45) + match = re.match('^( *#([0-9]+) *0x[0-9a-f]+) *\((.*)\+(0x[0-9a-f]+)\)', line) + if match: + frameno = match.group(2) + binary = match.group(3) + addr = match.group(4) + addr = patch_address(frameno, addr) + if not pipes.has_key(binary): + pipes[binary] = subprocess.Popen(["addr2line", "-f", "-e", binary], + stdin=subprocess.PIPE, stdout=subprocess.PIPE) + p = pipes[binary] + try: + print >>p.stdin, addr + function_name = p.stdout.readline().rstrip() + file_name = p.stdout.readline().rstrip() + except: + function_name = "" + file_name = "" + for path_to_cut in sys.argv[1:]: + file_name = re.sub(".*" + path_to_cut, "", file_name) + file_name = re.sub(".*asan_[a-z_]*.cc:[0-9]*", "_asan_rtl_", file_name) + file_name = re.sub(".*crtstuff.c:0", "???:0", file_name) + + print match.group(1), "in", function_name, file_name + else: + print line.rstrip() + +def symbolize_atos(line): + #0 0x7f6e35cf2e45 (/blah/foo.so+0x11fe45) + match = re.match('^( *#([0-9]+) *)(0x[0-9a-f]+) *\((.*)\+(0x[0-9a-f]+)\)', line) + if match: + #print line + prefix = match.group(1) + frameno = match.group(2) + addr = match.group(3) + binary = match.group(4) + offset = match.group(5) + addr = patch_address(frameno, addr) + load_addr = int(addr, 16) - int(offset, 16) + if not pipes.has_key(binary): + #print "atos -o %s -l %s" % (binary, hex(load_addr)) + pipes[binary] = subprocess.Popen(["atos", "-o", binary], + stdin=subprocess.PIPE, stdout=subprocess.PIPE,) + p = pipes[binary] + # TODO(glider): how to tell if the address is absolute? + if ".app/" in binary and not ".framework" in binary: + print >>p.stdin, "%s" % addr + else: + print >>p.stdin, "%s" % offset + # TODO(glider): it's more efficient to make a batch atos run for each binary. + p.stdin.close() + atos_line = p.stdout.readline().rstrip() + del pipes[binary] + + print "%s%s in %s" % (prefix, addr, atos_line) + else: + print line.rstrip() + +system = os.uname()[0] +if system in ['Linux', 'Darwin']: + for line in sys.stdin: + if system == 'Linux': + symbolize_addr2line(line) + elif system == 'Darwin': + symbolize_atos(line) +else: + print 'Unknown system: ', system diff --git a/lib/asan/sysinfo/LICENSE.TXT b/lib/asan/sysinfo/LICENSE.TXT new file mode 100644 index 0000000..b519af5 --- /dev/null +++ b/lib/asan/sysinfo/LICENSE.TXT @@ -0,0 +1,29 @@ +Copyright (c) 2005, Google Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/lib/asan/sysinfo/Makefile.mk b/lib/asan/sysinfo/Makefile.mk new file mode 100644 index 0000000..bc4a2ff --- /dev/null +++ b/lib/asan/sysinfo/Makefile.mk @@ -0,0 +1,22 @@ +#===- lib/asan/sysinfo/Makefile.mk -------------------------*- Makefile -*--===# +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# + +ModuleName := asan +SubDirs := + +Sources := $(foreach file,$(wildcard $(Dir)/*.cc),$(notdir $(file))) +ObjNames := $(Sources:%.c=%.o) + +Implementation := Generic + +# FIXME: use automatic dependencies? +Dependencies := $(wildcard $(Dir)/*.h) + +# Define a convenience variable for all the asan functions. +AsanFunctions += $(Sources:%.cc=%) diff --git a/lib/asan/sysinfo/basictypes.h b/lib/asan/sysinfo/basictypes.h new file mode 100644 index 0000000..ac21f8c --- /dev/null +++ b/lib/asan/sysinfo/basictypes.h @@ -0,0 +1,321 @@ +// Copyright (c) 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef _BASICTYPES_H_ +#define _BASICTYPES_H_ + +#include // uint16_t might be here; PRId64 too. +#include // to get uint16_t (ISO naming madness) +#include // our last best hope for uint16_t + +// Standard typedefs +// All Google code is compiled with -funsigned-char to make "char" +// unsigned. Google code therefore doesn't need a "uchar" type. +// TODO(csilvers): how do we make sure unsigned-char works on non-gcc systems? +typedef signed char schar; +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; + +// NOTE: unsigned types are DANGEROUS in loops and other arithmetical +// places. Use the signed types unless your variable represents a bit +// pattern (eg a hash value) or you really need the extra bit. Do NOT +// use 'unsigned' to express "this value should always be positive"; +// use assertions for this. + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; + +const uint16 kuint16max = ( (uint16) 0xFFFF); +const uint32 kuint32max = ( (uint32) 0xFFFFFFFF); +const uint64 kuint64max = ( (((uint64) kuint32max) << 32) | kuint32max ); + +const int8 kint8max = ( ( int8) 0x7F); +const int16 kint16max = ( ( int16) 0x7FFF); +const int32 kint32max = ( ( int32) 0x7FFFFFFF); +const int64 kint64max = ( ((( int64) kint32max) << 32) | kuint32max ); + +const int8 kint8min = ( ( int8) 0x80); +const int16 kint16min = ( ( int16) 0x8000); +const int32 kint32min = ( ( int32) 0x80000000); +const int64 kint64min = ( ((( int64) kint32min) << 32) | 0 ); + +// Define the "portable" printf and scanf macros, if they're not +// already there (via the inttypes.h we #included above, hopefully). +// Mostly it's old systems that don't support inttypes.h, so we assume +// they're 32 bit. +#ifndef PRIx64 +#define PRIx64 "llx" +#endif +#ifndef SCNx64 +#define SCNx64 "llx" +#endif +#ifndef PRId64 +#define PRId64 "lld" +#endif +#ifndef SCNd64 +#define SCNd64 "lld" +#endif +#ifndef PRIu64 +#define PRIu64 "llu" +#endif +#ifndef PRIxPTR +#define PRIxPTR "lx" +#endif + +// Also allow for printing of a pthread_t. +#define GPRIuPTHREAD "lu" +#define GPRIxPTHREAD "lx" +#if defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(__APPLE__) || defined(__FreeBSD__) +#define PRINTABLE_PTHREAD(pthreadt) reinterpret_cast(pthreadt) +#else +#define PRINTABLE_PTHREAD(pthreadt) pthreadt +#endif + +// A macro to disallow the evil copy constructor and operator= functions +// This should be used in the private: declarations for a class +#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) + +// An alternate name that leaves out the moral judgment... :-) +#define DISALLOW_COPY_AND_ASSIGN(TypeName) DISALLOW_EVIL_CONSTRUCTORS(TypeName) + +// The COMPILE_ASSERT macro can be used to verify that a compile time +// expression is true. For example, you could use it to verify the +// size of a static array: +// +// COMPILE_ASSERT(sizeof(num_content_type_names) == sizeof(int), +// content_type_names_incorrect_size); +// +// or to make sure a struct is smaller than a certain size: +// +// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); +// +// The second argument to the macro is the name of the variable. If +// the expression is false, most compilers will issue a warning/error +// containing the name of the variable. +// +// Implementation details of COMPILE_ASSERT: +// +// - COMPILE_ASSERT works by defining an array type that has -1 +// elements (and thus is invalid) when the expression is false. +// +// - The simpler definition +// +// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1] +// +// does not work, as gcc supports variable-length arrays whose sizes +// are determined at run-time (this is gcc's extension and not part +// of the C++ standard). As a result, gcc fails to reject the +// following code with the simple definition: +// +// int foo; +// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is +// // not a compile-time constant. +// +// - By using the type CompileAssert<(bool(expr))>, we ensures that +// expr is a compile-time constant. (Template arguments must be +// determined at compile-time.) +// +// - The outter parentheses in CompileAssert<(bool(expr))> are necessary +// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written +// +// CompileAssert +// +// instead, these compilers will refuse to compile +// +// COMPILE_ASSERT(5 > 0, some_message); +// +// (They seem to think the ">" in "5 > 0" marks the end of the +// template argument list.) +// +// - The array size is (bool(expr) ? 1 : -1), instead of simply +// +// ((expr) ? 1 : -1). +// +// This is to avoid running into a bug in MS VC 7.1, which +// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. + +template +struct CompileAssert { +}; + +#define COMPILE_ASSERT(expr, msg) \ + typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] + +#define arraysize(a) (sizeof(a) / sizeof(*(a))) + +#define OFFSETOF_MEMBER(strct, field) \ + (reinterpret_cast(&reinterpret_cast(16)->field) - \ + reinterpret_cast(16)) + +#ifdef HAVE___ATTRIBUTE__ +# define ATTRIBUTE_WEAK __attribute__((weak)) +# define ATTRIBUTE_NOINLINE __attribute__((noinline)) +#else +# define ATTRIBUTE_WEAK +# define ATTRIBUTE_NOINLINE +#endif + +// Section attributes are supported for both ELF and Mach-O, but in +// very different ways. Here's the API we provide: +// 1) ATTRIBUTE_SECTION: put this with the declaration of all functions +// you want to be in the same linker section +// 2) DEFINE_ATTRIBUTE_SECTION_VARS: must be called once per unique +// name. You want to make sure this is executed before any +// DECLARE_ATTRIBUTE_SECTION_VARS; the easiest way is to put them +// in the same .cc file. Put this call at the global level. +// 3) INIT_ATTRIBUTE_SECTION_VARS: you can scatter calls to this in +// multiple places to help ensure execution before any +// DECLARE_ATTRIBUTE_SECTION_VARS. You must have at least one +// DEFINE, but you can have many INITs. Put each in its own scope. +// 4) DECLARE_ATTRIBUTE_SECTION_VARS: must be called before using +// ATTRIBUTE_SECTION_START or ATTRIBUTE_SECTION_STOP on a name. +// Put this call at the global level. +// 5) ATTRIBUTE_SECTION_START/ATTRIBUTE_SECTION_STOP: call this to say +// where in memory a given section is. All functions declared with +// ATTRIBUTE_SECTION are guaranteed to be between START and STOP. + +#if defined(HAVE___ATTRIBUTE__) && defined(__ELF__) +# define ATTRIBUTE_SECTION(name) __attribute__ ((section (#name))) + + // Weak section declaration to be used as a global declaration + // for ATTRIBUTE_SECTION_START|STOP(name) to compile and link + // even without functions with ATTRIBUTE_SECTION(name). +# define DECLARE_ATTRIBUTE_SECTION_VARS(name) \ + extern char __start_##name[] ATTRIBUTE_WEAK; \ + extern char __stop_##name[] ATTRIBUTE_WEAK +# define INIT_ATTRIBUTE_SECTION_VARS(name) // no-op for ELF +# define DEFINE_ATTRIBUTE_SECTION_VARS(name) // no-op for ELF + + // Return void* pointers to start/end of a section of code with functions + // having ATTRIBUTE_SECTION(name), or 0 if no such function exists. + // One must DECLARE_ATTRIBUTE_SECTION(name) for this to compile and link. +# define ATTRIBUTE_SECTION_START(name) (reinterpret_cast(__start_##name)) +# define ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast(__stop_##name)) +# define HAVE_ATTRIBUTE_SECTION_START 1 + +#elif defined(HAVE___ATTRIBUTE__) && defined(__MACH__) +# define ATTRIBUTE_SECTION(name) __attribute__ ((section ("__TEXT, " #name))) + +#include +#include +class AssignAttributeStartEnd { + public: + AssignAttributeStartEnd(const char* name, char** pstart, char** pend) { + // Find out what dynamic library name is defined in + if (_dyld_present()) { + for (int i = _dyld_image_count() - 1; i >= 0; --i) { + const mach_header* hdr = _dyld_get_image_header(i); +#ifdef MH_MAGIC_64 + if (hdr->magic == MH_MAGIC_64) { + uint64_t len; + *pstart = getsectdatafromheader_64((mach_header_64*)hdr, + "__TEXT", name, &len); + if (*pstart) { // NULL if not defined in this dynamic library + *pstart += _dyld_get_image_vmaddr_slide(i); // correct for reloc + *pend = *pstart + len; + return; + } + } +#endif + if (hdr->magic == MH_MAGIC) { + uint32_t len; + *pstart = getsectdatafromheader(hdr, "__TEXT", name, &len); + if (*pstart) { // NULL if not defined in this dynamic library + *pstart += _dyld_get_image_vmaddr_slide(i); // correct for reloc + *pend = *pstart + len; + return; + } + } + } + } + // If we get here, not defined in a dll at all. See if defined statically. + unsigned long len; // don't ask me why this type isn't uint32_t too... + *pstart = getsectdata("__TEXT", name, &len); + *pend = *pstart + len; + } +}; + +#define DECLARE_ATTRIBUTE_SECTION_VARS(name) \ + extern char* __start_##name; \ + extern char* __stop_##name + +#define INIT_ATTRIBUTE_SECTION_VARS(name) \ + DECLARE_ATTRIBUTE_SECTION_VARS(name); \ + static const AssignAttributeStartEnd __assign_##name( \ + #name, &__start_##name, &__stop_##name) + +#define DEFINE_ATTRIBUTE_SECTION_VARS(name) \ + char* __start_##name, *__stop_##name; \ + INIT_ATTRIBUTE_SECTION_VARS(name) + +# define ATTRIBUTE_SECTION_START(name) (reinterpret_cast(__start_##name)) +# define ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast(__stop_##name)) +# define HAVE_ATTRIBUTE_SECTION_START 1 + +#else // not HAVE___ATTRIBUTE__ && __ELF__, nor HAVE___ATTRIBUTE__ && __MACH__ +# define ATTRIBUTE_SECTION(name) +# define DECLARE_ATTRIBUTE_SECTION_VARS(name) +# define INIT_ATTRIBUTE_SECTION_VARS(name) +# define DEFINE_ATTRIBUTE_SECTION_VARS(name) +# define ATTRIBUTE_SECTION_START(name) (reinterpret_cast(0)) +# define ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast(0)) + +#endif // HAVE___ATTRIBUTE__ and __ELF__ or __MACH__ + +#if defined(HAVE___ATTRIBUTE__) && (defined(__i386__) || defined(__x86_64__)) +# define CACHELINE_SIZE 64 +# define CACHELINE_ALIGNED __attribute__((aligned(CACHELINE_SIZE))) +#else +# define CACHELINE_ALIGNED +#endif // defined(HAVE___ATTRIBUTE__) && (__i386__ || __x86_64__) + + +// The following enum should be used only as a constructor argument to indicate +// that the variable has static storage class, and that the constructor should +// do nothing to its state. It indicates to the reader that it is legal to +// declare a static nistance of the class, provided the constructor is given +// the base::LINKER_INITIALIZED argument. Normally, it is unsafe to declare a +// static variable that has a constructor or a destructor because invocation +// order is undefined. However, IF the type can be initialized by filling with +// zeroes (which the loader does for static variables), AND the destructor also +// does nothing to the storage, then a constructor declared as +// explicit MyClass(base::LinkerInitialized x) {} +// and invoked as +// static MyClass my_variable_name(base::LINKER_INITIALIZED); +namespace base { +enum LinkerInitialized { LINKER_INITIALIZED }; +} + +#endif // _BASICTYPES_H_ diff --git a/lib/asan/sysinfo/sysinfo.cc b/lib/asan/sysinfo/sysinfo.cc new file mode 100644 index 0000000..ee06735 --- /dev/null +++ b/lib/asan/sysinfo/sysinfo.cc @@ -0,0 +1,617 @@ +// Copyright (c) 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include // for getenv() +#include // for snprintf(), sscanf() +#include // for memmove(), memchr(), etc. +#include // for open() +#include // for errno +#include // for read() +#if defined __MACH__ // Mac OS X, almost certainly +#include // for iterating over dll's in ProcMapsIter +#include // for iterating over dll's in ProcMapsIter +#include +#include // how we figure out numcpu's on OS X +#elif defined __FreeBSD__ +#include +#elif defined __sun__ // Solaris +#include // for, e.g., prmap_t +#elif defined(PLATFORM_WINDOWS) +#include // for getpid() (actually, _getpid()) +#include // for SHGetValueA() +#include // for Module32First() +#endif +#include "sysinfo.h" + +#ifdef PLATFORM_WINDOWS +#ifdef MODULEENTRY32 +// In a change from the usual W-A pattern, there is no A variant of +// MODULEENTRY32. Tlhelp32.h #defines the W variant, but not the A. +// In unicode mode, tlhelp32.h #defines MODULEENTRY32 to be +// MODULEENTRY32W. These #undefs are the only way I see to get back +// access to the original, ascii struct (and related functions). +#undef MODULEENTRY32 +#undef Module32First +#undef Module32Next +#undef PMODULEENTRY32 +#undef LPMODULEENTRY32 +#endif /* MODULEENTRY32 */ +// MinGW doesn't seem to define this, perhaps some windowsen don't either. +#ifndef TH32CS_SNAPMODULE32 +#define TH32CS_SNAPMODULE32 0 +#endif /* TH32CS_SNAPMODULE32 */ +#endif /* PLATFORM_WINDOWS */ + +// Re-run fn until it doesn't cause EINTR. +#define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR) + +// open/read/close can set errno, which may be illegal at this +// time, so prefer making the syscalls directly if we can. +#ifdef HAVE_SYS_SYSCALL_H +# include +# define safeopen(filename, mode) syscall(SYS_open, filename, mode) +# define saferead(fd, buffer, size) syscall(SYS_read, fd, buffer, size) +# define safeclose(fd) syscall(SYS_close, fd) +#else +# define safeopen(filename, mode) open(filename, mode) +# define saferead(fd, buffer, size) read(fd, buffer, size) +# define safeclose(fd) close(fd) +#endif + + +// ---------------------------------------------------------------------- +// HasPosixThreads() +// Return true if we're running POSIX (e.g., NPTL on Linux) +// threads, as opposed to a non-POSIX thread libary. The thing +// that we care about is whether a thread's pid is the same as +// the thread that spawned it. If so, this function returns +// true. +// ---------------------------------------------------------------------- +bool HasPosixThreads() { +#if defined(__linux__) and !defined(ANDROID) +#ifndef _CS_GNU_LIBPTHREAD_VERSION +#define _CS_GNU_LIBPTHREAD_VERSION 3 +#endif + char buf[32]; + // We assume that, if confstr() doesn't know about this name, then + // the same glibc is providing LinuxThreads. + if (confstr(_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof(buf)) == 0) + return false; + return strncmp(buf, "NPTL", 4) == 0; +#elif defined(PLATFORM_WINDOWS) || defined(__CYGWIN__) || defined(__CYGWIN32__) + return false; +#else // other OS + return true; // Assume that everything else has Posix +#endif // else OS_LINUX +} + +// ---------------------------------------------------------------------- + +#define CHECK_LT(x, y) do { assert((x) < (y)); } while (0) + +#if defined __linux__ || defined __FreeBSD__ || defined __sun__ || defined __CYGWIN__ || defined __CYGWIN32__ +static void ConstructFilename(const char* spec, pid_t pid, + char* buf, int buf_size) { + CHECK_LT(snprintf(buf, buf_size, + spec, + static_cast(pid ? pid : getpid())), buf_size); +} +#endif + +// A templatized helper function instantiated for Mach (OS X) only. +// It can handle finding info for both 32 bits and 64 bits. +// Returns true if it successfully handled the hdr, false else. +#ifdef __MACH__ // Mac OS X, almost certainly +template +static bool NextExtMachHelper(const mach_header* hdr, + int current_image, int current_load_cmd, + uint64 *start, uint64 *end, char **flags, + uint64 *offset, int64 *inode, char **filename, + uint64 *file_mapping, uint64 *file_pages, + uint64 *anon_mapping, uint64 *anon_pages, + dev_t *dev) { + static char kDefaultPerms[5] = "r-xp"; + if (hdr->magic != kMagic) + return false; + const char* lc = (const char *)hdr + sizeof(MachHeader); + // TODO(csilvers): make this not-quadradic (increment and hold state) + for (int j = 0; j < current_load_cmd; j++) // advance to *our* load_cmd + lc += ((const load_command *)lc)->cmdsize; + if (((const load_command *)lc)->cmd == kLCSegment) { + const intptr_t dlloff = _dyld_get_image_vmaddr_slide(current_image); + const SegmentCommand* sc = (const SegmentCommand *)lc; + if (start) *start = sc->vmaddr + dlloff; + if (end) *end = sc->vmaddr + sc->vmsize + dlloff; + if (flags) *flags = kDefaultPerms; // can we do better? + if (offset) *offset = sc->fileoff; + if (inode) *inode = 0; + if (filename) + *filename = const_cast(_dyld_get_image_name(current_image)); + if (file_mapping) *file_mapping = 0; + if (file_pages) *file_pages = 0; // could we use sc->filesize? + if (anon_mapping) *anon_mapping = 0; + if (anon_pages) *anon_pages = 0; + if (dev) *dev = 0; + return true; + } + + return false; +} +#endif + +ProcMapsIterator::ProcMapsIterator(pid_t pid) { + Init(pid, NULL, false); +} + +ProcMapsIterator::ProcMapsIterator(pid_t pid, Buffer *buffer) { + Init(pid, buffer, false); +} + +ProcMapsIterator::ProcMapsIterator(pid_t pid, Buffer *buffer, + bool use_maps_backing) { + Init(pid, buffer, use_maps_backing); +} + +void ProcMapsIterator::Init(pid_t pid, Buffer *buffer, + bool use_maps_backing) { + pid_ = pid; + using_maps_backing_ = use_maps_backing; + dynamic_buffer_ = NULL; + if (!buffer) { + // If the user didn't pass in any buffer storage, allocate it + // now. This is the normal case; the signal handler passes in a + // static buffer. + buffer = dynamic_buffer_ = new Buffer; + } else { + dynamic_buffer_ = NULL; + } + + ibuf_ = buffer->buf_; + + stext_ = etext_ = nextline_ = ibuf_; + ebuf_ = ibuf_ + Buffer::kBufSize - 1; + nextline_ = ibuf_; + +#if defined(__linux__) || defined(__CYGWIN__) || defined(__CYGWIN32__) + if (use_maps_backing) { // don't bother with clever "self" stuff in this case + ConstructFilename("/proc/%d/maps_backing", pid, ibuf_, Buffer::kBufSize); + } else if (pid == 0) { + // We have to kludge a bit to deal with the args ConstructFilename + // expects. The 1 is never used -- it's only impt. that it's not 0. + ConstructFilename("/proc/self/maps", 1, ibuf_, Buffer::kBufSize); + } else { + ConstructFilename("/proc/%d/maps", pid, ibuf_, Buffer::kBufSize); + } + // No error logging since this can be called from the crash dump + // handler at awkward moments. Users should call Valid() before + // using. + NO_INTR(fd_ = open(ibuf_, O_RDONLY)); +#elif defined(__FreeBSD__) + // We don't support maps_backing on freebsd + if (pid == 0) { + ConstructFilename("/proc/curproc/map", 1, ibuf_, Buffer::kBufSize); + } else { + ConstructFilename("/proc/%d/map", pid, ibuf_, Buffer::kBufSize); + } + NO_INTR(fd_ = open(ibuf_, O_RDONLY)); +#elif defined(__sun__) + if (pid == 0) { + ConstructFilename("/proc/self/map", 1, ibuf_, Buffer::kBufSize); + } else { + ConstructFilename("/proc/%d/map", pid, ibuf_, Buffer::kBufSize); + } + NO_INTR(fd_ = open(ibuf_, O_RDONLY)); +#elif defined(__MACH__) + current_image_ = _dyld_image_count(); // count down from the top + current_load_cmd_ = -1; +#elif defined(PLATFORM_WINDOWS) + snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | + TH32CS_SNAPMODULE32, + GetCurrentProcessId()); + memset(&module_, 0, sizeof(module_)); +#else + fd_ = -1; // so Valid() is always false +#endif + +} + +ProcMapsIterator::~ProcMapsIterator() { +#if defined(PLATFORM_WINDOWS) + if (snapshot_ != INVALID_HANDLE_VALUE) CloseHandle(snapshot_); +#elif defined(__MACH__) + // no cleanup necessary! +#else + if (fd_ >= 0) NO_INTR(close(fd_)); +#endif + delete dynamic_buffer_; +} + +bool ProcMapsIterator::Valid() const { +#if defined(PLATFORM_WINDOWS) + return snapshot_ != INVALID_HANDLE_VALUE; +#elif defined(__MACH__) + return 1; +#else + return fd_ != -1; +#endif +} + +bool ProcMapsIterator::Next(uint64 *start, uint64 *end, char **flags, + uint64 *offset, int64 *inode, char **filename) { + return NextExt(start, end, flags, offset, inode, filename, NULL, NULL, + NULL, NULL, NULL); +} + +// This has too many arguments. It should really be building +// a map object and returning it. The problem is that this is called +// when the memory allocator state is undefined, hence the arguments. +bool ProcMapsIterator::NextExt(uint64 *start, uint64 *end, char **flags, + uint64 *offset, int64 *inode, char **filename, + uint64 *file_mapping, uint64 *file_pages, + uint64 *anon_mapping, uint64 *anon_pages, + dev_t *dev) { + +#if defined(__linux__) || defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__CYGWIN32__) + do { + // Advance to the start of the next line + stext_ = nextline_; + + // See if we have a complete line in the buffer already + nextline_ = static_cast(memchr (stext_, '\n', etext_ - stext_)); + if (!nextline_) { + // Shift/fill the buffer so we do have a line + int count = etext_ - stext_; + + // Move the current text to the start of the buffer + memmove(ibuf_, stext_, count); + stext_ = ibuf_; + etext_ = ibuf_ + count; + + int nread = 0; // fill up buffer with text + while (etext_ < ebuf_) { + NO_INTR(nread = read(fd_, etext_, ebuf_ - etext_)); + if (nread > 0) + etext_ += nread; + else + break; + } + + // Zero out remaining characters in buffer at EOF to avoid returning + // garbage from subsequent calls. + if (etext_ != ebuf_ && nread == 0) { + memset(etext_, 0, ebuf_ - etext_); + } + *etext_ = '\n'; // sentinel; safe because ibuf extends 1 char beyond ebuf + nextline_ = static_cast(memchr (stext_, '\n', etext_ + 1 - stext_)); + } + *nextline_ = 0; // turn newline into nul + nextline_ += ((nextline_ < etext_)? 1 : 0); // skip nul if not end of text + // stext_ now points at a nul-terminated line + uint64 tmpstart, tmpend, tmpoffset; + int64 tmpinode; + int major, minor; + unsigned filename_offset = 0; +#if defined(__linux__) + // for now, assume all linuxes have the same format + if (sscanf(stext_, "%"SCNx64"-%"SCNx64" %4s %"SCNx64" %x:%x %"SCNd64" %n", + (unsigned long long *)(start ? start : &tmpstart), + (unsigned long long *)(end ? end : &tmpend), + flags_, + (unsigned long long *)(offset ? offset : &tmpoffset), + &major, &minor, + (unsigned long long *)(inode ? inode : &tmpinode), + &filename_offset) != 7) continue; +#elif defined(__CYGWIN__) || defined(__CYGWIN32__) + // cygwin is like linux, except the third field is the "entry point" + // rather than the offset (see format_process_maps at + // http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/fhandler_process.cc?rev=1.89&content-type=text/x-cvsweb-markup&cvsroot=src + // Offset is always be 0 on cygwin: cygwin implements an mmap + // by loading the whole file and then calling NtMapViewOfSection. + // Cygwin also seems to set its flags kinda randomly; use windows default. + char tmpflags[5]; + if (offset) + *offset = 0; + strcpy(flags_, "r-xp"); + if (sscanf(stext_, "%llx-%llx %4s %llx %x:%x %lld %n", + start ? start : &tmpstart, + end ? end : &tmpend, + tmpflags, + &tmpoffset, + &major, &minor, + inode ? inode : &tmpinode, &filename_offset) != 7) continue; +#elif defined(__FreeBSD__) + // For the format, see http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/fs/procfs/procfs_map.c?rev=1.31&content-type=text/x-cvsweb-markup + tmpstart = tmpend = tmpoffset = 0; + tmpinode = 0; + major = minor = 0; // can't get this info in freebsd + if (inode) + *inode = 0; // nor this + if (offset) + *offset = 0; // seems like this should be in there, but maybe not + // start end resident privateresident obj(?) prot refcnt shadowcnt + // flags copy_on_write needs_copy type filename: + // 0x8048000 0x804a000 2 0 0xc104ce70 r-x 1 0 0x0 COW NC vnode /bin/cat + if (sscanf(stext_, "0x%"SCNx64" 0x%"SCNx64" %*d %*d %*p %3s %*d %*d 0x%*x %*s %*s %*s %n", + start ? start : &tmpstart, + end ? end : &tmpend, + flags_, + &filename_offset) != 3) continue; +#endif + + // Depending on the Linux kernel being used, there may or may not be a space + // after the inode if there is no filename. sscanf will in such situations + // nondeterministically either fill in filename_offset or not (the results + // differ on multiple calls in the same run even with identical arguments). + // We don't want to wander off somewhere beyond the end of the string. + size_t stext_length = strlen(stext_); + if (filename_offset == 0 || filename_offset > stext_length) + filename_offset = stext_length; + + // We found an entry + if (flags) *flags = flags_; + if (filename) *filename = stext_ + filename_offset; + if (dev) *dev = minor | (major << 8); + + if (using_maps_backing_) { + // Extract and parse physical page backing info. + char *backing_ptr = stext_ + filename_offset + + strlen(stext_+filename_offset); + + // find the second '(' + int paren_count = 0; + while (--backing_ptr > stext_) { + if (*backing_ptr == '(') { + ++paren_count; + if (paren_count >= 2) { + uint64 tmp_file_mapping; + uint64 tmp_file_pages; + uint64 tmp_anon_mapping; + uint64 tmp_anon_pages; + + sscanf(backing_ptr+1, "F %"SCNx64" %"SCNd64") (A %"SCNx64" %"SCNd64")", + (unsigned long long *)(file_mapping ? + file_mapping : &tmp_file_mapping), + (unsigned long long *)(file_pages ? + file_pages : &tmp_file_pages), + (unsigned long long *)(anon_mapping + ? anon_mapping : &tmp_anon_mapping), + (unsigned long long *)(anon_pages + ? anon_pages : &tmp_anon_pages)); + // null terminate the file name (there is a space + // before the first (. + backing_ptr[-1] = 0; + break; + } + } + } + } + + return true; + } while (etext_ > ibuf_); +#elif defined(__sun__) + // This is based on MA_READ == 4, MA_WRITE == 2, MA_EXEC == 1 + static char kPerms[8][4] = { "---", "--x", "-w-", "-wx", + "r--", "r-x", "rw-", "rwx" }; + COMPILE_ASSERT(MA_READ == 4, solaris_ma_read_must_equal_4); + COMPILE_ASSERT(MA_WRITE == 2, solaris_ma_write_must_equal_2); + COMPILE_ASSERT(MA_EXEC == 1, solaris_ma_exec_must_equal_1); + Buffer object_path; + int nread = 0; // fill up buffer with text + NO_INTR(nread = read(fd_, ibuf_, sizeof(prmap_t))); + if (nread == sizeof(prmap_t)) { + long inode_from_mapname = 0; + prmap_t* mapinfo = reinterpret_cast(ibuf_); + // Best-effort attempt to get the inode from the filename. I think the + // two middle ints are major and minor device numbers, but I'm not sure. + sscanf(mapinfo->pr_mapname, "ufs.%*d.%*d.%ld", &inode_from_mapname); + + if (pid_ == 0) { + CHECK_LT(snprintf(object_path.buf_, Buffer::kBufSize, + "/proc/self/path/%s", mapinfo->pr_mapname), + Buffer::kBufSize); + } else { + CHECK_LT(snprintf(object_path.buf_, Buffer::kBufSize, + "/proc/%d/path/%s", + static_cast(pid_), mapinfo->pr_mapname), + Buffer::kBufSize); + } + ssize_t len = readlink(object_path.buf_, current_filename_, PATH_MAX); + CHECK_LT(len, PATH_MAX); + if (len < 0) + len = 0; + current_filename_[len] = '\0'; + + if (start) *start = mapinfo->pr_vaddr; + if (end) *end = mapinfo->pr_vaddr + mapinfo->pr_size; + if (flags) *flags = kPerms[mapinfo->pr_mflags & 7]; + if (offset) *offset = mapinfo->pr_offset; + if (inode) *inode = inode_from_mapname; + if (filename) *filename = current_filename_; + if (file_mapping) *file_mapping = 0; + if (file_pages) *file_pages = 0; + if (anon_mapping) *anon_mapping = 0; + if (anon_pages) *anon_pages = 0; + if (dev) *dev = 0; + return true; + } +#elif defined(__MACH__) + // We return a separate entry for each segment in the DLL. (TODO(csilvers): + // can we do better?) A DLL ("image") has load-commands, some of which + // talk about segment boundaries. + // cf image_for_address from http://svn.digium.com/view/asterisk/team/oej/minivoicemail/dlfcn.c?revision=53912 + for (; current_image_ >= 0; current_image_--) { + const mach_header* hdr = _dyld_get_image_header(current_image_); + if (!hdr) continue; + if (current_load_cmd_ < 0) // set up for this image + current_load_cmd_ = hdr->ncmds; // again, go from the top down + + // We start with the next load command (we've already looked at this one). + for (current_load_cmd_--; current_load_cmd_ >= 0; current_load_cmd_--) { +#ifdef MH_MAGIC_64 + if (NextExtMachHelper( + hdr, current_image_, current_load_cmd_, + start, end, flags, offset, inode, filename, + file_mapping, file_pages, anon_mapping, + anon_pages, dev)) { + return true; + } +#endif + if (NextExtMachHelper( + hdr, current_image_, current_load_cmd_, + start, end, flags, offset, inode, filename, + file_mapping, file_pages, anon_mapping, + anon_pages, dev)) { + return true; + } + } + // If we get here, no more load_cmd's in this image talk about + // segments. Go on to the next image. + } +#elif defined(PLATFORM_WINDOWS) + static char kDefaultPerms[5] = "r-xp"; + BOOL ok; + if (module_.dwSize == 0) { // only possible before first call + module_.dwSize = sizeof(module_); + ok = Module32First(snapshot_, &module_); + } else { + ok = Module32Next(snapshot_, &module_); + } + if (ok) { + uint64 base_addr = reinterpret_cast(module_.modBaseAddr); + if (start) *start = base_addr; + if (end) *end = base_addr + module_.modBaseSize; + if (flags) *flags = kDefaultPerms; + if (offset) *offset = 0; + if (inode) *inode = 0; + if (filename) *filename = module_.szExePath; + if (file_mapping) *file_mapping = 0; + if (file_pages) *file_pages = 0; + if (anon_mapping) *anon_mapping = 0; + if (anon_pages) *anon_pages = 0; + if (dev) *dev = 0; + return true; + } +#endif + + // We didn't find anything + return false; +} + +int ProcMapsIterator::FormatLine(char* buffer, int bufsize, + uint64 start, uint64 end, const char *flags, + uint64 offset, int64 inode, + const char *filename, dev_t dev) { + // We assume 'flags' looks like 'rwxp' or 'rwx'. + char r = (flags && flags[0] == 'r') ? 'r' : '-'; + char w = (flags && flags[0] && flags[1] == 'w') ? 'w' : '-'; + char x = (flags && flags[0] && flags[1] && flags[2] == 'x') ? 'x' : '-'; + // p always seems set on linux, so we set the default to 'p', not '-' + char p = (flags && flags[0] && flags[1] && flags[2] && flags[3] != 'p') + ? '-' : 'p'; + + const int rc = snprintf(buffer, bufsize, + "%08"PRIx64"-%08"PRIx64" %c%c%c%c %08"PRIx64" %02x:%02x %-11"PRId64" %s\n", + (unsigned long long)start, (unsigned long long)end, r,w,x,p, + (unsigned long long)offset, + static_cast(dev/256), static_cast(dev%256), + (unsigned long long)inode, filename); + return (rc < 0 || rc >= bufsize) ? 0 : rc; +} + +// Helper to add the list of mapped shared libraries to a profile. +// Fill formatted "/proc/self/maps" contents into buffer 'buf' of size 'size' +// and return the actual size occupied in 'buf'. We fill wrote_all to true +// if we successfully wrote all proc lines to buf, false else. +// We do not provision for 0-terminating 'buf'. +int FillProcSelfMaps(char buf[], int size, bool* wrote_all) { + ProcMapsIterator::Buffer iterbuf; + ProcMapsIterator it(0, &iterbuf); // 0 means "current pid" + + uint64 start, end, offset; + int64 inode; + char *flags, *filename; + int bytes_written = 0; + *wrote_all = true; + while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { + const int line_length = it.FormatLine(buf + bytes_written, + size - bytes_written, + start, end, flags, offset, + inode, filename, 0); + if (line_length == 0) + *wrote_all = false; // failed to write this line out + else + bytes_written += line_length; + + } + return bytes_written; +} + +// Dump the same data as FillProcSelfMaps reads to fd. +// It seems easier to repeat parts of FillProcSelfMaps here than to +// reuse it via a call. +void DumpProcSelfMaps(RawFD fd) { + ProcMapsIterator::Buffer iterbuf; + ProcMapsIterator it(0, &iterbuf); // 0 means "current pid" + + uint64 start, end, offset; + int64 inode; + char *flags, *filename; + ProcMapsIterator::Buffer linebuf; + while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { + int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), + start, end, flags, offset, inode, filename, + 0); + RawWrite(fd, linebuf.buf_, written); + } +} + +// Re-run fn until it doesn't cause EINTR. +#define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR) + +RawFD RawOpenForWriting(const char* filename) { + return open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0664); +} + +void RawWrite(RawFD fd, const char* buf, size_t len) { + while (len > 0) { + ssize_t r; + NO_INTR(r = write(fd, buf, len)); + if (r <= 0) break; + buf += r; + len -= r; + } +} + +void RawClose(RawFD fd) { + NO_INTR(close(fd)); +} diff --git a/lib/asan/sysinfo/sysinfo.h b/lib/asan/sysinfo/sysinfo.h new file mode 100644 index 0000000..707687e --- /dev/null +++ b/lib/asan/sysinfo/sysinfo.h @@ -0,0 +1,234 @@ +// Copyright (c) 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// All functions here are thread-hostile due to file caching unless +// commented otherwise. + +#ifndef _SYSINFO_H_ +#define _SYSINFO_H_ + +#include +#if (defined(_WIN32) || defined(__MINGW32__)) && (!defined(__CYGWIN__) && !defined(__CYGWIN32__)) +#include // for DWORD +#include // for CreateToolhelp32Snapshot +#endif +#ifdef HAVE_UNISTD_H +#include // for pid_t +#endif +#include // for size_t +#include // for PATH_MAX +#include "basictypes.h" + +// This getenv function is safe to call before the C runtime is initialized. +// On Windows, it utilizes GetEnvironmentVariable() and on unix it uses +// /proc/self/environ instead calling getenv(). It's intended to be used in +// routines that run before main(), when the state required for getenv() may +// not be set up yet. In particular, errno isn't set up until relatively late +// (after the pthreads library has a chance to make it threadsafe), and +// getenv() doesn't work until then. +// On some platforms, this call will utilize the same, static buffer for +// repeated GetenvBeforeMain() calls. Callers should not expect pointers from +// this routine to be long lived. +// Note that on unix, /proc only has the environment at the time the +// application was started, so this routine ignores setenv() calls/etc. Also +// note it only reads the first 16K of the environment. +extern const char* GetenvBeforeMain(const char* name); + +// This takes as an argument an environment-variable name (like +// CPUPROFILE) whose value is supposed to be a file-path, and sets +// path to that path, and returns true. Non-trivial for surprising +// reasons, as documented in sysinfo.cc. path must have space PATH_MAX. +extern bool GetUniquePathFromEnv(const char* env_name, char* path); + +extern int NumCPUs(); + +// processor cycles per second of each processor. Thread-safe. +extern double CyclesPerSecond(void); + + +// Return true if we're running POSIX (e.g., NPTL on Linux) threads, +// as opposed to a non-POSIX thread libary. The thing that we care +// about is whether a thread's pid is the same as the thread that +// spawned it. If so, this function returns true. +// Thread-safe. +// Note: We consider false negatives to be OK. +bool HasPosixThreads(); + +#ifndef SWIG // SWIG doesn't like struct Buffer and variable arguments. + +// A ProcMapsIterator abstracts access to /proc/maps for a given +// process. Needs to be stack-allocatable and avoid using stdio/malloc +// so it can be used in the google stack dumper, heap-profiler, etc. +// +// On Windows and Mac OS X, this iterator iterates *only* over DLLs +// mapped into this process space. For Linux, FreeBSD, and Solaris, +// it iterates over *all* mapped memory regions, including anonymous +// mmaps. For other O/Ss, it is unlikely to work at all, and Valid() +// will always return false. Also note: this routine only works on +// FreeBSD if procfs is mounted: make sure this is in your /etc/fstab: +// proc /proc procfs rw 0 0 +class ProcMapsIterator { + public: + struct Buffer { +#ifdef __FreeBSD__ + // FreeBSD requires us to read all of the maps file at once, so + // we have to make a buffer that's "always" big enough + static const size_t kBufSize = 102400; +#else // a one-line buffer is good enough + static const size_t kBufSize = PATH_MAX + 1024; +#endif + char buf_[kBufSize]; + }; + + + // Create a new iterator for the specified pid. pid can be 0 for "self". + explicit ProcMapsIterator(pid_t pid); + + // Create an iterator with specified storage (for use in signal + // handler). "buffer" should point to a ProcMapsIterator::Buffer + // buffer can be NULL in which case a bufer will be allocated. + ProcMapsIterator(pid_t pid, Buffer *buffer); + + // Iterate through maps_backing instead of maps if use_maps_backing + // is true. Otherwise the same as above. buffer can be NULL and + // it will allocate a buffer itself. + ProcMapsIterator(pid_t pid, Buffer *buffer, + bool use_maps_backing); + + // Returns true if the iterator successfully initialized; + bool Valid() const; + + // Returns a pointer to the most recently parsed line. Only valid + // after Next() returns true, and until the iterator is destroyed or + // Next() is called again. This may give strange results on non-Linux + // systems. Prefer FormatLine() if that may be a concern. + const char *CurrentLine() const { return stext_; } + + // Writes the "canonical" form of the /proc/xxx/maps info for a single + // line to the passed-in buffer. Returns the number of bytes written, + // or 0 if it was not able to write the complete line. (To guarantee + // success, buffer should have size at least Buffer::kBufSize.) + // Takes as arguments values set via a call to Next(). The + // "canonical" form of the line (taken from linux's /proc/xxx/maps): + // - + + // : Note: the + // eg + // 08048000-0804c000 r-xp 00000000 03:01 3793678 /bin/cat + // If you don't have the dev_t (dev), feel free to pass in 0. + // (Next() doesn't return a dev_t, though NextExt does.) + // + // Note: if filename and flags were obtained via a call to Next(), + // then the output of this function is only valid if Next() returned + // true, and only until the iterator is destroyed or Next() is + // called again. (Since filename, at least, points into CurrentLine.) + static int FormatLine(char* buffer, int bufsize, + uint64 start, uint64 end, const char *flags, + uint64 offset, int64 inode, const char *filename, + dev_t dev); + + // Find the next entry in /proc/maps; return true if found or false + // if at the end of the file. + // + // Any of the result pointers can be NULL if you're not interested + // in those values. + // + // If "flags" and "filename" are passed, they end up pointing to + // storage within the ProcMapsIterator that is valid only until the + // iterator is destroyed or Next() is called again. The caller may + // modify the contents of these strings (up as far as the first NUL, + // and only until the subsequent call to Next()) if desired. + + // The offsets are all uint64 in order to handle the case of a + // 32-bit process running on a 64-bit kernel + // + // IMPORTANT NOTE: see top-of-class notes for details about what + // mapped regions Next() iterates over, depending on O/S. + // TODO(csilvers): make flags and filename const. + bool Next(uint64 *start, uint64 *end, char **flags, + uint64 *offset, int64 *inode, char **filename); + + bool NextExt(uint64 *start, uint64 *end, char **flags, + uint64 *offset, int64 *inode, char **filename, + uint64 *file_mapping, uint64 *file_pages, + uint64 *anon_mapping, uint64 *anon_pages, + dev_t *dev); + + ~ProcMapsIterator(); + + private: + void Init(pid_t pid, Buffer *buffer, bool use_maps_backing); + + char *ibuf_; // input buffer + char *stext_; // start of text + char *etext_; // end of text + char *nextline_; // start of next line + char *ebuf_; // end of buffer (1 char for a nul) +#if (defined(_WIN32) || defined(__MINGW32__)) && (!defined(__CYGWIN__) && !defined(__CYGWIN32__)) + HANDLE snapshot_; // filehandle on dll info + // In a change from the usual W-A pattern, there is no A variant of + // MODULEENTRY32. Tlhelp32.h #defines the W variant, but not the A. + // We want the original A variants, and this #undef is the only + // way I see to get them. Redefining it when we're done prevents us + // from affecting other .cc files. +# ifdef MODULEENTRY32 // Alias of W +# undef MODULEENTRY32 + MODULEENTRY32 module_; // info about current dll (and dll iterator) +# define MODULEENTRY32 MODULEENTRY32W +# else // It's the ascii, the one we want. + MODULEENTRY32 module_; // info about current dll (and dll iterator) +# endif +#elif defined(__MACH__) + int current_image_; // dll's are called "images" in macos parlance + int current_load_cmd_; // the segment of this dll we're examining +#elif defined(__sun__) // Solaris + int fd_; + char current_filename_[PATH_MAX]; +#else + int fd_; // filehandle on /proc/*/maps +#endif + pid_t pid_; + char flags_[10]; + Buffer* dynamic_buffer_; // dynamically-allocated Buffer + bool using_maps_backing_; // true if we are looking at maps_backing instead of maps. +}; + +#endif /* #ifndef SWIG */ + +// Helper routines +typedef int RawFD; +const RawFD kIllegalRawFD = -1; // what open returns if it fails + +RawFD RawOpenForWriting(const char* filename); // uses default permissions +void RawWrite(RawFD fd, const char* buf, size_t len); +void RawClose(RawFD fd); + +int FillProcSelfMaps(char buf[], int size, bool* wrote_all); +void DumpProcSelfMaps(RawFD fd); + +#endif /* #ifndef _SYSINFO_H_ */ diff --git a/lib/asan/tests/asan_benchmarks_test.cc b/lib/asan/tests/asan_benchmarks_test.cc new file mode 100644 index 0000000..b72cc3f --- /dev/null +++ b/lib/asan/tests/asan_benchmarks_test.cc @@ -0,0 +1,86 @@ +//===-- asan_benchmarks_test.cc ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Some benchmarks for the instrumented code. +//===----------------------------------------------------------------------===// + +#include "asan_test_config.h" +#include "asan_test_utils.h" + +template +__attribute__((noinline)) +static void ManyAccessFunc(T *x, size_t n_elements, size_t n_iter) { + for (size_t iter = 0; iter < n_iter; iter++) { + break_optimization(0); + // hand unroll the loop to stress the reg alloc. + for (size_t i = 0; i <= n_elements - 16; i += 16) { + x[i + 0] = i; + x[i + 1] = i; + x[i + 2] = i; + x[i + 3] = i; + x[i + 4] = i; + x[i + 5] = i; + x[i + 6] = i; + x[i + 7] = i; + x[i + 8] = i; + x[i + 9] = i; + x[i + 10] = i; + x[i + 11] = i; + x[i + 12] = i; + x[i + 13] = i; + x[i + 14] = i; + x[i + 15] = i; + } + } +} + +TEST(AddressSanitizer, ManyAccessBenchmark) { + size_t kLen = 1024; + int *int_array = new int[kLen]; + ManyAccessFunc(int_array, kLen, 1 << 24); + delete [] int_array; +} + +// access 7 char elements in a 7 byte array (i.e. on the border). +__attribute__((noinline)) +static void BorderAccessFunc(char *x, size_t n_iter) { + for (size_t iter = 0; iter < n_iter; iter++) { + break_optimization(x); + x[0] = 0; + x[1] = 0; + x[2] = 0; + x[3] = 0; + x[4] = 0; + x[5] = 0; + x[6] = 0; + } +} + +TEST(AddressSanitizer, BorderAccessBenchmark) { + char *char_7_array = new char[7]; + BorderAccessFunc(char_7_array, 1 << 30); + delete [] char_7_array; +} + +static void FunctionWithLargeStack() { + int stack[1000]; + Ident(stack); +} + +TEST(AddressSanitizer, FakeStackBenchmark) { + for (int i = 0; i < 10000000; i++) + Ident(&FunctionWithLargeStack)(); +} + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/lib/asan/tests/asan_break_optimization.cc b/lib/asan/tests/asan_break_optimization.cc new file mode 100644 index 0000000..acd0427 --- /dev/null +++ b/lib/asan/tests/asan_break_optimization.cc @@ -0,0 +1,18 @@ +//===-- asan_break_optimization.cc ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +//===----------------------------------------------------------------------===// + +#include "asan_test_utils.h" +// Have this function in a separate file to avoid inlining. +// (Yes, we know about cross-file inlining, but let's assume we don't use it). +extern "C" void break_optimization(void *x) { +} diff --git a/lib/asan/tests/asan_exceptions_test.cc b/lib/asan/tests/asan_exceptions_test.cc new file mode 100644 index 0000000..ecd406d --- /dev/null +++ b/lib/asan/tests/asan_exceptions_test.cc @@ -0,0 +1,27 @@ +// See http://llvm.org/bugs/show_bug.cgi?id=11468 +#include +#include + +class Action { + public: + Action() {} + void PrintString(const std::string& msg) const { + fprintf(stderr, "%s\n", msg.c_str()); + } + void Throw(const char& arg) const { + PrintString("PrintString called!"); // this line is important + throw arg; + } +}; + +int main() { + const Action a; + fprintf(stderr, "&a before = %p\n", &a); + try { + a.Throw('c'); + } catch(const char&) { + fprintf(stderr, "&a in catch = %p\n", &a); + } + fprintf(stderr, "&a final = %p\n", &a); + return 0; +} diff --git a/lib/asan/tests/asan_globals_test.cc b/lib/asan/tests/asan_globals_test.cc new file mode 100644 index 0000000..2303f8b --- /dev/null +++ b/lib/asan/tests/asan_globals_test.cc @@ -0,0 +1,24 @@ +//===-- asan_globals_test.cc ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Some globals in a separate file. +//===----------------------------------------------------------------------===// + +extern char glob5[5]; +static char static10[10]; + +int GlobalsTest(int zero) { + static char func_static15[15]; + glob5[zero] = 0; + static10[zero] = 0; + func_static15[zero] = 0; + return glob5[1] + func_static15[2]; +} diff --git a/lib/asan/tests/asan_interface_test.cc b/lib/asan/tests/asan_interface_test.cc new file mode 100644 index 0000000..c26ed92 --- /dev/null +++ b/lib/asan/tests/asan_interface_test.cc @@ -0,0 +1,334 @@ +//===-- asan_interface_test.cc ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +//===----------------------------------------------------------------------===// +#include +#include +#include + +#include "asan_test_config.h" +#include "asan_test_utils.h" +#include "asan_interface.h" + +TEST(AddressSanitizerInterface, GetEstimatedAllocatedSize) { + EXPECT_EQ(1, __asan_get_estimated_allocated_size(0)); + const size_t sizes[] = { 1, 30, 1<<30 }; + for (size_t i = 0; i < 3; i++) { + EXPECT_EQ(sizes[i], __asan_get_estimated_allocated_size(sizes[i])); + } +} + +static const char* kGetAllocatedSizeErrorMsg = + "__asan_get_allocated_size failed"; + +TEST(AddressSanitizerInterface, GetAllocatedSizeAndOwnershipTest) { + const size_t kArraySize = 100; + char *array = Ident((char*)malloc(kArraySize)); + int *int_ptr = Ident(new int); + + // Allocated memory is owned by allocator. Allocated size should be + // equal to requested size. + EXPECT_EQ(true, __asan_get_ownership(array)); + EXPECT_EQ(kArraySize, __asan_get_allocated_size(array)); + EXPECT_EQ(true, __asan_get_ownership(int_ptr)); + EXPECT_EQ(sizeof(int), __asan_get_allocated_size(int_ptr)); + + // We cannot call GetAllocatedSize from the memory we didn't map, + // and from the interior pointers (not returned by previous malloc). + void *wild_addr = (void*)0x1; + EXPECT_EQ(false, __asan_get_ownership(wild_addr)); + EXPECT_DEATH(__asan_get_allocated_size(wild_addr), kGetAllocatedSizeErrorMsg); + EXPECT_EQ(false, __asan_get_ownership(array + kArraySize / 2)); + EXPECT_DEATH(__asan_get_allocated_size(array + kArraySize / 2), + kGetAllocatedSizeErrorMsg); + + // NULL is a valid argument and is owned. + EXPECT_EQ(true, __asan_get_ownership(NULL)); + EXPECT_EQ(0, __asan_get_allocated_size(NULL)); + + // When memory is freed, it's not owned, and call to GetAllocatedSize + // is forbidden. + free(array); + EXPECT_EQ(false, __asan_get_ownership(array)); + EXPECT_DEATH(__asan_get_allocated_size(array), kGetAllocatedSizeErrorMsg); + + delete int_ptr; +} + +TEST(AddressSanitizerInterface, GetCurrentAllocatedBytesTest) { + size_t before_malloc, after_malloc, after_free; + char *array; + const size_t kMallocSize = 100; + before_malloc = __asan_get_current_allocated_bytes(); + + array = Ident((char*)malloc(kMallocSize)); + after_malloc = __asan_get_current_allocated_bytes(); + EXPECT_EQ(before_malloc + kMallocSize, after_malloc); + + free(array); + after_free = __asan_get_current_allocated_bytes(); + EXPECT_EQ(before_malloc, after_free); +} + +static void DoDoubleFree() { + int *x = Ident(new int); + delete Ident(x); + delete Ident(x); +} + +// This test is run in a separate process, so that large malloced +// chunk won't remain in the free lists after the test. +// Note: use ASSERT_* instead of EXPECT_* here. +static void RunGetHeapSizeTestAndDie() { + size_t old_heap_size, new_heap_size, heap_growth; + // We unlikely have have chunk of this size in free list. + static const size_t kLargeMallocSize = 1 << 29; // 512M + old_heap_size = __asan_get_heap_size(); + fprintf(stderr, "allocating %zu bytes:\n", kLargeMallocSize); + free(Ident(malloc(kLargeMallocSize))); + new_heap_size = __asan_get_heap_size(); + heap_growth = new_heap_size - old_heap_size; + fprintf(stderr, "heap growth after first malloc: %zu\n", heap_growth); + ASSERT_GE(heap_growth, kLargeMallocSize); + ASSERT_LE(heap_growth, 2 * kLargeMallocSize); + + // Now large chunk should fall into free list, and can be + // allocated without increasing heap size. + old_heap_size = new_heap_size; + free(Ident(malloc(kLargeMallocSize))); + heap_growth = __asan_get_heap_size() - old_heap_size; + fprintf(stderr, "heap growth after second malloc: %zu\n", heap_growth); + ASSERT_LT(heap_growth, kLargeMallocSize); + + // Test passed. Now die with expected double-free. + DoDoubleFree(); +} + +TEST(AddressSanitizerInterface, GetHeapSizeTest) { + EXPECT_DEATH(RunGetHeapSizeTestAndDie(), "double-free"); +} + +// Note: use ASSERT_* instead of EXPECT_* here. +static void DoLargeMallocForGetFreeBytesTestAndDie() { + size_t old_free_bytes, new_free_bytes; + static const size_t kLargeMallocSize = 1 << 29; // 512M + // If we malloc and free a large memory chunk, it will not fall + // into quarantine and will be available for future requests. + old_free_bytes = __asan_get_free_bytes(); + fprintf(stderr, "allocating %zu bytes:\n", kLargeMallocSize); + fprintf(stderr, "free bytes before malloc: %zu\n", old_free_bytes); + free(Ident(malloc(kLargeMallocSize))); + new_free_bytes = __asan_get_free_bytes(); + fprintf(stderr, "free bytes after malloc and free: %zu\n", new_free_bytes); + ASSERT_GE(new_free_bytes, old_free_bytes + kLargeMallocSize); + // Test passed. + DoDoubleFree(); +} + +TEST(AddressSanitizerInterface, GetFreeBytesTest) { + static const size_t kNumOfChunks = 100; + static const size_t kChunkSize = 100; + char *chunks[kNumOfChunks]; + size_t i; + size_t old_free_bytes, new_free_bytes; + // Allocate a small chunk. Now allocator probably has a lot of these + // chunks to fulfill future requests. So, future requests will decrease + // the number of free bytes. + chunks[0] = Ident((char*)malloc(kChunkSize)); + old_free_bytes = __asan_get_free_bytes(); + for (i = 1; i < kNumOfChunks; i++) { + chunks[i] = Ident((char*)malloc(kChunkSize)); + new_free_bytes = __asan_get_free_bytes(); + EXPECT_LT(new_free_bytes, old_free_bytes); + old_free_bytes = new_free_bytes; + } + // Deleting these chunks will move them to quarantine, number of free + // bytes won't increase. + for (i = 0; i < kNumOfChunks; i++) { + free(chunks[i]); + EXPECT_EQ(old_free_bytes, __asan_get_free_bytes()); + } + EXPECT_DEATH(DoLargeMallocForGetFreeBytesTestAndDie(), "double-free"); +} + +static const size_t kManyThreadsMallocSizes[] = {5, 1UL<<10, 1UL<<20, 357}; +static const size_t kManyThreadsIterations = 250; +static const size_t kManyThreadsNumThreads = 200; + +void *ManyThreadsWithStatsWorker(void *arg) { + for (size_t iter = 0; iter < kManyThreadsIterations; iter++) { + for (size_t size_index = 0; size_index < 4; size_index++) { + free(Ident(malloc(kManyThreadsMallocSizes[size_index]))); + } + } + return 0; +} + +TEST(AddressSanitizerInterface, ManyThreadsWithStatsStressTest) { + size_t before_test, after_test, i; + pthread_t threads[kManyThreadsNumThreads]; + before_test = __asan_get_current_allocated_bytes(); + for (i = 0; i < kManyThreadsNumThreads; i++) { + pthread_create(&threads[i], 0, + (void* (*)(void *x))ManyThreadsWithStatsWorker, (void*)i); + } + for (i = 0; i < kManyThreadsNumThreads; i++) { + pthread_join(threads[i], 0); + } + after_test = __asan_get_current_allocated_bytes(); + // ASan stats also reflect memory usage of internal ASan RTL structs, + // so we can't check for equality here. + EXPECT_LT(after_test, before_test + (1UL<<20)); +} + +TEST(AddressSanitizerInterface, ExitCode) { + int original_exit_code = __asan_set_error_exit_code(7); + EXPECT_EXIT(DoDoubleFree(), ::testing::ExitedWithCode(7), ""); + EXPECT_EQ(7, __asan_set_error_exit_code(8)); + EXPECT_EXIT(DoDoubleFree(), ::testing::ExitedWithCode(8), ""); + EXPECT_EQ(8, __asan_set_error_exit_code(original_exit_code)); + EXPECT_EXIT(DoDoubleFree(), + ::testing::ExitedWithCode(original_exit_code), ""); +} + +static const char* kUseAfterPoisonErrorMessage = "use-after-poison"; + +#define ACCESS(ptr, offset) Ident(*(ptr + offset)) + +#define DIE_ON_ACCESS(ptr, offset) \ + EXPECT_DEATH(Ident(*(ptr + offset)), kUseAfterPoisonErrorMessage) + +TEST(AddressSanitizerInterface, SimplePoisonMemoryRegionTest) { + char *array = Ident((char*)malloc(120)); + // poison array[40..80) + ASAN_POISON_MEMORY_REGION(array + 40, 40); + ACCESS(array, 39); + ACCESS(array, 80); + DIE_ON_ACCESS(array, 40); + DIE_ON_ACCESS(array, 60); + DIE_ON_ACCESS(array, 79); + ASAN_UNPOISON_MEMORY_REGION(array + 40, 40); + // access previously poisoned memory. + ACCESS(array, 40); + ACCESS(array, 79); + free(array); +} + +TEST(AddressSanitizerInterface, OverlappingPoisonMemoryRegionTest) { + char *array = Ident((char*)malloc(120)); + // Poison [0..40) and [80..120) + ASAN_POISON_MEMORY_REGION(array, 40); + ASAN_POISON_MEMORY_REGION(array + 80, 40); + DIE_ON_ACCESS(array, 20); + ACCESS(array, 60); + DIE_ON_ACCESS(array, 100); + // Poison whole array - [0..120) + ASAN_POISON_MEMORY_REGION(array, 120); + DIE_ON_ACCESS(array, 60); + // Unpoison [24..96) + ASAN_UNPOISON_MEMORY_REGION(array + 24, 72); + DIE_ON_ACCESS(array, 23); + ACCESS(array, 24); + ACCESS(array, 60); + ACCESS(array, 95); + DIE_ON_ACCESS(array, 96); + free(array); +} + +TEST(AddressSanitizerInterface, PushAndPopWithPoisoningTest) { + // Vector of capacity 20 + char *vec = Ident((char*)malloc(20)); + ASAN_POISON_MEMORY_REGION(vec, 20); + for (size_t i = 0; i < 7; i++) { + // Simulate push_back. + ASAN_UNPOISON_MEMORY_REGION(vec + i, 1); + ACCESS(vec, i); + DIE_ON_ACCESS(vec, i + 1); + } + for (size_t i = 7; i > 0; i--) { + // Simulate pop_back. + ASAN_POISON_MEMORY_REGION(vec + i - 1, 1); + DIE_ON_ACCESS(vec, i - 1); + if (i > 1) ACCESS(vec, i - 2); + } + free(vec); +} + +// Make sure that each aligned block of size "2^granularity" doesn't have +// "true" value before "false" value. +static void MakeShadowValid(bool *shadow, int length, int granularity) { + bool can_be_poisoned = true; + for (int i = length - 1; i >= 0; i--) { + can_be_poisoned &= shadow[i]; + shadow[i] &= can_be_poisoned; + if (i % (1 << granularity) == 0) { + can_be_poisoned = true; + } + } +} + +TEST(AddressSanitizerInterface, PoisoningStressTest) { + const size_t kSize = 24; + bool expected[kSize]; + char *arr = Ident((char*)malloc(kSize)); + for (size_t l1 = 0; l1 < kSize; l1++) { + for (size_t s1 = 1; l1 + s1 <= kSize; s1++) { + for (size_t l2 = 0; l2 < kSize; l2++) { + for (size_t s2 = 1; l2 + s2 <= kSize; s2++) { + // Poison [l1, l1+s1), [l2, l2+s2) and check result. + ASAN_UNPOISON_MEMORY_REGION(arr, kSize); + ASAN_POISON_MEMORY_REGION(arr + l1, s1); + ASAN_POISON_MEMORY_REGION(arr + l2, s2); + memset(expected, false, kSize); + memset(expected + l1, true, s1); + MakeShadowValid(expected, 24, /*granularity*/ 3); + memset(expected + l2, true, s2); + MakeShadowValid(expected, 24, /*granularity*/ 3); + for (size_t i = 0; i < kSize; i++) { + ASSERT_EQ(expected[i], __asan_address_is_poisoned(arr + i)); + } + // Unpoison [l1, l1+s1) and [l2, l2+s2) and check result. + ASAN_POISON_MEMORY_REGION(arr, kSize); + ASAN_UNPOISON_MEMORY_REGION(arr + l1, s1); + ASAN_UNPOISON_MEMORY_REGION(arr + l2, s2); + memset(expected, true, kSize); + memset(expected + l1, false, s1); + MakeShadowValid(expected, 24, /*granularity*/ 3); + memset(expected + l2, false, s2); + MakeShadowValid(expected, 24, /*granularity*/ 3); + for (size_t i = 0; i < kSize; i++) { + ASSERT_EQ(expected[i], __asan_address_is_poisoned(arr + i)); + } + } + } + } + } +} + +static const char *kInvalidPoisonMessage = "invalid-poison-memory-range"; +static const char *kInvalidUnpoisonMessage = "invalid-unpoison-memory-range"; + +TEST(AddressSanitizerInterface, DISABLED_InvalidPoisonAndUnpoisonCallsTest) { + char *array = Ident((char*)malloc(120)); + ASAN_UNPOISON_MEMORY_REGION(array, 120); + // Try to unpoison not owned memory + EXPECT_DEATH(ASAN_UNPOISON_MEMORY_REGION(array, 121), + kInvalidUnpoisonMessage); + EXPECT_DEATH(ASAN_UNPOISON_MEMORY_REGION(array - 1, 120), + kInvalidUnpoisonMessage); + + ASAN_POISON_MEMORY_REGION(array, 120); + // Try to poison not owned memory. + EXPECT_DEATH(ASAN_POISON_MEMORY_REGION(array, 121), kInvalidPoisonMessage); + EXPECT_DEATH(ASAN_POISON_MEMORY_REGION(array - 1, 120), + kInvalidPoisonMessage); + free(array); +} diff --git a/lib/asan/tests/asan_mac_test.h b/lib/asan/tests/asan_mac_test.h new file mode 100644 index 0000000..e3ad827 --- /dev/null +++ b/lib/asan/tests/asan_mac_test.h @@ -0,0 +1,16 @@ +extern "C" { + void CFAllocatorDefaultDoubleFree(); + void CFAllocatorSystemDefaultDoubleFree(); + void CFAllocatorMallocDoubleFree(); + void CFAllocatorMallocZoneDoubleFree(); + void CallFreeOnWorkqueue(void *mem); + void TestGCDDispatchAsync(); + void TestGCDDispatchSync(); + void TestGCDReuseWqthreadsAsync(); + void TestGCDReuseWqthreadsSync(); + void TestGCDDispatchAfter(); + void TestGCDInTSDDestructor(); + void TestGCDSourceEvent(); + void TestGCDSourceCancel(); + void TestGCDGroupAsync(); +} diff --git a/lib/asan/tests/asan_mac_test.mm b/lib/asan/tests/asan_mac_test.mm new file mode 100644 index 0000000..b5dbbde --- /dev/null +++ b/lib/asan/tests/asan_mac_test.mm @@ -0,0 +1,203 @@ +// Mac OS X 10.6 or higher only. +#include +#include +#include +#include +#include + +#import +#import + +void CFAllocatorDefaultDoubleFree() { + void *mem = CFAllocatorAllocate(kCFAllocatorDefault, 5, 0); + CFAllocatorDeallocate(kCFAllocatorDefault, mem); + CFAllocatorDeallocate(kCFAllocatorDefault, mem); +} + +void CFAllocatorSystemDefaultDoubleFree() { + void *mem = CFAllocatorAllocate(kCFAllocatorSystemDefault, 5, 0); + CFAllocatorDeallocate(kCFAllocatorSystemDefault, mem); + CFAllocatorDeallocate(kCFAllocatorSystemDefault, mem); +} + +void CFAllocatorMallocDoubleFree() { + void *mem = CFAllocatorAllocate(kCFAllocatorMalloc, 5, 0); + CFAllocatorDeallocate(kCFAllocatorMalloc, mem); + CFAllocatorDeallocate(kCFAllocatorMalloc, mem); +} + +void CFAllocatorMallocZoneDoubleFree() { + void *mem = CFAllocatorAllocate(kCFAllocatorMallocZone, 5, 0); + CFAllocatorDeallocate(kCFAllocatorMallocZone, mem); + CFAllocatorDeallocate(kCFAllocatorMallocZone, mem); +} + + +// Test the +load instrumentation. +// Because the +load methods are invoked before anything else is initialized, +// it makes little sense to wrap the code below into a gTest test case. +// If AddressSanitizer doesn't instrument the +load method below correctly, +// everything will just crash. + +char kStartupStr[] = + "If your test didn't crash, AddressSanitizer is instrumenting " + "the +load methods correctly."; + +@interface LoadSomething : NSObject { +} +@end + +@implementation LoadSomething + ++(void) load { + for (int i = 0; i < strlen(kStartupStr); i++) { + volatile char ch = kStartupStr[i]; // make sure no optimizations occur. + } + // Don't print anything here not to interfere with the death tests. +} + +@end + +void worker_do_alloc(int size) { + char * volatile mem = malloc(size); + mem[0] = 0; // Ok + free(mem); +} + +void worker_do_crash(int size) { + char * volatile mem = malloc(size); + mem[size] = 0; // BOOM + free(mem); +} + +// Tests for the Grand Central Dispatch. See +// http://developer.apple.com/library/mac/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html +// for the reference. + +void TestGCDDispatchAsync() { + dispatch_queue_t queue = dispatch_get_global_queue(0, 0); + dispatch_block_t block = ^{ worker_do_crash(1024); }; + // dispatch_async() runs the task on a worker thread that does not go through + // pthread_create(). We need to verify that AddressSanitizer notices that the + // thread has started. + dispatch_async(queue, block); + // TODO(glider): this is hacky. Need to wait for the worker instead. + sleep(1); +} + +void TestGCDDispatchSync() { + dispatch_queue_t queue = dispatch_get_global_queue(2, 0); + dispatch_block_t block = ^{ worker_do_crash(1024); }; + // dispatch_sync() runs the task on a worker thread that does not go through + // pthread_create(). We need to verify that AddressSanitizer notices that the + // thread has started. + dispatch_sync(queue, block); + // TODO(glider): this is hacky. Need to wait for the worker instead. + sleep(1); +} + +// libdispatch spawns a rather small number of threads and reuses them. We need +// to make sure AddressSanitizer handles the reusing correctly. +void TestGCDReuseWqthreadsAsync() { + dispatch_queue_t queue = dispatch_get_global_queue(0, 0); + dispatch_block_t block_alloc = ^{ worker_do_alloc(1024); }; + dispatch_block_t block_crash = ^{ worker_do_crash(1024); }; + for (int i = 0; i < 100; i++) { + dispatch_async(queue, block_alloc); + } + dispatch_async(queue, block_crash); + // TODO(glider): this is hacky. Need to wait for the workers instead. + sleep(1); +} + +// Try to trigger abnormal behaviour of dispatch_sync() being unhandled by us. +void TestGCDReuseWqthreadsSync() { + dispatch_queue_t queue[4]; + queue[0] = dispatch_get_global_queue(2, 0); + queue[1] = dispatch_get_global_queue(0, 0); + queue[2] = dispatch_get_global_queue(-2, 0); + queue[3] = dispatch_queue_create("my_queue", NULL); + dispatch_block_t block_alloc = ^{ worker_do_alloc(1024); }; + dispatch_block_t block_crash = ^{ worker_do_crash(1024); }; + for (int i = 0; i < 1000; i++) { + dispatch_sync(queue[i % 4], block_alloc); + } + dispatch_sync(queue[3], block_crash); + // TODO(glider): this is hacky. Need to wait for the workers instead. + sleep(1); +} + +void TestGCDDispatchAfter() { + dispatch_queue_t queue = dispatch_get_global_queue(0, 0); + dispatch_block_t block_crash = ^{ worker_do_crash(1024); }; + // Schedule the event one second from the current time. + dispatch_time_t milestone = + dispatch_time(DISPATCH_TIME_NOW, 1LL * NSEC_PER_SEC); + dispatch_after(milestone, queue, block_crash); + // Let's wait for a bit longer now. + // TODO(glider): this is still hacky. + sleep(2); +} + +void worker_do_deallocate(void *ptr) { + free(ptr); +} + +void CallFreeOnWorkqueue(void *tsd) { + dispatch_queue_t queue = dispatch_get_global_queue(0, 0); + dispatch_block_t block_dealloc = ^{ worker_do_deallocate(tsd); }; + dispatch_async(queue, block_dealloc); + // Do not wait for the worker to free the memory -- nobody is going to touch + // it. +} + +void TestGCDSourceEvent() { + dispatch_queue_t queue = dispatch_get_global_queue(0, 0); + dispatch_source_t timer = + dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); + // Schedule the timer one second from the current time. + dispatch_time_t milestone = + dispatch_time(DISPATCH_TIME_NOW, 1LL * NSEC_PER_SEC); + + dispatch_source_set_timer(timer, milestone, DISPATCH_TIME_FOREVER, 0); + char * volatile mem = malloc(10); + dispatch_source_set_event_handler(timer, ^{ + mem[10] = 1; + }); + dispatch_resume(timer); + sleep(2); +} + +void TestGCDSourceCancel() { + dispatch_queue_t queue = dispatch_get_global_queue(0, 0); + dispatch_source_t timer = + dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); + // Schedule the timer one second from the current time. + dispatch_time_t milestone = + dispatch_time(DISPATCH_TIME_NOW, 1LL * NSEC_PER_SEC); + + dispatch_source_set_timer(timer, milestone, DISPATCH_TIME_FOREVER, 0); + char * volatile mem = malloc(10); + // Both dispatch_source_set_cancel_handler() and + // dispatch_source_set_event_handler() use dispatch_barrier_async_f(). + // It's tricky to test dispatch_source_set_cancel_handler() separately, + // so we test both here. + dispatch_source_set_event_handler(timer, ^{ + dispatch_source_cancel(timer); + }); + dispatch_source_set_cancel_handler(timer, ^{ + mem[10] = 1; + }); + dispatch_resume(timer); + sleep(2); +} + +void TestGCDGroupAsync() { + dispatch_queue_t queue = dispatch_get_global_queue(0, 0); + dispatch_group_t group = dispatch_group_create(); + char * volatile mem = malloc(10); + dispatch_group_async(group, queue, ^{ + mem[10] = 1; + }); + dispatch_group_wait(group, DISPATCH_TIME_FOREVER); +} diff --git a/lib/asan/tests/asan_noinst_test.cc b/lib/asan/tests/asan_noinst_test.cc new file mode 100644 index 0000000..204c0da --- /dev/null +++ b/lib/asan/tests/asan_noinst_test.cc @@ -0,0 +1,329 @@ +//===-- asan_noinst_test.cc ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// This test file should be compiled w/o asan instrumentation. +//===----------------------------------------------------------------------===// +#include "asan_allocator.h" +#include "asan_interface.h" +#include "asan_internal.h" +#include "asan_mapping.h" +#include "asan_stack.h" +#include "asan_test_utils.h" + +#include +#include +#include +#include +#include +#include "gtest/gtest.h" + +// Simple stand-alone pseudorandom number generator. +// Current algorithm is ANSI C linear congruential PRNG. +static inline uint32_t my_rand(uint32_t* state) { + return (*state = *state * 1103515245 + 12345) >> 16; +} + +static uint32_t global_seed = 0; + + +TEST(AddressSanitizer, InternalSimpleDeathTest) { + EXPECT_DEATH(exit(1), ""); +} + +static void MallocStress(size_t n) { + uint32_t seed = my_rand(&global_seed); + __asan::AsanStackTrace stack1; + stack1.trace[0] = 0xa123; + stack1.trace[1] = 0xa456; + stack1.size = 2; + + __asan::AsanStackTrace stack2; + stack2.trace[0] = 0xb123; + stack2.trace[1] = 0xb456; + stack2.size = 2; + + __asan::AsanStackTrace stack3; + stack3.trace[0] = 0xc123; + stack3.trace[1] = 0xc456; + stack3.size = 2; + + std::vector vec; + for (size_t i = 0; i < n; i++) { + if ((i % 3) == 0) { + if (vec.empty()) continue; + size_t idx = my_rand(&seed) % vec.size(); + void *ptr = vec[idx]; + vec[idx] = vec.back(); + vec.pop_back(); + __asan::asan_free(ptr, &stack1); + } else { + size_t size = my_rand(&seed) % 1000 + 1; + switch ((my_rand(&seed) % 128)) { + case 0: size += 1024; break; + case 1: size += 2048; break; + case 2: size += 4096; break; + } + size_t alignment = 1 << (my_rand(&seed) % 10 + 1); + char *ptr = (char*)__asan::asan_memalign(alignment, size, &stack2); + vec.push_back(ptr); + ptr[0] = 0; + ptr[size-1] = 0; + ptr[size/2] = 0; + } + } + for (size_t i = 0; i < vec.size(); i++) + __asan::asan_free(vec[i], &stack3); +} + + +TEST(AddressSanitizer, NoInstMallocTest) { +#ifdef __arm__ + MallocStress(300000); +#else + MallocStress(1000000); +#endif +} + +static void PrintShadow(const char *tag, uintptr_t ptr, size_t size) { + fprintf(stderr, "%s shadow: %lx size % 3ld: ", tag, (long)ptr, (long)size); + uintptr_t prev_shadow = 0; + for (intptr_t i = -32; i < (intptr_t)size + 32; i++) { + uintptr_t shadow = __asan::MemToShadow(ptr + i); + if (i == 0 || i == (intptr_t)size) + fprintf(stderr, "."); + if (shadow != prev_shadow) { + prev_shadow = shadow; + fprintf(stderr, "%02x", (int)*(uint8_t*)shadow); + } + } + fprintf(stderr, "\n"); +} + +TEST(AddressSanitizer, DISABLED_InternalPrintShadow) { + for (size_t size = 1; size <= 513; size++) { + char *ptr = new char[size]; + PrintShadow("m", (uintptr_t)ptr, size); + delete [] ptr; + PrintShadow("f", (uintptr_t)ptr, size); + } +} + +static uintptr_t pc_array[] = { +#if __WORDSIZE == 64 + 0x7effbf756068ULL, + 0x7effbf75e5abULL, + 0x7effc0625b7cULL, + 0x7effc05b8997ULL, + 0x7effbf990577ULL, + 0x7effbf990c56ULL, + 0x7effbf992f3cULL, + 0x7effbf950c22ULL, + 0x7effc036dba0ULL, + 0x7effc03638a3ULL, + 0x7effc035be4aULL, + 0x7effc0539c45ULL, + 0x7effc0539a65ULL, + 0x7effc03db9b3ULL, + 0x7effc03db100ULL, + 0x7effc037c7b8ULL, + 0x7effc037bfffULL, + 0x7effc038b777ULL, + 0x7effc038021cULL, + 0x7effc037c7d1ULL, + 0x7effc037bfffULL, + 0x7effc038b777ULL, + 0x7effc038021cULL, + 0x7effc037c7d1ULL, + 0x7effc037bfffULL, + 0x7effc038b777ULL, + 0x7effc038021cULL, + 0x7effc037c7d1ULL, + 0x7effc037bfffULL, + 0x7effc0520d26ULL, + 0x7effc009ddffULL, + 0x7effbf90bb50ULL, + 0x7effbdddfa69ULL, + 0x7effbdde1fe2ULL, + 0x7effbdde2424ULL, + 0x7effbdde27b3ULL, + 0x7effbddee53bULL, + 0x7effbdde1988ULL, + 0x7effbdde0904ULL, + 0x7effc106ce0dULL, + 0x7effbcc3fa04ULL, + 0x7effbcc3f6a4ULL, + 0x7effbcc3e726ULL, + 0x7effbcc40852ULL, + 0x7effb681ec4dULL, +#endif // __WORDSIZE + 0xB0B5E768, + 0x7B682EC1, + 0x367F9918, + 0xAE34E13, + 0xBA0C6C6, + 0x13250F46, + 0xA0D6A8AB, + 0x2B07C1A8, + 0x6C844F4A, + 0x2321B53, + 0x1F3D4F8F, + 0x3FE2924B, + 0xB7A2F568, + 0xBD23950A, + 0x61020930, + 0x33E7970C, + 0x405998A1, + 0x59F3551D, + 0x350E3028, + 0xBC55A28D, + 0x361F3AED, + 0xBEAD0F73, + 0xAEF28479, + 0x757E971F, + 0xAEBA450, + 0x43AD22F5, + 0x8C2C50C4, + 0x7AD8A2E1, + 0x69EE4EE8, + 0xC08DFF, + 0x4BA6538, + 0x3708AB2, + 0xC24B6475, + 0x7C8890D7, + 0x6662495F, + 0x9B641689, + 0xD3596B, + 0xA1049569, + 0x44CBC16, + 0x4D39C39F +}; + +void CompressStackTraceTest(size_t n_iter) { + uint32_t seed = my_rand(&global_seed); + const size_t kNumPcs = ASAN_ARRAY_SIZE(pc_array); + uint32_t compressed[2 * kNumPcs]; + + for (size_t iter = 0; iter < n_iter; iter++) { + std::random_shuffle(pc_array, pc_array + kNumPcs); + __asan::AsanStackTrace stack0, stack1; + stack0.CopyFrom(pc_array, kNumPcs); + stack0.size = std::max((size_t)1, (size_t)my_rand(&seed) % stack0.size); + size_t compress_size = + std::max((size_t)2, (size_t)my_rand(&seed) % (2 * kNumPcs)); + size_t n_frames = + __asan::AsanStackTrace::CompressStack(&stack0, compressed, compress_size); + assert(n_frames <= stack0.size); + __asan::AsanStackTrace::UncompressStack(&stack1, compressed, compress_size); + assert(stack1.size == n_frames); + for (size_t i = 0; i < stack1.size; i++) { + assert(stack0.trace[i] == stack1.trace[i]); + } + } +} + +TEST(AddressSanitizer, CompressStackTraceTest) { + CompressStackTraceTest(10000); +} + +void CompressStackTraceBenchmark(size_t n_iter) { + const size_t kNumPcs = ASAN_ARRAY_SIZE(pc_array); + uint32_t compressed[2 * kNumPcs]; + std::random_shuffle(pc_array, pc_array + kNumPcs); + + __asan::AsanStackTrace stack0; + stack0.CopyFrom(pc_array, kNumPcs); + stack0.size = kNumPcs; + for (size_t iter = 0; iter < n_iter; iter++) { + size_t compress_size = kNumPcs; + size_t n_frames = + __asan::AsanStackTrace::CompressStack(&stack0, compressed, compress_size); + Ident(n_frames); + } +} + +TEST(AddressSanitizer, CompressStackTraceBenchmark) { + CompressStackTraceBenchmark(1 << 24); +} + +TEST(AddressSanitizer, QuarantineTest) { + __asan::AsanStackTrace stack; + stack.trace[0] = 0x890; + stack.size = 1; + + const int size = 32; + void *p = __asan::asan_malloc(size, &stack); + __asan::asan_free(p, &stack); + size_t i; + size_t max_i = 1 << 30; + for (i = 0; i < max_i; i++) { + void *p1 = __asan::asan_malloc(size, &stack); + __asan::asan_free(p1, &stack); + if (p1 == p) break; + } + // fprintf(stderr, "i=%ld\n", i); + EXPECT_GE(i, 100000U); + EXPECT_LT(i, max_i); +} + +void *ThreadedQuarantineTestWorker(void *unused) { + uint32_t seed = my_rand(&global_seed); + __asan::AsanStackTrace stack; + stack.trace[0] = 0x890; + stack.size = 1; + + for (size_t i = 0; i < 1000; i++) { + void *p = __asan::asan_malloc(1 + (my_rand(&seed) % 4000), &stack); + __asan::asan_free(p, &stack); + } + return NULL; +} + +// Check that the thread local allocators are flushed when threads are +// destroyed. +TEST(AddressSanitizer, ThreadedQuarantineTest) { + const int n_threads = 3000; + size_t mmaped1 = __asan_get_heap_size(); + for (int i = 0; i < n_threads; i++) { + pthread_t t; + pthread_create(&t, NULL, ThreadedQuarantineTestWorker, 0); + pthread_join(t, 0); + size_t mmaped2 = __asan_get_heap_size(); + EXPECT_LT(mmaped2 - mmaped1, 320U * (1 << 20)); + } +} + +void *ThreadedOneSizeMallocStress(void *unused) { + __asan::AsanStackTrace stack; + stack.trace[0] = 0x890; + stack.size = 1; + const size_t kNumMallocs = 1000; + for (int iter = 0; iter < 1000; iter++) { + void *p[kNumMallocs]; + for (size_t i = 0; i < kNumMallocs; i++) { + p[i] = __asan::asan_malloc(32, &stack); + } + for (size_t i = 0; i < kNumMallocs; i++) { + __asan::asan_free(p[i], &stack); + } + } + return NULL; +} + +TEST(AddressSanitizer, ThreadedOneSizeMallocStressTest) { + const int kNumThreads = 4; + pthread_t t[kNumThreads]; + for (int i = 0; i < kNumThreads; i++) { + pthread_create(&t[i], 0, ThreadedOneSizeMallocStress, 0); + } + for (int i = 0; i < kNumThreads; i++) { + pthread_join(t[i], 0); + } +} diff --git a/lib/asan/tests/asan_test.cc b/lib/asan/tests/asan_test.cc new file mode 100644 index 0000000..0ff72d3 --- /dev/null +++ b/lib/asan/tests/asan_test.cc @@ -0,0 +1,2022 @@ +//===-- asan_test.cc ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(__i386__) or defined(__x86_64__) +#include +#endif + +#include "asan_test_config.h" +#include "asan_test_utils.h" + +#ifndef __APPLE__ +#include +#endif // __APPLE__ + +#ifdef __APPLE__ +static bool APPLE = true; +#else +static bool APPLE = false; +#endif + +#if ASAN_HAS_EXCEPTIONS +# define ASAN_THROW(x) throw (x) +#else +# define ASAN_THROW(x) +#endif + +#include + +typedef uint8_t U1; +typedef uint16_t U2; +typedef uint32_t U4; +typedef uint64_t U8; + +static const char *progname; +static const int kPageSize = 4096; + +// Simple stand-alone pseudorandom number generator. +// Current algorithm is ANSI C linear congruential PRNG. +static inline uint32_t my_rand(uint32_t* state) { + return (*state = *state * 1103515245 + 12345) >> 16; +} + +static uint32_t global_seed = 0; + +class ObjdumpOfMyself { + public: + explicit ObjdumpOfMyself(const string &binary) { + is_correct = true; + string objdump_name = APPLE ? "gobjdump" : "objdump"; + string prog = objdump_name + " -d " + binary; + // TODO(glider): popen() succeeds even if the file does not exist. + FILE *pipe = popen(prog.c_str(), "r"); + string objdump; + if (pipe) { + const int kBuffSize = 4096; + char buff[kBuffSize+1]; + int read_bytes; + while ((read_bytes = fread(buff, 1, kBuffSize, pipe)) > 0) { + buff[read_bytes] = 0; + objdump.append(buff); + } + pclose(pipe); + } else { + is_correct = false; + } + // cut the objdump into functions + string fn, next_fn; + size_t next_start; + for (size_t start = fn_start(objdump, 0, &fn); + start != string::npos; + start = next_start, fn = next_fn) { + next_start = fn_start(objdump, start, &next_fn); + // fprintf(stderr, "start: %d next_start = %d fn: %s\n", + // (int)start, (int)next_start, fn.c_str()); + // Mac OS adds the "_" prefix to function names. + if (fn.find(APPLE ? "_Disasm" : "Disasm") == string::npos) { + continue; + } + string fn_body = objdump.substr(start, next_start - start); + // fprintf(stderr, "%s:\n%s", fn.c_str(), fn_body.c_str()); + functions_[fn] = fn_body; + } + } + + string &GetFuncDisasm(const string &fn) { + return functions_[fn]; + } + + int CountInsnInFunc(const string &fn, const vector &insns) { + // Mac OS adds the "_" prefix to function names. + string fn_ref = APPLE ? "_" + fn : fn; + const string &disasm = GetFuncDisasm(fn_ref); + if (disasm.empty()) return -1; + size_t counter = 0; + for (size_t i = 0; i < insns.size(); i++) { + size_t pos = 0; + while ((pos = disasm.find(insns[i], pos)) != string::npos) { + counter++; + pos++; + } + } + return counter; + } + + bool IsCorrect() { return is_correct; } + + private: + size_t fn_start(const string &objdump, size_t start_pos, string *fn) { + size_t pos = objdump.find(">:\n", start_pos); + if (pos == string::npos) + return string::npos; + size_t beg = pos; + while (beg > 0 && objdump[beg - 1] != '<') + beg--; + *fn = objdump.substr(beg, pos - beg); + return pos + 3; + } + + map functions_; + bool is_correct; +}; + +static ObjdumpOfMyself *objdump_of_myself() { + static ObjdumpOfMyself *o = new ObjdumpOfMyself(progname); + return o; +} + +const size_t kLargeMalloc = 1 << 24; + +template +__attribute__((noinline)) +void asan_write(T *a) { + *a = 0; +} + +__attribute__((noinline)) +void asan_write_sized_aligned(uint8_t *p, size_t size) { + EXPECT_EQ(0, ((uintptr_t)p % size)); + if (size == 1) asan_write((uint8_t*)p); + else if (size == 2) asan_write((uint16_t*)p); + else if (size == 4) asan_write((uint32_t*)p); + else if (size == 8) asan_write((uint64_t*)p); +} + +__attribute__((noinline)) void *malloc_fff(size_t size) { + void *res = malloc/**/(size); break_optimization(0); return res;} +__attribute__((noinline)) void *malloc_eee(size_t size) { + void *res = malloc_fff(size); break_optimization(0); return res;} +__attribute__((noinline)) void *malloc_ddd(size_t size) { + void *res = malloc_eee(size); break_optimization(0); return res;} +__attribute__((noinline)) void *malloc_ccc(size_t size) { + void *res = malloc_ddd(size); break_optimization(0); return res;} +__attribute__((noinline)) void *malloc_bbb(size_t size) { + void *res = malloc_ccc(size); break_optimization(0); return res;} +__attribute__((noinline)) void *malloc_aaa(size_t size) { + void *res = malloc_bbb(size); break_optimization(0); return res;} + +#ifndef __APPLE__ +__attribute__((noinline)) void *memalign_fff(size_t alignment, size_t size) { + void *res = memalign/**/(alignment, size); break_optimization(0); return res;} +__attribute__((noinline)) void *memalign_eee(size_t alignment, size_t size) { + void *res = memalign_fff(alignment, size); break_optimization(0); return res;} +__attribute__((noinline)) void *memalign_ddd(size_t alignment, size_t size) { + void *res = memalign_eee(alignment, size); break_optimization(0); return res;} +__attribute__((noinline)) void *memalign_ccc(size_t alignment, size_t size) { + void *res = memalign_ddd(alignment, size); break_optimization(0); return res;} +__attribute__((noinline)) void *memalign_bbb(size_t alignment, size_t size) { + void *res = memalign_ccc(alignment, size); break_optimization(0); return res;} +__attribute__((noinline)) void *memalign_aaa(size_t alignment, size_t size) { + void *res = memalign_bbb(alignment, size); break_optimization(0); return res;} +#endif // __APPLE__ + + +__attribute__((noinline)) + void free_ccc(void *p) { free(p); break_optimization(0);} +__attribute__((noinline)) + void free_bbb(void *p) { free_ccc(p); break_optimization(0);} +__attribute__((noinline)) + void free_aaa(void *p) { free_bbb(p); break_optimization(0);} + +template +__attribute__((noinline)) +void oob_test(int size, int off) { + char *p = (char*)malloc_aaa(size); + // fprintf(stderr, "writing %d byte(s) into [%p,%p) with offset %d\n", + // sizeof(T), p, p + size, off); + asan_write((T*)(p + off)); + free_aaa(p); +} + + +template +__attribute__((noinline)) +void uaf_test(int size, int off) { + char *p = (char *)malloc_aaa(size); + free_aaa(p); + for (int i = 1; i < 100; i++) + free_aaa(malloc_aaa(i)); + fprintf(stderr, "writing %ld byte(s) at %p with offset %d\n", + (long)sizeof(T), p, off); + asan_write((T*)(p + off)); +} + +TEST(AddressSanitizer, HasFeatureAddressSanitizerTest) { +#if defined(__has_feature) && __has_feature(address_sanitizer) + bool asan = 1; +#else + bool asan = 0; +#endif + EXPECT_EQ(true, asan); +} + +TEST(AddressSanitizer, SimpleDeathTest) { + EXPECT_DEATH(exit(1), ""); +} + +TEST(AddressSanitizer, VariousMallocsTest) { + // fprintf(stderr, "malloc:\n"); + int *a = (int*)malloc(100 * sizeof(int)); + a[50] = 0; + free(a); + + // fprintf(stderr, "realloc:\n"); + int *r = (int*)malloc(10); + r = (int*)realloc(r, 2000 * sizeof(int)); + r[1000] = 0; + free(r); + + // fprintf(stderr, "operator new []\n"); + int *b = new int[100]; + b[50] = 0; + delete [] b; + + // fprintf(stderr, "operator new\n"); + int *c = new int; + *c = 0; + delete c; + +#ifndef __APPLE__ + // fprintf(stderr, "posix_memalign\n"); + int *pm; + int pm_res = posix_memalign((void**)&pm, kPageSize, kPageSize); + EXPECT_EQ(0, pm_res); + free(pm); + + int *ma = (int*)memalign(kPageSize, kPageSize); + EXPECT_EQ(0, (uintptr_t)ma % kPageSize); + ma[123] = 0; + free(ma); +#endif // __APPLE__ +} + +TEST(AddressSanitizer, CallocTest) { + int *a = (int*)calloc(100, sizeof(int)); + EXPECT_EQ(0, a[10]); + free(a); +} + +TEST(AddressSanitizer, VallocTest) { + void *a = valloc(100); + EXPECT_EQ(0, (uintptr_t)a % kPageSize); + free(a); +} + +#ifndef __APPLE__ +TEST(AddressSanitizer, PvallocTest) { + char *a = (char*)pvalloc(kPageSize + 100); + EXPECT_EQ(0, (uintptr_t)a % kPageSize); + a[kPageSize + 101] = 1; // we should not report an error here. + free(a); + + a = (char*)pvalloc(0); // pvalloc(0) should allocate at least one page. + EXPECT_EQ(0, (uintptr_t)a % kPageSize); + a[101] = 1; // we should not report an error here. + free(a); +} +#endif // __APPLE__ + +void NoOpSignalHandler(int unused) { + fprintf(stderr, "NoOpSignalHandler (should not happen). Aborting\n"); + abort(); +} + +void NoOpSigaction(int, siginfo_t *siginfo, void *context) { + fprintf(stderr, "NoOpSigaction (should not happen). Aborting\n"); + abort(); +} + +TEST(AddressSanitizer, SignalTest) { + signal(SIGSEGV, NoOpSignalHandler); + signal(SIGILL, NoOpSignalHandler); + // If asan did not intercept sigaction NoOpSigaction will fire. + char *x = Ident((char*)malloc(5)); + EXPECT_DEATH(x[6]++, "is located 1 bytes to the right"); + free(Ident(x)); +} + +TEST(AddressSanitizer, SigactionTest) { + { + struct sigaction sigact; + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_sigaction = NoOpSigaction;; + sigact.sa_flags = SA_SIGINFO; + sigaction(SIGSEGV, &sigact, 0); + } + + { + struct sigaction sigact; + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_sigaction = NoOpSigaction;; + sigact.sa_flags = SA_SIGINFO; + sigaction(SIGILL, &sigact, 0); + } + + // If asan did not intercept sigaction NoOpSigaction will fire. + char *x = Ident((char*)malloc(5)); + EXPECT_DEATH(x[6]++, "is located 1 bytes to the right"); + free(Ident(x)); +} + +void *TSDWorker(void *test_key) { + if (test_key) { + pthread_setspecific(*(pthread_key_t*)test_key, (void*)0xfeedface); + } + return NULL; +} + +void TSDDestructor(void *tsd) { + // Spawning a thread will check that the current thread id is not -1. + pthread_t th; + pthread_create(&th, NULL, TSDWorker, NULL); + pthread_join(th, NULL); +} + +// This tests triggers the thread-specific data destruction fiasco which occurs +// if we don't manage the TSD destructors ourselves. We create a new pthread +// key with a non-NULL destructor which is likely to be put after the destructor +// of AsanThread in the list of destructors. +// In this case the TSD for AsanThread will be destroyed before TSDDestructor +// is called for the child thread, and a CHECK will fail when we call +// pthread_create() to spawn the grandchild. +TEST(AddressSanitizer, DISABLED_TSDTest) { + pthread_t th; + pthread_key_t test_key; + pthread_key_create(&test_key, TSDDestructor); + pthread_create(&th, NULL, TSDWorker, &test_key); + pthread_join(th, NULL); + pthread_key_delete(test_key); +} + +template +void OOBTest() { + char expected_str[100]; + for (int size = sizeof(T); size < 20; size += 5) { + for (int i = -5; i < 0; i++) { + const char *str = + "is located.*%d byte.*to the left"; + sprintf(expected_str, str, abs(i)); + EXPECT_DEATH(oob_test(size, i), expected_str); + } + + for (int i = 0; i < size - sizeof(T) + 1; i++) + oob_test(size, i); + + for (int i = size - sizeof(T) + 1; i <= size + 3 * sizeof(T); i++) { + const char *str = + "is located.*%d byte.*to the right"; + int off = i >= size ? (i - size) : 0; + // we don't catch unaligned partially OOB accesses. + if (i % sizeof(T)) continue; + sprintf(expected_str, str, off); + EXPECT_DEATH(oob_test(size, i), expected_str); + } + } + + EXPECT_DEATH(oob_test(kLargeMalloc, -1), + "is located.*1 byte.*to the left"); + EXPECT_DEATH(oob_test(kLargeMalloc, kLargeMalloc), + "is located.*0 byte.*to the right"); +} + +// TODO(glider): the following tests are EXTREMELY slow on Darwin: +// AddressSanitizer.OOB_char (125503 ms) +// AddressSanitizer.OOB_int (126890 ms) +// AddressSanitizer.OOBRightTest (315605 ms) +// AddressSanitizer.SimpleStackTest (366559 ms) + +TEST(AddressSanitizer, OOB_char) { + OOBTest(); +} + +TEST(AddressSanitizer, OOB_int) { + OOBTest(); +} + +TEST(AddressSanitizer, OOBRightTest) { + for (size_t access_size = 1; access_size <= 8; access_size *= 2) { + for (size_t alloc_size = 1; alloc_size <= 8; alloc_size++) { + for (size_t offset = 0; offset <= 8; offset += access_size) { + void *p = malloc(alloc_size); + // allocated: [p, p + alloc_size) + // accessed: [p + offset, p + offset + access_size) + uint8_t *addr = (uint8_t*)p + offset; + if (offset + access_size <= alloc_size) { + asan_write_sized_aligned(addr, access_size); + } else { + int outside_bytes = offset > alloc_size ? (offset - alloc_size) : 0; + const char *str = + "is located.%d *byte.*to the right"; + char expected_str[100]; + sprintf(expected_str, str, outside_bytes); + EXPECT_DEATH(asan_write_sized_aligned(addr, access_size), + expected_str); + } + free(p); + } + } + } +} + +TEST(AddressSanitizer, UAF_char) { + const char *uaf_string = "AddressSanitizer.*heap-use-after-free"; + EXPECT_DEATH(uaf_test(1, 0), uaf_string); + EXPECT_DEATH(uaf_test(10, 0), uaf_string); + EXPECT_DEATH(uaf_test(10, 10), uaf_string); + EXPECT_DEATH(uaf_test(kLargeMalloc, 0), uaf_string); + EXPECT_DEATH(uaf_test(kLargeMalloc, kLargeMalloc / 2), uaf_string); +} + +#if ASAN_HAS_BLACKLIST +TEST(AddressSanitizer, IgnoreTest) { + int *x = Ident(new int); + delete Ident(x); + *x = 0; +} +#endif // ASAN_HAS_BLACKLIST + +struct StructWithBitField { + int bf1:1; + int bf2:1; + int bf3:1; + int bf4:29; +}; + +TEST(AddressSanitizer, BitFieldPositiveTest) { + StructWithBitField *x = new StructWithBitField; + delete Ident(x); + EXPECT_DEATH(x->bf1 = 0, "use-after-free"); + EXPECT_DEATH(x->bf2 = 0, "use-after-free"); + EXPECT_DEATH(x->bf3 = 0, "use-after-free"); + EXPECT_DEATH(x->bf4 = 0, "use-after-free"); +}; + +struct StructWithBitFields_8_24 { + int a:8; + int b:24; +}; + +TEST(AddressSanitizer, BitFieldNegativeTest) { + StructWithBitFields_8_24 *x = Ident(new StructWithBitFields_8_24); + x->a = 0; + x->b = 0; + delete Ident(x); +} + +TEST(AddressSanitizer, OutOfMemoryTest) { + size_t size = __WORDSIZE == 64 ? (size_t)(1ULL << 48) : (0xf0000000); + EXPECT_EQ(0, realloc(0, size)); + EXPECT_EQ(0, realloc(0, ~Ident(0))); + EXPECT_EQ(0, malloc(size)); + EXPECT_EQ(0, malloc(~Ident(0))); + EXPECT_EQ(0, calloc(1, size)); + EXPECT_EQ(0, calloc(1, ~Ident(0))); +} + +#if ASAN_NEEDS_SEGV +TEST(AddressSanitizer, WildAddressTest) { + char *c = (char*)0x123; + EXPECT_DEATH(*c = 0, "AddressSanitizer crashed on unknown address"); +} +#endif + +static void MallocStress(size_t n) { + uint32_t seed = my_rand(&global_seed); + for (size_t iter = 0; iter < 10; iter++) { + vector vec; + for (size_t i = 0; i < n; i++) { + if ((i % 3) == 0) { + if (vec.empty()) continue; + size_t idx = my_rand(&seed) % vec.size(); + void *ptr = vec[idx]; + vec[idx] = vec.back(); + vec.pop_back(); + free_aaa(ptr); + } else { + size_t size = my_rand(&seed) % 1000 + 1; +#ifndef __APPLE__ + size_t alignment = 1 << (my_rand(&seed) % 7 + 3); + char *ptr = (char*)memalign_aaa(alignment, size); +#else + char *ptr = (char*) malloc_aaa(size); +#endif + vec.push_back(ptr); + ptr[0] = 0; + ptr[size-1] = 0; + ptr[size/2] = 0; + } + } + for (size_t i = 0; i < vec.size(); i++) + free_aaa(vec[i]); + } +} + +TEST(AddressSanitizer, MallocStressTest) { + MallocStress(200000); +} + +static void TestLargeMalloc(size_t size) { + char buff[1024]; + sprintf(buff, "is located 1 bytes to the left of %lu-byte", (long)size); + EXPECT_DEATH(Ident((char*)malloc(size))[-1] = 0, buff); +} + +TEST(AddressSanitizer, LargeMallocTest) { + for (int i = 113; i < (1 << 28); i = i * 2 + 13) { + TestLargeMalloc(i); + } +} + +TEST(AddressSanitizer, HugeMallocTest) { +#ifdef __APPLE__ + // It was empirically found out that 1215 megabytes is the maximum amount of + // memory available to the process under AddressSanitizer on Darwin. + // (the libSystem malloc() allows allocating up to 2300 megabytes without + // ASan). + size_t n_megs = __WORDSIZE == 32 ? 1200 : 4100; +#else + size_t n_megs = __WORDSIZE == 32 ? 2600 : 4100; +#endif + TestLargeMalloc(n_megs << 20); +} + +TEST(AddressSanitizer, ThreadedMallocStressTest) { + const int kNumThreads = 4; + pthread_t t[kNumThreads]; + for (int i = 0; i < kNumThreads; i++) { + pthread_create(&t[i], 0, (void* (*)(void *x))MallocStress, (void*)100000); + } + for (int i = 0; i < kNumThreads; i++) { + pthread_join(t[i], 0); + } +} + +void *ManyThreadsWorker(void *a) { + for (int iter = 0; iter < 100; iter++) { + for (size_t size = 100; size < 2000; size *= 2) { + free(Ident(malloc(size))); + } + } + return 0; +} + +TEST(AddressSanitizer, ManyThreadsTest) { + const size_t kNumThreads = __WORDSIZE == 32 ? 30 : 1000; + pthread_t t[kNumThreads]; + for (size_t i = 0; i < kNumThreads; i++) { + pthread_create(&t[i], 0, (void* (*)(void *x))ManyThreadsWorker, (void*)i); + } + for (size_t i = 0; i < kNumThreads; i++) { + pthread_join(t[i], 0); + } +} + +TEST(AddressSanitizer, ReallocTest) { + const int kMinElem = 5; + int *ptr = (int*)malloc(sizeof(int) * kMinElem); + ptr[3] = 3; + for (int i = 0; i < 10000; i++) { + ptr = (int*)realloc(ptr, + (my_rand(&global_seed) % 1000 + kMinElem) * sizeof(int)); + EXPECT_EQ(3, ptr[3]); + } +} + +void WrongFree() { + int *x = (int*)malloc(100 * sizeof(int)); + // Use the allocated memory, otherwise Clang will optimize it out. + Ident(x); + free(x + 1); +} + +TEST(AddressSanitizer, WrongFreeTest) { + EXPECT_DEATH(WrongFree(), + "ERROR: AddressSanitizer attempting free.*not malloc"); +} + +void DoubleFree() { + int *x = (int*)malloc(100 * sizeof(int)); + fprintf(stderr, "DoubleFree: x=%p\n", x); + free(x); + free(x); + fprintf(stderr, "should have failed in the second free(%p)\n", x); + abort(); +} + +TEST(AddressSanitizer, DoubleFreeTest) { + EXPECT_DEATH(DoubleFree(), "ERROR: AddressSanitizer attempting double-free"); +} + +template +__attribute__((noinline)) +void SizedStackTest() { + char a[kSize]; + char *A = Ident((char*)&a); + for (size_t i = 0; i < kSize; i++) + A[i] = i; + EXPECT_DEATH(A[-1] = 0, ""); + EXPECT_DEATH(A[-20] = 0, ""); + EXPECT_DEATH(A[-31] = 0, ""); + EXPECT_DEATH(A[kSize] = 0, ""); + EXPECT_DEATH(A[kSize + 1] = 0, ""); + EXPECT_DEATH(A[kSize + 10] = 0, ""); + EXPECT_DEATH(A[kSize + 31] = 0, ""); +} + +TEST(AddressSanitizer, SimpleStackTest) { + SizedStackTest<1>(); + SizedStackTest<2>(); + SizedStackTest<3>(); + SizedStackTest<4>(); + SizedStackTest<5>(); + SizedStackTest<6>(); + SizedStackTest<7>(); + SizedStackTest<16>(); + SizedStackTest<25>(); + SizedStackTest<34>(); + SizedStackTest<43>(); + SizedStackTest<51>(); + SizedStackTest<62>(); + SizedStackTest<64>(); + SizedStackTest<128>(); +} + +TEST(AddressSanitizer, ManyStackObjectsTest) { + char XXX[10]; + char YYY[20]; + char ZZZ[30]; + Ident(XXX); + Ident(YYY); + EXPECT_DEATH(Ident(ZZZ)[-1] = 0, ASAN_PCRE_DOTALL "XXX.*YYY.*ZZZ"); +} + +__attribute__((noinline)) +static void Frame0(int frame, char *a, char *b, char *c) { + char d[4] = {0}; + char *D = Ident(d); + switch (frame) { + case 3: a[5]++; break; + case 2: b[5]++; break; + case 1: c[5]++; break; + case 0: D[5]++; break; + } +} +__attribute__((noinline)) static void Frame1(int frame, char *a, char *b) { + char c[4] = {0}; Frame0(frame, a, b, c); + break_optimization(0); +} +__attribute__((noinline)) static void Frame2(int frame, char *a) { + char b[4] = {0}; Frame1(frame, a, b); + break_optimization(0); +} +__attribute__((noinline)) static void Frame3(int frame) { + char a[4] = {0}; Frame2(frame, a); + break_optimization(0); +} + +TEST(AddressSanitizer, GuiltyStackFrame0Test) { + EXPECT_DEATH(Frame3(0), "located .*in frame <.*Frame0"); +} +TEST(AddressSanitizer, GuiltyStackFrame1Test) { + EXPECT_DEATH(Frame3(1), "located .*in frame <.*Frame1"); +} +TEST(AddressSanitizer, GuiltyStackFrame2Test) { + EXPECT_DEATH(Frame3(2), "located .*in frame <.*Frame2"); +} +TEST(AddressSanitizer, GuiltyStackFrame3Test) { + EXPECT_DEATH(Frame3(3), "located .*in frame <.*Frame3"); +} + +__attribute__((noinline)) +void LongJmpFunc1(jmp_buf buf) { + // create three red zones for these two stack objects. + int a; + int b; + + int *A = Ident(&a); + int *B = Ident(&b); + *A = *B; + longjmp(buf, 1); +} + +__attribute__((noinline)) +void UnderscopeLongJmpFunc1(jmp_buf buf) { + // create three red zones for these two stack objects. + int a; + int b; + + int *A = Ident(&a); + int *B = Ident(&b); + *A = *B; + _longjmp(buf, 1); +} + +__attribute__((noinline)) +void SigLongJmpFunc1(sigjmp_buf buf) { + // create three red zones for these two stack objects. + int a; + int b; + + int *A = Ident(&a); + int *B = Ident(&b); + *A = *B; + siglongjmp(buf, 1); +} + + +__attribute__((noinline)) +void TouchStackFunc() { + int a[100]; // long array will intersect with redzones from LongJmpFunc1. + int *A = Ident(a); + for (int i = 0; i < 100; i++) + A[i] = i*i; +} + +// Test that we handle longjmp and do not report fals positives on stack. +TEST(AddressSanitizer, LongJmpTest) { + static jmp_buf buf; + if (!setjmp(buf)) { + LongJmpFunc1(buf); + } else { + TouchStackFunc(); + } +} + +TEST(AddressSanitizer, UnderscopeLongJmpTest) { + static jmp_buf buf; + if (!_setjmp(buf)) { + UnderscopeLongJmpFunc1(buf); + } else { + TouchStackFunc(); + } +} + +TEST(AddressSanitizer, SigLongJmpTest) { + static sigjmp_buf buf; + if (!sigsetjmp(buf, 1)) { + SigLongJmpFunc1(buf); + } else { + TouchStackFunc(); + } +} + +#ifdef __EXCEPTIONS +__attribute__((noinline)) +void ThrowFunc() { + // create three red zones for these two stack objects. + int a; + int b; + + int *A = Ident(&a); + int *B = Ident(&b); + *A = *B; + ASAN_THROW(1); +} + +TEST(AddressSanitizer, CxxExceptionTest) { + if (ASAN_UAR) return; + // TODO(kcc): this test crashes on 32-bit for some reason... + if (__WORDSIZE == 32) return; + try { + ThrowFunc(); + } catch(...) {} + TouchStackFunc(); +} +#endif + +void *ThreadStackReuseFunc1(void *unused) { + // create three red zones for these two stack objects. + int a; + int b; + + int *A = Ident(&a); + int *B = Ident(&b); + *A = *B; + pthread_exit(0); + return 0; +} + +void *ThreadStackReuseFunc2(void *unused) { + TouchStackFunc(); + return 0; +} + +TEST(AddressSanitizer, ThreadStackReuseTest) { + pthread_t t; + pthread_create(&t, 0, ThreadStackReuseFunc1, 0); + pthread_join(t, 0); + pthread_create(&t, 0, ThreadStackReuseFunc2, 0); + pthread_join(t, 0); +} + +#if defined(__i386__) or defined(__x86_64__) +TEST(AddressSanitizer, Store128Test) { + char *a = Ident((char*)malloc(Ident(12))); + char *p = a; + if (((uintptr_t)a % 16) != 0) + p = a + 8; + assert(((uintptr_t)p % 16) == 0); + __m128i value_wide = _mm_set1_epi16(0x1234); + EXPECT_DEATH(_mm_store_si128((__m128i*)p, value_wide), + "AddressSanitizer heap-buffer-overflow"); + EXPECT_DEATH(_mm_store_si128((__m128i*)p, value_wide), + "WRITE of size 16"); + EXPECT_DEATH(_mm_store_si128((__m128i*)p, value_wide), + "located 0 bytes to the right of 12-byte"); + free(a); +} +#endif + +static string RightOOBErrorMessage(int oob_distance) { + assert(oob_distance >= 0); + char expected_str[100]; + sprintf(expected_str, "located %d bytes to the right", oob_distance); + return string(expected_str); +} + +static string LeftOOBErrorMessage(int oob_distance) { + assert(oob_distance > 0); + char expected_str[100]; + sprintf(expected_str, "located %d bytes to the left", oob_distance); + return string(expected_str); +} + +template +void MemSetOOBTestTemplate(size_t length) { + if (length == 0) return; + size_t size = Ident(sizeof(T) * length); + T *array = Ident((T*)malloc(size)); + int element = Ident(42); + int zero = Ident(0); + // memset interval inside array + memset(array, element, size); + memset(array, element, size - 1); + memset(array + length - 1, element, sizeof(T)); + memset(array, element, 1); + + // memset 0 bytes + memset(array - 10, element, zero); + memset(array - 1, element, zero); + memset(array, element, zero); + memset(array + length, 0, zero); + memset(array + length + 1, 0, zero); + + // try to memset bytes to the right of array + EXPECT_DEATH(memset(array, 0, size + 1), + RightOOBErrorMessage(0)); + EXPECT_DEATH(memset((char*)(array + length) - 1, element, 6), + RightOOBErrorMessage(4)); + EXPECT_DEATH(memset(array + 1, element, size + sizeof(T)), + RightOOBErrorMessage(2 * sizeof(T) - 1)); + // whole interval is to the right + EXPECT_DEATH(memset(array + length + 1, 0, 10), + RightOOBErrorMessage(sizeof(T))); + + // try to memset bytes to the left of array + EXPECT_DEATH(memset((char*)array - 1, element, size), + LeftOOBErrorMessage(1)); + EXPECT_DEATH(memset((char*)array - 5, 0, 6), + LeftOOBErrorMessage(5)); + EXPECT_DEATH(memset(array - 5, element, size + 5 * sizeof(T)), + LeftOOBErrorMessage(5 * sizeof(T))); + // whole interval is to the left + EXPECT_DEATH(memset(array - 2, 0, sizeof(T)), + LeftOOBErrorMessage(2 * sizeof(T))); + + // try to memset bytes both to the left & to the right + EXPECT_DEATH(memset((char*)array - 2, element, size + 4), + LeftOOBErrorMessage(2)); + + free(array); +} + +TEST(AddressSanitizer, MemSetOOBTest) { + MemSetOOBTestTemplate(100); + MemSetOOBTestTemplate(5); + MemSetOOBTestTemplate(256); + // We can test arrays of structres/classes here, but what for? +} + +// Same test for memcpy and memmove functions +template +void MemTransferOOBTestTemplate(size_t length) { + if (length == 0) return; + size_t size = Ident(sizeof(T) * length); + T *src = Ident((T*)malloc(size)); + T *dest = Ident((T*)malloc(size)); + int zero = Ident(0); + + // valid transfer of bytes between arrays + M::transfer(dest, src, size); + M::transfer(dest + 1, src, size - sizeof(T)); + M::transfer(dest, src + length - 1, sizeof(T)); + M::transfer(dest, src, 1); + + // transfer zero bytes + M::transfer(dest - 1, src, 0); + M::transfer(dest + length, src, zero); + M::transfer(dest, src - 1, zero); + M::transfer(dest, src, zero); + + // try to change mem to the right of dest + EXPECT_DEATH(M::transfer(dest + 1, src, size), + RightOOBErrorMessage(sizeof(T) - 1)); + EXPECT_DEATH(M::transfer((char*)(dest + length) - 1, src, 5), + RightOOBErrorMessage(3)); + + // try to change mem to the left of dest + EXPECT_DEATH(M::transfer(dest - 2, src, size), + LeftOOBErrorMessage(2 * sizeof(T))); + EXPECT_DEATH(M::transfer((char*)dest - 3, src, 4), + LeftOOBErrorMessage(3)); + + // try to access mem to the right of src + EXPECT_DEATH(M::transfer(dest, src + 2, size), + RightOOBErrorMessage(2 * sizeof(T) - 1)); + EXPECT_DEATH(M::transfer(dest, (char*)(src + length) - 3, 6), + RightOOBErrorMessage(2)); + + // try to access mem to the left of src + EXPECT_DEATH(M::transfer(dest, src - 1, size), + LeftOOBErrorMessage(sizeof(T))); + EXPECT_DEATH(M::transfer(dest, (char*)src - 6, 7), + LeftOOBErrorMessage(6)); + + // Generally we don't need to test cases where both accessing src and writing + // to dest address to poisoned memory. + + T *big_src = Ident((T*)malloc(size * 2)); + T *big_dest = Ident((T*)malloc(size * 2)); + // try to change mem to both sides of dest + EXPECT_DEATH(M::transfer(dest - 1, big_src, size * 2), + LeftOOBErrorMessage(sizeof(T))); + // try to access mem to both sides of src + EXPECT_DEATH(M::transfer(big_dest, src - 2, size * 2), + LeftOOBErrorMessage(2 * sizeof(T))); + + free(src); + free(dest); + free(big_src); + free(big_dest); +} + +class MemCpyWrapper { + public: + static void* transfer(void *to, const void *from, size_t size) { + return memcpy(to, from, size); + } +}; +TEST(AddressSanitizer, MemCpyOOBTest) { + MemTransferOOBTestTemplate(100); + MemTransferOOBTestTemplate(1024); +} + +class MemMoveWrapper { + public: + static void* transfer(void *to, const void *from, size_t size) { + return memmove(to, from, size); + } +}; +TEST(AddressSanitizer, MemMoveOOBTest) { + MemTransferOOBTestTemplate(100); + MemTransferOOBTestTemplate(1024); +} + +// Tests for string functions + +// Used for string functions tests +static char global_string[] = "global"; +static size_t global_string_length = 6; + +// Input to a test is a zero-terminated string str with given length +// Accesses to the bytes to the left and to the right of str +// are presumed to produce OOB errors +void StrLenOOBTestTemplate(char *str, size_t length, bool is_global) { + // Normal strlen calls + EXPECT_EQ(strlen(str), length); + if (length > 0) { + EXPECT_EQ(strlen(str + 1), length - 1); + EXPECT_EQ(strlen(str + length), 0); + } + // Arg of strlen is not malloced, OOB access + if (!is_global) { + // We don't insert RedZones to the left of global variables + EXPECT_DEATH(Ident(strlen(str - 1)), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(strlen(str - 5)), LeftOOBErrorMessage(5)); + } + EXPECT_DEATH(Ident(strlen(str + length + 1)), RightOOBErrorMessage(0)); + // Overwrite terminator + str[length] = 'a'; + // String is not zero-terminated, strlen will lead to OOB access + EXPECT_DEATH(Ident(strlen(str)), RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(strlen(str + length)), RightOOBErrorMessage(0)); + // Restore terminator + str[length] = 0; +} +TEST(AddressSanitizer, StrLenOOBTest) { + // Check heap-allocated string + size_t length = Ident(10); + char *heap_string = Ident((char*)malloc(length + 1)); + char stack_string[10 + 1]; + for (int i = 0; i < length; i++) { + heap_string[i] = 'a'; + stack_string[i] = 'b'; + } + heap_string[length] = 0; + stack_string[length] = 0; + StrLenOOBTestTemplate(heap_string, length, false); + // TODO(samsonov): Fix expected messages in StrLenOOBTestTemplate to + // make test for stack_string work. Or move it to output tests. + // StrLenOOBTestTemplate(stack_string, length, false); + StrLenOOBTestTemplate(global_string, global_string_length, true); + free(heap_string); +} + +static inline char* MallocAndMemsetString(size_t size) { + char *s = Ident((char*)malloc(size)); + memset(s, 'z', size); + return s; +} + +#ifndef __APPLE__ +TEST(AddressSanitizer, StrNLenOOBTest) { + size_t size = Ident(123); + char *str = MallocAndMemsetString(size); + // Normal strnlen calls. + Ident(strnlen(str - 1, 0)); + Ident(strnlen(str, size)); + Ident(strnlen(str + size - 1, 1)); + str[size - 1] = '\0'; + Ident(strnlen(str, 2 * size)); + // Argument points to not allocated memory. + EXPECT_DEATH(Ident(strnlen(str - 1, 1)), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(strnlen(str + size, 1)), RightOOBErrorMessage(0)); + // Overwrite the terminating '\0' and hit unallocated memory. + str[size - 1] = 'z'; + EXPECT_DEATH(Ident(strnlen(str, size + 1)), RightOOBErrorMessage(0)); + free(str); +} +#endif + +TEST(AddressSanitizer, StrDupOOBTest) { + size_t size = Ident(42); + char *str = MallocAndMemsetString(size); + char *new_str; + // Normal strdup calls. + str[size - 1] = '\0'; + new_str = strdup(str); + free(new_str); + new_str = strdup(str + size - 1); + free(new_str); + // Argument points to not allocated memory. + EXPECT_DEATH(Ident(strdup(str - 1)), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(strdup(str + size)), RightOOBErrorMessage(0)); + // Overwrite the terminating '\0' and hit unallocated memory. + str[size - 1] = 'z'; + EXPECT_DEATH(Ident(strdup(str)), RightOOBErrorMessage(0)); + free(str); +} + +TEST(AddressSanitizer, StrCpyOOBTest) { + size_t to_size = Ident(30); + size_t from_size = Ident(6); // less than to_size + char *to = Ident((char*)malloc(to_size)); + char *from = Ident((char*)malloc(from_size)); + // Normal strcpy calls. + strcpy(from, "hello"); + strcpy(to, from); + strcpy(to + to_size - from_size, from); + // Length of "from" is too small. + EXPECT_DEATH(Ident(strcpy(from, "hello2")), RightOOBErrorMessage(0)); + // "to" or "from" points to not allocated memory. + EXPECT_DEATH(Ident(strcpy(to - 1, from)), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(strcpy(to, from - 1)), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(strcpy(to, from + from_size)), RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(strcpy(to + to_size, from)), RightOOBErrorMessage(0)); + // Overwrite the terminating '\0' character and hit unallocated memory. + from[from_size - 1] = '!'; + EXPECT_DEATH(Ident(strcpy(to, from)), RightOOBErrorMessage(0)); + free(to); + free(from); +} + +TEST(AddressSanitizer, StrNCpyOOBTest) { + size_t to_size = Ident(20); + size_t from_size = Ident(6); // less than to_size + char *to = Ident((char*)malloc(to_size)); + // From is a zero-terminated string "hello\0" of length 6 + char *from = Ident((char*)malloc(from_size)); + strcpy(from, "hello"); + // copy 0 bytes + strncpy(to, from, 0); + strncpy(to - 1, from - 1, 0); + // normal strncpy calls + strncpy(to, from, from_size); + strncpy(to, from, to_size); + strncpy(to, from + from_size - 1, to_size); + strncpy(to + to_size - 1, from, 1); + // One of {to, from} points to not allocated memory + EXPECT_DEATH(Ident(strncpy(to, from - 1, from_size)), + LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(strncpy(to - 1, from, from_size)), + LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(strncpy(to, from + from_size, 1)), + RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(strncpy(to + to_size, from, 1)), + RightOOBErrorMessage(0)); + // Length of "to" is too small + EXPECT_DEATH(Ident(strncpy(to + to_size - from_size + 1, from, from_size)), + RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(strncpy(to + 1, from, to_size)), + RightOOBErrorMessage(0)); + // Overwrite terminator in from + from[from_size - 1] = '!'; + // normal strncpy call + strncpy(to, from, from_size); + // Length of "from" is too small + EXPECT_DEATH(Ident(strncpy(to, from, to_size)), + RightOOBErrorMessage(0)); + free(to); + free(from); +} + +typedef char*(*PointerToStrChr)(const char*, int); +void RunStrChrTest(PointerToStrChr StrChr) { + size_t size = Ident(100); + char *str = MallocAndMemsetString(size); + str[10] = 'q'; + str[11] = '\0'; + EXPECT_EQ(str, StrChr(str, 'z')); + EXPECT_EQ(str + 10, StrChr(str, 'q')); + EXPECT_EQ(NULL, StrChr(str, 'a')); + // StrChr argument points to not allocated memory. + EXPECT_DEATH(Ident(StrChr(str - 1, 'z')), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(StrChr(str + size, 'z')), RightOOBErrorMessage(0)); + // Overwrite the terminator and hit not allocated memory. + str[11] = 'z'; + EXPECT_DEATH(Ident(StrChr(str, 'a')), RightOOBErrorMessage(0)); + free(str); +} +TEST(AddressSanitizer, StrChrAndIndexOOBTest) { + RunStrChrTest(&strchr); + RunStrChrTest(&index); +} + +TEST(AddressSanitizer, StrCmpAndFriendsLogicTest) { + // strcmp + EXPECT_EQ(0, strcmp("", "")); + EXPECT_EQ(0, strcmp("abcd", "abcd")); + EXPECT_GT(0, strcmp("ab", "ac")); + EXPECT_GT(0, strcmp("abc", "abcd")); + EXPECT_LT(0, strcmp("acc", "abc")); + EXPECT_LT(0, strcmp("abcd", "abc")); + + // strncmp + EXPECT_EQ(0, strncmp("a", "b", 0)); + EXPECT_EQ(0, strncmp("abcd", "abcd", 10)); + EXPECT_EQ(0, strncmp("abcd", "abcef", 3)); + EXPECT_GT(0, strncmp("abcde", "abcfa", 4)); + EXPECT_GT(0, strncmp("a", "b", 5)); + EXPECT_GT(0, strncmp("bc", "bcde", 4)); + EXPECT_LT(0, strncmp("xyz", "xyy", 10)); + EXPECT_LT(0, strncmp("baa", "aaa", 1)); + EXPECT_LT(0, strncmp("zyx", "", 2)); + + // strcasecmp + EXPECT_EQ(0, strcasecmp("", "")); + EXPECT_EQ(0, strcasecmp("zzz", "zzz")); + EXPECT_EQ(0, strcasecmp("abCD", "ABcd")); + EXPECT_GT(0, strcasecmp("aB", "Ac")); + EXPECT_GT(0, strcasecmp("ABC", "ABCd")); + EXPECT_LT(0, strcasecmp("acc", "abc")); + EXPECT_LT(0, strcasecmp("ABCd", "abc")); + + // strncasecmp + EXPECT_EQ(0, strncasecmp("a", "b", 0)); + EXPECT_EQ(0, strncasecmp("abCD", "ABcd", 10)); + EXPECT_EQ(0, strncasecmp("abCd", "ABcef", 3)); + EXPECT_GT(0, strncasecmp("abcde", "ABCfa", 4)); + EXPECT_GT(0, strncasecmp("a", "B", 5)); + EXPECT_GT(0, strncasecmp("bc", "BCde", 4)); + EXPECT_LT(0, strncasecmp("xyz", "xyy", 10)); + EXPECT_LT(0, strncasecmp("Baa", "aaa", 1)); + EXPECT_LT(0, strncasecmp("zyx", "", 2)); + + // memcmp + EXPECT_EQ(0, memcmp("a", "b", 0)); + EXPECT_EQ(0, memcmp("ab\0c", "ab\0c", 4)); + EXPECT_GT(0, memcmp("\0ab", "\0ac", 3)); + EXPECT_GT(0, memcmp("abb\0", "abba", 4)); + EXPECT_LT(0, memcmp("ab\0cd", "ab\0c\0", 5)); + EXPECT_LT(0, memcmp("zza", "zyx", 3)); +} + +typedef int(*PointerToStrCmp)(const char*, const char*); +void RunStrCmpTest(PointerToStrCmp StrCmp) { + size_t size = Ident(100); + char *s1 = MallocAndMemsetString(size); + char *s2 = MallocAndMemsetString(size); + s1[size - 1] = '\0'; + s2[size - 1] = '\0'; + // Normal StrCmp calls + Ident(StrCmp(s1, s2)); + Ident(StrCmp(s1, s2 + size - 1)); + Ident(StrCmp(s1 + size - 1, s2 + size - 1)); + s1[size - 1] = 'z'; + s2[size - 1] = 'x'; + Ident(StrCmp(s1, s2)); + // One of arguments points to not allocated memory. + EXPECT_DEATH(Ident(StrCmp)(s1 - 1, s2), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(StrCmp)(s1, s2 - 1), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(StrCmp)(s1 + size, s2), RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(StrCmp)(s1, s2 + size), RightOOBErrorMessage(0)); + // Hit unallocated memory and die. + s2[size - 1] = 'z'; + EXPECT_DEATH(Ident(StrCmp)(s1, s1), RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(StrCmp)(s1 + size - 1, s2), RightOOBErrorMessage(0)); + free(s1); + free(s2); +} + +TEST(AddressSanitizer, StrCmpOOBTest) { + RunStrCmpTest(&strcmp); +} + +TEST(AddressSanitizer, StrCaseCmpOOBTest) { + RunStrCmpTest(&strcasecmp); +} + +typedef int(*PointerToStrNCmp)(const char*, const char*, size_t); +void RunStrNCmpTest(PointerToStrNCmp StrNCmp) { + size_t size = Ident(100); + char *s1 = MallocAndMemsetString(size); + char *s2 = MallocAndMemsetString(size); + s1[size - 1] = '\0'; + s2[size - 1] = '\0'; + // Normal StrNCmp calls + Ident(StrNCmp(s1, s2, size + 2)); + s1[size - 1] = 'z'; + s2[size - 1] = 'x'; + Ident(StrNCmp(s1 + size - 2, s2 + size - 2, size)); + s2[size - 1] = 'z'; + Ident(StrNCmp(s1 - 1, s2 - 1, 0)); + Ident(StrNCmp(s1 + size - 1, s2 + size - 1, 1)); + // One of arguments points to not allocated memory. + EXPECT_DEATH(Ident(StrNCmp)(s1 - 1, s2, 1), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(StrNCmp)(s1, s2 - 1, 1), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(StrNCmp)(s1 + size, s2, 1), RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(StrNCmp)(s1, s2 + size, 1), RightOOBErrorMessage(0)); + // Hit unallocated memory and die. + EXPECT_DEATH(Ident(StrNCmp)(s1 + 1, s2 + 1, size), RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(StrNCmp)(s1 + size - 1, s2, 2), RightOOBErrorMessage(0)); + free(s1); + free(s2); +} + +TEST(AddressSanitizer, StrNCmpOOBTest) { + RunStrNCmpTest(&strncmp); +} + +TEST(AddressSanitizer, StrNCaseCmpOOBTest) { + RunStrNCmpTest(&strncasecmp); +} + +TEST(AddressSanitizer, MemCmpOOBTest) { + size_t size = Ident(100); + char *s1 = MallocAndMemsetString(size); + char *s2 = MallocAndMemsetString(size); + // Normal memcmp calls. + Ident(memcmp(s1, s2, size)); + Ident(memcmp(s1 + size - 1, s2 + size - 1, 1)); + Ident(memcmp(s1 - 1, s2 - 1, 0)); + // One of arguments points to not allocated memory. + EXPECT_DEATH(Ident(memcmp)(s1 - 1, s2, 1), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(memcmp)(s1, s2 - 1, 1), LeftOOBErrorMessage(1)); + EXPECT_DEATH(Ident(memcmp)(s1 + size, s2, 1), RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(memcmp)(s1, s2 + size, 1), RightOOBErrorMessage(0)); + // Hit unallocated memory and die. + EXPECT_DEATH(Ident(memcmp)(s1 + 1, s2 + 1, size), RightOOBErrorMessage(0)); + EXPECT_DEATH(Ident(memcmp)(s1 + size - 1, s2, 2), RightOOBErrorMessage(0)); + // Zero bytes are not terminators and don't prevent from OOB. + s1[size - 1] = '\0'; + s2[size - 1] = '\0'; + EXPECT_DEATH(Ident(memcmp)(s1, s2, size + 1), RightOOBErrorMessage(0)); + free(s1); + free(s2); +} + +TEST(AddressSanitizer, StrCatOOBTest) { + size_t to_size = Ident(100); + char *to = MallocAndMemsetString(to_size); + to[0] = '\0'; + size_t from_size = Ident(20); + char *from = MallocAndMemsetString(from_size); + from[from_size - 1] = '\0'; + // Normal strcat calls. + strcat(to, from); + strcat(to, from); + strcat(to + from_size, from + from_size - 2); + // Catenate empty string is not always an error. + strcat(to - 1, from + from_size - 1); + // One of arguments points to not allocated memory. + EXPECT_DEATH(strcat(to - 1, from), LeftOOBErrorMessage(1)); + EXPECT_DEATH(strcat(to, from - 1), LeftOOBErrorMessage(1)); + EXPECT_DEATH(strcat(to + to_size, from), RightOOBErrorMessage(0)); + EXPECT_DEATH(strcat(to, from + from_size), RightOOBErrorMessage(0)); + + // "from" is not zero-terminated. + from[from_size - 1] = 'z'; + EXPECT_DEATH(strcat(to, from), RightOOBErrorMessage(0)); + from[from_size - 1] = '\0'; + // "to" is not zero-terminated. + memset(to, 'z', to_size); + EXPECT_DEATH(strcat(to, from), RightOOBErrorMessage(0)); + // "to" is too short to fit "from". + to[to_size - from_size + 1] = '\0'; + EXPECT_DEATH(strcat(to, from), RightOOBErrorMessage(0)); + // length of "to" is just enough. + strcat(to, from + 1); +} + +static string OverlapErrorMessage(const string &func) { + return func + "-param-overlap"; +} + +TEST(AddressSanitizer, StrArgsOverlapTest) { + size_t size = Ident(100); + char *str = Ident((char*)malloc(size)); + + // Check "memcpy". Use Ident() to avoid inlining. + memset(str, 'z', size); + Ident(memcpy)(str + 1, str + 11, 10); + Ident(memcpy)(str, str, 0); + EXPECT_DEATH(Ident(memcpy)(str, str + 14, 15), OverlapErrorMessage("memcpy")); + EXPECT_DEATH(Ident(memcpy)(str + 14, str, 15), OverlapErrorMessage("memcpy")); + EXPECT_DEATH(Ident(memcpy)(str + 20, str + 20, 1), + OverlapErrorMessage("memcpy")); + + // Check "strcpy". + memset(str, 'z', size); + str[9] = '\0'; + strcpy(str + 10, str); + EXPECT_DEATH(strcpy(str + 9, str), OverlapErrorMessage("strcpy")); + EXPECT_DEATH(strcpy(str, str + 4), OverlapErrorMessage("strcpy")); + strcpy(str, str + 5); + + // Check "strncpy". + memset(str, 'z', size); + strncpy(str, str + 10, 10); + EXPECT_DEATH(strncpy(str, str + 9, 10), OverlapErrorMessage("strncpy")); + EXPECT_DEATH(strncpy(str + 9, str, 10), OverlapErrorMessage("strncpy")); + str[10] = '\0'; + strncpy(str + 11, str, 20); + EXPECT_DEATH(strncpy(str + 10, str, 20), OverlapErrorMessage("strncpy")); + + // Check "strcat". + memset(str, 'z', size); + str[10] = '\0'; + str[20] = '\0'; + strcat(str, str + 10); + strcat(str, str + 11); + str[10] = '\0'; + strcat(str + 11, str); + EXPECT_DEATH(strcat(str, str + 9), OverlapErrorMessage("strcat")); + EXPECT_DEATH(strcat(str + 9, str), OverlapErrorMessage("strcat")); + EXPECT_DEATH(strcat(str + 10, str), OverlapErrorMessage("strcat")); + + free(str); +} + +// At the moment we instrument memcpy/memove/memset calls at compile time so we +// can't handle OOB error if these functions are called by pointer, see disabled +// MemIntrinsicCallByPointerTest below +typedef void*(*PointerToMemTransfer)(void*, const void*, size_t); +typedef void*(*PointerToMemSet)(void*, int, size_t); + +void CallMemSetByPointer(PointerToMemSet MemSet) { + size_t size = Ident(100); + char *array = Ident((char*)malloc(size)); + EXPECT_DEATH(MemSet(array, 0, 101), RightOOBErrorMessage(0)); + free(array); +} + +void CallMemTransferByPointer(PointerToMemTransfer MemTransfer) { + size_t size = Ident(100); + char *src = Ident((char*)malloc(size)); + char *dst = Ident((char*)malloc(size)); + EXPECT_DEATH(MemTransfer(dst, src, 101), RightOOBErrorMessage(0)); + free(src); + free(dst); +} + +TEST(AddressSanitizer, DISABLED_MemIntrinsicCallByPointerTest) { + CallMemSetByPointer(&memset); + CallMemTransferByPointer(&memcpy); + CallMemTransferByPointer(&memmove); +} + +// This test case fails +// Clang optimizes memcpy/memset calls which lead to unaligned access +TEST(AddressSanitizer, DISABLED_MemIntrinsicUnalignedAccessTest) { + int size = Ident(4096); + char *s = Ident((char*)malloc(size)); + EXPECT_DEATH(memset(s + size - 1, 0, 2), RightOOBErrorMessage(0)); + free(s); +} + +// TODO(samsonov): Add a test with malloc(0) +// TODO(samsonov): Add tests for str* and mem* functions. + +__attribute__((noinline)) +static int LargeFunction(bool do_bad_access) { + int *x = new int[100]; + x[0]++; + x[1]++; + x[2]++; + x[3]++; + x[4]++; + x[5]++; + x[6]++; + x[7]++; + x[8]++; + x[9]++; + + x[do_bad_access ? 100 : 0]++; int res = __LINE__; + + x[10]++; + x[11]++; + x[12]++; + x[13]++; + x[14]++; + x[15]++; + x[16]++; + x[17]++; + x[18]++; + x[19]++; + + delete x; + return res; +} + +// Test the we have correct debug info for the failing instruction. +// This test requires the in-process symbolizer to be enabled by default. +TEST(AddressSanitizer, DISABLED_LargeFunctionSymbolizeTest) { + int failing_line = LargeFunction(false); + char expected_warning[128]; + sprintf(expected_warning, "LargeFunction.*asan_test.cc:%d", failing_line); + EXPECT_DEATH(LargeFunction(true), expected_warning); +} + +// Check that we unwind and symbolize correctly. +TEST(AddressSanitizer, DISABLED_MallocFreeUnwindAndSymbolizeTest) { + int *a = (int*)malloc_aaa(sizeof(int)); + *a = 1; + free_aaa(a); + EXPECT_DEATH(*a = 1, "free_ccc.*free_bbb.*free_aaa.*" + "malloc_fff.*malloc_eee.*malloc_ddd"); +} + +void *ThreadedTestAlloc(void *a) { + int **p = (int**)a; + *p = new int; + return 0; +} + +void *ThreadedTestFree(void *a) { + int **p = (int**)a; + delete *p; + return 0; +} + +void *ThreadedTestUse(void *a) { + int **p = (int**)a; + **p = 1; + return 0; +} + +void ThreadedTestSpawn() { + pthread_t t; + int *x; + pthread_create(&t, 0, ThreadedTestAlloc, &x); + pthread_join(t, 0); + pthread_create(&t, 0, ThreadedTestFree, &x); + pthread_join(t, 0); + pthread_create(&t, 0, ThreadedTestUse, &x); + pthread_join(t, 0); +} + +TEST(AddressSanitizer, ThreadedTest) { + EXPECT_DEATH(ThreadedTestSpawn(), + ASAN_PCRE_DOTALL + "Thread T.*created" + ".*Thread T.*created" + ".*Thread T.*created"); +} + +#if ASAN_NEEDS_SEGV +TEST(AddressSanitizer, ShadowGapTest) { +#if __WORDSIZE == 32 + char *addr = (char*)0x22000000; +#else + char *addr = (char*)0x0000100000080000; +#endif + EXPECT_DEATH(*addr = 1, "AddressSanitizer crashed on unknown"); +} +#endif // ASAN_NEEDS_SEGV + +extern "C" { +__attribute__((noinline)) +static void UseThenFreeThenUse() { + char *x = Ident((char*)malloc(8)); + *x = 1; + free_aaa(x); + *x = 2; +} +} + +TEST(AddressSanitizer, UseThenFreeThenUseTest) { + EXPECT_DEATH(UseThenFreeThenUse(), "freed by thread"); +} + +TEST(AddressSanitizer, StrDupTest) { + free(strdup(Ident("123"))); +} + +TEST(AddressSanitizer, ObjdumpTest) { + ObjdumpOfMyself *o = objdump_of_myself(); + EXPECT_TRUE(o->IsCorrect()); +} + +extern "C" { +__attribute__((noinline)) +static void DisasmSimple() { + Ident(0); +} + +__attribute__((noinline)) +static void DisasmParamWrite(int *a) { + *a = 1; +} + +__attribute__((noinline)) +static void DisasmParamInc(int *a) { + (*a)++; +} + +__attribute__((noinline)) +static void DisasmParamReadIfWrite(int *a) { + if (*a) + *a = 1; +} + +__attribute__((noinline)) +static int DisasmParamIfReadWrite(int *a, int cond) { + int res = 0; + if (cond) + res = *a; + *a = 0; + return res; +} + +static int GLOBAL; + +__attribute__((noinline)) +static void DisasmWriteGlob() { + GLOBAL = 1; +} +} // extern "C" + +TEST(AddressSanitizer, DisasmTest) { + int a; + DisasmSimple(); + DisasmParamWrite(&a); + DisasmParamInc(&a); + Ident(DisasmWriteGlob)(); + DisasmParamReadIfWrite(&a); + + a = 7; + EXPECT_EQ(7, DisasmParamIfReadWrite(&a, Ident(1))); + EXPECT_EQ(0, a); + + ObjdumpOfMyself *o = objdump_of_myself(); + vector insns; + insns.push_back("ud2"); + insns.push_back("__asan_report_"); + EXPECT_EQ(0, o->CountInsnInFunc("DisasmSimple", insns)); + EXPECT_EQ(1, o->CountInsnInFunc("DisasmParamWrite", insns)); + EXPECT_EQ(1, o->CountInsnInFunc("DisasmParamInc", insns)); + EXPECT_EQ(0, o->CountInsnInFunc("DisasmWriteGlob", insns)); + + // TODO(kcc): implement these (needs just one __asan_report). + EXPECT_EQ(2, o->CountInsnInFunc("DisasmParamReadIfWrite", insns)); + EXPECT_EQ(2, o->CountInsnInFunc("DisasmParamIfReadWrite", insns)); +} + +// Currently we create and poison redzone at right of global variables. +char glob5[5]; +static char static110[110]; +const char ConstGlob[7] = {1, 2, 3, 4, 5, 6, 7}; +static const char StaticConstGlob[3] = {9, 8, 7}; +extern int GlobalsTest(int x); + +TEST(AddressSanitizer, GlobalTest) { + static char func_static15[15]; + + static char fs1[10]; + static char fs2[10]; + static char fs3[10]; + + glob5[Ident(0)] = 0; + glob5[Ident(1)] = 0; + glob5[Ident(2)] = 0; + glob5[Ident(3)] = 0; + glob5[Ident(4)] = 0; + + EXPECT_DEATH(glob5[Ident(5)] = 0, + "0 bytes to the right of global variable.*glob5.* size 5"); + EXPECT_DEATH(glob5[Ident(5+6)] = 0, + "6 bytes to the right of global variable.*glob5.* size 5"); + Ident(static110); // avoid optimizations + static110[Ident(0)] = 0; + static110[Ident(109)] = 0; + EXPECT_DEATH(static110[Ident(110)] = 0, + "0 bytes to the right of global variable"); + EXPECT_DEATH(static110[Ident(110+7)] = 0, + "7 bytes to the right of global variable"); + + Ident(func_static15); // avoid optimizations + func_static15[Ident(0)] = 0; + EXPECT_DEATH(func_static15[Ident(15)] = 0, + "0 bytes to the right of global variable"); + EXPECT_DEATH(func_static15[Ident(15 + 9)] = 0, + "9 bytes to the right of global variable"); + + Ident(fs1); + Ident(fs2); + Ident(fs3); + + // We don't create left redzones, so this is not 100% guaranteed to fail. + // But most likely will. + EXPECT_DEATH(fs2[Ident(-1)] = 0, "is located.*of global variable"); + + EXPECT_DEATH(Ident(Ident(ConstGlob)[8]), + "is located 1 bytes to the right of .*ConstGlob"); + EXPECT_DEATH(Ident(Ident(StaticConstGlob)[5]), + "is located 2 bytes to the right of .*StaticConstGlob"); + + // call stuff from another file. + GlobalsTest(0); +} + +TEST(AddressSanitizer, GlobalStringConstTest) { + static const char *zoo = "FOOBAR123"; + const char *p = Ident(zoo); + EXPECT_DEATH(Ident(p[15]), "is ascii string 'FOOBAR123'"); +} + +TEST(AddressSanitizer, FileNameInGlobalReportTest) { + static char zoo[10]; + const char *p = Ident(zoo); + // The file name should be present in the report. + EXPECT_DEATH(Ident(p[15]), "zoo.*asan_test.cc"); +} + +int *ReturnsPointerToALocalObject() { + int a = 0; + return Ident(&a); +} + +#if ASAN_UAR == 1 +TEST(AddressSanitizer, LocalReferenceReturnTest) { + int *(*f)() = Ident(ReturnsPointerToALocalObject); + int *p = f(); + // Call 'f' a few more times, 'p' should still be poisoned. + for (int i = 0; i < 32; i++) + f(); + EXPECT_DEATH(*p = 1, "AddressSanitizer stack-use-after-return"); + EXPECT_DEATH(*p = 1, "is located.*in frame .*ReturnsPointerToALocal"); +} +#endif + +template +__attribute__((noinline)) +static void FuncWithStack() { + char x[kSize]; + Ident(x)[0] = 0; + Ident(x)[kSize-1] = 0; +} + +static void LotsOfStackReuse() { + int LargeStack[10000]; + Ident(LargeStack)[0] = 0; + for (int i = 0; i < 10000; i++) { + FuncWithStack<128 * 1>(); + FuncWithStack<128 * 2>(); + FuncWithStack<128 * 4>(); + FuncWithStack<128 * 8>(); + FuncWithStack<128 * 16>(); + FuncWithStack<128 * 32>(); + FuncWithStack<128 * 64>(); + FuncWithStack<128 * 128>(); + FuncWithStack<128 * 256>(); + FuncWithStack<128 * 512>(); + Ident(LargeStack)[0] = 0; + } +} + +TEST(AddressSanitizer, StressStackReuseTest) { + LotsOfStackReuse(); +} + +TEST(AddressSanitizer, ThreadedStressStackReuseTest) { + const int kNumThreads = 20; + pthread_t t[kNumThreads]; + for (int i = 0; i < kNumThreads; i++) { + pthread_create(&t[i], 0, (void* (*)(void *x))LotsOfStackReuse, 0); + } + for (int i = 0; i < kNumThreads; i++) { + pthread_join(t[i], 0); + } +} + +#ifdef __EXCEPTIONS +__attribute__((noinline)) +static void StackReuseAndException() { + int large_stack[1000]; + Ident(large_stack); + ASAN_THROW(1); +} + +// TODO(kcc): support exceptions with use-after-return. +TEST(AddressSanitizer, DISABLED_StressStackReuseAndExceptionsTest) { + for (int i = 0; i < 10000; i++) { + try { + StackReuseAndException(); + } catch(...) { + } + } +} +#endif + +TEST(AddressSanitizer, MlockTest) { + EXPECT_EQ(0, mlockall(MCL_CURRENT)); + EXPECT_EQ(0, mlock((void*)0x12345, 0x5678)); + EXPECT_EQ(0, munlockall()); + EXPECT_EQ(0, munlock((void*)0x987, 0x654)); +} + +// ------------------ demo tests; run each one-by-one ------------- +// e.g. --gtest_filter=*DemoOOBLeftHigh --gtest_also_run_disabled_tests +TEST(AddressSanitizer, DISABLED_DemoThreadedTest) { + ThreadedTestSpawn(); +} + +void *SimpleBugOnSTack(void *x = 0) { + char a[20]; + Ident(a)[20] = 0; + return 0; +} + +TEST(AddressSanitizer, DISABLED_DemoStackTest) { + SimpleBugOnSTack(); +} + +TEST(AddressSanitizer, DISABLED_DemoThreadStackTest) { + pthread_t t; + pthread_create(&t, 0, SimpleBugOnSTack, 0); + pthread_join(t, 0); +} + +TEST(AddressSanitizer, DISABLED_DemoUAFLowIn) { + uaf_test(10, 0); +} +TEST(AddressSanitizer, DISABLED_DemoUAFLowLeft) { + uaf_test(10, -2); +} +TEST(AddressSanitizer, DISABLED_DemoUAFLowRight) { + uaf_test(10, 10); +} + +TEST(AddressSanitizer, DISABLED_DemoUAFHigh) { + uaf_test(kLargeMalloc, 0); +} + +TEST(AddressSanitizer, DISABLED_DemoOOBLeftLow) { + oob_test(10, -1); +} + +TEST(AddressSanitizer, DISABLED_DemoOOBLeftHigh) { + oob_test(kLargeMalloc, -1); +} + +TEST(AddressSanitizer, DISABLED_DemoOOBRightLow) { + oob_test(10, 10); +} + +TEST(AddressSanitizer, DISABLED_DemoOOBRightHigh) { + oob_test(kLargeMalloc, kLargeMalloc); +} + +TEST(AddressSanitizer, DISABLED_DemoOOM) { + size_t size = __WORDSIZE == 64 ? (size_t)(1ULL << 40) : (0xf0000000); + printf("%p\n", malloc(size)); +} + +TEST(AddressSanitizer, DISABLED_DemoDoubleFreeTest) { + DoubleFree(); +} + +TEST(AddressSanitizer, DISABLED_DemoNullDerefTest) { + int *a = 0; + Ident(a)[10] = 0; +} + +TEST(AddressSanitizer, DISABLED_DemoFunctionStaticTest) { + static char a[100]; + static char b[100]; + static char c[100]; + Ident(a); + Ident(b); + Ident(c); + Ident(a)[5] = 0; + Ident(b)[105] = 0; + Ident(a)[5] = 0; +} + +TEST(AddressSanitizer, DISABLED_DemoTooMuchMemoryTest) { + const size_t kAllocSize = (1 << 28) - 1024; + size_t total_size = 0; + while (true) { + char *x = (char*)malloc(kAllocSize); + memset(x, 0, kAllocSize); + total_size += kAllocSize; + fprintf(stderr, "total: %ldM\n", (long)total_size >> 20); + } +} + +#ifdef __APPLE__ +#include "asan_mac_test.h" +// TODO(glider): figure out whether we still need these tests. Is it correct +// to intercept CFAllocator? +TEST(AddressSanitizerMac, DISABLED_CFAllocatorDefaultDoubleFree) { + EXPECT_DEATH( + CFAllocatorDefaultDoubleFree(), + "attempting double-free"); +} + +TEST(AddressSanitizerMac, DISABLED_CFAllocatorSystemDefaultDoubleFree) { + EXPECT_DEATH( + CFAllocatorSystemDefaultDoubleFree(), + "attempting double-free"); +} + +TEST(AddressSanitizerMac, DISABLED_CFAllocatorMallocDoubleFree) { + EXPECT_DEATH(CFAllocatorMallocDoubleFree(), "attempting double-free"); +} + +TEST(AddressSanitizerMac, DISABLED_CFAllocatorMallocZoneDoubleFree) { + EXPECT_DEATH(CFAllocatorMallocZoneDoubleFree(), "attempting double-free"); +} + +TEST(AddressSanitizerMac, GCDDispatchAsync) { + // Make sure the whole ASan report is printed, i.e. that we don't die + // on a CHECK. + EXPECT_DEATH(TestGCDDispatchAsync(), "Shadow byte and word"); +} + +TEST(AddressSanitizerMac, GCDDispatchSync) { + // Make sure the whole ASan report is printed, i.e. that we don't die + // on a CHECK. + EXPECT_DEATH(TestGCDDispatchSync(), "Shadow byte and word"); +} + + +TEST(AddressSanitizerMac, GCDReuseWqthreadsAsync) { + // Make sure the whole ASan report is printed, i.e. that we don't die + // on a CHECK. + EXPECT_DEATH(TestGCDReuseWqthreadsAsync(), "Shadow byte and word"); +} + +TEST(AddressSanitizerMac, GCDReuseWqthreadsSync) { + // Make sure the whole ASan report is printed, i.e. that we don't die + // on a CHECK. + EXPECT_DEATH(TestGCDReuseWqthreadsSync(), "Shadow byte and word"); +} + +TEST(AddressSanitizerMac, GCDDispatchAfter) { + // Make sure the whole ASan report is printed, i.e. that we don't die + // on a CHECK. + EXPECT_DEATH(TestGCDDispatchAfter(), "Shadow byte and word"); +} + +TEST(AddressSanitizerMac, GCDSourceEvent) { + // Make sure the whole ASan report is printed, i.e. that we don't die + // on a CHECK. + EXPECT_DEATH(TestGCDSourceEvent(), "Shadow byte and word"); +} + +TEST(AddressSanitizerMac, GCDSourceCancel) { + // Make sure the whole ASan report is printed, i.e. that we don't die + // on a CHECK. + EXPECT_DEATH(TestGCDSourceCancel(), "Shadow byte and word"); +} + +TEST(AddressSanitizerMac, GCDGroupAsync) { + // Make sure the whole ASan report is printed, i.e. that we don't die + // on a CHECK. + EXPECT_DEATH(TestGCDGroupAsync(), "Shadow byte and word"); +} + +void *MallocIntrospectionLockWorker(void *_) { + const int kNumPointers = 100; + int i; + void *pointers[kNumPointers]; + for (i = 0; i < kNumPointers; i++) { + pointers[i] = malloc(i + 1); + } + for (i = 0; i < kNumPointers; i++) { + free(pointers[i]); + } + + return NULL; +} + +void *MallocIntrospectionLockForker(void *_) { + pid_t result = fork(); + if (result == -1) { + perror("fork"); + } + assert(result != -1); + if (result == 0) { + // Call malloc in the child process to make sure we won't deadlock. + void *ptr = malloc(42); + free(ptr); + exit(0); + } else { + // Return in the parent process. + return NULL; + } +} + +TEST(AddressSanitizerMac, MallocIntrospectionLock) { + // Incorrect implementation of force_lock and force_unlock in our malloc zone + // will cause forked processes to deadlock. + // TODO(glider): need to detect that none of the child processes deadlocked. + const int kNumWorkers = 5, kNumIterations = 100; + int i, iter; + for (iter = 0; iter < kNumIterations; iter++) { + pthread_t workers[kNumWorkers], forker; + for (i = 0; i < kNumWorkers; i++) { + pthread_create(&workers[i], 0, MallocIntrospectionLockWorker, 0); + } + pthread_create(&forker, 0, MallocIntrospectionLockForker, 0); + for (i = 0; i < kNumWorkers; i++) { + pthread_join(workers[i], 0); + } + pthread_join(forker, 0); + } +} + +void *TSDAllocWorker(void *test_key) { + if (test_key) { + void *mem = malloc(10); + pthread_setspecific(*(pthread_key_t*)test_key, mem); + } + return NULL; +} + +TEST(AddressSanitizerMac, DISABLED_TSDWorkqueueTest) { + pthread_t th; + pthread_key_t test_key; + pthread_key_create(&test_key, CallFreeOnWorkqueue); + pthread_create(&th, NULL, TSDAllocWorker, &test_key); + pthread_join(th, NULL); + pthread_key_delete(test_key); +} +#endif // __APPLE__ + +int main(int argc, char **argv) { + progname = argv[0]; + testing::GTEST_FLAG(death_test_style) = "threadsafe"; + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/lib/asan/tests/asan_test.ignore b/lib/asan/tests/asan_test.ignore new file mode 100644 index 0000000..7bafa83 --- /dev/null +++ b/lib/asan/tests/asan_test.ignore @@ -0,0 +1,2 @@ +fun:*IgnoreTest* +fun:*SomeOtherFunc* diff --git a/lib/asan/tests/asan_test_config.h b/lib/asan/tests/asan_test_config.h new file mode 100644 index 0000000..de4ae95 --- /dev/null +++ b/lib/asan/tests/asan_test_config.h @@ -0,0 +1,44 @@ +//===-- asan_test_config.h ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +//===----------------------------------------------------------------------===// +#ifndef ASAN_TEST_CONFIG_H +#define ASAN_TEST_CONFIG_H + +#include +#include +#include + +#include "gtest/gtest.h" + +using std::string; +using std::vector; +using std::map; + +#ifndef ASAN_UAR +# error "please define ASAN_UAR" +#endif + +#ifndef ASAN_HAS_EXCEPTIONS +# error "please define ASAN_HAS_EXCEPTIONS" +#endif + +#ifndef ASAN_HAS_BLACKLIST +# error "please define ASAN_HAS_BLACKLIST" +#endif + +#ifndef ASAN_NEEDS_SEGV +# error "please define ASAN_NEEDS_SEGV" +#endif + +#define ASAN_PCRE_DOTALL "" + +#endif // ASAN_TEST_CONFIG_H diff --git a/lib/asan/tests/asan_test_utils.h b/lib/asan/tests/asan_test_utils.h new file mode 100644 index 0000000..a480981 --- /dev/null +++ b/lib/asan/tests/asan_test_utils.h @@ -0,0 +1,30 @@ +//===-- asan_test_utils.h ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +//===----------------------------------------------------------------------===// + +#ifndef ASAN_TEST_UTILS_H +#define ASAN_TEST_UTILS_H + +// Make the compiler think that something is going on there. +extern "C" void break_optimization(void *); + +// This function returns its parameter but in such a way that compiler +// can not prove it. +template +__attribute__((noinline)) +static T Ident(T t) { + T ret = t; + break_optimization(&ret); + return ret; +} + +#endif // ASAN_TEST_UTILS_H diff --git a/lib/asan/tests/dlclose-test-so.cc b/lib/asan/tests/dlclose-test-so.cc new file mode 100644 index 0000000..fae2f81 --- /dev/null +++ b/lib/asan/tests/dlclose-test-so.cc @@ -0,0 +1,33 @@ +//===-- asan_rtl.cc ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Regression test for +// http://code.google.com/p/address-sanitizer/issues/detail?id=19 +//===----------------------------------------------------------------------===// +#include + +static int pad1; +static int static_var; +static int pad2; + +extern "C" +int *get_address_of_static_var() { + return &static_var; +} + +__attribute__((constructor)) +void at_dlopen() { + printf("%s: I am being dlopened\n", __FILE__); +} +__attribute__((destructor)) +void at_dlclose() { + printf("%s: I am being dlclosed\n", __FILE__); +} diff --git a/lib/asan/tests/dlclose-test.cc b/lib/asan/tests/dlclose-test.cc new file mode 100644 index 0000000..3078866 --- /dev/null +++ b/lib/asan/tests/dlclose-test.cc @@ -0,0 +1,73 @@ +//===-- asan_rtl.cc ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// Regression test for +// http://code.google.com/p/address-sanitizer/issues/detail?id=19 +// Bug description: +// 1. application dlopens foo.so +// 2. asan registers all globals from foo.so +// 3. application dlcloses foo.so +// 4. application mmaps some memory to the location where foo.so was before +// 5. application starts using this mmaped memory, but asan still thinks there +// are globals. +// 6. BOOM +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include + +#include + +using std::string; + +static const int kPageSize = 4096; + +typedef int *(fun_t)(); + +int main(int argc, char *argv[]) { + string path = string(argv[0]) + "-so.so"; + printf("opening %s ... \n", path.c_str()); + void *lib = dlopen(path.c_str(), RTLD_NOW); + if (!lib) { + printf("error in dlopen(): %s\n", dlerror()); + return 1; + } + fun_t *get = (fun_t*)dlsym(lib, "get_address_of_static_var"); + if (!get) { + printf("failed dlsym\n"); + return 1; + } + int *addr = get(); + assert(((size_t)addr % 32) == 0); // should be 32-byte aligned. + printf("addr: %p\n", addr); + addr[0] = 1; // make sure we can write there. + + // Now dlclose the shared library. + printf("attempting to dlclose\n"); + if (dlclose(lib)) { + printf("failed to dlclose\n"); + return 1; + } + // Now, the page where 'addr' is unmapped. Map it. + size_t page_beg = ((size_t)addr) & ~(kPageSize - 1); + void *res = mmap((void*)(page_beg), kPageSize, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE, 0, 0); + if (res == (char*)-1L) { + printf("failed to mmap\n"); + return 1; + } + addr[1] = 2; // BOOM (if the bug is not fixed). + printf("PASS\n"); + return 0; +} diff --git a/lib/asan/tests/dlclose-test.tmpl b/lib/asan/tests/dlclose-test.tmpl new file mode 100644 index 0000000..7ef22e9 --- /dev/null +++ b/lib/asan/tests/dlclose-test.tmpl @@ -0,0 +1 @@ +PASS diff --git a/lib/asan/tests/global-overflow.cc b/lib/asan/tests/global-overflow.cc new file mode 100644 index 0000000..b85c4d2 --- /dev/null +++ b/lib/asan/tests/global-overflow.cc @@ -0,0 +1,12 @@ +#include +int main(int argc, char **argv) { + static char XXX[10]; + static char YYY[10]; + static char ZZZ[10]; + memset(XXX, 0, 10); + memset(YYY, 0, 10); + memset(ZZZ, 0, 10); + int res = YYY[argc * 10]; // BOOOM + res += XXX[argc] + ZZZ[argc]; + return res; +} diff --git a/lib/asan/tests/global-overflow.tmpl b/lib/asan/tests/global-overflow.tmpl new file mode 100644 index 0000000..c5d5442 --- /dev/null +++ b/lib/asan/tests/global-overflow.tmpl @@ -0,0 +1,3 @@ +READ of size 1 at 0x.* thread T0 + #0 0x.* in main .*global-overflow.cc:9 +0x.* is located 0 bytes to the right of global variable .*YYY.* of size 10 diff --git a/lib/asan/tests/heap-overflow.cc b/lib/asan/tests/heap-overflow.cc new file mode 100644 index 0000000..475d163 --- /dev/null +++ b/lib/asan/tests/heap-overflow.cc @@ -0,0 +1,9 @@ +#include +#include +int main(int argc, char **argv) { + char *x = (char*)malloc(10 * sizeof(char)); + memset(x, 0, 10); + int res = x[argc * 10]; // BOOOM + free(x); + return res; +} diff --git a/lib/asan/tests/heap-overflow.tmpl b/lib/asan/tests/heap-overflow.tmpl new file mode 100644 index 0000000..e2ab65f --- /dev/null +++ b/lib/asan/tests/heap-overflow.tmpl @@ -0,0 +1,6 @@ +READ of size 1 at 0x.* thread T0 + #0 0x.* in main .*heap-overflow.cc:6 +0x.* is located 0 bytes to the right of 10-byte region +allocated by thread T0 here: + #0 0x.* in malloc + #1 0x.* in main .*heap-overflow.cc:[45] diff --git a/lib/asan/tests/heap-overflow.tmpl.Darwin b/lib/asan/tests/heap-overflow.tmpl.Darwin new file mode 100644 index 0000000..e4611d0 --- /dev/null +++ b/lib/asan/tests/heap-overflow.tmpl.Darwin @@ -0,0 +1,8 @@ +READ of size 1 at 0x.* thread T0 + #0 0x.* in main .*heap-overflow.cc:6 +0x.* is located 0 bytes to the right of 10-byte region +allocated by thread T0 here: + #0 0x.* in .*mz_malloc.* _asan_rtl_ + #1 0x.* in malloc_zone_malloc.* + #2 0x.* in malloc.* + #3 0x.* in main heap-overflow.cc:4 diff --git a/lib/asan/tests/large_func_test.cc b/lib/asan/tests/large_func_test.cc new file mode 100644 index 0000000..70bc36f --- /dev/null +++ b/lib/asan/tests/large_func_test.cc @@ -0,0 +1,33 @@ +#include +__attribute__((noinline)) +static void LargeFunction(int *x, int zero) { + x[0]++; + x[1]++; + x[2]++; + x[3]++; + x[4]++; + x[5]++; + x[6]++; + x[7]++; + x[8]++; + x[9]++; + + x[zero + 111]++; // we should report this exact line + + x[10]++; + x[11]++; + x[12]++; + x[13]++; + x[14]++; + x[15]++; + x[16]++; + x[17]++; + x[18]++; + x[19]++; +} + +int main(int argc, char **argv) { + int *x = new int[100]; + LargeFunction(x, argc - 1); + delete x; +} diff --git a/lib/asan/tests/large_func_test.tmpl b/lib/asan/tests/large_func_test.tmpl new file mode 100644 index 0000000..45a13d0 --- /dev/null +++ b/lib/asan/tests/large_func_test.tmpl @@ -0,0 +1,8 @@ +.*ERROR: AddressSanitizer heap-buffer-overflow on address 0x.* at pc 0x.* bp 0x.* sp 0x.* +READ of size 4 at 0x.* thread T0 + #0 0x.* in LargeFunction .*large_func_test.cc:15 + #1 0x.* in main .*large_func_test.cc:3[012] +0x.* is located 44 bytes to the right of 400-byte region +allocated by thread T0 here: + #0 0x.* in operator new.* + #1 0x.* in main .*large_func_test.cc:30 diff --git a/lib/asan/tests/match_output.py b/lib/asan/tests/match_output.py new file mode 100755 index 0000000..31095f3 --- /dev/null +++ b/lib/asan/tests/match_output.py @@ -0,0 +1,35 @@ +#!/usr/bin/python + +import re +import sys + +def matchFile(f, f_re): + for line_re in f_re: + line_re = line_re.rstrip() + if not line_re: + continue + if line_re[0] == '#': + continue + match = False + for line in f: + line = line.rstrip() + # print line + if re.search(line_re, line): + match = True + #print 'match: %s =~ %s' % (line, line_re) + break + if not match: + print 'no match for: %s' % (line_re) + return False + return True + +if len(sys.argv) != 2: + print >>sys.stderr, 'Usage: %s