Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -q --quiet option - anonymize serial numbers #366

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions man/nwipe.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 50 additions & 1 deletion src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/nwipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
16 changes: 14 additions & 2 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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 },

Expand All @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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" );
Expand Down
1 change: 1 addition & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]";
Expand All @@ -14,4 +14,4 @@ Modifications to original dwipe Copyright Andy Beverley <[email protected]>\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";