if pciids file not found, deal with the error

This commit is contained in:
iadgovuser58 2024-09-04 11:32:51 -04:00
parent c29730da43
commit 0f8fc63341
2 changed files with 8 additions and 8 deletions

View File

@ -25,7 +25,7 @@ import java.util.List;
@Log4j2
public final class PciIds {
private static boolean pciIdsFileNotFound = true;
private static boolean pciIdsFileFound = false;
/**
* This pci ids file can be in different places on different distributions.
@ -60,6 +60,7 @@ public final class PciIds {
}
}
if (dbFile != null) {
pciIdsFileFound = true;
InputStream is = null;
try {
is = new FileInputStream(new File(dbFile));
@ -78,7 +79,6 @@ public final class PciIds {
}
}
else {
pciIdsFileNotFound = true;
log.info("PCI IDs file was NOT found");
}
}
@ -97,7 +97,7 @@ public final class PciIds {
*/
public static ASN1UTF8String translateVendor(final ASN1UTF8String refManufacturer) {
ASN1UTF8String manufacturer = refManufacturer;
if (!pciIdsFileNotFound && manufacturer != null
if (pciIdsFileFound && manufacturer != null
&& manufacturer.getString().trim().matches("^[0-9A-Fa-f]{4}$")) {
Vendor ven = DB.findVendor(manufacturer.getString().toLowerCase());
if (ven != null && !Strings.isNullOrEmpty(ven.getName())) {
@ -115,7 +115,7 @@ public final class PciIds {
*/
public static String translateVendor(final String refManufacturer) {
String manufacturer = refManufacturer;
if (!pciIdsFileNotFound && manufacturer != null
if (pciIdsFileFound && manufacturer != null
&& manufacturer.trim().matches("^[0-9A-Fa-f]{4}$")) {
Vendor ven = DB.findVendor(manufacturer.toLowerCase());
if (ven != null && !Strings.isNullOrEmpty(ven.getName())) {
@ -137,7 +137,7 @@ public final class PciIds {
final ASN1UTF8String refModel) {
ASN1UTF8String manufacturer = refManufacturer;
ASN1UTF8String model = refModel;
if (!pciIdsFileNotFound
if (pciIdsFileFound
&& manufacturer != null
&& model != null
&& manufacturer.getString().trim().matches("^[0-9A-Fa-f]{4}$")
@ -162,7 +162,7 @@ public final class PciIds {
public static String translateDevice(final String refManufacturer,
final String refModel) {
String model = refModel;
if (!pciIdsFileNotFound
if (pciIdsFileFound
&& refManufacturer != null
&& model != null
&& refManufacturer.trim().matches("^[0-9A-Fa-f]{4}$")
@ -193,7 +193,7 @@ public final class PciIds {
List<String> translatedClassCode = new ArrayList<>();
String classCode = refClassCode;
if (!pciIdsFileNotFound && classCode != null
if (pciIdsFileFound && classCode != null
&& classCode.trim().matches("^[0-9A-Fa-f]{6}$")) {
String deviceClass = classCode.substring(0, 2).toLowerCase();
String deviceSubclass = classCode.substring(2, 4).toLowerCase();

View File

@ -124,7 +124,7 @@ public class DeviceSecurityEventDataPciContext extends DeviceSecurityEventDataDe
dSEDpciContextInfo += " Subclass = " + classCodeList.get(1) + "\n";
dSEDpciContextInfo += " Programming Interface = " + classCodeList.get(2) + "\n";
} else {
dSEDpciContextInfo += " ** Class code could not be determined **";
dSEDpciContextInfo += " ** Class code could not be determined **\n";
}
dSEDpciContextInfo += " SubsystemVendor = " + translateVendor(subsystemVendorId) + "\n";
dSEDpciContextInfo += " Subsystem = " + translateDevice(subsystemVendorId, subsystemId) + "\n";