Back to index

glibc  2.9
Classes | Defines | Enumerations | Functions | Variables
tst-setuid1.c File Reference
#include <pthread.h>
#include <pwd.h>
#include <grp.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include "../test-skeleton.c"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  setuid_test

Defines

#define TESTNO(arg)   ((long int) (arg) & 0xff)
#define THREADNO(arg)   ((long int) (arg) >> 8)
#define TEST_FUNCTION   do_test ()

Enumerations

enum  ACTION {
  FIND, ENTER, PREPARE, SET,
  CHECK_BEFORE, CHECK_AFTER
}

Functions

static void check_prev_uid (int tno)
static void check_prev_gid (int tno)
static void test_setuid1 (enum ACTION action, int tno)
static void test_setuid2 (enum ACTION action, int tno)
static void test_seteuid1 (enum ACTION action, int tno)
static void test_seteuid2 (enum ACTION action, int tno)
static void test_setreuid1 (enum ACTION action, int tno)
static void test_setreuid2 (enum ACTION action, int tno)
static void test_setreuid3 (enum ACTION action, int tno)
static void test_setreuid4 (enum ACTION action, int tno)
static void test_setresuid1 (enum ACTION action, int tno)
static void test_setresuid2 (enum ACTION action, int tno)
static void test_setresuid3 (enum ACTION action, int tno)
static void test_setresuid4 (enum ACTION action, int tno)
static void test_setgid1 (enum ACTION action, int tno)
static void test_setgid2 (enum ACTION action, int tno)
static void test_setegid1 (enum ACTION action, int tno)
static void test_setegid2 (enum ACTION action, int tno)
static void test_setregid1 (enum ACTION action, int tno)
static void test_setregid2 (enum ACTION action, int tno)
static void test_setregid3 (enum ACTION action, int tno)
static void test_setregid4 (enum ACTION action, int tno)
static void test_setresgid1 (enum ACTION action, int tno)
static void test_setresgid2 (enum ACTION action, int tno)
static void test_setresgid3 (enum ACTION action, int tno)
static void test_setresgid4 (enum ACTION action, int tno)
static void * tf2 (void *arg)
static void * tf (void *arg)
static int do_one_test (long int testno)
static int do_test (void)

Variables

static pthread_barrier_t b3
static pthread_barrier_t b4
static uid_t prev_ruid
static uid_t prev_euid
static uid_t prev_suid
static uid_t nobody_uid
static gid_t prev_rgid
static gid_t prev_egid
static gid_t prev_sgid
static gid_t nobody_gid
static struct setuid_test setuid_tests []

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 1084 of file tst-setuid1.c.

#define TESTNO (   arg)    ((long int) (arg) & 0xff)

Definition at line 33 of file tst-setuid1.c.

#define THREADNO (   arg)    ((long int) (arg) >> 8)

Definition at line 34 of file tst-setuid1.c.


Enumeration Type Documentation

enum ACTION
Enumerator:
FIND 
ENTER 
PREPARE 
SET 
CHECK_BEFORE 
CHECK_AFTER 

Definition at line 32 of file tst-setuid1.c.


Function Documentation

static void check_prev_gid ( int  tno) [static]

Definition at line 57 of file tst-setuid1.c.

{
  gid_t rgid, egid, sgid;
  if (getresgid (&rgid, &egid, &sgid) < 0)
    {
      printf ("getresgid failed: %d %m\n", tno);
      exit (1);
    }

  if (rgid != prev_rgid || egid != prev_egid || sgid != prev_sgid)
    {
      printf ("gids before in %d (%d %d %d) != (%d %d %d)\n", tno,
             rgid, egid, sgid, prev_rgid, prev_egid, prev_sgid);
      exit (1);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void check_prev_uid ( int  tno) [static]

Definition at line 38 of file tst-setuid1.c.

{
  uid_t ruid, euid, suid;
  if (getresuid (&ruid, &euid, &suid) < 0)
    {
      printf ("getresuid failed: %d %m\n", tno);
      exit (1);
    }

  if (ruid != prev_ruid || euid != prev_euid || suid != prev_suid)
    {
      printf ("uids before in %d (%d %d %d) != (%d %d %d)\n", tno,
             ruid, euid, suid, prev_ruid, prev_euid, prev_suid);
      exit (1);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int do_one_test ( long int  testno) [static]

Definition at line 917 of file tst-setuid1.c.

{
  printf ("%s test\n", setuid_tests[testno].name);

  pid_t pid = fork ();
  if (pid == 0)
    {
      setuid_tests[testno].test (PREPARE, 0);
      setuid_tests[testno].test (SET, 0);
      exit (0);
    }

  if (pid < 0)
    {
      printf ("fork failed: %m\n");
      exit (1);
    }

  int status;
  if (waitpid (pid, &status, 0) < 0)
    {
      printf ("waitpid failed: %m\n");
      exit (1);
    }

  if (!WIFEXITED (status))
    {
      puts ("child did not exit");
      exit (1);
    }

  if (WEXITSTATUS (status))
    {
      printf ("skipping %s test\n", setuid_tests[testno].name);
      return 0;
    }

  pid = fork ();
  if (pid == 0)
    {
      setuid_tests[testno].test (PREPARE, 0);

      pthread_t th;
      int e = pthread_create (&th, NULL, tf, (void *) (testno | 0x100L));
      if (e != 0)
       {
         printf ("create failed: %m\n");
         exit (1);
       }

      pthread_t th2;
      e = pthread_create (&th2, NULL, tf, (void *) (testno | 0x200L));
      if (e != 0)
       {
         printf ("create failed: %m\n");
         exit (1);
       }

      e = pthread_barrier_wait (&b3);
      if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
       {
         puts ("barrier_wait failed");
         exit (1);
       }

      setuid_tests[testno].test (SET, 0);

      pthread_t th3;
      e = pthread_create (&th3, NULL, tf2, (void *) (testno | 0x300L));
      if (e != 0)
       {
         printf ("create failed: %m\n");
         exit (1);
       }

      e = pthread_barrier_wait (&b4);
      if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
       {
         puts ("barrier_wait failed");
         exit (1);
       }

      exit (0);
    }

  if (pid < 0)
    {
      printf ("fork failed: %m\n");
      exit (1);
    }

  if (waitpid (pid, &status, 0) < 0)
    {
      printf ("waitpid failed: %m\n");
      exit (1);
    }

  if (!WIFEXITED (status))
    {
      puts ("second child did not exit");
      exit (1);
    }

  if (WEXITSTATUS (status))
    exit (WEXITSTATUS (status));

  return 0;
}

Here is the call graph for this function:

static int do_test ( void  ) [static]

Definition at line 1028 of file tst-setuid1.c.

{
  struct passwd *pwd = getpwnam ("nobody");
  if (pwd == NULL)
    {
      puts ("User nobody doesn't exist");
      return 0;
    }
  nobody_uid = pwd->pw_uid;
  nobody_gid = pwd->pw_gid;

  if (getresuid (&prev_ruid, &prev_euid, &prev_suid) < 0)
    {
      printf ("getresuid failed: %m\n");
      exit (1);
    }

  if (getresgid (&prev_rgid, &prev_egid, &prev_sgid) < 0)
    {
      printf ("getresgid failed: %m\n");
      exit (1);
    }

  if (prev_ruid == nobody_uid || prev_euid == nobody_uid
      || prev_suid == nobody_uid)
    {
      puts ("already running as user nobody, skipping tests");
      exit (0);
    }

  if (prev_rgid == nobody_gid || prev_egid == nobody_gid
      || prev_sgid == nobody_gid)
    {
      puts ("already running as group nobody, skipping tests");
      exit (0);
    }

  if (pthread_barrier_init (&b3, NULL, 3) != 0)
    {
      puts ("barrier_init failed");
      exit (1);
    }

  if (pthread_barrier_init (&b4, NULL, 4) != 0)
    {
      puts ("barrier_init failed");
      exit (1);
    }

  for (unsigned long int testno = 0;
       testno < sizeof (setuid_tests) / sizeof (setuid_tests[0]);
       ++testno)
    do_one_test (testno);
  return 0;
}

Here is the call graph for this function:

static void test_setegid1 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 547 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_gid (tno);

  if (action == SET && setegid (nobody_gid) < 0)
    {
       printf ("setegid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      gid_t rgid, egid, sgid;
      if (getresgid (&rgid, &egid, &sgid) < 0)
       {
         printf ("getresgid failed: %d %m\n", tno);
         exit (1);
       }

      if (rgid != prev_rgid || egid != nobody_gid || sgid != prev_sgid)
       {
         printf ("after setegid %d (%d %d %d) != (%d %d %d)\n", tno,
                rgid, egid, sgid, prev_rgid, nobody_gid, prev_sgid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_setegid2 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 581 of file tst-setuid1.c.

{
  if (action == PREPARE)
    {
      if (setresgid (nobody_gid, nobody_gid, -1) < 0)
       {
         printf ("setresgid failed: %m\n");
         exit (1);
       }

      prev_rgid = nobody_gid;
      prev_egid = nobody_gid;
      nobody_gid = prev_sgid;
      return;
    }

  test_setegid1 (action, tno);
}

Here is the call graph for this function:

static void test_seteuid1 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 154 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_uid (tno);

  if (action == SET && seteuid (nobody_uid) < 0)
    {
       printf ("seteuid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      uid_t ruid, euid, suid;
      if (getresuid (&ruid, &euid, &suid) < 0)
       {
         printf ("getresuid failed: %d %m\n", tno);
         exit (1);
       }

      if (ruid != prev_ruid || euid != nobody_uid || suid != prev_suid)
       {
         printf ("after seteuid %d (%d %d %d) != (%d %d %d)\n", tno,
                ruid, euid, suid, prev_ruid, nobody_uid, prev_suid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_seteuid2 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 188 of file tst-setuid1.c.

{
  if (action == PREPARE)
    {
      if (setresuid (nobody_uid, nobody_uid, -1) < 0)
       {
         printf ("setresuid failed: %m\n");
         exit (1);
       }

      prev_ruid = nobody_uid;
      prev_euid = nobody_uid;
      nobody_uid = prev_suid;
      return;
    }

  test_seteuid1 (action, tno);
}

Here is the call graph for this function:

static void test_setgid1 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 460 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_gid (tno);

  if (action == SET && setgid (nobody_gid) < 0)
    {
       printf ("setgid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      gid_t rgid, egid, sgid;
      if (getresgid (&rgid, &egid, &sgid) < 0)
       {
         printf ("getresgid failed: %d %m\n", tno);
         exit (1);
       }

      if (rgid != nobody_gid || egid != nobody_gid || sgid != nobody_gid)
       {
         printf ("after setgid %d (%d %d %d) != (%d %d %d)\n", tno,
                rgid, egid, sgid, nobody_gid, nobody_gid, nobody_gid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setgid2 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 494 of file tst-setuid1.c.

{
  if (action == PREPARE)
    {
      if (setresgid (nobody_gid, nobody_gid, -1) < 0)
       {
         printf ("setresgid failed: %m\n");
         exit (1);
       }

      prev_rgid = nobody_gid;
      prev_egid = nobody_gid;

      if (setresuid (nobody_uid, nobody_uid, -1) < 0)
       {
         printf ("setresuid failed: %m\n");
         exit (1);
       }

      prev_ruid = nobody_uid;
      prev_euid = nobody_uid;
      return;
    }

  if (action != CHECK_AFTER)
    check_prev_gid (tno);

  if (action == SET && setgid (prev_sgid) < 0)
    {
      printf ("setgid failed: %m\n");
      exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      gid_t rgid, egid, sgid;
      if (getresgid (&rgid, &egid, &sgid) < 0)
       {
         printf ("getresgid failed: %d %m\n", tno);
         exit (1);
       }

      if (rgid != nobody_gid || egid != prev_sgid || sgid != prev_sgid)
       {
         printf ("after setgid %d (%d %d %d) != (%d %d %d)\n", tno,
                rgid, egid, sgid, nobody_gid, prev_sgid, prev_sgid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setregid1 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 602 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_gid (tno);

  if (action == SET && setregid (-1, nobody_gid) < 0)
    {
       printf ("setregid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      gid_t rgid, egid, sgid, esgid;
      if (getresgid (&rgid, &egid, &sgid) < 0)
       {
         printf ("getresgid failed: %d %m\n", tno);
         exit (1);
       }

      if (prev_rgid != nobody_gid)
       esgid = nobody_gid;
      else
       esgid = prev_sgid;

      if (rgid != prev_rgid || egid != nobody_gid || sgid != esgid)
       {
         printf ("after setregid %d (%d %d %d) != (%d %d %d)\n", tno,
                rgid, egid, sgid, prev_rgid, nobody_gid, esgid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_setregid2 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 641 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_gid (tno);

  if (action == SET && setregid (nobody_gid, -1) < 0)
    {
       printf ("setregid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      gid_t rgid, egid, sgid;
      if (getresgid (&rgid, &egid, &sgid) < 0)
       {
         printf ("getresgid failed: %d %m\n", tno);
         exit (1);
       }

      if (rgid != nobody_gid || egid != prev_egid || sgid != prev_egid)
       {
         printf ("after setregid %d (%d %d %d) != (%d %d %d)\n", tno,
                rgid, egid, sgid, nobody_gid, prev_egid, prev_egid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setregid3 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 675 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_gid (tno);

  if (action == SET && setregid (nobody_gid, nobody_gid) < 0)
    {
       printf ("setregid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      gid_t rgid, egid, sgid;
      if (getresgid (&rgid, &egid, &sgid) < 0)
       {
         printf ("getresgid failed: %d %m\n", tno);
         exit (1);
       }

      if (rgid != nobody_gid || egid != nobody_gid || sgid != nobody_gid)
       {
         printf ("after setregid %d (%d %d %d) != (%d %d %d)\n", tno,
                rgid, egid, sgid, nobody_gid, nobody_gid, nobody_gid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setregid4 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 709 of file tst-setuid1.c.

{
  if (action == PREPARE)
    {
      if (setresgid (nobody_gid, nobody_gid, -1) < 0)
       {
         printf ("setresgid failed: %m\n");
         exit (1);
       }

      prev_rgid = nobody_gid;
      prev_egid = nobody_gid;
      nobody_gid = prev_sgid;
      return;
    }

  test_setregid1 (action, tno);
}

Here is the call graph for this function:

static void test_setresgid1 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 730 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_gid (tno);

  if (action == SET && setresgid (-1, nobody_gid, -1) < 0)
    {
       printf ("setresgid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      gid_t rgid, egid, sgid;
      if (getresgid (&rgid, &egid, &sgid) < 0)
       {
         printf ("getresgid failed: %d %m\n", tno);
         exit (1);
       }

      if (rgid != prev_rgid || egid != nobody_gid || sgid != prev_sgid)
       {
         printf ("after setresgid %d (%d %d %d) != (%d %d %d)\n", tno,
                rgid, egid, sgid, prev_rgid, nobody_gid, prev_sgid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_setresgid2 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 764 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_gid (tno);

  if (action == SET && setresgid (prev_egid, nobody_gid, nobody_gid) < 0)
    {
       printf ("setresgid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      gid_t rgid, egid, sgid;
      if (getresgid (&rgid, &egid, &sgid) < 0)
       {
         printf ("getresgid failed: %d %m\n", tno);
         exit (1);
       }

      if (rgid != prev_egid || egid != nobody_gid || sgid != nobody_gid)
       {
         printf ("after setresgid %d (%d %d %d) != (%d %d %d)\n", tno,
                rgid, egid, sgid, prev_egid, nobody_gid, nobody_gid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setresgid3 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 798 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_gid (tno);

  if (action == SET && setresgid (nobody_gid, nobody_gid, nobody_gid) < 0)
    {
       printf ("setresgid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      gid_t rgid, egid, sgid;
      if (getresgid (&rgid, &egid, &sgid) < 0)
       {
         printf ("getresgid failed: %d %m\n", tno);
         exit (1);
       }

      if (rgid != nobody_gid || egid != nobody_gid || sgid != nobody_gid)
       {
         printf ("after setresgid %d (%d %d %d) != (%d %d %d)\n", tno,
                rgid, egid, sgid, nobody_gid, nobody_gid, nobody_gid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setresgid4 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 832 of file tst-setuid1.c.

{
  if (action == PREPARE)
    {
      if (setresgid (nobody_gid, nobody_gid, -1) < 0)
       {
         printf ("setresgid failed: %m\n");
         exit (1);
       }

      prev_rgid = nobody_gid;
      prev_egid = nobody_gid;
      nobody_gid = prev_sgid;
      return;
    }

  test_setresgid1 (action, tno);
}

Here is the call graph for this function:

static void test_setresuid1 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 337 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_uid (tno);

  if (action == SET && setresuid (-1, nobody_uid, -1) < 0)
    {
       printf ("setresuid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      uid_t ruid, euid, suid;
      if (getresuid (&ruid, &euid, &suid) < 0)
       {
         printf ("getresuid failed: %d %m\n", tno);
         exit (1);
       }

      if (ruid != prev_ruid || euid != nobody_uid || suid != prev_suid)
       {
         printf ("after setresuid %d (%d %d %d) != (%d %d %d)\n", tno,
                ruid, euid, suid, prev_ruid, nobody_uid, prev_suid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_setresuid2 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 371 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_uid (tno);

  if (action == SET && setresuid (prev_euid, nobody_uid, nobody_uid) < 0)
    {
       printf ("setresuid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      uid_t ruid, euid, suid;
      if (getresuid (&ruid, &euid, &suid) < 0)
       {
         printf ("getresuid failed: %d %m\n", tno);
         exit (1);
       }

      if (ruid != prev_euid || euid != nobody_uid || suid != nobody_uid)
       {
         printf ("after setresuid %d (%d %d %d) != (%d %d %d)\n", tno,
                ruid, euid, suid, prev_euid, nobody_uid, nobody_uid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setresuid3 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 405 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_uid (tno);

  if (action == SET && setresuid (nobody_uid, nobody_uid, nobody_uid) < 0)
    {
       printf ("setresuid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      uid_t ruid, euid, suid;
      if (getresuid (&ruid, &euid, &suid) < 0)
       {
         printf ("getresuid failed: %d %m\n", tno);
         exit (1);
       }

      if (ruid != nobody_uid || euid != nobody_uid || suid != nobody_uid)
       {
         printf ("after setresuid %d (%d %d %d) != (%d %d %d)\n", tno,
                ruid, euid, suid, nobody_uid, nobody_uid, nobody_uid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setresuid4 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 439 of file tst-setuid1.c.

{
  if (action == PREPARE)
    {
      if (setresuid (nobody_uid, nobody_uid, -1) < 0)
       {
         printf ("setresuid failed: %m\n");
         exit (1);
       }

      prev_ruid = nobody_uid;
      prev_euid = nobody_uid;
      nobody_uid = prev_suid;
      return;
    }

  test_setresuid1 (action, tno);
}

Here is the call graph for this function:

static void test_setreuid1 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 209 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_uid (tno);

  if (action == SET && setreuid (-1, nobody_uid) < 0)
    {
       printf ("setreuid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      uid_t ruid, euid, suid, esuid;
      if (getresuid (&ruid, &euid, &suid) < 0)
       {
         printf ("getresuid failed: %d %m\n", tno);
         exit (1);
       }

      if (prev_ruid != nobody_uid)
       esuid = nobody_uid;
      else
       esuid = prev_suid;

      if (ruid != prev_ruid || euid != nobody_uid || suid != esuid)
       {
         printf ("after setreuid %d (%d %d %d) != (%d %d %d)\n", tno,
                ruid, euid, suid, prev_ruid, nobody_uid, esuid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_setreuid2 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 248 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_uid (tno);

  if (action == SET && setreuid (nobody_uid, -1) < 0)
    {
       printf ("setreuid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      uid_t ruid, euid, suid;
      if (getresuid (&ruid, &euid, &suid) < 0)
       {
         printf ("getresuid failed: %d %m\n", tno);
         exit (1);
       }

      if (ruid != nobody_uid || euid != prev_euid || suid != prev_euid)
       {
         printf ("after setreuid %d (%d %d %d) != (%d %d %d)\n", tno,
                ruid, euid, suid, nobody_uid, prev_euid, prev_euid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setreuid3 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 282 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_uid (tno);

  if (action == SET && setreuid (nobody_uid, nobody_uid) < 0)
    {
       printf ("setreuid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      uid_t ruid, euid, suid;
      if (getresuid (&ruid, &euid, &suid) < 0)
       {
         printf ("getresuid failed: %d %m\n", tno);
         exit (1);
       }

      if (ruid != nobody_uid || euid != nobody_uid || suid != nobody_uid)
       {
         printf ("after setreuid %d (%d %d %d) != (%d %d %d)\n", tno,
                ruid, euid, suid, nobody_uid, nobody_uid, nobody_uid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setreuid4 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 316 of file tst-setuid1.c.

{
  if (action == PREPARE)
    {
      if (setresuid (nobody_uid, nobody_uid, -1) < 0)
       {
         printf ("setresuid failed: %m\n");
         exit (1);
       }

      prev_ruid = nobody_uid;
      prev_euid = nobody_uid;
      nobody_uid = prev_suid;
      return;
    }

  test_setreuid1 (action, tno);
}

Here is the call graph for this function:

static void test_setuid1 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 76 of file tst-setuid1.c.

{
  if (action == PREPARE)
    return;

  if (action != CHECK_AFTER)
    check_prev_uid (tno);

  if (action == SET && setuid (nobody_uid) < 0)
    {
       printf ("setuid failed: %m\n");
       exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      uid_t ruid, euid, suid;
      if (getresuid (&ruid, &euid, &suid) < 0)
       {
         printf ("getresuid failed: %d %m\n", tno);
         exit (1);
       }

      if (ruid != nobody_uid || euid != nobody_uid || suid != nobody_uid)
       {
         printf ("after setuid %d (%d %d %d) != (%d %d %d)\n", tno,
                ruid, euid, suid, nobody_uid, nobody_uid, nobody_uid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void test_setuid2 ( enum ACTION  action,
int  tno 
) [static]

Definition at line 110 of file tst-setuid1.c.

{
  if (action == PREPARE)
    {
      if (setresuid (nobody_uid, nobody_uid, -1) < 0)
       {
         printf ("setresuid failed: %m\n");
         exit (1);
       }

      prev_ruid = nobody_uid;
      prev_euid = nobody_uid;
      return;
    }

  if (action != CHECK_AFTER)
    check_prev_uid (tno);

  if (action == SET && setuid (prev_suid) < 0)
    {
      printf ("setuid failed: %m\n");
      exit (1);
    }

  if (action != CHECK_BEFORE)
    {
      uid_t ruid, euid, suid;
      if (getresuid (&ruid, &euid, &suid) < 0)
       {
         printf ("getresuid failed: %d %m\n", tno);
         exit (1);
       }

      if (ruid != nobody_uid || euid != prev_suid || suid != prev_suid)
       {
         printf ("after setuid %d (%d %d %d) != (%d %d %d)\n", tno,
                ruid, euid, suid, nobody_uid, prev_suid, prev_suid);
         exit (1);
       }
    }
}

Here is the call graph for this function:

static void* tf ( void *  arg) [static]

Definition at line 901 of file tst-setuid1.c.

{
  setuid_tests[TESTNO (arg)].test (CHECK_BEFORE, THREADNO (arg));

  int e = pthread_barrier_wait (&b3);
  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      puts ("barrier_wait failed");
      exit (1);
    }

  return tf2 (arg);
}

Here is the call graph for this function:

static void* tf2 ( void *  arg) [static]

Definition at line 886 of file tst-setuid1.c.

{
  int e = pthread_barrier_wait (&b4);
  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      puts ("barrier_wait failed");
      exit (1);
    }

  setuid_tests[TESTNO (arg)].test (CHECK_AFTER, THREADNO (arg));
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

pthread_barrier_t b3 [static]

Definition at line 29 of file tst-setuid1.c.

pthread_barrier_t b4 [static]

Definition at line 29 of file tst-setuid1.c.

gid_t nobody_gid [static]

Definition at line 31 of file tst-setuid1.c.

uid_t nobody_uid [static]

Definition at line 30 of file tst-setuid1.c.

gid_t prev_egid [static]

Definition at line 31 of file tst-setuid1.c.

uid_t prev_euid [static]

Definition at line 30 of file tst-setuid1.c.

gid_t prev_rgid [static]

Definition at line 31 of file tst-setuid1.c.

uid_t prev_ruid [static]

Definition at line 30 of file tst-setuid1.c.

gid_t prev_sgid [static]

Definition at line 31 of file tst-setuid1.c.

uid_t prev_suid [static]

Definition at line 30 of file tst-setuid1.c.

struct setuid_test setuid_tests[] [static]