Commit 7dbd38db authored by Ruslan Kuprieiev's avatar Ruslan Kuprieiev Committed by Pavel Emelyanov

zdtm: set additional groups along with uids and gids

Currently zdtm doesn't set additional groups when running
tests. It sets uids and gids to some non-root values, but
additional groups remain untouched, which allows tests
to inherit groups list, which leads to different
behaviour depending on a way you run tests.
Signed-off-by: 's avatarRuslan Kuprieiev <kupruser@gmail.com>
Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8eaf0142
...@@ -475,10 +475,12 @@ start_test() ...@@ -475,10 +475,12 @@ start_test()
unset ZDTM_UID unset ZDTM_UID
unset ZDTM_GID unset ZDTM_GID
unset ZDTM_GROUPS
if ! echo $TEST_SUID_LIST | grep -q $tname; then if ! echo $TEST_SUID_LIST | grep -q $tname; then
export ZDTM_UID=18943 export ZDTM_UID=18943
export ZDTM_GID=58467 export ZDTM_GID=58467
export ZDTM_GROUPS="27495 48244"
chmod a+w $tdir chmod a+w $tdir
fi fi
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include <grp.h>
#include "zdtmtst.h" #include "zdtmtst.h"
#include "lock.h" #include "lock.h"
...@@ -120,6 +121,24 @@ void test_init(int argc, char **argv) ...@@ -120,6 +121,24 @@ void test_init(int argc, char **argv)
/* "3" -- run the test */ /* "3" -- run the test */
} }
val = getenv("ZDTM_GROUPS");
if (val) {
char *tok = NULL;
unsigned int size = 0, groups[NGROUPS_MAX];
tok = strtok(val, " ");
while (tok) {
size++;
groups[size - 1] = atoi(tok);
tok = strtok(NULL, " ");
}
if (setgroups(size, groups)) {
fprintf(stderr, "Can't set groups: %m");
exit(1);
}
}
val = getenv("ZDTM_GID"); val = getenv("ZDTM_GID");
if (val && (setgid(atoi(val)) == -1)) { if (val && (setgid(atoi(val)) == -1)) {
fprintf(stderr, "Can't set gid: %m"); fprintf(stderr, "Can't set gid: %m");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment