-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdactylogramme.c
63 lines (47 loc) · 1.44 KB
/
dactylogramme.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#define _GNU_SOURCE
#include <stdlib.h>
#include <systemd/sd-bus.h>
static int begin_authentication(sd_bus_message *m, void *userdata, sd_bus_error *error) {
const char *cookie;
int p[2];
sd_bus_message_skip(m, "sssa{ss}");
sd_bus_message_read(m, "s", &cookie);
pipe(p);
if (!fork()) {
dup2(p[0], STDIN_FILENO);
close(p[0]);
close(p[1]);
execlp("polkit-agent-helper-1", "polkit-agent-helper-1", getenv("USER"), NULL);
_exit(EXIT_FAILURE);
}
dprintf(p[1], "%s\n", cookie);
close(p[0]);
close(p[1]);
wait(NULL);
return sd_bus_reply_method_return(m, NULL);
}
int main() {
sd_bus *bus;
sd_bus_open_system(&bus);
sd_bus_add_object_vtable(bus,
NULL,
"/org/freedesktop/PolicyKit1/AuthenticationAgent",
"org.freedesktop.PolicyKit1.AuthenticationAgent",
(sd_bus_vtable[]){ SD_BUS_VTABLE_START(0), SD_BUS_METHOD("BeginAuthentication", "sssa{ss}sa(sa{sv})", "", begin_authentication, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END },
NULL);
sd_bus_call_method(bus,
"org.freedesktop.PolicyKit1",
"/org/freedesktop/PolicyKit1/Authority",
"org.freedesktop.PolicyKit1.Authority",
"RegisterAuthenticationAgent",
NULL,
NULL,
"(sa{sv})ss",
"unix-session", 1, "session-id", "s", getenv("XDG_SESSION_ID"),
NULL /* locale */,
"/org/freedesktop/PolicyKit1/AuthenticationAgent");
for (;;) {
sd_bus_wait(bus, -1);
sd_bus_process(bus, NULL);
}
}