From 0fec3a1213d6a51c77abb86d7b6758f96b1c9246 Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Thu, 29 Aug 2019 18:12:19 +0100 Subject: [PATCH] Log system's hardware as described in the system BIOS according to the SMBIOS/DMI standard. Uses dmidecode with search keywords arguments. dmidecode -s to see available keywords. --- src/logging.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/logging.h | 1 + src/nwipe.c | 3 +++ 3 files changed, 72 insertions(+) diff --git a/src/logging.c b/src/logging.c index cd405be..6fd2528 100644 --- a/src/logging.c +++ b/src/logging.c @@ -19,7 +19,10 @@ */ #define _POSIX_SOURCE +#define _DEFAULT_SOURCE +#include "stdio.h" +#include "stdlib.h" #include "nwipe.h" #include "context.h" #include "method.h" @@ -318,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 */ diff --git a/src/logging.h b/src/logging.h index 514daf5..6cda821 100644 --- a/src/logging.h +++ b/src/logging.h @@ -39,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; diff --git a/src/nwipe.c b/src/nwipe.c index 02ec8a3..c7586fd 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -107,6 +107,9 @@ int main( int argc, char** argv ) } } + + /* Log the System information */ + nwipe_log_sysinfo(); /* The array of pointers to contexts that will actually be wiped. */