From bbcb4fc219d5f7dd4abdab6d24d061f6c225ad70 Mon Sep 17 00:00:00 2001 From: Gerold Gruber Date: Sun, 1 Oct 2023 23:45:48 +0200 Subject: [PATCH 1/6] fix for issue #492 --- configure.ac | 7 ++++--- src/device.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 558d398..e88748b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,11 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ([2.64]) -AC_INIT([nwipe], [0.34], [git@brumit.nl]) +AC_PREREQ([2.71]) +AC_INIT([nwipe],[0.34],[git@brumit.nl]) AM_INIT_AUTOMAKE(foreign subdir-objects) -AC_OUTPUT(Makefile src/Makefile man/Makefile) +AC_CONFIG_FILES([Makefile src/Makefile man/Makefile]) +AC_OUTPUT AC_CONFIG_SRCDIR([src/nwipe.c]) AC_CONFIG_HEADERS([config.h]) diff --git a/src/device.c b/src/device.c index 23c3be7..d5853bc 100644 --- a/src/device.c +++ b/src/device.c @@ -244,11 +244,18 @@ int check_device( nwipe_context_t*** c, PedDevice* dev, int dcount ) for( idx = 0; idx < 20; idx++ ) { - next_device->device_serial_no[idx] = next_device->identity.serial_no[idx]; + if( isascii( next_device->identity.serial_no[idx] ) ) + { + next_device->device_serial_no[idx] = next_device->identity.serial_no[idx]; + } + else + { + break; + } } // Terminate the string. - next_device->device_serial_no[20] = 0; + next_device->device_serial_no[idx] = 0; // Remove leading/trailing whitespace from serial number and left justify. trim( (char*) next_device->device_serial_no ); From 4675a17693b9827cb35fb0abac46471801b24301 Mon Sep 17 00:00:00 2001 From: Gerold Gruber Date: Sun, 1 Oct 2023 23:52:38 +0200 Subject: [PATCH 2/6] manpage typo --- man/nwipe.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/nwipe.1 b/man/nwipe.1 index 7f37a02..7806c09 100644 --- a/man/nwipe.1 +++ b/man/nwipe.1 @@ -35,7 +35,7 @@ devices immediately. If devices have been specified, starts wiping only those specified devices immediately. .TP \fB\-\-autopoweroff\fR -Power off system on completion of wipe delayed for for one minute. During +Power off system on completion of wipe delayed for one minute. During this one minute delay you can abort the shutdown by typing sudo shutdown -c .TP \fB\-\-sync\fR=\fINUM\fR From 7c9939e228a26dc95de11fef74bfbfd798feb31d Mon Sep 17 00:00:00 2001 From: Gerold Gruber Date: Mon, 2 Oct 2023 00:21:49 +0200 Subject: [PATCH 3/6] possible solution for issue #418 --- src/context.h | 2 +- src/miscellaneous.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/context.h b/src/context.h index 63dea2e..4c0f6ec 100644 --- a/src/context.h +++ b/src/context.h @@ -70,7 +70,7 @@ typedef struct nwipe_speedring_t_ } nwipe_speedring_t; #define NWIPE_DEVICE_LABEL_LENGTH 200 -#define NWIPE_DEVICE_SIZE_TXT_LENGTH 7 +#define NWIPE_DEVICE_SIZE_TXT_LENGTH 8 // Arbitrary length, so far most paths don't exceed about 25 characters #define MAX_HWMON_PATH_LENGTH 100 diff --git a/src/miscellaneous.c b/src/miscellaneous.c index 488c8fd..04e9fe2 100644 --- a/src/miscellaneous.c +++ b/src/miscellaneous.c @@ -159,25 +159,25 @@ void Determine_C_B_nomenclature( u64 qty, char* result, int result_array_size ) } /* Determine the size of throughput so that the correct nomenclature can be used */ - if( qty >= INT64_C( 1000000000000 ) ) + if( qty >= INT64_C( 10000000000000 ) ) { - snprintf( result, result_array_size, "%3llu TB", qty / INT64_C( 1000000000000 ) ); + snprintf( result, result_array_size, "%4llu TB", qty / INT64_C( 1000000000000 ) ); } - else if( qty >= INT64_C( 1000000000 ) ) + else if( qty >= INT64_C( 10000000000 ) ) { - snprintf( result, result_array_size, "%3llu GB", qty / INT64_C( 1000000000 ) ); + snprintf( result, result_array_size, "%4llu GB", qty / INT64_C( 1000000000 ) ); } - else if( qty >= INT64_C( 1000000 ) ) + else if( qty >= INT64_C( 10000000 ) ) { - snprintf( result, result_array_size, "%3llu MB", qty / INT64_C( 1000000 ) ); + snprintf( result, result_array_size, "%4llu MB", qty / INT64_C( 1000000 ) ); } - else if( qty >= INT64_C( 1000 ) ) + else if( qty >= INT64_C( 10000 ) ) { - snprintf( result, result_array_size, "%3llu KB", qty / INT64_C( 1000 ) ); + snprintf( result, result_array_size, "%4llu KB", qty / INT64_C( 1000 ) ); } else { - snprintf( result, result_array_size, "%3llu B", qty / INT64_C( 1 ) ); + snprintf( result, result_array_size, "%4llu B", qty / INT64_C( 1 ) ); } } From 8124d2d493591f9027bc7da03fe9e84298afb077 Mon Sep 17 00:00:00 2001 From: Gerold Gruber Date: Mon, 2 Oct 2023 16:42:41 +0200 Subject: [PATCH 4/6] improved fix for issue #492 --- src/device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/device.c b/src/device.c index d5853bc..57a1add 100644 --- a/src/device.c +++ b/src/device.c @@ -244,7 +244,8 @@ int check_device( nwipe_context_t*** c, PedDevice* dev, int dcount ) for( idx = 0; idx < 20; idx++ ) { - if( isascii( next_device->identity.serial_no[idx] ) ) + if( isascii( next_device->identity.serial_no[idx] ) && + !iscntrl( next_device->identity.serial_no[idx] ) ) { next_device->device_serial_no[idx] = next_device->identity.serial_no[idx]; } From c1e943d2832b6844242660f018d4b4b9c644f9b2 Mon Sep 17 00:00:00 2001 From: Gerold Gruber Date: Mon, 2 Oct 2023 17:30:28 +0200 Subject: [PATCH 5/6] improved formatted fix for issue #492 --- src/device.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/device.c b/src/device.c index 57a1add..6c67216 100644 --- a/src/device.c +++ b/src/device.c @@ -244,8 +244,7 @@ int check_device( nwipe_context_t*** c, PedDevice* dev, int dcount ) for( idx = 0; idx < 20; idx++ ) { - if( isascii( next_device->identity.serial_no[idx] ) && - !iscntrl( next_device->identity.serial_no[idx] ) ) + if( isascii( next_device->identity.serial_no[idx] ) && !iscntrl( next_device->identity.serial_no[idx] ) ) { next_device->device_serial_no[idx] = next_device->identity.serial_no[idx]; } From 8124e6b3d5e3712824ac4c6ff3f66a5c698de3ce Mon Sep 17 00:00:00 2001 From: Gerold Gruber Date: Mon, 2 Oct 2023 20:28:49 +0200 Subject: [PATCH 6/6] added -P option for PDFreportpath --- man/nwipe.1 | 5 +++++ src/context.h | 2 +- src/create_pdf.c | 4 +++- src/logging.c | 9 +++++++-- src/nwipe.c | 12 ++++++++++++ src/options.c | 15 ++++++++++++++- src/options.h | 1 + 7 files changed, 43 insertions(+), 5 deletions(-) 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