diff --git a/.github/workflows/ci_formatting.yml b/.github/workflows/ci_formatting.yml index 2de8383..af5ba3a 100644 --- a/.github/workflows/ci_formatting.yml +++ b/.github/workflows/ci_formatting.yml @@ -12,7 +12,7 @@ jobs: - name: updating available system dependencies run: sudo apt-get update - name: installing system dependencies - run: sudo apt-get install -y build-essential pkg-config automake libncurses5-dev autotools-dev libparted-dev dmidecode clang-format + run: sudo apt-get install -y build-essential pkg-config automake libncurses5-dev autotools-dev libparted-dev libconfig-dev libconfig++-dev dmidecode clang-format - name: creating autoconf files run: ./autogen.sh - name: configuring diff --git a/.github/workflows/ci_ubuntu_latest.yml b/.github/workflows/ci_ubuntu_latest.yml index 657938e..e397dce 100644 --- a/.github/workflows/ci_ubuntu_latest.yml +++ b/.github/workflows/ci_ubuntu_latest.yml @@ -12,7 +12,7 @@ jobs: - name: updating available system dependencies run: sudo apt-get update - name: installing system dependencies - run: sudo apt-get install -y build-essential pkg-config automake libncurses5-dev autotools-dev libparted-dev dmidecode + run: sudo apt-get install -y build-essential pkg-config automake libncurses5-dev autotools-dev libparted-dev libconfig-dev libconfig++-dev dmidecode - name: creating autoconf files run: ./autogen.sh - name: configuring diff --git a/README.md b/README.md index 01a0cd5..692d670 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ nwipe is a fork of the dwipe command originally used by Darik's Boot and Nuke (D nwipe is a program that will securely erase the entire contents of disks. It can wipe a single drive or multiple disks simultaneously. It can operate as both a command line tool without a GUI or with a ncurses GUI as shown in the example below: > **Warning** -> Nwipe does not currently support HDA (hidden disc area) detection. You will need to run hdparm to detect and if necessary correct the reported size of the disc prior to using nwipe. +> Nwipe does not currently support HDA (hidden disc area) detection but will be available in the next release v0.35. For versions prior to this, you will need to run hdparm to detect and if necessary correct the reported size of the disc prior to using nwipe. `sudo hdparm -N /dev/sdx` and `sudo hdparm --dco-identify /dev/sdx`. The three sector values returned should all be identical for there to be no hidden sectors on the disc. xxxxxxxxxx / yyyyyyyyyy as returned by hdparm -N and Real max sectors = zzzzzzzzzz as returned by hdparm --dco-identify. ![Example wipe](/images/example_wipe.gif) @@ -46,6 +46,11 @@ For a development setup, see the [Hacking section](#hacking) below. For a bootab * ncurses * pthreads * parted +* libconfig + +`nwipe` also requires the following program to be installed, it will abort with a warning if not found: + +* hdparm (as of current master and v0.35+) and optionally, but recommended, the following programs: @@ -65,9 +70,12 @@ sudo apt install \ libncurses5-dev \ autotools-dev \ libparted-dev \ + libconfig-dev \ + libconfig++-dev \ dmidecode \ coreutils \ - smartmontools + smartmontools \ + hdparm ``` ### Fedora prerequisites @@ -79,19 +87,25 @@ dnf groupinstall "Development Tools" dnf groupinstall "C Development Tools and Libraries" yum install ncurses-devel yum install parted-devel +yum install libconfig-devel +yum install libconfig++-devel yum install dmidecode yum install coreutils yum install smartmontools +yum install hdparm ``` Note. The following programs are optionally installed although recommended. 1. dmidecode 2. readlink 3. smartmontools. -#### dmidecode +#### hdparm [REQUIRED] +hdparm provides some of the information regarding disk size in sectors as related to the host protected area (HPA) and device configuration overlay (DCO). We do however have our own function that directly access the DCO to obtain the 'real max sectors' so reliance on hdparm may be removed at a future date. + +#### dmidecode [RECOMMENDED] dmidecode provides SMBIOS/DMI host data to stdout or the log file. If you don't install it you won't see the SMBIOS/DMI host data at the beginning of nwipes log. -#### coreutils (provides readlink) +#### coreutils (provides readlink) [RECOMMENDED] readlink determines the bus type, i.e. ATA, USB etc. Without it the --nousb option won't work and bus type information will be missing from nwipes selection and wipe windows. The coreutils package is often automatically installed as default in most if not all distros. -#### smartmontools +#### smartmontools [RECOMMENDED] smartmontools obtains serial number information for supported USB to IDE/SATA adapters. Without it, drives plugged into USB ports will not show serial number information. If you want a quick and easy way to keep your copy of nwipe running the latest master release of nwipe see the [automating the download and compilation](#automating-the-download-and-compilation-process-for-debian-based-distros) section. diff --git a/configure.ac b/configure.ac index 3e87040..558d398 100644 --- a/configure.ac +++ b/configure.ac @@ -49,13 +49,30 @@ PKG_CHECK_MODULES( )] ) +PKG_CHECK_MODULES( + [LIBCONFIG], + [libconfig], + [ + CFLAGS="${CFLAGS} ${LIBCONFIG_CFLAGS}" + LIBS="${LIBS} ${LIBCONFIG_LIBS}" + ], + [AC_CHECK_LIB([libconfig], [main], [ + LIBS="-llibconfig $LIBS" + AC_CHECK_HEADERS(libconfig.h,, [ + AC_CHECK_HEADERS(libconfig.h, [ + AC_DEFINE([LIBCONFIG_IN_SUBDIR], [libconfig/], [Look for libconfig headers in subdir]) + ], [AC_MSG_ERROR([libconfig headers not found])]) + ]) + ], [AC_MSG_ERROR([libconfig library not found])])] +) + AC_CHECK_LIB([intl], [libintl_dgettext]) # needed to statically link libparted, but not given in its pkgconfig file AC_CHECK_LIB([uuid], [uuid_generate]) # needed to statically link libparted, but not given in its pkgconfig file -PKG_CHECK_MODULES([PARTED], [libparted]) +PKG_CHECK_MODULES([PARTED], [libparted], [libconfig]) AC_CHECK_LIB([pthread], [main], ,[AC_MSG_ERROR([pthread development library not found])]) # Checks for header files. -AC_CHECK_HEADERS([fcntl.h inttypes.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/file.h sys/ioctl.h unistd.h]) +AC_CHECK_HEADERS([libconfig.h fcntl.h inttypes.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/file.h sys/ioctl.h unistd.h]) # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_SIZE_T diff --git a/src/Makefile.am b/src/Makefile.am index 96fa8d5..c2b895b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,5 +6,5 @@ AM_LDFLAGS = # this lists the binaries to produce, the (non-PHONY, binary) targets in # the previous manual Makefile bin_PROGRAMS = nwipe -nwipe_SOURCES = context.h logging.h options.h prng.h version.h temperature.h nwipe.c gui.c method.h pass.c device.c gui.h isaac_rand/isaac_standard.h isaac_rand/isaac_rand.h isaac_rand/isaac_rand.c isaac_rand/isaac64.h isaac_rand/isaac64.c mt19937ar-cok/mt19937ar-cok.c nwipe.h mt19937ar-cok/mt19937ar-cok.h pass.h device.h logging.c method.c options.c prng.c version.c temperature.c PDFGen/pdfgen.h PDFGen/pdfgen.c create_pdf.c create_pdf.h embedded_images/shred_db.jpg.c embedded_images/shred_db.jpg.h embedded_images/tick_erased.jpg.c embedded_images/tick_erased.jpg.h embedded_images/redcross.c embedded_images/redcross.h hpa_dco.h hpa_dco.c miscellaneous.h miscellaneous.c embedded_images/nwipe_exclamation.jpg.h embedded_images/nwipe_exclamation.jpg.c -nwipe_LDADD = $(PARTED_LIBS) +nwipe_SOURCES = context.h logging.h options.h prng.h version.h temperature.h nwipe.c gui.c method.h pass.c device.c gui.h isaac_rand/isaac_standard.h isaac_rand/isaac_rand.h isaac_rand/isaac_rand.c isaac_rand/isaac64.h isaac_rand/isaac64.c mt19937ar-cok/mt19937ar-cok.c nwipe.h mt19937ar-cok/mt19937ar-cok.h pass.h device.h logging.c method.c options.c prng.c version.c temperature.c PDFGen/pdfgen.h PDFGen/pdfgen.c create_pdf.c create_pdf.h embedded_images/shred_db.jpg.c embedded_images/shred_db.jpg.h embedded_images/tick_erased.jpg.c embedded_images/tick_erased.jpg.h embedded_images/redcross.c embedded_images/redcross.h hpa_dco.h hpa_dco.c miscellaneous.h miscellaneous.c embedded_images/nwipe_exclamation.jpg.h embedded_images/nwipe_exclamation.jpg.c conf.h conf.c +nwipe_LDADD = $(PARTED_LIBS) $(LIBCONFIG) diff --git a/src/conf.c b/src/conf.c new file mode 100644 index 0000000..e8447f3 --- /dev/null +++ b/src/conf.c @@ -0,0 +1,84 @@ +/* + * conf.c: functions that handle the nwipe.conf configuration file. + * + * Copyright PartialVolume . + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * + * + */ + +#include +#include +#include +#include "nwipe.h" +#include "context.h" +#include "logging.h" + +config_t nwipe_cfg; +config_setting_t* nwipe_conf_setting; +const char* nwipe_conf_str; + +void nwipe_conf_init() +{ + FILE* fp; + + config_init( &nwipe_cfg ); + + /* Read /etc/nwipe/nwipe.conf. If there is an error, determine whether + * it's because it doesn't exist. If it doesn't exist create it and + * populate it with a basic structure. + */ + if( !config_read_file( &nwipe_cfg, "/etc/nwipe/nwipe.conf" ) ) + { + fprintf( stderr, + "%s:%d - %s\n", + config_error_file( &nwipe_cfg ), + config_error_line( &nwipe_cfg ), + config_error_text( &nwipe_cfg ) ); + + /* Does the /etc/nwipe/nwipe.conf file exist? If not, then create it */ + if( access( "/etc/nwipe/nwipe.conf", F_OK ) == 0 ) + { + nwipe_log( NWIPE_LOG_INFO, "/etc/nwipe/nwipe.conf exists" ); + } + else + { + nwipe_log( NWIPE_LOG_WARNING, "/etc/nwipe/nwipe.conf does not exist" ); + + /* We assume the /etc/nwipe directory doesn't exist, so try to create it */ + mkdir( "/etc/nwipe", 0755 ); + + /* create the nwipe.conf file */ + if( !( fp = fopen( "/etc/nwipe/nwipe.conf", "w" ) ) ) + { + nwipe_log( NWIPE_LOG_ERROR, "Failed to create /etc/nwipe/nwipe.conf" ); + } + else + { + nwipe_log( NWIPE_LOG_INFO, "Created /etc/nwipe/nwipe.conf" ); + + /* Populate with some basic structure */ + // NOTE ADD CODE HERE NOTE + } + } + } + return; +} + +void nwipe_conf_close() +{ + config_destroy( &nwipe_cfg ); +} diff --git a/src/conf.h b/src/conf.h new file mode 100644 index 0000000..7bec47c --- /dev/null +++ b/src/conf.h @@ -0,0 +1,21 @@ +#ifndef CONF_H_ +#define CONF_H_ + +/** + * Initialises the libconfig code, called once at the + * start of nwipe, prior to any attempts to access + * nwipe's config file /etc/nwipe/nwipe.conf + * @param none + * @return void + */ +void nwipe_conf_init(); + +/** + * Before exiting nwipe, this function should be called + * to free up libconfig's memory usage + * @param none + * @return void + */ +void nwipe_conf_close(); + +#endif /* CONF_H_ */ diff --git a/src/nwipe.c b/src/nwipe.c index 8055938..da1029f 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -50,6 +50,7 @@ #include #include +#include "conf.h" #include "version.h" #include "hpa_dco.h" @@ -128,9 +129,12 @@ int main( int argc, char** argv ) /* Log OS info */ nwipe_log_OSinfo(); - /* Check that hdparm exists, we use hdparm for HPA/DCO detection etc, if not exit nwipe - * required if the PATH environment is not setup ! (Debian sid 'su' as - * opposed to 'su -' + /* Initialise the libconfig code that handles nwipe.conf */ + nwipe_conf_init(); + + /* Check that hdparm exists, we use hdparm for some HPA/DCO detection etc, if not + * exit nwipe. These checks are required if the PATH environment is not setup ! + * Example: Debian sid 'su' as opposed to 'su -' */ if( system( "which hdparm > /dev/null 2>&1" ) ) {