diff --git a/man/nwipe.1 b/man/nwipe.1 index 7806c09..aed590a 100644 --- a/man/nwipe.1 +++ b/man/nwipe.1 @@ -111,6 +111,11 @@ is5enh \- HMG IS5 enhanced \fB\-l\fR, \fB\-\-logfile\fR=\fIFILE\fR Filename to log to. Default is STDOUT .TP +\fB\-P\fR, \fB\-\-PDFreportpath\fR=\fIDIR\fR +Directory to write the PDF nwipe reports/certificates to. +Defaults to ".". +If \fIDIR\fR is set to \fInoPDF\fR no report PDF files are written. +.TP \fB\-p\fR, \fB\-\-prng\fR=\fIMETHOD\fR PRNG option (mersenne|twister|isaac|isaac64) .TP diff --git a/src/context.h b/src/context.h index 4c0f6ec..8d2d12d 100644 --- a/src/context.h +++ b/src/context.h @@ -157,7 +157,7 @@ typedef struct nwipe_context_t_ time_t start_time; // Start time of wipe time_t end_time; // End time of wipe u64 fsyncdata_errors; // The number of fsyncdata errors across all passes. - char PDF_filename[256]; // The filename of the PDF certificate/report. + char PDF_filename[FILENAME_MAX]; // The filename of the PDF certificate/report. int HPA_status; // 0 = No HPA found/disabled, 1 = HPA detected, 2 = Unknown, unable to checked, // 3 = Not applicable to this device u64 HPA_reported_set; // the 'HPA set' value reported hdparm -N, i.e the first value of n/n diff --git a/src/create_pdf.c b/src/create_pdf.c index c5b5fa4..b0313df 100644 --- a/src/create_pdf.c +++ b/src/create_pdf.c @@ -841,7 +841,8 @@ int create_pdf( nwipe_context_t* ptr ) replace_non_alphanumeric( c->device_serial_no, '_' ); snprintf( c->PDF_filename, sizeof( c->PDF_filename ), - "nwipe_report_%s_Model_%s_Serial_%s.pdf", + "%s/nwipe_report_%s_Model_%s_Serial_%s.pdf", + nwipe_options.PDFreportpath, end_time_text, c->device_model, c->device_serial_no ); @@ -960,6 +961,7 @@ int nwipe_get_smart_data( char* device ) } } + pdf_set_font( pdf, "Courier" ); pdf_add_text( pdf, page_2, result, 6, x, y, PDF_BLACK ); y -= 9; } diff --git a/src/logging.c b/src/logging.c index 07fe040..e868da0 100644 --- a/src/logging.c +++ b/src/logging.c @@ -890,8 +890,13 @@ void nwipe_log_summary( nwipe_context_t** ptr, int nwipe_selected ) model, serial_no ); - /* Create the PDF certificate */ - create_pdf( c[i] ); + /* Create the PDF report/certificate */ + if( strcmp( nwipe_options.PDFreportpath, "noPDF" ) != 0 ) + { + nwipe_log( NWIPE_LOG_NOTIMESTAMP, "Creating PDF report in %s\n", nwipe_options.PDFreportpath ); + printf( "Creating PDF report in %s\n", nwipe_options.PDFreportpath ); + create_pdf( c[i] ); + } } /* Determine the size of throughput so that the correct nomenclature can be used */ diff --git a/src/nwipe.c b/src/nwipe.c index cc5419b..0dcde07 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "nwipe.h" #include "context.h" @@ -154,6 +155,17 @@ int main( int argc, char** argv ) } } + /* Check if the given path for PDF reports is a writeable directory */ + if( strcmp( nwipe_options.PDFreportpath, "noPDF" ) != 0 ) + { + if( access( nwipe_options.PDFreportpath, W_OK ) != 0 ) + { + nwipe_log( NWIPE_LOG_ERROR, "PDFreportpath %s is not a writeable directory.", nwipe_options.PDFreportpath ); + cleanup(); + exit( 2 ); + } + } + if( nwipe_optind == argc ) { /* File names were not given by the user. Scan for devices. */ diff --git a/src/options.c b/src/options.c index 2930f3b..ef4df26 100644 --- a/src/options.c +++ b/src/options.c @@ -54,7 +54,7 @@ int nwipe_options_parse( int argc, char** argv ) int i; /* The list of acceptable short options. */ - char nwipe_options_short[] = "Vvhl:m:p:qr:e:"; + char nwipe_options_short[] = "Vvhl:P:m:p:qr:e:"; /* The list of acceptable long options. */ static struct option nwipe_options_long[] = { @@ -73,6 +73,9 @@ int nwipe_options_parse( int argc, char** argv ) /* Log file. Corresponds to the 'l' short option. */ { "logfile", required_argument, 0, 'l' }, + /* PDFreport path. Corresponds to the 'P' short option. */ + { "PDFreportpath", required_argument, 0, 'P' }, + /* Exclude devices, comma separated list */ { "exclude", required_argument, 0, 'e' }, @@ -131,6 +134,8 @@ int nwipe_options_parse( int argc, char** argv ) nwipe_options.verbose = 0; nwipe_options.verify = NWIPE_VERIFY_LAST; memset( nwipe_options.logfile, '\0', sizeof( nwipe_options.logfile ) ); + memset( nwipe_options.PDFreportpath, '\0', sizeof( nwipe_options.PDFreportpath ) ); + strncpy( nwipe_options.PDFreportpath, ".", 2 ); /* Initialise each of the strings in the excluded drives array */ for( i = 0; i < MAX_NUMBER_EXCLUDED_DRIVES; i++ ) @@ -315,6 +320,12 @@ int nwipe_options_parse( int argc, char** argv ) strncpy( nwipe_options.logfile, optarg, sizeof( nwipe_options.logfile ) ); break; + case 'P': /* PDFreport path option. */ + + nwipe_options.PDFreportpath[strlen( optarg )] = '\0'; + strncpy( nwipe_options.PDFreportpath, optarg, sizeof( nwipe_options.PDFreportpath ) ); + break; + case 'e': /* exclude drives option */ idx_drive_chr = 0; @@ -570,6 +581,8 @@ void display_help() puts( " verify_zero - Verifies disk is zero filled" ); puts( " verify_one - Verifies disk is 0xFF filled\n" ); puts( " -l, --logfile=FILE Filename to log to. Default is STDOUT\n" ); + puts( " -P, --PDFreportpath=PATH Path to write PDF reports to. Default is \".\"" ); + puts( " If set to \"noPDF\" no PDF reports are written.\n" ); puts( " -p, --prng=METHOD PRNG option (mersenne|twister|isaac|isaac64)\n" ); puts( " -q, --quiet Anonymize logs and the GUI by removing unique data, i.e." ); puts( " serial numbers, LU WWN Device ID, and SMBIOS/DMI data" ); diff --git a/src/options.h b/src/options.h index 354a832..fff46b7 100644 --- a/src/options.h +++ b/src/options.h @@ -58,6 +58,7 @@ typedef struct char* banner; // The product banner shown on the top line of the screen. void* method; // A function pointer to the wipe method that will be used. char logfile[FILENAME_MAX]; // The filename to log the output to. + char PDFreportpath[FILENAME_MAX]; // The path to write the PDF report to. char exclude[MAX_NUMBER_EXCLUDED_DRIVES][MAX_DRIVE_PATH_LENGTH]; // Drives excluded from the search. nwipe_prng_t* prng; // The pseudo random number generator implementation. pointer to the function. int quiet; // Anonymize serial numbers