From: leslie Date: Mon, 8 Jun 2009 13:05:36 +0000 (+0800) Subject: check SCAPI version on library load X-Git-Tag: 0.9.2~20 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=c932d422d2b6550665703d8d7a29aa698df039ea;p=sasc-ng.git check SCAPI version on library load --- diff --git a/Makefile b/Makefile index 7641ec3..656e422 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ SUBREL := $(shell if test -d .hg; then \ echo -n "Unknown"; \ fi) VERSION := $(RELEASE)-$(SUBREL) -SCAPIVERS := $(shell sed -ne '/define SCAPIVERS/ s/^.[a-zA-Z ]*\([0-9]*\).*$$/\1/p' $(PLUGIN).c) +SCAPIVERS := $(shell sed -ne '/define SCAPIVERS/ s/^.[a-zA-Z ]*\([0-9]*\).*$$/\1/p' version.h) ### The directory environment: diff --git a/sc.c b/sc.c index 7fb7e11..b2051af 100644 --- a/sc.c +++ b/sc.c @@ -77,9 +77,6 @@ #error Your VDR API version is too old. See README. #endif -// SC API version number for loading shared libraries -#define SCAPIVERS 24 - static cPlugin *ScPlugin; static cOpts *ScOpts, *LogOpts; static const char * const cfgsub="sc"; @@ -1137,12 +1134,18 @@ cScDll::~cScDll() bool cScDll::Load(void) { char *base=rindex(fileName,'/'); - if(!base) base=fileName; + if(base) base++; else base=fileName; PRINTF(L_CORE_DYN,"loading library: %s",base); if(!handle) { handle=dlopen(fileName,RTLD_NOW|RTLD_LOCAL); - if(handle) return true; - PRINTF(L_GEN_ERROR,"dload: %s: %s",base,dlerror()); + if(handle) { + dlerror(); + int *libapivers=(int *)dlsym(handle,"ScLibApiVersion"); + const char *error=dlerror(); + if(!error && *libapivers==SCAPIVERS) return true; + else PRINTF(L_GEN_ERROR,"dload: %s: SCAPI version doesn't match (plugin=%d, library=%d)",base,SCAPIVERS,!error?*libapivers:0); + } + else PRINTF(L_GEN_ERROR,"dload: %s: %s",base,dlerror()); } return false; } @@ -1223,6 +1226,7 @@ private: cScDlls dlls; #endif cScHousekeeper *keeper; + bool dllSuccess; public: cScPlugin(void); virtual ~cScPlugin(); @@ -1265,9 +1269,11 @@ cScPlugin::cScPlugin(void) LogOpts->Add(new cOptBool ("LogSyslog" ,trNOOP("Log to syslog") ,&logcfg.logSys)); LogOpts->Add(new cOptBool ("LogUserMsg" ,trNOOP("Show user messages") ,&logcfg.logUser)); #ifndef STATICBUILD - dlls.Load(); + dllSuccess=dlls.Load(); +#else + dllSuccess=true; #endif - cScDvbDevice::Capture(); + if(dllSuccess) cScDvbDevice::Capture(); keeper=0; } @@ -1281,7 +1287,7 @@ cScPlugin::~cScPlugin() bool cScPlugin::Initialize(void) { PRINTF(L_GEN_INFO,"SC version %s initializing",ScVersion); - return cScDvbDevice::Initialize(); + return dllSuccess && cScDvbDevice::Initialize(); } bool cScPlugin::Start(void) diff --git a/systems/cardclient/cc.c b/systems/cardclient/cc.c index e7afdfa..1f73c96 100644 --- a/systems/cardclient/cc.c +++ b/systems/cardclient/cc.c @@ -29,6 +29,9 @@ #include "misc.h" #include "opts.h" #include "log-core.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_NAME "Cardclient" #define SYSTEM_PRI -15 diff --git a/systems/conax/conax.c b/systems/conax/conax.c index 390760b..9bc6cc1 100644 --- a/systems/conax/conax.c +++ b/systems/conax/conax.c @@ -26,6 +26,9 @@ #include "data.h" #include "misc.h" #include "log-sys.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_CONAX 0x0B00 diff --git a/systems/constcw/constcw.c b/systems/constcw/constcw.c index 901c307..314e9a7 100644 --- a/systems/constcw/constcw.c +++ b/systems/constcw/constcw.c @@ -28,6 +28,9 @@ #include "system-common.h" #include "data.h" #include "misc.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_NAME "ConstCW" #define SYSTEM_PRI -20 diff --git a/systems/cryptoworks/cryptoworks.c b/systems/cryptoworks/cryptoworks.c index 1fc0d6b..c8a2b0c 100644 --- a/systems/cryptoworks/cryptoworks.c +++ b/systems/cryptoworks/cryptoworks.c @@ -28,6 +28,9 @@ #include "crypto.h" #include "misc.h" #include "log-sys.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_CRYPTOWORKS 0x0D00 diff --git a/systems/irdeto/irdeto.c b/systems/irdeto/irdeto.c index 02b166e..ebcf007 100644 --- a/systems/irdeto/irdeto.c +++ b/systems/irdeto/irdeto.c @@ -25,6 +25,9 @@ #include "irdeto.h" #include "log-irdeto.h" +#include "version.h" + +SCAPIVERSTAG(); static const struct LogModule lm_sys = { (LMOD_ENABLE|L_SYS_ALL)&LOPT_MASK, diff --git a/systems/nagra/nagra.c b/systems/nagra/nagra.c index 09fa884..5436c70 100644 --- a/systems/nagra/nagra.c +++ b/systems/nagra/nagra.c @@ -25,6 +25,9 @@ #include "nagra-def.h" #include "log-nagra.h" #include "log-core.h" +#include "version.h" + +SCAPIVERSTAG(); static const struct LogModule lm_sys = { (LMOD_ENABLE|L_SYS_ALL)&LOPT_MASK, diff --git a/systems/nds/nds.c b/systems/nds/nds.c index 0d04ed0..159a014 100644 --- a/systems/nds/nds.c +++ b/systems/nds/nds.c @@ -19,6 +19,9 @@ #include "nds.h" #include "log-nds.h" +#include "version.h" + +SCAPIVERSTAG(); static const struct LogModule lm_sys = { (LMOD_ENABLE|L_SYS_ALL)&LOPT_MASK, diff --git a/systems/sc-conax/sc-conax.c b/systems/sc-conax/sc-conax.c index 06a9b2e..83925bf 100644 --- a/systems/sc-conax/sc-conax.c +++ b/systems/sc-conax/sc-conax.c @@ -25,6 +25,9 @@ #include "parse.h" #include "misc.h" #include "log-sc.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_CONAX 0x0B00 diff --git a/systems/sc-cryptoworks/sc-cryptoworks.c b/systems/sc-cryptoworks/sc-cryptoworks.c index fa54bff..1f3eb7e 100644 --- a/systems/sc-cryptoworks/sc-cryptoworks.c +++ b/systems/sc-cryptoworks/sc-cryptoworks.c @@ -30,6 +30,9 @@ #include "misc.h" #include "log-sc.h" #include "log-core.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_NAME "SC-Cryptoworks" #define SYSTEM_PRI -5 diff --git a/systems/sc-irdeto/sc-irdeto.c b/systems/sc-irdeto/sc-irdeto.c index 2a316f5..783b9ec 100644 --- a/systems/sc-irdeto/sc-irdeto.c +++ b/systems/sc-irdeto/sc-irdeto.c @@ -30,6 +30,9 @@ #include "parse.h" #include "log-sc.h" #include "log-core.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_NAME "SC-Irdeto" #define SYSTEM_PRI -5 diff --git a/systems/sc-nagra/sc-nagra.c b/systems/sc-nagra/sc-nagra.c index e0feeac..7a17be6 100644 --- a/systems/sc-nagra/sc-nagra.c +++ b/systems/sc-nagra/sc-nagra.c @@ -28,6 +28,9 @@ #include "helper.h" #include "log-sc.h" #include "log-core.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_NAGRA 0x1801 diff --git a/systems/sc-seca/sc-seca.c b/systems/sc-seca/sc-seca.c index 763da5f..d0ff742 100644 --- a/systems/sc-seca/sc-seca.c +++ b/systems/sc-seca/sc-seca.c @@ -28,6 +28,9 @@ #include "opts.h" #include "parse.h" #include "log-sc.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_SECA 0x0100 diff --git a/systems/sc-viaccess/sc-viaccess.c b/systems/sc-viaccess/sc-viaccess.c index 5b0faf4..7561462 100644 --- a/systems/sc-viaccess/sc-viaccess.c +++ b/systems/sc-viaccess/sc-viaccess.c @@ -27,6 +27,9 @@ #include "misc.h" #include "log-sc.h" #include "log-core.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_VIACCESS 0x0500 diff --git a/systems/sc-videoguard2/sc-videoguard2.c b/systems/sc-videoguard2/sc-videoguard2.c index 3080e88..7e98e1e 100644 --- a/systems/sc-videoguard2/sc-videoguard2.c +++ b/systems/sc-videoguard2/sc-videoguard2.c @@ -29,6 +29,9 @@ #include "helper.h" #include "log-sc.h" #include "log-core.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_VIDEOGUARD2 0x0900 diff --git a/systems/seca/seca.c b/systems/seca/seca.c index 5f51736..5723032 100644 --- a/systems/seca/seca.c +++ b/systems/seca/seca.c @@ -32,6 +32,9 @@ #include "misc.h" #include "log-sys.h" #include "log-core.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_SECA 0x0100 diff --git a/systems/shl/shl.c b/systems/shl/shl.c index 95a8877..af42e4b 100644 --- a/systems/shl/shl.c +++ b/systems/shl/shl.c @@ -32,6 +32,9 @@ #include "filter.h" #include "misc.h" #include "log-sys.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_SHL 0x4A60 diff --git a/systems/viaccess/viaccess.c b/systems/viaccess/viaccess.c index 305083a..5178247 100644 --- a/systems/viaccess/viaccess.c +++ b/systems/viaccess/viaccess.c @@ -30,6 +30,9 @@ #include "viaccess.h" #include "tps.h" #include "log-viaccess.h" +#include "version.h" + +SCAPIVERSTAG(); #define SYSTEM_NAME "Viaccess" #define SYSTEM_PRI -10 diff --git a/testing/Makefile b/testing/Makefile index 189fea5..72f02b9 100644 --- a/testing/Makefile +++ b/testing/Makefile @@ -14,12 +14,11 @@ CXXFLAGS ?= -g -march=pentium3 -O2 -Wall -Woverloaded-virtual ### Includes and Defines -SCAPIVERS = $(shell sed -ne '/define SCAPIVERS/ s/^.[a-zA-Z ]*\([0-9]*\).*$$/\1/p' ../sc.c) APIVERSION = $(shell sed -ne '/define APIVERSION/ s/^.*"\(.*\)".*$$/\1/p' $(VDRDIR)/include/vdr/config.h) APIVERSNUM = $(shell sed -ne '/define APIVERSNUM/ s/^.[a-zA-Z ]*\([0-9]*\) .*$$/\1/p' $(VDRDIR)/include/vdr/config.h) INCLUDES = -I.. -I$(VDRDIR)/include -DEFINES = -DAPIVERSNUM=$(APIVERSNUM) -DAPIVERSION='"$(APIVERSION)"' -DSCAPIVERS=$(SCAPIVERS) -D_GNU_SOURCE +DEFINES = -DAPIVERSNUM=$(APIVERSNUM) -DAPIVERSION='"$(APIVERSION)"' -D_GNU_SOURCE OBJS = misc.o log.o override.o data.o crypto.o parse.o system.o system-common.o smartcard.o network.o filter.o version.o SHAREDOBJS = compat.o $(VDRDIR)/tools.o $(VDRDIR)/thread.o diff --git a/testing/compat.c b/testing/compat.c index 56d8ac6..01a3ffd 100644 --- a/testing/compat.c +++ b/testing/compat.c @@ -23,10 +23,17 @@ static bool DllLoad(const char *fileName) { const char *base=rindex(fileName,'/'); - if(!base) base=fileName; + if(base) base++; else base=fileName; void *handle=dlopen(fileName,RTLD_NOW|RTLD_LOCAL); - if(handle) return true; - printf("dload: %s: %s\n",base,dlerror()); + if(handle) { + dlerror(); + int *libapivers=(int *)dlsym(handle,"ScLibApiVersion"); + const char *error=dlerror(); + if(!error && *libapivers==SCAPIVERS) + return true; + else printf("dload: %s: SCAPI version doesn't match (plugin=%d, library=%d)\n",base,SCAPIVERS,!error?*libapivers:0); + } + else printf("dload: %s: %s\n",base,dlerror()); return false; } @@ -39,7 +46,7 @@ bool DllsLoad(const char *libdir) struct dirent *e; while((e=dir.Next())) { if(!fnmatch(pat,e->d_name,FNM_PATHNAME|FNM_NOESCAPE)) { - DllLoad(AddDirectory(libdir,e->d_name)); + if(!DllLoad(AddDirectory(libdir,e->d_name))) res=false; } } return res; diff --git a/version.h b/version.h index 956a976..6f3bcdd 100644 --- a/version.h +++ b/version.h @@ -24,4 +24,8 @@ extern const char *ScVersion; +// SC API version number for loading shared libraries +#define SCAPIVERS 24 +#define SCAPIVERSTAG() int ScLibApiVersion=SCAPIVERS + #endif