From a83a27f8e5dd7e0e34065036e60a0589e7556c0b Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Sun, 12 Dec 2021 20:22:35 +0000 Subject: [PATCH] Fix missing serial number on SAS drive This was caused by inconsistent labeling of the serial number by smartctl. In a majority of cases smartctl would output serial number data using the label "Serial Number:" however on a SAS drive we found that smartctl output the label as "Serial number:" i.e. differs with a lower case 'n'. Unfortunately we were doing a case sensitive search for "Serial Number" so the result being the serial number was not found. This patch converts both strings in the search to lower case before searching. In addition a new field was added to the anonymize list, "logical unit id:" so when the -q option is used "serial number", "lu wwn device id:" and "logical unit id:" are all now anonymized in the smartctl debug data. --- src/device.c | 29 +++++++++++++++++++++++------ src/version.c | 4 ++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/device.c b/src/device.c index 01632c0..b7a87f5 100644 --- a/src/device.c +++ b/src/device.c @@ -459,7 +459,7 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, c char final_cmd_smartctl[sizeof( smartctl_command ) + 256]; char* pResult; char smartctl_labels_to_anonymize[][18] = { - "Serial Number:", "LU WWN Device Id:", "" /* Don't remove this empty string !, important */ + "serial number:", "lu wwn device id:", "logical unit id:", "" /* Don't remove this empty string !, important */ }; /* Initialise return value */ @@ -660,6 +660,23 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, c /* Read the output a line at a time - output it. */ while( fgets( result, sizeof( result ) - 1, fp ) != NULL ) { + /* Convert the label, i.e everything before the ':' to lower case, it's required to + * convert to lower case as smartctl seems to use inconsistent case when labeling + * for serial number, i.e mostly it produces labels "Serial Number:" but occasionaly + * it produces a label "Serial number:" */ + + idx = 0; + while( result[idx] != 0 && result[idx] != ':' ) + { + /* If upper case alpha character, change to lower case */ + if( result[idx] >= 'A' && result[idx] <= 'Z' ) + { + result[idx] += 32; + } + + idx++; + } + if( nwipe_options.verbose && result[0] != 0x0A ) { strip_CR_LF( result ); @@ -704,7 +721,7 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, c nwipe_log( NWIPE_LOG_DEBUG, "smartctl: %s", result ); } - if( strstr( result, "Serial Number:" ) != 0 ) + if( strstr( result, "serial number:" ) != 0 ) { /* strip any leading or trailing spaces and left justify, +15 is the length of "Serial Number:" */ trim( &result[15] ); @@ -714,24 +731,24 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, c if( *bus == 0 ) { - if( strstr( result, "Transport protocol:" ) != 0 ) + if( strstr( result, "transport protocol:" ) != 0 ) { /* strip any leading or trailing spaces and left justify, +4 is the length of "bus type:" */ trim( &result[19] ); - if( strncmp( &result[19], "SAS", 3 ) == 0 ) + if( strncmp( &result[19], "sas", 3 ) == 0 ) { *bus = NWIPE_DEVICE_SAS; } } - if( strstr( result, "SATA Version is:" ) != 0 ) + if( strstr( result, "sata version is:" ) != 0 ) { /* strip any leading or trailing spaces and left justify, +4 is the length of "bus type:" */ trim( &result[16] ); - if( strncmp( &result[16], "SATA", 4 ) == 0 ) + if( strncmp( &result[16], "sata", 4 ) == 0 ) { *bus = NWIPE_DEVICE_ATA; } diff --git a/src/version.c b/src/version.c index 4ebe1db..04bcbba 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.018"; +const char* version_string = "0.32.019"; 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.018"; +const char* banner = "nwipe 0.32.019";