mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-21 22:42:29 +00:00
Compare commits
89 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37dfb1a2b6 | ||
|
|
55783c0b8d | ||
|
|
52d0508b23 | ||
|
|
d2a66e0047 | ||
|
|
11ed6b1472 | ||
|
|
0fec3a1213 | ||
|
|
b341d1dab0 | ||
|
|
c92a87860d | ||
|
|
545491940e | ||
|
|
cd16c2e86b | ||
|
|
00469644d8 | ||
|
|
ac680b4225 | ||
|
|
c58ab04ff6 | ||
|
|
bb91f093a3 | ||
|
|
025a02e87c | ||
|
|
68cad1b640 | ||
|
|
54f643559f | ||
|
|
cd3716f260 | ||
|
|
43172a9741 | ||
|
|
10221fb2a9 | ||
|
|
9b821292ea | ||
|
|
6b350a2348 | ||
|
|
6ec7826692 | ||
|
|
00e9350dd6 | ||
|
|
c46e0c8ba4 | ||
|
|
af1b470456 | ||
|
|
ae51d548d4 | ||
|
|
5f712f3b0c | ||
|
|
99778f187d | ||
|
|
528bb9fd6a | ||
|
|
08215f3fb2 | ||
|
|
f20e7c6b74 | ||
|
|
27bb409efa | ||
|
|
cfd75a918c | ||
|
|
f56977930a | ||
|
|
fa0d72cbaf | ||
|
|
42a114abc0 | ||
|
|
58d4733273 | ||
|
|
fe4fdaee93 | ||
|
|
157797c1ca | ||
|
|
396896e16c | ||
|
|
5cb6003fc0 | ||
|
|
b2bee8ac83 | ||
|
|
4606834286 | ||
|
|
ed5ca0fce7 | ||
|
|
9c69bc0e1a | ||
|
|
a049c871b6 | ||
|
|
f960da3f4a | ||
|
|
81850bde42 | ||
|
|
e92ac3a870 | ||
|
|
0ecc90786d | ||
|
|
5912d0f57a | ||
|
|
e16da663a1 | ||
|
|
a9ed8a091a | ||
|
|
dd74c429b0 | ||
|
|
baab603809 | ||
|
|
0fa21d4c04 | ||
|
|
3bc0235d38 | ||
|
|
533fa56de8 | ||
|
|
011901b28e | ||
|
|
b47fe001b3 | ||
|
|
3638eae8d4 | ||
|
|
b0bc174d32 | ||
|
|
8f5c05506f | ||
|
|
23c69f34c1 | ||
|
|
0b1cb83013 | ||
|
|
17f23ba03b | ||
|
|
22665fa781 | ||
|
|
95dc8abcf3 | ||
|
|
fd55f48267 | ||
|
|
d9ba357722 | ||
|
|
8a85d7e96f | ||
|
|
cac9b17f9b | ||
|
|
37109daae7 | ||
|
|
052852d475 | ||
|
|
4b20e7ca76 | ||
|
|
c8a5a16108 | ||
|
|
4e64cab3c3 | ||
|
|
5f65683f63 | ||
|
|
7b170bb444 | ||
|
|
464bf788c5 | ||
|
|
16e78b8523 | ||
|
|
f71b23afc4 | ||
|
|
e7d9ff73fe | ||
|
|
1fce0eb936 | ||
|
|
72c5cd8a0f | ||
|
|
0f06e91ce5 | ||
|
|
0f26c8ea68 | ||
|
|
b808b8402c |
31
.gitignore
vendored
Normal file
31
.gitignore
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
autom4te.cache/
|
||||
compile
|
||||
config.h
|
||||
config.h.in
|
||||
config.log
|
||||
config.status
|
||||
configure
|
||||
depcomp
|
||||
install-sh
|
||||
man/Makefile
|
||||
man/Makefile.in
|
||||
missing
|
||||
src/.deps/
|
||||
src/Makefile
|
||||
src/Makefile.in
|
||||
src/nwipe
|
||||
src/nwipe-device.o
|
||||
src/nwipe-gui.o
|
||||
src/nwipe-isaac_rand.o
|
||||
src/nwipe-logging.o
|
||||
src/nwipe-method.o
|
||||
src/nwipe-mt19937ar-cok.o
|
||||
src/nwipe-nwipe.o
|
||||
src/nwipe-options.o
|
||||
src/nwipe-pass.o
|
||||
src/nwipe-prng.o
|
||||
src/nwipe-version.o
|
||||
stamp-h1
|
||||
92
README
92
README
@@ -1,14 +1,70 @@
|
||||
Installation
|
||||
============
|
||||
First bootstrap the source tree:
|
||||
Compiling & Installing
|
||||
======================
|
||||
|
||||
Nwipe requires the following libraries to be installed.
|
||||
|
||||
ncurses
|
||||
pthreads
|
||||
parted
|
||||
|
||||
Debian & Ubuntu prerequisites
|
||||
============================
|
||||
|
||||
If you compiling nwipe from source the following will need to be installed first
|
||||
|
||||
sudo apt install build-essential
|
||||
sudo apt install pkg-config
|
||||
sudo apt install automake
|
||||
sudo apt install libncurses5-dev
|
||||
sudo apt install autotools-dev
|
||||
sudo apt install libparted-dev
|
||||
|
||||
Fedora prerequisites
|
||||
====================
|
||||
|
||||
sudo bash
|
||||
dnf update
|
||||
dnf groupinstall "Development Tools"
|
||||
dnf groupinstall "C Development Tools and Libraries"
|
||||
yum install ncurses-devel
|
||||
yum install parted-devel
|
||||
|
||||
Compilation
|
||||
===========
|
||||
|
||||
then create all the autoconf files:
|
||||
|
||||
./init.sh
|
||||
|
||||
The install using the standard:
|
||||
Then compile & install using the standard: (Devs see below)
|
||||
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
|
||||
The ncurses, pthreads and parted libraries are required for compiling.
|
||||
Developers !
|
||||
==========
|
||||
|
||||
If you wish to submit pull requests to this code we would prefer you enable all warnings,
|
||||
this can be done using the alternate compile commands
|
||||
|
||||
./configure --prefix=/usr CFLAGS='-O0 -g -Wall -Wextra'
|
||||
make
|
||||
make install
|
||||
|
||||
The '-O0 -g' flags disable optimisations, this is required if your debugging with
|
||||
gdb in an IDE such as Kdevelop. Without these optimisations disabled you won't be
|
||||
able to see the values of many variables in nwipe, not to mention the IDE won't step
|
||||
through the code properly.
|
||||
|
||||
The -Wall & -Wextra flags enable all compiler warnings. Please submit code with zero warnings.
|
||||
|
||||
Once done with your coding then the released/patch/fixed code can be compiled with
|
||||
|
||||
./configure --prefix=/usr && make && make install
|
||||
|
||||
complete with all it's optimisations.
|
||||
|
||||
For any problems, please use the Github page:
|
||||
https://github.com/martijnvanbrummelen/nwipe
|
||||
|
||||
@@ -18,6 +74,32 @@ Martijn van Brummelen
|
||||
RELEASE NOTES
|
||||
=============
|
||||
|
||||
v0.26
|
||||
- New release
|
||||
- Add exclude drive option(Thanks PartialVolume)
|
||||
- Log hardware (Thanks PartialVolume)
|
||||
|
||||
v0.25
|
||||
- Correct J=Up K=Down in footer(Thanks PartialVolume)
|
||||
- Fix segfault initialize nwipe_gui_thread (Thanks PartialVolume)
|
||||
- Fix memory leaks (Thanks PartialVolume)
|
||||
- Check right pointer (Thanks PartialVolume)
|
||||
- Fix casting problem (Thanks PartialVolume)
|
||||
- Fix serial number
|
||||
- Fixes uninitialized variable warning ( Thanks PartialVolume)
|
||||
|
||||
v0.24
|
||||
- use include values for version 0.17
|
||||
- display throughput value more friendly(Thanks Kelderek)
|
||||
|
||||
v0.23
|
||||
- make serial visible again on 32Bit machines
|
||||
|
||||
v0.22
|
||||
- Update manpage
|
||||
- use long long for device size
|
||||
- Use ped_unit_format_byte function to display(friendly) size of device
|
||||
|
||||
v0.21
|
||||
- Fix ETA not updating properly and bad total throughput display. Thanks (Niels Bassler).
|
||||
|
||||
|
||||
@@ -11,5 +11,5 @@ To use from the git repository, first create all the autoconf files with
|
||||
|
||||
Then do the standard ./configure --prefix=/usr && make && make install
|
||||
|
||||
For release notes please see the [README file](README)
|
||||
For developer & release notes please see the [README file](README)
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.64])
|
||||
AC_INIT(nwipe, 0.21, git@brumit.nl)
|
||||
AM_INIT_AUTOMAKE(nwipe, 0.21)
|
||||
AC_INIT(nwipe, 0.26, git@brumit.nl)
|
||||
AM_INIT_AUTOMAKE(nwipe, 0.26)
|
||||
AC_OUTPUT(Makefile src/Makefile man/Makefile)
|
||||
AC_CONFIG_SRCDIR([src/nwipe.c])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
|
||||
11
man/nwipe.1
11
man/nwipe.1
@@ -1,4 +1,4 @@
|
||||
.TH NWIPE "1" "October 2014" "nwipe version 0.17" "User Commands"
|
||||
.TH NWIPE "1" "September 2019" "nwipe version 0.26" "User Commands"
|
||||
.SH NAME
|
||||
nwipe \- securely erase disks
|
||||
.SH SYNOPSIS
|
||||
@@ -7,7 +7,7 @@ nwipe \- securely erase disks
|
||||
.SH DESCRIPTION
|
||||
nwipe is a command that will securely erase disks using a variety of
|
||||
recognised methods. It is a fork of the dwipe command used by Darik's Boot
|
||||
and Nuke (dban). nwipe is included with partedmagic if want a quick and
|
||||
and Nuke (dban). nwipe is included with partedmagic if you want a quick and
|
||||
easy bootable CD version. nwipe was created out of a need to run the DBAN
|
||||
dwipe command outside of DBAN, in order to allow its use with any host
|
||||
distribution, thus giving better hardware support. It is essentially the
|
||||
@@ -78,11 +78,10 @@ PRNG option (mersenne|twister|isaac)
|
||||
\fB\-r\fR, \fB\-\-rounds\fR=\fINUM\fR
|
||||
Number of times to wipe the device using the selected method (default: 1)
|
||||
.SH BUGS
|
||||
Please see the sourceforge site for the latest list
|
||||
(http://nwipe.sourceforge.net)
|
||||
Please see the GitHub site for the latest list
|
||||
(https://github.com/martijnvanbrummelen/nwipe/issues)
|
||||
.SH AUTHOR
|
||||
Nwipe was released by Andy Beverley <andy@andybev.com>
|
||||
as modified version of dwipe from DBAN by Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
Nwipe is developed by Martijn van Brummelen <github@brumit.nl>
|
||||
.SH "SEE ALSO"
|
||||
.BR shred (1),
|
||||
.BR dwipe (1),
|
||||
|
||||
@@ -72,48 +72,53 @@ typedef struct nwipe_speedring_t_
|
||||
|
||||
typedef struct nwipe_context_t_
|
||||
{
|
||||
int block_size; /* The soft block size reported the device. */
|
||||
int device_bus; /* The device bus number. */
|
||||
int device_fd; /* The file descriptor of the device file being wiped. */
|
||||
int device_host; /* The host number. */
|
||||
struct hd_driveid device_id; /* The WIN_IDENTIFY data for IDE drives. */
|
||||
int device_lun; /* The device logical unit number. */
|
||||
int device_major; /* The major device number. */
|
||||
int device_minor; /* The minor device number. */
|
||||
int device_part; /* The device partition or slice number. */
|
||||
char* device_name; /* The device file name. */
|
||||
off64_t device_size; /* The device size in bytes. */
|
||||
struct stat device_stat; /* The device file state from fstat(). */
|
||||
nwipe_device_t device_type; /* Indicates an IDE, SCSI, or Compaq SMART device. */
|
||||
int device_target; /* The device target. */
|
||||
u64 eta; /* The estimated number of seconds until method completion. */
|
||||
int entropy_fd; /* The entropy source. Usually /dev/urandom. */
|
||||
char* label; /* The string that we will show the user. */
|
||||
int pass_count; /* The number of passes performed by the working wipe method. */
|
||||
u64 pass_done; /* The number of bytes that have already been i/o'd in this pass. */
|
||||
u64 pass_errors; /* The number of errors across all passes. */
|
||||
u64 pass_size; /* The total number of i/o bytes across all passes. */
|
||||
nwipe_pass_t pass_type; /* The type of the current working pass. */
|
||||
int pass_working; /* The current working pass. */
|
||||
nwipe_prng_t* prng; /* The PRNG implementation. */
|
||||
nwipe_entropy_t prng_seed; /* The random data that is used to seed the PRNG. */
|
||||
void* prng_state; /* The private internal state of the PRNG. */
|
||||
int result; /* The process return value. */
|
||||
int round_count; /* The number of rounds performed by the working wipe method. */
|
||||
u64 round_done; /* The number of bytes that have already been i/o'd. */
|
||||
u64 round_errors; /* The number of errors across all rounds. */
|
||||
u64 round_size; /* The total number of i/o bytes across all rounds. */
|
||||
double round_percent; /* The percentage complete across all rounds. */
|
||||
int round_working; /* The current working round. */
|
||||
int sector_size; /* The hard sector size reported by the device. */
|
||||
nwipe_select_t select; /* Indicates whether this device should be wiped. */
|
||||
int signal; /* Set when the child is killed by a signal. */
|
||||
nwipe_speedring_t speedring; /* Ring buffer for computing the rolling throughput average. */
|
||||
short sync_status; /* A flag to indicate when the method is syncing. */
|
||||
pthread_t thread; /* The ID of the thread. */
|
||||
u64 throughput; /* Average throughput in bytes per second. */
|
||||
u64 verify_errors; /* The number of verification errors across all passes. */
|
||||
struct hd_driveid identity; /* The serial number of the drive (where applicable) */
|
||||
int block_size; /* The soft block size reported the device. */
|
||||
int device_bus; /* The device bus number. */
|
||||
int device_fd; /* The file descriptor of the device file being wiped. */
|
||||
int device_host; /* The host number. */
|
||||
struct hd_driveid device_id; /* The WIN_IDENTIFY data for IDE drives. */
|
||||
int device_lun; /* The device logical unit number. */
|
||||
int device_major; /* The major device number. */
|
||||
int device_minor; /* The minor device number. */
|
||||
int device_part; /* The device partition or slice number. */
|
||||
char* device_name; /* The device file name. */
|
||||
long long device_size; /* The device size in bytes. */
|
||||
char* device_size_text; /* The device size in a more (human)readable format. */
|
||||
struct stat device_stat; /* The device file state from fstat(). */
|
||||
nwipe_device_t device_type; /* Indicates an IDE, SCSI, or Compaq SMART device. */
|
||||
int device_target; /* The device target. */
|
||||
u64 eta; /* The estimated number of seconds until method completion. */
|
||||
int entropy_fd; /* The entropy source. Usually /dev/urandom. */
|
||||
char* label; /* The string that we will show the user. */
|
||||
int pass_count; /* The number of passes performed by the working wipe method. */
|
||||
u64 pass_done; /* The number of bytes that have already been i/o'd in this pass. */
|
||||
u64 pass_errors; /* The number of errors across all passes. */
|
||||
u64 pass_size; /* The total number of i/o bytes across all passes. */
|
||||
nwipe_pass_t pass_type; /* The type of the current working pass. */
|
||||
int pass_working; /* The current working pass. */
|
||||
nwipe_prng_t* prng; /* The PRNG implementation. */
|
||||
nwipe_entropy_t prng_seed; /* The random data that is used to seed the PRNG. */
|
||||
void* prng_state; /* The private internal state of the PRNG. */
|
||||
int result; /* The process return value. */
|
||||
int round_count; /* The number of rounds performed by the working wipe method. */
|
||||
u64 round_done; /* The number of bytes that have already been i/o'd. */
|
||||
u64 round_errors; /* The number of errors across all rounds. */
|
||||
u64 round_size; /* The total number of i/o bytes across all rounds. */
|
||||
double round_percent; /* The percentage complete across all rounds. */
|
||||
int round_working; /* The current working round. */
|
||||
int sector_size; /* The hard sector size reported by the device. */
|
||||
nwipe_select_t select; /* Indicates whether this device should be wiped. */
|
||||
int signal; /* Set when the child is killed by a signal. */
|
||||
nwipe_speedring_t speedring; /* Ring buffer for computing the rolling throughput average. */
|
||||
short sync_status; /* A flag to indicate when the method is syncing. */
|
||||
pthread_t thread; /* The ID of the thread. */
|
||||
u64 throughput; /* Average throughput in bytes per second. */
|
||||
u64 verify_errors; /* The number of verification errors across all passes. */
|
||||
char serial_no[21]; /* Serial number(processed), 20 characters, plus null termination */
|
||||
struct hd_driveid identity; /* Identity contains the raw serial number of the drive */
|
||||
/* (where applicable), however, for use within nwipe use the */
|
||||
/* processed serial_no[21] string above. To access serial no. use */
|
||||
/* c[i]->serial_no) and not c[i]->identity.serial_no); */
|
||||
} nwipe_context_t;
|
||||
|
||||
|
||||
|
||||
141
src/device.c
141
src/device.c
@@ -20,19 +20,26 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* Why is this needed? Segfaults without it */
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "nwipe.h"
|
||||
#include "context.h"
|
||||
#include "method.h"
|
||||
#include "options.h"
|
||||
#include "logging.h"
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/hdreg.h> //Drive specific defs
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <parted/parted.h>
|
||||
#include <parted/debug.h>
|
||||
#include <parted/debug.h>
|
||||
|
||||
int check_device( nwipe_context_t*** c, PedDevice* dev, int dcount );
|
||||
char *trim(char *str);
|
||||
|
||||
int nwipe_device_scan( nwipe_context_t*** c )
|
||||
{
|
||||
@@ -85,8 +92,8 @@ int nwipe_device_get( nwipe_context_t*** c, char **devnamelist, int ndevnames )
|
||||
if (!dev)
|
||||
break;
|
||||
|
||||
if (check_device(c, dev, dcount))
|
||||
dcount++;
|
||||
if (check_device(c, dev, dcount))
|
||||
dcount++;
|
||||
}
|
||||
|
||||
/* Return the number of devices that were found. */
|
||||
@@ -98,38 +105,114 @@ int check_device( nwipe_context_t*** c, PedDevice* dev, int dcount )
|
||||
{
|
||||
/* Populate this struct, then assign it to overall array of structs. */
|
||||
nwipe_context_t* next_device;
|
||||
int fd;
|
||||
int idx;
|
||||
|
||||
/* Try opening the device to see if it's valid. Close on completion. */
|
||||
if (!ped_device_open(dev))
|
||||
return 0;
|
||||
ped_device_close(dev);
|
||||
/* Check whether this drive is on the excluded drive list ? */
|
||||
idx=0;
|
||||
while ( idx < 10 )
|
||||
{
|
||||
if ( !strcmp( dev->path, nwipe_options.exclude[idx++] ))
|
||||
{
|
||||
nwipe_log( NWIPE_LOG_NOTICE, "Device %s excluded as per command line option -e", dev->path );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Try opening the device to see if it's valid. Close on completion. */
|
||||
if (!ped_device_open(dev))
|
||||
{
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to open device" );
|
||||
return 0;
|
||||
}
|
||||
ped_device_close(dev);
|
||||
|
||||
/* New device, reallocate memory for additional struct pointer */
|
||||
*c = realloc (*c, (dcount+1) * sizeof(nwipe_context_t *));
|
||||
/* New device, reallocate memory for additional struct pointer */
|
||||
*c = realloc (*c, (dcount+1) * sizeof(nwipe_context_t *));
|
||||
|
||||
next_device = malloc (sizeof(nwipe_context_t));
|
||||
next_device = malloc (sizeof(nwipe_context_t));
|
||||
|
||||
/* Check the allocation. */
|
||||
if( ! next_device )
|
||||
{
|
||||
nwipe_perror( errno, __FUNCTION__, "malloc" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to create the array of enumeration contexts." );
|
||||
return 0;
|
||||
}
|
||||
/* Check the allocation. */
|
||||
if( ! next_device )
|
||||
{
|
||||
nwipe_perror( errno, __FUNCTION__, "malloc" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to create the array of enumeration contexts." );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Zero the allocation. */
|
||||
memset( next_device , 0, sizeof( nwipe_context_t ) );
|
||||
/* Zero the allocation. */
|
||||
memset( next_device , 0, sizeof( nwipe_context_t ) );
|
||||
|
||||
/* Get device information */
|
||||
next_device->label = dev->model;
|
||||
next_device->device_name = dev->path;
|
||||
next_device->device_size = dev->length * dev->sector_size;
|
||||
/* Attempt to get serial number of device. */
|
||||
ioctl(next_device->device_fd, HDIO_GET_IDENTITY, &next_device->identity);
|
||||
/* Get device information */
|
||||
next_device->label = dev->model;
|
||||
next_device->device_name = dev->path;
|
||||
next_device->device_size = dev->length * dev->sector_size;
|
||||
next_device->device_size_text = ped_unit_format_byte(dev, dev->length * dev->sector_size);
|
||||
/* Attempt to get serial number of device. */
|
||||
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 );
|
||||
}
|
||||
/* We don't check the ioctl return status because there are plenty of situations where a serial number may not be
|
||||
* returned by ioctl such as USB drives, logical volumes, encryted volumes, so the log file would have multiple
|
||||
* benign ioctl errors reported which isn't necessarily a problem.
|
||||
*/
|
||||
ioctl(fd, HDIO_GET_IDENTITY, &next_device->identity);
|
||||
close( fd );
|
||||
|
||||
(*c)[dcount] = next_device;
|
||||
for (idx=0; idx<20; idx++) next_device->serial_no[idx]=next_device->identity.serial_no[idx];
|
||||
|
||||
next_device->serial_no[20]=0; /* terminate the string */
|
||||
trim ( (char*) next_device->serial_no ); /* Remove leading/training whitespace from serial number and left justify */
|
||||
|
||||
nwipe_log( NWIPE_LOG_INFO,"Found drive model=\"%s\", device path=\"%s\", size=\"%s\", serial number=\"%s\"", next_device->label, next_device->device_name, next_device->device_size_text, next_device->serial_no);
|
||||
|
||||
(*c)[dcount] = next_device;
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Remove leading/training whitespace from a string and left justify result */
|
||||
char *trim(char *str)
|
||||
{
|
||||
size_t len = 0;
|
||||
char *frontp = str;
|
||||
char *endp = NULL;
|
||||
|
||||
if( str == NULL )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if( str[0] == '\0' )
|
||||
{
|
||||
return str;
|
||||
}
|
||||
len = strlen(str);
|
||||
endp = str + len;
|
||||
|
||||
/* Move the front and back pointers to address the first non-whitespace
|
||||
* characters from each end.
|
||||
*/
|
||||
while( isspace((unsigned char) *frontp) ) { ++frontp; }
|
||||
if( endp != frontp )
|
||||
{
|
||||
while( isspace((unsigned char) *(--endp)) && endp != frontp ) {}
|
||||
}
|
||||
if( str + len - 1 != endp )
|
||||
*(endp + 1) = '\0';
|
||||
else if( frontp != str && endp == frontp )
|
||||
*str = '\0';
|
||||
/* Shift the string so that it starts at str so that if it's dynamically
|
||||
* allocated, we can still free it on the returned pointer. Note the reuse
|
||||
* of endp to mean the front of the string buffer now.
|
||||
*/
|
||||
endp = str;
|
||||
if( frontp != str )
|
||||
{
|
||||
while( *frontp ) { *endp++ = *frontp++; }
|
||||
*endp = '\0';
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/* eof */
|
||||
|
||||
72
src/gui.c
72
src/gui.c
@@ -29,9 +29,9 @@
|
||||
* and things like ncurses libmenu are not worth the storage overhead.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Why is this needed? Segfaults without it */
|
||||
#include <netinet/in.h>
|
||||
#include <ncurses.h>
|
||||
#include <panel.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "nwipe.h"
|
||||
#include "context.h"
|
||||
@@ -41,6 +41,8 @@
|
||||
#include "gui.h"
|
||||
#include "pass.h"
|
||||
#include "logging.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#define NWIPE_GUI_PANE 8
|
||||
|
||||
@@ -124,7 +126,7 @@ const char* stats_title = " Statistics ";
|
||||
|
||||
/* Footer labels. */
|
||||
const char* nwipe_buttons1 = "Ctrl-C=Quit S=Start M=Method P=PRNG V=Verify R=Rounds B=Blanking-pass Space=Select";
|
||||
const char* nwipe_buttons2 = " J=Up K=Down Space=Select";
|
||||
const char* nwipe_buttons2 = " J=Down K=Up Space=Select";
|
||||
const char* nwipe_buttons3 = " B=Blank screen, ctrl-c=Quit";
|
||||
|
||||
|
||||
@@ -138,6 +140,7 @@ void nwipe_gui_title( WINDOW* w, const char* s )
|
||||
|
||||
/* The number of lines in the window. (Not used.) */
|
||||
int wy;
|
||||
(void) wy; /* flag wy not used to the compiler, to silence warning */
|
||||
|
||||
/* The number of columns in the window. */
|
||||
int wx;
|
||||
@@ -229,7 +232,7 @@ void nwipe_gui_init( void )
|
||||
wclear( header_window );
|
||||
|
||||
/* Print the product banner. */
|
||||
nwipe_gui_title( header_window, nwipe_options.banner );
|
||||
nwipe_gui_title( header_window, banner );
|
||||
|
||||
/* Create the footer window. */
|
||||
footer_window = newwin( NWIPE_GUI_FOOTER_H, NWIPE_GUI_FOOTER_W, NWIPE_GUI_FOOTER_Y, NWIPE_GUI_FOOTER_X );
|
||||
@@ -446,40 +449,40 @@ void nwipe_gui_select( int count, nwipe_context_t** c )
|
||||
{
|
||||
case NWIPE_SELECT_TRUE:
|
||||
|
||||
wprintw( main_window, " [wipe] %i. %s - %s %s (%lld bytes)", (i + offset + 1),
|
||||
wprintw( main_window, " [wipe] %i. %s - %s %s (%s)", (i + offset + 1),
|
||||
c[i+offset]->device_name,
|
||||
c[i+offset]->label,
|
||||
c[i+offset]->identity.serial_no,
|
||||
c[i+offset]->device_size );
|
||||
c[i+offset]->serial_no,
|
||||
c[i+offset]->device_size_text );
|
||||
break;
|
||||
|
||||
case NWIPE_SELECT_FALSE:
|
||||
/* Print an element that is not selected. */
|
||||
wprintw( main_window, " [ ] %i. %s - %s %s (%lld bytes)", (i + offset +1),
|
||||
wprintw( main_window, " [ ] %i. %s - %s %s (%s)", (i + offset +1),
|
||||
c[i+offset]->device_name,
|
||||
c[i+offset]->label,
|
||||
c[i+offset]->identity.serial_no,
|
||||
c[i+offset]->device_size );
|
||||
c[i+offset]->serial_no,
|
||||
c[i+offset]->device_size_text );
|
||||
break;
|
||||
|
||||
case NWIPE_SELECT_TRUE_PARENT:
|
||||
|
||||
/* This element will be wiped when its parent is wiped. */
|
||||
wprintw( main_window, " [****] %i. %s - %s %s (%lld bytes)", (i + offset +1),
|
||||
wprintw( main_window, " [****] %i. %s - %s %s (%s)", (i + offset +1),
|
||||
c[i+offset]->device_name,
|
||||
c[i+offset]->label,
|
||||
c[i+offset]->identity.serial_no,
|
||||
c[i+offset]->device_size );
|
||||
c[i+offset]->serial_no,
|
||||
c[i+offset]->device_size_text );
|
||||
break;
|
||||
|
||||
case NWIPE_SELECT_FALSE_CHILD:
|
||||
|
||||
/* We can't wipe this element because it has a child that is being wiped. */
|
||||
wprintw( main_window, " [----] %i. %s - %s %s (%lld bytes)", (i + offset +1),
|
||||
wprintw( main_window, " [----] %i. %s - %s %s (%s)", (i + offset +1),
|
||||
c[i+offset]->device_name,
|
||||
c[i+offset]->label,
|
||||
c[i+offset]->identity.serial_no,
|
||||
c[i+offset]->device_size );
|
||||
c[i+offset]->serial_no,
|
||||
c[i+offset]->device_size_text );
|
||||
break;
|
||||
|
||||
case NWIPE_SELECT_DISABLED:
|
||||
@@ -994,7 +997,7 @@ void nwipe_gui_prng( void )
|
||||
if( nwipe_options.prng == &nwipe_isaac ) { focus = 1; }
|
||||
|
||||
|
||||
while( keystroke != ERR )
|
||||
do
|
||||
{
|
||||
/* Clear the main window. */
|
||||
werase( main_window );
|
||||
@@ -1084,7 +1087,8 @@ void nwipe_gui_prng( void )
|
||||
|
||||
} /* switch */
|
||||
|
||||
} /* while */
|
||||
}
|
||||
while( keystroke != ERR );
|
||||
|
||||
} /* nwipe_gui_prng */
|
||||
|
||||
@@ -1123,7 +1127,7 @@ void nwipe_gui_verify( void )
|
||||
nwipe_gui_title( footer_window, nwipe_buttons2 );
|
||||
wrefresh( footer_window );
|
||||
|
||||
while( keystroke != ERR )
|
||||
do
|
||||
{
|
||||
/* Clear the main window. */
|
||||
werase( main_window );
|
||||
@@ -1218,7 +1222,8 @@ void nwipe_gui_verify( void )
|
||||
|
||||
} /* switch */
|
||||
|
||||
} /* while */
|
||||
}
|
||||
while( keystroke != ERR );
|
||||
|
||||
} /* nwipe_gui_verify */
|
||||
|
||||
@@ -1256,7 +1261,7 @@ void nwipe_gui_noblank( void )
|
||||
nwipe_gui_title( footer_window, nwipe_buttons2 );
|
||||
wrefresh( footer_window );
|
||||
|
||||
while( keystroke != ERR )
|
||||
do
|
||||
{
|
||||
/* Clear the main window. */
|
||||
werase( main_window );
|
||||
@@ -1338,8 +1343,9 @@ void nwipe_gui_noblank( void )
|
||||
|
||||
} /* switch */
|
||||
|
||||
} /* while */
|
||||
}
|
||||
|
||||
while( keystroke != ERR );
|
||||
} /* nwipe_gui_noblank */
|
||||
|
||||
|
||||
@@ -1811,11 +1817,11 @@ void *nwipe_gui_status( void *ptr )
|
||||
for( i = offset ; i < offset + slots && i < count ; i++ )
|
||||
{
|
||||
/* Print the context label. */
|
||||
if ( strlen(c[i]->identity.serial_no) )
|
||||
if ( strlen((const char*)c[i]->serial_no) )
|
||||
{
|
||||
mvwprintw( main_window, yy++, 2, "%s - %s (%s)", c[i]->device_name,
|
||||
c[i]->label,
|
||||
c[i]->identity.serial_no);
|
||||
c[i]->serial_no);
|
||||
}
|
||||
else {
|
||||
mvwprintw( main_window, yy++, 2, "%s - %s", c[i]->device_name,
|
||||
@@ -1867,13 +1873,13 @@ void *nwipe_gui_status( void *ptr )
|
||||
|
||||
if( c[i]->sync_status ) { wprintw( main_window, "[syncing] " ); }
|
||||
|
||||
if( c[i]->throughput >= INT64_C( 1000000000000000 ) )
|
||||
if( c[i]->throughput >= INT64_C( 1000000000000 ) )
|
||||
{ wprintw( main_window, "[%llu TB/s] ", c[i]->throughput / INT64_C( 1000000000000 ) ); }
|
||||
else if( c[i]->throughput >= INT64_C( 1000000000000 ) )
|
||||
{ wprintw( main_window, "[%llu GB/s] ", c[i]->throughput / INT64_C( 1000000000 ) ); }
|
||||
else if( c[i]->throughput >= INT64_C( 1000000000 ) )
|
||||
{ wprintw( main_window, "[%llu MB/s] ", c[i]->throughput / INT64_C( 1000000 ) ); }
|
||||
{ wprintw( main_window, "[%llu GB/s] ", c[i]->throughput / INT64_C( 1000000000 ) ); }
|
||||
else if( c[i]->throughput >= INT64_C( 1000000 ) )
|
||||
{ wprintw( main_window, "[%llu MB/s] ", c[i]->throughput / INT64_C( 1000000 ) ); }
|
||||
else if( c[i]->throughput >= INT64_C( 1000 ) )
|
||||
{ wprintw( main_window, "[%llu KB/s] ", c[i]->throughput / INT64_C( 1000 ) ); }
|
||||
else
|
||||
{ wprintw( main_window, "[%llu B/s] ", c[i]->throughput / INT64_C( 1 ) ); }
|
||||
@@ -1908,13 +1914,13 @@ void *nwipe_gui_status( void *ptr )
|
||||
|
||||
|
||||
u64 nwipe_throughput = nwipe_misc_thread_data->throughput;
|
||||
if( nwipe_throughput >= INT64_C( 1000000000000000 ) )
|
||||
if( nwipe_throughput >= INT64_C( 1000000000000 ) )
|
||||
{ nwipe_throughput /= INT64_C( 1000000000000 ); nwipe_format = nwipe_tera; }
|
||||
else if( nwipe_throughput >= INT64_C( 1000000000000 ) )
|
||||
{ nwipe_throughput /= INT64_C( 1000000000 ); nwipe_format = nwipe_giga; }
|
||||
else if( nwipe_throughput >= INT64_C( 1000000000 ) )
|
||||
{ nwipe_throughput /= INT64_C( 1000000 ); nwipe_format = nwipe_mega; }
|
||||
{ nwipe_throughput /= INT64_C( 1000000000 ); nwipe_format = nwipe_giga; }
|
||||
else if( nwipe_throughput >= INT64_C( 1000000 ) )
|
||||
{ nwipe_throughput /= INT64_C( 1000000 ); nwipe_format = nwipe_mega; }
|
||||
else if( nwipe_throughput >= INT64_C( 1000 ) )
|
||||
{ nwipe_throughput /= INT64_C( 1000 ); nwipe_format = nwipe_kilo; }
|
||||
else
|
||||
{ nwipe_throughput /= INT64_C( 1 ); nwipe_format = nwipe_unit; }
|
||||
|
||||
@@ -29,8 +29,10 @@ void isaac(ctx)
|
||||
randctx *ctx;
|
||||
{
|
||||
register ub4 a,b,x,y,*m,*mm,*m2,*r,*mend;
|
||||
mm=ctx->randmem; r=ctx->randrsl;
|
||||
a = ctx->randa; b = ctx->randb + (++ctx->randc);
|
||||
mm=ctx->randmem;
|
||||
r=ctx->randrsl;
|
||||
a = ctx->randa;
|
||||
b = ctx->randb + (++ctx->randc);
|
||||
for (m = mm, mend = m2 = m+(RANDSIZ/2); m<mend; )
|
||||
{
|
||||
rngstep( a<<13, a, b, mm, m, m2, r, x);
|
||||
@@ -84,20 +86,44 @@ word flag;
|
||||
/* initialize using the contents of r[] as the seed */
|
||||
for (i=0; i<RANDSIZ; i+=8)
|
||||
{
|
||||
a+=r[i ]; b+=r[i+1]; c+=r[i+2]; d+=r[i+3];
|
||||
e+=r[i+4]; f+=r[i+5]; g+=r[i+6]; h+=r[i+7];
|
||||
a+=r[i ];
|
||||
b+=r[i+1];
|
||||
c+=r[i+2];
|
||||
d+=r[i+3];
|
||||
e+=r[i+4];
|
||||
f+=r[i+5];
|
||||
g+=r[i+6];
|
||||
h+=r[i+7];
|
||||
mix(a,b,c,d,e,f,g,h);
|
||||
m[i ]=a; m[i+1]=b; m[i+2]=c; m[i+3]=d;
|
||||
m[i+4]=e; m[i+5]=f; m[i+6]=g; m[i+7]=h;
|
||||
m[i ]=a;
|
||||
m[i+1]=b;
|
||||
m[i+2]=c;
|
||||
m[i+3]=d;
|
||||
m[i+4]=e;
|
||||
m[i+5]=f;
|
||||
m[i+6]=g;
|
||||
m[i+7]=h;
|
||||
}
|
||||
/* do a second pass to make all of the seed affect all of m */
|
||||
for (i=0; i<RANDSIZ; i+=8)
|
||||
{
|
||||
a+=m[i ]; b+=m[i+1]; c+=m[i+2]; d+=m[i+3];
|
||||
e+=m[i+4]; f+=m[i+5]; g+=m[i+6]; h+=m[i+7];
|
||||
a+=m[i ];
|
||||
b+=m[i+1];
|
||||
c+=m[i+2];
|
||||
d+=m[i+3];
|
||||
e+=m[i+4];
|
||||
f+=m[i+5];
|
||||
g+=m[i+6];
|
||||
h+=m[i+7];
|
||||
mix(a,b,c,d,e,f,g,h);
|
||||
m[i ]=a; m[i+1]=b; m[i+2]=c; m[i+3]=d;
|
||||
m[i+4]=e; m[i+5]=f; m[i+6]=g; m[i+7]=h;
|
||||
m[i ]=a;
|
||||
m[i+1]=b;
|
||||
m[i+2]=c;
|
||||
m[i+3]=d;
|
||||
m[i+4]=e;
|
||||
m[i+5]=f;
|
||||
m[i+6]=g;
|
||||
m[i+7]=h;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -106,8 +132,14 @@ word flag;
|
||||
for (i=0; i<RANDSIZ; i+=8)
|
||||
{
|
||||
mix(a,b,c,d,e,f,g,h);
|
||||
m[i ]=a; m[i+1]=b; m[i+2]=c; m[i+3]=d;
|
||||
m[i+4]=e; m[i+5]=f; m[i+6]=g; m[i+7]=h;
|
||||
m[i ]=a;
|
||||
m[i+1]=b;
|
||||
m[i+2]=c;
|
||||
m[i+3]=d;
|
||||
m[i+4]=e;
|
||||
m[i+5]=f;
|
||||
m[i+6]=g;
|
||||
m[i+7]=h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
249
src/logging.c
249
src/logging.c
@@ -18,7 +18,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _POSIX_SOURCE
|
||||
#define _DEFAULT_SOURCE
|
||||
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "nwipe.h"
|
||||
#include "context.h"
|
||||
#include "method.h"
|
||||
@@ -26,8 +30,6 @@
|
||||
#include "options.h"
|
||||
#include "logging.h"
|
||||
|
||||
int const MAX_LOG_LINE_CHARS = 512;
|
||||
|
||||
/* Global array to hold log values to print when logging to STDOUT */
|
||||
char **log_lines;
|
||||
int log_current_element = 0;
|
||||
@@ -41,6 +43,12 @@ void nwipe_log( nwipe_log_t level, const char* format, ... )
|
||||
*
|
||||
*/
|
||||
|
||||
char **result;
|
||||
char *malloc_result;
|
||||
char message_buffer[MAX_LOG_LINE_CHARS * sizeof(char)];
|
||||
int chars_written;
|
||||
|
||||
int message_buffer_length;
|
||||
|
||||
/* A time buffer. */
|
||||
time_t t;
|
||||
@@ -50,63 +58,105 @@ void nwipe_log( nwipe_log_t level, const char* format, ... )
|
||||
|
||||
/* Get the current time. */
|
||||
t = time( NULL );
|
||||
p = gmtime( &t );
|
||||
p = localtime( &t );
|
||||
|
||||
pthread_mutex_lock( &mutex1 );
|
||||
|
||||
/* Increase the current log element pointer - we will write here */
|
||||
if (log_current_element == log_elements_allocated) {
|
||||
log_elements_allocated++;
|
||||
log_lines = (char **) realloc (log_lines, (log_elements_allocated) * sizeof(char *));
|
||||
log_lines[log_current_element] = malloc(MAX_LOG_LINE_CHARS * sizeof(char));
|
||||
}
|
||||
|
||||
/* Position of writing to current log string */
|
||||
int line_current_pos = 0;
|
||||
|
||||
/* Print the date. The rc script uses the same format. */
|
||||
line_current_pos = snprintf( log_lines[log_current_element], MAX_LOG_LINE_CHARS, "[%i/%02i/%02i %02i:%02i:%02i] nwipe: ", \
|
||||
chars_written = snprintf( message_buffer, MAX_LOG_LINE_CHARS, "[%i/%02i/%02i %02i:%02i:%02i] nwipe: ", \
|
||||
1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec );
|
||||
|
||||
/* Has the end of the buffer been reached ?, snprintf returns the number of characters that would have been
|
||||
* written if MAX_LOG_LINE_CHARS had not been reached, it does not return the actual characters written in
|
||||
* all circumstances, hence why we need to check whether it's greater than MAX_LOG_LINE_CHARS and if so set
|
||||
* it to MAX_LOG_LINE_CHARS, preventing a buffer overrun further down this function.
|
||||
*/
|
||||
|
||||
switch( level )
|
||||
/* check if there was a complete failure to write this part of the message, in which case return */
|
||||
if ( chars_written < 0 )
|
||||
{
|
||||
fprintf( stderr, "nwipe_log: snprintf error when writing log line to memory.\n" );
|
||||
pthread_mutex_unlock( &mutex1 );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (line_current_pos + chars_written) > MAX_LOG_LINE_CHARS )
|
||||
{
|
||||
fprintf( stderr, "nwipe_log: Warning! The log line has been truncated as it exceeded %i characters\n", MAX_LOG_LINE_CHARS );
|
||||
line_current_pos = MAX_LOG_LINE_CHARS;
|
||||
}
|
||||
else
|
||||
{
|
||||
line_current_pos += chars_written;
|
||||
}
|
||||
}
|
||||
|
||||
case NWIPE_LOG_NONE:
|
||||
/* Do nothing. */
|
||||
break;
|
||||
if ( line_current_pos < MAX_LOG_LINE_CHARS )
|
||||
{
|
||||
switch( level )
|
||||
{
|
||||
|
||||
case NWIPE_LOG_DEBUG:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "debug: " );
|
||||
break;
|
||||
case NWIPE_LOG_NONE:
|
||||
/* Do nothing. */
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_INFO:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "info: " );
|
||||
break;
|
||||
case NWIPE_LOG_DEBUG:
|
||||
chars_written = snprintf( message_buffer + line_current_pos, MAX_LOG_LINE_CHARS - line_current_pos, "debug: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_NOTICE:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "notice: " );
|
||||
break;
|
||||
case NWIPE_LOG_INFO:
|
||||
chars_written = snprintf( message_buffer + line_current_pos, MAX_LOG_LINE_CHARS - line_current_pos, "info: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_WARNING:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "warning: " );
|
||||
break;
|
||||
case NWIPE_LOG_NOTICE:
|
||||
chars_written = snprintf( message_buffer + line_current_pos, MAX_LOG_LINE_CHARS - line_current_pos, "notice: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_ERROR:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "error: " );
|
||||
break;
|
||||
case NWIPE_LOG_WARNING:
|
||||
chars_written = snprintf( message_buffer + line_current_pos, MAX_LOG_LINE_CHARS - line_current_pos, "warning: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_FATAL:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "fatal: " );
|
||||
break;
|
||||
case NWIPE_LOG_ERROR:
|
||||
chars_written = snprintf( message_buffer + line_current_pos, MAX_LOG_LINE_CHARS - line_current_pos, "error: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_SANITY:
|
||||
/* TODO: Request that the user report the log. */
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "sanity: " );
|
||||
break;
|
||||
case NWIPE_LOG_FATAL:
|
||||
chars_written = snprintf( message_buffer + line_current_pos, MAX_LOG_LINE_CHARS - line_current_pos, "fatal: " );
|
||||
break;
|
||||
|
||||
default:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "level %i: ", level );
|
||||
case NWIPE_LOG_SANITY:
|
||||
/* TODO: Request that the user report the log. */
|
||||
chars_written = snprintf( message_buffer + line_current_pos, MAX_LOG_LINE_CHARS - line_current_pos, "sanity: " );
|
||||
break;
|
||||
|
||||
default:
|
||||
chars_written = snprintf( message_buffer + line_current_pos, MAX_LOG_LINE_CHARS - line_current_pos, "level %i: ", level );
|
||||
}
|
||||
|
||||
/* Has the end of the buffer been reached ?
|
||||
*/
|
||||
if ( chars_written < 0 )
|
||||
{
|
||||
fprintf( stderr, "nwipe_log: snprintf error when writing log line to memory.\n" );
|
||||
pthread_mutex_unlock( &mutex1 );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (line_current_pos + chars_written) > MAX_LOG_LINE_CHARS )
|
||||
{
|
||||
fprintf( stderr, "nwipe_log: Warning! The log line has been truncated as it exceeded %i characters\n", MAX_LOG_LINE_CHARS );
|
||||
line_current_pos = MAX_LOG_LINE_CHARS;
|
||||
}
|
||||
else
|
||||
{
|
||||
line_current_pos += chars_written;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The variable argument pointer. */
|
||||
@@ -114,9 +164,61 @@ void nwipe_log( nwipe_log_t level, const char* format, ... )
|
||||
|
||||
/* Fetch the argument list. */
|
||||
va_start( ap, format );
|
||||
|
||||
|
||||
|
||||
/* Print the event. */
|
||||
line_current_pos += vsnprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, format, ap );
|
||||
if ( line_current_pos < MAX_LOG_LINE_CHARS )
|
||||
{
|
||||
chars_written = vsnprintf( message_buffer + line_current_pos, MAX_LOG_LINE_CHARS - line_current_pos -1, format, ap );
|
||||
|
||||
if ( chars_written < 0 )
|
||||
{
|
||||
fprintf( stderr, "nwipe_log: snprintf error when writing log line to memory.\n" );
|
||||
pthread_mutex_unlock( &mutex1 );
|
||||
va_end( ap );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (line_current_pos + chars_written) > MAX_LOG_LINE_CHARS )
|
||||
{
|
||||
fprintf( stderr, "nwipe_log: Warning! The log line has been truncated as it exceeded %i characters\n", MAX_LOG_LINE_CHARS );
|
||||
line_current_pos = MAX_LOG_LINE_CHARS;
|
||||
}
|
||||
else
|
||||
{
|
||||
line_current_pos += chars_written;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Increase the current log element pointer - we will write here, deallocation is done in cleanup() in nwipe.c */
|
||||
if (log_current_element == log_elements_allocated) {
|
||||
log_elements_allocated++;
|
||||
result = realloc (log_lines, (log_elements_allocated) * sizeof(char *));
|
||||
if ( result == NULL )
|
||||
{
|
||||
fprintf( stderr, "nwipe_log: realloc failed when adding a log line.\n" );
|
||||
pthread_mutex_unlock( &mutex1 );
|
||||
va_end( ap );
|
||||
return;
|
||||
}
|
||||
log_lines = result;
|
||||
|
||||
/* Allocate memory for storing a single log message, deallocation is done in cleanup() in nwipe.c */
|
||||
message_buffer_length = strlen( message_buffer ) * sizeof(char);
|
||||
malloc_result = malloc((message_buffer_length + 1) * sizeof(char));
|
||||
if (malloc_result == NULL)
|
||||
{
|
||||
fprintf( stderr, "nwipe_log: malloc failed when adding a log line.\n" );
|
||||
pthread_mutex_unlock( &mutex1 );
|
||||
va_end( ap );
|
||||
return;
|
||||
}
|
||||
log_lines[log_current_element] = malloc_result;
|
||||
}
|
||||
|
||||
strcpy ( log_lines[log_current_element], message_buffer );
|
||||
|
||||
/*
|
||||
if( level >= NWIPE_LOG_WARNING )
|
||||
@@ -219,4 +321,69 @@ void nwipe_perror( int nwipe_errno, const char* f, const char* s )
|
||||
|
||||
} /* nwipe_perror */
|
||||
|
||||
int nwipe_log_sysinfo()
|
||||
{
|
||||
FILE *fp;
|
||||
char path[256];
|
||||
char cmd[50];
|
||||
int len;
|
||||
|
||||
/* Remove or add keywords to be searched, depending on what information is to
|
||||
be logged, making sure the last entry in the array is a NULL string. To remove
|
||||
an entry simply comment out the keyword with // */
|
||||
char dmidecode_keywords[][24] = {
|
||||
"bios-version",
|
||||
"bios-release-date",
|
||||
"system-manufacturer",
|
||||
"system-product-name",
|
||||
"system-version",
|
||||
"system-serial-number",
|
||||
"system-uuid",
|
||||
"baseboard-manufacturer",
|
||||
"baseboard-product-name",
|
||||
"baseboard-version",
|
||||
"baseboard-serial-number",
|
||||
"baseboard-asset-tag",
|
||||
"chassis-manufacturer",
|
||||
"chassis-type",
|
||||
"chassis-version",
|
||||
"chassis-serial-number",
|
||||
"chassis-asset-tag",
|
||||
"processor-family",
|
||||
"processor-manufacturer",
|
||||
"processor-version",
|
||||
"processor-frequency",
|
||||
"" //terminates the keyword array. DO NOT REMOVE
|
||||
};
|
||||
unsigned int keywords_idx;
|
||||
|
||||
keywords_idx = 0;
|
||||
|
||||
/* Run the dmidecode command to retrieve system serial number */
|
||||
while ( dmidecode_keywords[keywords_idx][0] != 0 )
|
||||
{
|
||||
sprintf(cmd,"dmidecode -s %s", &dmidecode_keywords[keywords_idx][0] );
|
||||
fp = popen(cmd, "r");
|
||||
if (fp == NULL ) {
|
||||
nwipe_log( NWIPE_LOG_INFO, "Failed to run command dmidecode -s %s", &dmidecode_keywords[keywords_idx][0], path );
|
||||
return 1;
|
||||
}
|
||||
/* Read the output a line at a time - output it. */
|
||||
while (fgets(path, sizeof(path)-1, fp) != NULL)
|
||||
{
|
||||
/* Remove any trailing return from the string, as nwipe_log automatically adds a return */
|
||||
len = strlen(path);
|
||||
if( path[len-1] == '\n' ) {
|
||||
path[len-1] = 0;
|
||||
}
|
||||
nwipe_log( NWIPE_LOG_INFO, "%s = %s", &dmidecode_keywords[keywords_idx][0], path );
|
||||
}
|
||||
/* close */
|
||||
pclose(fp);
|
||||
keywords_idx++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* eof */
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
#ifndef LOGGING_H_
|
||||
#define LOGGING_H_
|
||||
|
||||
/* Maximum size a log message can be */
|
||||
#define MAX_LOG_LINE_CHARS 512
|
||||
|
||||
typedef enum nwipe_log_t_
|
||||
{
|
||||
NWIPE_LOG_NONE = 0,
|
||||
@@ -36,6 +39,7 @@ typedef enum nwipe_log_t_
|
||||
|
||||
void nwipe_log( nwipe_log_t level, const char* format, ... );
|
||||
void nwipe_perror( int nwipe_errno, const char* f, const char* s );
|
||||
int nwipe_log_sysinfo();
|
||||
|
||||
/* Global array to hold log values to print when logging to STDOUT */
|
||||
//extern char **log_lines;
|
||||
|
||||
30
src/method.c
30
src/method.c
@@ -38,8 +38,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* Why is this needed? Segfaults without it */
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "nwipe.h"
|
||||
#include "context.h"
|
||||
@@ -416,11 +415,12 @@ void *nwipe_ops2( void *ptr )
|
||||
/* Allocate the array of complement characters. */
|
||||
t = malloc( sizeof( char ) * u );
|
||||
|
||||
if( s == NULL )
|
||||
if( t == NULL )
|
||||
{
|
||||
nwipe_perror( errno, __FUNCTION__, "malloc" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the complement character array." );
|
||||
c->result = -1;
|
||||
free(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -436,6 +436,8 @@ void *nwipe_ops2( void *ptr )
|
||||
nwipe_perror( errno, __FUNCTION__, "malloc" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the pattern array." );
|
||||
c->result = -1;
|
||||
free(s);
|
||||
free(t);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -448,10 +450,24 @@ void *nwipe_ops2( void *ptr )
|
||||
r = errno;
|
||||
nwipe_perror( r, __FUNCTION__, "read" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_ops2_label );
|
||||
|
||||
/* Ensure a negative return. */
|
||||
if( r < 0 ) { c->result = r; return NULL; }
|
||||
else { c->result = -1; return NULL; }
|
||||
|
||||
if( r < 0 )
|
||||
{
|
||||
c->result = r;
|
||||
free(s);
|
||||
free(t);
|
||||
free(patterns);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
c->result = -1;
|
||||
free(s);
|
||||
free(t);
|
||||
free(patterns);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
45
src/nwipe.c
45
src/nwipe.c
@@ -20,10 +20,14 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
#define _POSIX_SOURCE
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <bits/pthreadtypes.h>
|
||||
#include <bits/sigthread.h>
|
||||
|
||||
#include "nwipe.h"
|
||||
#include "context.h"
|
||||
@@ -48,7 +52,7 @@ int main( int argc, char** argv )
|
||||
int nwipe_enumerated; /* The number of contexts that have been enumerated. */
|
||||
int nwipe_error = 0; /* An error counter. */
|
||||
int nwipe_selected = 0; /* The number of contexts that have been selected. */
|
||||
pthread_t nwipe_gui_thread; /* The thread ID of the GUI thread. */
|
||||
pthread_t nwipe_gui_thread = 0; /* The thread ID of the GUI thread. */
|
||||
pthread_t nwipe_sigint_thread; /* The thread ID of the sigint handler. */
|
||||
|
||||
/* The entropy source file handle. */
|
||||
@@ -92,17 +96,20 @@ int main( int argc, char** argv )
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
argv += nwipe_optind;
|
||||
argc -= nwipe_optind;
|
||||
|
||||
nwipe_enumerated = nwipe_device_get( &c1, argv, argc );
|
||||
if ( nwipe_enumerated == 0 )
|
||||
{
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Log the System information */
|
||||
nwipe_log_sysinfo();
|
||||
|
||||
|
||||
/* The array of pointers to contexts that will actually be wiped. */
|
||||
@@ -143,6 +150,7 @@ int main( int argc, char** argv )
|
||||
|
||||
nwipe_thread_data_ptr.c = c2;
|
||||
nwipe_misc_thread_data.nwipe_enumerated = nwipe_enumerated;
|
||||
nwipe_misc_thread_data.nwipe_selected = 0;
|
||||
if( !nwipe_options.nogui )
|
||||
nwipe_misc_thread_data.gui_thread = &nwipe_gui_thread;
|
||||
nwipe_thread_data_ptr.nwipe_misc_thread_data = &nwipe_misc_thread_data;
|
||||
@@ -206,6 +214,7 @@ int main( int argc, char** argv )
|
||||
if( nwipe_options.nogui )
|
||||
{
|
||||
printf("--nogui option must be used with autonuke option\n");
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
@@ -287,8 +296,8 @@ int main( int argc, char** argv )
|
||||
*/
|
||||
|
||||
/* Print serial number of device if it exists. */
|
||||
if ( strlen(c2[i]->identity.serial_no) ) {
|
||||
nwipe_log( NWIPE_LOG_INFO, "Device %s has serial number %s", c2[i]->device_name, c2[i]->identity.serial_no);
|
||||
if ( strlen((const char*)c2[i]->serial_no) ) {
|
||||
nwipe_log( NWIPE_LOG_INFO, "Device %s has serial number %s", c2[i]->device_name, c2[i]->serial_no);
|
||||
}
|
||||
|
||||
|
||||
@@ -356,7 +365,7 @@ int main( int argc, char** argv )
|
||||
}
|
||||
|
||||
|
||||
if( c2[i]->device_size == (off64_t)-1 )
|
||||
if( c2[i]->device_size == (long long)-1 )
|
||||
{
|
||||
/* We cannot determine the size of this device. */
|
||||
nwipe_perror( errno, __FUNCTION__, "lseek" );
|
||||
@@ -477,6 +486,8 @@ int main( int argc, char** argv )
|
||||
printf("%s\n", log_lines[i]);
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
/* Success. */
|
||||
return 0;
|
||||
|
||||
@@ -567,12 +578,14 @@ void *signal_hand(void *ptr)
|
||||
case SIGQUIT :
|
||||
case SIGTERM :
|
||||
{
|
||||
nwipe_log( NWIPE_LOG_INFO, "nwipe_selected = %lu", nwipe_misc_thread_data->nwipe_selected );
|
||||
|
||||
for( i = 0; i < nwipe_misc_thread_data->nwipe_selected; i++ )
|
||||
{
|
||||
|
||||
if ( c[i]->thread )
|
||||
{
|
||||
nwipe_log( NWIPE_LOG_INFO, "Cancelling thread for %s", c[i]->device_name );
|
||||
pthread_cancel( c[i]->thread );
|
||||
}
|
||||
}
|
||||
@@ -580,7 +593,7 @@ void *signal_hand(void *ptr)
|
||||
// Kill the GUI thread
|
||||
if( !nwipe_options.nogui )
|
||||
{
|
||||
if ( nwipe_misc_thread_data->gui_thread )
|
||||
if ( *nwipe_misc_thread_data->gui_thread )
|
||||
{
|
||||
pthread_cancel( *nwipe_misc_thread_data->gui_thread );
|
||||
*nwipe_misc_thread_data->gui_thread = 0;
|
||||
@@ -598,8 +611,7 @@ void *signal_hand(void *ptr)
|
||||
|
||||
printf("Program interrupted (caught signal %d)\n", sig);
|
||||
|
||||
// Cleanup
|
||||
// TODO: All other cleanup required
|
||||
cleanup();
|
||||
|
||||
exit(0);
|
||||
|
||||
@@ -613,5 +625,20 @@ void *signal_hand(void *ptr)
|
||||
|
||||
} /* end of signal_hand */
|
||||
|
||||
int cleanup()
|
||||
{
|
||||
/* Deallocate memory used by logging */
|
||||
int idx;
|
||||
for ( idx=0; idx < log_elements_allocated; idx++ )
|
||||
{
|
||||
free ( log_lines[idx] );
|
||||
}
|
||||
log_elements_allocated=0; /* zeroed just in case cleanup is called twice */
|
||||
free ( log_lines );
|
||||
|
||||
/* TODO: All other cleanup required */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* eof */
|
||||
|
||||
10
src/nwipe.h
10
src/nwipe.h
@@ -20,9 +20,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NWIPE_H_
|
||||
#define NWIPE_H_
|
||||
|
||||
/* Function prototypes */
|
||||
int cleanup();
|
||||
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
@@ -33,7 +37,11 @@
|
||||
|
||||
/* workaround for Fedora */
|
||||
#ifndef off64_t
|
||||
# define off64_t off_t
|
||||
#ifndef off_t
|
||||
#define off64_t int64_t
|
||||
#else
|
||||
#define off64_t off_t
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Busybox headers. */
|
||||
|
||||
@@ -42,17 +42,19 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
extern nwipe_prng_t nwipe_twister;
|
||||
extern nwipe_prng_t nwipe_isaac;
|
||||
|
||||
/* The maximum banner size, including the null. */
|
||||
const int nwipe_banner_size = 81;
|
||||
|
||||
/* The getopt() result holder. */
|
||||
int nwipe_opt;
|
||||
|
||||
/* Excluded drive indexes */
|
||||
int idx_drive_chr;
|
||||
int idx_optarg;
|
||||
int idx_drive;
|
||||
|
||||
/* Array index variable. */
|
||||
int i;
|
||||
|
||||
/* The list of acceptable short options. */
|
||||
char nwipe_options_short [] = "Vhl:hm:p:r:";
|
||||
char nwipe_options_short [] = "Vhl:hm:p:r:e:";
|
||||
|
||||
/* The list of acceptable long options. */
|
||||
static struct option nwipe_options_long [] =
|
||||
@@ -68,6 +70,9 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
|
||||
/* Log file. Corresponds to the 'l' short option. */
|
||||
{ "logfile", required_argument, 0, 'l' },
|
||||
|
||||
/* Exclude devices, comma separated list */
|
||||
{ "exclude", required_argument, 0, 'e' },
|
||||
|
||||
/* The Pseudo Random Number Generator. */
|
||||
{ "prng", required_argument, 0, 'p' },
|
||||
@@ -100,15 +105,6 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
/* Note that COLS isn't available until ncurses is initialized. */
|
||||
nwipe_options.banner = malloc( nwipe_banner_size );
|
||||
|
||||
/* Set the default product banner. */
|
||||
/* TODO: Add version constant. */
|
||||
strncpy ( nwipe_options.banner, program_name, nwipe_banner_size);
|
||||
strncat ( nwipe_options.banner, " ", nwipe_banner_size - strlen (nwipe_options.banner) - 1);
|
||||
strncat ( nwipe_options.banner, version_string, nwipe_banner_size - strlen (nwipe_options.banner) - 1);
|
||||
strncat ( nwipe_options.banner, " (based on DBAN's dwipe - Darik's Wipe)", nwipe_banner_size - strlen (nwipe_options.banner) - 1);
|
||||
|
||||
/* Set default options. */
|
||||
nwipe_options.autonuke = 0;
|
||||
@@ -123,6 +119,11 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
nwipe_options.verify = NWIPE_VERIFY_LAST;
|
||||
memset( nwipe_options.logfile, '\0', sizeof(nwipe_options.logfile) );
|
||||
|
||||
/* Initialise each of the strings in the excluded drives array */
|
||||
for ( i=0; i < MAX_NUMBER_EXCLUDED_DRIVES; i++ )
|
||||
{
|
||||
nwipe_options.exclude[i][0]=0;
|
||||
}
|
||||
|
||||
/* Parse command line options. */
|
||||
while( 1 )
|
||||
@@ -254,6 +255,46 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
strncpy(nwipe_options.logfile, optarg, sizeof(nwipe_options.logfile));
|
||||
break;
|
||||
|
||||
case 'e': /* exclude drives option */
|
||||
|
||||
idx_drive_chr=0;
|
||||
idx_optarg=0;
|
||||
idx_drive=0;
|
||||
|
||||
/* Create an array of excluded drives from the comma separated string */
|
||||
while ( optarg[idx_optarg] != 0 && idx_drive<MAX_NUMBER_EXCLUDED_DRIVES )
|
||||
{
|
||||
/* drop the leading '=' character if used */
|
||||
if ( optarg[idx_optarg] == '=' && idx_optarg == 0 )
|
||||
{ idx_optarg++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( optarg[idx_optarg] == ',' )
|
||||
{
|
||||
/* terminate string and move onto next drive */
|
||||
nwipe_options.exclude[idx_drive++][idx_drive_chr]=0;
|
||||
idx_drive_chr=0;
|
||||
idx_optarg++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( idx_drive_chr < MAX_DRIVE_PATH_LENGTH )
|
||||
{
|
||||
nwipe_options.exclude[idx_drive][idx_drive_chr++]=optarg[idx_optarg++];
|
||||
}
|
||||
else
|
||||
{ /* This section deals with file names that exceed MAX_DRIVE_PATH_LENGTH */
|
||||
nwipe_options.exclude[idx_drive][idx_drive_chr]=0;
|
||||
while ( optarg[idx_optarg] != 0 || optarg[idx_optarg] != ',' )
|
||||
{
|
||||
idx_optarg++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'h': /* Display help. */
|
||||
|
||||
display_help();
|
||||
@@ -286,7 +327,7 @@ int nwipe_options_parse( int argc, char** argv )
|
||||
|| nwipe_options.rounds < 1
|
||||
)
|
||||
{
|
||||
fprintf( stderr, "Error: The rounds argument must be a postive integer.\n" );
|
||||
fprintf( stderr, "Error: The rounds argument must be a positive integer.\n" );
|
||||
exit( EINVAL );
|
||||
}
|
||||
|
||||
@@ -352,7 +393,7 @@ void nwipe_options_log( void )
|
||||
nwipe_log( NWIPE_LOG_NOTICE, " do not show GUI interface" );
|
||||
}
|
||||
|
||||
nwipe_log( NWIPE_LOG_NOTICE, " banner = %s", nwipe_options.banner );
|
||||
nwipe_log( NWIPE_LOG_NOTICE, " banner = %s", banner );
|
||||
nwipe_log( NWIPE_LOG_NOTICE, " method = %s", nwipe_method_label( nwipe_options.method ) );
|
||||
nwipe_log( NWIPE_LOG_NOTICE, " rounds = %i", nwipe_options.rounds );
|
||||
nwipe_log( NWIPE_LOG_NOTICE, " sync = %i", nwipe_options.sync );
|
||||
@@ -412,6 +453,10 @@ display_help()
|
||||
puts(" --nosignals Do not allow signals to interrupt a wipe (default is to allow)" );
|
||||
puts(" --nogui Do not show the GUI interface. Automatically invokes the nowait option" );
|
||||
puts(" Must be used with --autonuke option. Send SIGUSR1 to log current stats");
|
||||
puts(" -e, --exclude=DEVICES Up to ten comma separted devices to be excluded, examples:");
|
||||
puts(" --exclude=/dev/sdc");
|
||||
puts(" --exclude=/dev/sdc,/dev/sdd");
|
||||
puts(" --exclude=/dev/sdc,/dev/sdd,/dev/mapper/cryptswap1");
|
||||
puts("");
|
||||
exit( EXIT_SUCCESS );
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#define NWIPE_KNOB_SCSI "/proc/scsi/scsi"
|
||||
#define NWIPE_KNOB_SLEEP 1
|
||||
#define NWIPE_KNOB_STAT "/proc/stat"
|
||||
#define MAX_NUMBER_EXCLUDED_DRIVES 10
|
||||
#define MAX_DRIVE_PATH_LENGTH 200 /* e.g. /dev/sda is only 8 characters long, so 200 should be plenty*/
|
||||
|
||||
/* Function prototypes for loading options from the environment and command line. */
|
||||
int nwipe_options_parse( int argc, char** argv );
|
||||
@@ -48,13 +50,14 @@ typedef struct /* nwipe_options_t */
|
||||
{
|
||||
int autonuke; /* Do not prompt the user for confirmation when set. */
|
||||
int noblank; /* Do not perform a final blanking pass. */
|
||||
int nowait; /* Do not wait for a final key before exiting. */
|
||||
int nosignals; /* Do not allow signals to interrupt a wipe. */
|
||||
int nogui ; /* Do not show the GUI. */
|
||||
int nowait; /* Do not wait for a final key before exiting. */
|
||||
int nosignals; /* Do not allow signals to interrupt a wipe. */
|
||||
int nogui ; /* Do not show the GUI. */
|
||||
char* banner; /* The product banner shown on the top line of the screen. */
|
||||
// nwipe_method_t method; /* A function pointer to the wipe method that will be used. */
|
||||
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 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 rounds; /* The number of times that the wipe method should be called. */
|
||||
int sync; /* A flag to indicate whether writes should be sync'd. */
|
||||
|
||||
14
src/pass.c
14
src/pass.c
@@ -20,9 +20,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* Why is this needed? Segfaults without it */
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include "nwipe.h"
|
||||
#include "context.h"
|
||||
#include "method.h"
|
||||
@@ -89,6 +88,7 @@ int nwipe_random_verify( nwipe_context_t* c )
|
||||
{
|
||||
nwipe_perror( errno, __FUNCTION__, "malloc" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate memory for the pattern buffer." );
|
||||
free(b);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,8 @@ int nwipe_random_verify( nwipe_context_t* c )
|
||||
{
|
||||
nwipe_perror( errno, __FUNCTION__, "lseek" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to reset the '%s' file offset.", c->device_name );
|
||||
free(b);
|
||||
free(d);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -109,6 +111,8 @@ int nwipe_random_verify( nwipe_context_t* c )
|
||||
{
|
||||
/* This is system insanity. */
|
||||
nwipe_log( NWIPE_LOG_SANITY, "lseek() returned a bogus offset on '%s'.", c->device_name );
|
||||
free(b);
|
||||
free(d);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -271,6 +275,7 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE )
|
||||
{
|
||||
nwipe_perror( errno, __FUNCTION__, "lseek" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to reset the '%s' file offset.", c->device_name );
|
||||
free(b);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -278,6 +283,7 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE )
|
||||
{
|
||||
/* This is system insanity. */
|
||||
nwipe_log( NWIPE_LOG_SANITY, "__FUNCTION__: lseek() returned a bogus offset on '%s'.", c->device_name );
|
||||
free(b);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -438,6 +444,7 @@ int nwipe_static_verify( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern )
|
||||
{
|
||||
nwipe_perror( errno, __FUNCTION__, "malloc" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate memory for the pattern buffer." );
|
||||
free(b);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -474,6 +481,7 @@ int nwipe_static_verify( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern )
|
||||
{
|
||||
nwipe_perror( errno, __FUNCTION__, "lseek" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to reset the '%s' file offset.", c->device_name );
|
||||
free(b);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -481,6 +489,8 @@ int nwipe_static_verify( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern )
|
||||
{
|
||||
/* This is system insanity. */
|
||||
nwipe_log( NWIPE_LOG_SANITY, "nwipe_static_verify: lseek() returned a bogus offset on '%s'.", c->device_name );
|
||||
free(b);
|
||||
free(d);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
13
src/prng.c
13
src/prng.c
@@ -149,6 +149,19 @@ int nwipe_isaac_init( NWIPE_PRNG_INIT_SIGNATURE )
|
||||
|
||||
int nwipe_isaac_read( NWIPE_PRNG_READ_SIGNATURE )
|
||||
{
|
||||
/* The purpose of this function is unclear, as it does not do anything except immediately return !
|
||||
* Because the variables in the macro NWIPE_PRNG_READ_SIGNATURE were then unused this throws
|
||||
* up a handful of compiler warnings, related to variables being unused. To stop the compiler warnings
|
||||
* I've simply put in a (void) var so that compiler sees the variable are supposed to be unused.
|
||||
*
|
||||
* As this code works, I thought it best not to remove this function, just in case it servers
|
||||
* some purpose or is there for future use.
|
||||
*/
|
||||
|
||||
(void) state;
|
||||
(void) buffer;
|
||||
(void) count;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
* used by configure to dynamically assign those values
|
||||
* to documentation files.
|
||||
*/
|
||||
const char *version_string = "0.21";
|
||||
const char *version_string = "0.26";
|
||||
const char *program_name = "nwipe";
|
||||
const char *author_name = "Martijn van Brummelen";
|
||||
const char *email_address = "git@brumit.nl";
|
||||
const char *years = "2016";
|
||||
const char *years = "2019";
|
||||
const char *copyright = "Copyright Darik Horn <dajhorn-dban@vanadac.com>\n\
|
||||
Modifications to original dwipe Copyright Andy Beverley <andy@andybev.com>\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.26 (based on DBAN's dwipe - Darik's Wipe)";
|
||||
|
||||
@@ -6,5 +6,6 @@ extern char *program_name;
|
||||
extern char *author_name;
|
||||
extern char *email_address;
|
||||
extern char *copyright;
|
||||
extern char *banner;
|
||||
|
||||
#endif/*__VERSION_H*/
|
||||
|
||||
Reference in New Issue
Block a user