From e982ca5fee30bb61bfdf3ce4b977b7c7a505dff2 Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Mon, 15 Nov 2021 18:19:47 +0000 Subject: [PATCH] Add -q --quiet option - anonymize serial numbers Anonymize the serial numbers in the gui, the log and the summary table. If a serial number was obtained from the device, it is replaced with "XXXXXXXXXXXXXXX". If the serial number could not be obtained from the device, it's replaced with "???????????????". --- man/nwipe.1 | 5 +++++ src/device.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/nwipe.c | 2 +- src/options.c | 16 ++++++++++++++-- src/options.h | 1 + src/version.c | 4 ++-- 6 files changed, 73 insertions(+), 6 deletions(-) diff --git a/man/nwipe.1 b/man/nwipe.1 index 2a3452a6..58f8812d 100644 --- a/man/nwipe.1 +++ b/man/nwipe.1 @@ -114,6 +114,11 @@ Filename to log to. Default is STDOUT \fB\-p\fR, \fB\-\-prng\fR=\fIMETHOD\fR PRNG option (mersenne|twister|isaac) .TP +\fB\-q\fR, \fB\-\-quiet\fR +Anonymize serial numbers, Gui & logs display: + XXXXXXXX = S/N obtained & anonymized. + ???????? = S/N not available. +.TP \fB\-r\fR, \fB\-\-rounds\fR=\fINUM\fR Number of times to wipe the device using the selected method (default: 1) .TP diff --git a/src/device.c b/src/device.c index 8f5d2d97..c3de8730 100644 --- a/src/device.c +++ b/src/device.c @@ -231,7 +231,10 @@ int check_device( nwipe_context_t*** c, PedDevice* dev, int dcount ) next_device->device_size_text = next_device->device_size_txt; next_device->result = -2; - /* Attempt to get serial number of device. */ + /* Attempt to get serial number of device. + */ + next_device->device_serial_no[0] = 0; /* initialise the serial number */ + if( ( fd = open( next_device->device_name = dev->path, O_RDONLY ) ) == ERR ) { nwipe_log( NWIPE_LOG_WARNING, "Unable to open device %s to obtain serial number", next_device->device_name ); @@ -269,6 +272,19 @@ int check_device( nwipe_context_t*** c, PedDevice* dev, int dcount ) } } + /* Does the user want to anonymize serial numbers ? */ + if( nwipe_options.quiet ) + { + if( next_device->device_serial_no[0] == 0 ) + { + strcpy( next_device->device_serial_no, "???????????????" ); + } + else + { + strcpy( next_device->device_serial_no, "XXXXXXXXXXXXXXX" ); + } + } + /* All device strings should be 4 characters, prefix with space if under 4 characters */ switch( next_device->device_type ) { @@ -428,6 +444,7 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, c int device_len; int set_return_value; int exit_status; + int idx; char readlink_command[] = "readlink /sys/block/%s"; char readlink_command2[] = "/usr/bin/readlink /sys/block/%s"; @@ -439,6 +456,7 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, c char result[512]; char final_cmd_readlink[sizeof( readlink_command ) + sizeof( device_shortform )]; char final_cmd_smartctl[sizeof( smartctl_command ) + 256]; + char* pResult; /* Initialise return value */ set_return_value = 0; @@ -641,6 +659,37 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, c if( nwipe_options.verbose && result[0] != 0x0A ) { strip_CR_LF( result ); + + /* Remove serial number if -q option specified */ + if( nwipe_options.quiet ) + { + /* set index to character after end of 'Serial Number:' label */ + idx = 14; + + if( ( pResult = strstr( result, "Serial Number:" ) ) != 0 ) + { + /* Ignore spaces, overwrite other characters */ + while( *( pResult + idx ) != 0x0A && *( pResult + idx ) != 0x0D && *( pResult + idx ) != 0 + && idx <= sizeof( result ) - 1 ) + { + if( *( pResult + idx ) == ' ' ) + { + idx++; + continue; + } + else + { + /* ignore if the serial number has been written over with '?' */ + if( *( pResult + idx ) != '?' ) + { + *( pResult + idx ) = 'X'; + } + idx++; + } + } + } + } + nwipe_log( NWIPE_LOG_DEBUG, "smartctl: %s", result ); } diff --git a/src/nwipe.c b/src/nwipe.c index aae4b476..426d51e2 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -206,7 +206,7 @@ int main( int argc, char** argv ) /* Makesure the drivetemp module is loaded, else drives hwmon entries won't appear in /sys/class/hwmon */ if( system( "modprobe drivetemp" ) != 0 ) { - nwipe_log( NWIPE_LOG_ERROR, "hwmon: Unable to load module drivetemp, drive temperatures may not be available" ); + nwipe_log( NWIPE_LOG_WARNING, "hwmon: Unable to load module drivetemp, drivetemp may be build into kernel?" ); } else { diff --git a/src/options.c b/src/options.c index efedc84b..35442078 100644 --- a/src/options.c +++ b/src/options.c @@ -53,7 +53,7 @@ int nwipe_options_parse( int argc, char** argv ) int i; /* The list of acceptable short options. */ - char nwipe_options_short[] = "Vvhl:m:p:r:e:"; + char nwipe_options_short[] = "Vvhl:m:p:qr:e:"; /* The list of acceptable long options. */ static struct option nwipe_options_long[] = { @@ -93,9 +93,12 @@ int nwipe_options_parse( int argc, char** argv ) /* Whether to allow signals to interrupt a wipe. */ { "nosignals", no_argument, 0, 0 }, - /* Whether to exit after wiping or wait for a keypress. */ + /* Whether to display the gui. */ { "nogui", no_argument, 0, 0 }, + /* Whether to anonymize the serial numbers. */ + { "quiet", no_argument, 0, 'q' }, + /* A flag to indicate whether the devices would be opened in sync mode. */ { "sync", required_argument, 0, 0 }, @@ -122,6 +125,7 @@ int nwipe_options_parse( int argc, char** argv ) nwipe_options.nowait = 0; nwipe_options.nosignals = 0; nwipe_options.nogui = 0; + nwipe_options.quiet = 0; nwipe_options.sync = DEFAULT_SYNC_RATE; nwipe_options.verbose = 0; nwipe_options.verify = NWIPE_VERIFY_LAST; @@ -375,6 +379,11 @@ int nwipe_options_parse( int argc, char** argv ) fprintf( stderr, "Error: Unknown prng '%s'.\n", optarg ); exit( EINVAL ); + case 'q': /* Anonymize serial numbers */ + + nwipe_options.quiet = 1; + break; + case 'r': /* Rounds option. */ if( sscanf( optarg, " %i", &nwipe_options.rounds ) != 1 || nwipe_options.rounds < 1 ) @@ -477,6 +486,7 @@ void nwipe_options_log( void ) } nwipe_log( NWIPE_LOG_NOTICE, " method = %s", nwipe_method_label( nwipe_options.method ) ); + nwipe_log( NWIPE_LOG_NOTICE, " quiet = %i", nwipe_options.quiet ); nwipe_log( NWIPE_LOG_NOTICE, " rounds = %i", nwipe_options.rounds ); nwipe_log( NWIPE_LOG_NOTICE, " sync = %i", nwipe_options.sync ); @@ -546,6 +556,8 @@ void display_help() puts( " verify_one - Verifies disk is 0xFF filled\n" ); puts( " -l, --logfile=FILE Filename to log to. Default is STDOUT\n" ); puts( " -p, --prng=METHOD PRNG option (mersenne|twister|isaac)\n" ); + puts( " -q, --quiet Anonymize logs/GUI by removing serial numbers" ); + puts( " XXXXXX = S/N exists, ????? = S/N not obtainable \n" ); puts( " -r, --rounds=NUM Number of times to wipe the device using the selected" ); puts( " method (default: 1)\n" ); puts( " --noblank Do NOT blank disk after wipe" ); diff --git a/src/options.h b/src/options.h index 5731adee..f70a3ec3 100644 --- a/src/options.h +++ b/src/options.h @@ -60,6 +60,7 @@ typedef struct char logfile[FILENAME_MAX]; // The filename to log the output 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. + int quiet; // Anonymize serial numbers int rounds; // The number of times that the wipe method should be called. int sync; // A flag to indicate whether and how often writes should be sync'd. int verbose; // Make log more verbose diff --git a/src/version.c b/src/version.c index 3843e50b..c4ffe119 100644 --- a/src/version.c +++ b/src/version.c @@ -4,7 +4,7 @@ * used by configure to dynamically assign those values * to documentation files. */ -const char* version_string = "0.32.005"; +const char* version_string = "0.32.006"; const char* program_name = "nwipe"; const char* author_name = "Martijn van Brummelen"; const char* email_address = "git@brumit.nl"; @@ -14,4 +14,4 @@ Modifications to original dwipe Copyright Andy Beverley \n\ This is free software; see the source for copying conditions.\n\ There is NO warranty; not even for MERCHANTABILITY or FITNESS\n\ FOR A PARTICULAR PURPOSE.\n"; -const char* banner = "nwipe 0.32.005"; +const char* banner = "nwipe 0.32.006";