From: Enrico Scholz Date: Wed, 4 Jan 2006 17:28:42 +0000 (+0000) Subject: added 'hashcalc-plain' tests to track down broken beecrypt/vhashify on X-Git-Tag: version_0_30_210~36 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b38fd3ee74604c158da45b6c5cf2e2e477ae8121;p=util-vserver.git added 'hashcalc-plain' tests to track down broken beecrypt/vhashify on some Debians git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2245 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/src/testsuite/.cvsignore b/util-vserver/src/testsuite/.cvsignore index 6fc8d33..15735eb 100644 --- a/util-vserver/src/testsuite/.cvsignore +++ b/util-vserver/src/testsuite/.cvsignore @@ -4,5 +4,6 @@ chbind-test chcontext-test hashcalc +hashcalc-plain rpm-fake-test vunify-functest diff --git a/util-vserver/src/testsuite/Makefile-files b/util-vserver/src/testsuite/Makefile-files index 3edd389..3e9b2a1 100644 --- a/util-vserver/src/testsuite/Makefile-files +++ b/util-vserver/src/testsuite/Makefile-files @@ -23,7 +23,8 @@ src_testsuite_check_passive_PRGS = src/testsuite/rpm-fake-test if ENSC_HAVE_C99_COMPILER if ENSC_HAVE_BEECRYPT -src_testsuite_check_passive_PRGS += src/testsuite/hashcalc +src_testsuite_check_passive_PRGS += src/testsuite/hashcalc \ + src/testsuite/hashcalc-plain endif endif @@ -33,7 +34,8 @@ check_PROGRAMS += $(src_testsuite_check_passive_PRGS) \ if ENSC_HAVE_C99_COMPILER src_testsuite_check_src_C99_SCRPTS = src/testsuite/vunify-test.sh if ENSC_HAVE_BEECRYPT -src_testsuite_check_src_C99_SCRPTS += src/testsuite/hashcalc.sh +src_testsuite_check_src_C99_SCRPTS += src/testsuite/hashcalc-plain.sh \ + src/testsuite/hashcalc.sh endif else src_testsuite_check_src_C99_SCRPTS = @@ -52,6 +54,7 @@ TESTS += $(src_testsuite_check_active_PRGS) \ EXTRA_DIST += $(src_testsuite_check_src_SCRPTS) \ src/testsuite/vunify-test.sh \ src/testsuite/hashcalc.sh \ + src/testsuite/hashcalc-plain.sh \ src/testsuite/vwait-test.sh src_testsuite_rpm_fake_test_SOURCES = src/testsuite/rpm-fake-test.c @@ -69,12 +72,19 @@ src_testsuite_chbind_test_SOURCES = src/testsuite/chbind-test.c src_testsuite_chbind_test_LDADD = lib/libvserver.la src_testsuite_hashcalc_SOURCES = src/testsuite/hashcalc.c +src_testsuite_hashcalc_plain_SOURCES = src/testsuite/hashcalc-plain.c if ENSC_CAN_BEECRYPT_WITH_DIETLIBC src_testsuite_hashcalc_LDADD = $(LIBINTERNAL) $(LIBENSCVECTOR) -lbeecrypt $(VSERVER_LDADDS) src_testsuite_hashcalc_LDFLAGS = $(VSERVER_LDFLGS) + +src_testsuite_hashcalc_plain_LDADD = $(LIBINTERNAL) $(LIBENSCVECTOR) -lbeecrypt $(VSERVER_LDADDS) +src_testsuite_hashcalc_plain_LDFLAGS = $(VSERVER_LDFLGS) else src_testsuite_hashcalc_LDADD = $(LIBINTERNAL_GLIBC) $(LIBENSCVECTOR_GLIBC) $(LIBVSERVER_GLIBC) -lbeecrypt src_testsuite_hashcalc_LDFLAGS = + +src_testsuite_hashcalc_plain_LDADD = $(LIBINTERNAL_GLIBC) $(LIBENSCVECTOR_GLIBC) $(LIBVSERVER_GLIBC) -lbeecrypt +src_testsuite_hashcalc_plain_LDFLAGS = endif src_testsuite_CPPFLAGS = -I $(top_srcdir)/src -D ENSC_TESTSUITE diff --git a/util-vserver/src/testsuite/hashcalc-plain.c b/util-vserver/src/testsuite/hashcalc-plain.c new file mode 100644 index 0000000..7e2421b --- /dev/null +++ b/util-vserver/src/testsuite/hashcalc-plain.c @@ -0,0 +1,92 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2006 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include + +#define ENSC_TESTSUITE +#include "lib_internal/coreassert.h" + +#define HASH_BLOCKSIZE 0x10000000u + +static bool +convertDigest(char res[], hashFunctionContext * h_ctx) +{ + static char const HEX_DIGIT[] = "0123456789abcdef"; + size_t d_size = h_ctx->algo->digestsize; + + unsigned char digest[d_size]; + size_t out = 0; + + if (hashFunctionContextDigest(h_ctx, digest)==-1) + return false; + + for (size_t in=0; in> 4]; + res[out++] = HEX_DIGIT[digest[in] & 0x0f]; + } + res[out++] = '\0'; + + return true; +} + +int main(int UNUSED argc, char *argv[]) +{ + int fd = open(argv[1], O_NOFOLLOW|O_NONBLOCK|O_RDONLY|O_NOCTTY); + hashFunctionContext hash_context; + hashFunction const *method; + struct stat st; + off_t size; + loff_t offset = 0; + char digest[1024]; + + assert((method = hashFunctionFind(argv[2]))!=0); + assert(hashFunctionContextInit(&hash_context, method)!=-1); + + assert(fstat(fd, &st)!=-1); + assert(hashFunctionContextReset(&hash_context)!=-1); + + size = st.st_size; + + while (offset < size) { + loff_t volatile buf_size = size-offset; + void const * buf; + if (buf_size>HASH_BLOCKSIZE) buf_size = HASH_BLOCKSIZE; + + assert((buf=mmap(0, buf_size, PROT_READ, MAP_SHARED, fd, offset))!=0); + offset += buf_size; + assert(hashFunctionContextUpdate(&hash_context, buf, buf_size)!=-1); + munmap((void *)(buf), buf_size); + } + + assert(convertDigest(digest, &hash_context)); + + Vwrite(1, digest, strlen(digest)); + Vwrite(1, "\n", 1); + + hashFunctionContextFree(&hash_context); + + return 0; +} diff --git a/util-vserver/src/testsuite/hashcalc-plain.sh b/util-vserver/src/testsuite/hashcalc-plain.sh new file mode 100755 index 0000000..f5fd724 --- /dev/null +++ b/util-vserver/src/testsuite/hashcalc-plain.sh @@ -0,0 +1,19 @@ +#! /bin/bash + +# Copyright (C) 2006 Enrico Scholz +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +hashcalc=${builddir:-.}/src/testsuite/hashcalc-plain \ +exec ${srcdir:-.}/src/testsuite/hashcalc.sh