From 407f1ffe143885f0b27ec56a401ff4619b3c6379 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Mon, 28 Nov 2022 13:25:15 -0800 Subject: [PATCH 1/4] Use all best available checksums from metalink file (fixes: #373) --- plugins/metalink/utils.c | 46 ++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/plugins/metalink/utils.c b/plugins/metalink/utils.c index 3c9c8a51..c0c74ca5 100644 --- a/plugins/metalink/utils.c +++ b/plugins/metalink/utils.c @@ -371,7 +371,6 @@ TDNFCheckRepoMDFileHashFromMetalink( { uint32_t dwError = 0; TDNF_ML_HASH_LIST *hashList = NULL; - TDNF_ML_HASH_INFO *hashInfo = NULL; unsigned char digest[EVP_MAX_MD_SIZE] = {0}; int hash_Type = -1; TDNF_ML_HASH_INFO *currHashInfo = NULL; @@ -383,6 +382,7 @@ TDNFCheckRepoMDFileHashFromMetalink( BAIL_ON_TDNF_ERROR(dwError); } + /* find best (highest) available hash type */ for(hashList = ml_ctx->hashes; hashList; hashList = hashList->next) { int currHashType = TDNF_HASH_SENTINEL; @@ -397,28 +397,42 @@ TDNFCheckRepoMDFileHashFromMetalink( dwError = TDNFGetResourceType(currHashInfo->type, &currHashType); BAIL_ON_TDNF_ERROR(dwError); - if ((hash_Type > currHashType)|| - (!TDNFCheckHexDigest(currHashInfo->value, hash_ops[currHashType].length))) - { - continue; - } - hash_Type = currHashType; - hashInfo = currHashInfo; + if (hash_Type < currHashType) + hash_Type = currHashType; } - if (hashInfo != NULL) - { - dwError = TDNFChecksumFromHexDigest(hashInfo->value, digest); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = TDNFCheckHash(pszFile, digest, hash_Type); + if (hash_Type < 0) { + /* no hash type was found */ + dwError = ERROR_TDNF_INVALID_REPO_FILE; BAIL_ON_TDNF_ERROR(dwError); } - else + /* otherwise hash_Type is the best one */ + + /* now check for all best hash types. Test until one succeeds + or until we run out */ + for(hashList = ml_ctx->hashes; hashList; hashList = hashList->next) { - dwError = ERROR_TDNF_INVALID_REPO_FILE; + int currHashType = TDNF_HASH_SENTINEL; + currHashInfo = hashList->data; + + dwError = TDNFGetResourceType(currHashInfo->type, &currHashType); BAIL_ON_TDNF_ERROR(dwError); + + /* filter for our best type and also check that the value is valid */ + if (hash_Type == currHashType && + TDNFCheckHexDigest(currHashInfo->value, hash_ops[currHashType].length)) { + dwError = TDNFChecksumFromHexDigest(currHashInfo->value, digest); + BAIL_ON_TDNF_ERROR(dwError); + + dwError = TDNFCheckHash(pszFile, digest, hash_Type); + if (dwError != 0 && dwError != ERROR_TDNF_CHECKSUM_VALIDATION_FAILED) { + BAIL_ON_TDNF_ERROR(dwError); + } + if (dwError == 0) + break; + } } + cleanup: return dwError; error: From 7121dcc575cdf40a0df92c4043bbcb061a35687d Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Mon, 28 Nov 2022 13:35:00 -0800 Subject: [PATCH 2/4] move leftover metalink bits from core to plugin --- client/prototypes.h | 6 ------ client/structs.h | 34 ---------------------------------- plugins/metalink/prototypes.h | 6 ++++++ plugins/metalink/structs.h | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/client/prototypes.h b/client/prototypes.h index dd5aac46..e60b7829 100644 --- a/client/prototypes.h +++ b/client/prototypes.h @@ -225,12 +225,6 @@ TDNFFreeHistoryInfoItems( int nCount ); -uint32_t -TDNFCheckRepoMDFileHashFromMetalink( - const char *pszFile, - TDNF_ML_CTX *ml_ctx - ); - //remoterepo.c uint32_t TDNFDownloadFileFromRepo( diff --git a/client/structs.h b/client/structs.h index 15473d1a..7909861a 100644 --- a/client/structs.h +++ b/client/structs.h @@ -81,40 +81,6 @@ typedef struct _TDNF_EVENT_DATA_ struct _TDNF_EVENT_DATA_ *pNext; } TDNF_EVENT_DATA, *PTDNF_EVENT_DATA; -//Metalink Structures. -typedef struct _TDNF_ML_LIST_ -{ - struct _TDNF_ML_LIST_ *next; - void* data; -} TDNF_ML_LIST, TDNF_ML_URL_LIST, TDNF_ML_HASH_LIST; - -//Metalink hash info per hash type. -typedef struct _TDNF_ML_HASH_INFO_ -{ - char *type; - char *value; -} TDNF_ML_HASH_INFO; - -//Metalink url info per hash type. -typedef struct _TDNF_ML_URL_INFO_ -{ - char *protocol; - char *type; - char *location; - char *url; - int preference; -} TDNF_ML_URL_INFO; - -//Metalink global parsed info. -typedef struct _TDNF_ML_CTX_ -{ - char *filename; - signed long timestamp; - signed long size; - TDNF_ML_LIST *hashes; - TDNF_ML_LIST *urls; -} TDNF_ML_CTX; - typedef struct progress_cb_data { time_t cur_time; time_t prev_time; diff --git a/plugins/metalink/prototypes.h b/plugins/metalink/prototypes.h index 0348d680..7a48c24e 100644 --- a/plugins/metalink/prototypes.h +++ b/plugins/metalink/prototypes.h @@ -50,6 +50,12 @@ TDNFParseUrlTag( xmlNode *node ); +uint32_t +TDNFCheckRepoMDFileHashFromMetalink( + const char *pszFile, + TDNF_ML_CTX *ml_ctx + ); + // api.c const char * diff --git a/plugins/metalink/structs.h b/plugins/metalink/structs.h index 7d51c49c..c5375191 100644 --- a/plugins/metalink/structs.h +++ b/plugins/metalink/structs.h @@ -8,6 +8,40 @@ #pragma once +//Metalink Structures. +typedef struct _TDNF_ML_LIST_ +{ + struct _TDNF_ML_LIST_ *next; + void* data; +} TDNF_ML_LIST, TDNF_ML_URL_LIST, TDNF_ML_HASH_LIST; + +//Metalink hash info per hash type. +typedef struct _TDNF_ML_HASH_INFO_ +{ + char *type; + char *value; +} TDNF_ML_HASH_INFO; + +//Metalink url info per hash type. +typedef struct _TDNF_ML_URL_INFO_ +{ + char *protocol; + char *type; + char *location; + char *url; + int preference; +} TDNF_ML_URL_INFO; + +//Metalink global parsed info. +typedef struct _TDNF_ML_CTX_ +{ + char *filename; + signed long timestamp; + signed long size; + TDNF_ML_LIST *hashes; + TDNF_ML_LIST *urls; +} TDNF_ML_CTX; + /* per repo */ typedef struct _TDNF_METALINK_DATA_ { From 130ffa4947fff244b2a2216fe60dcf0bd13543b8 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Mon, 21 Nov 2022 10:38:05 -0800 Subject: [PATCH 3/4] plugins: move plugin search dir one level up --- client/plugins.c | 3 +-- plugins/metalink/CMakeLists.txt | 2 +- plugins/metalink/utils.c | 4 +++- plugins/repogpgcheck/CMakeLists.txt | 2 +- tdnf.spec.in | 23 ++++++++----------- tools/cli/lib/CMakeLists.txt | 6 ++--- .../{tdnfcli.pc.in => tdnf-cli-libs.pc.in} | 0 7 files changed, 18 insertions(+), 22 deletions(-) rename tools/cli/lib/{tdnfcli.pc.in => tdnf-cli-libs.pc.in} (100%) diff --git a/client/plugins.c b/client/plugins.c index d714015b..67bf128c 100644 --- a/client/plugins.c +++ b/client/plugins.c @@ -549,9 +549,8 @@ _TDNFLoadPluginLibs( } dwError = TDNFAllocateStringPrintf( &pszPlugin, - "%s/%s/lib%s.so", + "%s/lib%s.so", pszLibPath, - pPlugin->pszName, pPlugin->pszName); BAIL_ON_TDNF_ERROR(dwError); diff --git a/plugins/metalink/CMakeLists.txt b/plugins/metalink/CMakeLists.txt index a72078c6..3ee28e57 100644 --- a/plugins/metalink/CMakeLists.txt +++ b/plugins/metalink/CMakeLists.txt @@ -30,5 +30,5 @@ target_link_libraries(${PROJECT_NAME} ) set_target_properties(${PROJECT_NAME} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/lib/${PROJECT_NAME}) + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/lib) install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/tdnf-plugins) diff --git a/plugins/metalink/utils.c b/plugins/metalink/utils.c index c0c74ca5..e89e3d4b 100644 --- a/plugins/metalink/utils.c +++ b/plugins/metalink/utils.c @@ -780,7 +780,9 @@ TDNFXmlParseData( BAIL_ON_TDNF_ERROR(dwError); } } - TDNFXmlParseData(ml_ctx, node->children, filename); + if (node->children) { + TDNFXmlParseData(ml_ctx, node->children, filename); + } node = node->next; } diff --git a/plugins/repogpgcheck/CMakeLists.txt b/plugins/repogpgcheck/CMakeLists.txt index ccf6d61b..c6e8a374 100644 --- a/plugins/repogpgcheck/CMakeLists.txt +++ b/plugins/repogpgcheck/CMakeLists.txt @@ -31,5 +31,5 @@ target_link_libraries(${PROJECT_NAME} ) set_target_properties(${PROJECT_NAME} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/lib/${PROJECT_NAME}) + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/lib) install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/tdnf-plugins) diff --git a/tdnf.spec.in b/tdnf.spec.in index b50152b4..2e93d97b 100644 --- a/tdnf.spec.in +++ b/tdnf.spec.in @@ -116,7 +116,7 @@ mkdir build && cd build cmake \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ - -DCMAKE_INSTALL_LIBDIR:PATH=lib \ + -DCMAKE_INSTALL_LIBDIR=%{_libdir} \ -DSYSTEMD_DIR=%{_unitdir} \ .. @@ -130,15 +130,10 @@ cd build && make %{?_smp_mflags} check %install cd build && make DESTDIR=%{buildroot} install %{?_smp_mflags} find %{buildroot} -name '*.a' -delete -mkdir -p %{buildroot}/var/cache/tdnf %{buildroot}%{_unitdir} -ln -sf %{_bindir}/tdnf %{buildroot}%{_bindir}/tyum -ln -sf %{_bindir}/tdnf %{buildroot}%{_bindir}/yum -ln -sf %{_bindir}/tdnf %{buildroot}%{_bindir}/tdnfj -mv %{buildroot}%{_libdir}/pkgconfig/tdnfcli.pc %{buildroot}%{_libdir}/pkgconfig/tdnf-cli-libs.pc -mkdir -p %{buildroot}%{_tdnfpluginsdir}/tdnfmetalink -mkdir -p %{buildroot}%{_tdnfpluginsdir}/tdnfrepogpgcheck -mv %{buildroot}%{_tdnfpluginsdir}/libtdnfmetalink.so %{buildroot}%{_tdnfpluginsdir}/tdnfmetalink/ -mv %{buildroot}%{_tdnfpluginsdir}/libtdnfrepogpgcheck.so %{buildroot}%{_tdnfpluginsdir}/tdnfrepogpgcheck/ +mkdir -p %{buildroot}/var/cache/%{name} %{buildroot}%{_unitdir} +ln -sfv %{name} %{buildroot}%{_bindir}/tyum +ln -sfv %{name} %{buildroot}%{_bindir}/yum +ln -sfv %{name} %{buildroot}%{_bindir}/tdnfj pushd python python3 setup.py install --skip-build --prefix=%{_prefix} --root=%{buildroot} @@ -235,13 +230,13 @@ systemctl try-restart tdnf-cache-updateinfo.timer >/dev/null 2>&1 || : %defattr(-,root,root) %dir %{_sysconfdir}/tdnf/pluginconf.d %config(noreplace) %{_sysconfdir}/tdnf/pluginconf.d/tdnfmetalink.conf -%{_tdnfpluginsdir}/tdnfmetalink/libtdnfmetalink.so +%{_tdnfpluginsdir}/libtdnfmetalink.so %files plugin-repogpgcheck %defattr(-,root,root) -%dir %{_sysconfdir}/tdnf/pluginconf.d -%config(noreplace) %{_sysconfdir}/tdnf/pluginconf.d/tdnfrepogpgcheck.conf -%{_tdnfpluginsdir}/tdnfrepogpgcheck/libtdnfrepogpgcheck.so +%dir %{_sysconfdir}/%{name}/pluginconf.d +%config(noreplace) %{_sysconfdir}/%{name}/pluginconf.d/tdnfrepogpgcheck.conf +%{_tdnfpluginsdir}/libtdnfrepogpgcheck.so %files python %defattr(-,root,root) diff --git a/tools/cli/lib/CMakeLists.txt b/tools/cli/lib/CMakeLists.txt index 070556ee..7f5e3ab4 100644 --- a/tools/cli/lib/CMakeLists.txt +++ b/tools/cli/lib/CMakeLists.txt @@ -8,8 +8,8 @@ # configure pkgconfig file configure_file( - tdnfcli.pc.in - tdnfcli.pc @ONLY + tdnf-cli-libs.pc.in + tdnf-cli-libs.pc @ONLY ) add_library(${LIB_TDNF_CLI} SHARED @@ -38,5 +38,5 @@ set_target_properties(${LIB_TDNF_CLI} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LIB_TDNF_CLI}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tdnf-cli-libs.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(TARGETS ${LIB_TDNF_CLI} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library) diff --git a/tools/cli/lib/tdnfcli.pc.in b/tools/cli/lib/tdnf-cli-libs.pc.in similarity index 100% rename from tools/cli/lib/tdnfcli.pc.in rename to tools/cli/lib/tdnf-cli-libs.pc.in From b8f0032b08227c4bfd83cd5f6942e155dcf7c067 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Thu, 1 Dec 2022 12:00:18 -0800 Subject: [PATCH 4/4] bump version to 3.4.4 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79f56800..6c86d041 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0 FATAL_ERROR) -project(tdnf VERSION 3.4.3 LANGUAGES C) +project(tdnf VERSION 3.4.4 LANGUAGES C) set(VERSION ${PROJECT_VERSION}) set(PROJECT_YEAR 2022)