From d76afbaaf40e953243da921844cddff8185324f3 Mon Sep 17 00:00:00 2001 From: Lyonel Vincent Date: Tue, 28 Jun 2022 10:22:38 +0200 Subject: [PATCH 2/2] make version check optional cf. Github PR#86 Rather than using an LSM such as SELinux to limit network access, or having to add exceptions into network monitoring, allow lshw to be built so that it doesn't do the DNS lookup to check for upstream version updates. Signed-off-by: Stewart Smith trawets@amazon.com --- src/Makefile | 10 ++++++++-- src/core/Makefile | 5 ++++- src/core/version.cc | 9 ++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Makefile b/src/Makefile index 220f3f6..ac726d0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -24,7 +24,10 @@ export ZLIB CXX?=$(CROSS_COMPILE)c++ PKG_CONFIG ?= pkg-config INCLUDES=-I./core/ -DEFINES=-DPREFIX=\"$(PREFIX)\" -DSBINDIR=\"$(SBINDIR)\" -DMANDIR=\"$(MANDIR)\" -DDATADIR=\"$(DATADIR)\" -DVERSION=\"$(VERSION)\" +ifneq ($(NO_VERSION_CHECK), 1) +REMOTE_VERSION_CHECK?=-DREMOTE_VERSION_CHECK +endif +DEFINES=-DPREFIX=\"$(PREFIX)\" -DSBINDIR=\"$(SBINDIR)\" -DMANDIR=\"$(MANDIR)\" -DDATADIR=\"$(DATADIR)\" -DVERSION=\"$(VERSION)\" $(REMOTE_VERSION_CHECK) CXXFLAGS=-g -Wall -g $(INCLUDES) $(DEFINES) $(RPM_OPT_FLAGS) ifeq ($(SQLITE), 1) CXXFLAGS+= -DSQLITE $(shell $(PKG_CONFIG) --cflags sqlite3) @@ -37,7 +40,10 @@ ifneq ($(shell $(LD) --help 2| grep -- --as-needed), ) LDFLAGS+= -Wl,--as-needed endif LDSTATIC=-static -LIBS+=-llshw -lresolv +LIBS+=-llshw +ifneq ($(NO_VERSION_CHECK), 1) +LIBS+=-lresolv +endif ifeq ($(SQLITE), 1) LIBS+= $(shell $(PKG_CONFIG) --libs sqlite3) endif diff --git a/src/core/Makefile b/src/core/Makefile index a8ed0cf..5035062 100644 --- a/src/core/Makefile +++ b/src/core/Makefile @@ -2,7 +2,10 @@ PACKAGENAME?=lshw CXX?=$(CROSS_COMPILE)c++ INCLUDES= -DEFINES=-DPREFIX=\"$(PREFIX)\" -DSBINDIR=\"$(SBINDIR)\" -DMANDIR=\"$(MANDIR)\" -DDATADIR=\"$(DATADIR)\" +ifneq ($(NO_VERSION_CHECK), 1) +REMOTE_VERSION_CHECK?=-DREMOTE_VERSION_CHECK +endif +DEFINES=-DPREFIX=\"$(PREFIX)\" -DSBINDIR=\"$(SBINDIR)\" -DMANDIR=\"$(MANDIR)\" -DDATADIR=\"$(DATADIR)\" $(REMOTE_VERSION_CHECK) CXXFLAGS?=-g -Wall $(INCLUDES) $(DEFINES) $(RPM_OPT_FLAGS) LDFLAGS= LDSTATIC= diff --git a/src/core/version.cc b/src/core/version.cc index 1f64b3a..ea8dd4a 100644 --- a/src/core/version.cc +++ b/src/core/version.cc @@ -13,6 +13,7 @@ #include #include #include +#ifdef REMOTE_VERSION_CHECK #include #include #include @@ -21,7 +22,7 @@ #ifndef PACKETSZ #define PACKETSZ 512 #endif - +#endif const char *getpackageversion() { @@ -31,6 +32,7 @@ const char *getpackageversion() return "unknown"; } +#ifdef REMOTE_VERSION_CHECK static char *txtquery(const char *name, const char *domain, unsigned int *ttl) { unsigned char answer[PACKETSZ], *pt; @@ -84,13 +86,18 @@ static char *txtquery(const char *name, const char *domain, unsigned int *ttl) return txt; } +#endif const char * checkupdates() { +#ifdef REMOTE_VERSION_CHECK static char *latest = NULL; if(!latest) latest = txtquery(PACKAGE, "ezix.org", NULL); return latest; +#else + return NULL; +#endif } -- 2.33.1