Ejemplo n.º 1
0
int
main(int argc, char* argv[])
{
  if (argc < 3) {
    show_usage();
    return 1;
  }

  if (argc < 4) {
    if (strcmp(argv[1], "-reap") == 0) {
      int REAP_UID = atoi(argv[2]);
      setreuid(0, 0);
      reap_user(REAP_UID);
      return 0;
    }

    if (strcmp(argv[1], "-teardown") == 0) {
      setreuid(0, 0);
      chdir(argv[2]);
      system(DIR_TEARDOWN_CMD);
      return 0;
    }

    show_usage();
    return 1;
  }

  const char* DIR = argv[1];
  int         UID = atoi(argv[2]);
  const char* KEY = argv[3];

  if (DIR[0] == '-') {
    show_usage();
    return 1;
  }

  setlinebuf(stdout);
  setreuid(0, 0);

  chdir(DIR);
  system(DIR_SETUP_CMD);
 
  printf("\n== Building assignment. ==\n\n");
  run_in_sandbox(UID, START_MAKE_CMD);

  printf("\n== Testing assignment. ==\n\n");
  system(GRADING_PREP_CMD);
  printf("%s\n", KEY);
  run_in_sandbox(UID, START_TEST_CMD);
  printf("%s\n", KEY);

  reap_user(UID);  
  system(DIR_TEARDOWN_CMD);

  return 0;
}
Ejemplo n.º 2
0
int
main(int argc, char* argv[])
{
    if (argc < 3) {
        show_usage();
        return 1;
    }
    
    if (argc < 4) {
        if (strcmp(argv[1], "-reap") == 0) {
            int REAP_UID = atoi(argv[2]);
            setreuid(0, 0);
            reap_user(REAP_UID);
            return 0;
        }
        
        if (strcmp(argv[1], "-teardown") == 0) {
            setreuid(0, 0);
            chdir(argv[2]);
            system(DIR_TEARDOWN_CMD);
            return 0;
        }
        
        show_usage();
        return 1;
    }
    
    const char* DIR = argv[1];
    int         UID = atoi(argv[2]);
    const char* KEY = argv[3];
    
    if (DIR[0] == '-') {
        show_usage();
        return 1;
    }
    
    setlinebuf(stdout);
    setreuid(0, 0);
    
    int fail = 0;
    int rv = 0;
   
    printf("\n== Setting up directory ==\n\n");
    chdir(DIR);
    rv = system(DIR_SETUP_CMD);
    if (WEXITSTATUS(rv) != 0) {
        fail = 1;
        printf("Bad return from DIR_SETUP_CMD\n");
        goto done;
    }
    
    printf("\n== Building assignment. ==\n\n");
    fail = run_in_sandbox(UID, START_MAKE_CMD);
    if (fail) {
        printf("Bad return from START_MAKE_CMD\n");
        goto done;
    }
    
    printf("\n== Testing assignment. ==\n\n");
    rv = system(GRADING_PREP_CMD);
    if (WEXITSTATUS(rv) != 0) {
        fail = 1;
        printf("Bad return from GRADING_PREP_CMD\n");
        goto done;
    }
    
    printf("%s\n", KEY);
    fail = run_in_sandbox(UID, START_TEST_CMD);
    if (fail) {
        printf("Bad return from START_TEST_CMD\n");
        goto done;
    }
    
    printf("%s\n", KEY);
    
done:
    reap_user(UID);  
    system(DIR_TEARDOWN_CMD);
    
    return fail;
}