This commit is contained in:
mcrha 2025-07-30 11:08:27 +02:00 committed by GitHub
commit 797414193f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 447 additions and 39 deletions

View File

@ -35,14 +35,37 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
<arg name="success" type="b" direction="out"/>
</method>
<!--
clean_with_options:
@cache_type: cache type to clean up. Supported types are "all", "packages", "metadata", "dbcache", and "expire-cache".
@options: an array of key/value pairs to modify the call behavior
@success: `true` if the cache was successfully cleaned, `false` otherwise.
@error_msg: string, contains errors encountered while cleaning the cache.
Remove or expire cached data.
Following @options are supported:
- interactive: boolean, default true
Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
Unknown options are ignored.
-->
<method name="clean_with_options">
<arg name="cache_type" type="s" direction="in"/>
<arg name="options" type="a{sv}" direction="in" />
<arg name="success" type="b" direction="out"/>
<arg name="error_msg" type="s" direction="out"/>
</method>
<!--
clean:
@cache_type: cache type to clean up. Supported types are "all", "packages", "metadata", "dbcache", and "expire-cache".
@success: `true` if the cache was successfully cleaned, `false` otherwise.
@error_msg: string, contains errors encountered while cleaning the cache.
Remove or expire cached data.
This is equivalent to call "clean_with_options()" with empty options.
-->
<method name="clean">
<arg name="cache_type" type="s" direction="in"/>

View File

@ -87,6 +87,8 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
Adds a comment to a transaction.
- offline: boolean, default false
If true, the transaction will be prepared to run during the next reboot. Otherwise, it will run immediately.
- interactive: boolean, default true
Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
Unknown options are ignored.
-->

View File

@ -37,6 +37,25 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
<arg name="transaction_status" type="a{sv}" direction="out" />
</method>
<!--
cancel_with_options:
@options: an array of key/value pairs to modify the call behavior
@success: boolean, returns `false` if there was an error during the transaction cancellation, or if the offline transaction was initiated by another tool than dnf5. Returns `true` if the offline transaction was successfully cancelled or if no offline transaction was configured.
@error_msg: string, contains error encountered while cancelling the transaction
Cancel the dnf5 offline transaction configured for the next reboot. Offline updates scheduled by another tool are not cancelled.
Following @options are supported:
- interactive: boolean, default true
Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
Unknown options are ignored.
-->
<method name="cancel_with_options">
<arg name="options" type="a{sv}" direction="in" />
<arg name="success" type="b" direction="out" />
<arg name="error_msg" type="s" direction="out" />
</method>
<!--
cancel:
@ -44,20 +63,67 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
@error_msg: string, contains error encountered while cancelling the transaction
Cancel the dnf5 offline transaction configured for the next reboot. Offline updates scheduled by another tool are not cancelled.
This is equivalent to call "cancel_with_options()" with empty options.
-->
<method name="cancel">
<arg name="success" type="b" direction="out" />
<arg name="error_msg" type="s" direction="out" />
</method>
<!--
clean_with_options:
@options: an array of key/value pairs to modify the call behavior
@success: boolean, returns `false` if there was an error during the transaction cleanup. Returns `true` if the offline transaction was successfully cleaned or if no offline transaction was configured.
@error_msg: string, contains error encountered while cleaning the transaction
Cancel the dnf5 offline transaction configured for the next reboot and remove all stored offline transaction data, including downloaded packages. Offline updates scheduled by another tool are not affected.
Following @options are supported:
- interactive: boolean, default true
Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
Unknown options are ignored.
-->
<method name="clean_with_options">
<arg name="success" type="b" direction="out" />
<arg name="error_msg" type="s" direction="out" />
</method>
<!--
clean:
@success: boolean, returns `false` if there was an error during the transaction cleanup. Returns `true` if the offline transaction was successfully cleaned or if no offline transaction was configured.
@error_msg: string, contains error encountered while cleaning the transaction
Cancel the dnf5 offline transaction configured for the next reboot and remove all stored offline transaction data, including downloaded packages. Offline updates scheduled by another tool are not affected.
This is equivalent to call "clean_with_options()" with empty options.
-->
<method name="clean">
<arg name="options" type="a{sv}" direction="in" />
<arg name="success" type="b" direction="out" />
<arg name="error_msg" type="s" direction="out" />
</method>
<!--
set_finish_action_with_options:
@action: string, one of "poweroff", or "reboot". If set to "poweroff", the system will be powered off after applying the offline transaction. Otherwise the system will reboot.
@options: an array of key/value pairs to modify the call behavior
@success: boolean, true if the action was successfully set
@error_msg: string, contains error encountered while setting the action
Set the action that should be performed after the offline transaction is applied. If the `action` is "poweroff", the system will be powered off, otherwise it will be rebooted (which is default).
The call might fail in case there is no scheduled offline transaction, or the transaction was not scheduled using libdnf5.
Following @options are supported:
- interactive: boolean, default true
Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
Unknown options are ignored.
-->
<method name="set_finish_action_with_options">
<arg name="action" type="s" direction="in" />
<arg name="options" type="a{sv}" direction="in" />
<arg name="success" type="b" direction="out" />
<arg name="error_msg" type="s" direction="out" />
</method>
@ -70,6 +136,9 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
Set the action that should be performed after the offline transaction is applied. If the `action` is "poweroff", the system will be powered off, otherwise it will be rebooted (which is default).
The call might fail in case there is no scheduled offline transaction, or the transaction was not scheduled using libdnf5.
This is equivalent to call "set_finish_action_with_options()" with empty options.
-->
<method name="set_finish_action">
<arg name="action" type="s" direction="in" />

View File

@ -48,33 +48,95 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
<arg name="repositories" type="aa{sv}" direction="out"/>
</method>
<!--
confirm_key_with_options:
@key_id: id of the key in question
@confirmed: whether the key import is confirmed by user
@options: an array of key/value pairs to modify the call behavior
Confirm repository OpenPGP key import.
Following @options are supported:
- interactive: boolean, default true
Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
Unknown options are ignored.
-->
<method name="confirm_key_with_options">
<arg name="key_id" type="s" direction="in"/>
<arg name="confirmed" type="b" direction="in"/>
<arg name="options" type="a{sv}" direction="in" />
</method>
<!--
confirm_key:
@key_id: id of the key in question
@confirmed: whether the key import is confirmed by user
Confirm repository OpenPGP key import.
This is equivalent to call "confirm_key_with_options()" with empty options.
-->
<method name="confirm_key">
<arg name="key_id" type="s" direction="in"/>
<arg name="confirmed" type="b" direction="in"/>
</method>
<!--
enable_with_options:
@repo_ids: array of strings containing all repo ids to be enabled
@options: an array of key/value pairs to modify the call behavior
Enable repositories based on the list of given ids.
Following @options are supported:
- interactive: boolean, default true
Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
Unknown options are ignored.
-->
<method name="enable_with_options">
<arg name="repo_ids" type="as" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
<!--
enable:
@repo_ids: array of strings containing all repo ids to be enabled
Enable repositories based on the list of given ids.
This is equivalent to call "enable_with_options()" with empty options.
-->
<method name="enable">
<arg name="repo_ids" type="as" direction="in"/>
</method>
<!--
disable_with_options:
@repo_ids: array of strings containing all repo ids to be disabled
@options: an array of key/value pairs to modify the call behavior
Disable repositories based on the list of given ids.
Following @options are supported:
- interactive: boolean, default true
Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
Unknown options are ignored.
-->
<method name="disable_with_options">
<arg name="repo_ids" type="as" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
<!--
disable:
@repo_ids: array of strings containing all repo ids to be disabled
Disable repositories based on the list of given ids.
This is equivalent to call "disable_with_options()" with empty options.
-->
<method name="disable">
<arg name="repo_ids" type="as" direction="in"/>

View File

@ -223,6 +223,8 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
- mode: string (one of "distrosync", "upgrade", default is "distrosync")
By default the system_upgrade behaves like `dnf distro-sync`, always installing packages from the new release, even if they are older than the currently installed version. If set to "upgrade", packages from the new release are not installed if they are older than what is currently installed (behave like `dnf upgrade`).
- interactive: boolean, default true
Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
Unknown options are ignored.
-->

View File

@ -59,6 +59,16 @@ void Base::dbus_register() {
*this, &Base::read_all_repos, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"clean_with_options"},
sdbus::Signature{"sa{sv}"},
{"cache_type", "options"},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Base::clean_with_options, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"clean"},
sdbus::Signature{"s"},
@ -110,6 +120,16 @@ void Base::dbus_register() {
dnfdaemon::INTERFACE_BASE, "read_all_repos", "", {}, "b", {"success"}, [this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Base::read_all_repos, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_BASE,
"clean_with_options",
"sa{sv}",
{"cache_type", "options"},
"bs",
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Base::clean_with_options, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_BASE,
"clean",
@ -166,13 +186,14 @@ sdbus::MethodReply Base::read_all_repos(sdbus::MethodCall & call) {
return reply;
}
sdbus::MethodReply Base::clean(sdbus::MethodCall & call) {
// let the "expire-cache" do anyone, just as read_all_repos()
std::string cache_type{};
call >> cache_type;
sdbus::MethodReply Base::impl_clean(sdbus::MethodCall & call,
const std::string & cache_type,
const dnfdaemon::KeyValueMap & options) {
bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
// let the "expire-cache" do anyone, just as read_all_repos()
if (cache_type != "expire-cache" &&
!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRUSTED_TRANSACTION, call.getSender())) {
!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRUSTED_TRANSACTION, call.getSender(), interactive)) {
throw std::runtime_error("Not authorized");
}
@ -223,6 +244,22 @@ sdbus::MethodReply Base::clean(sdbus::MethodCall & call) {
return reply;
}
sdbus::MethodReply Base::clean_with_options(sdbus::MethodCall & call) {
std::string cache_type{};
dnfdaemon::KeyValueMap options;
call >> cache_type >> options;
return impl_clean(call, cache_type, options);
}
sdbus::MethodReply Base::clean(sdbus::MethodCall & call) {
std::string cache_type{};
dnfdaemon::KeyValueMap options{};
call >> cache_type;
return impl_clean(call, cache_type, options);
}
sdbus::MethodReply Base::reset(sdbus::MethodCall & call) {
bool success{true};
std::string error_msg{};

View File

@ -35,6 +35,9 @@ public:
void dbus_deregister();
private:
sdbus::MethodReply impl_clean(sdbus::MethodCall & call, const std::string & cache_type,
const dnfdaemon::KeyValueMap & options);
sdbus::MethodReply clean_with_options(sdbus::MethodCall & call);
sdbus::MethodReply clean(sdbus::MethodCall & call);
sdbus::MethodReply reset(sdbus::MethodCall & call);
sdbus::MethodReply read_all_repos(sdbus::MethodCall & call);

View File

@ -374,10 +374,14 @@ bool is_transaction_trusted(libdnf5::base::Transaction * transaction) {
sdbus::MethodReply Goal::do_transaction(sdbus::MethodCall & call) {
transaction_resolved_assert();
auto * transaction = session.get_transaction();
// read options from dbus call
dnfdaemon::KeyValueMap options;
call >> options;
bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
if (!session.check_authorization(
is_transaction_trusted(transaction) ? dnfdaemon::POLKIT_EXECUTE_RPM_TRUSTED_TRANSACTION
: dnfdaemon::POLKIT_EXECUTE_RPM_TRANSACTION,
call.getSender())) {
call.getSender(), interactive)) {
throw std::runtime_error("Not authorized");
}
@ -390,10 +394,6 @@ sdbus::MethodReply Goal::do_transaction(sdbus::MethodCall & call) {
session.set_cancel_download(Session::CancelDownload::NOT_REQUESTED);
// read options from dbus call
dnfdaemon::KeyValueMap options;
call >> options;
bool offline = dnfdaemon::key_value_map_get<bool>(options, "offline", false);
if (offline) {

View File

@ -55,6 +55,16 @@ void Offline::dbus_register() {
#ifdef SDBUS_CPP_VERSION_2
dbus_object
->addVTable(
sdbus::MethodVTableItem{
sdbus::MethodName{"cancel_with_options"},
sdbus::Signature{"a{sv}"},
{"options"},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Offline::cancel_with_options, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"cancel"},
{},
@ -76,6 +86,16 @@ void Offline::dbus_register() {
*this, &Offline::get_status, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"clean_with_options"},
sdbus::Signature{"a{sv}"},
{"options"},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Offline::clean_with_options, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"clean"},
{},
@ -86,6 +106,17 @@ void Offline::dbus_register() {
session.get_threads_manager().handle_method(*this, &Offline::clean, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"set_finish_action_with_options"},
sdbus::Signature{"sa{sv}"},
{"action", "options"},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(
*this, &Offline::set_finish_action_with_options, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"set_finish_action"},
sdbus::Signature{"s"},
@ -99,6 +130,16 @@ void Offline::dbus_register() {
{}})
.forInterface(dnfdaemon::INTERFACE_OFFLINE);
#else
dbus_object->registerMethod(
dnfdaemon::INTERFACE_OFFLINE,
"cancel_with_options",
{"a{sv}"},
{"options"},
"bs",
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Offline::cancel_with_options, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_OFFLINE,
"cancel",
@ -119,6 +160,16 @@ void Offline::dbus_register() {
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Offline::get_status, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_OFFLINE,
"clean_with_options",
{"a{sv}"},
{"options"},
"bs",
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Offline::clean_with_options, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_OFFLINE,
"clean",
@ -129,6 +180,17 @@ void Offline::dbus_register() {
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Offline::clean, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_OFFLINE,
"set_finish_action_with_options",
"sa{sv}",
{"action", "options"},
"bs",
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(
*this, &Offline::set_finish_action_with_options, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_OFFLINE,
"set_finish_action",
@ -167,8 +229,9 @@ sdbus::MethodReply Offline::get_status(sdbus::MethodCall & call) {
return reply;
}
sdbus::MethodReply Offline::cancel(sdbus::MethodCall & call) {
if (!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRUSTED_TRANSACTION, call.getSender())) {
sdbus::MethodReply Offline::impl_cancel(sdbus::MethodCall & call, const dnfdaemon::KeyValueMap & options) {
bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
if (!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRUSTED_TRANSACTION, call.getSender(), interactive)) {
throw std::runtime_error("Not authorized");
}
bool success = true;
@ -194,8 +257,20 @@ sdbus::MethodReply Offline::cancel(sdbus::MethodCall & call) {
return reply;
}
sdbus::MethodReply Offline::clean(sdbus::MethodCall & call) {
if (!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRUSTED_TRANSACTION, call.getSender())) {
sdbus::MethodReply Offline::cancel_with_options(sdbus::MethodCall & call) {
dnfdaemon::KeyValueMap options;
call >> options;
return impl_cancel(call, options);
}
sdbus::MethodReply Offline::cancel(sdbus::MethodCall & call) {
dnfdaemon::KeyValueMap options{};
return impl_cancel(call, options);
}
sdbus::MethodReply Offline::impl_clean(sdbus::MethodCall & call, const dnfdaemon::KeyValueMap & options) {
bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
if (!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRUSTED_TRANSACTION, call.getSender(), interactive)) {
throw std::runtime_error("Not authorized");
}
std::vector<std::string> error_msgs;
@ -223,19 +298,30 @@ sdbus::MethodReply Offline::clean(sdbus::MethodCall & call) {
return reply;
}
sdbus::MethodReply Offline::set_finish_action(sdbus::MethodCall & call) {
if (!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRUSTED_TRANSACTION, call.getSender())) {
sdbus::MethodReply Offline::clean_with_options(sdbus::MethodCall & call) {
dnfdaemon::KeyValueMap options;
call >> options;
return impl_clean(call, options);
}
sdbus::MethodReply Offline::clean(sdbus::MethodCall & call) {
dnfdaemon::KeyValueMap options{};
return impl_clean(call, options);
}
sdbus::MethodReply Offline::impl_set_finish_action(sdbus::MethodCall & call, const std::string & action,
const dnfdaemon::KeyValueMap & options) {
bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
if (!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRUSTED_TRANSACTION, call.getSender(), interactive)) {
throw std::runtime_error("Not authorized");
}
bool success{false};
std::string error_msg{};
std::string finish_action;
call >> finish_action;
// check finish_action validity
if (finish_action != "poweroff" && finish_action != "reboot") {
if (action != "poweroff" && action != "reboot") {
error_msg = fmt::format(
"Unsupported finish action \"{}\". Valid options are \"reboot\", or \"poweroff\".", finish_action);
"Unsupported finish action \"{}\". Valid options are \"reboot\", or \"poweroff\".", action);
} else {
const std::filesystem::path state_path{get_datadir() / libdnf5::offline::TRANSACTION_STATE_FILENAME};
std::error_code ec;
@ -248,7 +334,7 @@ sdbus::MethodReply Offline::set_finish_action(sdbus::MethodCall & call) {
const auto & read_exception = state.get_read_exception();
if (read_exception == nullptr) {
// set the poweroff_after item accordingly
state.get_data().set_poweroff_after(finish_action == "poweroff");
state.get_data().set_poweroff_after(action == "poweroff");
// write the new state
state.write();
success = true;
@ -266,3 +352,17 @@ sdbus::MethodReply Offline::set_finish_action(sdbus::MethodCall & call) {
reply << error_msg;
return reply;
}
sdbus::MethodReply Offline::set_finish_action_with_options(sdbus::MethodCall & call) {
std::string action;
dnfdaemon::KeyValueMap options;
call >> action >> options;
return impl_set_finish_action(call, action, options);
}
sdbus::MethodReply Offline::set_finish_action(sdbus::MethodCall & call) {
std::string action;
dnfdaemon::KeyValueMap options{};
call >> action;
return impl_set_finish_action(call, action, options);
}

View File

@ -34,9 +34,15 @@ public:
void dbus_deregister();
private:
sdbus::MethodReply impl_cancel(sdbus::MethodCall & call, const dnfdaemon::KeyValueMap & options);
sdbus::MethodReply cancel_with_options(sdbus::MethodCall & call);
sdbus::MethodReply cancel(sdbus::MethodCall & call);
sdbus::MethodReply impl_clean(sdbus::MethodCall & call, const dnfdaemon::KeyValueMap & options);
sdbus::MethodReply clean_with_options(sdbus::MethodCall & call);
sdbus::MethodReply clean(sdbus::MethodCall & call);
sdbus::MethodReply get_status(sdbus::MethodCall & call);
sdbus::MethodReply impl_set_finish_action(sdbus::MethodCall & call, const std::string & action, const dnfdaemon::KeyValueMap & options);
sdbus::MethodReply set_finish_action_with_options(sdbus::MethodCall & call);
sdbus::MethodReply set_finish_action(sdbus::MethodCall & call);
enum class Scheduled { NOT_SCHEDULED, ANOTHER_TOOL, SCHEDULED };

View File

@ -276,6 +276,16 @@ void Repo::dbus_register() {
session.get_threads_manager().handle_method(*this, &Repo::list, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"confirm_key_with_options"},
sdbus::Signature{"sb"},
{"key_id", "confirmed"},
sdbus::Signature{""},
{},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::confirm_key_with_options, call);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"confirm_key"},
sdbus::Signature{"sb"},
@ -286,6 +296,16 @@ void Repo::dbus_register() {
session.get_threads_manager().handle_method(*this, &Repo::confirm_key, call);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"enable_with_options"},
sdbus::Signature{"asa{sv}"},
{"repo_ids", "options"},
sdbus::Signature{""},
{},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::enable_with_options, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"enable"},
sdbus::Signature{"as"},
@ -296,6 +316,16 @@ void Repo::dbus_register() {
session.get_threads_manager().handle_method(*this, &Repo::enable, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"disable_with_options"},
sdbus::Signature{"asa{sv}"},
{"repo_ids", "options"},
sdbus::Signature{""},
{},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::disable_with_options, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"disable"},
sdbus::Signature{"as"},
@ -318,6 +348,16 @@ void Repo::dbus_register() {
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::list, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_REPO,
"confirm_key_with_options",
"sba{sv}",
{"key_id", "confirmed", "options"},
"",
{},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::confirm_key_with_options, call);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_REPO,
"confirm_key",
@ -328,10 +368,18 @@ void Repo::dbus_register() {
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::confirm_key, call);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_REPO, "enable_with_options", "asa{sv}", {"repo_ids", "options"}, "", {}, [this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::enable_with_options, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_REPO, "enable", "as", {"repo_ids"}, "", {}, [this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::enable, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_REPO, "disable_with_options", "asa{sv}", {"repo_ids", "options"}, "", {}, [this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::disable_with_options, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_REPO, "disable", "as", {"repo_ids"}, "", {}, [this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::disable, call, session.session_locale);
@ -339,12 +387,11 @@ void Repo::dbus_register() {
#endif
}
sdbus::MethodReply Repo::confirm_key(sdbus::MethodCall & call) {
std::string key_id;
bool confirmed;
call >> key_id >> confirmed;
sdbus::MethodReply Repo::impl_confirm_key(sdbus::MethodCall & call, const std::string &key_id, bool confirmed,
const dnfdaemon::KeyValueMap & options) {
bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
if (confirmed) {
if (!session.check_authorization(dnfdaemon::POLKIT_CONFIRM_KEY_IMPORT, call.getSender())) {
if (!session.check_authorization(dnfdaemon::POLKIT_CONFIRM_KEY_IMPORT, call.getSender(), interactive)) {
session.confirm_key(key_id, false);
throw std::runtime_error("Not authorized");
}
@ -353,6 +400,24 @@ sdbus::MethodReply Repo::confirm_key(sdbus::MethodCall & call) {
return call.createReply();
}
sdbus::MethodReply Repo::confirm_key_with_options(sdbus::MethodCall & call) {
std::string key_id;
bool confirmed;
dnfdaemon::KeyValueMap options{};
call >> key_id >> confirmed >> options;
return impl_confirm_key(call, key_id, confirmed, options);
}
sdbus::MethodReply Repo::confirm_key(sdbus::MethodCall & call) {
std::string key_id;
bool confirmed;
dnfdaemon::KeyValueMap options{};
call >> key_id >> confirmed;
return impl_confirm_key(call, key_id, confirmed, options);
}
sdbus::MethodReply Repo::list(sdbus::MethodCall & call) {
dnfdaemon::KeyValueMap options;
call >> options;
@ -449,11 +514,11 @@ void Repo::enable_disable_repos(const std::vector<std::string> & ids, const bool
}
}
sdbus::MethodReply Repo::enable_disable(sdbus::MethodCall && call, const bool & enable) {
sdbus::MethodReply Repo::impl_enable_disable(sdbus::MethodCall & call, bool enable, const std::vector<std::string> & ids,
const dnfdaemon::KeyValueMap & options) {
auto sender = call.getSender();
std::vector<std::string> ids;
call >> ids;
auto is_authorized = session.check_authorization(dnfdaemon::POLKIT_REPOCONF_WRITE, sender);
bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
auto is_authorized = session.check_authorization(dnfdaemon::POLKIT_REPOCONF_WRITE, sender, interactive);
if (!is_authorized) {
throw sdbus::Error(dnfdaemon::ERROR_REPOCONF, "Not authorized.");
}
@ -463,3 +528,35 @@ sdbus::MethodReply Repo::enable_disable(sdbus::MethodCall && call, const bool &
auto reply = call.createReply();
return reply;
}
sdbus::MethodReply Repo::enable_with_options(sdbus::MethodCall & call) {
std::vector<std::string> ids;
dnfdaemon::KeyValueMap options;
call >> ids >> options;
return impl_enable_disable(call, true, ids, options);
}
sdbus::MethodReply Repo::enable(sdbus::MethodCall & call) {
std::vector<std::string> ids;
dnfdaemon::KeyValueMap options{};
call >> ids;
return impl_enable_disable(call, true, ids, options);
}
sdbus::MethodReply Repo::disable_with_options(sdbus::MethodCall & call) {
std::vector<std::string> ids;
dnfdaemon::KeyValueMap options;
call >> ids >> options;
return impl_enable_disable(call, false, ids, options);
}
sdbus::MethodReply Repo::disable(sdbus::MethodCall & call) {
std::vector<std::string> ids;
dnfdaemon::KeyValueMap options{};
call >> ids;
return impl_enable_disable(call, false, ids, options);
}

View File

@ -36,10 +36,16 @@ public:
private:
sdbus::MethodReply list(sdbus::MethodCall & call);
sdbus::MethodReply impl_confirm_key(sdbus::MethodCall & call, const std::string &key_id, bool confirmed,
const dnfdaemon::KeyValueMap & options);
sdbus::MethodReply confirm_key_with_options(sdbus::MethodCall & call);
sdbus::MethodReply confirm_key(sdbus::MethodCall & call);
sdbus::MethodReply enable_disable(sdbus::MethodCall && call, const bool & enable);
sdbus::MethodReply enable(sdbus::MethodCall & call) { return enable_disable(std::move(call), true); };
sdbus::MethodReply disable(sdbus::MethodCall & call) { return enable_disable(std::move(call), false); };
sdbus::MethodReply impl_enable_disable(sdbus::MethodCall & call, bool enable, const std::vector<std::string> & ids,
const dnfdaemon::KeyValueMap & options);
sdbus::MethodReply enable_with_options(sdbus::MethodCall & call);
sdbus::MethodReply enable(sdbus::MethodCall & call);
sdbus::MethodReply disable_with_options(sdbus::MethodCall & call);
sdbus::MethodReply disable(sdbus::MethodCall & call);
void enable_disable_repos(const std::vector<std::string> & ids, const bool enable);
};

View File

@ -817,14 +817,15 @@ sdbus::MethodReply Rpm::remove(sdbus::MethodCall & call) {
}
sdbus::MethodReply Rpm::system_upgrade(sdbus::MethodCall & call) {
if (!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRANSACTION, call.getSender())) {
throw std::runtime_error("Not authorized");
}
auto base = session.get_base();
// read options from dbus call
dnfdaemon::KeyValueMap options;
call >> options;
bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
if (!session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRANSACTION, call.getSender(), interactive)) {
throw std::runtime_error("Not authorized");
}
auto base = session.get_base();
// check that releasever is different than the detected one
auto target_releasever = base->get_vars()->get_value("releasever");