Exemplo n.º 1
0
// describe Scalpel error conditions.  Some errors are fatal, while
// others are advisory.
void handleError(struct scalpelState *state, int error) {
  
  switch(error) {
    
  case SCALPEL_ERROR_FILE_OPEN:
    // non-fatal
    scalpelLog(state,"Scalpel was unable to open the image file: %s\n"
		"Skipping...\n\n",
		state->imagefile);
    break;

  case SCALPEL_ERROR_FILE_READ:
    // non-fatal
    scalpelLog(state,"Scalpel was unable to read the image file: %s\n"
		"Skipping...\n\n",
		state->imagefile);
    break;

  case SCALPEL_ERROR_FATAL_READ:
    // fatal
    scalpelLog(state,"Scalpel was unable to read a needed file and will abort.\n");
    closeFile(state->auditFile);
    exit (-1);
    break;

  case SCALPEL_ERROR_FILE_WRITE:
    // fatal--unable to write files, which may mean that disk space is exhausted.
    fprintf(stderr,
	    "Scalpel was unable to write output files and will abort.\n");
    fprintf(stderr,
	    "This error generally indicates that disk space is exhausted.\n");
    closeFile(state->auditFile);
    exit (-1);

  case SCALPEL_ERROR_NO_SEARCH_SPEC:
    // fatal, configuration file didn't specify anything to carve
    scalpelLog(state,
		 "ERROR: The configuration file didn't specify any file types to carve.\n");
    scalpelLog(state, "(If you're using the default configuration file, you'll have to\n");
    scalpelLog(state, "uncomment some of the file types.)\n");
    closeFile(state->auditFile);
    exit (-1);

  case SCALPEL_GENERAL_ABORT:
    // fatal
    scalpelLog(state,"Scalpel will abort.\n");
    closeFile(state->auditFile);
    exit (-1);
    break;
  
  default:
    // fatal
    scalpelLog(state,
		"Scalpel has encountered an error it doesn't know"
		"how to handle.\nError code: %d\n", error);
    closeFile(state->auditFile);
    exit (-1);
  }
}
Exemplo n.º 2
0
// describe Scalpel error conditions.  Some errors are fatal, while
// others are advisory.
void handleError(struct scalpelState *state, int error) 
{

    const char * inputId = NULL;
    std::string msg;

    if (state->inReader) {
        inputId = scalpelInputGetId(state->inReader);
    }
    else {
        inputId = " (input reader not yet set)";
    }

    switch (error) {

    case SCALPEL_ERROR_PTHREAD_FAILURE:
        // fatal
        msg = "Scalpel was unable to create threads and will abort.\n";
        scalpelLog(state, msg.c_str());
        closeAuditFile(state->auditFile);
        throw std::runtime_error(msg);

        break;

    case SCALPEL_ERROR_FILE_OPEN:
        // non-fatal
        if (inputId == 0 || *(inputId) == '\0') {
            scalpelLog(state, "Scalpel was unable to open the input file: <blank>....\n"
                "Skipping...\n");
        }
        else {
            scalpelLog(state, "Scalpel was unable to open the input file: %s...%s\n"
                "Skipping...\n", inputId, strerror(errno));
        }
        break;
    case SCALPEL_ERROR_FILE_TOO_SMALL:
        // non-fatal
        scalpelLog(state,
            "The input file %s is smaller than the longest header/footer and cannot be processed.\n"
            "Skipping...\n", inputId);
        break;

    case SCALPEL_ERROR_FILE_READ:
        // non-fatal
        scalpelLog(state, "Scalpel was unable to read the input file: %s\n"
            "Skipping...\n", inputId);
        break;

    case SCALPEL_ERROR_FATAL_READ:
        // fatal
        msg = "Scalpel was unable to read a needed file and will abort.\n";
        scalpelLog(state, msg.c_str());
        closeAuditFile(state->auditFile);
        throw std::runtime_error(msg);
        break;

    case SCALPEL_ERROR_NONEMPTY_DIRECTORY:
        // fatal
        msg = "Scalpel will write only to empty output directories to avoid\n"
            "mixing the output from multiple carving operations.\n"
            "Please specify a different output directory or delete the specified\noutput directory.\n";
        fprintf(stderr, msg.c_str());
        closeAuditFile(state->auditFile);
        throw std::runtime_error(msg);
        break;

    case SCALPEL_ERROR_FILE_WRITE:
        // fatal--unable to write files, which may mean that disk space is exhausted.
        msg = "Scalpel was unable to write output files and will abort.\n"
            "This error generally indicates that disk space is exhausted.\n";
        fprintf(stderr, msg.c_str());
        closeAuditFile(state->auditFile);
        throw std::runtime_error(msg);
        break;

    case SCALPEL_ERROR_NO_SEARCH_SPEC:
        // fatal, configuration file didn't specify anything to carve
        msg = "ERROR: The configuration file didn't specify any file types to carve.\n"
            "(If you're using the default configuration file, you'll have to "
            "uncomment some of the file types.)\n";
        scalpelLog(state, msg.c_str() );
        closeAuditFile(state->auditFile);
        throw std::runtime_error(msg);
        break;

    case SCALPEL_GENERAL_ABORT:
        // fatal
        msg = "Scalpel will abort.\n";
        scalpelLog(state, msg.c_str());
        closeAuditFile(state->auditFile);
        throw std::runtime_error(msg);
        break;

    default:
        // fatal
        closeAuditFile(state->auditFile);
        throw std::runtime_error("Unexpected error");
    }
}