From 3f452c6c8e9a3c53ca4c70c1f2faf66d21095f4a Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Fri, 26 Dec 2003 00:50:37 +0000 Subject: [PATCH] initial checkin git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@498 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/compat-c99.h | 31 ++++++++ util-vserver/src/testsuite/Makefile-files | 45 ++++++++++++ util-vserver/src/testsuite/data/rpm-fake-test.inp | 14 ++++ util-vserver/src/testsuite/data/rpm-fake-test.out | 13 ++++ util-vserver/src/testsuite/rpm-fake-test.c | 89 +++++++++++++++++++++++ util-vserver/src/testsuite/rpm-fake-test.sh | 37 ++++++++++ util-vserver/src/testsuite/vunify-functest.c | 30 ++++++++ util-vserver/src/testsuite/vunify-test.sh | 53 ++++++++++++++ 8 files changed, 312 insertions(+) create mode 100644 util-vserver/compat-c99.h create mode 100644 util-vserver/src/testsuite/Makefile-files create mode 100644 util-vserver/src/testsuite/data/rpm-fake-test.inp create mode 100644 util-vserver/src/testsuite/data/rpm-fake-test.out create mode 100644 util-vserver/src/testsuite/rpm-fake-test.c create mode 100755 util-vserver/src/testsuite/rpm-fake-test.sh create mode 100644 util-vserver/src/testsuite/vunify-functest.c create mode 100755 util-vserver/src/testsuite/vunify-test.sh diff --git a/util-vserver/compat-c99.h b/util-vserver/compat-c99.h new file mode 100644 index 0000000..8317fc8 --- /dev/null +++ b/util-vserver/compat-c99.h @@ -0,0 +1,31 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2003 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. + + +#ifndef H_UTIL_VSERVER_COMPAT_C99_H +#define H_UTIL_VSERVER_COMPAT_C99_H + +#if defined(__GNUC__) && __GNUC__ < 3 || (__GNUC__==3 && __GNUC_MINOR__<3) +# warning Enabling hacks to make it compilable with non-C99 compilers +# define BS { do {} while (0) +# define BE } do {} while (0) +#else +# define BS do {} while (0) +# define BE do {} while (0) +#endif + +#endif // H_UTIL_VSERVER_COMPAT_C99_H diff --git a/util-vserver/src/testsuite/Makefile-files b/util-vserver/src/testsuite/Makefile-files new file mode 100644 index 0000000..98aa352 --- /dev/null +++ b/util-vserver/src/testsuite/Makefile-files @@ -0,0 +1,45 @@ +## $Id$ --*- makefile -*-- + +## Copyright (C) 2003 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. + +src_testsuite_check_active_PRGS = src/testsuite/vunify-functest +src_testsuite_check_passive_PRGS = src/testsuite/rpm-fake-test + + +src_testsuite_check_PRGS = $(src_testsuite_check_passive_PRGS) \ + $(src_testsuite_check_active_PRGS) + +src_testsuite_check_src_SCRPTS = src/testsuite/vunify-test.sh +src_testsuite_check_gen_SCRPTS = + +src_testsuite_check_SCRPTS = $(src_testsuite_check_src_SCRPTS) \ + $(src_testsuite_check_gen_SCRPTS) + +src_testsuite_TSTS = $(src_testsuite_check_active_PRGS) \ + $(src_testsuite_check_SCRPTS) + +src_testsuite_XTRAS = $(src_testsuite_check_src_SCRPTS) + + +src_testsuite_rpm_fake_test_SOURCES = src/testsuite/rpm-fake-test.c + +src_testsuite_vunify_functest_SOURCES = src/testsuite/vunify-functest.c \ + src/vunify-matchlist.c + +src_testsuite_vunify_functest_CPPFLAGS= $(AM_CPPFLAGS) $(src_testsuite_CPPFLAGS) + + +src_testsuite_CPPFLAGS = -I $(top_srcdir)/src -D ENSC_TESTSUITE diff --git a/util-vserver/src/testsuite/data/rpm-fake-test.inp b/util-vserver/src/testsuite/data/rpm-fake-test.inp new file mode 100644 index 0000000..a09ed48 --- /dev/null +++ b/util-vserver/src/testsuite/data/rpm-fake-test.inp @@ -0,0 +1,14 @@ +Proot +Groot +Pbar +Gbar +Pfoo +Gfoo +Pnobody +Gnobody +Cp +Cg +Pfoo +Gfoo +Pnobody +Gnobody diff --git a/util-vserver/src/testsuite/data/rpm-fake-test.out b/util-vserver/src/testsuite/data/rpm-fake-test.out new file mode 100644 index 0000000..497558f --- /dev/null +++ b/util-vserver/src/testsuite/data/rpm-fake-test.out @@ -0,0 +1,13 @@ +P(root) = 0 +G(root) = 0 +P(bar) = 501 +G(bar) = 501 +P(foo) = 500 +G(foo) = 500 +P(nobody) = (null) +G(nobody) = (null) +P(foo) = 500 +G(foo) = 500 +P(nobody) = (null) +G(nobody) = (null) +s_context: 49171 [ -16365] diff --git a/util-vserver/src/testsuite/rpm-fake-test.c b/util-vserver/src/testsuite/rpm-fake-test.c new file mode 100644 index 0000000..979950e --- /dev/null +++ b/util-vserver/src/testsuite/rpm-fake-test.c @@ -0,0 +1,89 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2003 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 "src/wrappers.h" + +#include +#include +#include +#include +#include +#include + +int wrapper_exit_code = 1; + +int main(int argc, char *argv[]) +{ + char buf[1000]; + + while (true) { + char *ptr = buf; + char c; + do { + if (read(0, &c, 1)==0) break; + if (c=='\n') break; + *ptr++ = c; + } while (ptrpw_uid); + else printf("(null)\n"); + + break; + } + + case 'G' : { + struct group *gr; + + gr = getgrnam(buf+1); + printf("G(%s) = ", buf+1); + if (gr) printf("%u\n", gr->gr_gid); + else printf("(null)\n"); + + break; + } + + case 'C' : + switch (buf[1]) { + case 'g' : endgrent(); break; + case 'p' : endpwent(); break; + default : abort(); break; + } + break; + + default : + abort(); + } + } + + { + char const * cmd[] = { "/bin/grep", "^s_context", "/proc/self/status", 0 }; + Eexecv(cmd[0], cmd); + } +} diff --git a/util-vserver/src/testsuite/rpm-fake-test.sh b/util-vserver/src/testsuite/rpm-fake-test.sh new file mode 100755 index 0000000..edc33ed --- /dev/null +++ b/util-vserver/src/testsuite/rpm-fake-test.sh @@ -0,0 +1,37 @@ +#! /bin/bash + +: ${srcdir=.} +: ${srctestsuitedir=./src/testsuite} +: ${srcdatadir=$srctestsuitedir/data} +: ${tmptopdir=/var/tmp} + +DEBUG='strace -E' + +set -e + +tmpdir=$(mktemp -d /var/tmp/rpm-fake-test.XXXXXX) +trap "rm -rf $tmpdir" EXIT + +mkdir -p $tmpdir/{etc,bin} +cat <$tmpdir/etc/passwd +root:x:0:0:root:/root:/bin/bash +foo:x:500:500:foo:/:/bin/false +bar:x:501:501:bar:/:/bin/false +EOF + +cat <$tmpdir/etc/group +root:x:0:root +foo:x:500:foo +bar:x:501:bar +EOF + +chmod +rx $tmpdir + +RPM_FAKE_RESOLVER_UID=1000 \ +RPM_FAKE_RESOLVER_GID=1000 \ +RPM_FAKE_CTX=-1 \ +RPM_FAKE_RESOLVER=$srcdir/src/rpm-fake-resolver \ +RPM_FAKE_CHROOT=$tmpdir \ +RPM_FAKE_NAMESPACE_MOUNTS=/proc \ +LD_PRELOAD=$srcdir/src/rpm-fake.so \ +./src/testsuite/rpm-fake-test <$srcdir/src/testsuite/data/rpm-fake-test.inp diff --git a/util-vserver/src/testsuite/vunify-functest.c b/util-vserver/src/testsuite/vunify-functest.c new file mode 100644 index 0000000..5af5f93 --- /dev/null +++ b/util-vserver/src/testsuite/vunify-functest.c @@ -0,0 +1,30 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2003 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 "vunify-matchlist.h" + +extern void PathInfo_test(); + +int main() +{ + PathInfo_test(); +} diff --git a/util-vserver/src/testsuite/vunify-test.sh b/util-vserver/src/testsuite/vunify-test.sh new file mode 100755 index 0000000..a0d2f3b --- /dev/null +++ b/util-vserver/src/testsuite/vunify-test.sh @@ -0,0 +1,53 @@ +#! /bin/bash + +: ${srcdir=.} +: ${tmptopdir=/var/tmp} + +set -e + +tmpdir=$(mktemp -d /var/tmp/vunify-test.XXXXXX) +trap "rm -rf $tmpdir" EXIT + +function createFiles +{ + local base=$1 + shift + + local idx=0 + local i + for i; do + echo $i >$base$idx + let ++idx + done +} + +function createSet +{ + local base=$1 + + createFiles a/$base a b c d + createFiles b/$base a b c + createFiles c/$base XX XX + + ln a/${base}3 b/${base}3 +} + +pushd $tmpdir &>/dev/null + mkdir -p {a,b,c}{/etc/sysconfig,/usr/lib,/usr/local/lib/foobar,/var/run} + + createSet etc/CFG + createSet etc/sysconfig/CFG + + createSet usr/PROG + createSet usr/lib/PROG + + createSet usr/local/lib/LOCAL + createSet usr/local/lib/foobar/LOCAL + + createSet var/TEMP + createSet var/run/TEMP +popd &>/dev/null + + +$D $srcdir/src/vunify $tmpdir/a $tmpdir/b +$D $srcdir/src/vunify $tmpdir/a $tmpdir/c -- 1.8.1.5