Пример #1
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;
}
Пример #2
0
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;
}