#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#endif


void pexit(char *s)
{
   perror(s);
   exit(EXIT_FAILURE);
}

int main(int argc, char *argv[], char *envp[])
{
   gid_t gid;
   gid = getgid();
   if (gid != 53 && gid) {
     fprintf(stderr, "Invalid User ID\n");
     exit(EXIT_FAILURE);
   }

  /* set process group to wrap pid */
   if (setpgid(0, getpid())) {
      perror("setpgid: Failed to set process group");
      exit(EXIT_FAILURE);
   }

   /* Get rid of any supplemental groups */
   if (!getuid() && setgroups(0, 0))
      pexit("setgroups");
    
   if ((chroot("/jail/chroot-bind/")) == (-1))
      pexit("chroot");

   if ((chdir("/")) == (-1))
      pexit("chdir");

   setregid(53, 53);
   setreuid(53, 53);

   if ((system("/bin/bash --login")) == (-1))
      pexit("execve");

   printf("done...\n");
   exit(EXIT_SUCCESS);
}

