mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-22 17:49:13 +00:00
zdtm: execite test cases from a test user
Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
42d861bb48
commit
495c8007bc
6 changed files with 51 additions and 6 deletions
24
test/zdtm.sh
24
test/zdtm.sh
|
|
@ -131,6 +131,21 @@ static/sigpending
|
|||
static/sk-netlink
|
||||
"
|
||||
|
||||
TEST_SUID_LIST="
|
||||
pid00
|
||||
caps00
|
||||
maps01
|
||||
groups
|
||||
sched_prio00
|
||||
sched_policy00
|
||||
sock_opts00
|
||||
sock_opts01
|
||||
cmdlinenv00
|
||||
packet_sock
|
||||
fanotify00
|
||||
sk-netlink
|
||||
"
|
||||
|
||||
CRTOOLS=$(readlink -f `dirname $0`/../crtools)
|
||||
CRTOOLS_CPT=$CRTOOLS
|
||||
TMP_TREE=""
|
||||
|
|
@ -216,6 +231,15 @@ start_test()
|
|||
killall -9 $tname > /dev/null 2>&1
|
||||
make -C $tdir $tname.cleanout
|
||||
|
||||
unset ZDTM_UID
|
||||
unset ZDTM_GID
|
||||
|
||||
echo $TEST_SUID_LIST | grep $tname || {
|
||||
export ZDTM_UID=18943
|
||||
export ZDTM_GID=58467
|
||||
chown $ZDTM_UID:$ZDTM_GID $tdir
|
||||
}
|
||||
|
||||
if [ -z "$PIDNS" ]; then
|
||||
make -C $tdir $tname.pid
|
||||
PID=`cat $test.pid` || return 1
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ static int prepare_mntns()
|
|||
fprintf(stderr, "mknod(/dev/ptmx) failed: %m\n");
|
||||
return -1;
|
||||
}
|
||||
chmod("/dev/ptmx", 0666);
|
||||
if (mkdir("/dev/pts", 0755) && errno != EEXIST) {
|
||||
fprintf(stderr, "mkdir(/dev/pts) failed: %m\n");
|
||||
return -1;
|
||||
|
|
@ -88,6 +89,7 @@ static int prepare_mntns()
|
|||
|
||||
mkdir("/dev", 0777);
|
||||
mknod("/dev/null", 0777 | S_IFCHR, makedev(1, 3));
|
||||
chmod("/dev/null", 0777);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,6 +126,18 @@ void test_init(int argc, char **argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
val = getenv("ZDTM_GID");
|
||||
if (val && (setgid(atoi(val)) == -1)) {
|
||||
fprintf(stderr, "Can't set gid: %m");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
val = getenv("ZDTM_UID");
|
||||
if (val && (setuid(atoi(val)) == -1)) {
|
||||
fprintf(stderr, "Can't set gid: %m");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (sigaction(SIGTERM, &sa, NULL)) {
|
||||
fprintf(stderr, "Can't set SIGTERM handler: %m\n");
|
||||
exit(1);
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ cleanout:
|
|||
$(RM) -f -r *.pid *.out* *.test* *.state
|
||||
|
||||
%.cleanout: %
|
||||
$(RM) -f -r $<.pid $<.out* $<.test* $<.*.test $<.state
|
||||
$(RM) -f -r $<.pid $<.out* *$<.test* $<.*.test $<.state
|
||||
|
||||
realclean: cleandep cleanout
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ int main(int argc, char *argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
if (setresuid(-1, 1, -1)) {
|
||||
if (!getuid() && setresuid(-1, 1, -1)) {
|
||||
fail("setresuid failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,14 +58,21 @@ int main(int argc, char ** argv)
|
|||
mode = (fst.st_mode | S_IXOTH);
|
||||
else
|
||||
mode = (fst.st_mode ^ S_IXOTH);
|
||||
|
||||
if (fchmod(fd, mode) < 0) {
|
||||
err("can't chmod %s: %m\n", filename);
|
||||
goto failed;
|
||||
}
|
||||
/* Change uid, gid */
|
||||
if (fchown(fd, (uid = fst.st_uid + 1), (gid = fst.st_gid + 1)) < 0) {
|
||||
err("can't chown %s: %m\n", filename);
|
||||
goto failed;
|
||||
|
||||
if (getuid()) {
|
||||
uid = getuid();
|
||||
gid = getgid();
|
||||
} else {
|
||||
/* Change uid, gid */
|
||||
if (fchown(fd, (uid = fst.st_uid + 1), (gid = fst.st_gid + 1)) < 0) {
|
||||
err("can't chown %s: %m\n", filename);
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) != 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue