Skip to content

Commit

Permalink
added -P option for PDFreportpath
Browse files Browse the repository at this point in the history
  • Loading branch information
ggruber committed Oct 2, 2023
1 parent c1e943d commit 8124e6b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 5 deletions.
5 changes: 5 additions & 0 deletions man/nwipe.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/create_pdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 7 additions & 2 deletions src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
12 changes: 12 additions & 0 deletions src/nwipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <signal.h>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>

#include "nwipe.h"
#include "context.h"
Expand Down Expand Up @@ -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. */
Expand Down
15 changes: 14 additions & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand All @@ -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' },

Expand Down Expand Up @@ -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++ )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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" );
Expand Down
1 change: 1 addition & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8124e6b

Please sign in to comment.