/* * Copyright (C) 2006, Intel Corporation * * This file is part of the Linux-ready Firmware Developer Kit * * This program file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation;version 2.1 of the License. * * This library 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 Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program in a file named COPYING; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ /* * This test checks if the dmi information has common bugs */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include char *full_dmi = NULL; static int found_error; static void report_dmi_error (char *id, int res, char *summ, char* detail, char* uri) { report_result("dmi", FAIL, "No SMBIOS nor DMI entry point found.", NULL, "dmi://"); found_error++; } /* check_line() -- parses a line of dmidecode output for common errors. If * it finds any, it calls report_result() to report. * * Parameters * line - line of dmidecode output * Returns * nothing */ void check_line(char *line) { if (strstr(line, "No SMBIOS nor DMI entry point found, sorry.")) report_dmi_error("dmi", FAIL, "No SMBIOS nor DMI entry point found.", NULL, "dmi://"); if (strstr(line, "Wrong DMI structures count")) report_dmi_error("dmi", FAIL, "Incorrect DMI structures count", line, "dmi://"); if (strstr(line, "Wrong DMI structures length:")) report_dmi_error("dmi", FAIL, "Incorrect DMI structures length", line, "dmi://"); if (strstr(line, "")) report_dmi_error("dmi", FAIL, "Out of spec value found", line, "dmi://"); if (strstr(line, "")) report_dmi_error("dmi", FAIL, "Bad index value found", line, "dmi://"); if (strstr(line,"Bad checksum! Please report.")) report_dmi_error("dmi", FAIL, "Incorrect checksum found", line, "dmi://"); if (strstr(line, "Serial Number:") && strstr(line,"0123456789")) report_dmi_error("dmi", FAIL, "Template serial number not updated", line, "dmi://"); if (strstr(line, "Asset Tag") && strstr(line,"1234567890")) report_dmi_error("dmi", FAIL, "Template Asset Tag not updated", line, "dmi://"); if (strstr(line, "UUID:") && strstr(line,"0A0A0A0A-0A0A-0A0A-0A0A-0A0A0A0A0A0A.")) report_dmi_error("dmi", FAIL, "Template UUID number not updated", line, "dmi://"); if (strstr(line,"To Be Filled By O.E.M.")) report_dmi_error("dmi", FAIL, "Template value not updated", line, "dmi://"); } /* main() -- Checks DMI/SMBIOS tables for common errors by calling the * 'dmidecode' command, then parsing through the output * for common errors (by calling check_line()). * * Parameters * argc & argv * Returns * EXIT_SUCCESS upon success of running this plugin * EXIT_FAILURE upon failure of running this plugin */ int main(int argc, char **argv) { FILE *file; char *dmidecode_file = "/usr/sbin/dmidecode"; struct stat buffer; start_test("dmi", "DMI information check", "This test checks the DMI/SMBIOS tables for common errors."); /* Check if dmidecode command exists */ if(stat(dmidecode_file, &buffer) != 0) { report_result("dmi", FAIL, "Cannot find dmidecode file", dmidecode_file, NULL); goto finish; } /* Execute dmidecode command and obtain output stream */ file = popen(dmidecode_file, "r"); if (file == NULL) { report_result("dmi", FAIL, "Error opening dmidecode command", dmidecode_file, NULL); goto finish; } /* Parse through output for common errors */ found_error = 0; full_dmi = strdup("DMI information:\n"); while (!feof(file)) { char line[4096]; memset(line, 0, 4096); if (fgets(line, 4095, file)==NULL) break; full_dmi = scatprintf(full_dmi, "%s", line); check_line(line); } pclose(file); /* Add to our resource list, passing all the lines of output*/ announce_resource("dmi://", full_dmi, NULL); if (found_error == 0) { report_result("dmi", PASS, "Successfully found no errors in SMBIOS/DMI", NULL, NULL); } finish: finish_test("dmi"); return EXIT_SUCCESS; }