/*
* c8-polkit: cont8nuum's polkit authentication agent. When an app asks
* polkit for something that needs a password (pkexec, mounting a disk,
* starting a service), polkit asks the session's agent, and this one
* shows Windows 8's User Account Control card over the dimmed screen,
* as c8-askpass does for sudo.
*
* c8-polkit [--process PID]
*
* It registers for the session it runs in (logind's display session of
* the user when it runs as a user service). --process PID registers for
* that one process instead, for testing beside another agent: only that
* process's requests come here.
*
* Requests queue and are shown one at a time. A wrong password keeps the
* card up to try again; No, Escape, or the caller giving up closes it.
* The password goes through libpolkit-agent-1, which runs polkit's own
* helper (PAM) for the chosen account.
*
* Exits 3 when it can't be the agent here (no compositor or no layer
* shell, no session, another agent registered), so c8-polkit-agent goes
* on to another one.
*/
#define _GNU_SOURCE
#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
#include <malloc.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <gio/gio.h>
#include <polkit/polkit.h>
#include <polkitagent/polkitagent.h>
#include <xkbcommon/xkbcommon-keysyms.h>
#include "pixels.h"
#include "uac.h"
#define EXIT_NOT_HERE 3
#define AGENT_PATH "/org/cont8nuum/PolicyKit1/AuthenticationAgent"
/* An account polkit will take the password of */
struct user {
PolkitIdentity *id;
uid_t uid;
char *name, *real_name;
cairo_surface_t *face;
};
struct request {
GTask *task;
char *action_id, *message, *cookie;
PolkitDetails *details;
GPtrArray *users; // struct user *
int chosen;
GSource *gave_up; // the caller cancelled
PolkitAgentSession *session;
bool asked; // the session waits for an answer
bool typed; // Yes was pressed before it asked
char *error; // what PAM last said went wrong
bool answered;
bool known;
cairo_surface_t *face; // the chosen account's, drawn by the card
struct c8ui_window *win;
struct zwlr_layer_surface_v1 *layer;
struct c8ui_widget *entry, *note, *info, *more, *yes, *ring, *name;
struct c8ui_widget *instruction;
};
static struct {
struct c8ui_app *app;
struct zwlr_layer_shell_v1 *shell;
PolkitAuthority *authority;
GHashTable *vendors; // action id -> who ships it
GQueue queue; // struct request *; the head is on screen
gpointer handle;
} P;
static void show(struct request *r);
/* Who is asking: a process's name and command line */
static char *proc_cmdline(int pid) {
gsize len = 0;
char *data = uac_proc_read(pid, "cmdline", &len);
if (data == NULL || len == 0) {
g_free(data);
return NULL;
}
for (gsize i = 0; i + 1 < len; i++) {
if (data[i] == '\0') {
data[i] = ' ';
}
}
return data;
}
static int detail_pid(struct request *r, const char *key) {
const char *v = polkit_details_lookup(r->details, key);
return v ? atoi(v) : 0;
}
/* Accounts */
static void user_free(gpointer data) {
struct user *u = data;
g_object_unref(u->id);
g_free(u->name);
g_free(u->real_name);
if (u->face) {
cairo_surface_destroy(u->face);
}
g_free(u);
}
static struct user *user_new(PolkitIdentity *id) {
if (!POLKIT_IS_UNIX_USER(id)) {
return NULL; // polkitd hands over groups' members as users
}
struct user *u = g_new0(struct user, 1);
u->id = g_object_ref(id);
u->uid = polkit_unix_user_get_uid(POLKIT_UNIX_USER(id));
struct passwd *pw = getpwuid(u->uid);
if (pw == NULL) {
u->name = g_strdup_printf("%u", (unsigned)u->uid);
u->real_name = g_strdup(u->name);
return u;
}
account_read_for(pw, &u->name, &u->real_name, &u->face, UAC_FACE * 2);
if (u->uid == 0) {
g_free(u->real_name);
u->real_name = g_strdup("Administrator");
}
return u;
}
static struct user *chosen(struct request *r) {
return g_ptr_array_index(r->users, r->chosen);
}
/* Answering polkit */
static gboolean close_later(gpointer data) {
struct request *r = data;
bool was_shown = r->win != NULL;
if (r->layer) {
zwlr_layer_surface_v1_destroy(r->layer);
}
if (r->win) {
c8ui_window_destroy(r->win);
}
bool head = g_queue_peek_head(&P.queue) == r;
g_queue_remove(&P.queue, r);
if (r->gave_up) {
g_source_destroy(r->gave_up);
g_source_unref(r->gave_up);
}
g_ptr_array_unref(r->users);
g_object_unref(r->details);
g_free(r->action_id);
g_free(r->message);
g_free(r->cookie);
g_free(r->error);
g_free(r);
struct request *next = g_queue_peek_head(&P.queue);
if ((head || was_shown) && next && next->win == NULL) {
show(next);
}
return G_SOURCE_REMOVE;
}
static gboolean unref_later(gpointer data) {
g_object_unref(data);
return G_SOURCE_REMOVE;
}
/* Done with the session: its signals no longer reach us, and it goes once
* whatever emitted from it has returned */
static void drop_session(struct request *r) {
if (r->session == NULL) {
return;
}
g_signal_handlers_disconnect_by_data(r->session, r);
polkit_agent_session_cancel(r->session);
g_idle_add(unref_later, r->session);
r->session = NULL;
r->asked = false;
}
/* error NULL: authorised. The card goes from an idle, as this may run in
* one of its own callbacks. */
static void answer(struct request *r, GError *error) {
if (r->answered) {
if (error) {
g_error_free(error);
}
return;
}
r->answered = true;
drop_session(r);
if (r->entry) {
c8ui_entry_set(r->entry, ""); // not left lying in memory
}
if (error) {
g_task_return_error(r->task, error);
} else {
g_task_return_boolean(r->task, TRUE);
}
g_object_unref(r->task);
r->task = NULL;
g_idle_add(close_later, r);
}
static void dismissed(struct request *r) {
answer(r, g_error_new_literal(POLKIT_ERROR, POLKIT_ERROR_CANCELLED,
"The user said no"));
}
static gboolean caller_gave_up(GCancellable *cancellable, gpointer data) {
struct request *r = data;
answer(r, g_error_new_literal(G_IO_ERROR, G_IO_ERROR_CANCELLED,
"The caller cancelled"));
return G_SOURCE_REMOVE;
}
/* The authentication session */
static void set_busy(struct request *r, bool busy) {
if (r->ring == NULL) {
return;
}
c8ui_widget_set_hidden(r->ring, !busy);
c8ui_ring_set_active(r->ring, busy);
c8ui_widget_set_disabled(r->entry, busy);
c8ui_widget_set_disabled(r->yes, busy);
if (!busy) {
c8ui_widget_grab_focus(r->entry);
}
}
static void respond(struct request *r) {
if (r->answered || r->entry == NULL) {
return;
}
const char *text = c8ui_entry_get(r->entry);
if (text[0] == '\0') {
return;
}
if (!r->asked) {
/* Typed before the helper asked: answered when it does */
r->typed = true;
set_busy(r, true);
return;
}
r->asked = false;
r->typed = false;
set_busy(r, true);
polkit_agent_session_response(r->session, text);
c8ui_entry_set(r->entry, "");
}
/* PAM's question, "Password: " mostly; what the box says when empty */
static void session_request(PolkitAgentSession *session, const char *ask,
gboolean echo_on, gpointer data) {
struct request *r = data;
r->asked = true;
char *hint = g_strstrip(g_strdup(ask ? ask : ""));
gsize n = strlen(hint);
while (n > 0 && (hint[n - 1] == ':' || hint[n - 1] == ' ')) {
hint[--n] = '\0';
}
c8ui_entry_set_placeholder(r->entry, n ? hint : "Password");
c8ui_entry_set_password(r->entry, !echo_on);
g_free(hint);
if (r->typed) {
/* Keep it when the box was typed in before the question came */
respond(r);
return;
}
set_busy(r, false);
}
static void session_error(PolkitAgentSession *session, const char *text,
gpointer data) {
struct request *r = data;
g_free(r->error);
r->error = g_strdup(text);
}
/* A fingerprint reader's "Place your finger", and the like */
static void session_info(PolkitAgentSession *session, const char *text,
gpointer data) {
struct request *r = data;
c8ui_label_set_text(r->info, text);
c8ui_widget_set_hidden(r->info, text == NULL || text[0] == '\0');
}
static void start_session(struct request *r);
static void session_completed(PolkitAgentSession *session,
gboolean authorised, gpointer data) {
struct request *r = data;
drop_session(r);
if (authorised) {
answer(r, NULL);
return;
}
/* Wrong (or PAM said why not): the card stays for another try */
c8ui_label_set_text(r->note, r->error && r->error[0] ? r->error :
"The password is incorrect. Try again.");
c8ui_widget_set_hidden(r->note, false);
g_clear_pointer(&r->error, g_free);
c8ui_widget_set_hidden(r->info, true);
r->typed = false;
c8ui_entry_set(r->entry, "");
set_busy(r, false);
start_session(r);
}
static void start_session(struct request *r) {
drop_session(r);
r->session = polkit_agent_session_new(chosen(r)->id, r->cookie);
g_signal_connect(r->session, "request", G_CALLBACK(session_request), r);
g_signal_connect(r->session, "show-error", G_CALLBACK(session_error), r);
g_signal_connect(r->session, "show-info", G_CALLBACK(session_info), r);
g_signal_connect(r->session, "completed", G_CALLBACK(session_completed),
r);
polkit_agent_session_initiate(r->session);
}
/* The card */
static void yes_clicked(struct c8ui_widget *w, void *data) {
respond(data);
}
static void no_clicked(struct c8ui_widget *w, void *data) {
dismissed(data);
}
static bool key(const struct c8ui_event *ev, void *data) {
switch (ev->sym) {
case XKB_KEY_Escape:
dismissed(data);
return true;
case XKB_KEY_Return:
case XKB_KEY_KP_Enter:
respond(data);
return true;
}
return false;
}
static void details_clicked(struct c8ui_widget *w, void *data) {
struct request *r = data;
c8ui_widget_set_hidden(r->more, !r->more->hidden);
}
static const char *instruction(struct request *r) {
return chosen(r)->uid == getuid() ?
"To continue, type your password, and then click Yes." :
"To continue, type an administrator password, and then click Yes.";
}
/* Another account picked: its password from now on */
static void user_picked(struct c8ui_widget *w, void *data) {
struct request *r = data;
int i = c8ui_combo_get(w);
if (i < 0 || i >= (int)r->users->len || i == r->chosen) {
return;
}
r->chosen = i;
r->face = chosen(r)->face;
c8ui_label_set_text(r->instruction, instruction(r));
c8ui_widget_set_hidden(r->note, true);
r->typed = false;
set_busy(r, false);
start_session(r);
}
static void detail(struct c8ui_widget *box, const char *name,
const char *value) {
if (value && value[0]) {
char *text = g_strdup_printf("%s: %s", name,
c8_stealth_show(value));
uac_caption(box, text);
g_free(text);
}
}
static struct c8ui_widget *build_card(struct request *r) {
struct c8ui_widget *body;
struct c8ui_widget *card = uac_card_new(&r->known,
"Do you want to allow this app to make changes to your PC?", &body);
/* What for, in polkit's words, then who and what */
if (r->message && r->message[0]) {
struct c8ui_widget *m = c8ui_label_new(c8_stealth_show(r->message),
C8UI_TEXT_BODY);
c8ui_label_set_max_lines(m, 4);
c8ui_widget_add(body, m);
}
int subject = detail_pid(r, "polkit.subject-pid");
int caller = detail_pid(r, "polkit.caller-pid");
char *comm = subject ? uac_proc_comm(subject) : NULL;
char *cmdline = subject ? proc_cmdline(subject) : NULL;
/* pkexec says what it will run, and as whom */
const char *program = polkit_details_lookup(r->details, "program");
const char *command = polkit_details_lookup(r->details, "command_line");
const char *run_as = polkit_details_lookup(r->details, "user");
uac_row(body, "Program", program ? program : comm ? comm : "an app");
uac_row(body, "Verified publisher",
g_hash_table_lookup(P.vendors, r->action_id));
uac_row(body, "Runs as", run_as);
r->more = c8ui_box_new(C8UI_VERTICAL, 4);
c8ui_widget_set_hidden(r->more, true);
c8ui_widget_add(body, r->more);
detail(r->more, "Action", r->action_id);
if (subject) {
char *who = g_strdup_printf("%s (process %d)", comm ? comm : "?",
subject);
detail(r->more, "Asked by", who);
g_free(who);
}
detail(r->more, "Command", command ? command : cmdline);
if (caller && caller != subject) {
char *via_comm = uac_proc_comm(caller);
char *via = g_strdup_printf("%s (process %d)",
via_comm ? via_comm : "?", caller);
detail(r->more, "On behalf of it", via);
g_free(via);
g_free(via_comm);
}
/* Whatever else the caller passed along */
char **keys = polkit_details_get_keys(r->details);
for (int i = 0; keys && keys[i]; i++) {
if (!g_str_has_prefix(keys[i], "polkit.") &&
strcmp(keys[i], "program") != 0 &&
strcmp(keys[i], "command_line") != 0 &&
strcmp(keys[i], "user") != 0) {
detail(r->more, keys[i],
polkit_details_lookup(r->details, keys[i]));
}
}
g_strfreev(keys);
g_free(comm);
g_free(cmdline);
c8ui_widget_add(body, c8ui_spacer_new(0, 8));
r->note = c8ui_label_new("", C8UI_TEXT_BODY_STRONG);
c8ui_label_set_max_lines(r->note, 3);
c8ui_widget_set_hidden(r->note, true);
c8ui_widget_add(body, r->note);
r->instruction = c8ui_label_new(instruction(r), C8UI_TEXT_BODY);
c8ui_label_set_max_lines(r->instruction, 2);
c8ui_widget_add(body, r->instruction);
struct c8ui_widget *who_row = c8ui_box_new(C8UI_HORIZONTAL, 16);
who_row->fill = true;
c8ui_widget_add(body, who_row);
c8ui_widget_add(who_row, c8ui_canvas_new(UAC_FACE, UAC_FACE,
uac_draw_face, NULL, &r->face));
struct c8ui_widget *col = c8ui_box_new(C8UI_VERTICAL, 6);
col->expand = true;
c8ui_widget_add(who_row, col);
if (r->users->len > 1) {
/* polkit takes any of these (the admin group's members) */
const char **names = g_new0(const char *, r->users->len);
char **owned = g_new0(char *, r->users->len + 1);
for (guint i = 0; i < r->users->len; i++) {
struct user *u = g_ptr_array_index(r->users, i);
/* Stealth mode: our login shows as the persona's */
const char *login = u->uid == getuid() ?
c8_stealth_show(u->name) : u->name;
owned[i] = strcmp(u->real_name, login) == 0 ?
g_strdup(login) :
g_strdup_printf("%s (%s)", u->real_name, login);
names[i] = owned[i];
}
r->name = c8ui_combo_new(NULL, names, r->users->len, r->chosen,
user_picked, r);
g_free(names);
g_strfreev(owned);
} else {
r->name = c8ui_label_new(chosen(r)->real_name, C8UI_TEXT_BODY_STRONG);
}
r->name->fill = true;
c8ui_widget_add(col, r->name);
r->entry = c8ui_entry_new(NULL, "", yes_clicked, r);
c8ui_entry_set_enter_only(r->entry, true); // not focus leaving
c8ui_entry_set_password(r->entry, true);
c8ui_entry_set_placeholder(r->entry, "Password");
r->entry->fill = true;
c8ui_widget_add(col, r->entry);
r->info = c8ui_label_new("", C8UI_TEXT_CAPTION);
c8ui_label_set_max_lines(r->info, 3);
c8ui_widget_set_hidden(r->info, true);
c8ui_widget_add(col, r->info);
r->ring = c8ui_ring_new(24);
r->ring->align = C8UI_ALIGN_CENTER;
c8ui_widget_set_hidden(r->ring, true);
c8ui_widget_add(who_row, r->ring);
uac_footer(card, "Yes", details_clicked, yes_clicked, no_clicked, r,
&r->yes);
return card;
}
static void layer_closed(void *data, struct zwlr_layer_surface_v1 *layer) {
/* The screen went: nobody can answer this one */
struct request *r = g_queue_peek_head(&P.queue);
if (r && r->layer == layer) {
dismissed(r);
}
}
static const struct zwlr_layer_surface_v1_listener layer_listener = {
.configure = uac_layer_configure,
.closed = layer_closed,
};
static void show(struct request *r) {
r->win = c8ui_window_new_bare(P.app);
r->layer = uac_overlay_new(P.shell, r->win, "c8-polkit", &layer_listener);
struct c8ui_widget *card = build_card(r);
struct c8ui_root *root = c8ui_window_root(r->win);
c8ui_root_set_child(root, uac_cover(card));
c8ui_root_set_key_handler(root, key, r);
c8ui_widget_grab_focus(r->entry);
c8ui_widget_enter(card);
start_session(r);
}
/* The listener polkit calls */
typedef struct {
PolkitAgentListener parent;
} C8Listener;
typedef struct {
PolkitAgentListenerClass parent_class;
} C8ListenerClass;
G_DEFINE_TYPE(C8Listener, c8_listener, POLKIT_AGENT_TYPE_LISTENER)
static void initiate(PolkitAgentListener *listener, const gchar *action_id,
const gchar *message, const gchar *icon_name, PolkitDetails *details,
const gchar *cookie, GList *identities, GCancellable *cancellable,
GAsyncReadyCallback callback, gpointer user_data) {
struct request *r = g_new0(struct request, 1);
r->task = g_task_new(listener, NULL, callback, user_data);
r->action_id = g_strdup(action_id);
r->message = g_strdup(message);
r->cookie = g_strdup(cookie);
r->details = details ? g_object_ref(details) : polkit_details_new();
r->known = true; // polkit's actions are the system's own
r->users = g_ptr_array_new_with_free_func(user_free);
int me = -1, root = -1;
for (GList *l = identities; l; l = l->next) {
struct user *u = user_new(l->data);
if (u == NULL) {
continue;
}
if (u->uid == getuid() && me < 0) {
me = r->users->len;
}
if (u->uid == 0 && root < 0) {
root = r->users->len;
}
g_ptr_array_add(r->users, u);
}
if (r->users->len == 0) {
g_task_return_new_error(r->task, POLKIT_ERROR, POLKIT_ERROR_FAILED,
"No account to ask the password of");
g_object_unref(r->task);
r->task = NULL;
r->answered = true;
g_queue_push_tail(&P.queue, r);
g_idle_add(close_later, r);
return;
}
/* Our own password when it will do, else the administrator's */
r->chosen = me >= 0 ? me : root >= 0 ? root : 0;
r->face = chosen(r)->face;
if (cancellable) {
r->gave_up = g_cancellable_source_new(cancellable);
g_source_set_callback(r->gave_up,
(GSourceFunc)(void (*)(void))caller_gave_up, r, NULL);
g_source_attach(r->gave_up, NULL);
}
g_queue_push_tail(&P.queue, r);
if (g_queue_get_length(&P.queue) == 1) {
show(r);
}
}
static gboolean initiate_finish(PolkitAgentListener *listener,
GAsyncResult *res, GError **error) {
return g_task_propagate_boolean(G_TASK(res), error);
}
static void c8_listener_init(C8Listener *self) {
}
static void c8_listener_class_init(C8ListenerClass *klass) {
PolkitAgentListenerClass *lk = POLKIT_AGENT_LISTENER_CLASS(klass);
lk->initiate_authentication = initiate;
lk->initiate_authentication_finish = initiate_finish;
}
/* Who ships each action, as UAC named the verified publisher */
static void got_actions(GObject *src, GAsyncResult *res, gpointer data) {
GList *actions = polkit_authority_enumerate_actions_finish(
POLKIT_AUTHORITY(src), res, NULL);
g_hash_table_remove_all(P.vendors);
for (GList *l = actions; l; l = l->next) {
PolkitActionDescription *a = l->data;
const char *vendor = polkit_action_description_get_vendor_name(a);
if (vendor && vendor[0]) {
g_hash_table_insert(P.vendors,
g_strdup(polkit_action_description_get_action_id(a)),
g_strdup(vendor));
}
}
g_list_free_full(actions, g_object_unref);
/* Hundreds of actions with all their texts came and went: what they
* took is given back, as this sits idle for days */
malloc_trim(0);
}
static void read_actions(void) {
polkit_authority_enumerate_actions(P.authority, NULL, got_actions, NULL);
}
static void authority_changed(PolkitAuthority *authority, gpointer data) {
read_actions();
}
/* The session to be the agent of: ours, or as a user service (not in a
* session itself) logind's display session of this user */
static PolkitSubject *session_subject(GError **error) {
PolkitSubject *s = polkit_unix_session_new_for_process_sync(getpid(),
NULL, NULL);
if (s) {
return s;
}
GDBusConnection *bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
if (bus == NULL) {
return NULL;
}
GVariant *ret = g_dbus_connection_call_sync(bus, "org.freedesktop.login1",
"/org/freedesktop/login1", "org.freedesktop.login1.Manager", "GetUser",
g_variant_new("(u)", (guint32)getuid()), G_VARIANT_TYPE("(o)"),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
char *path = NULL;
if (ret) {
g_variant_get(ret, "(o)", &path);
g_variant_unref(ret);
ret = g_dbus_connection_call_sync(bus, "org.freedesktop.login1", path,
"org.freedesktop.DBus.Properties", "Get",
g_variant_new("(ss)", "org.freedesktop.login1.User", "Display"),
G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
}
char *id = NULL;
if (ret) {
GVariant *v;
g_variant_get(ret, "(v)", &v);
g_variant_get(v, "(so)", &id, NULL);
g_variant_unref(v);
g_variant_unref(ret);
}
g_free(path);
g_object_unref(bus);
if (id && id[0] == '\0') {
g_clear_pointer(&id, g_free);
/* Logged in on a text console only */
const char *env = getenv("XDG_SESSION_ID");
if (env && env[0]) {
id = g_strdup(env);
} else if (error && *error == NULL) {
g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"no graphical session of this user");
}
}
if (id == NULL) {
return NULL;
}
s = polkit_unix_session_new(id);
g_free(id);
return s;
}
int main(int argc, char *argv[]) {
int process = 0;
if (argc == 3 && strcmp(argv[1], "--process") == 0) {
process = atoi(argv[2]);
} else if (argc != 1) {
fprintf(stderr, "usage: c8-polkit [--process PID]\n");
return 2;
}
P.app = c8ui_app_new("org.cont8nuum.PolicyKit");
if (P.app == NULL) {
fprintf(stderr, "c8-polkit: can't reach the compositor\n");
return EXIT_NOT_HERE;
}
P.shell = c8ui_app_bind(P.app, &zwlr_layer_shell_v1_interface, 4);
if (P.shell == NULL) {
fprintf(stderr, "c8-polkit: the compositor has no layer shell\n");
return EXIT_NOT_HERE;
}
GError *error = NULL;
P.authority = polkit_authority_get_sync(NULL, &error);
if (P.authority == NULL) {
fprintf(stderr, "c8-polkit: no polkit: %s\n", error->message);
return EXIT_NOT_HERE;
}
P.vendors = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
g_signal_connect(P.authority, "changed", G_CALLBACK(authority_changed),
NULL);
read_actions();
PolkitSubject *subject = process ?
polkit_unix_process_new_for_owner(process, 0, -1) :
session_subject(&error);
if (subject == NULL) {
fprintf(stderr, "c8-polkit: no session to be the agent of: %s\n",
error ? error->message : "?");
return EXIT_NOT_HERE;
}
PolkitAgentListener *listener = g_object_new(c8_listener_get_type(), NULL);
P.handle = polkit_agent_listener_register(listener,
POLKIT_AGENT_REGISTER_FLAGS_NONE, subject, AGENT_PATH, NULL, &error);
if (P.handle == NULL) {
fprintf(stderr, "c8-polkit: can't be the agent: %s\n",
error->message);
return EXIT_NOT_HERE;
}
char *what = polkit_subject_to_string(subject);
fprintf(stderr, "c8-polkit: the agent of %s\n", what);
g_free(what);
g_object_unref(subject);
c8ui_app_hold(P.app); // no windows most of the time
int status = c8ui_app_run(P.app);
polkit_agent_listener_unregister(P.handle);
g_object_unref(listener);
return status;
}