initial checkin
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Fri, 26 Dec 2003 00:50:37 +0000 (00:50 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Fri, 26 Dec 2003 00:50:37 +0000 (00:50 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@498 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/compat-c99.h [new file with mode: 0644]
util-vserver/src/testsuite/Makefile-files [new file with mode: 0644]
util-vserver/src/testsuite/data/rpm-fake-test.inp [new file with mode: 0644]
util-vserver/src/testsuite/data/rpm-fake-test.out [new file with mode: 0644]
util-vserver/src/testsuite/rpm-fake-test.c [new file with mode: 0644]
util-vserver/src/testsuite/rpm-fake-test.sh [new file with mode: 0755]
util-vserver/src/testsuite/vunify-functest.c [new file with mode: 0644]
util-vserver/src/testsuite/vunify-test.sh [new file with mode: 0755]

diff --git a/util-vserver/compat-c99.h b/util-vserver/compat-c99.h
new file mode 100644 (file)
index 0000000..8317fc8
--- /dev/null
@@ -0,0 +1,31 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//  
+// 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 (file)
index 0000000..98aa352
--- /dev/null
@@ -0,0 +1,45 @@
+## $Id$                --*- makefile -*--
+
+## Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+##  
+## 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 (file)
index 0000000..a09ed48
--- /dev/null
@@ -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 (file)
index 0000000..497558f
--- /dev/null
@@ -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 (file)
index 0000000..979950e
--- /dev/null
@@ -0,0 +1,89 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//  
+// 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 <config.h>
+#endif
+
+#include "src/wrappers.h"
+
+#include <grp.h>
+#include <pwd.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+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 (ptr<buf+sizeof(buf));
+    *ptr = '\0';
+    if (ptr==buf) break;
+
+    switch (buf[0]) {
+      case 'P'         : {
+       struct passwd   *pw;
+       
+       pw = getpwnam(buf+1);
+       printf("P(%s) = ", buf+1);
+       if (pw) printf("%u\n", pw->pw_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 (executable)
index 0000000..edc33ed
--- /dev/null
@@ -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 <<EOF >$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 <<EOF >$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 (file)
index 0000000..5af5f93
--- /dev/null
@@ -0,0 +1,30 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//  
+// 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 <config.h>
+#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 (executable)
index 0000000..a0d2f3b
--- /dev/null
@@ -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