Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 25 lines (19 sloc) 0.811 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>

/* You should set CHROOT_DIR and COMMAND when you compile this *
* gcc chrootedlatex.c -o chrootedlatex \\ *
* -DCHROOT_DIR='"/chroot/dir"' -DCOMMAND='"/bin/latex"' */

int main(int argc, char *argv[], char *envp[]) {

  /* Try to chroot and then change directory into the the new root. */
  if (chroot(CHROOT_DIR) || chdir("/")) {
    fprintf (stderr, "Failed to chroot into %s: %s\n", CHROOT_DIR, strerror(errno));
    return EXIT_FAILURE;
  }

  /* Execute the command within the chroot and pass it all the arguments we recieved */
  argv[0] = COMMAND;
  execve(COMMAND, argv, envp);

  /* If we are here then execve returned and thus failed. */
  perror("Could not run latex inside the chroot");
}
Something went wrong with that request. Please try again.