示例#1
0
static int process_cmd_line(state *s, int argc, char **argv)
{
  int i;

  while ((i=getopt(argc,argv,"tb:hV")) != -1) {
    switch(i) {

    case 't':
      s->mode |= mode_transitional;
      break;

    case 'b':
      find_block_size(s,optarg);
      break;

    case 'h':      
      usage();
      exit(EXIT_SUCCESS);

    case 'V':
      print_status ("%s", VERSION);
      exit(EXIT_SUCCESS);
      
    default:
      try_msg();
      exit(EXIT_FAILURE);
    }
  }

  return (sanity_check(s));
}
示例#2
0
文件: main.c 项目: kona4kona/md5deep
static int parse_hashing_algorithms(state *s, char *val)
{
    uint8_t i;
    char **ap, *buf[MAX_KNOWN_COLUMNS];

    if (NULL == s || NULL == val)
        return TRUE;

    for (ap = buf ; (*ap = strsep(&val,",")) != NULL ; )
        if (*ap != '\0')
            if (++ap >= &buf[MAX_KNOWN_COLUMNS])
                break;

    for (i = 0 ; i < MAX_KNOWN_COLUMNS && buf[i] != NULL ; i++)
    {
        if (STRINGS_CASE_EQUAL(buf[i],"md5"))
            s->hashes[alg_md5]->inuse = TRUE;

        else if (STRINGS_CASE_EQUAL(buf[i],"sha1") ||
                 STRINGS_CASE_EQUAL(buf[i],"sha-1"))
            s->hashes[alg_sha1]->inuse = TRUE;

        else if (STRINGS_CASE_EQUAL(buf[i],"sha256") ||
                 STRINGS_CASE_EQUAL(buf[i],"sha-256"))
            s->hashes[alg_sha256]->inuse = TRUE;

        else if (STRINGS_CASE_EQUAL(buf[i],"tiger"))
            s->hashes[alg_tiger]->inuse = TRUE;

        else if (STRINGS_CASE_EQUAL(buf[i],"whirlpool"))
            s->hashes[alg_whirlpool]->inuse = TRUE;

        else if (STRINGS_CASE_EQUAL(buf[i],"all"))
        {
            hashname_t count;
            for (count = 0 ; count < NUM_ALGORITHMS ; ++count)
                s->hashes[count]->inuse = TRUE;
            return FALSE;
        }

        else
        {
            print_error(s,"%s: Unknown algorithm: %s", __progname, buf[i]);
            try_msg();
            exit(EXIT_FAILURE);
        }
    }

    return FALSE;
}
示例#3
0
void sanity_check(state *s, int condition, const char *msg)
{
  if (NULL == s)
    exit(EXIT_FAILURE);
  
  if (condition)
    {
      if (!(s->mode & mode_silent))
	{
	  print_status("%s: %s", __progname, msg);
	  try_msg();
	}
      exit (EXIT_FAILURE);
    }
}
示例#4
0
int process_cmd_line(state *s, int argc, char **argv)
{
  int i;

  while ((i = getopt(argc,argv,"w:ovhdV")) != -1) {
    switch (i) {

    case 'd':
      s->direction   = !s->direction;
      break;

    case 'o':
      s->orientation = !s->orientation;
      break;

    case 'w':
      s->image_width = atoll(optarg);
      if (0 == s->image_width)
	fatal_error("%s: Illegal width", __progname);
      break;

    case 'v':
      if (s->verbose)
	{
	  print_error ("%s: Already at maximum verbosity", __progname);
	  print_error ("%s: Error message displayed successfully", __progname);
	}
      else
	s->verbose = TRUE;
      break;
      
    case 'h':
      usage();
      exit (EXIT_SUCCESS);

    case 'V':
      print_status ("%s", VERSION);
      exit (EXIT_SUCCESS);
      
    default:
      try_msg();
      exit (EXIT_FAILURE);
    }
  }

  return FALSE;
}
示例#5
0
static void process_cmd_line(state *s, int argc, char **argv)
{
  int i, match_files_loaded = FALSE;
  while ((i=getopt(argc,argv,"avhVpdsblcxt:rm:k:")) != -1) {
    switch(i) {

    case 'a':
      s->mode |= mode_display_all;
      break;

    case 'v': 
      if (MODE(mode_verbose))
      {
	print_error(s,"%s: Already at maximum verbosity", __progname);
	print_error(s,
		    "%s: Error message display to user correctly", 
		    __progname);
      }
      else
	s->mode |= mode_verbose;
      break;
      
    case 'p':
      s->mode |= mode_match_pretty;
      break;

    case 'd':
      s->mode |= mode_directory; 
      break;

    case 's':
      s->mode |= mode_silent; break;

    case 'b':
      s->mode |= mode_barename; break;

    case 'l':
      s->mode |= mode_relative; break;

    case 'c':
      s->mode |= mode_csv; break;

    case 'x':
      if (MODE(mode_match) || MODE(mode_sigcompare))
	fatal_error("Signature matching cannot be combined with other matching modes");
      s->mode |= mode_sigcompare; break;

    case 'r':
      s->mode |= mode_recursive; break;

    case 't':
      s->threshold = (uint8_t)atol(optarg);
      if (s->threshold > 100)
	fatal_error("%s: Illegal threshold", __progname);
      s->mode |= mode_threshold;
      break;
      
    case 'm':
      if (MODE(mode_compare_unknown) || MODE(mode_sigcompare))
	fatal_error("Positive matching cannot be combined with other matching modes");
      s->mode |= mode_match;
      if (!match_load(s,optarg))
	match_files_loaded = TRUE;
      break;
      
    case 'k':
      if (MODE(mode_match) || MODE(mode_sigcompare))
	fatal_error("Signature matching cannot be combined with other matching modes");
      s->mode |= mode_compare_unknown;
      if (!match_load(s,optarg))
	match_files_loaded = TRUE;
      break;

    case 'h':
      usage(); 
      exit (EXIT_SUCCESS);
      
    case 'V':
      print_status ("%s", VERSION);
      exit (EXIT_SUCCESS);
      
    default:
      try_msg();
      exit (EXIT_FAILURE);
    }
  }

  // We don't include mode_sigcompare in this list as we haven't loaded
  // the matching files yet. In that mode the matching files are in fact 
  // the command line arguments.
  sanity_check(s,
	       ((MODE(mode_match) || MODE(mode_compare_unknown))
		&& !match_files_loaded),
	       "No matching files loaded");
  
  sanity_check(s,
	       ((s->mode & mode_barename) && (s->mode & mode_relative)),
	       "Relative paths and bare names are mutually exclusive");

  sanity_check(s,
	       ((s->mode & mode_match_pretty) && (s->mode & mode_directory)),
	       "Directory mode and pretty matching are mutallty exclusive");
}
示例#6
0
static int process_command_line(state *s, int argc, char **argv)
{
  int i;
  
  while ((i = getopt(argc,
		     argv,
		     "I:i:M:X:x:m:o:A:a:tnwzsSp:erhvV0lbkqU")) != -1) { 
    switch (i) {

    case 'I':
      s->mode |= mode_size_all;
      // Note that there is no break here
    case 'i':
      s->mode |= mode_size;
      s->size_threshold = find_block_size(s,optarg);
      if (0 == s->size_threshold)
      {
	print_error(s,"%s: Requested size threshold implies not hashing anything",
		    __progname);
	exit(STATUS_USER_ERROR);
      }
      break;

    case 'p':
      s->mode |= mode_piecewise;
      s->piecewise_size = find_block_size(s, optarg);
      if (0 == s->piecewise_size)
      {
	print_error(s,"%s: Piecewise blocks of zero bytes are impossible", 
		    __progname);
	exit(STATUS_USER_ERROR);
      }

      break;

    case 'q': 
      s->mode |= mode_quiet; 
      break;
    case 't':
      s->mode |= mode_timestamp;
      MD5DEEP_ALLOC(char,s->time_str,MAX_TIME_STRING_LENGTH);
      break;
    case 'n': 
      s->mode |= mode_not_matched; 
      break;
    case 'w': 
      s->mode |= mode_which; 
      break;

    case 'a':
      s->mode |= mode_match;
      check_matching_modes(s);
      add_hash(s,optarg,optarg);
      s->hashes_loaded = TRUE;
      break;

    case 'A':
      s->mode |= mode_match_neg;
      check_matching_modes(s);
      add_hash(s,optarg,optarg);
      s->hashes_loaded = TRUE;
      break;
      
    case 'l': 
      s->mode |= mode_relative; 
      break;

    case 'b': 
      s->mode |= mode_barename; 
      break;

    case 'o': 
      s->mode |= mode_expert; 
      setup_expert_mode(s,optarg);
      break;
      
    case 'M':
      s->mode |= mode_display_hash;
    case 'm':
      s->mode |= mode_match;
      check_matching_modes(s);
      if (load_match_file(s,optarg))
	s->hashes_loaded = TRUE;
      break;

    case 'X':
      s->mode |= mode_display_hash;
    case 'x':
      s->mode |= mode_match_neg;
      check_matching_modes(s);
      if (load_match_file(s,optarg))
	s->hashes_loaded = TRUE;
      break;

    case 'z': 
      s->mode |= mode_display_size; 
      break;

    case '0': 
      s->mode |= mode_zero; 
      break;

    case 'S': 
      s->mode |= mode_warn_only;
      s->mode |= mode_silent;
      break;

    case 's':
      s->mode |= mode_silent;
      break;

    case 'e':
      s->mode |= mode_estimate;
      break;

    case 'r':
      s->mode |= mode_recursive;
      break;

    case 'k':
      s->mode |= mode_asterisk;
      break;

    case 'h':
      usage();
      exit (STATUS_OK);

    case 'v':
      print_status("%s",VERSION);
      exit (STATUS_OK);

    case 'V':
      // COPYRIGHT is a format string, complete with newlines
      print_status(COPYRIGHT);
      exit (STATUS_OK);

    default:
      try_msg();
      exit (STATUS_USER_ERROR);

    }
  }

  check_flags_okay(s);

  return STATUS_OK;
}
示例#7
0
文件: main.c 项目: kona4kona/md5deep
static int process_command_line(state *s, int argc, char **argv)
{
    int i;

    while ((i=getopt(argc,argv,"o:I:i:c:MmXxtablk:resp:wvVh")) != -1)
    {
        switch (i)
        {
        case 'o':
            s->mode |= mode_expert;
            setup_expert_mode(s,optarg);
            break;

        case 'I':
            s->mode |= mode_size_all;
        // Note no break here;
        case 'i':
            s->mode |= mode_size;
            s->size_threshold = find_block_size(s,optarg);
            if (0 == s->size_threshold)
            {
                print_error(s,"%s: Requested size threshold implies not hashing anything",
                            __progname);
                exit(STATUS_USER_ERROR);
            }
            break;

        case 'c':
            s->primary_function = primary_compute;
            /* Before we parse which algorithms we're using now, we have
            to erase the default (or previously entered) values */
            clear_algorithms_inuse(s);
            if (parse_hashing_algorithms(s,optarg))
                fatal_error(s,"%s: Unable to parse hashing algorithms",__progname);
            break;

        case 'M':
            s->mode |= mode_display_hash;
        case 'm':
            s->primary_function = primary_match;
            break;

        case 'X':
            s->mode |= mode_display_hash;
        case 'x':
            s->primary_function = primary_match_neg;
            break;

        case 'a':
            s->primary_function = primary_audit;
            break;

        // TODO: Add -t mode to hashdeep
        //    case 't': s->mode |= mode_timestamp;    break;

        case 'b':
            s->mode |= mode_barename;
            break;
        case 'l':
            s->mode |= mode_relative;
            break;
        case 'e':
            s->mode |= mode_estimate;
            break;
        case 'r':
            s->mode |= mode_recursive;
            break;
        case 's':
            s->mode |= mode_silent;
            break;

        case 'p':
            s->mode |= mode_piecewise;
            s->piecewise_size = find_block_size(s, optarg);
            if (0 == s->piecewise_size)
                fatal_error(s,"%s: Piecewise blocks of zero bytes are impossible",
                            __progname);

            break;

        case 'w':
            s->mode |= mode_which;
            break;

        case 'k':
            switch (load_match_file(s,optarg))
            {
            case status_ok:
                s->hashes_loaded = TRUE;
                break;

            case status_contains_no_hashes:
                /* Trying to load an empty file is fine, but we shouldn't
                   change s->hashes_loaded */
                break;

            case status_contains_bad_hashes:
                s->hashes_loaded = TRUE;
                print_error(s,"%s: %s: contains some bad hashes, using anyway",
                            __progname, optarg);
                break;

            case status_unknown_filetype:
            case status_file_error:
                /* The loading code has already printed an error */
                break;

            default:
                print_error(s,"%s: %s: unknown error, skipping", __progname, optarg);
                break;
            }
            break;

        case 'v':
            if (s->mode & mode_insanely_verbose)
                print_error(s,"%s: User request for insane verbosity denied", __progname);
            else if (s->mode & mode_more_verbose)
                s->mode |= mode_insanely_verbose;
            else if (s->mode & mode_verbose)
                s->mode |= mode_more_verbose;
            else
                s->mode |= mode_verbose;
            break;

        case 'V':
            print_status("%s", VERSION);
            exit(EXIT_SUCCESS);

        case 'h':
            usage(s);
            exit(EXIT_SUCCESS);

        default:
            try_msg();
            exit(EXIT_FAILURE);
        }
    }

    check_flags_okay(s);

    return FALSE;
}