From 3017c13413481834a3df2c12c878177b51549f5f Mon Sep 17 00:00:00 2001 From: iadgovuser58 <124906646+iadgovuser58@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:34:07 -0400 Subject: [PATCH] get pciids from code if not found on filesystem --- .../src/main/java/hirs/utils/PciIds.java | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/HIRS_Utils/src/main/java/hirs/utils/PciIds.java b/HIRS_Utils/src/main/java/hirs/utils/PciIds.java index 46b2a67c..bab597c4 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/PciIds.java +++ b/HIRS_Utils/src/main/java/hirs/utils/PciIds.java @@ -36,7 +36,7 @@ public final class PciIds { /** * Name of pciids file in code. */ - private static final String PCIIDS_FILENAME = "pci.ids"; + private static final String PCIIDS_FILENAME = "/pci.ids"; /** * This pci ids file can be in different places on different distributions. @@ -65,6 +65,8 @@ public final class PciIds { //Configure the PCI IDs Database object. static { if (!DB.isReady()) { + + // if pciids file is found on the system, then process using this String dbFile = null; for (final String path : PCI_IDS_PATH) { if ((new File(path)).exists()) { @@ -73,21 +75,13 @@ public final class PciIds { break; } } - // if pciids file is not found on the system, then attempt to grab it from code + if(dbFile != null) { - pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM; - } - else { - dbFile = PciIds.class.getResource(PCIIDS_FILENAME).getPath(); - } - if (dbFile != null) { - if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_FROM_FILESYSTEM)) { - pciidsFileStatus = UefiConstants.FILESTATUS_FROM_CODE; - } InputStream is = null; try { is = new FileInputStream(new File(dbFile)); DB.loadStream(is); + pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM; } catch (IOException e) { // DB will not be ready, hardware IDs will not be translated dbFile = null; @@ -101,8 +95,28 @@ public final class PciIds { } } } - else { - log.info("PCI IDs file was NOT found"); + + // if pciids file is not found on the system or not accessible, then attempt to grab it from code + if(pciidsFileStatus == UefiConstants.FILESTATUS_NOT_ACCESSIBLE) { + InputStream istemp = PciIds.class.getResourceAsStream(PCIIDS_FILENAME); + try { + DB.loadStream(istemp); + pciidsFileStatus = UefiConstants.FILESTATUS_FROM_CODE; + } catch (IOException e) { + // DB will not be ready, hardware IDs will not be translated + } finally { + if (istemp != null) { + try { + istemp.close(); + } catch (IOException e) { + } + } + } + } + + // if pciids file is not accessible on system or from within code, then log error + if(pciidsFileStatus == UefiConstants.FILESTATUS_NOT_ACCESSIBLE) { + log.info("PCI IDs file was NOT accessible from within the system or within the code"); } } }