Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rhel-9.5: Fix for RHEL-1454 #1663

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libdnf/dnf-rpmts-private.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ gboolean dnf_rpmts_add_install_filename2(rpmts ts,
DnfPackage *pkg,
GError **error);

gboolean dnf_rpmts_add_reinstall_filename(rpmts ts,
const gchar *filename,
gboolean allow_untrusted,
GError **error);


#endif /* __DNF_RPMTS_PRIVATE_HPP */
108 changes: 73 additions & 35 deletions libdnf/dnf-rpmts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,94 +88,132 @@ test_fail_safe(Header * hdr, DnfPackage * pkg, GError **error)
return ret;
}

gboolean
dnf_rpmts_add_install_filename2(rpmts ts,
const gchar *filename,
gboolean allow_untrusted,
gboolean is_update,
DnfPackage * pkg,
GError **error) try
{
gboolean ret = TRUE;
gint res;
Header hdr;
FD_t fd;

/* open this */
fd = Fopen(filename, "r.ufdio");
res = rpmReadPackageFile(ts, fd, filename, &hdr);

static gboolean
result_is_accepted(gint result, gboolean allow_untrusted, const gchar *filename, GError **error) {
/* be less strict when we're allowing untrusted transactions */
if (allow_untrusted) {
switch(res) {
switch(result) {
case RPMRC_NOKEY:
case RPMRC_NOTFOUND:
case RPMRC_NOTTRUSTED:
case RPMRC_OK:
break;
return TRUE;
case RPMRC_FAIL:
ret = FALSE;
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
_("signature does not verify for %s"),
filename);
goto out;
return FALSE;
default:
ret = FALSE;
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
_("failed to open(generic error): %s"),
filename);
goto out;
return FALSE;
}
} else {
switch(res) {
switch(result) {
case RPMRC_OK:
break;
return TRUE;
case RPMRC_NOTTRUSTED:
ret = FALSE;
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
_("failed to verify key for %s"),
filename);
goto out;
return FALSE;
case RPMRC_NOKEY:
ret = FALSE;
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
_("public key unavailable for %s"),
filename);
goto out;
return FALSE;
case RPMRC_NOTFOUND:
ret = FALSE;
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
_("signature not found for %s"),
filename);
goto out;
return FALSE;
case RPMRC_FAIL:
ret = FALSE;
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
_("signature does not verify for %s"),
filename);
goto out;
return FALSE;
default:
ret = FALSE;
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
_("failed to open(generic error): %s"),
filename);
goto out;
return FALSE;
}
}
}

gboolean
dnf_rpmts_add_reinstall_filename(rpmts ts,
const gchar *filename,
gboolean allow_untrusted,
GError **error) try
{
gboolean ret = TRUE;
gint res;
Header hdr;
FD_t fd;

/* open this */
fd = Fopen(filename, "r.ufdio");
res = rpmReadPackageFile(ts, fd, filename, &hdr);

if (!result_is_accepted(res, allow_untrusted, filename, error)) {
ret = FALSE;
goto out;
}

/* add to the transaction */
res = rpmtsAddReinstallElement(ts, hdr, (fnpyKey) filename);
if (res != 0) {
ret = FALSE;
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
_("failed to add reinstall element: %1$s [%2$i]"),
filename, res);
goto out;
}
out:
Fclose(fd);
headerFree(hdr);
return ret;
} CATCH_TO_GERROR(FALSE)

gboolean
dnf_rpmts_add_install_filename2(rpmts ts,
const gchar *filename,
gboolean allow_untrusted,
gboolean is_update,
DnfPackage * pkg,
GError **error) try
{
gboolean ret = TRUE;
gint res;
Header hdr;
FD_t fd;

/* open this */
fd = Fopen(filename, "r.ufdio");
res = rpmReadPackageFile(ts, fd, filename, &hdr);

if (!result_is_accepted(res, allow_untrusted, filename, error)) {
ret = FALSE;
goto out;
}
if (pkg) {
if (!test_fail_safe(&hdr, pkg, error)) {
ret = FALSE;
Expand Down
23 changes: 18 additions & 5 deletions libdnf/dnf-transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ dnf_transaction_ts_progress_cb(const void *arg,

/* map to correct action code */
action = dnf_package_get_action(pkg);
if (action == DNF_STATE_ACTION_UNKNOWN)
if (action == DNF_STATE_ACTION_UNKNOWN || action == DNF_STATE_ACTION_REINSTALL)
action = DNF_STATE_ACTION_INSTALL;

/* set the pkgid if not already set */
Expand Down Expand Up @@ -641,7 +641,7 @@ dnf_transaction_ts_progress_cb(const void *arg,

/* map to correct action code */
action = dnf_package_get_action(pkg);
if (action == DNF_STATE_ACTION_UNKNOWN)
if (action == DNF_STATE_ACTION_UNKNOWN || action == DNF_STATE_ACTION_REINSTALL)
action = DNF_STATE_ACTION_REMOVE;

/* remove start */
Expand Down Expand Up @@ -716,7 +716,7 @@ dnf_transaction_ts_progress_cb(const void *arg,

/* map to correct action code */
action = dnf_package_get_action(pkg);
if (action == DNF_STATE_ACTION_UNKNOWN)
if (action == DNF_STATE_ACTION_UNKNOWN || action == DNF_STATE_ACTION_REINSTALL)
action = DNF_STATE_ACTION_REMOVE;

dnf_state_set_package_progress(
Expand Down Expand Up @@ -1221,8 +1221,12 @@ dnf_transaction_commit(DnfTransaction *transaction, HyGoal goal, DnfState *state
filename = dnf_package_get_filename(pkg);
allow_untrusted = (priv->flags & DNF_TRANSACTION_FLAG_ONLY_TRUSTED) == 0;
is_update = action == DNF_STATE_ACTION_UPDATE || action == DNF_STATE_ACTION_DOWNGRADE;
ret = dnf_rpmts_add_install_filename2(
priv->ts, filename, allow_untrusted, is_update, pkg, error);
if (action == DNF_STATE_ACTION_REINSTALL) {
ret = dnf_rpmts_add_reinstall_filename(priv->ts, filename, allow_untrusted, error);
} else {
ret = dnf_rpmts_add_install_filename2(
priv->ts, filename, allow_untrusted, is_update, pkg, error);
}
if (!ret)
goto out;

Expand Down Expand Up @@ -1334,6 +1338,15 @@ dnf_transaction_commit(DnfTransaction *transaction, HyGoal goal, DnfState *state
g_ptr_array_unref(pkglist);
}

/* add reinstalled packages to a helper array which is used to
* map removed packages auto-added by rpm to actual DnfPackage's */
pkglist = dnf_goal_get_packages(goal, DNF_PACKAGE_INFO_REINSTALL, -1);
for (i = 0; i < pkglist->len; i++) {
pkg_tmp = static_cast< DnfPackage * >(g_ptr_array_index(pkglist, i));
g_ptr_array_add(priv->remove_helper, g_object_ref(pkg_tmp));
}
g_ptr_array_unref(pkglist);

/* this section done */
ret = dnf_state_done(state, error);
if (!ret)
Expand Down
Loading