mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-26 17:25:34 +03:00
polkit: on async pk requests, re-validate action/details
When we do an async pk request, let's store which action/details we used for the original request, and when we are called for the second time, let's compare. If the action/details changed, let's not allow the access to go through. (cherry picked from commit7f56982289
) (cherry picked from commit0697d0d972
)
This commit is contained in:
parent
81532beddc
commit
54791aff01
@ -155,6 +155,9 @@ int bus_test_polkit(
|
|||||||
#if ENABLE_POLKIT
|
#if ENABLE_POLKIT
|
||||||
|
|
||||||
typedef struct AsyncPolkitQuery {
|
typedef struct AsyncPolkitQuery {
|
||||||
|
char *action;
|
||||||
|
char **details;
|
||||||
|
|
||||||
sd_bus_message *request, *reply;
|
sd_bus_message *request, *reply;
|
||||||
sd_bus_message_handler_t callback;
|
sd_bus_message_handler_t callback;
|
||||||
void *userdata;
|
void *userdata;
|
||||||
@ -175,6 +178,9 @@ static void async_polkit_query_free(AsyncPolkitQuery *q) {
|
|||||||
sd_bus_message_unref(q->request);
|
sd_bus_message_unref(q->request);
|
||||||
sd_bus_message_unref(q->reply);
|
sd_bus_message_unref(q->reply);
|
||||||
|
|
||||||
|
free(q->action);
|
||||||
|
strv_free(q->details);
|
||||||
|
|
||||||
free(q);
|
free(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,11 +245,17 @@ int bus_verify_polkit_async(
|
|||||||
if (q) {
|
if (q) {
|
||||||
int authorized, challenge;
|
int authorized, challenge;
|
||||||
|
|
||||||
/* This is the second invocation of this function, and
|
/* This is the second invocation of this function, and there's already a response from
|
||||||
* there's already a response from polkit, let's
|
* polkit, let's process it */
|
||||||
* process it */
|
|
||||||
assert(q->reply);
|
assert(q->reply);
|
||||||
|
|
||||||
|
/* If the operation we want to authenticate changed between the first and the second time,
|
||||||
|
* let's not use this authentication, it might be out of date as the object and context we
|
||||||
|
* operate on might have changed. */
|
||||||
|
if (!streq(q->action, action) ||
|
||||||
|
!strv_equal(q->details, (char**) details))
|
||||||
|
return -ESTALE;
|
||||||
|
|
||||||
if (sd_bus_message_is_method_error(q->reply, NULL)) {
|
if (sd_bus_message_is_method_error(q->reply, NULL)) {
|
||||||
const sd_bus_error *e;
|
const sd_bus_error *e;
|
||||||
|
|
||||||
@ -339,6 +351,18 @@ int bus_verify_polkit_async(
|
|||||||
q->callback = callback;
|
q->callback = callback;
|
||||||
q->userdata = userdata;
|
q->userdata = userdata;
|
||||||
|
|
||||||
|
q->action = strdup(action);
|
||||||
|
if (!q->action) {
|
||||||
|
async_polkit_query_free(q);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
q->details = strv_copy((char**) details);
|
||||||
|
if (!q->details) {
|
||||||
|
async_polkit_query_free(q);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
r = hashmap_put(*registry, call, q);
|
r = hashmap_put(*registry, call, q);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
async_polkit_query_free(q);
|
async_polkit_query_free(q);
|
||||||
|
Loading…
Reference in New Issue
Block a user