Skip to content

Commit

Permalink
Merge pull request #418 from oliverkurth/stable-3.5
Browse files Browse the repository at this point in the history
Stable 3.5
  • Loading branch information
oliverkurth committed Apr 4, 2023
2 parents ba31ffe + 2e11e3d commit 476197e
Show file tree
Hide file tree
Showing 84 changed files with 463 additions and 243 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2019-2022 VMware, Inc. All Rights Reserved.
# Copyright (C) 2019-2023 VMware, Inc. All Rights Reserved.
#
# Licensed under the GNU General Public License v2 (the "License");
# you may not use this file except in compliance with the License. The terms
Expand All @@ -8,7 +8,7 @@

CMAKE_MINIMUM_REQUIRED(VERSION 3.0 FATAL_ERROR)

project(tdnf VERSION 3.5.1 LANGUAGES C)
project(tdnf VERSION 3.5.2 LANGUAGES C)
set(VERSION ${PROJECT_VERSION})
set(PROJECT_YEAR 2023)

Expand Down
2 changes: 1 addition & 1 deletion client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2022 VMware, Inc. All Rights Reserved.
# Copyright (C) 2020-2023 VMware, Inc. All Rights Reserved.
#
# Licensed under the GNU General Public License v2 (the "License");
# you may not use this file except in compliance with the License. The terms
Expand Down
5 changes: 1 addition & 4 deletions client/api.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2022 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2023 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -1675,9 +1675,6 @@ TDNFResolve(
}
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFCheckProtectedPkgs(pSolvedPkgInfo);
BAIL_ON_TDNF_ERROR(dwError);

pSolvedPkgInfo->nNeedAction =
pSolvedPkgInfo->pPkgsToInstall ||
pSolvedPkgInfo->pPkgsToUpgrade ||
Expand Down
2 changes: 1 addition & 1 deletion client/client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2020 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2022 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down
25 changes: 14 additions & 11 deletions client/config.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2022 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2023 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -53,10 +53,10 @@ TDNFReadConfig(
{
uint32_t dwError = 0;
PTDNF_CONF pConf = NULL;
char *pszConfFileCopy = NULL;
char *pszConfDir = NULL;
char *pszMinVersionsDir = NULL;
char *pszConfFileCopy2 = NULL;
char *pszPkgLocksDir = NULL;
char *pszProtectedDir = NULL;

const char *pszProxyUser = NULL;
const char *pszProxyPass = NULL;
Expand Down Expand Up @@ -239,33 +239,35 @@ TDNFReadConfig(
if (pConf->pszPersistDir == NULL)
pConf->pszPersistDir = strdup(TDNF_DEFAULT_DB_LOCATION);

/* We need a copy of pszConfFile because dirname() modifies its argument */
dwError = TDNFAllocateString(pszConfFile, &pszConfFileCopy);
dwError = TDNFDirName(pszConfFile, &pszConfDir);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFJoinPath(&pszMinVersionsDir, dirname(pszConfFileCopy), "minversions.d", NULL);
dwError = TDNFJoinPath(&pszMinVersionsDir, pszConfDir, "minversions.d", NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFReadConfFilesFromDir(pszMinVersionsDir, &pConf->ppszMinVersions);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFAllocateString(pszConfFile, &pszConfFileCopy2);
dwError = TDNFJoinPath(&pszPkgLocksDir, pszConfDir, "locks.d", NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFJoinPath(&pszPkgLocksDir, dirname(pszConfFileCopy2), "locks.d", NULL);
dwError = TDNFReadConfFilesFromDir(pszPkgLocksDir, &pConf->ppszPkgLocks);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFReadConfFilesFromDir(pszPkgLocksDir, &pConf->ppszPkgLocks);
dwError = TDNFJoinPath(&pszProtectedDir, pszConfDir, "protected.d", NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFReadConfFilesFromDir(pszProtectedDir, &pConf->ppszProtectedPkgs);
BAIL_ON_TDNF_ERROR(dwError);

pTdnf->pConf = pConf;

cleanup:
destroy_cnftree(cn_conf);
TDNF_SAFE_FREE_MEMORY(pszConfFileCopy);
TDNF_SAFE_FREE_MEMORY(pszConfFileCopy2);
TDNF_SAFE_FREE_MEMORY(pszConfDir);
TDNF_SAFE_FREE_MEMORY(pszMinVersionsDir);
TDNF_SAFE_FREE_MEMORY(pszPkgLocksDir);
TDNF_SAFE_FREE_MEMORY(pszProtectedDir);
return dwError;

error:
Expand Down Expand Up @@ -345,6 +347,7 @@ TDNFFreeConfig(
TDNF_SAFE_FREE_STRINGARRAY(pConf->ppszExcludes);
TDNF_SAFE_FREE_STRINGARRAY(pConf->ppszMinVersions);
TDNF_SAFE_FREE_STRINGARRAY(pConf->ppszPkgLocks);
TDNF_SAFE_FREE_STRINGARRAY(pConf->ppszProtectedPkgs);
TDNFFreeMemory(pConf);
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/defines.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2022 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2023 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -234,7 +234,7 @@ typedef enum
{ERROR_TDNF_RPM_CHECK, "ERROR_TDNF_RPM_CHECK", "rpm check reported errors"}, \
{ERROR_TDNF_RPMTS_BAD_ROOT_DIR, "ERROR_TDNF_RPMTS_BAD_ROOT_DIR", "Bad root directory"}, \
{ERROR_TDNF_METADATA_EXPIRE_PARSE, "ERROR_TDNF_METADATA_EXPIRE_PARSE", "metadata_expire value could not be parsed. Check your repo files."},\
{ERROR_TDNF_SELF_ERASE, "ERROR_TDNF_SELF_ERASE", "The operation would result in removing the protected package : tdnf"},\
{ERROR_TDNF_PROTECTED, "ERROR_TDNF_PROTECTED", "The operation would result in removing a protected package."},\
{ERROR_TDNF_DOWNGRADE_NOT_ALLOWED,\
"ERROR_TDNF_DOWNGRADE_NOT_ALLOWED",\
"a downgrade is not allowed below the minimal version. Check 'minversions' in the configuration."},\
Expand Down
150 changes: 148 additions & 2 deletions client/goal.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2022 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2023 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -355,7 +355,12 @@ TDNFSolv(

if(nAllowErasing)
{
solver_set_flag(pSolv, SOLVER_FLAG_ALLOW_UNINSTALL, 1);
if (pTdnf->pConf->ppszProtectedPkgs) {
dwError = TDNFSolvAddProtectPkgs(pTdnf, pQueueJobs, pTdnf->pSack->pPool);
BAIL_ON_TDNF_ERROR(dwError);
} else {
solver_set_flag(pSolv, SOLVER_FLAG_ALLOW_UNINSTALL, 1);
}
}
solver_set_flag(pSolv, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
solver_set_flag(pSolv, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
Expand Down Expand Up @@ -387,6 +392,12 @@ TDNFSolv(
BAIL_ON_TDNF_ERROR(dwError);
}

if (pTdnf->pConf->ppszProtectedPkgs) {
/* catch protected obsoleted packages, and double check for removals */
dwError = TDNFSolvCheckProtectPkgsInTrans(pTdnf, pTrans, pTdnf->pSack->pPool);
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = TDNFGoalGetAllResultsIgnoreNoData(
pTrans,
pSolv,
Expand Down Expand Up @@ -1037,3 +1048,138 @@ TDNFSolvAddMinVersions(
goto cleanup;
}

uint32_t
TDNFSolvAddProtectPkgs(
PTDNF pTdnf,
Queue* pQueueJobs,
Pool *pPool
)
{
uint32_t dwError = 0;
char **ppszProtectedPkgs = NULL;
int i, j;
Queue qPkgs = {0};
Id p;
Solvable *s;

if(!pTdnf || !pQueueJobs || !pPool || !pTdnf->pConf)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

ppszProtectedPkgs = pTdnf->pConf->ppszProtectedPkgs;
queue_init(&qPkgs);
for (i = 0; ppszProtectedPkgs[i]; i++) {
Id idPkg = pool_str2id(pPool, ppszProtectedPkgs[i], 1);
if (idPkg) {
queue_push(&qPkgs, idPkg);
}
}

/* Not setting SOLVER_ALLOWUNINSTALL will not prevent a package from being
uninstalled if it's going to be removed directly. */
for (j = 0; j < pQueueJobs->count; j += 2) {
Id how = pQueueJobs->elements[j];
/* assuming that all erase jobs that we added use SOLVER_SOLVABLE */
if (((how & SOLVER_JOBMASK) == SOLVER_ERASE) && (how & SOLVER_SOLVABLE)) {
Id what = pQueueJobs->elements[j+1];
Solvable *s = pool_id2solvable(pPool, what);
for (i = 0; i < qPkgs.count; i++) {
if (qPkgs.elements[i] == s->name)
break;
}
if (i < qPkgs.count) {
pr_err("package %s is protected\n", ppszProtectedPkgs[i]);
dwError = ERROR_TDNF_PROTECTED;
BAIL_ON_TDNF_ERROR(dwError);
}
}
}

/* There is no "SOLVER_PROTECTED" flag, so we allow
all pkgs that are not protected to be removed. */
FOR_REPO_SOLVABLES(pPool->installed, p, s)
{
for (i = 0; i < qPkgs.count; i++) {
if (qPkgs.elements[i] == s->name)
break;
}
if (i == qPkgs.count) {
queue_push2(pQueueJobs, SOLVER_SOLVABLE|SOLVER_ALLOWUNINSTALL, p);
} else {
/* autoerase would remove this, even if we do not set
SOLVER_ALLOWUNINSTALL for it */
queue_push2(pQueueJobs, SOLVER_SOLVABLE|SOLVER_USERINSTALLED, p);
}
}

cleanup:
queue_free(&qPkgs);
return dwError;
error:
goto cleanup;
}

uint32_t
TDNFSolvCheckProtectPkgsInTrans(
PTDNF pTdnf,
Transaction *pTrans,
Pool *pPool
)
{
uint32_t dwError = 0;
char **ppszProtectedPkgs = NULL;
int i;
Queue qPkgs = {0};

if(!pTdnf || !pTrans || !pPool || !pTdnf->pConf)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

ppszProtectedPkgs = pTdnf->pConf->ppszProtectedPkgs;
queue_init(&qPkgs);
for (i = 0; ppszProtectedPkgs[i]; i++) {
Id idPkg = pool_str2id(pPool, ppszProtectedPkgs[i], 1);
if (idPkg) {
queue_push(&qPkgs, idPkg);
}
}

for (i = 0; i < pTrans->steps.count; i++) {
Id idType;
Id idPkg = pTrans->steps.elements[i];

idType = transaction_type(pTrans, idPkg,
SOLVER_TRANSACTION_SHOW_OBSOLETES);
if (idType != SOLVER_TRANSACTION_OBSOLETED) {
idType = transaction_type(pTrans, idPkg,
SOLVER_TRANSACTION_SHOW_ACTIVE|
SOLVER_TRANSACTION_SHOW_ALL);
}
if (idType == SOLVER_TRANSACTION_OBSOLETED ||
idType == SOLVER_TRANSACTION_ERASE) {
int j;
Solvable *s = pool_id2solvable(pPool, idPkg);
for (j = 0; j < qPkgs.count; j++) {
if (qPkgs.elements[j] == s->name) {
pr_err("package %s would be %s but it is protected\n",
ppszProtectedPkgs[j],
idType == SOLVER_TRANSACTION_OBSOLETED ?
"obsoleted" : "removed");
dwError = ERROR_TDNF_PROTECTED;
BAIL_ON_TDNF_ERROR(dwError);
}
}
}
}

cleanup:
queue_free(&qPkgs);
return dwError;
error:
goto cleanup;
}

15 changes: 3 additions & 12 deletions client/gpgcheck.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2021 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2023 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -516,7 +516,6 @@ TDNFFetchRemoteGPGKey(
uint32_t dwError = 0;
char* pszFilePath = NULL;
char* pszNormalPath = NULL;
char* pszFilePathCopy = NULL;
char* pszTopKeyCacheDir = NULL;
char* pszRealTopKeyCacheDir = NULL;
char* pszDownloadCacheDir = NULL;
Expand Down Expand Up @@ -562,16 +561,8 @@ TDNFFetchRemoteGPGKey(
BAIL_ON_TDNF_ERROR(dwError);
}

// dirname() may modify the contents of path, so it may be desirable to
// pass a copy when calling this function.
dwError = TDNFAllocateString(pszNormalPath, &pszFilePathCopy);
dwError = TDNFDirName(pszNormalPath, &pszDownloadCacheDir);
BAIL_ON_TDNF_ERROR(dwError);
pszDownloadCacheDir = dirname(pszFilePathCopy);
if(!pszDownloadCacheDir)
{
dwError = ENOENT;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}

if(access(pszDownloadCacheDir, F_OK))
{
Expand All @@ -595,7 +586,7 @@ TDNFFetchRemoteGPGKey(
TDNF_SAFE_FREE_MEMORY(pszFilePath);
TDNF_SAFE_FREE_MEMORY(pszRealTopKeyCacheDir);
TDNF_SAFE_FREE_MEMORY(pszTopKeyCacheDir);
TDNF_SAFE_FREE_MEMORY(pszFilePathCopy);
TDNF_SAFE_FREE_MEMORY(pszDownloadCacheDir);
TDNF_SAFE_FREE_MEMORY(pszKeyLocation);
return dwError;

Expand Down
2 changes: 1 addition & 1 deletion client/includes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2022 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2023 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down
2 changes: 1 addition & 1 deletion client/init.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2022 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2023 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down
Loading

0 comments on commit 476197e

Please sign in to comment.