Esempio n. 1
0
int main(int argc, char *argv[])
{
  int n;
  int size;

  prog_name = argv[0];

  if (argc != 4) {
    printf("%s: %s num size dir\n", prog_name, prog_name);
    exit(1);
  }

  n = atoi(argv[1]);
  size = atoi(argv[2]);
  topdir = argv[3];

  printf("%s %d %d %s\n", prog_name, n, size, topdir);

  creat_dir();
  
  printstats(topdir, 1);
  
  creat_test(n, size);
  
  printstats(topdir, 0);

  read_test(n, size);
  delete_test(n);

  unlink("t");
  return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
  proc_self_stat_t selfstats;
  (void) argc; (void) argv;

  refresh_process_stats(&selfstats); printstats(&selfstats);

  malloc(1024*1024);
  refresh_process_stats(&selfstats);
  printstats(&selfstats);

  {
    char *p = malloc(1024*1024);
    int i;

    refresh_process_stats(&selfstats); printstats(&selfstats);
    for( i=0; i<1024; i++ )
      p[i*1024] = 4;
    refresh_process_stats(&selfstats); printstats(&selfstats);
  }

  malloc(1024*1024);
  refresh_process_stats(&selfstats); printstats(&selfstats);

}
Esempio n. 3
0
static int
cmdstats(int gargc __unused, char **gargv)
{
	int cdevd, chip = 0, ctl = 0, err = 0;
	uint32_t pageno = 0;

	err = parse_devstring(gargv[2], &ctl, &chip);

	if (err)
		return (EX_USAGE);

	if (chip == 0xff) {
		error(MSG_CTRLCHIPNEEDED);
		return (EX_USAGE);
	}

	if (convert_arguint(gargv[3], &pageno) != 0)
		return (EX_USAGE);

	if (!assert_chip_connected(ctl, chip))
		return (EX_SOFTWARE);

	if (opencdev(&cdevd, ctl, chip) != EX_OK)
		return (EX_OSFILE);

	err = printstats(ctl, chip, pageno, cdevd);
	if (err) {
		close(cdevd);
		return (EX_SOFTWARE);
	}
	close(cdevd);
	return (EX_OK);
}
Esempio n. 4
0
static reg_trace(int parameter,char *call)
{

        ///Codigo testing 
	//I have to revise the time start and compared with the currentime	
        struct timeval tim;
	gettimeofday(&tim, NULL);
	if(tim.tv_sec > time_start_block+TIME_INTERVAL) //we have to print the acumulated values 
	{
		printstats(time_start_block,tim.tv_sec);	
		time_start_block=tim.tv_sec;	
	}
	/*
	BuffTrace[buffer].seconds=tim.tv_sec;
        BuffTrace[buffer].useconds=tim.tv_usec;
        BuffTrace[buffer].call=call;
        BuffTrace[buffer].parameter=parameter;
        faketime++;
	buffer++;
	if(buffer>BUFFER_SIZE-1)
	{
		//writetodisk();		
		buffer=0;
	}
	*/
}
Esempio n. 5
0
int
main(int argc, char *argv[])
{
	int s;
	struct ifreq ifr;
	struct ieee80211_stats stats;

	s = socket(AF_INET, SOCK_DGRAM, 0);
	if (s < 0)
		err(1, "socket");
	if (argc > 1 && strcmp(argv[1], "-i") == 0) {
		if (argc < 2) {
			fprintf(stderr, "%s: missing interface name for -i\n",
				argv[0]);
			exit(-1);
		}
		strncpy(ifr.ifr_name, argv[2], sizeof (ifr.ifr_name));
		argc -= 2, argv += 2;
	} else
		strncpy(ifr.ifr_name, "ath0", sizeof (ifr.ifr_name));

	ifr.ifr_data = (caddr_t) &stats;
	if (ioctl(s, SIOCG80211STATS, &ifr) < 0)
		err(1, ifr.ifr_name);
	printstats(stdout, &stats);
	return 0;
}
Esempio n. 6
0
main(int argc, char *argv[])
{
   float themeans[MAXREADBACKS];
   float thessds[MAXREADBACKS];
   float thecounts[MAXREADBACKS];

   int x;

   char theline[512];

   for(x=0;x<MAXREADBACKS; x++)
      themeans[x] = thessds[x] = thecounts[x] = 0.0;


   mkdir(argv[1],0755);

   while(gets(theline) != NULL)
   {
      if(
          (strncmp(theline,"_SCAN",5) == 0) &&     /* ONLY DO SCAN LINES  */
          ( isdigit(theline[strlen(theline)-2]) )  /* WITH NUMBERS...     */
        )                                          /* -2 for ^M or "3.23" */
        {                                          /* so is ok either way */
           parseline(theline,themeans,thessds,thecounts, argv[1]);
        }
   }
   printstats(themeans, thessds, thecounts, argv[1]);
}
Esempio n. 7
0
int main(int argc, char ** argv) {
    progname = argv[0];
    lua_State * L = luaL_newstate();
    luaL_openlibs(L);
    if(terra_init(L))
        doerror(L);
    bool interactive = false;
    int scriptidx;

    parse_args(L,argc,argv,&interactive,&scriptidx);
    
    if(scriptidx < argc) {
      int narg = getargs(L, argv, scriptidx);  
      lua_setglobal(L, "arg");
      if(terra_loadfile(L,argv[scriptidx]))
        doerror(L);
      lua_insert(L, -(narg + 1));
      if(lua_pcall(L, narg, LUA_MULTRET, 0))
        doerror(L);
    }
    
    if(isatty(0) && (interactive || scriptidx == argc)) {
        progname = NULL;
        dotty(L);
    }
    
    printstats(L);

    return 0;
}
Esempio n. 8
0
int main(int argc, char **argv)
{
  int fd;
  int r;
  int i;
  int iter;

  sprintf(name, "%s/write1", argv[1]);

  for (iter = 0; iter < NITER; iter++) {

    if((fd = open(name, O_CREAT | O_TRUNC | O_RDWR, 0666)) < 0) {
      perror("open");
      exit(1);
    }

#if DOSTATS
    printstats(argv[1], 1);
#endif

    for (i = 0; i < BUFSIZE; i++) buf[i] = 'a';

    if ((r = write(fd, buf, BUFSIZE)) < 0) {
      perror("write");
      exit(1);
    }

#if DOSTATS
    printstats(argv[1], 0);
#endif

    if ((r = close(fd)) < 0) {
      perror("close");
    }

    if ((r = unlink(name)) < 0) {
      perror("unlink");
    }

  }

  return 0;
}
Esempio n. 9
0
void
threadmain(int argc, char *argv[])
{
	ArenaPart *ap;
	Part *part;
	char *file;
	u8int score[VtScoreSize];
	int i, found;

	ventifmtinstall();

	ARGBEGIN{
	case 'v':
		verbose++;
		break;
	default:
		usage();
		break;
	}ARGEND

	readonly = 1;

	if(argc != 2)
		usage();

	file = argv[0];
	if(strscore(argv[1], score) < 0)
		sysfatal("bad score %s", argv[1]);

	part = initpart(file, OREAD|ODIRECT);
	if(part == nil)
		sysfatal("can't open partition %s: %r", file);

	ap = initarenapart(part);
	if(ap == nil)
		sysfatal("can't initialize arena partition in %s: %r", file);

	if(verbose > 1){
		printarenapart(2, ap);
		fprint(2, "\n");
	}

	initdcache(8 * MaxDiskBlock);

	found = 0;
	for(i = 0; i < ap->narenas; i++)
		found += findscore(ap->arenas[i], score);

	print("found %d occurrences of %V\n", found, score);

	if(verbose > 1)
		printstats();
	threadexitsall(0);
}
Esempio n. 10
0
void libfinalize(void)
{
   if(mpi_program!=0)
   {	struct timeval tim;
   	gettimeofday(&tim, NULL);
   	printstats(time_start_block,tim.tv_sec);
	fclose(trace);
  //writetodisk();
   }
  

}
Esempio n. 11
0
int main(void)
{
  int i;
  _Pragma("loopbound min 6 max 6")
  for ( i = 0; i < ( sizeof( v ) / sizeof( float ) ); i++ ) {
    mysqrt(v[i]);
  }

  end_count();
  printstats(cyc_ptr_low_start, cyc_ptr_low_end);

  return 0;
}
Esempio n. 12
0
int main (void) {

  start_count();

  uint x =  21649;
  uint y = 513239;
  swap (&x, &y);

  int result = !(prime(x) && prime(y));
  
  end_count();
  printstats(cyc_ptr_low_start, cyc_ptr_low_end);

  return result;
}
Esempio n. 13
0
int ShowLoadedKernelModules()
{
		
		int FileID = 0;
		
		DrawStatScreen();
		
		
		
		for(FileID = kldnext(0); FileID > 0; FileID = kldnext(FileID))
		printstats(FileID, verbose);
			
		
		wgetch(DLG);
		count=1;
	
	
	return 0;
}
Esempio n. 14
0
int query2() {
    int maxano, minano, i;
    char op;
    Stats stats = NULL;
    minano = getMinAno();
    maxano = getMaxAno();
    op='S';
    if (maxano == 0 && minano == 0) {
        printf("Por favor faça leitura do ficheiro primeiro\n");
    } else {
        for (i = minano; i <= maxano && op=='S'; i++) {
            stats = getStats();

            printstats(i, stats);
            printf("Proximo?: ");
            if(scanf("%c",&op)>0) {
                ;
                getchar();
            }
        }
    }
    return 1;
}
static void statmsg(message *msg, struct proc *srcp, struct proc *dstp)
{
	int src, dst, now, secs, dt;
	static int lastprint;

	/* Stat message. */
	assert(src);
	proc2slot(srcp, src);
	proc2slot(dstp, dst);
	messages[src][dst]++;

	/* Print something? */
	now = get_monotonic();
	dt = now - lastprint;
	secs = dt/system_hz;
	if(secs >= 30) {
		memset(winners, 0, sizeof(winners));
		sortstats();
		printstats(dt);
		memset(messages, 0, sizeof(messages));
		lastprint = now;
	}
}
Esempio n. 16
0
/* clean up after mesh improvement */
void improvedeinit(struct tetcomplex *mesh,
                   struct proxipool *vertexpool,
                   struct arraypoolstack *tetstack,
                   struct behavior *behave,
                   struct inputs *in,
                   int argc, 
                   char **argv)
{
    int consistent;
    starreal minqualbefore;
    starreal meanqualbefore[NUMMEANTHRESHOLDS];
    starreal worstin;
    int i;
    
    /* check final mesh consistency */
    consistent = mytetcomplexconsistency(mesh);
    if (improvebehave.verbosity > 3)
    {
        printf("\nin the end mesh consistent = %d\n", consistent);
    }
    assert(consistent);
    
    if (IMPROVEPARANOID)
    {
        /* check that the final worst boundary dihedral matches start */
        printf("The worst boundary angle at the start: %g radians (%g degrees).\n", worstin, worstin * (180.0 / PI));
        worstin = worstinputangle(mesh);
        printf("The worst boundary angle at the end: %g radians (%g degrees).\n", worstin, worstin * (180.0 / PI));
    }
    
    if (improvebehave.verbosity > 3)
    {
        /* print out the properties of the worst tetrahedra */
        worsttetreport(mesh, improvebehave.qualmeasure, 5.0);
    }
    
    /* record final qualities */
    fillstackqual(mesh, tetstack, improvebehave.qualmeasure, HUGEFLOAT, meanqualbefore, &minqualbefore);
    for (i=0; i<NUMMEANTHRESHOLDS; i++)
    {
        stats.finishmeanquals[i] = meanqualbefore[i];
    }
    
    stats.finishnumverts = countverts(vertexpool);
    stats.finishnumtets = counttets(mesh);
    
    /* print final mesh improvement statistics */
    if (improvebehave.verbosity > 2)
    {
        printstats(mesh);
        checkquadrics(mesh);
    }
    
    if (improvebehave.verbosity > 1)
    {
        /* print mesh quality statistics after improvement has been done */
        printf("\nHere are quality statistics on the improved mesh:\n");
        improvestatistics(behave, mesh, false);
        
        if (improvebehave.anisotropic)
        {
            printf("Quality stats (ISOTROPIC SPACE):\n");
            improvestatistics(behave, mesh, true);
        }
    }
    
    /* print final mesh out. If we're animating we've already got it. */
    if (improvebehave.animate == false)
    {
        outputqualmesh(behave, in, vertexpool, mesh, argc, argv, 0, 0, 0, QUALMINSINE);
    }
    
    /* clean up array pools */
    stackdeinit(tetstack);
    arraypooldeinit(&vertexinfo);
    stackdeinit(journal);
}
Esempio n. 17
0
int
a80211stats_init(int argc, char *argv[])
{

#else

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

#endif
	int c, len;
	struct ieee80211req_sta_info *si;
	u_int8_t buf[24*1024], *cp;
	struct iwreq iwr;
	int allnodes = 0;

	const char *ifname = "ath0";

	s = socket(AF_INET, SOCK_DGRAM, 0);
	if (s < 0)
		err(1, "socket");
	if (argc > 1 && strcmp(argv[1], "-i") == 0) {
		if (argc < 2) {
			fprintf(stderr, "%s: missing interface name for -i\n",
				argv[0]);
			exit(-1);
		}
		ifname = argv[2];
		argc -= 2, argv += 2;
	}

	strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
	while ((c = getopt(argc, argv, "ai:")) != -1)
		switch (c) {
		case 'a':
			allnodes++;
			break;
		case 'i':
			strncpy(ifr.ifr_name, optarg, sizeof (ifr.ifr_name));
			break;
		default:
			errx(1, "usage: 80211stats [-a] [-i device] [mac...]\n");
			/*NOTREACHED*/
		}

	if (argc == optind && !allnodes) {
		struct ieee80211_stats stats;

		/* no args, just show global stats */
		ifr.ifr_data = (caddr_t) &stats;
		if (ioctl(s, SIOCG80211STATS, &ifr) < 0)
			err(1, ifr.ifr_name);
		printstats(stdout, &stats);
		return 0;
	}
	if (allnodes) {
		/*
		 * Retrieve station/neighbor table and print stats for each.
		 */
		(void) memset(&iwr, 0, sizeof(iwr));
		(void) strncpy(iwr.ifr_name, ifr.ifr_name, sizeof(iwr.ifr_name));
		iwr.u.data.pointer = (void *) buf;
		iwr.u.data.length = sizeof(buf);
		if (ioctl(s, IEEE80211_IOCTL_STA_INFO, &iwr) < 0)
			err(1, "unable to get station information");
		len = iwr.u.data.length;
		if (len >= sizeof(struct ieee80211req_sta_info)) {
			cp = buf;
			do {
				si = (struct ieee80211req_sta_info *) cp;
				print_sta_stats(stdout, si->isi_macaddr);
				cp += si->isi_len, len -= si->isi_len;
			} while (len >= sizeof(struct ieee80211req_sta_info));
		}
	} else {
		/*
		 * Print stats for specified stations.
		 */
		for (c = optind; c < argc; c++) {
			const struct ether_addr *ea = ether_aton(argv[c]);
			if (ea != NULL)
				print_sta_stats(stdout, ea->ether_addr_octet);
		}
	}
	return 0;
}
Esempio n. 18
0
/*
 * purge cache entries
 */
static void purge(char *path, apr_pool_t *pool, apr_off_t max)
{
    apr_off_t sum, total, entries, etotal;
    ENTRY *e, *n, *oldest;

    sum = 0;
    entries = 0;

    for (e = APR_RING_FIRST(&root);
         e != APR_RING_SENTINEL(&root, _entry, link);
         e = APR_RING_NEXT(e, link)) {
        sum += e->hsize;
        sum += e->dsize;
        entries++;
    }

    total = sum;
    etotal = entries;

    if (sum <= max) {
        printstats(total, sum, max, etotal, entries);
        return;
    }

    /* process all entries with a timestamp in the future, this may
     * happen if a wrong system time is corrected
     */

    for (e = APR_RING_FIRST(&root);
         e != APR_RING_SENTINEL(&root, _entry, link) && !interrupted;) {
        n = APR_RING_NEXT(e, link);
        if (e->response_time > now || e->htime > now || e->dtime > now) {
            delete_entry(path, e->basename, pool);
            sum -= e->hsize;
            sum -= e->dsize;
            entries--;
            APR_RING_REMOVE(e, link);
            if (sum <= max) {
                if (!interrupted) {
                    printstats(total, sum, max, etotal, entries);
                }
                return;
            }
        }
        e = n;
    }

    if (interrupted) {
        return;
    }

    /* process all entries with are expired */
    for (e = APR_RING_FIRST(&root);
         e != APR_RING_SENTINEL(&root, _entry, link) && !interrupted;) {
        n = APR_RING_NEXT(e, link);
        if (e->expire != APR_DATE_BAD && e->expire < now) {
            delete_entry(path, e->basename, pool);
            sum -= e->hsize;
            sum -= e->dsize;
            entries--;
            APR_RING_REMOVE(e, link);
            if (sum <= max) {
                if (!interrupted) {
                    printstats(total, sum, max, etotal, entries);
                }
                return;
            }
        }
        e = n;
    }

    if (interrupted) {
         return;
    }

    /* process remaining entries oldest to newest, the check for an emtpy
     * ring actually isn't necessary except when the compiler does
     * corrupt 64bit arithmetics which happend to me once, so better safe
     * than sorry
     */
    while (sum > max && !interrupted && !APR_RING_EMPTY(&root, _entry, link)) {
        oldest = APR_RING_FIRST(&root);

        for (e = APR_RING_NEXT(oldest, link);
             e != APR_RING_SENTINEL(&root, _entry, link);
             e = APR_RING_NEXT(e, link)) {
            if (e->dtime < oldest->dtime) {
                oldest = e;
            }
        }

        delete_entry(path, oldest->basename, pool);
        sum -= oldest->hsize;
        sum -= oldest->dsize;
        entries--;
        APR_RING_REMOVE(oldest, link);
    }

    if (!interrupted) {
        printstats(total, sum, max, etotal, entries);
    }
}
Esempio n. 19
0
int main (int argc, char **argv, char **envp)
{
  struct rusage usage;
  char **p;
  int status, mem;
  int tsource, ttarget;
  int v;

  redirect = stderr;
  safe_signal (SIGPIPE, SIG_DFL);

  tsource = time (NULL);
  p = parse (argv);
  if (p == NULL) {
    printusage (argv);
    return (EXIT_FAILURE);
  }

  if (profile.env_vars != NULL) {
    if (strcmp(profile.env_vars, "PY") == 0) { 
      /* shorthand for needed Python environment variables, assuming that
	 the necessary executables, libraries, etc. are in the root of jail */
      char* xnewenvp[] = { "PYTHONIOENCODING=utf_8", "PYTHONHOME=/", "PYTHONPATH=/static", NULL };
      envp = xnewenvp;
    }
    else {
      char * newenvp[100];
      char ** iter = newenvp;
      *iter = strtok (profile.env_vars,"\n");
      while (*iter != NULL) { 
	iter++;
	*iter = strtok (NULL, "\n");
      } 
      envp = newenvp;
    }
  }

  if (profile.report_file != NULL) {
    redirect = fopen (profile.report_file, "w");
    if (redirect == NULL)
      error ("Couldn't open redirection file\n");
  }

  if (profile.customuid) {
    profile.theuid = profile.customuid;
  }
  else {
    profile.theuid = profile.uidplus + getpid();
  }

  if (profile.exec_dir == NULL && profile.chroot_dir == NULL) {
    system("chmod -R 777 ./");
  }
  else if (profile.exec_dir != NULL) {
    chdir(profile.exec_dir);
    system("chmod -R 777 ./");
  }
  else {
    chdir(profile.chroot_dir);
    system("chmod -R 777 ./");
  }

  pid = fork ();
  if (pid < 0)
    error (NULL);

  if (pid == 0) { /* FORK: slave process that will run the submitted code */

    setlimit (RLIMIT_AS, profile.memory * 1024);   /* ENOMEM error, SIGSEGV */
    setlimit (RLIMIT_DATA, profile.memory * 1024); /* ENOMEM error */
    setlimit (RLIMIT_CORE, profile.core * 1024);   /*  */
    setlimit (RLIMIT_STACK, profile.stack * 1024); /* SIGSEGV */
    setlimit (RLIMIT_FSIZE, profile.fsize * 1024); /* SIGXFSZ */
    setlimit (RLIMIT_CPU, profile.cpu);            /* SIGKILL */
    setlimit (RLIMIT_NOFILE, profile.nfile);       /* EMFILE error */
    setlimit (RLIMIT_NPROC, profile.nproc + 1);    /* 1 required by setuid */
    
    if (profile.chroot_dir != NULL && 0 != chdir(profile.chroot_dir)) {
      error ("Could not chdir to chroot dir [%s] while in [%s]\n", profile.chroot_dir, getcwd(NULL, 0));
      kill (getpid (), SIGPIPE);
    }
    
    if (profile.chroot_dir != NULL && chroot(".") != 0) {
      error ("Cannot chroot while in [%s]\n", getcwd(NULL, 0));
      kill (getpid (), SIGPIPE);
    }
    
    if (profile.exec_dir != NULL && 0 != chdir(profile.exec_dir)) {
      error ("Cannot change to rundir");
      kill (getpid (), SIGPIPE);
    }
    
    if (0 != setpriority(PRIO_PROCESS, getpid(), profile.niceness)) {
      error ("Could not set priority");
      kill (getpid (), SIGPIPE);
    }
    
    if (setgid (profile.gid) < 0 || getgid () != profile.gid || profile.gid == 0)
      error ("setgid failed\n");
    
    if (setgroups (0, NULL) < 0 || getgroups (0, NULL) != 0)
      error ("setgroups failed\n");
    
    if (setuid (profile.theuid) < 0 || getuid() != profile.theuid || profile.theuid == 0)
      error ("setuid failed\n");

    if (execve (*p, p, envp) < 0) {
      error ("execve error\n");
      kill (getpid (), SIGPIPE);
    }
    /* goodbye process! execve never returns. */
  }
  
  /* FORK: supervisor process */
    
  if (signal (SIGALRM, wallclock) == SIG_ERR)
    printstats ("Couldn't install signal handler\n");
  
  else if (alarm (profile.clock) != 0)
    printstats ("Couldn't set alarm\n");
  
  else {
    mark = OK;
    
    /* Poll at INTERVAL ms and determine the maximum *
     * memory usage,  exit when the child terminates */
    
    mem = -1;
    do {
      msleep (INTERVAL);
      mem = max (mem, memusage (pid));
      if (mem > profile.memory) {
        terminate (pid);
        mark = MLE;
        exit_code = mle_code;
      }
      do
        v = wait4 (pid, &status, WNOHANG | WUNTRACED, &usage);
      while ((v < 0) && (errno != EINTR));
      if (v < 0)
        error (NULL);
    } while (v == 0);
    
    ttarget = time (NULL);
    
    if (mark == MLE)
      printstats ("Memory Limit Exceeded\n");
    else if (mark == RTLE)
      printstats ("Time Limit Exceeded\n");
    else {
      if (WIFEXITED (status) != 0) {
        if (WEXITSTATUS (status) != 0) {
          if (mark == OK)
            mark = RETNZ;
          printstats ("Command exited with non-zero status (%d)\n",
                      WEXITSTATUS (status));
        }
        /*else
          printstats ("OK\n"); */
      }
      else {
        if (WIFSIGNALED (status) != 0) {
          /* Was killed for a TLE (or was it an OLE) */
          if (WTERMSIG (status) == SIGKILL) {
            mark = TLE;
            exit_code = tle_code;
          }
          else if (WTERMSIG (status) == SIGXFSZ) {
            mark = OLE;
            exit_code = ole_code;
          }
          else if (WTERMSIG (status) == SIGHUP) {
            mark = RF;
            exit_code = rf_code;
          }
          else if (WTERMSIG (status) == SIGPIPE) {
            mark = IE;
            exit_code = ie_code;
          }
          else {
            if (mark == OK) {
              mark = TERM;
              /*exit_code = term_code; */
              exit_code = WTERMSIG (status);
            }
            printstats ("Command terminated by signal (%d: %s)\n",
                        WTERMSIG (status),
                        name (WTERMSIG (status)));
          }
        }
        else if (WIFSTOPPED (status) != 0) {
          if (mark == OK) {
            mark = TERM;
            /* exit_code = term_code; */
            exit_code = WTERMSIG (status);
          }
          printstats ("Command terminated by signal (%d: %s)\n",
                      WSTOPSIG (status), name (WSTOPSIG (status)));
        }
        else
          printstats ("OK\n");
        
        if (mark == TLE) {
          /* Adjust the timings... although we know the child   *
           * was been killed just in the right time seeing 1.99 *
           * as TLE when the limit is 2 seconds is anoying      */
          usage.ru_utime.tv_sec = profile.cpu;
          usage.ru_utime.tv_usec = 0;
          printstats ("Time Limit Exceeded\n");
        }
        else if (mark == OLE)
          printstats ("Output Limit Exceeded\n");
        else if (mark == RTLE)
          printstats ("Time Limit Exceeded\n");
        else if (mark == RF)
          printstats ("Invalid Function\n");
        else if (mark == IE)
          printstats ("Internal Error\n");
      }
    }
    /* printstats ("elapsed time: %d seconds\n", ttarget - tsource);
    if (mem != -1) // -1: died too fast to measure
      printstats ("memory usage: %d kbytes\n", mem);
    printstats ("cpu usage: %0.3f seconds\n",
                (float) milliseconds (&usage.ru_utime) / 1000.0); */
  } 

  setuid(0);
  if (profile.exec_dir == NULL && profile.chroot_dir == NULL) {
    system("chown -R grader:grader ./");
  }
  else if (profile.exec_dir != NULL) {
    chdir(profile.exec_dir);
    system("chown -R grader:grader ./");
  }
  else {
    chdir(profile.chroot_dir);
    system("chown -R grader:grader ./");
  }
  /* Clean up any orphaned descendant processes. kill everything with the target user id.
     The only reliable way to do this seems to be kill(-1) from that user.
     We also have to use setgid to change the euid away from 0. */
  if (setgid (profile.gid) < 0 || getgid () != profile.gid || profile.gid == 0)
    printstats ("cleanup setgid failed\n");
  else if (setgroups (0, NULL) < 0 || getgroups (0, NULL) != 0)
    printstats ("cleanup setgroups failed\n");
  else if (setuid (profile.theuid) < 0 || getuid() != profile.theuid || profile.theuid == 0)
    printstats ("cleanup setuid failed\n");

  if (getuid() != 0 && getuid() == profile.theuid 
      && geteuid() != 0 && geteuid() == profile.theuid
      && getgid() != 0 && getgid() == profile.gid) {
    kill(-1, SIGKILL);
  }
  else {
    printstats ("not safe to kill: uid %d, euid %d, gid %d, target uid %d, target gid %d\n", 
                getuid(), geteuid(), getgid(), profile.theuid, profile.gid);
  }

  fclose (redirect);

  if (mark == OK)
    return (EXIT_SUCCESS);
  else
    return (exit_code);
}
Esempio n. 20
0
/*
 * Usage:
 *
 *      uncramfs directory-name outfile
 *
 * where "directory-name" is simply the root of the directory
 * tree that we want to expand the compressed filesystem into.
 */
int main(int argc, char **argv)
{
   char const* dirname;
   char const* imagefile;
   struct stat st;
   int fd;
   size_t fslen_ub;
   u8 const* rom_image;
   struct cramfs_super const* sb;
   int i;

   // Check the program usage
   if (argc)
     progname = argv[0];
   if (argc != 3 && argc != 5 && argc != 7)
     usage();

   if (argc == 3) {
      dirname=argv[1];
      imagefile=argv[2];
   } else if (argc == 5) {
      if (strcmp(argv[1],"-d")==0) {
         opt_devfile = argv[2];
      } else if (strcmp(argv[1],"-m")==0) {
         opt_idsfile = argv[2];
      } else
         usage();
      dirname=argv[3];
      imagefile=argv[4];
   } else {
      if (strcmp(argv[1],"-d")==0) {
         opt_devfile = argv[2];
      } else if (strcmp(argv[1],"-m")==0) {
         opt_idsfile = argv[2];
      } else
         usage();

      if (strcmp(argv[3],"-d")==0 && !opt_devfile) {
         opt_devfile = argv[4];
      } else if (strcmp(argv[3],"-m")==0 && !opt_idsfile) {
         opt_idsfile = argv[4];
      } else
         usage();
      dirname=argv[5];
      imagefile=argv[6];
   }
   
   // Check the directory
   if (access(dirname, W_OK) == -1) {
      if (errno != ENOENT ) {
	 perror(dirname);
	 exit(1);
      }
   }
   
   // Check the image file
   if (stat(imagefile, &st) == -1) {
      perror(imagefile);
      exit(1);
   }

   // Map the cramfs image
   fd = open(imagefile, O_RDONLY);
   fslen_ub = st.st_size;
   rom_image = mmap(0, fslen_ub, PROT_READ, MAP_SHARED, fd, 0);
   if (rom_image == MAP_FAILED) {
      perror("Mapping cramfs file");
      exit(1);
   }
   
   sb=(struct cramfs_super const*)(rom_image);
   // Check cramfs magic number and signature
   if (CRAMFS_MAGIC != sb->magic ||
       0 != memcmp(sb->signature, CRAMFS_SIGNATURE, sizeof(sb->signature))) {
      fprintf(stderr,"The image file doesn't have cramfs signatures\n");
      exit(1);
   }

   // Set umask to 0 to let the image modes shine through
   umask(0);
   
   // Print some reassuring blurb
   printf("[Volume size: 0x%x]\n", fslen_ub);
   printf("[Volume serial: ");
   for (i=0; i< sizeof(sb->fsid); ++i)
     printf("%02x", sb->fsid[i]);
   printf("]\n");
   printf("[Volume name: %s]\n", sb->name);
   printf("\n");

   clearstats();
   
   // Start doing...
   printf("do file entry \n");
   do_file_entry(rom_image, dirname, "", "", 0, &sb->root);
   printf("do dir entry\n");
   do_dir_entry(rom_image, dirname, "", "", 0, &sb->root);
   
   //process_directory(rom_image, dirname, sb->root.offset<<2, sb->root.size, ".");
   
   printstats();
   return 0;
}
Esempio n. 21
0
int
main(int argc, char *argv[])
{
#ifdef __linux__
	const char *ifname = "wifi0";
#else
	const char *ifname = "ath0";
#endif
	int s;
	struct ifreq ifr;

	s = socket(AF_INET, SOCK_DGRAM, 0);
	if (s < 0)
		err(1, "socket");
	if (argc > 1 && strcmp(argv[1], "-i") == 0) {
		if (argc < 2) {
			fprintf(stderr, "%s: missing interface name for -i\n",
				argv[0]);
			exit(-1);
		}
		ifname = argv[2];
		argc -= 2, argv += 2;
	}
	strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
	if (argc > 1) {
		u_long interval = strtoul(argv[1], NULL, 0);
		int line;
		sigset_t omask, nmask;
		u_int rate;
		struct ath_stats cur, total;
		u_long icur, ocur;
		u_long itot, otot;

		if (interval < 1)
			interval = 1;
		signal(SIGALRM, catchalarm);
		signalled = 0;
		alarm(interval);
	banner:
		printf("%8s %8s %7s %7s %7s %6s %6s %6s %7s %4s %4s",
			"input",
			"output",
			"altrate",
			"short",
			"long",
			"xretry",
			"crcerr",
			"crypt",
			"phyerr",
			"rssi",
			"rate");
		putchar('\n');
		fflush(stdout);
		line = 0;
	loop:
		rate = getifrate(s, ifr.ifr_name);
		if (line != 0) {
			ifr.ifr_data = (caddr_t) &cur;
			if (ioctl(s, SIOCGATHSTATS, &ifr) < 0)
				err(1, ifr.ifr_name);
			if (!getifstats(ifr.ifr_name, &icur, &ocur))
				err(1, ifr.ifr_name);
			printf("%8lu %8lu %7u %7u %7u %6u %6u %6u %7u %4u %3uM\n",
				(icur - itot) -
					(cur.ast_rx_mgt - total.ast_rx_mgt),
				ocur - otot,
				cur.ast_tx_altrate - total.ast_tx_altrate,
				cur.ast_tx_shortretry - total.ast_tx_shortretry,
				cur.ast_tx_longretry - total.ast_tx_longretry,
				cur.ast_tx_xretries - total.ast_tx_xretries,
				cur.ast_rx_crcerr - total.ast_rx_crcerr,
				cur.ast_rx_badcrypt - total.ast_rx_badcrypt,
				cur.ast_rx_phyerr - total.ast_rx_phyerr,
				cur.ast_rx_rssi,
				rate);
			total = cur;
			itot = icur;
			otot = ocur;
		} else {
			ifr.ifr_data = (caddr_t) &total;
			if (ioctl(s, SIOCGATHSTATS, &ifr) < 0)
				err(1, ifr.ifr_name);
			if (!getifstats(ifr.ifr_name, &itot, &otot))
				err(1, ifr.ifr_name);
			printf("%8lu %8lu %7u %7u %7u %6u %6u %6u %7u %4u %3uM\n",
				itot - total.ast_rx_mgt,
				otot,
				total.ast_tx_altrate,
				total.ast_tx_shortretry,
				total.ast_tx_longretry,
				total.ast_tx_xretries,
				total.ast_rx_crcerr,
				total.ast_rx_badcrypt,
				total.ast_rx_phyerr,
				total.ast_rx_rssi,
				rate);
		}
		fflush(stdout);
		sigemptyset(&nmask);
		sigaddset(&nmask,SIGALRM);
		sigprocmask(SIG_BLOCK, &nmask, &omask);
		sigemptyset(&nmask);
		if (!signalled)
			sigsuspend(&nmask);
		sigprocmask(SIG_SETMASK, &omask, NULL);
		signalled = 0;
		alarm(interval);
		line++;
		if (line == 21)		/* XXX tty line count */
			goto banner;
		else
			goto loop;
		/*NOTREACHED*/
	} else {
		struct ath_stats stats;

		ifr.ifr_data = (caddr_t) &stats;
		if (ioctl(s, SIOCGATHSTATS, &ifr) < 0)
			err(1, ifr.ifr_name);
		printstats(stdout, &stats);
	}
	return 0;
}
Esempio n. 22
0
    int main(int argc, char **argv)
    {
        struct user_opt opt;
        struct crack_data cdata;
        struct capture_data capdata;
        struct wpa_eapol_key *eapkeypacket;
        u8 eapolkey_nomic[99];
        struct timeval start, end;
        int ret;
        char passphrase[MAXPASSLEN + 1];

        printf("%s %s - WPA-PSK dictionary attack. <*****@*****.**>\n",
               PROGNAME, VER);

        memset(&opt, 0, sizeof(struct user_opt));
        memset(&capdata, 0, sizeof(struct capture_data));
        memset(&cdata, 0, sizeof(struct crack_data));
        memset(&eapolkey_nomic, 0, sizeof(eapolkey_nomic));

        /* Collect and test command-line arguments */
        parseopts(&opt, argc, argv);
        testopts(&opt);
        printf("\n");

        /* Populate capdata struct */
        strncpy(capdata.pcapfilename, opt.pcapfile,
            sizeof(capdata.pcapfilename));
        if (openpcap(&capdata) != 0) {
            printf("Unsupported or unrecognized pcap file.\n");
            exit(-1);
        }

        /* populates global *packet */
        while (getpacket(&capdata) > 0) {
            if (opt.verbose > 2) {
                lamont_hdump(packet, h->len);
            }
            /* test packet for data that we are looking for */
            if (memcmp(&packet[capdata.l2type_offset], DOT1X_LLCTYPE, 2) ==
                0 && (h->len >
                capdata.l2type_offset + sizeof(struct wpa_eapol_key))) {
                /* It's a dot1x frame, process it */
                handle_dot1x(&cdata, &capdata, &opt);
                if (cdata.aaset && cdata.spaset && cdata.snonceset &&
                    cdata.anonceset && cdata.keymicset
                    && cdata.eapolframeset) {
                    /* We've collected everything we need. */
                    break;
                }
            }
        }

        if (!(cdata.aaset && cdata.spaset && cdata.snonceset &&
              cdata.anonceset && cdata.keymicset && cdata.eapolframeset)) {

                cdata.aaset = 0;
                cdata.spaset = 0;
                cdata.snonceset = 0;
                cdata.anonceset = 0;
                cdata.keymicset = 0;
                cdata.eapolframeset = 0;

                opt.nonstrict = 1;

                memset(&capdata, 0, sizeof(struct capture_data));
                memset(&cdata, 0, sizeof(struct crack_data));
                memset(&eapolkey_nomic, 0, sizeof(eapolkey_nomic));

                /* Populate capdata struct */
                strncpy(capdata.pcapfilename, opt.pcapfile,
                    sizeof(capdata.pcapfilename));
                if (openpcap(&capdata) != 0) {
                    printf("Unsupported or unrecognized pcap file.\n");
                    exit(-1);
                }

                /* populates global *packet */
                while (getpacket(&capdata) > 0) {
                    if (opt.verbose > 2) {
                        lamont_hdump(packet, h->len);
                    }
                    /* test packet for data that we are looking for */
                    if (memcmp(&packet[capdata.l2type_offset], DOT1X_LLCTYPE, 2) ==
                        0 && (h->len >capdata.l2type_offset + sizeof(struct wpa_eapol_key))) {
                        /* It's a dot1x frame, process it */
                        handle_dot1x(&cdata, &capdata, &opt);

                        if (cdata.aaset && cdata.spaset && cdata.snonceset
			 && cdata.anonceset && cdata.keymicset
                         && cdata.eapolframeset) {

			    if (cdata.replay_counter1 != 0 
                             && cdata.replay_counter2 != 0) {

                              if (memcmp (cdata.replay_counter1,
				          cdata.replay_counter2, 8) == 0) {

				   cdata.counters = 1;
	                           /* We've collected everything we need. */
        	                   break;

			      } 

			    } 

			    if (cdata.replay_counter3 != 0
			     && cdata.replay_counter4 != 0) {

			      if (memcmp (cdata.replay_counter3,
			                  cdata.replay_counter4, 8) == 0) {

				    cdata.counters = 1;
				    /* We've collected everything we need. */
				    break;

			      }

			    }
						
                        }
                    }
                }
        }

        closepcap(&capdata);

        if (!(cdata.aaset && cdata.spaset && cdata.snonceset &&
              cdata.anonceset && cdata.keymicset && cdata.eapolframeset && cdata.counters)) {
            printf("End of pcap capture file, incomplete four-way handshake "
                   "exchange.  Try using a\ndifferent capture.\n");
            exit(-1);
        } else {
            if (cdata.ver == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES) {
                printf("Collected all necessary data to mount crack"
                            " against WPA2/PSK passphrase.\n");
             } else if (cdata.ver == WPA_KEY_INFO_TYPE_HMAC_MD5_RC4) {
                printf("Collected all necessary data to mount crack"
                            " against WPA/PSK passphrase.\n");
            }
        }

        if (opt.verbose > 1) {
            dump_all_fields(cdata, &opt);
        }

        if (opt.checkonly) {
            /* Don't attack the PSK, just return non-error return code */
            return 0;
        }

	/* Zero mic and length data for hmac-md5 calculation */
	eapkeypacket =
	    (struct wpa_eapol_key *)&cdata.eapolframe[EAPDOT1XOFFSET];
	memset(&eapkeypacket->key_mic, 0, sizeof(eapkeypacket->key_mic));
	if (opt.nonstrict == 0) {
		eapkeypacket->key_data_length = 0;
	}

	printf("Starting dictionary attack.  Please be patient.\n");
	fflush(stdout);

	signal(SIGINT, cleanup);
	signal(SIGTERM, cleanup);
	signal(SIGQUIT, cleanup);

	gettimeofday(&start, 0);

	if (!IsBlank(opt.hashfile)) {
		ret = hashfile_attack(&opt, passphrase, &cdata);
	} else if (!IsBlank(opt.dictfile)) {
		ret = dictfile_attack(&opt, passphrase, &cdata);
	} else {
		usage("Must specify dictfile or hashfile (-f or -d)");
		exit(-1);
	}

	if (ret == 0) {
		printf("\nThe PSK is \"%s\".\n", passphrase);
		gettimeofday(&end, 0);
		printstats(start, end, wordstested);
		return 0;
	} else {
		printf("Unable to identify the PSK from the dictionary file. " 
	       		"Try expanding your\npassphrase list, and double-check"
		        " the SSID.  Sorry it didn't work out.\n");
		gettimeofday(&end, 0);
		printstats(start, end, wordstested);
		return 1;
	}

	return 1;

}
Esempio n. 23
0
/*
 * Receive a file.
 */
void
recvfile(int peer, char *port, int fd, char *name, char *mode)
{
	struct tftphdr *rp;
	uint16_t block;
	char recvbuffer[MAXPKTSIZE];
	int n, i;
	struct tftp_stats tftp_stats;

	stats_init(&tftp_stats);

	rp = (struct tftphdr *)recvbuffer;

	if (port == NULL) {
		struct servent *se;
		se = getservbyname("tftp", "udp");
		((struct sockaddr_in *)&peer_sock)->sin_port = se->s_port;
	} else
		((struct sockaddr_in *)&peer_sock)->sin_port =
		    htons(atoi(port));

	for (i = 0; i < 12; i++) {
		struct sockaddr_storage from;

		/* Tell the other side what we want to do */
		if (debug&DEBUG_SIMPLE)
			printf("Requesting %s\n", name);

		n = send_rrq(peer, name, mode);
		if (n > 0) {
			printf("Cannot send RRQ packet\n");
			return;
		}

		/*
		 * The first packet we receive has the new destination port
		 * we have to send the next packets to.
		 */
		n = receive_packet(peer, recvbuffer,
		    MAXPKTSIZE, &from, timeoutpacket);

		/* We got something useful! */
		if (n >= 0) {
			((struct sockaddr_in *)&peer_sock)->sin_port =
			    ((struct sockaddr_in *)&from)->sin_port;
			break;
		}

		/* We should retry if this happens */
		if (n == RP_TIMEOUT) {
			printf("Try %d, didn't receive answer from remote.\n",
			    i + 1);
			continue;
		}

		/* Otherwise it is a fatal error */
		break;
	}
	if (i == 12) {
		printf("Transfer timed out.\n");
		return;
	}
	if (rp->th_opcode == ERROR) {
		tftp_log(LOG_ERR, "Error code %d: %s", rp->th_code, rp->th_msg);
		return;
	}

	if (write_init(fd, NULL, mode) < 0) {
		warn("write_init");
		return;
	}

	/*
	 * If the first packet is an OACK packet instead of an DATA packet,
	 * handle it different.
	 */
	if (rp->th_opcode == OACK) {
		if (!options_rfc_enabled) {
			printf("Got OACK while options are not enabled!\n");
			send_error(peer, EBADOP);
			return;
		}

		parse_options(peer, rp->th_stuff, n + 2);

		n = send_ack(peer, 0);
		if (n > 0) {
			printf("Cannot send ACK on OACK.\n");
			return;
		}
		block = 0;
		tftp_receive(peer, &block, &tftp_stats, NULL, 0);
	} else {
		block = 1;
		tftp_receive(peer, &block, &tftp_stats, rp, n);
	}

	write_close();
	if (tftp_stats.amount > 0)
		printstats("Received", verbose, &tftp_stats);
	return;
}
Esempio n. 24
0
int main (int argc, char **argv, char **envp)
{
  struct rusage usage;
  char **p;
  int status, mem;
  int tsource, ttarget;
  int v;

  redirect = stderr;
  safe_signal (SIGPIPE, SIG_DFL);

  tsource = time (NULL);
  p = parse (argv);
  if (p == NULL)
    {
      printusage (argv);
      return (EXIT_FAILURE);
    }
  else
    {
      /*
         fprintf (stderr, "profile: \"%s\"\n", limit->name);
         fprintf (stderr, "  cpu=%u\n  mem=%u\n", (unsigned int) limit->cpu,
         (unsigned int) limit->memory);
         fprintf (stderr, "  core=%u\n  stack=%u\n", (unsigned int) limit->core,
         (unsigned int) limit->stack);
         fprintf (stderr, "  fsize=%u\n  nproc=%u\n", (unsigned int) limit->fsize,
         (unsigned int) limit->nproc);
         fprintf (stderr, "  minuid=%u\n  maxuid=%u\n", (unsigned int) limit->minuid,
         (unsigned int) limit->maxuid);
         fprintf (stderr, "  clock=%u\n",
         (unsigned int) limit->clock);
       */

      /* Still missing: get an unused uid from interval */
      if (profile.minuid != profile.maxuid)
        {
          srand (time (NULL) ^ getpid ());
          profile.minuid += rand () % (profile.maxuid - profile.minuid);
        }

      if (setuid (profile.minuid) < 0)
        error (NULL);

      if (strcmp (usage_file, "/dev/null") != 0)
        {
          redirect = fopen (usage_file, "w");
          chmod (usage_file, 0644);
          if (redirect == NULL)
            error ("Couldn't open redirection file\n");
        }

      if (getuid () == 0)
        error ("Not changing the uid to an unpriviledged one is a BAD ideia");

      if (signal (SIGALRM, wallclock) == SIG_ERR)
        error ("Couldn't install signal handler");

      if (alarm (profile.clock) != 0)
        error ("Couldn't set alarm");

      pid = fork ();
      if (pid < 0)
        error (NULL);
      if (pid == 0)
        {
          /* change to chroot dir */
          if (0 != chdir(chroot_dir))
            {
              kill (getpid (), SIGPIPE);
              error ("Cannot change to chroot dir");
            }

          /* chroot to judge dir  */
          if (0 != chroot(chroot_dir))
            {
              kill (getpid (), SIGPIPE);
              error ("Cannot chroot");
            }
          /* change to run dir */
          if (0 != chdir(run_dir))
            {
              kill (getpid (), SIGPIPE);
              error ("Cannot change to rundir");
            }

          if (setuid (profile.minuid) < 0)
            error (NULL);

          if (getuid () == 0)
            error ("Not changing the uid to an unpriviledged one is a BAD ideia");

          /* set priority */
          if (0 != setpriority(PRIO_USER,profile.minuid,NICE_LEVEL))
            {
              kill (getpid (), SIGPIPE);
              error (NULL);
            }

          /* Set Address space limit, 1 mbyte tolerancy (librarys also count!) */
          /*setlimit (RLIMIT_AS, (1024 + limit->memory) * 1024); */
          setlimit (RLIMIT_CORE, profile.core * 1024);
          setlimit (RLIMIT_STACK, profile.stack * 1024);
          setlimit (RLIMIT_FSIZE, profile.fsize * 1024);
          setlimit (RLIMIT_NPROC, profile.nproc);
          setlimit (RLIMIT_CPU, profile.cpu);

          /* Execute the program */
          if (execve (*p, p, envp) < 0)
            {
              kill (getpid (), SIGPIPE);
              error (NULL);
            }
        }
      else
        {
          if (setuid (profile.minuid) < 0)
            error (NULL);

          if (getuid () == 0)
            error ("Not changing the uid to an unpriviledged one is a BAD ideia");

          mark = OK;

          /* Poll at INTERVAL ms and determine the maximum *
           * memory usage,  exit when the child terminates */

          mem = 64;
          do
            {
              msleep (INTERVAL);
              mem = max (mem, memusage (pid));
              if (mem > profile.memory)
                {
                  terminate (pid);
                  mark = MLE;
                }
              do
                v = wait4 (pid, &status, WNOHANG | WUNTRACED, &usage);
              while ((v < 0) && (errno != EINTR));
              if (v < 0)
                error (NULL);
            }
          while (v == 0);

          ttarget = time (NULL);

          if (mark == MLE)
            printstats ("Memory Limit Exceeded\n");
          else if (mark == RTLE)
            printstats ("Time Limit Exceeded\n");
          else
            {
              if (WIFEXITED (status) != 0)
                {
                  if (WEXITSTATUS (status) != 0)
                    printstats ("Command exited with non-zero status (%d)\n",
                                WEXITSTATUS (status));
                  else
                    printstats ("OK\n");
                }
              else
                {
                  if (WIFSIGNALED (status) != 0)
                    {
                      /* Was killed for a TLE (or was it an OLE) */
                      if (WTERMSIG (status) == SIGKILL)
                        mark = TLE;
                      else if (WTERMSIG (status) == SIGXFSZ)
                        mark = OLE;
                      else if (WTERMSIG (status) == SIGHUP)
                        mark = RF;
                      else if (WTERMSIG (status) == SIGPIPE)
                        mark = IE;
                      else
                        printstats ("Command terminated by signal (%d: %s)\n",
                                    WTERMSIG (status),
                                    name (WTERMSIG (status)));
                    }
                  else if (WIFSTOPPED (status) != 0)
                    printstats ("Command terminated by signal (%d: %s)\n",
                                WSTOPSIG (status), name (WSTOPSIG (status)));
                  else
                    printstats ("OK\n");

                  if (mark == TLE)
                    {
                      /* Adjust the timings... although we know the child   *
                       * was been killed just in the right time seing 1.990 *
                       * as TLE when the limit is 2 seconds is anoying      */
                      usage.ru_utime.tv_sec = profile.cpu;
                      usage.ru_utime.tv_usec = 0;
                      printstats ("Time Limit Exceeded\n");
                    }
                  else if (mark == OLE)
                    printstats ("Output Limit Exceeded\n");
                  else if (mark == RTLE)
                    printstats ("Time Limit Exceeded\n");
                  else if (mark == RF)
                    printstats ("Invalid Function\n");
                  else if (mark == IE)
                    printstats ("Internal Error\n");
                }
            }
          printstats ("elapsed time: %d seconds\n", ttarget - tsource);
          printstats ("memory usage: %d kbytes\n", mem);
          printstats ("cpu usage: %0.3f seconds\n",
                      (float) miliseconds (&usage.ru_utime) / 1000.0);
        }
    }
  fclose (redirect);

  return (EXIT_SUCCESS);
}
Esempio n. 25
0
/*
 * Send the requested file.
 */
void
xmitfile(int peer, char *port, int fd, char *name, char *mode)
{
	struct tftphdr *rp;
	int n, i;
	uint16_t block;
	struct sockaddr_storage serv;	/* valid server port number */
	char recvbuffer[MAXPKTSIZE];
	struct tftp_stats tftp_stats;

	stats_init(&tftp_stats);

	memset(&serv, 0, sizeof(serv));
	rp = (struct tftphdr *)recvbuffer;

	if (port == NULL) {
		struct servent *se;
		se = getservbyname("tftp", "udp");
		((struct sockaddr_in *)&peer_sock)->sin_port = se->s_port;
	} else
		((struct sockaddr_in *)&peer_sock)->sin_port =
		    htons(atoi(port));

	for (i = 0; i < 12; i++) {
		struct sockaddr_storage from;

		/* Tell the other side what we want to do */
		if (debug&DEBUG_SIMPLE)
			printf("Sending %s\n", name);

		n = send_wrq(peer, name, mode);
		if (n > 0) {
			printf("Cannot send WRQ packet\n");
			return;
		}

		/*
		 * The first packet we receive has the new destination port
		 * we have to send the next packets to.
		 */
		n = receive_packet(peer, recvbuffer,
		    MAXPKTSIZE, &from, timeoutpacket);

		/* We got some data! */
		if (n >= 0) {
			((struct sockaddr_in *)&peer_sock)->sin_port =
			    ((struct sockaddr_in *)&from)->sin_port;
			break;
		}

		/* This should be retried */
		if (n == RP_TIMEOUT) {
			printf("Try %d, didn't receive answer from remote.\n",
			    i + 1);
			continue;
		}

		/* Everything else is fatal */
		break;
	}
	if (i == 12) {
		printf("Transfer timed out.\n");
		return;
	}
	if (rp->th_opcode == ERROR) {
		printf("Got ERROR, aborted\n");
		return;
	}

	/*
	 * If the first packet is an OACK instead of an ACK packet,
	 * handle it different.
	 */
	if (rp->th_opcode == OACK) {
		if (!options_rfc_enabled) {
			printf("Got OACK while options are not enabled!\n");
			send_error(peer, EBADOP);
			return;
		}

		parse_options(peer, rp->th_stuff, n + 2);
	}

	if (read_init(fd, NULL, mode) < 0) {
		warn("read_init()");
		return;
	}

	block = 1;
	tftp_send(peer, &block, &tftp_stats);

	read_close();
	if (tftp_stats.amount > 0)
		printstats("Sent", verbose, &tftp_stats);

	txrx_error = 1;
}
Esempio n. 26
0
static void doerror(lua_State * L) {
    printf("%s\n",luaL_checkstring(L,-1));
    printstats(L);
    exit(1);
}
Esempio n. 27
0
int hashfile_attack(struct user_opt *opt, char *passphrase, 
	struct crack_data *cdata)
{
	
	FILE *fp;
	int reclen, wordlen;
	u8 pmk[32];
	u8 ptk[64];
	u8 keymic[16];
	struct wpa_ptk *ptkset;
	struct hashdb_rec rec;
	struct hashdb_head hf_head;
	char headerssid[33];

	/* Open the hash file */
	if (*opt->hashfile == '-') {
		printf("Using STDIN for hashfile contents.\n");
		fp = stdin;
	} else {
		fp = fopen(opt->hashfile, "rb");
		if (fp == NULL) {
			perror("fopen");
			return(-1);
		}
	}

	/* Read the record header contents */
	if (fread(&hf_head, sizeof(hf_head), 1, fp) != 1) {
		perror("fread");
		return(-1);
	}

	/* Ensure selected SSID matches what's stored in the header record */
	if (memcmp(hf_head.ssid, opt->ssid, hf_head.ssidlen) != 0) {
		
		memcpy(&headerssid, hf_head.ssid, hf_head.ssidlen);
		headerssid[hf_head.ssidlen] = 0; /* NULL terminate string */

		fprintf(stderr, "\nSSID in hashfile (\"%s\") does not match "
			"SSID specified on the \n"
			"command line (\"%s\").  You cannot "
			"mix and match SSID's for this\nattack.\n\n",
			headerssid, opt->ssid);
		return(-1);
	}


	while (feof(fp) == 0 && sig == 0) {

		/* Populate the hashdb_rec with the next record */
		reclen = nexthashrec(fp, &rec);

		/* nexthashrec returns the length of the record, test to ensure
		   passphrase is greater than 8 characters */
		wordlen = rec.rec_size - 
			(sizeof(rec.pmk) + sizeof(rec.rec_size));
		if (wordlen < 8) {
			printf("Found a record that was too short, this "
				"shouldn't happen in practice!\n");
			return(-1);
		}

		/* Populate passphrase with the record contents */
		memcpy(passphrase, rec.word, wordlen);

		/* NULL terminate passphrase string */
		passphrase[wordlen] = 0;

		if (opt->verbose > 1) {
			printf("Testing passphrase: %s\n", passphrase);
		}

		/* Increment the words tested counter */
		wordstested++;

		/* Status display */
#ifdef FPGA
		if ((wordstested % 1000) == 0) {
#else
		if ((wordstested % 10000) == 0) {
#endif
			printf("key no. %ld: %s\n", wordstested, passphrase);
			fflush(stdout);
		}

		if (opt->verbose > 1) {
			printf("Calculating PTK for \"%s\".\n", passphrase);
		}
		
		if (opt->verbose > 2) {
			printf("PMK is");
			lamont_hdump(pmk, sizeof(pmk));
		}

		if (opt->verbose > 1) {
			printf("Calculating PTK with collected data and "
			       "PMK.\n");
		}

		wpa_pmk_to_ptk(rec.pmk, cdata->aa, cdata->spa, cdata->anonce,
			       cdata->snonce, ptk, sizeof(ptk));

		if (opt->verbose > 2) {
			printf("Calculated PTK for \"%s\" is", passphrase);
			lamont_hdump(ptk, sizeof(ptk));
		}

		ptkset = (struct wpa_ptk *)ptk;

		if (opt->verbose > 1) {
			printf("Calculating hmac-MD5 Key MIC for this "
			       "frame.\n");
		}

		hmac_md5(ptkset->mic_key, 16, cdata->eapolframe,
			 sizeof(cdata->eapolframe), keymic);

		if (opt->verbose > 2) {
			printf("Calculated MIC with \"%s\" is", passphrase);
			lamont_hdump(keymic, sizeof(keymic));
		}

		if (memcmp(&cdata->keymic, &keymic, sizeof(keymic)) == 0) {
			return 0;
		} else {
			continue;
		}
	}

	return 1;
}

#ifdef FPGA
struct crack_data *cdata_g;
struct user_opt *opt_g;
struct timeval start_g;

int dictfile_found(unsigned char *pmk, char *passphrase)
{
	
	u8 ptk[64];
	u8 keymic[16];
	struct wpa_ptk *ptkset;
	struct timeval end;

	if (opt_g->verbose > 2) {
		printf("PMK is");
		lamont_hdump(pmk, sizeof(pmk));
	}

	if (opt_g->verbose > 1) {
		printf("Calculating PTK with collected data and "
		       "PMK.\n");
	}

	wpa_pmk_to_ptk(pmk, cdata_g->aa, cdata_g->spa, cdata_g->anonce,
		       cdata_g->snonce, ptk, sizeof(ptk));

	if (opt_g->verbose > 2) {
		printf("Calculated PTK for \"%s\" is", passphrase);
		lamont_hdump(ptk, sizeof(ptk));
	}

	ptkset = (struct wpa_ptk *)ptk;

	if (opt_g->verbose > 1) {
		printf("Calculating hmac-MD5 Key MIC for this "
		       "frame.\n");
	}

	hmac_md5(ptkset->mic_key, 16, cdata_g->eapolframe,
		 sizeof(cdata_g->eapolframe), keymic);

	if (opt_g->verbose > 2) {
		printf("Calculated MIC with \"%s\" is", passphrase);
		lamont_hdump(keymic, sizeof(keymic));
	}

	if (memcmp(&cdata_g->keymic, &keymic, sizeof(keymic)) == 0) {
		printf("\nThe PSK is \"%s\".\n", passphrase);
	} else {
		return 1;
	}
	gettimeofday(&end, NULL);
	printstats(start_g, end, wordstested);

	exit(0);
	return 0;
}
Esempio n. 28
0
int main (int argc, char **argv, char **envp)
{

  struct rusage usage;

  char **p;
  int status, mem, skipped, memused;
  int tsource, ttarget;
  int v;

  redirect = stderr;
  safe_signal (SIGPIPE, SIG_DFL);

  tsource = time (NULL);
  p = parse (argv);
  if (p == NULL)
    {
      printusage (argv);
      return (EXIT_FAILURE);
    }
  else
    {
      /* Get an unused uid */
      if (profile.minuid != profile.maxuid)
        {
          srand (time (NULL) ^ getpid ());
          profile.minuid += rand () % (profile.maxuid - profile.minuid);
        }

      if (strcmp (usage_file, "/dev/null") != 0)
        {
          redirect = fopen (usage_file, "w");
          chown (usage_file, profile.minuid, getgid());
          chmod (usage_file, 0640);
          if (redirect == NULL)
            error ("Couldn't open usage file\n");
        }

      /* stderr from user program is junk */
      junk = fopen (error_file, "w");
      if (junk == NULL)
        error ("Couldn't open junk file %s\n", error_file);
      if (strcmp (error_file, "/dev/null") != 0)
        {
          chown (error_file, profile.minuid, getgid());
          chmod (error_file, 0640);
        }

      if (setgid (profile.minuid) < 0)
        {
          if (errno == EPERM)
            {
              error ("Couldn't setgid due to permission");
            }
          else
            {
              error (NULL);
            }
        }
      if (setuid (profile.minuid) < 0)
        {
          if (errno == EPERM)
            {
              error ("Couldn't setuid due to permission");
            }
          else
            {
              error (NULL);
            }
        }


      if (getuid () == 0)
        error ("Not changing the uid to an unpriviledged one is a BAD ideia");

      if (signal (SIGALRM, wallclock) == SIG_ERR)
        error ("Couldn't install signal handler");

      if (alarm (profile.clock) != 0)
        error ("Couldn't set alarm");

      /* Fork new process */
      pid = fork ();
      if (pid < 0)
        error (NULL);

      if (pid == 0)
        /* Forked/child process */
        {
          /* Chrooting */
          if (chroot_dir != NULL)
            {
              if (0 != chdir(chroot_dir))
                {
                  kill (getpid (), SIGPIPE);
                  error ("Can not change to chroot dir");
                }
              if (0 != chroot(chroot_dir))
                {
                  kill (getpid (), SIGPIPE);
                  error ("Can not chroot");
                }
            }
          /* Change dir */
          if (run_dir != NULL)
            {
              if (0 != chdir(run_dir))
                {
                  kill (getpid (), SIGPIPE);
                  error ("Cannot change to rundir");
                }
            }

          dup2(fileno(junk), fileno(stderr));

          if (setuid (profile.minuid) < 0)
            error (NULL);

          /* Don't run as root */
          if (getuid () == 0)
            error ("Running as a root is not secure!");

          /* Set priority */
          if (0 != setpriority(PRIO_USER,profile.minuid,NICE_LEVEL))
            {
              kill (getpid (), SIGPIPE);
              error (NULL);
            }

          /* Set resource limits - memory, time etc */
          setlimits(profile);

          /* Execute the program */
          if (execve (*p, p, envp) < 0)
            {
              kill (getpid (), SIGPIPE);
              error (NULL);
            }
        }
      else
        /* Parent process */
        {
          if (setuid (profile.minuid) < 0)
            error (NULL);

          if (getuid () == 0)
            error ("Running as a root is not secure!");

          memusage_init ();

          mark = OK;

          /* Poll every INTERVAL ms and get the maximum   *
           * memory usage, exit when the child terminates */
          mem = 64;
          skipped = 0;
          memused = 0;
          do
            {
              msleep (INTERVAL);
              memused = memusage (pid);
              if (memused > -1)
                {
                  mem = max (mem, memused);
                }
              else
                { /* Can not read memory usage! */
                  skipped++;
                }

              if (skipped > 10)
                { /* process is already finished or something wrong happened */
                  terminate (pid);
                  mark = MLE;
                }

              if (mem > profile.memory)
                {
                  terminate (pid);
                  mark = MLE;
                }

              do
                v = wait4 (pid, &status, WNOHANG | WUNTRACED, &usage);
              //v = wait4 (pid, &status, WNOHANG | WUNTRACED | WCONTINUED | WEXITED, &usage);
              while ((v < 0) && (errno != EINTR));
              if (v < 0)
                error (NULL);
            }
          while (v == 0);

          memusage_close ();

          ttarget = time (NULL);

          if (mark == MLE)
            printstats ("Memory Limit Exceeded\n");
          else if (mark == RTLE)
            printstats ("Time Limit Exceeded\n");
          else
            {
              if (WIFEXITED (status) != 0)
                {
                  if (WEXITSTATUS (status) != 0)
                    printstats ("Command exited with non-zero status (%d)\n",
                                WEXITSTATUS (status));
                  else
                    printstats ("OK\n");
                }
              else
                {
                  if (WIFSIGNALED (status) != 0)
                    {
                      /* Was killed for a TLE (or was it an OLE) */
                      if (WTERMSIG (status) == SIGKILL)
                        mark = TLE;
                      else if (WTERMSIG (status) == SIGXFSZ)
                        mark = OLE;
                      else if (WTERMSIG (status) == SIGHUP)
                        mark = RF;
                      else if (WTERMSIG (status) == SIGPIPE)
                        mark = IE;
                      else
                        printstats ("Command terminated by signal (%d: %s)\n",
                                    WTERMSIG (status),
                                    name (WTERMSIG (status)));
                    }
                  else if (WIFSTOPPED (status) != 0)
                    printstats ("Command terminated by signal (%d: %s)\n",
                                WSTOPSIG (status), name (WSTOPSIG (status)));
                  else
                    printstats ("OK\n");

                  if (mark == TLE)
                    {
                      /* We know the child has terminated at right time(OS did). *
                       * But seing 1.990 as TLE while limit 2.0 is confusing.    *
                       * So here is small adjustment for presentation.           */
                      usage.ru_utime.tv_sec = profile.cpu;
                      usage.ru_utime.tv_usec = 0;
                      printstats ("Time Limit Exceeded\n");
                    }
                  else if (mark == OLE)
                    printstats ("Output Limit Exceeded\n");
                  else if (mark == RTLE)
                    printstats ("Time Limit Exceeded\n");
                  else if (mark == RF)
                    printstats ("Invalid Function\n");
                  else if (mark == IE)
                    printstats ("Internal Error\n");
                }
            }
          printstats ("elapsed time: %d seconds\n", ttarget - tsource);
          printstats ("memory usage: %d kbytes\n", mem);
          printstats ("cpu usage: %0.3f seconds\n",
                      (float) miliseconds (&usage.ru_utime) / 1000.0);
        }
    }
  fclose (redirect);

  return (EXIT_SUCCESS);
}
Esempio n. 29
0
int dictfile_attack(struct user_opt *opt, char *passphrase, 
	struct crack_data *cdata)
{
	
	FILE *fp;
	int fret;
	u8 pmk[32];
	u8 ptk[64];
	u8 keymic[16];
	struct wpa_ptk *ptkset;

#ifdef FPGA
//	int i;
	opt_g = opt;
	cdata_g = cdata;
	if(usefpga)
		initfpga();
#endif

	/* Open the dictionary file */
	if (*opt->dictfile == '-') {
		printf("Using STDIN for words.\n");
		fp = stdin;
	} else {
		fp = fopen(opt->dictfile, "r");
		if (fp == NULL) {
			perror("fopen");
			exit(-1);
		}
	}


	while (feof(fp) == 0 && sig == 0) {

		/* Populate "passphrase" with the next word */
		fret = nextdictword(passphrase, fp);
		if (fret < 0) {
			break;
		}

		if (opt->verbose > 1) {
			printf("Testing passphrase: %s\n", passphrase);
		}

		/*
		 * Test length of word.  IEEE 802.11i indicates the passphrase
		 * must be at least 8 characters in length, and no more than 63 
		 * characters in length. 
		 */
		if (fret < 8 || fret > 63) {
			if (opt->verbose) {
				printf("Invalid passphrase length: %s (%d).\n",
				       passphrase, strlen(passphrase));
			}
			continue;
		} else {
			/* This word is good, increment the words tested
			counter */
			wordstested++;
		}

		/* Status display */
#ifdef FPGA
		if ((wordstested % 100) == 0) {
#else
		if ((wordstested % 1000) == 0) {
#endif
			printf("key no. %ld: %s\n", wordstested, passphrase);
			fflush(stdout);
		}

		if (opt->verbose > 1) {
			printf("Calculating PMK for \"%s\".\n", passphrase);
		}
		
		pbkdf2_sha1(passphrase, opt->ssid, strlen(opt->ssid), 4096,
			    pmk, sizeof(pmk), USECACHED);

#ifdef FPGA
		if (!usefpga) {
#endif
		if (opt->verbose > 2) {
			printf("PMK is");
			lamont_hdump(pmk, sizeof(pmk));
		}

		if (opt->verbose > 1) {
			printf("Calculating PTK with collected data and "
			       "PMK.\n");
		}

#ifdef FPGA
/*
		for(i = 0; i < 32; i++)
			printf("%02x ", pmk[i]);
		printf("\n");
*/
#endif

		wpa_pmk_to_ptk(pmk, cdata->aa, cdata->spa, cdata->anonce,
			       cdata->snonce, ptk, sizeof(ptk));

		if (opt->verbose > 2) {
			printf("Calculated PTK for \"%s\" is", passphrase);
			lamont_hdump(ptk, sizeof(ptk));
		}

		ptkset = (struct wpa_ptk *)ptk;

		if (opt->verbose > 1) {
			printf("Calculating hmac-MD5 Key MIC for this "
			       "frame.\n");
		}

		hmac_md5(ptkset->mic_key, 16, cdata->eapolframe,
			 sizeof(cdata->eapolframe), keymic);

		if (opt->verbose > 2) {
			printf("Calculated MIC with \"%s\" is", passphrase);
			lamont_hdump(keymic, sizeof(keymic));
		}

		if (memcmp(&cdata->keymic, &keymic, sizeof(keymic)) == 0) {
			return 0;
		} else {
			continue;
		}
#ifdef FPGA
		}
#endif
	}

#ifdef FPGA
	if(usefpga) {	
		printf("waiting..."); fflush(stdout);
		finishreg();
		printf("\ndone\n");
	}
#endif

	return 1;
}

int main(int argc, char **argv)
{
	struct user_opt opt;
	struct crack_data cdata;
	struct capture_data capdata;
	struct wpa_eapol_key *eapkeypacket;
	u8 eapolkey_nomic[99];
	struct timeval start, end;
	int ret;
	char passphrase[MAXPASSLEN + 1];

	printf("%s %s - WPA-PSK dictionary attack. <*****@*****.**>\n",
	       PROGNAME, VER);

	memset(&opt, 0, sizeof(struct user_opt));
	memset(&capdata, 0, sizeof(struct capture_data));
	memset(&cdata, 0, sizeof(struct crack_data));
	memset(&eapolkey_nomic, 0, sizeof(eapolkey_nomic));

	/* Collect and test command-line arguments */
	parseopts(&opt, argc, argv);
	testopts(&opt);
	printf("\n");

	/* Populate capdata struct */
	strncpy(capdata.pcapfilename, opt.pcapfile,
		sizeof(capdata.pcapfilename));
	if (openpcap(&capdata) != 0) {
		printf("Unsupported or unrecognized pcap file.\n");
		exit(1);
	}

	/* populates global *packet */
	while (getpacket(&capdata) > 0) {
		if (opt.verbose > 2) {
			lamont_hdump(packet, h->len);
		}
		/* test packet for data that we are looking for */
		if (memcmp(&packet[capdata.l2type_offset], DOT1X_LLCTYPE, 2) ==
		    0 && (h->len >
			capdata.l2type_offset + sizeof(struct wpa_eapol_key))) {
			/* It's a dot1x frame, process it */
			handle_dot1x(&cdata, &capdata);
			if (cdata.aaset && cdata.spaset && cdata.snonceset &&
			    cdata.anonceset && cdata.keymicset
			    && cdata.eapolframeset) {
				/* We've collected everything we need. */
				break;
			}
		}
	}

	closepcap(&capdata);

	if (!(cdata.aaset && cdata.spaset && cdata.snonceset &&
	      cdata.anonceset && cdata.keymicset && cdata.eapolframeset)) {
		printf("End of pcap capture file, incomplete TKIP four-way "
		       "exchange.  Try using a\ndifferent capture.\n");
		exit(1);
	} else {
		printf("Collected all necessary data to mount crack against "
		       "passphrase.\n");
	}

	if (opt.verbose > 1) {
		dump_all_fields(cdata);
	}

	/* Zero mic and length data for hmac-md5 calculation */
	eapkeypacket =
	    (struct wpa_eapol_key *)&cdata.eapolframe[EAPDOT1XOFFSET];
	memset(&eapkeypacket->key_mic, 0, sizeof(eapkeypacket->key_mic));
	eapkeypacket->key_data_length = 0;

	printf("Starting dictionary attack.  Please be patient.\n");
	fflush(stdout);

//	signal(SIGINT, cleanup);
//	signal(SIGTERM, cleanup);
//	signal(SIGQUIT, cleanup);

	gettimeofday(&start, NULL);
#ifdef FPGA
	start_g = start;
#endif

	if (!IsBlank(opt.hashfile)) {
		ret = hashfile_attack(&opt, passphrase, &cdata);
	} else if (!IsBlank(opt.dictfile)) {
		ret = dictfile_attack(&opt, passphrase, &cdata);
	} else {
		usage("Must specify dictfile or hashfile (-f or -d)");
		exit(1);
	}

	if (ret == 0) {
		printf("\nThe PSK is \"%s\".\n", passphrase);
	} else {
		printf("Unable to identify the PSK from the dictionary file. " 
	       		"Try expanding your\npassphrase list, and double-check"
		        " the SSID.  Sorry it didn't work out.\n");
	}

	gettimeofday(&end, NULL);
	printstats(start, end, wordstested);
	return (1);
}
Esempio n. 30
0
int main (int argc, char **argv) {
    int norun;
    char *startbrk, *endbrk;
    char *indir, *outdir, *outprefix;
    int attr;
    int splicemode;
    float digits;
    int bboxflag;

    startbrk = (char *) sbrk (0);
    indir = ".";
    outdir = ".";
    outprefix = "tiger";
    attr = T_EATTR_STATE;
    splicemode = 1;
    digits = 6;
    bboxflag = 0;
    savemask = 15;
    norun = 0;
    for (;;) {
        switch (optget (argv, usage)) {
        case -100:
            indir = opt_info.arg;
            continue;
        case -101:
            outdir = opt_info.arg;
            continue;
        case -200:
            splicemode = opt_info.num;
            continue;
        case -201:
            if ((digits = atof (opt_info.arg)) < 0)
                digits = -1;
            continue;
        case -300:
            if (strcmp (opt_info.arg, "zip") == 0)
                attr = T_EATTR_ZIP;
            else if (strcmp (opt_info.arg, "npanxxloc") == 0)
                attr = T_EATTR_NPANXXLOC;
            else if (strcmp (opt_info.arg, "state") == 0)
                attr = T_EATTR_STATE;
            else if (strcmp (opt_info.arg, "county") == 0)
                attr = T_EATTR_COUNTY;
            else if (strcmp (opt_info.arg, "ctbna") == 0)
                attr = T_EATTR_CTBNA;
            else if (strcmp (opt_info.arg, "blkg") == 0)
                attr = T_EATTR_BLKG;
            else if (strcmp (opt_info.arg, "blk") == 0)
                attr = T_EATTR_BLK;
            else if (strcmp (opt_info.arg, "blks") == 0)
                attr = T_EATTR_BLKS;
            else if (strcmp (opt_info.arg, "country") == 0)
                attr = T_EATTR_COUNTRY;
            else
                SUerror ("tiger2ps", "bad argument for -a option");
            continue;
        case -302:
            outprefix = opt_info.arg;
            continue;
        case -306:
            bboxflag = 1;
            continue;
        case -600:
            savemask &= 14;
            continue;
        case -601:
            savemask &= 13;
            continue;
        case -602:
            savemask &= 11;
            continue;
        case -603:
            savemask &= 7;
            continue;
        case -999:
            SUwarnlevel++;
            continue;
        case '?':
            SUusage (0, "tiger2ps", opt_info.arg);
            norun = 1;
            continue;
        case ':':
            SUusage (1, "tiger2ps", opt_info.arg);
            norun = 2;
            continue;
        }
        break;
    }
    if (norun)
        return norun - 1;
    argc -= opt_info.index, argv += opt_info.index;

    initrecords ();
    if (!(itemdict = dtopen (&itemdisc, Dtset)))
        SUerror ("tiger2ps", "dtopen failed");
    if (loaddata (indir) == -1)
        SUerror ("tiger2ps", "loaddata failed");
    if (splicemode > 0 && removedegree2vertices (splicemode) == -1)
        SUerror ("tiger2ps", "removedegree2vertices");
    if (digits >= 0 && simplifyxys (digits) == -1)
        SUerror ("tiger2ps", "simplifyxys failed");
    if (genpoints (attr) == -1)
        SUerror ("tiger2ps", "genpoints failed");
    calcbbox ();
    if (bboxflag)
        printbbox ();
    if ((savemask & 1) && savepoints (outdir, outprefix) == -1)
        SUerror ("tiger2ps", "savepoints failed for %s/%s", outdir, outprefix);
    if ((savemask & 2) && savelines (outdir, outprefix) == -1)
        SUerror ("tiger2ps", "savelines failed for %s/%s", outdir, outprefix);
    if ((savemask & 4) && savepolys (outdir, outprefix) == -1)
        SUerror ("tiger2ps", "savepolys failed for %s/%s", outdir, outprefix);
    if ((savemask & 8) && gentris () == -1)
        SUerror ("tiger2ps", "gentris failed");
    if ((savemask & 8) && savetris (outdir, outprefix) == -1)
        SUerror ("tiger2ps", "savetris failed for %s/%s", outdir, outprefix);
    printstats ();
    endbrk = (char *) sbrk (0);
    SUmessage (1, "tiger2ps", "memory usage %d", endbrk - startbrk);
    return 0;
}