File: | build-scan/../src/login/logind-dbus.c |
Warning: | line 946, column 13 Access to field 'seat' results in a dereference of an undefined pointer value (loaded from variable 'session') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
2 | ||||
3 | #include <errno(*__errno_location ()).h> | |||
4 | #include <pwd.h> | |||
5 | #include <string.h> | |||
6 | #include <unistd.h> | |||
7 | ||||
8 | #include "sd-messages.h" | |||
9 | ||||
10 | #include "alloc-util.h" | |||
11 | #include "audit-util.h" | |||
12 | #include "bus-common-errors.h" | |||
13 | #include "bus-error.h" | |||
14 | #include "bus-unit-util.h" | |||
15 | #include "bus-util.h" | |||
16 | #include "dirent-util.h" | |||
17 | #include "efivars.h" | |||
18 | #include "escape.h" | |||
19 | #include "fd-util.h" | |||
20 | #include "fileio-label.h" | |||
21 | #include "format-util.h" | |||
22 | #include "fs-util.h" | |||
23 | #include "logind.h" | |||
24 | #include "mkdir.h" | |||
25 | #include "path-util.h" | |||
26 | #include "process-util.h" | |||
27 | #include "cgroup-util.h" | |||
28 | #include "selinux-util.h" | |||
29 | #include "sleep-config.h" | |||
30 | #include "special.h" | |||
31 | #include "strv.h" | |||
32 | #include "terminal-util.h" | |||
33 | #include "udev-util.h" | |||
34 | #include "unit-name.h" | |||
35 | #include "user-util.h" | |||
36 | #include "utmp-wtmp.h" | |||
37 | ||||
38 | static int get_sender_session(Manager *m, sd_bus_message *message, sd_bus_error *error, Session **ret) { | |||
39 | ||||
40 | _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0); | |||
41 | const char *name; | |||
42 | Session *session; | |||
43 | int r; | |||
44 | ||||
45 | /* Get client login session. This is not what you are looking for these days, | |||
46 | * as apps may instead belong to a user service unit. This includes terminal | |||
47 | * emulators and hence command-line apps. */ | |||
48 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_SESSION|SD_BUS_CREDS_AUGMENT, &creds); | |||
49 | if (r < 0) | |||
50 | return r; | |||
51 | ||||
52 | r = sd_bus_creds_get_session(creds, &name); | |||
53 | if (r == -ENXIO6) | |||
54 | goto err_no_session; | |||
55 | if (r < 0) | |||
56 | return r; | |||
57 | ||||
58 | session = hashmap_get(m->sessions, name); | |||
59 | if (!session) | |||
60 | goto err_no_session; | |||
61 | ||||
62 | *ret = session; | |||
63 | return 0; | |||
64 | ||||
65 | err_no_session: | |||
66 | return sd_bus_error_setf(error, BUS_ERROR_NO_SESSION_FOR_PID"org.freedesktop.login1.NoSessionForPID", | |||
67 | "Caller does not belong to any known session"); | |||
68 | } | |||
69 | ||||
70 | int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) { | |||
71 | Session *session; | |||
72 | ||||
73 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 73, __PRETTY_FUNCTION__ ); } while (0); | |||
74 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 74, __PRETTY_FUNCTION__); } while (0); | |||
75 | assert(ret)do { if ((__builtin_expect(!!(!(ret)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret"), "../src/login/logind-dbus.c", 75 , __PRETTY_FUNCTION__); } while (0); | |||
76 | ||||
77 | if (isempty(name)) | |||
78 | return get_sender_session(m, message, error, ret); | |||
79 | ||||
80 | session = hashmap_get(m->sessions, name); | |||
81 | if (!session) | |||
82 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION"org.freedesktop.login1.NoSuchSession", "No session '%s' known", name); | |||
83 | ||||
84 | *ret = session; | |||
85 | return 0; | |||
86 | } | |||
87 | ||||
88 | static int get_sender_user(Manager *m, sd_bus_message *message, sd_bus_error *error, User **ret) { | |||
89 | ||||
90 | _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0); | |||
91 | uid_t uid; | |||
92 | User *user; | |||
93 | int r; | |||
94 | ||||
95 | /* Note that we get the owner UID of the session, not the actual client UID here! */ | |||
96 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_OWNER_UID|SD_BUS_CREDS_AUGMENT, &creds); | |||
97 | if (r < 0) | |||
98 | return r; | |||
99 | ||||
100 | r = sd_bus_creds_get_owner_uid(creds, &uid); | |||
101 | if (r == -ENXIO6) | |||
102 | goto err_no_user; | |||
103 | if (r < 0) | |||
104 | return r; | |||
105 | ||||
106 | user = hashmap_get(m->users, UID_TO_PTR(uid)((void*) (((uintptr_t) (uid))+1))); | |||
107 | if (!user) | |||
108 | goto err_no_user; | |||
109 | ||||
110 | *ret = user; | |||
111 | return 0; | |||
112 | ||||
113 | err_no_user: | |||
114 | return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID"org.freedesktop.login1.NoUserForPID", "Caller does not belong to any logged in user or lingering user"); | |||
115 | } | |||
116 | ||||
117 | int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret) { | |||
118 | User *user; | |||
119 | ||||
120 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 120, __PRETTY_FUNCTION__); } while (0); | |||
121 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 121, __PRETTY_FUNCTION__); } while (0); | |||
122 | assert(ret)do { if ((__builtin_expect(!!(!(ret)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret"), "../src/login/logind-dbus.c", 122 , __PRETTY_FUNCTION__); } while (0); | |||
123 | ||||
124 | if (!uid_is_valid(uid)) | |||
125 | return get_sender_user(m, message, error, ret); | |||
126 | ||||
127 | user = hashmap_get(m->users, UID_TO_PTR(uid)((void*) (((uintptr_t) (uid))+1))); | |||
128 | if (!user) | |||
129 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER"org.freedesktop.login1.NoSuchUser", "User ID "UID_FMT"%" "u"" is not logged in or lingering", uid); | |||
130 | ||||
131 | *ret = user; | |||
132 | return 0; | |||
133 | } | |||
134 | ||||
135 | int manager_get_seat_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Seat **ret) { | |||
136 | Seat *seat; | |||
137 | int r; | |||
138 | ||||
139 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 139, __PRETTY_FUNCTION__); } while (0); | |||
140 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 140, __PRETTY_FUNCTION__); } while (0); | |||
141 | assert(ret)do { if ((__builtin_expect(!!(!(ret)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret"), "../src/login/logind-dbus.c", 141 , __PRETTY_FUNCTION__); } while (0); | |||
142 | ||||
143 | if (isempty(name)) { | |||
144 | Session *session; | |||
145 | ||||
146 | r = manager_get_session_from_creds(m, message, NULL((void*)0), error, &session); | |||
147 | if (r < 0) | |||
148 | return r; | |||
149 | ||||
150 | seat = session->seat; | |||
151 | if (!seat) | |||
152 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SEAT"org.freedesktop.login1.NoSuchSeat", "Session has no seat."); | |||
153 | } else { | |||
154 | seat = hashmap_get(m->seats, name); | |||
155 | if (!seat) | |||
156 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SEAT"org.freedesktop.login1.NoSuchSeat", "No seat '%s' known", name); | |||
157 | } | |||
158 | ||||
159 | *ret = seat; | |||
160 | return 0; | |||
161 | } | |||
162 | ||||
163 | static int property_get_idle_hint( | |||
164 | sd_bus *bus, | |||
165 | const char *path, | |||
166 | const char *interface, | |||
167 | const char *property, | |||
168 | sd_bus_message *reply, | |||
169 | void *userdata, | |||
170 | sd_bus_error *error) { | |||
171 | ||||
172 | Manager *m = userdata; | |||
173 | ||||
174 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/login/logind-dbus.c", 174 , __PRETTY_FUNCTION__); } while (0); | |||
175 | assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 175 , __PRETTY_FUNCTION__); } while (0); | |||
176 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 176, __PRETTY_FUNCTION__); } while (0); | |||
177 | ||||
178 | return sd_bus_message_append(reply, "b", manager_get_idle_hint(m, NULL((void*)0)) > 0); | |||
179 | } | |||
180 | ||||
181 | static int property_get_idle_since_hint( | |||
182 | sd_bus *bus, | |||
183 | const char *path, | |||
184 | const char *interface, | |||
185 | const char *property, | |||
186 | sd_bus_message *reply, | |||
187 | void *userdata, | |||
188 | sd_bus_error *error) { | |||
189 | ||||
190 | Manager *m = userdata; | |||
191 | dual_timestamp t = DUAL_TIMESTAMP_NULL((struct dual_timestamp) {}); | |||
192 | ||||
193 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/login/logind-dbus.c", 193 , __PRETTY_FUNCTION__); } while (0); | |||
194 | assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 194 , __PRETTY_FUNCTION__); } while (0); | |||
195 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 195, __PRETTY_FUNCTION__); } while (0); | |||
196 | ||||
197 | manager_get_idle_hint(m, &t); | |||
198 | ||||
199 | return sd_bus_message_append(reply, "t", streq(property, "IdleSinceHint")(strcmp((property),("IdleSinceHint")) == 0) ? t.realtime : t.monotonic); | |||
200 | } | |||
201 | ||||
202 | static int property_get_inhibited( | |||
203 | sd_bus *bus, | |||
204 | const char *path, | |||
205 | const char *interface, | |||
206 | const char *property, | |||
207 | sd_bus_message *reply, | |||
208 | void *userdata, | |||
209 | sd_bus_error *error) { | |||
210 | ||||
211 | Manager *m = userdata; | |||
212 | InhibitWhat w; | |||
213 | ||||
214 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/login/logind-dbus.c", 214 , __PRETTY_FUNCTION__); } while (0); | |||
215 | assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 215 , __PRETTY_FUNCTION__); } while (0); | |||
216 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 216, __PRETTY_FUNCTION__); } while (0); | |||
217 | ||||
218 | w = manager_inhibit_what(m, streq(property, "BlockInhibited")(strcmp((property),("BlockInhibited")) == 0) ? INHIBIT_BLOCK : INHIBIT_DELAY); | |||
219 | ||||
220 | return sd_bus_message_append(reply, "s", inhibit_what_to_string(w)); | |||
221 | } | |||
222 | ||||
223 | static int property_get_preparing( | |||
224 | sd_bus *bus, | |||
225 | const char *path, | |||
226 | const char *interface, | |||
227 | const char *property, | |||
228 | sd_bus_message *reply, | |||
229 | void *userdata, | |||
230 | sd_bus_error *error) { | |||
231 | ||||
232 | Manager *m = userdata; | |||
233 | bool_Bool b; | |||
234 | ||||
235 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/login/logind-dbus.c", 235 , __PRETTY_FUNCTION__); } while (0); | |||
236 | assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 236 , __PRETTY_FUNCTION__); } while (0); | |||
237 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 237, __PRETTY_FUNCTION__); } while (0); | |||
238 | ||||
239 | if (streq(property, "PreparingForShutdown")(strcmp((property),("PreparingForShutdown")) == 0)) | |||
240 | b = m->action_what & INHIBIT_SHUTDOWN; | |||
241 | else | |||
242 | b = m->action_what & INHIBIT_SLEEP; | |||
243 | ||||
244 | return sd_bus_message_append(reply, "b", b); | |||
245 | } | |||
246 | ||||
247 | static int property_get_scheduled_shutdown( | |||
248 | sd_bus *bus, | |||
249 | const char *path, | |||
250 | const char *interface, | |||
251 | const char *property, | |||
252 | sd_bus_message *reply, | |||
253 | void *userdata, | |||
254 | sd_bus_error *error) { | |||
255 | ||||
256 | Manager *m = userdata; | |||
257 | int r; | |||
258 | ||||
259 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/login/logind-dbus.c", 259 , __PRETTY_FUNCTION__); } while (0); | |||
260 | assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 260 , __PRETTY_FUNCTION__); } while (0); | |||
261 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 261, __PRETTY_FUNCTION__); } while (0); | |||
262 | ||||
263 | r = sd_bus_message_open_container(reply, 'r', "st"); | |||
264 | if (r < 0) | |||
265 | return r; | |||
266 | ||||
267 | r = sd_bus_message_append(reply, "st", m->scheduled_shutdown_type, m->scheduled_shutdown_timeout); | |||
268 | if (r < 0) | |||
269 | return r; | |||
270 | ||||
271 | return sd_bus_message_close_container(reply); | |||
272 | } | |||
273 | ||||
274 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_handle_action, handle_action, HandleAction)int property_get_handle_action(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message * reply, void *userdata, sd_bus_error *error) { HandleAction *data = userdata; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/login/logind-dbus.c", 274 , __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 274, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/login/logind-dbus.c", 274 , __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append (reply, "s", handle_action_to_string((*(data)))); }; | |||
275 | static BUS_DEFINE_PROPERTY_GET(property_get_docked, "b", Manager, manager_is_docked_or_external_displays)int property_get_docked(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) { Manager *data = userdata; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/login/logind-dbus.c", 275 , __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 275, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/login/logind-dbus.c", 275 , __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append (reply, "b", (manager_is_docked_or_external_displays(data))); }; | |||
276 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_compat_user_tasks_max, "t", CGROUP_LIMIT_MAX)int property_get_compat_user_tasks_max(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) { do { if ((__builtin_expect (!!(!(bus)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "bus"), "../src/login/logind-dbus.c", 276, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 276 , __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append (reply, "t", ((uint64_t) -1)); }; | |||
277 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_hashmap_size, "t", Hashmap *, (uint64_t) hashmap_size)int property_get_hashmap_size(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply , void *userdata, sd_bus_error *error) { Hashmap * *data = userdata ; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/login/logind-dbus.c", 277 , __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 277, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/login/logind-dbus.c", 277 , __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append (reply, "t", (uint64_t) hashmap_size((*(data)))); }; | |||
278 | ||||
279 | static int method_get_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
280 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
281 | Manager *m = userdata; | |||
282 | const char *name; | |||
283 | Session *session; | |||
284 | int r; | |||
285 | ||||
286 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 286, __PRETTY_FUNCTION__); } while (0); | |||
287 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 287, __PRETTY_FUNCTION__); } while (0); | |||
288 | ||||
289 | r = sd_bus_message_read(message, "s", &name); | |||
290 | if (r < 0) | |||
291 | return r; | |||
292 | ||||
293 | r = manager_get_session_from_creds(m, message, name, error, &session); | |||
294 | if (r < 0) | |||
295 | return r; | |||
296 | ||||
297 | p = session_bus_path(session); | |||
298 | if (!p) | |||
299 | return -ENOMEM12; | |||
300 | ||||
301 | return sd_bus_reply_method_return(message, "o", p); | |||
302 | } | |||
303 | ||||
304 | /* Get login session of a process. This is not what you are looking for these days, | |||
305 | * as apps may instead belong to a user service unit. This includes terminal | |||
306 | * emulators and hence command-line apps. */ | |||
307 | static int method_get_session_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
308 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
309 | Session *session = NULL((void*)0); | |||
310 | Manager *m = userdata; | |||
311 | pid_t pid; | |||
312 | int r; | |||
313 | ||||
314 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 314, __PRETTY_FUNCTION__); } while (0); | |||
315 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 315, __PRETTY_FUNCTION__); } while (0); | |||
316 | ||||
317 | assert_cc(sizeof(pid_t) == sizeof(uint32_t))GCC diagnostic push
; GCC diagnostic ignored "-Wdeclaration-after-statement" ; struct _assert_struct_37 { char x[(sizeof(pid_t) == sizeof (uint32_t)) ? 0 : -1]; }; GCC diagnostic pop ; | |||
318 | ||||
319 | r = sd_bus_message_read(message, "u", &pid); | |||
320 | if (r < 0) | |||
321 | return r; | |||
322 | if (pid < 0) | |||
323 | return -EINVAL22; | |||
324 | ||||
325 | if (pid == 0) { | |||
326 | r = manager_get_session_from_creds(m, message, NULL((void*)0), error, &session); | |||
327 | if (r < 0) | |||
328 | return r; | |||
329 | } else { | |||
330 | r = manager_get_session_by_pid(m, pid, &session); | |||
331 | if (r < 0) | |||
332 | return r; | |||
333 | ||||
334 | if (!session) | |||
335 | return sd_bus_error_setf(error, BUS_ERROR_NO_SESSION_FOR_PID"org.freedesktop.login1.NoSessionForPID", "PID "PID_FMT"%" "i"" does not belong to any known session", pid); | |||
336 | } | |||
337 | ||||
338 | p = session_bus_path(session); | |||
339 | if (!p) | |||
340 | return -ENOMEM12; | |||
341 | ||||
342 | return sd_bus_reply_method_return(message, "o", p); | |||
343 | } | |||
344 | ||||
345 | static int method_get_user(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
346 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
347 | Manager *m = userdata; | |||
348 | uint32_t uid; | |||
349 | User *user; | |||
350 | int r; | |||
351 | ||||
352 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 352, __PRETTY_FUNCTION__); } while (0); | |||
353 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 353, __PRETTY_FUNCTION__); } while (0); | |||
354 | ||||
355 | r = sd_bus_message_read(message, "u", &uid); | |||
356 | if (r < 0) | |||
357 | return r; | |||
358 | ||||
359 | r = manager_get_user_from_creds(m, message, uid, error, &user); | |||
360 | if (r < 0) | |||
361 | return r; | |||
362 | ||||
363 | p = user_bus_path(user); | |||
364 | if (!p) | |||
365 | return -ENOMEM12; | |||
366 | ||||
367 | return sd_bus_reply_method_return(message, "o", p); | |||
368 | } | |||
369 | ||||
370 | static int method_get_user_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
371 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
372 | Manager *m = userdata; | |||
373 | User *user = NULL((void*)0); | |||
374 | pid_t pid; | |||
375 | int r; | |||
376 | ||||
377 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 377, __PRETTY_FUNCTION__); } while (0); | |||
378 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 378, __PRETTY_FUNCTION__); } while (0); | |||
379 | ||||
380 | assert_cc(sizeof(pid_t) == sizeof(uint32_t))GCC diagnostic push
; GCC diagnostic ignored "-Wdeclaration-after-statement" ; struct _assert_struct_38 { char x[(sizeof(pid_t) == sizeof (uint32_t)) ? 0 : -1]; }; GCC diagnostic pop ; | |||
381 | ||||
382 | r = sd_bus_message_read(message, "u", &pid); | |||
383 | if (r < 0) | |||
384 | return r; | |||
385 | if (pid < 0) | |||
386 | return -EINVAL22; | |||
387 | ||||
388 | if (pid == 0) { | |||
389 | r = manager_get_user_from_creds(m, message, UID_INVALID((uid_t) -1), error, &user); | |||
390 | if (r < 0) | |||
391 | return r; | |||
392 | } else { | |||
393 | r = manager_get_user_by_pid(m, pid, &user); | |||
394 | if (r < 0) | |||
395 | return r; | |||
396 | if (!user) | |||
397 | return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID"org.freedesktop.login1.NoUserForPID", | |||
398 | "PID "PID_FMT"%" "i"" does not belong to any logged in user or lingering user", | |||
399 | pid); | |||
400 | } | |||
401 | ||||
402 | p = user_bus_path(user); | |||
403 | if (!p) | |||
404 | return -ENOMEM12; | |||
405 | ||||
406 | return sd_bus_reply_method_return(message, "o", p); | |||
407 | } | |||
408 | ||||
409 | static int method_get_seat(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
410 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
411 | Manager *m = userdata; | |||
412 | const char *name; | |||
413 | Seat *seat; | |||
414 | int r; | |||
415 | ||||
416 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 416, __PRETTY_FUNCTION__); } while (0); | |||
417 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 417, __PRETTY_FUNCTION__); } while (0); | |||
418 | ||||
419 | r = sd_bus_message_read(message, "s", &name); | |||
420 | if (r < 0) | |||
421 | return r; | |||
422 | ||||
423 | r = manager_get_seat_from_creds(m, message, name, error, &seat); | |||
424 | if (r < 0) | |||
425 | return r; | |||
426 | ||||
427 | p = seat_bus_path(seat); | |||
428 | if (!p) | |||
429 | return -ENOMEM12; | |||
430 | ||||
431 | return sd_bus_reply_method_return(message, "o", p); | |||
432 | } | |||
433 | ||||
434 | static int method_list_sessions(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
435 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0); | |||
436 | Manager *m = userdata; | |||
437 | Session *session; | |||
438 | Iterator i; | |||
439 | int r; | |||
440 | ||||
441 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 441, __PRETTY_FUNCTION__); } while (0); | |||
442 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 442, __PRETTY_FUNCTION__); } while (0); | |||
443 | ||||
444 | r = sd_bus_message_new_method_return(message, &reply); | |||
445 | if (r < 0) | |||
446 | return r; | |||
447 | ||||
448 | r = sd_bus_message_open_container(reply, 'a', "(susso)"); | |||
449 | if (r < 0) | |||
450 | return r; | |||
451 | ||||
452 | HASHMAP_FOREACH(session, m->sessions, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((m->sessions), & (i), (void**)&(session), ((void*)0)); ) { | |||
453 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
454 | ||||
455 | p = session_bus_path(session); | |||
456 | if (!p) | |||
457 | return -ENOMEM12; | |||
458 | ||||
459 | r = sd_bus_message_append(reply, "(susso)", | |||
460 | session->id, | |||
461 | (uint32_t) session->user->uid, | |||
462 | session->user->name, | |||
463 | session->seat ? session->seat->id : "", | |||
464 | p); | |||
465 | if (r < 0) | |||
466 | return r; | |||
467 | } | |||
468 | ||||
469 | r = sd_bus_message_close_container(reply); | |||
470 | if (r < 0) | |||
471 | return r; | |||
472 | ||||
473 | return sd_bus_send(NULL((void*)0), reply, NULL((void*)0)); | |||
474 | } | |||
475 | ||||
476 | static int method_list_users(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
477 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0); | |||
478 | Manager *m = userdata; | |||
479 | User *user; | |||
480 | Iterator i; | |||
481 | int r; | |||
482 | ||||
483 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 483, __PRETTY_FUNCTION__); } while (0); | |||
484 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 484, __PRETTY_FUNCTION__); } while (0); | |||
485 | ||||
486 | r = sd_bus_message_new_method_return(message, &reply); | |||
487 | if (r < 0) | |||
488 | return r; | |||
489 | ||||
490 | r = sd_bus_message_open_container(reply, 'a', "(uso)"); | |||
491 | if (r < 0) | |||
492 | return r; | |||
493 | ||||
494 | HASHMAP_FOREACH(user, m->users, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((m->users), & (i), (void**)&(user), ((void*)0)); ) { | |||
495 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
496 | ||||
497 | p = user_bus_path(user); | |||
498 | if (!p) | |||
499 | return -ENOMEM12; | |||
500 | ||||
501 | r = sd_bus_message_append(reply, "(uso)", | |||
502 | (uint32_t) user->uid, | |||
503 | user->name, | |||
504 | p); | |||
505 | if (r < 0) | |||
506 | return r; | |||
507 | } | |||
508 | ||||
509 | r = sd_bus_message_close_container(reply); | |||
510 | if (r < 0) | |||
511 | return r; | |||
512 | ||||
513 | return sd_bus_send(NULL((void*)0), reply, NULL((void*)0)); | |||
514 | } | |||
515 | ||||
516 | static int method_list_seats(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
517 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0); | |||
518 | Manager *m = userdata; | |||
519 | Seat *seat; | |||
520 | Iterator i; | |||
521 | int r; | |||
522 | ||||
523 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 523, __PRETTY_FUNCTION__); } while (0); | |||
524 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 524, __PRETTY_FUNCTION__); } while (0); | |||
525 | ||||
526 | r = sd_bus_message_new_method_return(message, &reply); | |||
527 | if (r < 0) | |||
528 | return r; | |||
529 | ||||
530 | r = sd_bus_message_open_container(reply, 'a', "(so)"); | |||
531 | if (r < 0) | |||
532 | return r; | |||
533 | ||||
534 | HASHMAP_FOREACH(seat, m->seats, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((m->seats), & (i), (void**)&(seat), ((void*)0)); ) { | |||
535 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
536 | ||||
537 | p = seat_bus_path(seat); | |||
538 | if (!p) | |||
539 | return -ENOMEM12; | |||
540 | ||||
541 | r = sd_bus_message_append(reply, "(so)", seat->id, p); | |||
542 | if (r < 0) | |||
543 | return r; | |||
544 | } | |||
545 | ||||
546 | r = sd_bus_message_close_container(reply); | |||
547 | if (r < 0) | |||
548 | return r; | |||
549 | ||||
550 | return sd_bus_send(NULL((void*)0), reply, NULL((void*)0)); | |||
551 | } | |||
552 | ||||
553 | static int method_list_inhibitors(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
554 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0); | |||
555 | Manager *m = userdata; | |||
556 | Inhibitor *inhibitor; | |||
557 | Iterator i; | |||
558 | int r; | |||
559 | ||||
560 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 560, __PRETTY_FUNCTION__); } while (0); | |||
561 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 561, __PRETTY_FUNCTION__); } while (0); | |||
562 | ||||
563 | r = sd_bus_message_new_method_return(message, &reply); | |||
564 | if (r < 0) | |||
565 | return r; | |||
566 | ||||
567 | r = sd_bus_message_open_container(reply, 'a', "(ssssuu)"); | |||
568 | if (r < 0) | |||
569 | return r; | |||
570 | ||||
571 | HASHMAP_FOREACH(inhibitor, m->inhibitors, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((m->inhibitors), &(i), (void**)&(inhibitor), ((void*)0)); ) { | |||
572 | ||||
573 | r = sd_bus_message_append(reply, "(ssssuu)", | |||
574 | strempty(inhibit_what_to_string(inhibitor->what)), | |||
575 | strempty(inhibitor->who), | |||
576 | strempty(inhibitor->why), | |||
577 | strempty(inhibit_mode_to_string(inhibitor->mode)), | |||
578 | (uint32_t) inhibitor->uid, | |||
579 | (uint32_t) inhibitor->pid); | |||
580 | if (r < 0) | |||
581 | return r; | |||
582 | } | |||
583 | ||||
584 | r = sd_bus_message_close_container(reply); | |||
585 | if (r < 0) | |||
586 | return r; | |||
587 | ||||
588 | return sd_bus_send(NULL((void*)0), reply, NULL((void*)0)); | |||
589 | } | |||
590 | ||||
591 | static int method_create_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
592 | const char *service, *type, *class, *cseat, *tty, *display, *remote_user, *remote_host, *desktop; | |||
593 | _cleanup_free___attribute__((cleanup(freep))) char *id = NULL((void*)0); | |||
594 | Session *session = NULL((void*)0); | |||
595 | uint32_t audit_id = 0; | |||
596 | Manager *m = userdata; | |||
597 | User *user = NULL((void*)0); | |||
598 | Seat *seat = NULL((void*)0); | |||
599 | pid_t leader; | |||
600 | uid_t uid; | |||
601 | int remote; | |||
602 | uint32_t vtnr = 0; | |||
603 | SessionType t; | |||
604 | SessionClass c; | |||
605 | int r; | |||
606 | ||||
607 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 607, __PRETTY_FUNCTION__); } while (0); | |||
608 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 608, __PRETTY_FUNCTION__); } while (0); | |||
609 | ||||
610 | assert_cc(sizeof(pid_t) == sizeof(uint32_t))GCC diagnostic push
; GCC diagnostic ignored "-Wdeclaration-after-statement" ; struct _assert_struct_39 { char x[(sizeof(pid_t) == sizeof (uint32_t)) ? 0 : -1]; }; GCC diagnostic pop ; | |||
611 | assert_cc(sizeof(uid_t) == sizeof(uint32_t))GCC diagnostic push
; GCC diagnostic ignored "-Wdeclaration-after-statement" ; struct _assert_struct_40 { char x[(sizeof(uid_t) == sizeof (uint32_t)) ? 0 : -1]; }; GCC diagnostic pop ; | |||
612 | ||||
613 | r = sd_bus_message_read(message, "uusssssussbss", &uid, &leader, &service, &type, &class, &desktop, &cseat, &vtnr, &tty, &display, &remote, &remote_user, &remote_host); | |||
614 | if (r < 0) | |||
615 | return r; | |||
616 | ||||
617 | if (!uid_is_valid(uid)) | |||
618 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid UID"); | |||
619 | if (leader < 0 || leader == 1 || leader == getpid_cached()) | |||
620 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid leader PID"); | |||
621 | ||||
622 | if (isempty(type)) | |||
623 | t = _SESSION_TYPE_INVALID; | |||
624 | else { | |||
625 | t = session_type_from_string(type); | |||
626 | if (t < 0) | |||
627 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid session type %s", type); | |||
628 | } | |||
629 | ||||
630 | if (isempty(class)) | |||
631 | c = _SESSION_CLASS_INVALID; | |||
632 | else { | |||
633 | c = session_class_from_string(class); | |||
634 | if (c < 0) | |||
635 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid session class %s", class); | |||
636 | } | |||
637 | ||||
638 | if (isempty(desktop)) | |||
639 | desktop = NULL((void*)0); | |||
640 | else { | |||
641 | if (!string_is_safe(desktop)) | |||
642 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid desktop string %s", desktop); | |||
643 | } | |||
644 | ||||
645 | if (isempty(cseat)) | |||
646 | seat = NULL((void*)0); | |||
647 | else { | |||
648 | seat = hashmap_get(m->seats, cseat); | |||
649 | if (!seat) | |||
650 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SEAT"org.freedesktop.login1.NoSuchSeat", "No seat '%s' known", cseat); | |||
651 | } | |||
652 | ||||
653 | if (tty_is_vc(tty)) { | |||
654 | int v; | |||
655 | ||||
656 | if (!seat) | |||
657 | seat = m->seat0; | |||
658 | else if (seat != m->seat0) | |||
659 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "TTY %s is virtual console but seat %s is not seat0", tty, seat->id); | |||
660 | ||||
661 | v = vtnr_from_tty(tty); | |||
662 | if (v <= 0) | |||
663 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Cannot determine VT number from virtual console TTY %s", tty); | |||
664 | ||||
665 | if (vtnr == 0) | |||
666 | vtnr = (uint32_t) v; | |||
667 | else if (vtnr != (uint32_t) v) | |||
668 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Specified TTY and VT number do not match"); | |||
669 | ||||
670 | } else if (tty_is_console(tty)) { | |||
671 | ||||
672 | if (!seat) | |||
673 | seat = m->seat0; | |||
674 | else if (seat != m->seat0) | |||
675 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Console TTY specified but seat is not seat0"); | |||
676 | ||||
677 | if (vtnr != 0) | |||
678 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Console TTY specified but VT number is not 0"); | |||
679 | } | |||
680 | ||||
681 | if (seat) { | |||
682 | if (seat_has_vts(seat)) { | |||
683 | if (vtnr <= 0 || vtnr > 63) | |||
684 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "VT number out of range"); | |||
685 | } else { | |||
686 | if (vtnr != 0) | |||
687 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Seat has no VTs but VT number not 0"); | |||
688 | } | |||
689 | } | |||
690 | ||||
691 | if (t == _SESSION_TYPE_INVALID) { | |||
692 | if (!isempty(display)) | |||
693 | t = SESSION_X11; | |||
694 | else if (!isempty(tty)) | |||
695 | t = SESSION_TTY; | |||
696 | else | |||
697 | t = SESSION_UNSPECIFIED; | |||
698 | } | |||
699 | ||||
700 | if (c == _SESSION_CLASS_INVALID) { | |||
701 | if (t == SESSION_UNSPECIFIED) | |||
702 | c = SESSION_BACKGROUND; | |||
703 | else | |||
704 | c = SESSION_USER; | |||
705 | } | |||
706 | ||||
707 | if (leader == 0) { | |||
708 | _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0); | |||
709 | ||||
710 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |||
711 | if (r < 0) | |||
712 | return r; | |||
713 | ||||
714 | r = sd_bus_creds_get_pid(creds, (pid_t*) &leader); | |||
715 | if (r < 0) | |||
716 | return r; | |||
717 | } | |||
718 | ||||
719 | /* Check if we are already in a logind session. Or if we are in user@.service which is a special PAM session | |||
720 | * that avoids creating a logind session. */ | |||
721 | r = manager_get_user_by_pid(m, leader, NULL((void*)0)); | |||
722 | if (r < 0) | |||
723 | return r; | |||
724 | if (r > 0) | |||
725 | return sd_bus_error_setf(error, BUS_ERROR_SESSION_BUSY"org.freedesktop.login1.SessionBusy", "Already running in a session or user slice"); | |||
726 | ||||
727 | /* | |||
728 | * Old gdm and lightdm start the user-session on the same VT as | |||
729 | * the greeter session. But they destroy the greeter session | |||
730 | * after the user-session and want the user-session to take | |||
731 | * over the VT. We need to support this for | |||
732 | * backwards-compatibility, so make sure we allow new sessions | |||
733 | * on a VT that a greeter is running on. Furthermore, to allow | |||
734 | * re-logins, we have to allow a greeter to take over a used VT for | |||
735 | * the exact same reasons. | |||
736 | */ | |||
737 | if (c != SESSION_GREETER && | |||
738 | vtnr > 0 && | |||
739 | vtnr < m->seat0->position_count && | |||
740 | m->seat0->positions[vtnr] && | |||
741 | m->seat0->positions[vtnr]->class != SESSION_GREETER) | |||
742 | return sd_bus_error_setf(error, BUS_ERROR_SESSION_BUSY"org.freedesktop.login1.SessionBusy", "Already occupied by a session"); | |||
743 | ||||
744 | if (hashmap_size(m->sessions) >= m->sessions_max) | |||
745 | return sd_bus_error_setf(error, SD_BUS_ERROR_LIMITS_EXCEEDED"org.freedesktop.DBus.Error.LimitsExceeded", "Maximum number of sessions (%" PRIu64"l" "u" ") reached, refusing further sessions.", m->sessions_max); | |||
746 | ||||
747 | (void) audit_session_from_pid(leader, &audit_id); | |||
748 | if (audit_session_is_valid(audit_id)) { | |||
749 | /* Keep our session IDs and the audit session IDs in sync */ | |||
750 | ||||
751 | if (asprintf(&id, "%"PRIu32"u", audit_id) < 0) | |||
752 | return -ENOMEM12; | |||
753 | ||||
754 | /* Wut? There's already a session by this name and we | |||
755 | * didn't find it above? Weird, then let's not trust | |||
756 | * the audit data and let's better register a new | |||
757 | * ID */ | |||
758 | if (hashmap_get(m->sessions, id)) { | |||
759 | log_warning("Existing logind session ID %s used by new audit session, ignoring.", id)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 759, __func__, "Existing logind session ID %s used by new audit session, ignoring." , id) : -abs(_e); }); | |||
760 | audit_id = AUDIT_SESSION_INVALID((uint32_t) -1); | |||
761 | id = mfree(id); | |||
762 | } | |||
763 | } | |||
764 | ||||
765 | if (!id) { | |||
766 | do { | |||
767 | id = mfree(id); | |||
768 | ||||
769 | if (asprintf(&id, "c%lu", ++m->session_counter) < 0) | |||
770 | return -ENOMEM12; | |||
771 | ||||
772 | } while (hashmap_get(m->sessions, id)); | |||
773 | } | |||
774 | ||||
775 | r = manager_add_user_by_uid(m, uid, &user); | |||
776 | if (r < 0) | |||
777 | goto fail; | |||
778 | ||||
779 | r = manager_add_session(m, id, &session); | |||
780 | if (r < 0) | |||
781 | goto fail; | |||
782 | ||||
783 | session_set_user(session, user); | |||
784 | ||||
785 | session->leader = leader; | |||
786 | session->audit_id = audit_id; | |||
787 | session->type = t; | |||
788 | session->class = c; | |||
789 | session->remote = remote; | |||
790 | session->vtnr = vtnr; | |||
791 | ||||
792 | if (!isempty(tty)) { | |||
793 | session->tty = strdup(tty); | |||
794 | if (!session->tty) { | |||
795 | r = -ENOMEM12; | |||
796 | goto fail; | |||
797 | } | |||
798 | } | |||
799 | ||||
800 | if (!isempty(display)) { | |||
801 | session->display = strdup(display); | |||
802 | if (!session->display) { | |||
803 | r = -ENOMEM12; | |||
804 | goto fail; | |||
805 | } | |||
806 | } | |||
807 | ||||
808 | if (!isempty(remote_user)) { | |||
809 | session->remote_user = strdup(remote_user); | |||
810 | if (!session->remote_user) { | |||
811 | r = -ENOMEM12; | |||
812 | goto fail; | |||
813 | } | |||
814 | } | |||
815 | ||||
816 | if (!isempty(remote_host)) { | |||
817 | session->remote_host = strdup(remote_host); | |||
818 | if (!session->remote_host) { | |||
819 | r = -ENOMEM12; | |||
820 | goto fail; | |||
821 | } | |||
822 | } | |||
823 | ||||
824 | if (!isempty(service)) { | |||
825 | session->service = strdup(service); | |||
826 | if (!session->service) { | |||
827 | r = -ENOMEM12; | |||
828 | goto fail; | |||
829 | } | |||
830 | } | |||
831 | ||||
832 | if (!isempty(desktop)) { | |||
833 | session->desktop = strdup(desktop); | |||
834 | if (!session->desktop) { | |||
835 | r = -ENOMEM12; | |||
836 | goto fail; | |||
837 | } | |||
838 | } | |||
839 | ||||
840 | if (seat) { | |||
841 | r = seat_attach_session(seat, session); | |||
842 | if (r < 0) | |||
843 | goto fail; | |||
844 | } | |||
845 | ||||
846 | r = sd_bus_message_enter_container(message, 'a', "(sv)"); | |||
847 | if (r < 0) | |||
848 | return r; | |||
849 | ||||
850 | r = session_start(session, message); | |||
851 | if (r < 0) | |||
852 | goto fail; | |||
853 | ||||
854 | r = sd_bus_message_exit_container(message); | |||
855 | if (r < 0) | |||
856 | goto fail; | |||
857 | ||||
858 | session->create_message = sd_bus_message_ref(message); | |||
859 | ||||
860 | /* Now, let's wait until the slice unit and stuff got created. We send the reply back from | |||
861 | * session_send_create_reply(). */ | |||
862 | ||||
863 | return 1; | |||
864 | ||||
865 | fail: | |||
866 | if (session) | |||
867 | session_add_to_gc_queue(session); | |||
868 | ||||
869 | if (user) | |||
870 | user_add_to_gc_queue(user); | |||
871 | ||||
872 | return r; | |||
873 | } | |||
874 | ||||
875 | static int method_release_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
876 | Manager *m = userdata; | |||
877 | Session *session; | |||
878 | const char *name; | |||
879 | int r; | |||
880 | ||||
881 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 881, __PRETTY_FUNCTION__); } while (0); | |||
882 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 882, __PRETTY_FUNCTION__); } while (0); | |||
883 | ||||
884 | r = sd_bus_message_read(message, "s", &name); | |||
885 | if (r < 0) | |||
886 | return r; | |||
887 | ||||
888 | r = manager_get_session_from_creds(m, message, name, error, &session); | |||
889 | if (r < 0) | |||
890 | return r; | |||
891 | ||||
892 | r = session_release(session); | |||
893 | if (r < 0) | |||
894 | return r; | |||
895 | ||||
896 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
897 | } | |||
898 | ||||
899 | static int method_activate_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
900 | Manager *m = userdata; | |||
901 | Session *session; | |||
902 | const char *name; | |||
903 | int r; | |||
904 | ||||
905 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 905, __PRETTY_FUNCTION__); } while (0); | |||
906 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 906, __PRETTY_FUNCTION__); } while (0); | |||
907 | ||||
908 | r = sd_bus_message_read(message, "s", &name); | |||
909 | if (r < 0) | |||
910 | return r; | |||
911 | ||||
912 | r = manager_get_session_from_creds(m, message, name, error, &session); | |||
913 | if (r < 0) | |||
914 | return r; | |||
915 | ||||
916 | /* PolicyKit is done by bus_session_method_activate() */ | |||
917 | ||||
918 | return bus_session_method_activate(message, session, error); | |||
919 | } | |||
920 | ||||
921 | static int method_activate_session_on_seat(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
922 | const char *session_name, *seat_name; | |||
923 | Manager *m = userdata; | |||
924 | Session *session; | |||
| ||||
925 | Seat *seat; | |||
926 | int r; | |||
927 | ||||
928 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 928, __PRETTY_FUNCTION__); } while (0); | |||
929 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 929, __PRETTY_FUNCTION__); } while (0); | |||
930 | ||||
931 | /* Same as ActivateSession() but refuses to work if | |||
932 | * the seat doesn't match */ | |||
933 | ||||
934 | r = sd_bus_message_read(message, "ss", &session_name, &seat_name); | |||
935 | if (r < 0) | |||
936 | return r; | |||
937 | ||||
938 | r = manager_get_session_from_creds(m, message, session_name, error, &session); | |||
939 | if (r < 0) | |||
940 | return r; | |||
941 | ||||
942 | r = manager_get_seat_from_creds(m, message, seat_name, error, &seat); | |||
943 | if (r
| |||
944 | return r; | |||
945 | ||||
946 | if (session->seat != seat) | |||
| ||||
947 | return sd_bus_error_setf(error, BUS_ERROR_SESSION_NOT_ON_SEAT"org.freedesktop.login1.SessionNotOnSeat", "Session %s not on seat %s", session_name, seat_name); | |||
948 | ||||
949 | r = bus_verify_polkit_async( | |||
950 | message, | |||
951 | CAP_SYS_ADMIN21, | |||
952 | "org.freedesktop.login1.chvt", | |||
953 | NULL((void*)0), | |||
954 | false0, | |||
955 | UID_INVALID((uid_t) -1), | |||
956 | &m->polkit_registry, | |||
957 | error); | |||
958 | if (r < 0) | |||
959 | return r; | |||
960 | if (r == 0) | |||
961 | return 1; /* Will call us back */ | |||
962 | ||||
963 | r = session_activate(session); | |||
964 | if (r < 0) | |||
965 | return r; | |||
966 | ||||
967 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
968 | } | |||
969 | ||||
970 | static int method_lock_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
971 | Manager *m = userdata; | |||
972 | Session *session; | |||
973 | const char *name; | |||
974 | int r; | |||
975 | ||||
976 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 976, __PRETTY_FUNCTION__); } while (0); | |||
977 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 977, __PRETTY_FUNCTION__); } while (0); | |||
978 | ||||
979 | r = sd_bus_message_read(message, "s", &name); | |||
980 | if (r < 0) | |||
981 | return r; | |||
982 | ||||
983 | r = manager_get_session_from_creds(m, message, name, error, &session); | |||
984 | if (r < 0) | |||
985 | return r; | |||
986 | ||||
987 | return bus_session_method_lock(message, session, error); | |||
988 | } | |||
989 | ||||
990 | static int method_lock_sessions(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
991 | Manager *m = userdata; | |||
992 | int r; | |||
993 | ||||
994 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 994, __PRETTY_FUNCTION__); } while (0); | |||
995 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 995, __PRETTY_FUNCTION__); } while (0); | |||
996 | ||||
997 | r = bus_verify_polkit_async( | |||
998 | message, | |||
999 | CAP_SYS_ADMIN21, | |||
1000 | "org.freedesktop.login1.lock-sessions", | |||
1001 | NULL((void*)0), | |||
1002 | false0, | |||
1003 | UID_INVALID((uid_t) -1), | |||
1004 | &m->polkit_registry, | |||
1005 | error); | |||
1006 | if (r < 0) | |||
1007 | return r; | |||
1008 | if (r == 0) | |||
1009 | return 1; /* Will call us back */ | |||
1010 | ||||
1011 | r = session_send_lock_all(m, streq(sd_bus_message_get_member(message), "LockSessions")(strcmp((sd_bus_message_get_member(message)),("LockSessions") ) == 0)); | |||
1012 | if (r < 0) | |||
1013 | return r; | |||
1014 | ||||
1015 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
1016 | } | |||
1017 | ||||
1018 | static int method_kill_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1019 | const char *name; | |||
1020 | Manager *m = userdata; | |||
1021 | Session *session; | |||
1022 | int r; | |||
1023 | ||||
1024 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1024, __PRETTY_FUNCTION__); } while (0); | |||
1025 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1025 , __PRETTY_FUNCTION__); } while (0); | |||
1026 | ||||
1027 | r = sd_bus_message_read(message, "s", &name); | |||
1028 | if (r < 0) | |||
1029 | return r; | |||
1030 | ||||
1031 | r = manager_get_session_from_creds(m, message, name, error, &session); | |||
1032 | if (r < 0) | |||
1033 | return r; | |||
1034 | ||||
1035 | return bus_session_method_kill(message, session, error); | |||
1036 | } | |||
1037 | ||||
1038 | static int method_kill_user(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1039 | Manager *m = userdata; | |||
1040 | uint32_t uid; | |||
1041 | User *user; | |||
1042 | int r; | |||
1043 | ||||
1044 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1044, __PRETTY_FUNCTION__); } while (0); | |||
1045 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1045 , __PRETTY_FUNCTION__); } while (0); | |||
1046 | ||||
1047 | r = sd_bus_message_read(message, "u", &uid); | |||
1048 | if (r < 0) | |||
1049 | return r; | |||
1050 | ||||
1051 | r = manager_get_user_from_creds(m, message, uid, error, &user); | |||
1052 | if (r < 0) | |||
1053 | return r; | |||
1054 | ||||
1055 | return bus_user_method_kill(message, user, error); | |||
1056 | } | |||
1057 | ||||
1058 | static int method_terminate_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1059 | Manager *m = userdata; | |||
1060 | const char *name; | |||
1061 | Session *session; | |||
1062 | int r; | |||
1063 | ||||
1064 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1064, __PRETTY_FUNCTION__); } while (0); | |||
1065 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1065 , __PRETTY_FUNCTION__); } while (0); | |||
1066 | ||||
1067 | r = sd_bus_message_read(message, "s", &name); | |||
1068 | if (r < 0) | |||
1069 | return r; | |||
1070 | ||||
1071 | r = manager_get_session_from_creds(m, message, name, error, &session); | |||
1072 | if (r < 0) | |||
1073 | return r; | |||
1074 | ||||
1075 | return bus_session_method_terminate(message, session, error); | |||
1076 | } | |||
1077 | ||||
1078 | static int method_terminate_user(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1079 | Manager *m = userdata; | |||
1080 | uint32_t uid; | |||
1081 | User *user; | |||
1082 | int r; | |||
1083 | ||||
1084 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1084, __PRETTY_FUNCTION__); } while (0); | |||
1085 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1085 , __PRETTY_FUNCTION__); } while (0); | |||
1086 | ||||
1087 | r = sd_bus_message_read(message, "u", &uid); | |||
1088 | if (r < 0) | |||
1089 | return r; | |||
1090 | ||||
1091 | r = manager_get_user_from_creds(m, message, uid, error, &user); | |||
1092 | if (r < 0) | |||
1093 | return r; | |||
1094 | ||||
1095 | return bus_user_method_terminate(message, user, error); | |||
1096 | } | |||
1097 | ||||
1098 | static int method_terminate_seat(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1099 | Manager *m = userdata; | |||
1100 | const char *name; | |||
1101 | Seat *seat; | |||
1102 | int r; | |||
1103 | ||||
1104 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1104, __PRETTY_FUNCTION__); } while (0); | |||
1105 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1105 , __PRETTY_FUNCTION__); } while (0); | |||
1106 | ||||
1107 | r = sd_bus_message_read(message, "s", &name); | |||
1108 | if (r < 0) | |||
1109 | return r; | |||
1110 | ||||
1111 | r = manager_get_seat_from_creds(m, message, name, error, &seat); | |||
1112 | if (r < 0) | |||
1113 | return r; | |||
1114 | ||||
1115 | return bus_seat_method_terminate(message, seat, error); | |||
1116 | } | |||
1117 | ||||
1118 | static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1119 | _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0); | |||
1120 | _cleanup_free___attribute__((cleanup(freep))) char *cc = NULL((void*)0); | |||
1121 | Manager *m = userdata; | |||
1122 | int r, b, interactive; | |||
1123 | struct passwd *pw; | |||
1124 | const char *path; | |||
1125 | uint32_t uid, auth_uid; | |||
1126 | ||||
1127 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1127, __PRETTY_FUNCTION__); } while (0); | |||
1128 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1128 , __PRETTY_FUNCTION__); } while (0); | |||
1129 | ||||
1130 | r = sd_bus_message_read(message, "ubb", &uid, &b, &interactive); | |||
1131 | if (r < 0) | |||
1132 | return r; | |||
1133 | ||||
1134 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID | | |||
1135 | SD_BUS_CREDS_OWNER_UID|SD_BUS_CREDS_AUGMENT, &creds); | |||
1136 | if (r < 0) | |||
1137 | return r; | |||
1138 | ||||
1139 | if (!uid_is_valid(uid)) { | |||
1140 | /* Note that we get the owner UID of the session or user unit, | |||
1141 | * not the actual client UID here! */ | |||
1142 | r = sd_bus_creds_get_owner_uid(creds, &uid); | |||
1143 | if (r < 0) | |||
1144 | return r; | |||
1145 | } | |||
1146 | ||||
1147 | /* owner_uid is racy, so for authorization we must use euid */ | |||
1148 | r = sd_bus_creds_get_euid(creds, &auth_uid); | |||
1149 | if (r < 0) | |||
1150 | return r; | |||
1151 | ||||
1152 | errno(*__errno_location ()) = 0; | |||
1153 | pw = getpwuid(uid); | |||
1154 | if (!pw) | |||
1155 | return errno(*__errno_location ()) > 0 ? -errno(*__errno_location ()) : -ENOENT2; | |||
1156 | ||||
1157 | r = bus_verify_polkit_async( | |||
1158 | message, | |||
1159 | CAP_SYS_ADMIN21, | |||
1160 | uid == auth_uid ? "org.freedesktop.login1.set-self-linger" : | |||
1161 | "org.freedesktop.login1.set-user-linger", | |||
1162 | NULL((void*)0), | |||
1163 | interactive, | |||
1164 | UID_INVALID((uid_t) -1), | |||
1165 | &m->polkit_registry, | |||
1166 | error); | |||
1167 | if (r < 0) | |||
1168 | return r; | |||
1169 | if (r == 0) | |||
1170 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
1171 | ||||
1172 | mkdir_p_label("/var/lib/systemd", 0755); | |||
1173 | ||||
1174 | r = mkdir_safe_label("/var/lib/systemd/linger", 0755, 0, 0, MKDIR_WARN_MODE); | |||
1175 | if (r < 0) | |||
1176 | return r; | |||
1177 | ||||
1178 | cc = cescape(pw->pw_name); | |||
1179 | if (!cc) | |||
1180 | return -ENOMEM12; | |||
1181 | ||||
1182 | path = strjoina("/var/lib/systemd/linger/", cc)({ const char *_appendees_[] = { "/var/lib/systemd/linger/", cc }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
1183 | if (b) { | |||
1184 | User *u; | |||
1185 | ||||
1186 | r = touch(path); | |||
1187 | if (r < 0) | |||
1188 | return r; | |||
1189 | ||||
1190 | if (manager_add_user_by_uid(m, uid, &u) >= 0) | |||
1191 | user_start(u); | |||
1192 | ||||
1193 | } else { | |||
1194 | User *u; | |||
1195 | ||||
1196 | r = unlink(path); | |||
1197 | if (r < 0 && errno(*__errno_location ()) != ENOENT2) | |||
1198 | return -errno(*__errno_location ()); | |||
1199 | ||||
1200 | u = hashmap_get(m->users, UID_TO_PTR(uid)((void*) (((uintptr_t) (uid))+1))); | |||
1201 | if (u) | |||
1202 | user_add_to_gc_queue(u); | |||
1203 | } | |||
1204 | ||||
1205 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
1206 | } | |||
1207 | ||||
1208 | static int trigger_device(Manager *m, struct udev_device *d) { | |||
1209 | _cleanup_(udev_enumerate_unrefp)__attribute__((cleanup(udev_enumerate_unrefp))) struct udev_enumerate *e = NULL((void*)0); | |||
1210 | struct udev_list_entry *first, *item; | |||
1211 | int r; | |||
1212 | ||||
1213 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1213 , __PRETTY_FUNCTION__); } while (0); | |||
1214 | ||||
1215 | e = udev_enumerate_new(m->udev); | |||
1216 | if (!e) | |||
1217 | return -ENOMEM12; | |||
1218 | ||||
1219 | if (d) { | |||
1220 | r = udev_enumerate_add_match_parent(e, d); | |||
1221 | if (r < 0) | |||
1222 | return r; | |||
1223 | } | |||
1224 | ||||
1225 | r = udev_enumerate_scan_devices(e); | |||
1226 | if (r < 0) | |||
1227 | return r; | |||
1228 | ||||
1229 | first = udev_enumerate_get_list_entry(e); | |||
1230 | udev_list_entry_foreach(item, first)for (item = first; item != ((void*)0); item = udev_list_entry_get_next (item)) { | |||
1231 | _cleanup_free___attribute__((cleanup(freep))) char *t = NULL((void*)0); | |||
1232 | const char *p; | |||
1233 | ||||
1234 | p = udev_list_entry_get_name(item); | |||
1235 | ||||
1236 | t = strappend(p, "/uevent"); | |||
1237 | if (!t) | |||
1238 | return -ENOMEM12; | |||
1239 | ||||
1240 | (void) write_string_file(t, "change", 0); | |||
1241 | } | |||
1242 | ||||
1243 | return 0; | |||
1244 | } | |||
1245 | ||||
1246 | static int attach_device(Manager *m, const char *seat, const char *sysfs) { | |||
1247 | _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0); | |||
1248 | _cleanup_free___attribute__((cleanup(freep))) char *rule = NULL((void*)0), *file = NULL((void*)0); | |||
1249 | const char *id_for_seat; | |||
1250 | int r; | |||
1251 | ||||
1252 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1252 , __PRETTY_FUNCTION__); } while (0); | |||
1253 | assert(seat)do { if ((__builtin_expect(!!(!(seat)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("seat"), "../src/login/logind-dbus.c", 1253 , __PRETTY_FUNCTION__); } while (0); | |||
1254 | assert(sysfs)do { if ((__builtin_expect(!!(!(sysfs)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("sysfs"), "../src/login/logind-dbus.c", 1254 , __PRETTY_FUNCTION__); } while (0); | |||
1255 | ||||
1256 | d = udev_device_new_from_syspath(m->udev, sysfs); | |||
1257 | if (!d) | |||
1258 | return -ENODEV19; | |||
1259 | ||||
1260 | if (!udev_device_has_tag(d, "seat")) | |||
1261 | return -ENODEV19; | |||
1262 | ||||
1263 | id_for_seat = udev_device_get_property_value(d, "ID_FOR_SEAT"); | |||
1264 | if (!id_for_seat) | |||
1265 | return -ENODEV19; | |||
1266 | ||||
1267 | if (asprintf(&file, "/etc/udev/rules.d/72-seat-%s.rules", id_for_seat) < 0) | |||
1268 | return -ENOMEM12; | |||
1269 | ||||
1270 | if (asprintf(&rule, "TAG==\"seat\", ENV{ID_FOR_SEAT}==\"%s\", ENV{ID_SEAT}=\"%s\"", id_for_seat, seat) < 0) | |||
1271 | return -ENOMEM12; | |||
1272 | ||||
1273 | mkdir_p_label("/etc/udev/rules.d", 0755); | |||
1274 | r = write_string_file_atomic_label(file, rule); | |||
1275 | if (r < 0) | |||
1276 | return r; | |||
1277 | ||||
1278 | return trigger_device(m, d); | |||
1279 | } | |||
1280 | ||||
1281 | static int flush_devices(Manager *m) { | |||
1282 | _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d; | |||
1283 | ||||
1284 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1284 , __PRETTY_FUNCTION__); } while (0); | |||
1285 | ||||
1286 | d = opendir("/etc/udev/rules.d"); | |||
1287 | if (!d) { | |||
1288 | if (errno(*__errno_location ()) != ENOENT2) | |||
1289 | log_warning_errno(errno, "Failed to open /etc/udev/rules.d: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/login/logind-dbus.c", 1289, __func__ , "Failed to open /etc/udev/rules.d: %m") : -abs(_e); }); | |||
1290 | } else { | |||
1291 | struct dirent *de; | |||
1292 | ||||
1293 | FOREACH_DIRENT_ALL(de, d, break)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location ()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location ( )) > 0) { break; } break; } else { | |||
1294 | if (!dirent_is_file(de)) | |||
1295 | continue; | |||
1296 | ||||
1297 | if (!startswith(de->d_name, "72-seat-")) | |||
1298 | continue; | |||
1299 | ||||
1300 | if (!endswith(de->d_name, ".rules")) | |||
1301 | continue; | |||
1302 | ||||
1303 | if (unlinkat(dirfd(d), de->d_name, 0) < 0) | |||
1304 | log_warning_errno(errno, "Failed to unlink %s: %m", de->d_name)({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/login/logind-dbus.c", 1304, __func__ , "Failed to unlink %s: %m", de->d_name) : -abs(_e); }); | |||
1305 | } | |||
1306 | } | |||
1307 | ||||
1308 | return trigger_device(m, NULL((void*)0)); | |||
1309 | } | |||
1310 | ||||
1311 | static int method_attach_device(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1312 | const char *sysfs, *seat; | |||
1313 | Manager *m = userdata; | |||
1314 | int interactive, r; | |||
1315 | ||||
1316 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1316, __PRETTY_FUNCTION__); } while (0); | |||
1317 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1317 , __PRETTY_FUNCTION__); } while (0); | |||
1318 | ||||
1319 | r = sd_bus_message_read(message, "ssb", &seat, &sysfs, &interactive); | |||
1320 | if (r < 0) | |||
1321 | return r; | |||
1322 | ||||
1323 | if (!path_startswith(sysfs, "/sys")) | |||
1324 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Path %s is not in /sys", sysfs); | |||
1325 | ||||
1326 | if (!seat_name_is_valid(seat)) | |||
1327 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Seat %s is not valid", seat); | |||
1328 | ||||
1329 | r = bus_verify_polkit_async( | |||
1330 | message, | |||
1331 | CAP_SYS_ADMIN21, | |||
1332 | "org.freedesktop.login1.attach-device", | |||
1333 | NULL((void*)0), | |||
1334 | interactive, | |||
1335 | UID_INVALID((uid_t) -1), | |||
1336 | &m->polkit_registry, | |||
1337 | error); | |||
1338 | if (r < 0) | |||
1339 | return r; | |||
1340 | if (r == 0) | |||
1341 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
1342 | ||||
1343 | r = attach_device(m, seat, sysfs); | |||
1344 | if (r < 0) | |||
1345 | return r; | |||
1346 | ||||
1347 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
1348 | } | |||
1349 | ||||
1350 | static int method_flush_devices(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1351 | Manager *m = userdata; | |||
1352 | int interactive, r; | |||
1353 | ||||
1354 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1354, __PRETTY_FUNCTION__); } while (0); | |||
1355 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1355 , __PRETTY_FUNCTION__); } while (0); | |||
1356 | ||||
1357 | r = sd_bus_message_read(message, "b", &interactive); | |||
1358 | if (r < 0) | |||
1359 | return r; | |||
1360 | ||||
1361 | r = bus_verify_polkit_async( | |||
1362 | message, | |||
1363 | CAP_SYS_ADMIN21, | |||
1364 | "org.freedesktop.login1.flush-devices", | |||
1365 | NULL((void*)0), | |||
1366 | interactive, | |||
1367 | UID_INVALID((uid_t) -1), | |||
1368 | &m->polkit_registry, | |||
1369 | error); | |||
1370 | if (r < 0) | |||
1371 | return r; | |||
1372 | if (r == 0) | |||
1373 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
1374 | ||||
1375 | r = flush_devices(m); | |||
1376 | if (r < 0) | |||
1377 | return r; | |||
1378 | ||||
1379 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
1380 | } | |||
1381 | ||||
1382 | static int have_multiple_sessions( | |||
1383 | Manager *m, | |||
1384 | uid_t uid) { | |||
1385 | ||||
1386 | Session *session; | |||
1387 | Iterator i; | |||
1388 | ||||
1389 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1389 , __PRETTY_FUNCTION__); } while (0); | |||
1390 | ||||
1391 | /* Check for other users' sessions. Greeter sessions do not | |||
1392 | * count, and non-login sessions do not count either. */ | |||
1393 | HASHMAP_FOREACH(session, m->sessions, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((m->sessions), & (i), (void**)&(session), ((void*)0)); ) | |||
1394 | if (session->class == SESSION_USER && | |||
1395 | session->user->uid != uid) | |||
1396 | return true1; | |||
1397 | ||||
1398 | return false0; | |||
1399 | } | |||
1400 | ||||
1401 | static int bus_manager_log_shutdown( | |||
1402 | Manager *m, | |||
1403 | const char *unit_name) { | |||
1404 | ||||
1405 | const char *p, *q; | |||
1406 | ||||
1407 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1407 , __PRETTY_FUNCTION__); } while (0); | |||
1408 | assert(unit_name)do { if ((__builtin_expect(!!(!(unit_name)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit_name"), "../src/login/logind-dbus.c" , 1408, __PRETTY_FUNCTION__); } while (0); | |||
1409 | ||||
1410 | if (streq(unit_name, SPECIAL_POWEROFF_TARGET)(strcmp((unit_name),("poweroff.target")) == 0)) { | |||
1411 | p = "MESSAGE=System is powering down"; | |||
1412 | q = "SHUTDOWN=power-off"; | |||
1413 | } else if (streq(unit_name, SPECIAL_REBOOT_TARGET)(strcmp((unit_name),("reboot.target")) == 0)) { | |||
1414 | p = "MESSAGE=System is rebooting"; | |||
1415 | q = "SHUTDOWN=reboot"; | |||
1416 | } else if (streq(unit_name, SPECIAL_HALT_TARGET)(strcmp((unit_name),("halt.target")) == 0)) { | |||
1417 | p = "MESSAGE=System is halting"; | |||
1418 | q = "SHUTDOWN=halt"; | |||
1419 | } else if (streq(unit_name, SPECIAL_KEXEC_TARGET)(strcmp((unit_name),("kexec.target")) == 0)) { | |||
1420 | p = "MESSAGE=System is rebooting with kexec"; | |||
1421 | q = "SHUTDOWN=kexec"; | |||
1422 | } else { | |||
1423 | p = "MESSAGE=System is shutting down"; | |||
1424 | q = NULL((void*)0); | |||
1425 | } | |||
1426 | ||||
1427 | if (isempty(m->wall_message)) | |||
1428 | p = strjoina(p, ".")({ const char *_appendees_[] = { p, "." }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ ( __builtin_choose_expr( !__builtin_types_compatible_p(typeof(_appendees_ ), typeof(&*(_appendees_))), sizeof(_appendees_)/sizeof(( _appendees_)[0]), ((void)0))) && _appendees_[_i_]; _i_ ++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
1429 | else | |||
1430 | p = strjoina(p, " (", m->wall_message, ").")({ const char *_appendees_[] = { p, " (", m->wall_message, ")." }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for ( _i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
1431 | ||||
1432 | return log_struct(LOG_NOTICE,log_struct_internal(((LOG_REALM_SYSTEMD) << 10 | (5)), 0 , "../src/login/logind-dbus.c", 1435, __func__, "MESSAGE_ID=" "98" "26" "88" "66" "d1" "d5" "4a" "49" "9c" "4e" "98" "92" "1d" "93" "bc" "40", p, q, ((void*)0)) | |||
1433 | "MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_STR,log_struct_internal(((LOG_REALM_SYSTEMD) << 10 | (5)), 0 , "../src/login/logind-dbus.c", 1435, __func__, "MESSAGE_ID=" "98" "26" "88" "66" "d1" "d5" "4a" "49" "9c" "4e" "98" "92" "1d" "93" "bc" "40", p, q, ((void*)0)) | |||
1434 | p,log_struct_internal(((LOG_REALM_SYSTEMD) << 10 | (5)), 0 , "../src/login/logind-dbus.c", 1435, __func__, "MESSAGE_ID=" "98" "26" "88" "66" "d1" "d5" "4a" "49" "9c" "4e" "98" "92" "1d" "93" "bc" "40", p, q, ((void*)0)) | |||
1435 | q)log_struct_internal(((LOG_REALM_SYSTEMD) << 10 | (5)), 0 , "../src/login/logind-dbus.c", 1435, __func__, "MESSAGE_ID=" "98" "26" "88" "66" "d1" "d5" "4a" "49" "9c" "4e" "98" "92" "1d" "93" "bc" "40", p, q, ((void*)0)); | |||
1436 | } | |||
1437 | ||||
1438 | static int lid_switch_ignore_handler(sd_event_source *e, uint64_t usec, void *userdata) { | |||
1439 | Manager *m = userdata; | |||
1440 | ||||
1441 | assert(e)do { if ((__builtin_expect(!!(!(e)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("e"), "../src/login/logind-dbus.c", 1441 , __PRETTY_FUNCTION__); } while (0); | |||
1442 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1442 , __PRETTY_FUNCTION__); } while (0); | |||
1443 | ||||
1444 | m->lid_switch_ignore_event_source = sd_event_source_unref(m->lid_switch_ignore_event_source); | |||
1445 | return 0; | |||
1446 | } | |||
1447 | ||||
1448 | int manager_set_lid_switch_ignore(Manager *m, usec_t until) { | |||
1449 | int r; | |||
1450 | ||||
1451 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1451 , __PRETTY_FUNCTION__); } while (0); | |||
1452 | ||||
1453 | if (until <= now(CLOCK_MONOTONIC1)) | |||
1454 | return 0; | |||
1455 | ||||
1456 | /* We want to ignore the lid switch for a while after each | |||
1457 | * suspend, and after boot-up. Hence let's install a timer for | |||
1458 | * this. As long as the event source exists we ignore the lid | |||
1459 | * switch. */ | |||
1460 | ||||
1461 | if (m->lid_switch_ignore_event_source) { | |||
1462 | usec_t u; | |||
1463 | ||||
1464 | r = sd_event_source_get_time(m->lid_switch_ignore_event_source, &u); | |||
1465 | if (r < 0) | |||
1466 | return r; | |||
1467 | ||||
1468 | if (until <= u) | |||
1469 | return 0; | |||
1470 | ||||
1471 | r = sd_event_source_set_time(m->lid_switch_ignore_event_source, until); | |||
1472 | } else | |||
1473 | r = sd_event_add_time( | |||
1474 | m->event, | |||
1475 | &m->lid_switch_ignore_event_source, | |||
1476 | CLOCK_MONOTONIC1, | |||
1477 | until, 0, | |||
1478 | lid_switch_ignore_handler, m); | |||
1479 | ||||
1480 | return r; | |||
1481 | } | |||
1482 | ||||
1483 | static int send_prepare_for(Manager *m, InhibitWhat w, bool_Bool _active) { | |||
1484 | ||||
1485 | static const char * const signal_name[_INHIBIT_WHAT_MAX] = { | |||
1486 | [INHIBIT_SHUTDOWN] = "PrepareForShutdown", | |||
1487 | [INHIBIT_SLEEP] = "PrepareForSleep" | |||
1488 | }; | |||
1489 | ||||
1490 | int active = _active; | |||
1491 | ||||
1492 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1492 , __PRETTY_FUNCTION__); } while (0); | |||
1493 | assert(w >= 0)do { if ((__builtin_expect(!!(!(w >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("w >= 0"), "../src/login/logind-dbus.c" , 1493, __PRETTY_FUNCTION__); } while (0); | |||
1494 | assert(w < _INHIBIT_WHAT_MAX)do { if ((__builtin_expect(!!(!(w < _INHIBIT_WHAT_MAX)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("w < _INHIBIT_WHAT_MAX" ), "../src/login/logind-dbus.c", 1494, __PRETTY_FUNCTION__); } while (0); | |||
1495 | assert(signal_name[w])do { if ((__builtin_expect(!!(!(signal_name[w])),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("signal_name[w]"), "../src/login/logind-dbus.c" , 1495, __PRETTY_FUNCTION__); } while (0); | |||
1496 | ||||
1497 | return sd_bus_emit_signal(m->bus, | |||
1498 | "/org/freedesktop/login1", | |||
1499 | "org.freedesktop.login1.Manager", | |||
1500 | signal_name[w], | |||
1501 | "b", | |||
1502 | active); | |||
1503 | } | |||
1504 | ||||
1505 | static int execute_shutdown_or_sleep( | |||
1506 | Manager *m, | |||
1507 | InhibitWhat w, | |||
1508 | const char *unit_name, | |||
1509 | sd_bus_error *error) { | |||
1510 | ||||
1511 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0); | |||
1512 | char *c = NULL((void*)0); | |||
1513 | const char *p; | |||
1514 | int r; | |||
1515 | ||||
1516 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1516 , __PRETTY_FUNCTION__); } while (0); | |||
1517 | assert(w > 0)do { if ((__builtin_expect(!!(!(w > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("w > 0"), "../src/login/logind-dbus.c" , 1517, __PRETTY_FUNCTION__); } while (0); | |||
1518 | assert(w < _INHIBIT_WHAT_MAX)do { if ((__builtin_expect(!!(!(w < _INHIBIT_WHAT_MAX)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("w < _INHIBIT_WHAT_MAX" ), "../src/login/logind-dbus.c", 1518, __PRETTY_FUNCTION__); } while (0); | |||
1519 | assert(unit_name)do { if ((__builtin_expect(!!(!(unit_name)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit_name"), "../src/login/logind-dbus.c" , 1519, __PRETTY_FUNCTION__); } while (0); | |||
1520 | ||||
1521 | if (w == INHIBIT_SHUTDOWN) | |||
1522 | bus_manager_log_shutdown(m, unit_name); | |||
1523 | ||||
1524 | r = sd_bus_call_method( | |||
1525 | m->bus, | |||
1526 | "org.freedesktop.systemd1", | |||
1527 | "/org/freedesktop/systemd1", | |||
1528 | "org.freedesktop.systemd1.Manager", | |||
1529 | "StartUnit", | |||
1530 | error, | |||
1531 | &reply, | |||
1532 | "ss", unit_name, "replace-irreversibly"); | |||
1533 | if (r < 0) | |||
1534 | goto error; | |||
1535 | ||||
1536 | r = sd_bus_message_read(reply, "o", &p); | |||
1537 | if (r < 0) | |||
1538 | goto error; | |||
1539 | ||||
1540 | c = strdup(p); | |||
1541 | if (!c) { | |||
1542 | r = -ENOMEM12; | |||
1543 | goto error; | |||
1544 | } | |||
1545 | ||||
1546 | m->action_unit = unit_name; | |||
1547 | free(m->action_job); | |||
1548 | m->action_job = c; | |||
1549 | m->action_what = w; | |||
1550 | ||||
1551 | /* Make sure the lid switch is ignored for a while */ | |||
1552 | manager_set_lid_switch_ignore(m, now(CLOCK_MONOTONIC1) + m->holdoff_timeout_usec); | |||
1553 | ||||
1554 | return 0; | |||
1555 | ||||
1556 | error: | |||
1557 | /* Tell people that they now may take a lock again */ | |||
1558 | (void) send_prepare_for(m, w, false0); | |||
1559 | ||||
1560 | return r; | |||
1561 | } | |||
1562 | ||||
1563 | int manager_dispatch_delayed(Manager *manager, bool_Bool timeout) { | |||
1564 | ||||
1565 | _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0}); | |||
1566 | Inhibitor *offending = NULL((void*)0); | |||
1567 | int r; | |||
1568 | ||||
1569 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 1569, __PRETTY_FUNCTION__); } while (0); | |||
1570 | ||||
1571 | if (manager->action_what == 0 || manager->action_job) | |||
1572 | return 0; | |||
1573 | ||||
1574 | if (manager_is_inhibited(manager, manager->action_what, INHIBIT_DELAY, NULL((void*)0), false0, false0, 0, &offending)) { | |||
1575 | _cleanup_free___attribute__((cleanup(freep))) char *comm = NULL((void*)0), *u = NULL((void*)0); | |||
1576 | ||||
1577 | if (!timeout) | |||
1578 | return 0; | |||
1579 | ||||
1580 | (void) get_process_comm(offending->pid, &comm); | |||
1581 | u = uid_to_name(offending->uid); | |||
1582 | ||||
1583 | log_notice("Delay lock is active (UID "UID_FMT"/%s, PID "PID_FMT"/%s) but inhibitor timeout is reached.",({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1585, __func__, "Delay lock is active (UID " "%" "u""/%s, PID ""%" "i""/%s) but inhibitor timeout is reached." , offending->uid, strna(u), offending->pid, strna(comm) ) : -abs(_e); }) | |||
1584 | offending->uid, strna(u),({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1585, __func__, "Delay lock is active (UID " "%" "u""/%s, PID ""%" "i""/%s) but inhibitor timeout is reached." , offending->uid, strna(u), offending->pid, strna(comm) ) : -abs(_e); }) | |||
1585 | offending->pid, strna(comm))({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1585, __func__, "Delay lock is active (UID " "%" "u""/%s, PID ""%" "i""/%s) but inhibitor timeout is reached." , offending->uid, strna(u), offending->pid, strna(comm) ) : -abs(_e); }); | |||
1586 | } | |||
1587 | ||||
1588 | /* Actually do the operation */ | |||
1589 | r = execute_shutdown_or_sleep(manager, manager->action_what, manager->action_unit, &error); | |||
1590 | if (r < 0) { | |||
1591 | log_warning("Error during inhibitor-delayed operation (already returned success to client): %s",({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1592, __func__, "Error during inhibitor-delayed operation (already returned success to client): %s" , bus_error_message(&error, r)) : -abs(_e); }) | |||
1592 | bus_error_message(&error, r))({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1592, __func__, "Error during inhibitor-delayed operation (already returned success to client): %s" , bus_error_message(&error, r)) : -abs(_e); }); | |||
1593 | ||||
1594 | manager->action_unit = NULL((void*)0); | |||
1595 | manager->action_what = 0; | |||
1596 | return r; | |||
1597 | } | |||
1598 | ||||
1599 | return 1; | |||
1600 | } | |||
1601 | ||||
1602 | static int manager_inhibit_timeout_handler( | |||
1603 | sd_event_source *s, | |||
1604 | uint64_t usec, | |||
1605 | void *userdata) { | |||
1606 | ||||
1607 | Manager *manager = userdata; | |||
1608 | int r; | |||
1609 | ||||
1610 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 1610, __PRETTY_FUNCTION__); } while (0); | |||
1611 | assert(manager->inhibit_timeout_source == s)do { if ((__builtin_expect(!!(!(manager->inhibit_timeout_source == s)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("manager->inhibit_timeout_source == s" ), "../src/login/logind-dbus.c", 1611, __PRETTY_FUNCTION__); } while (0); | |||
1612 | ||||
1613 | r = manager_dispatch_delayed(manager, true1); | |||
1614 | return (r < 0) ? r : 0; | |||
1615 | } | |||
1616 | ||||
1617 | static int delay_shutdown_or_sleep( | |||
1618 | Manager *m, | |||
1619 | InhibitWhat w, | |||
1620 | const char *unit_name) { | |||
1621 | ||||
1622 | int r; | |||
1623 | usec_t timeout_val; | |||
1624 | ||||
1625 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1625 , __PRETTY_FUNCTION__); } while (0); | |||
1626 | assert(w >= 0)do { if ((__builtin_expect(!!(!(w >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("w >= 0"), "../src/login/logind-dbus.c" , 1626, __PRETTY_FUNCTION__); } while (0); | |||
1627 | assert(w < _INHIBIT_WHAT_MAX)do { if ((__builtin_expect(!!(!(w < _INHIBIT_WHAT_MAX)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("w < _INHIBIT_WHAT_MAX" ), "../src/login/logind-dbus.c", 1627, __PRETTY_FUNCTION__); } while (0); | |||
1628 | assert(unit_name)do { if ((__builtin_expect(!!(!(unit_name)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit_name"), "../src/login/logind-dbus.c" , 1628, __PRETTY_FUNCTION__); } while (0); | |||
1629 | ||||
1630 | timeout_val = now(CLOCK_MONOTONIC1) + m->inhibit_delay_max; | |||
1631 | ||||
1632 | if (m->inhibit_timeout_source) { | |||
1633 | r = sd_event_source_set_time(m->inhibit_timeout_source, timeout_val); | |||
1634 | if (r < 0) | |||
1635 | return log_error_errno(r, "sd_event_source_set_time() failed: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1635, __func__, "sd_event_source_set_time() failed: %m" ) : -abs(_e); }); | |||
1636 | ||||
1637 | r = sd_event_source_set_enabled(m->inhibit_timeout_source, SD_EVENT_ONESHOT); | |||
1638 | if (r < 0) | |||
1639 | return log_error_errno(r, "sd_event_source_set_enabled() failed: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1639, __func__, "sd_event_source_set_enabled() failed: %m" ) : -abs(_e); }); | |||
1640 | } else { | |||
1641 | r = sd_event_add_time(m->event, &m->inhibit_timeout_source, CLOCK_MONOTONIC1, | |||
1642 | timeout_val, 0, manager_inhibit_timeout_handler, m); | |||
1643 | if (r < 0) | |||
1644 | return r; | |||
1645 | } | |||
1646 | ||||
1647 | m->action_unit = unit_name; | |||
1648 | m->action_what = w; | |||
1649 | ||||
1650 | return 0; | |||
1651 | } | |||
1652 | ||||
1653 | int bus_manager_shutdown_or_sleep_now_or_later( | |||
1654 | Manager *m, | |||
1655 | const char *unit_name, | |||
1656 | InhibitWhat w, | |||
1657 | sd_bus_error *error) { | |||
1658 | ||||
1659 | _cleanup_free___attribute__((cleanup(freep))) char *load_state = NULL((void*)0); | |||
1660 | bool_Bool delayed; | |||
1661 | int r; | |||
1662 | ||||
1663 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1663 , __PRETTY_FUNCTION__); } while (0); | |||
1664 | assert(unit_name)do { if ((__builtin_expect(!!(!(unit_name)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit_name"), "../src/login/logind-dbus.c" , 1664, __PRETTY_FUNCTION__); } while (0); | |||
1665 | assert(w > 0)do { if ((__builtin_expect(!!(!(w > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("w > 0"), "../src/login/logind-dbus.c" , 1665, __PRETTY_FUNCTION__); } while (0); | |||
1666 | assert(w <= _INHIBIT_WHAT_MAX)do { if ((__builtin_expect(!!(!(w <= _INHIBIT_WHAT_MAX)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("w <= _INHIBIT_WHAT_MAX" ), "../src/login/logind-dbus.c", 1666, __PRETTY_FUNCTION__); } while (0); | |||
1667 | assert(!m->action_job)do { if ((__builtin_expect(!!(!(!m->action_job)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!m->action_job"), "../src/login/logind-dbus.c" , 1667, __PRETTY_FUNCTION__); } while (0); | |||
1668 | ||||
1669 | r = unit_load_state(m->bus, unit_name, &load_state); | |||
1670 | if (r < 0) | |||
1671 | return r; | |||
1672 | ||||
1673 | if (!streq(load_state, "loaded")(strcmp((load_state),("loaded")) == 0)) { | |||
1674 | log_notice("Unit %s is %s, refusing operation.", unit_name, load_state)({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1674, __func__, "Unit %s is %s, refusing operation." , unit_name, load_state) : -abs(_e); }); | |||
1675 | return -EACCES13; | |||
1676 | } | |||
1677 | ||||
1678 | /* Tell everybody to prepare for shutdown/sleep */ | |||
1679 | (void) send_prepare_for(m, w, true1); | |||
1680 | ||||
1681 | delayed = | |||
1682 | m->inhibit_delay_max > 0 && | |||
1683 | manager_is_inhibited(m, w, INHIBIT_DELAY, NULL((void*)0), false0, false0, 0, NULL((void*)0)); | |||
1684 | ||||
1685 | if (delayed) | |||
1686 | /* Shutdown is delayed, keep in mind what we | |||
1687 | * want to do, and start a timeout */ | |||
1688 | r = delay_shutdown_or_sleep(m, w, unit_name); | |||
1689 | else | |||
1690 | /* Shutdown is not delayed, execute it | |||
1691 | * immediately */ | |||
1692 | r = execute_shutdown_or_sleep(m, w, unit_name, error); | |||
1693 | ||||
1694 | return r; | |||
1695 | } | |||
1696 | ||||
1697 | static int verify_shutdown_creds( | |||
1698 | Manager *m, | |||
1699 | sd_bus_message *message, | |||
1700 | InhibitWhat w, | |||
1701 | bool_Bool interactive, | |||
1702 | const char *action, | |||
1703 | const char *action_multiple_sessions, | |||
1704 | const char *action_ignore_inhibit, | |||
1705 | sd_bus_error *error) { | |||
1706 | ||||
1707 | _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0); | |||
1708 | bool_Bool multiple_sessions, blocked; | |||
1709 | uid_t uid; | |||
1710 | int r; | |||
1711 | ||||
1712 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1712 , __PRETTY_FUNCTION__); } while (0); | |||
1713 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1713, __PRETTY_FUNCTION__); } while (0); | |||
1714 | assert(w >= 0)do { if ((__builtin_expect(!!(!(w >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("w >= 0"), "../src/login/logind-dbus.c" , 1714, __PRETTY_FUNCTION__); } while (0); | |||
1715 | assert(w <= _INHIBIT_WHAT_MAX)do { if ((__builtin_expect(!!(!(w <= _INHIBIT_WHAT_MAX)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("w <= _INHIBIT_WHAT_MAX" ), "../src/login/logind-dbus.c", 1715, __PRETTY_FUNCTION__); } while (0); | |||
1716 | ||||
1717 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds); | |||
1718 | if (r < 0) | |||
1719 | return r; | |||
1720 | ||||
1721 | r = sd_bus_creds_get_euid(creds, &uid); | |||
1722 | if (r < 0) | |||
1723 | return r; | |||
1724 | ||||
1725 | r = have_multiple_sessions(m, uid); | |||
1726 | if (r < 0) | |||
1727 | return r; | |||
1728 | ||||
1729 | multiple_sessions = r > 0; | |||
1730 | blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL((void*)0), false0, true1, uid, NULL((void*)0)); | |||
1731 | ||||
1732 | if (multiple_sessions && action_multiple_sessions) { | |||
1733 | r = bus_verify_polkit_async(message, CAP_SYS_BOOT22, action_multiple_sessions, NULL((void*)0), interactive, UID_INVALID((uid_t) -1), &m->polkit_registry, error); | |||
1734 | if (r < 0) | |||
1735 | return r; | |||
1736 | if (r == 0) | |||
1737 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
1738 | } | |||
1739 | ||||
1740 | if (blocked && action_ignore_inhibit) { | |||
1741 | r = bus_verify_polkit_async(message, CAP_SYS_BOOT22, action_ignore_inhibit, NULL((void*)0), interactive, UID_INVALID((uid_t) -1), &m->polkit_registry, error); | |||
1742 | if (r < 0) | |||
1743 | return r; | |||
1744 | if (r == 0) | |||
1745 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
1746 | } | |||
1747 | ||||
1748 | if (!multiple_sessions && !blocked && action) { | |||
1749 | r = bus_verify_polkit_async(message, CAP_SYS_BOOT22, action, NULL((void*)0), interactive, UID_INVALID((uid_t) -1), &m->polkit_registry, error); | |||
1750 | if (r < 0) | |||
1751 | return r; | |||
1752 | if (r == 0) | |||
1753 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
1754 | } | |||
1755 | ||||
1756 | return 0; | |||
1757 | } | |||
1758 | ||||
1759 | static int method_do_shutdown_or_sleep( | |||
1760 | Manager *m, | |||
1761 | sd_bus_message *message, | |||
1762 | const char *unit_name, | |||
1763 | InhibitWhat w, | |||
1764 | const char *action, | |||
1765 | const char *action_multiple_sessions, | |||
1766 | const char *action_ignore_inhibit, | |||
1767 | const char *sleep_verb, | |||
1768 | sd_bus_error *error) { | |||
1769 | ||||
1770 | int interactive, r; | |||
1771 | ||||
1772 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1772 , __PRETTY_FUNCTION__); } while (0); | |||
1773 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 1773, __PRETTY_FUNCTION__); } while (0); | |||
1774 | assert(unit_name)do { if ((__builtin_expect(!!(!(unit_name)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit_name"), "../src/login/logind-dbus.c" , 1774, __PRETTY_FUNCTION__); } while (0); | |||
1775 | assert(w >= 0)do { if ((__builtin_expect(!!(!(w >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("w >= 0"), "../src/login/logind-dbus.c" , 1775, __PRETTY_FUNCTION__); } while (0); | |||
1776 | assert(w <= _INHIBIT_WHAT_MAX)do { if ((__builtin_expect(!!(!(w <= _INHIBIT_WHAT_MAX)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("w <= _INHIBIT_WHAT_MAX" ), "../src/login/logind-dbus.c", 1776, __PRETTY_FUNCTION__); } while (0); | |||
1777 | ||||
1778 | r = sd_bus_message_read(message, "b", &interactive); | |||
1779 | if (r < 0) | |||
1780 | return r; | |||
1781 | ||||
1782 | /* Don't allow multiple jobs being executed at the same time */ | |||
1783 | if (m->action_what) | |||
1784 | return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS"org.freedesktop.login1.OperationInProgress", "There's already a shutdown or sleep operation in progress"); | |||
1785 | ||||
1786 | if (sleep_verb) { | |||
1787 | r = can_sleep(sleep_verb); | |||
1788 | if (r == -ENOSPC28) | |||
1789 | return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED"org.freedesktop.login1.SleepVerbNotSupported", | |||
1790 | "Not enough swap space for hibernation"); | |||
1791 | if (r == 0) | |||
1792 | return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED"org.freedesktop.login1.SleepVerbNotSupported", | |||
1793 | "Sleep verb \"%s\" not supported", sleep_verb); | |||
1794 | if (r < 0) | |||
1795 | return r; | |||
1796 | } | |||
1797 | ||||
1798 | r = verify_shutdown_creds(m, message, w, interactive, action, action_multiple_sessions, | |||
1799 | action_ignore_inhibit, error); | |||
1800 | if (r != 0) | |||
1801 | return r; | |||
1802 | ||||
1803 | r = bus_manager_shutdown_or_sleep_now_or_later(m, unit_name, w, error); | |||
1804 | if (r < 0) | |||
1805 | return r; | |||
1806 | ||||
1807 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
1808 | } | |||
1809 | ||||
1810 | static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1811 | Manager *m = userdata; | |||
1812 | ||||
1813 | return method_do_shutdown_or_sleep( | |||
1814 | m, message, | |||
1815 | SPECIAL_POWEROFF_TARGET"poweroff.target", | |||
1816 | INHIBIT_SHUTDOWN, | |||
1817 | "org.freedesktop.login1.power-off", | |||
1818 | "org.freedesktop.login1.power-off-multiple-sessions", | |||
1819 | "org.freedesktop.login1.power-off-ignore-inhibit", | |||
1820 | NULL((void*)0), | |||
1821 | error); | |||
1822 | } | |||
1823 | ||||
1824 | static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1825 | Manager *m = userdata; | |||
1826 | ||||
1827 | return method_do_shutdown_or_sleep( | |||
1828 | m, message, | |||
1829 | SPECIAL_REBOOT_TARGET"reboot.target", | |||
1830 | INHIBIT_SHUTDOWN, | |||
1831 | "org.freedesktop.login1.reboot", | |||
1832 | "org.freedesktop.login1.reboot-multiple-sessions", | |||
1833 | "org.freedesktop.login1.reboot-ignore-inhibit", | |||
1834 | NULL((void*)0), | |||
1835 | error); | |||
1836 | } | |||
1837 | ||||
1838 | static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1839 | Manager *m = userdata; | |||
1840 | ||||
1841 | return method_do_shutdown_or_sleep( | |||
1842 | m, message, | |||
1843 | SPECIAL_HALT_TARGET"halt.target", | |||
1844 | INHIBIT_SHUTDOWN, | |||
1845 | "org.freedesktop.login1.halt", | |||
1846 | "org.freedesktop.login1.halt-multiple-sessions", | |||
1847 | "org.freedesktop.login1.halt-ignore-inhibit", | |||
1848 | NULL((void*)0), | |||
1849 | error); | |||
1850 | } | |||
1851 | ||||
1852 | static int method_suspend(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1853 | Manager *m = userdata; | |||
1854 | ||||
1855 | return method_do_shutdown_or_sleep( | |||
1856 | m, message, | |||
1857 | SPECIAL_SUSPEND_TARGET"suspend.target", | |||
1858 | INHIBIT_SLEEP, | |||
1859 | "org.freedesktop.login1.suspend", | |||
1860 | "org.freedesktop.login1.suspend-multiple-sessions", | |||
1861 | "org.freedesktop.login1.suspend-ignore-inhibit", | |||
1862 | "suspend", | |||
1863 | error); | |||
1864 | } | |||
1865 | ||||
1866 | static int method_hibernate(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1867 | Manager *m = userdata; | |||
1868 | ||||
1869 | return method_do_shutdown_or_sleep( | |||
1870 | m, message, | |||
1871 | SPECIAL_HIBERNATE_TARGET"hibernate.target", | |||
1872 | INHIBIT_SLEEP, | |||
1873 | "org.freedesktop.login1.hibernate", | |||
1874 | "org.freedesktop.login1.hibernate-multiple-sessions", | |||
1875 | "org.freedesktop.login1.hibernate-ignore-inhibit", | |||
1876 | "hibernate", | |||
1877 | error); | |||
1878 | } | |||
1879 | ||||
1880 | static int method_hybrid_sleep(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1881 | Manager *m = userdata; | |||
1882 | ||||
1883 | return method_do_shutdown_or_sleep( | |||
1884 | m, message, | |||
1885 | SPECIAL_HYBRID_SLEEP_TARGET"hybrid-sleep.target", | |||
1886 | INHIBIT_SLEEP, | |||
1887 | "org.freedesktop.login1.hibernate", | |||
1888 | "org.freedesktop.login1.hibernate-multiple-sessions", | |||
1889 | "org.freedesktop.login1.hibernate-ignore-inhibit", | |||
1890 | "hybrid-sleep", | |||
1891 | error); | |||
1892 | } | |||
1893 | ||||
1894 | static int method_suspend_then_hibernate(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
1895 | Manager *m = userdata; | |||
1896 | ||||
1897 | return method_do_shutdown_or_sleep( | |||
1898 | m, message, | |||
1899 | SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET"suspend-then-hibernate.target", | |||
1900 | INHIBIT_SLEEP, | |||
1901 | "org.freedesktop.login1.hibernate", | |||
1902 | "org.freedesktop.login1.hibernate-multiple-sessions", | |||
1903 | "org.freedesktop.login1.hibernate-ignore-inhibit", | |||
1904 | "hybrid-sleep", | |||
1905 | error); | |||
1906 | } | |||
1907 | ||||
1908 | static int nologin_timeout_handler( | |||
1909 | sd_event_source *s, | |||
1910 | uint64_t usec, | |||
1911 | void *userdata) { | |||
1912 | ||||
1913 | Manager *m = userdata; | |||
1914 | ||||
1915 | log_info("Creating /run/nologin, blocking further logins...")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1915, __func__, "Creating /run/nologin, blocking further logins..." ) : -abs(_e); }); | |||
1916 | ||||
1917 | m->unlink_nologin = | |||
1918 | create_shutdown_run_nologin_or_warn() >= 0; | |||
1919 | ||||
1920 | return 0; | |||
1921 | } | |||
1922 | ||||
1923 | static int update_schedule_file(Manager *m) { | |||
1924 | _cleanup_free___attribute__((cleanup(freep))) char *temp_path = NULL((void*)0); | |||
1925 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); | |||
1926 | int r; | |||
1927 | ||||
1928 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1928 , __PRETTY_FUNCTION__); } while (0); | |||
1929 | ||||
1930 | r = mkdir_safe_label("/run/systemd/shutdown", 0755, 0, 0, MKDIR_WARN_MODE); | |||
1931 | if (r < 0) | |||
1932 | return log_error_errno(r, "Failed to create shutdown subdirectory: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1932, __func__, "Failed to create shutdown subdirectory: %m" ) : -abs(_e); }); | |||
1933 | ||||
1934 | r = fopen_temporary("/run/systemd/shutdown/scheduled", &f, &temp_path); | |||
1935 | if (r < 0) | |||
1936 | return log_error_errno(r, "Failed to save information about scheduled shutdowns: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1936, __func__, "Failed to save information about scheduled shutdowns: %m" ) : -abs(_e); }); | |||
1937 | ||||
1938 | (void) fchmod(fileno(f), 0644); | |||
1939 | ||||
1940 | fprintf(f, | |||
1941 | "USEC="USEC_FMT"%" "l" "u""\n" | |||
1942 | "WARN_WALL=%i\n" | |||
1943 | "MODE=%s\n", | |||
1944 | m->scheduled_shutdown_timeout, | |||
1945 | m->enable_wall_messages, | |||
1946 | m->scheduled_shutdown_type); | |||
1947 | ||||
1948 | if (!isempty(m->wall_message)) { | |||
1949 | _cleanup_free___attribute__((cleanup(freep))) char *t; | |||
1950 | ||||
1951 | t = cescape(m->wall_message); | |||
1952 | if (!t) { | |||
1953 | r = -ENOMEM12; | |||
1954 | goto fail; | |||
1955 | } | |||
1956 | ||||
1957 | fprintf(f, "WALL_MESSAGE=%s\n", t); | |||
1958 | } | |||
1959 | ||||
1960 | r = fflush_and_check(f); | |||
1961 | if (r < 0) | |||
1962 | goto fail; | |||
1963 | ||||
1964 | if (rename(temp_path, "/run/systemd/shutdown/scheduled") < 0) { | |||
1965 | r = -errno(*__errno_location ()); | |||
1966 | goto fail; | |||
1967 | } | |||
1968 | ||||
1969 | return 0; | |||
1970 | ||||
1971 | fail: | |||
1972 | (void) unlink(temp_path); | |||
1973 | (void) unlink("/run/systemd/shutdown/scheduled"); | |||
1974 | ||||
1975 | return log_error_errno(r, "Failed to write information about scheduled shutdowns: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 1975, __func__, "Failed to write information about scheduled shutdowns: %m" ) : -abs(_e); }); | |||
1976 | } | |||
1977 | ||||
1978 | static void reset_scheduled_shutdown(Manager *m) { | |||
1979 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 1979 , __PRETTY_FUNCTION__); } while (0); | |||
1980 | ||||
1981 | m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source); | |||
1982 | m->wall_message_timeout_source = sd_event_source_unref(m->wall_message_timeout_source); | |||
1983 | m->nologin_timeout_source = sd_event_source_unref(m->nologin_timeout_source); | |||
1984 | ||||
1985 | m->scheduled_shutdown_type = mfree(m->scheduled_shutdown_type); | |||
1986 | m->scheduled_shutdown_timeout = 0; | |||
1987 | m->shutdown_dry_run = false0; | |||
1988 | ||||
1989 | if (m->unlink_nologin) { | |||
1990 | (void) unlink_or_warn("/run/nologin"); | |||
1991 | m->unlink_nologin = false0; | |||
1992 | } | |||
1993 | ||||
1994 | (void) unlink("/run/systemd/shutdown/scheduled"); | |||
1995 | } | |||
1996 | ||||
1997 | static int manager_scheduled_shutdown_handler( | |||
1998 | sd_event_source *s, | |||
1999 | uint64_t usec, | |||
2000 | void *userdata) { | |||
2001 | ||||
2002 | _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0}); | |||
2003 | Manager *m = userdata; | |||
2004 | const char *target; | |||
2005 | int r; | |||
2006 | ||||
2007 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2007 , __PRETTY_FUNCTION__); } while (0); | |||
2008 | ||||
2009 | if (isempty(m->scheduled_shutdown_type)) | |||
2010 | return 0; | |||
2011 | ||||
2012 | if (streq(m->scheduled_shutdown_type, "poweroff")(strcmp((m->scheduled_shutdown_type),("poweroff")) == 0)) | |||
2013 | target = SPECIAL_POWEROFF_TARGET"poweroff.target"; | |||
2014 | else if (streq(m->scheduled_shutdown_type, "reboot")(strcmp((m->scheduled_shutdown_type),("reboot")) == 0)) | |||
2015 | target = SPECIAL_REBOOT_TARGET"reboot.target"; | |||
2016 | else if (streq(m->scheduled_shutdown_type, "halt")(strcmp((m->scheduled_shutdown_type),("halt")) == 0)) | |||
2017 | target = SPECIAL_HALT_TARGET"halt.target"; | |||
2018 | else | |||
2019 | assert_not_reached("unexpected shutdown type")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, ( "unexpected shutdown type"), "../src/login/logind-dbus.c", 2019 , __PRETTY_FUNCTION__); } while (0); | |||
2020 | ||||
2021 | /* Don't allow multiple jobs being executed at the same time */ | |||
2022 | if (m->action_what) { | |||
2023 | r = -EALREADY114; | |||
2024 | log_error("Scheduled shutdown to %s failed: shutdown or sleep operation already in progress", target)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2024, __func__, "Scheduled shutdown to %s failed: shutdown or sleep operation already in progress" , target) : -abs(_e); }); | |||
2025 | goto error; | |||
2026 | } | |||
2027 | ||||
2028 | if (m->shutdown_dry_run) { | |||
2029 | /* We do not process delay inhibitors here. Otherwise, we | |||
2030 | * would have to be considered "in progress" (like the check | |||
2031 | * above) for some seconds after our admin has seen the final | |||
2032 | * wall message. */ | |||
2033 | ||||
2034 | bus_manager_log_shutdown(m, target); | |||
2035 | log_info("Running in dry run, suppressing action.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2035, __func__, "Running in dry run, suppressing action." ) : -abs(_e); }); | |||
2036 | reset_scheduled_shutdown(m); | |||
2037 | ||||
2038 | return 0; | |||
2039 | } | |||
2040 | ||||
2041 | r = bus_manager_shutdown_or_sleep_now_or_later(m, target, INHIBIT_SHUTDOWN, &error); | |||
2042 | if (r < 0) { | |||
2043 | log_error_errno(r, "Scheduled shutdown to %s failed: %m", target)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2043, __func__, "Scheduled shutdown to %s failed: %m" , target) : -abs(_e); }); | |||
2044 | goto error; | |||
2045 | } | |||
2046 | ||||
2047 | return 0; | |||
2048 | ||||
2049 | error: | |||
2050 | reset_scheduled_shutdown(m); | |||
2051 | return r; | |||
2052 | } | |||
2053 | ||||
2054 | static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2055 | Manager *m = userdata; | |||
2056 | _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0); | |||
2057 | const char *action_multiple_sessions = NULL((void*)0); | |||
2058 | const char *action_ignore_inhibit = NULL((void*)0); | |||
2059 | const char *action = NULL((void*)0); | |||
2060 | uint64_t elapse; | |||
2061 | char *type; | |||
2062 | int r; | |||
2063 | bool_Bool dry_run = false0; | |||
2064 | ||||
2065 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2065 , __PRETTY_FUNCTION__); } while (0); | |||
2066 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2066, __PRETTY_FUNCTION__); } while (0); | |||
2067 | ||||
2068 | r = sd_bus_message_read(message, "st", &type, &elapse); | |||
2069 | if (r < 0) | |||
2070 | return r; | |||
2071 | ||||
2072 | if (startswith(type, "dry-")) { | |||
2073 | type += 4; | |||
2074 | dry_run = true1; | |||
2075 | } | |||
2076 | ||||
2077 | if (streq(type, "poweroff")(strcmp((type),("poweroff")) == 0)) { | |||
2078 | action = "org.freedesktop.login1.power-off"; | |||
2079 | action_multiple_sessions = "org.freedesktop.login1.power-off-multiple-sessions"; | |||
2080 | action_ignore_inhibit = "org.freedesktop.login1.power-off-ignore-inhibit"; | |||
2081 | } else if (streq(type, "reboot")(strcmp((type),("reboot")) == 0)) { | |||
2082 | action = "org.freedesktop.login1.reboot"; | |||
2083 | action_multiple_sessions = "org.freedesktop.login1.reboot-multiple-sessions"; | |||
2084 | action_ignore_inhibit = "org.freedesktop.login1.reboot-ignore-inhibit"; | |||
2085 | } else if (streq(type, "halt")(strcmp((type),("halt")) == 0)) { | |||
2086 | action = "org.freedesktop.login1.halt"; | |||
2087 | action_multiple_sessions = "org.freedesktop.login1.halt-multiple-sessions"; | |||
2088 | action_ignore_inhibit = "org.freedesktop.login1.halt-ignore-inhibit"; | |||
2089 | } else | |||
2090 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Unsupported shutdown type"); | |||
2091 | ||||
2092 | r = verify_shutdown_creds(m, message, INHIBIT_SHUTDOWN, false0, | |||
2093 | action, action_multiple_sessions, action_ignore_inhibit, error); | |||
2094 | if (r != 0) | |||
2095 | return r; | |||
2096 | ||||
2097 | if (m->scheduled_shutdown_timeout_source) { | |||
2098 | r = sd_event_source_set_time(m->scheduled_shutdown_timeout_source, elapse); | |||
2099 | if (r < 0) | |||
2100 | return log_error_errno(r, "sd_event_source_set_time() failed: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2100, __func__, "sd_event_source_set_time() failed: %m" ) : -abs(_e); }); | |||
2101 | ||||
2102 | r = sd_event_source_set_enabled(m->scheduled_shutdown_timeout_source, SD_EVENT_ONESHOT); | |||
2103 | if (r < 0) | |||
2104 | return log_error_errno(r, "sd_event_source_set_enabled() failed: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2104, __func__, "sd_event_source_set_enabled() failed: %m" ) : -abs(_e); }); | |||
2105 | } else { | |||
2106 | r = sd_event_add_time(m->event, &m->scheduled_shutdown_timeout_source, | |||
2107 | CLOCK_REALTIME0, elapse, 0, manager_scheduled_shutdown_handler, m); | |||
2108 | if (r < 0) | |||
2109 | return log_error_errno(r, "sd_event_add_time() failed: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2109, __func__, "sd_event_add_time() failed: %m" ) : -abs(_e); }); | |||
2110 | } | |||
2111 | ||||
2112 | r = free_and_strdup(&m->scheduled_shutdown_type, type); | |||
2113 | if (r < 0) { | |||
2114 | m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source); | |||
2115 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/login/logind-dbus.c" , 2115, __func__); | |||
2116 | } | |||
2117 | ||||
2118 | m->shutdown_dry_run = dry_run; | |||
2119 | ||||
2120 | if (m->nologin_timeout_source) { | |||
2121 | r = sd_event_source_set_time(m->nologin_timeout_source, elapse); | |||
2122 | if (r < 0) | |||
2123 | return log_error_errno(r, "sd_event_source_set_time() failed: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2123, __func__, "sd_event_source_set_time() failed: %m" ) : -abs(_e); }); | |||
2124 | ||||
2125 | r = sd_event_source_set_enabled(m->nologin_timeout_source, SD_EVENT_ONESHOT); | |||
2126 | if (r < 0) | |||
2127 | return log_error_errno(r, "sd_event_source_set_enabled() failed: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2127, __func__, "sd_event_source_set_enabled() failed: %m" ) : -abs(_e); }); | |||
2128 | } else { | |||
2129 | r = sd_event_add_time(m->event, &m->nologin_timeout_source, | |||
2130 | CLOCK_REALTIME0, elapse - 5 * USEC_PER_MINUTE((usec_t) (60ULL*((usec_t) 1000000ULL))), 0, nologin_timeout_handler, m); | |||
2131 | if (r < 0) | |||
2132 | return log_error_errno(r, "sd_event_add_time() failed: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2132, __func__, "sd_event_add_time() failed: %m" ) : -abs(_e); }); | |||
2133 | } | |||
2134 | ||||
2135 | m->scheduled_shutdown_timeout = elapse; | |||
2136 | ||||
2137 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_AUGMENT|SD_BUS_CREDS_TTY|SD_BUS_CREDS_UID, &creds); | |||
2138 | if (r >= 0) { | |||
2139 | const char *tty = NULL((void*)0); | |||
2140 | ||||
2141 | (void) sd_bus_creds_get_uid(creds, &m->scheduled_shutdown_uid); | |||
2142 | (void) sd_bus_creds_get_tty(creds, &tty); | |||
2143 | ||||
2144 | r = free_and_strdup(&m->scheduled_shutdown_tty, tty); | |||
2145 | if (r < 0) { | |||
2146 | m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source); | |||
2147 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/login/logind-dbus.c" , 2147, __func__); | |||
2148 | } | |||
2149 | } | |||
2150 | ||||
2151 | r = manager_setup_wall_message_timer(m); | |||
2152 | if (r < 0) | |||
2153 | return r; | |||
2154 | ||||
2155 | r = update_schedule_file(m); | |||
2156 | if (r < 0) | |||
2157 | return r; | |||
2158 | ||||
2159 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
2160 | } | |||
2161 | ||||
2162 | static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2163 | Manager *m = userdata; | |||
2164 | bool_Bool cancelled; | |||
2165 | ||||
2166 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2166 , __PRETTY_FUNCTION__); } while (0); | |||
2167 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2167, __PRETTY_FUNCTION__); } while (0); | |||
2168 | ||||
2169 | cancelled = m->scheduled_shutdown_type != NULL((void*)0); | |||
2170 | reset_scheduled_shutdown(m); | |||
2171 | ||||
2172 | if (cancelled && m->enable_wall_messages) { | |||
2173 | _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0); | |||
2174 | _cleanup_free___attribute__((cleanup(freep))) char *username = NULL((void*)0); | |||
2175 | const char *tty = NULL((void*)0); | |||
2176 | uid_t uid = 0; | |||
2177 | int r; | |||
2178 | ||||
2179 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_AUGMENT|SD_BUS_CREDS_TTY|SD_BUS_CREDS_UID, &creds); | |||
2180 | if (r >= 0) { | |||
2181 | (void) sd_bus_creds_get_uid(creds, &uid); | |||
2182 | (void) sd_bus_creds_get_tty(creds, &tty); | |||
2183 | } | |||
2184 | ||||
2185 | username = uid_to_name(uid); | |||
2186 | utmp_wall("The system shutdown has been cancelled", | |||
2187 | username, tty, logind_wall_tty_filter, m); | |||
2188 | } | |||
2189 | ||||
2190 | return sd_bus_reply_method_return(message, "b", cancelled); | |||
2191 | } | |||
2192 | ||||
2193 | static int method_can_shutdown_or_sleep( | |||
2194 | Manager *m, | |||
2195 | sd_bus_message *message, | |||
2196 | InhibitWhat w, | |||
2197 | const char *action, | |||
2198 | const char *action_multiple_sessions, | |||
2199 | const char *action_ignore_inhibit, | |||
2200 | const char *sleep_verb, | |||
2201 | sd_bus_error *error) { | |||
2202 | ||||
2203 | _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0); | |||
2204 | HandleAction handle; | |||
2205 | bool_Bool multiple_sessions, challenge, blocked; | |||
2206 | const char *result = NULL((void*)0); | |||
2207 | uid_t uid; | |||
2208 | int r; | |||
2209 | ||||
2210 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2210 , __PRETTY_FUNCTION__); } while (0); | |||
2211 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2211, __PRETTY_FUNCTION__); } while (0); | |||
2212 | assert(w >= 0)do { if ((__builtin_expect(!!(!(w >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("w >= 0"), "../src/login/logind-dbus.c" , 2212, __PRETTY_FUNCTION__); } while (0); | |||
2213 | assert(w <= _INHIBIT_WHAT_MAX)do { if ((__builtin_expect(!!(!(w <= _INHIBIT_WHAT_MAX)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("w <= _INHIBIT_WHAT_MAX" ), "../src/login/logind-dbus.c", 2213, __PRETTY_FUNCTION__); } while (0); | |||
2214 | assert(action)do { if ((__builtin_expect(!!(!(action)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("action"), "../src/login/logind-dbus.c", 2214, __PRETTY_FUNCTION__); } while (0); | |||
2215 | assert(action_multiple_sessions)do { if ((__builtin_expect(!!(!(action_multiple_sessions)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("action_multiple_sessions" ), "../src/login/logind-dbus.c", 2215, __PRETTY_FUNCTION__); } while (0); | |||
2216 | assert(action_ignore_inhibit)do { if ((__builtin_expect(!!(!(action_ignore_inhibit)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("action_ignore_inhibit"), "../src/login/logind-dbus.c" , 2216, __PRETTY_FUNCTION__); } while (0); | |||
2217 | ||||
2218 | if (sleep_verb) { | |||
2219 | r = can_sleep(sleep_verb); | |||
2220 | if (IN_SET(r, 0, -ENOSPC)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){0, -28})/sizeof(int)]; switch(r) { case 0 : case -28: _found = 1; break; default: break; } _found; })) | |||
2221 | return sd_bus_reply_method_return(message, "s", "na"); | |||
2222 | if (r < 0) | |||
2223 | return r; | |||
2224 | } | |||
2225 | ||||
2226 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds); | |||
2227 | if (r < 0) | |||
2228 | return r; | |||
2229 | ||||
2230 | r = sd_bus_creds_get_euid(creds, &uid); | |||
2231 | if (r < 0) | |||
2232 | return r; | |||
2233 | ||||
2234 | r = have_multiple_sessions(m, uid); | |||
2235 | if (r < 0) | |||
2236 | return r; | |||
2237 | ||||
2238 | multiple_sessions = r > 0; | |||
2239 | blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL((void*)0), false0, true1, uid, NULL((void*)0)); | |||
2240 | ||||
2241 | handle = handle_action_from_string(sleep_verb); | |||
2242 | if (handle >= 0) { | |||
2243 | const char *target; | |||
2244 | ||||
2245 | target = manager_target_for_action(handle); | |||
2246 | if (target) { | |||
2247 | _cleanup_free___attribute__((cleanup(freep))) char *load_state = NULL((void*)0); | |||
2248 | ||||
2249 | r = unit_load_state(m->bus, target, &load_state); | |||
2250 | if (r < 0) | |||
2251 | return r; | |||
2252 | ||||
2253 | if (!streq(load_state, "loaded")(strcmp((load_state),("loaded")) == 0)) { | |||
2254 | result = "no"; | |||
2255 | goto finish; | |||
2256 | } | |||
2257 | } | |||
2258 | } | |||
2259 | ||||
2260 | if (multiple_sessions) { | |||
2261 | r = bus_test_polkit(message, CAP_SYS_BOOT22, action_multiple_sessions, NULL((void*)0), UID_INVALID((uid_t) -1), &challenge, error); | |||
2262 | if (r < 0) | |||
2263 | return r; | |||
2264 | ||||
2265 | if (r > 0) | |||
2266 | result = "yes"; | |||
2267 | else if (challenge) | |||
2268 | result = "challenge"; | |||
2269 | else | |||
2270 | result = "no"; | |||
2271 | } | |||
2272 | ||||
2273 | if (blocked) { | |||
2274 | r = bus_test_polkit(message, CAP_SYS_BOOT22, action_ignore_inhibit, NULL((void*)0), UID_INVALID((uid_t) -1), &challenge, error); | |||
2275 | if (r < 0) | |||
2276 | return r; | |||
2277 | ||||
2278 | if (r > 0 && !result) | |||
2279 | result = "yes"; | |||
2280 | else if (challenge && (!result || streq(result, "yes")(strcmp((result),("yes")) == 0))) | |||
2281 | result = "challenge"; | |||
2282 | else | |||
2283 | result = "no"; | |||
2284 | } | |||
2285 | ||||
2286 | if (!multiple_sessions && !blocked) { | |||
2287 | /* If neither inhibit nor multiple sessions | |||
2288 | * apply then just check the normal policy */ | |||
2289 | ||||
2290 | r = bus_test_polkit(message, CAP_SYS_BOOT22, action, NULL((void*)0), UID_INVALID((uid_t) -1), &challenge, error); | |||
2291 | if (r < 0) | |||
2292 | return r; | |||
2293 | ||||
2294 | if (r > 0) | |||
2295 | result = "yes"; | |||
2296 | else if (challenge) | |||
2297 | result = "challenge"; | |||
2298 | else | |||
2299 | result = "no"; | |||
2300 | } | |||
2301 | ||||
2302 | finish: | |||
2303 | return sd_bus_reply_method_return(message, "s", result); | |||
2304 | } | |||
2305 | ||||
2306 | static int method_can_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2307 | Manager *m = userdata; | |||
2308 | ||||
2309 | return method_can_shutdown_or_sleep( | |||
2310 | m, message, | |||
2311 | INHIBIT_SHUTDOWN, | |||
2312 | "org.freedesktop.login1.power-off", | |||
2313 | "org.freedesktop.login1.power-off-multiple-sessions", | |||
2314 | "org.freedesktop.login1.power-off-ignore-inhibit", | |||
2315 | NULL((void*)0), | |||
2316 | error); | |||
2317 | } | |||
2318 | ||||
2319 | static int method_can_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2320 | Manager *m = userdata; | |||
2321 | ||||
2322 | return method_can_shutdown_or_sleep( | |||
2323 | m, message, | |||
2324 | INHIBIT_SHUTDOWN, | |||
2325 | "org.freedesktop.login1.reboot", | |||
2326 | "org.freedesktop.login1.reboot-multiple-sessions", | |||
2327 | "org.freedesktop.login1.reboot-ignore-inhibit", | |||
2328 | NULL((void*)0), | |||
2329 | error); | |||
2330 | } | |||
2331 | ||||
2332 | static int method_can_halt(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2333 | Manager *m = userdata; | |||
2334 | ||||
2335 | return method_can_shutdown_or_sleep( | |||
2336 | m, message, | |||
2337 | INHIBIT_SHUTDOWN, | |||
2338 | "org.freedesktop.login1.halt", | |||
2339 | "org.freedesktop.login1.halt-multiple-sessions", | |||
2340 | "org.freedesktop.login1.halt-ignore-inhibit", | |||
2341 | NULL((void*)0), | |||
2342 | error); | |||
2343 | } | |||
2344 | ||||
2345 | static int method_can_suspend(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2346 | Manager *m = userdata; | |||
2347 | ||||
2348 | return method_can_shutdown_or_sleep( | |||
2349 | m, message, | |||
2350 | INHIBIT_SLEEP, | |||
2351 | "org.freedesktop.login1.suspend", | |||
2352 | "org.freedesktop.login1.suspend-multiple-sessions", | |||
2353 | "org.freedesktop.login1.suspend-ignore-inhibit", | |||
2354 | "suspend", | |||
2355 | error); | |||
2356 | } | |||
2357 | ||||
2358 | static int method_can_hibernate(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2359 | Manager *m = userdata; | |||
2360 | ||||
2361 | return method_can_shutdown_or_sleep( | |||
2362 | m, message, | |||
2363 | INHIBIT_SLEEP, | |||
2364 | "org.freedesktop.login1.hibernate", | |||
2365 | "org.freedesktop.login1.hibernate-multiple-sessions", | |||
2366 | "org.freedesktop.login1.hibernate-ignore-inhibit", | |||
2367 | "hibernate", | |||
2368 | error); | |||
2369 | } | |||
2370 | ||||
2371 | static int method_can_hybrid_sleep(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2372 | Manager *m = userdata; | |||
2373 | ||||
2374 | return method_can_shutdown_or_sleep( | |||
2375 | m, message, | |||
2376 | INHIBIT_SLEEP, | |||
2377 | "org.freedesktop.login1.hibernate", | |||
2378 | "org.freedesktop.login1.hibernate-multiple-sessions", | |||
2379 | "org.freedesktop.login1.hibernate-ignore-inhibit", | |||
2380 | "hybrid-sleep", | |||
2381 | error); | |||
2382 | } | |||
2383 | ||||
2384 | static int method_can_suspend_then_hibernate(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2385 | Manager *m = userdata; | |||
2386 | ||||
2387 | return method_can_shutdown_or_sleep( | |||
2388 | m, message, | |||
2389 | INHIBIT_SLEEP, | |||
2390 | "org.freedesktop.login1.hibernate", | |||
2391 | "org.freedesktop.login1.hibernate-multiple-sessions", | |||
2392 | "org.freedesktop.login1.hibernate-ignore-inhibit", | |||
2393 | "suspend-then-hibernate", | |||
2394 | error); | |||
2395 | } | |||
2396 | ||||
2397 | static int property_get_reboot_to_firmware_setup( | |||
2398 | sd_bus *bus, | |||
2399 | const char *path, | |||
2400 | const char *interface, | |||
2401 | const char *property, | |||
2402 | sd_bus_message *reply, | |||
2403 | void *userdata, | |||
2404 | sd_bus_error *error) { | |||
2405 | int r; | |||
2406 | ||||
2407 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/login/logind-dbus.c", 2407 , __PRETTY_FUNCTION__); } while (0); | |||
2408 | assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("reply"), "../src/login/logind-dbus.c", 2408 , __PRETTY_FUNCTION__); } while (0); | |||
2409 | assert(userdata)do { if ((__builtin_expect(!!(!(userdata)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("userdata"), "../src/login/logind-dbus.c" , 2409, __PRETTY_FUNCTION__); } while (0); | |||
2410 | ||||
2411 | r = efi_get_reboot_to_firmware(); | |||
2412 | if (r < 0 && r != -EOPNOTSUPP95) | |||
2413 | log_warning_errno(r, "Failed to determine reboot-to-firmware state: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2413, __func__, "Failed to determine reboot-to-firmware state: %m" ) : -abs(_e); }); | |||
2414 | ||||
2415 | return sd_bus_message_append(reply, "b", r > 0); | |||
2416 | } | |||
2417 | ||||
2418 | static int method_set_reboot_to_firmware_setup( | |||
2419 | sd_bus_message *message, | |||
2420 | void *userdata, | |||
2421 | sd_bus_error *error) { | |||
2422 | ||||
2423 | int b, r; | |||
2424 | Manager *m = userdata; | |||
2425 | ||||
2426 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2426, __PRETTY_FUNCTION__); } while (0); | |||
2427 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2427 , __PRETTY_FUNCTION__); } while (0); | |||
2428 | ||||
2429 | r = sd_bus_message_read(message, "b", &b); | |||
2430 | if (r < 0) | |||
2431 | return r; | |||
2432 | ||||
2433 | r = bus_verify_polkit_async(message, | |||
2434 | CAP_SYS_ADMIN21, | |||
2435 | "org.freedesktop.login1.set-reboot-to-firmware-setup", | |||
2436 | NULL((void*)0), | |||
2437 | false0, | |||
2438 | UID_INVALID((uid_t) -1), | |||
2439 | &m->polkit_registry, | |||
2440 | error); | |||
2441 | if (r < 0) | |||
2442 | return r; | |||
2443 | if (r == 0) | |||
2444 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
2445 | ||||
2446 | r = efi_set_reboot_to_firmware(b); | |||
2447 | if (r < 0) | |||
2448 | return r; | |||
2449 | ||||
2450 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
2451 | } | |||
2452 | ||||
2453 | static int method_can_reboot_to_firmware_setup( | |||
2454 | sd_bus_message *message, | |||
2455 | void *userdata, | |||
2456 | sd_bus_error *error) { | |||
2457 | ||||
2458 | int r; | |||
2459 | bool_Bool challenge; | |||
2460 | const char *result; | |||
2461 | Manager *m = userdata; | |||
2462 | ||||
2463 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2463, __PRETTY_FUNCTION__); } while (0); | |||
2464 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2464 , __PRETTY_FUNCTION__); } while (0); | |||
2465 | ||||
2466 | r = efi_reboot_to_firmware_supported(); | |||
2467 | if (r < 0) { | |||
2468 | if (r != -EOPNOTSUPP95) | |||
2469 | log_warning_errno(errno, "Failed to determine whether reboot to firmware is supported: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/login/logind-dbus.c", 2469, __func__ , "Failed to determine whether reboot to firmware is supported: %m" ) : -abs(_e); }); | |||
2470 | ||||
2471 | return sd_bus_reply_method_return(message, "s", "na"); | |||
2472 | } | |||
2473 | ||||
2474 | r = bus_test_polkit(message, | |||
2475 | CAP_SYS_ADMIN21, | |||
2476 | "org.freedesktop.login1.set-reboot-to-firmware-setup", | |||
2477 | NULL((void*)0), | |||
2478 | UID_INVALID((uid_t) -1), | |||
2479 | &challenge, | |||
2480 | error); | |||
2481 | if (r < 0) | |||
2482 | return r; | |||
2483 | ||||
2484 | if (r > 0) | |||
2485 | result = "yes"; | |||
2486 | else if (challenge) | |||
2487 | result = "challenge"; | |||
2488 | else | |||
2489 | result = "no"; | |||
2490 | ||||
2491 | return sd_bus_reply_method_return(message, "s", result); | |||
2492 | } | |||
2493 | ||||
2494 | static int method_set_wall_message( | |||
2495 | sd_bus_message *message, | |||
2496 | void *userdata, | |||
2497 | sd_bus_error *error) { | |||
2498 | ||||
2499 | int r; | |||
2500 | Manager *m = userdata; | |||
2501 | char *wall_message; | |||
2502 | unsigned enable_wall_messages; | |||
2503 | ||||
2504 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2504, __PRETTY_FUNCTION__); } while (0); | |||
2505 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2505 , __PRETTY_FUNCTION__); } while (0); | |||
2506 | ||||
2507 | r = sd_bus_message_read(message, "sb", &wall_message, &enable_wall_messages); | |||
2508 | if (r < 0) | |||
2509 | return r; | |||
2510 | ||||
2511 | r = bus_verify_polkit_async(message, | |||
2512 | CAP_SYS_ADMIN21, | |||
2513 | "org.freedesktop.login1.set-wall-message", | |||
2514 | NULL((void*)0), | |||
2515 | false0, | |||
2516 | UID_INVALID((uid_t) -1), | |||
2517 | &m->polkit_registry, | |||
2518 | error); | |||
2519 | if (r < 0) | |||
2520 | return r; | |||
2521 | if (r == 0) | |||
2522 | return 1; /* Will call us back */ | |||
2523 | ||||
2524 | r = free_and_strdup(&m->wall_message, empty_to_null(wall_message)); | |||
2525 | if (r < 0) | |||
2526 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/login/logind-dbus.c" , 2526, __func__); | |||
2527 | ||||
2528 | m->enable_wall_messages = enable_wall_messages; | |||
2529 | ||||
2530 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
2531 | } | |||
2532 | ||||
2533 | static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2534 | _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0); | |||
2535 | const char *who, *why, *what, *mode; | |||
2536 | _cleanup_free___attribute__((cleanup(freep))) char *id = NULL((void*)0); | |||
2537 | _cleanup_close___attribute__((cleanup(closep))) int fifo_fd = -1; | |||
2538 | Manager *m = userdata; | |||
2539 | Inhibitor *i = NULL((void*)0); | |||
2540 | InhibitMode mm; | |||
2541 | InhibitWhat w; | |||
2542 | pid_t pid; | |||
2543 | uid_t uid; | |||
2544 | int r; | |||
2545 | ||||
2546 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2546, __PRETTY_FUNCTION__); } while (0); | |||
2547 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2547 , __PRETTY_FUNCTION__); } while (0); | |||
2548 | ||||
2549 | r = sd_bus_message_read(message, "ssss", &what, &who, &why, &mode); | |||
2550 | if (r < 0) | |||
2551 | return r; | |||
2552 | ||||
2553 | w = inhibit_what_from_string(what); | |||
2554 | if (w <= 0) | |||
2555 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid what specification %s", what); | |||
2556 | ||||
2557 | mm = inhibit_mode_from_string(mode); | |||
2558 | if (mm < 0) | |||
2559 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid mode specification %s", mode); | |||
2560 | ||||
2561 | /* Delay is only supported for shutdown/sleep */ | |||
2562 | if (mm == INHIBIT_DELAY && (w & ~(INHIBIT_SHUTDOWN|INHIBIT_SLEEP))) | |||
2563 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Delay inhibitors only supported for shutdown and sleep"); | |||
2564 | ||||
2565 | /* Don't allow taking delay locks while we are already | |||
2566 | * executing the operation. We shouldn't create the impression | |||
2567 | * that the lock was successful if the machine is about to go | |||
2568 | * down/suspend any moment. */ | |||
2569 | if (m->action_what & w) | |||
2570 | return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS"org.freedesktop.login1.OperationInProgress", "The operation inhibition has been requested for is already running"); | |||
2571 | ||||
2572 | r = bus_verify_polkit_async( | |||
2573 | message, | |||
2574 | CAP_SYS_BOOT22, | |||
2575 | w == INHIBIT_SHUTDOWN ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") : | |||
2576 | w == INHIBIT_SLEEP ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-sleep" : "org.freedesktop.login1.inhibit-delay-sleep") : | |||
2577 | w == INHIBIT_IDLE ? "org.freedesktop.login1.inhibit-block-idle" : | |||
2578 | w == INHIBIT_HANDLE_POWER_KEY ? "org.freedesktop.login1.inhibit-handle-power-key" : | |||
2579 | w == INHIBIT_HANDLE_SUSPEND_KEY ? "org.freedesktop.login1.inhibit-handle-suspend-key" : | |||
2580 | w == INHIBIT_HANDLE_HIBERNATE_KEY ? "org.freedesktop.login1.inhibit-handle-hibernate-key" : | |||
2581 | "org.freedesktop.login1.inhibit-handle-lid-switch", | |||
2582 | NULL((void*)0), | |||
2583 | false0, | |||
2584 | UID_INVALID((uid_t) -1), | |||
2585 | &m->polkit_registry, | |||
2586 | error); | |||
2587 | if (r < 0) | |||
2588 | return r; | |||
2589 | if (r == 0) | |||
2590 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
2591 | ||||
2592 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID|SD_BUS_CREDS_PID, &creds); | |||
2593 | if (r < 0) | |||
2594 | return r; | |||
2595 | ||||
2596 | r = sd_bus_creds_get_euid(creds, &uid); | |||
2597 | if (r < 0) | |||
2598 | return r; | |||
2599 | ||||
2600 | r = sd_bus_creds_get_pid(creds, &pid); | |||
2601 | if (r < 0) | |||
2602 | return r; | |||
2603 | ||||
2604 | if (hashmap_size(m->inhibitors) >= m->inhibitors_max) | |||
2605 | return sd_bus_error_setf(error, SD_BUS_ERROR_LIMITS_EXCEEDED"org.freedesktop.DBus.Error.LimitsExceeded", "Maximum number of inhibitors (%" PRIu64"l" "u" ") reached, refusing further inhibitors.", m->inhibitors_max); | |||
2606 | ||||
2607 | do { | |||
2608 | id = mfree(id); | |||
2609 | ||||
2610 | if (asprintf(&id, "%lu", ++m->inhibit_counter) < 0) | |||
2611 | return -ENOMEM12; | |||
2612 | ||||
2613 | } while (hashmap_get(m->inhibitors, id)); | |||
2614 | ||||
2615 | r = manager_add_inhibitor(m, id, &i); | |||
2616 | if (r < 0) | |||
2617 | return r; | |||
2618 | ||||
2619 | i->what = w; | |||
2620 | i->mode = mm; | |||
2621 | i->pid = pid; | |||
2622 | i->uid = uid; | |||
2623 | i->why = strdup(why); | |||
2624 | i->who = strdup(who); | |||
2625 | ||||
2626 | if (!i->why || !i->who) { | |||
2627 | r = -ENOMEM12; | |||
2628 | goto fail; | |||
2629 | } | |||
2630 | ||||
2631 | fifo_fd = inhibitor_create_fifo(i); | |||
2632 | if (fifo_fd < 0) { | |||
2633 | r = fifo_fd; | |||
2634 | goto fail; | |||
2635 | } | |||
2636 | ||||
2637 | inhibitor_start(i); | |||
2638 | ||||
2639 | return sd_bus_reply_method_return(message, "h", fifo_fd); | |||
2640 | ||||
2641 | fail: | |||
2642 | if (i) | |||
2643 | inhibitor_free(i); | |||
2644 | ||||
2645 | return r; | |||
2646 | } | |||
2647 | ||||
2648 | const sd_bus_vtable manager_vtable[] = { | |||
2649 | SD_BUS_VTABLE_START(0){ .type = _SD_BUS_VTABLE_START, .flags = 0, .x = { .start = { .element_size = sizeof(sd_bus_vtable) }, }, }, | |||
2650 | ||||
2651 | SD_BUS_WRITABLE_PROPERTY("EnableWallMessages", "b", NULL, NULL, offsetof(Manager, enable_wall_messages), 0){ .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, .flags = 0, .x = { .property = { .member = "EnableWallMessages", .signature = "b" , .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, enable_wall_messages), }, }, }, | |||
2652 | SD_BUS_WRITABLE_PROPERTY("WallMessage", "s", NULL, NULL, offsetof(Manager, wall_message), 0){ .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, .flags = 0, .x = { .property = { .member = "WallMessage", .signature = "s", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, wall_message), }, }, }, | |||
2653 | ||||
2654 | SD_BUS_PROPERTY("NAutoVTs", "u", NULL, offsetof(Manager, n_autovts), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "NAutoVTs", .signature = "u" , .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, n_autovts), }, }, }, | |||
2655 | SD_BUS_PROPERTY("KillOnlyUsers", "as", NULL, offsetof(Manager, kill_only_users), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "KillOnlyUsers", .signature = "as", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, kill_only_users), }, }, }, | |||
2656 | SD_BUS_PROPERTY("KillExcludeUsers", "as", NULL, offsetof(Manager, kill_exclude_users), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "KillExcludeUsers", .signature = "as", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, kill_exclude_users), }, }, }, | |||
2657 | SD_BUS_PROPERTY("KillUserProcesses", "b", NULL, offsetof(Manager, kill_user_processes), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "KillUserProcesses", .signature = "b", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, kill_user_processes), }, }, }, | |||
2658 | SD_BUS_PROPERTY("RebootToFirmwareSetup", "b", property_get_reboot_to_firmware_setup, 0, SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "RebootToFirmwareSetup", .signature = "b", .get = property_get_reboot_to_firmware_setup, .set = ( (void*)0), .offset = 0, }, }, }, | |||
2659 | SD_BUS_PROPERTY("IdleHint", "b", property_get_idle_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "IdleHint", .signature = "b" , .get = property_get_idle_hint, .set = ((void*)0), .offset = 0, }, }, }, | |||
2660 | SD_BUS_PROPERTY("IdleSinceHint", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "IdleSinceHint", .signature = "t", .get = property_get_idle_since_hint, .set = ((void*)0), .offset = 0, }, }, }, | |||
2661 | SD_BUS_PROPERTY("IdleSinceHintMonotonic", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "IdleSinceHintMonotonic", .signature = "t", .get = property_get_idle_since_hint, .set = ((void*)0 ), .offset = 0, }, }, }, | |||
2662 | SD_BUS_PROPERTY("BlockInhibited", "s", property_get_inhibited, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "BlockInhibited", .signature = "s", .get = property_get_inhibited, .set = ((void*)0), .offset = 0, }, }, }, | |||
2663 | SD_BUS_PROPERTY("DelayInhibited", "s", property_get_inhibited, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "DelayInhibited", .signature = "s", .get = property_get_inhibited, .set = ((void*)0), .offset = 0, }, }, }, | |||
2664 | SD_BUS_PROPERTY("InhibitDelayMaxUSec", "t", NULL, offsetof(Manager, inhibit_delay_max), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "InhibitDelayMaxUSec", .signature = "t", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, inhibit_delay_max), }, }, }, | |||
2665 | SD_BUS_PROPERTY("HandlePowerKey", "s", property_get_handle_action, offsetof(Manager, handle_power_key), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "HandlePowerKey", .signature = "s", .get = property_get_handle_action, .set = ((void*)0), .offset = __builtin_offsetof(Manager, handle_power_key), }, } , }, | |||
2666 | SD_BUS_PROPERTY("HandleSuspendKey", "s", property_get_handle_action, offsetof(Manager, handle_suspend_key), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "HandleSuspendKey", .signature = "s", .get = property_get_handle_action, .set = ((void*)0), .offset = __builtin_offsetof(Manager, handle_suspend_key), } , }, }, | |||
2667 | SD_BUS_PROPERTY("HandleHibernateKey", "s", property_get_handle_action, offsetof(Manager, handle_hibernate_key), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "HandleHibernateKey", .signature = "s", .get = property_get_handle_action, .set = ((void*)0), .offset = __builtin_offsetof(Manager, handle_hibernate_key), }, }, }, | |||
2668 | SD_BUS_PROPERTY("HandleLidSwitch", "s", property_get_handle_action, offsetof(Manager, handle_lid_switch), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "HandleLidSwitch", .signature = "s", .get = property_get_handle_action, .set = ((void*)0), .offset = __builtin_offsetof(Manager, handle_lid_switch), }, }, }, | |||
2669 | SD_BUS_PROPERTY("HandleLidSwitchExternalPower", "s", property_get_handle_action, offsetof(Manager, handle_lid_switch_ep), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "HandleLidSwitchExternalPower" , .signature = "s", .get = property_get_handle_action, .set = ((void*)0), .offset = __builtin_offsetof(Manager, handle_lid_switch_ep ), }, }, }, | |||
2670 | SD_BUS_PROPERTY("HandleLidSwitchDocked", "s", property_get_handle_action, offsetof(Manager, handle_lid_switch_docked), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "HandleLidSwitchDocked", .signature = "s", .get = property_get_handle_action, .set = ((void*)0), .offset = __builtin_offsetof(Manager, handle_lid_switch_docked ), }, }, }, | |||
2671 | SD_BUS_PROPERTY("HoldoffTimeoutUSec", "t", NULL, offsetof(Manager, holdoff_timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "HoldoffTimeoutUSec", .signature = "t", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, holdoff_timeout_usec), }, }, }, | |||
2672 | SD_BUS_PROPERTY("IdleAction", "s", property_get_handle_action, offsetof(Manager, idle_action), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "IdleAction", .signature = "s" , .get = property_get_handle_action, .set = ((void*)0), .offset = __builtin_offsetof(Manager, idle_action), }, }, }, | |||
2673 | SD_BUS_PROPERTY("IdleActionUSec", "t", NULL, offsetof(Manager, idle_action_usec), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "IdleActionUSec", .signature = "t", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, idle_action_usec), }, }, }, | |||
2674 | SD_BUS_PROPERTY("PreparingForShutdown", "b", property_get_preparing, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property = { .member = "PreparingForShutdown", .signature = "b", .get = property_get_preparing, .set = ((void*)0), .offset = 0, }, }, }, | |||
2675 | SD_BUS_PROPERTY("PreparingForSleep", "b", property_get_preparing, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property = { .member = "PreparingForSleep", .signature = "b", .get = property_get_preparing , .set = ((void*)0), .offset = 0, }, }, }, | |||
2676 | SD_BUS_PROPERTY("ScheduledShutdown", "(st)", property_get_scheduled_shutdown, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property = { .member = "ScheduledShutdown", .signature = "(st)", .get = property_get_scheduled_shutdown, .set = ((void*)0), .offset = 0, }, }, }, | |||
2677 | SD_BUS_PROPERTY("Docked", "b", property_get_docked, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property = { .member = "Docked", .signature = "b", .get = property_get_docked , .set = ((void*)0), .offset = 0, }, }, }, | |||
2678 | SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(Manager, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "RemoveIPC", .signature = "b" , .get = bus_property_get_bool, .set = ((void*)0), .offset = __builtin_offsetof (Manager, remove_ipc), }, }, }, | |||
2679 | SD_BUS_PROPERTY("RuntimeDirectorySize", "t", NULL, offsetof(Manager, runtime_dir_size), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "RuntimeDirectorySize", .signature = "t", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, runtime_dir_size), }, }, }, | |||
2680 | SD_BUS_PROPERTY("InhibitorsMax", "t", NULL, offsetof(Manager, inhibitors_max), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "InhibitorsMax", .signature = "t", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, inhibitors_max), }, }, }, | |||
2681 | SD_BUS_PROPERTY("NCurrentInhibitors", "t", property_get_hashmap_size, offsetof(Manager, inhibitors), 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property = { .member = "NCurrentInhibitors", .signature = "t", .get = property_get_hashmap_size, .set = ((void*)0), .offset = __builtin_offsetof (Manager, inhibitors), }, }, }, | |||
2682 | SD_BUS_PROPERTY("SessionsMax", "t", NULL, offsetof(Manager, sessions_max), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "SessionsMax", .signature = "t" , .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Manager, sessions_max), }, }, }, | |||
2683 | SD_BUS_PROPERTY("NCurrentSessions", "t", property_get_hashmap_size, offsetof(Manager, sessions), 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property = { .member = "NCurrentSessions", .signature = "t", .get = property_get_hashmap_size , .set = ((void*)0), .offset = __builtin_offsetof(Manager, sessions ), }, }, }, | |||
2684 | SD_BUS_PROPERTY("UserTasksMax", "t", property_get_compat_user_tasks_max, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST |SD_BUS_VTABLE_HIDDEN, .x = { .property = { .member = "UserTasksMax" , .signature = "t", .get = property_get_compat_user_tasks_max , .set = ((void*)0), .offset = 0, }, }, }, | |||
2685 | ||||
2686 | SD_BUS_METHOD("GetSession", "s", "o", method_get_session, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "GetSession", .signature = "s" , .result = "o", .handler = method_get_session, .offset = 0, } , }, }, | |||
2687 | SD_BUS_METHOD("GetSessionByPID", "u", "o", method_get_session_by_pid, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "GetSessionByPID", .signature = "u", .result = "o", .handler = method_get_session_by_pid, .offset = 0, }, }, }, | |||
2688 | SD_BUS_METHOD("GetUser", "u", "o", method_get_user, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "GetUser", .signature = "u", . result = "o", .handler = method_get_user, .offset = 0, }, }, }, | |||
2689 | SD_BUS_METHOD("GetUserByPID", "u", "o", method_get_user_by_pid, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "GetUserByPID", .signature = "u" , .result = "o", .handler = method_get_user_by_pid, .offset = 0, }, }, }, | |||
2690 | SD_BUS_METHOD("GetSeat", "s", "o", method_get_seat, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "GetSeat", .signature = "s", . result = "o", .handler = method_get_seat, .offset = 0, }, }, }, | |||
2691 | SD_BUS_METHOD("ListSessions", NULL, "a(susso)", method_list_sessions, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "ListSessions", .signature = ( (void*)0), .result = "a(susso)", .handler = method_list_sessions , .offset = 0, }, }, }, | |||
2692 | SD_BUS_METHOD("ListUsers", NULL, "a(uso)", method_list_users, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "ListUsers", .signature = ((void *)0), .result = "a(uso)", .handler = method_list_users, .offset = 0, }, }, }, | |||
2693 | SD_BUS_METHOD("ListSeats", NULL, "a(so)", method_list_seats, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "ListSeats", .signature = ((void *)0), .result = "a(so)", .handler = method_list_seats, .offset = 0, }, }, }, | |||
2694 | SD_BUS_METHOD("ListInhibitors", NULL, "a(ssssuu)", method_list_inhibitors, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "ListInhibitors", .signature = ((void*)0), .result = "a(ssssuu)", .handler = method_list_inhibitors , .offset = 0, }, }, }, | |||
2695 | SD_BUS_METHOD("CreateSession", "uusssssussbssa(sv)", "soshusub", method_create_session, 0){ .type = _SD_BUS_VTABLE_METHOD, .flags = 0, .x = { .method = { .member = "CreateSession", .signature = "uusssssussbssa(sv)" , .result = "soshusub", .handler = method_create_session, .offset = 0, }, }, }, | |||
2696 | SD_BUS_METHOD("ReleaseSession", "s", NULL, method_release_session, 0){ .type = _SD_BUS_VTABLE_METHOD, .flags = 0, .x = { .method = { .member = "ReleaseSession", .signature = "s", .result = (( void*)0), .handler = method_release_session, .offset = 0, }, } , }, | |||
2697 | SD_BUS_METHOD("ActivateSession", "s", NULL, method_activate_session, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "ActivateSession", .signature = "s", .result = ((void*)0), .handler = method_activate_session , .offset = 0, }, }, }, | |||
2698 | SD_BUS_METHOD("ActivateSessionOnSeat", "ss", NULL, method_activate_session_on_seat, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "ActivateSessionOnSeat", .signature = "ss", .result = ((void*)0), .handler = method_activate_session_on_seat , .offset = 0, }, }, }, | |||
2699 | SD_BUS_METHOD("LockSession", "s", NULL, method_lock_session, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "LockSession", .signature = "s" , .result = ((void*)0), .handler = method_lock_session, .offset = 0, }, }, }, | |||
2700 | SD_BUS_METHOD("UnlockSession", "s", NULL, method_lock_session, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "UnlockSession", .signature = "s" , .result = ((void*)0), .handler = method_lock_session, .offset = 0, }, }, }, | |||
2701 | SD_BUS_METHOD("LockSessions", NULL, NULL, method_lock_sessions, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "LockSessions", .signature = ( (void*)0), .result = ((void*)0), .handler = method_lock_sessions , .offset = 0, }, }, }, | |||
2702 | SD_BUS_METHOD("UnlockSessions", NULL, NULL, method_lock_sessions, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "UnlockSessions", .signature = ((void*)0), .result = ((void*)0), .handler = method_lock_sessions , .offset = 0, }, }, }, | |||
2703 | SD_BUS_METHOD("KillSession", "ssi", NULL, method_kill_session, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "KillSession", .signature = "ssi" , .result = ((void*)0), .handler = method_kill_session, .offset = 0, }, }, }, | |||
2704 | SD_BUS_METHOD("KillUser", "ui", NULL, method_kill_user, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "KillUser", .signature = "ui", .result = ((void*)0), .handler = method_kill_user, .offset = 0, }, }, }, | |||
2705 | SD_BUS_METHOD("TerminateSession", "s", NULL, method_terminate_session, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "TerminateSession", .signature = "s", .result = ((void*)0), .handler = method_terminate_session , .offset = 0, }, }, }, | |||
2706 | SD_BUS_METHOD("TerminateUser", "u", NULL, method_terminate_user, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "TerminateUser", .signature = "u" , .result = ((void*)0), .handler = method_terminate_user, .offset = 0, }, }, }, | |||
2707 | SD_BUS_METHOD("TerminateSeat", "s", NULL, method_terminate_seat, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "TerminateSeat", .signature = "s" , .result = ((void*)0), .handler = method_terminate_seat, .offset = 0, }, }, }, | |||
2708 | SD_BUS_METHOD("SetUserLinger", "ubb", NULL, method_set_user_linger, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "SetUserLinger", .signature = "ubb" , .result = ((void*)0), .handler = method_set_user_linger, .offset = 0, }, }, }, | |||
2709 | SD_BUS_METHOD("AttachDevice", "ssb", NULL, method_attach_device, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "AttachDevice", .signature = "ssb" , .result = ((void*)0), .handler = method_attach_device, .offset = 0, }, }, }, | |||
2710 | SD_BUS_METHOD("FlushDevices", "b", NULL, method_flush_devices, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "FlushDevices", .signature = "b" , .result = ((void*)0), .handler = method_flush_devices, .offset = 0, }, }, }, | |||
2711 | SD_BUS_METHOD("PowerOff", "b", NULL, method_poweroff, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "PowerOff", .signature = "b", . result = ((void*)0), .handler = method_poweroff, .offset = 0, }, }, }, | |||
2712 | SD_BUS_METHOD("Reboot", "b", NULL, method_reboot, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "Reboot", .signature = "b", .result = ((void*)0), .handler = method_reboot, .offset = 0, }, }, }, | |||
2713 | SD_BUS_METHOD("Halt", "b", NULL, method_halt, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "Halt", .signature = "b", .result = ((void*)0), .handler = method_halt, .offset = 0, }, }, }, | |||
2714 | SD_BUS_METHOD("Suspend", "b", NULL, method_suspend, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "Suspend", .signature = "b", . result = ((void*)0), .handler = method_suspend, .offset = 0, } , }, }, | |||
2715 | SD_BUS_METHOD("Hibernate", "b", NULL, method_hibernate, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "Hibernate", .signature = "b", .result = ((void*)0), .handler = method_hibernate, .offset = 0, }, }, }, | |||
2716 | SD_BUS_METHOD("HybridSleep", "b", NULL, method_hybrid_sleep, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "HybridSleep", .signature = "b" , .result = ((void*)0), .handler = method_hybrid_sleep, .offset = 0, }, }, }, | |||
2717 | SD_BUS_METHOD("SuspendThenHibernate", "b", NULL, method_suspend_then_hibernate, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "SuspendThenHibernate", .signature = "b", .result = ((void*)0), .handler = method_suspend_then_hibernate , .offset = 0, }, }, }, | |||
2718 | SD_BUS_METHOD("CanPowerOff", NULL, "s", method_can_poweroff, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "CanPowerOff", .signature = (( void*)0), .result = "s", .handler = method_can_poweroff, .offset = 0, }, }, }, | |||
2719 | SD_BUS_METHOD("CanReboot", NULL, "s", method_can_reboot, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "CanReboot", .signature = ((void *)0), .result = "s", .handler = method_can_reboot, .offset = 0 , }, }, }, | |||
2720 | SD_BUS_METHOD("CanHalt", NULL, "s", method_can_halt, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "CanHalt", .signature = ((void *)0), .result = "s", .handler = method_can_halt, .offset = 0, }, }, }, | |||
2721 | SD_BUS_METHOD("CanSuspend", NULL, "s", method_can_suspend, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "CanSuspend", .signature = ((void *)0), .result = "s", .handler = method_can_suspend, .offset = 0, }, }, }, | |||
2722 | SD_BUS_METHOD("CanHibernate", NULL, "s", method_can_hibernate, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "CanHibernate", .signature = ( (void*)0), .result = "s", .handler = method_can_hibernate, .offset = 0, }, }, }, | |||
2723 | SD_BUS_METHOD("CanHybridSleep", NULL, "s", method_can_hybrid_sleep, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "CanHybridSleep", .signature = ((void*)0), .result = "s", .handler = method_can_hybrid_sleep , .offset = 0, }, }, }, | |||
2724 | SD_BUS_METHOD("CanSuspendThenHibernate", NULL, "s", method_can_suspend_then_hibernate, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "CanSuspendThenHibernate", .signature = ((void*)0), .result = "s", .handler = method_can_suspend_then_hibernate , .offset = 0, }, }, }, | |||
2725 | SD_BUS_METHOD("ScheduleShutdown", "st", NULL, method_schedule_shutdown, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "ScheduleShutdown", .signature = "st", .result = ((void*)0), .handler = method_schedule_shutdown , .offset = 0, }, }, }, | |||
2726 | SD_BUS_METHOD("CancelScheduledShutdown", NULL, "b", method_cancel_scheduled_shutdown, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "CancelScheduledShutdown", .signature = ((void*)0), .result = "b", .handler = method_cancel_scheduled_shutdown , .offset = 0, }, }, }, | |||
2727 | SD_BUS_METHOD("Inhibit", "ssss", "h", method_inhibit, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "Inhibit", .signature = "ssss" , .result = "h", .handler = method_inhibit, .offset = 0, }, } , }, | |||
2728 | SD_BUS_METHOD("CanRebootToFirmwareSetup", NULL, "s", method_can_reboot_to_firmware_setup, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "CanRebootToFirmwareSetup", .signature = ((void*)0), .result = "s", .handler = method_can_reboot_to_firmware_setup , .offset = 0, }, }, }, | |||
2729 | SD_BUS_METHOD("SetRebootToFirmwareSetup", "b", NULL, method_set_reboot_to_firmware_setup, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "SetRebootToFirmwareSetup", .signature = "b", .result = ((void*)0), .handler = method_set_reboot_to_firmware_setup , .offset = 0, }, }, }, | |||
2730 | SD_BUS_METHOD("SetWallMessage", "sb", NULL, method_set_wall_message, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "SetWallMessage", .signature = "sb", .result = ((void*)0), .handler = method_set_wall_message , .offset = 0, }, }, }, | |||
2731 | ||||
2732 | SD_BUS_SIGNAL("SessionNew", "so", 0){ .type = _SD_BUS_VTABLE_SIGNAL, .flags = 0, .x = { .signal = { .member = "SessionNew", .signature = "so", }, }, }, | |||
2733 | SD_BUS_SIGNAL("SessionRemoved", "so", 0){ .type = _SD_BUS_VTABLE_SIGNAL, .flags = 0, .x = { .signal = { .member = "SessionRemoved", .signature = "so", }, }, }, | |||
2734 | SD_BUS_SIGNAL("UserNew", "uo", 0){ .type = _SD_BUS_VTABLE_SIGNAL, .flags = 0, .x = { .signal = { .member = "UserNew", .signature = "uo", }, }, }, | |||
2735 | SD_BUS_SIGNAL("UserRemoved", "uo", 0){ .type = _SD_BUS_VTABLE_SIGNAL, .flags = 0, .x = { .signal = { .member = "UserRemoved", .signature = "uo", }, }, }, | |||
2736 | SD_BUS_SIGNAL("SeatNew", "so", 0){ .type = _SD_BUS_VTABLE_SIGNAL, .flags = 0, .x = { .signal = { .member = "SeatNew", .signature = "so", }, }, }, | |||
2737 | SD_BUS_SIGNAL("SeatRemoved", "so", 0){ .type = _SD_BUS_VTABLE_SIGNAL, .flags = 0, .x = { .signal = { .member = "SeatRemoved", .signature = "so", }, }, }, | |||
2738 | SD_BUS_SIGNAL("PrepareForShutdown", "b", 0){ .type = _SD_BUS_VTABLE_SIGNAL, .flags = 0, .x = { .signal = { .member = "PrepareForShutdown", .signature = "b", }, }, }, | |||
2739 | SD_BUS_SIGNAL("PrepareForSleep", "b", 0){ .type = _SD_BUS_VTABLE_SIGNAL, .flags = 0, .x = { .signal = { .member = "PrepareForSleep", .signature = "b", }, }, }, | |||
2740 | ||||
2741 | SD_BUS_VTABLE_END{ .type = _SD_BUS_VTABLE_END, .flags = 0, .x = { { 0 } }, } | |||
2742 | }; | |||
2743 | ||||
2744 | static int session_jobs_reply(Session *s, const char *unit, const char *result) { | |||
2745 | int r = 0; | |||
2746 | ||||
2747 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/login/logind-dbus.c", 2747 , __PRETTY_FUNCTION__); } while (0); | |||
2748 | assert(unit)do { if ((__builtin_expect(!!(!(unit)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit"), "../src/login/logind-dbus.c", 2748 , __PRETTY_FUNCTION__); } while (0); | |||
2749 | ||||
2750 | if (!s->started) | |||
2751 | return r; | |||
2752 | ||||
2753 | if (streq(result, "done")(strcmp((result),("done")) == 0)) | |||
2754 | r = session_send_create_reply(s, NULL((void*)0)); | |||
2755 | else { | |||
2756 | _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error e = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0}); | |||
2757 | ||||
2758 | sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED"org.freedesktop.systemd1.JobFailed", "Start job for unit %s failed with '%s'", unit, result); | |||
2759 | r = session_send_create_reply(s, &e); | |||
2760 | } | |||
2761 | ||||
2762 | return r; | |||
2763 | } | |||
2764 | ||||
2765 | int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2766 | const char *path, *result, *unit; | |||
2767 | Manager *m = userdata; | |||
2768 | Session *session; | |||
2769 | uint32_t id; | |||
2770 | User *user; | |||
2771 | int r; | |||
2772 | ||||
2773 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2773, __PRETTY_FUNCTION__); } while (0); | |||
2774 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2774 , __PRETTY_FUNCTION__); } while (0); | |||
2775 | ||||
2776 | r = sd_bus_message_read(message, "uoss", &id, &path, &unit, &result); | |||
2777 | if (r < 0) { | |||
2778 | bus_log_parse_error(r); | |||
2779 | return 0; | |||
2780 | } | |||
2781 | ||||
2782 | if (m->action_job && streq(m->action_job, path)(strcmp((m->action_job),(path)) == 0)) { | |||
2783 | log_info("Operation '%s' finished.", inhibit_what_to_string(m->action_what))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2783, __func__, "Operation '%s' finished." , inhibit_what_to_string(m->action_what)) : -abs(_e); }); | |||
2784 | ||||
2785 | /* Tell people that they now may take a lock again */ | |||
2786 | (void) send_prepare_for(m, m->action_what, false0); | |||
2787 | ||||
2788 | m->action_job = mfree(m->action_job); | |||
2789 | m->action_unit = NULL((void*)0); | |||
2790 | m->action_what = 0; | |||
2791 | return 0; | |||
2792 | } | |||
2793 | ||||
2794 | session = hashmap_get(m->session_units, unit); | |||
2795 | if (session && streq_ptr(path, session->scope_job)) { | |||
2796 | session->scope_job = mfree(session->scope_job); | |||
2797 | session_jobs_reply(session, unit, result); | |||
2798 | ||||
2799 | session_save(session); | |||
2800 | user_save(session->user); | |||
2801 | session_add_to_gc_queue(session); | |||
2802 | } | |||
2803 | ||||
2804 | user = hashmap_get(m->user_units, unit); | |||
2805 | if (user && | |||
2806 | (streq_ptr(path, user->service_job) || | |||
2807 | streq_ptr(path, user->slice_job))) { | |||
2808 | ||||
2809 | if (streq_ptr(path, user->service_job)) | |||
2810 | user->service_job = mfree(user->service_job); | |||
2811 | ||||
2812 | if (streq_ptr(path, user->slice_job)) | |||
2813 | user->slice_job = mfree(user->slice_job); | |||
2814 | ||||
2815 | LIST_FOREACH(sessions_by_user, session, user->sessions)for ((session) = (user->sessions); (session); (session) = ( session)->sessions_by_user_next) | |||
2816 | session_jobs_reply(session, unit, result); | |||
2817 | ||||
2818 | user_save(user); | |||
2819 | user_add_to_gc_queue(user); | |||
2820 | } | |||
2821 | ||||
2822 | return 0; | |||
2823 | } | |||
2824 | ||||
2825 | int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2826 | const char *path, *unit; | |||
2827 | Manager *m = userdata; | |||
2828 | Session *session; | |||
2829 | User *user; | |||
2830 | int r; | |||
2831 | ||||
2832 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2832, __PRETTY_FUNCTION__); } while (0); | |||
2833 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2833 , __PRETTY_FUNCTION__); } while (0); | |||
2834 | ||||
2835 | r = sd_bus_message_read(message, "so", &unit, &path); | |||
2836 | if (r < 0) { | |||
2837 | bus_log_parse_error(r); | |||
2838 | return 0; | |||
2839 | } | |||
2840 | ||||
2841 | session = hashmap_get(m->session_units, unit); | |||
2842 | if (session) | |||
2843 | session_add_to_gc_queue(session); | |||
2844 | ||||
2845 | user = hashmap_get(m->user_units, unit); | |||
2846 | if (user) | |||
2847 | user_add_to_gc_queue(user); | |||
2848 | ||||
2849 | return 0; | |||
2850 | } | |||
2851 | ||||
2852 | int match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2853 | _cleanup_free___attribute__((cleanup(freep))) char *unit = NULL((void*)0); | |||
2854 | Manager *m = userdata; | |||
2855 | const char *path; | |||
2856 | Session *session; | |||
2857 | User *user; | |||
2858 | int r; | |||
2859 | ||||
2860 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2860, __PRETTY_FUNCTION__); } while (0); | |||
2861 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2861 , __PRETTY_FUNCTION__); } while (0); | |||
2862 | ||||
2863 | path = sd_bus_message_get_path(message); | |||
2864 | if (!path) | |||
2865 | return 0; | |||
2866 | ||||
2867 | r = unit_name_from_dbus_path(path, &unit); | |||
2868 | if (r == -EINVAL22) /* not a unit */ | |||
2869 | return 0; | |||
2870 | if (r < 0) { | |||
2871 | log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/login/logind-dbus.c" , 2871, __func__); | |||
2872 | return 0; | |||
2873 | } | |||
2874 | ||||
2875 | session = hashmap_get(m->session_units, unit); | |||
2876 | if (session) | |||
2877 | session_add_to_gc_queue(session); | |||
2878 | ||||
2879 | user = hashmap_get(m->user_units, unit); | |||
2880 | if (user) | |||
2881 | user_add_to_gc_queue(user); | |||
2882 | ||||
2883 | return 0; | |||
2884 | } | |||
2885 | ||||
2886 | int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
2887 | Manager *m = userdata; | |||
2888 | Session *session; | |||
2889 | Iterator i; | |||
2890 | int b, r; | |||
2891 | ||||
2892 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/login/logind-dbus.c" , 2892, __PRETTY_FUNCTION__); } while (0); | |||
2893 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/login/logind-dbus.c", 2893 , __PRETTY_FUNCTION__); } while (0); | |||
2894 | ||||
2895 | r = sd_bus_message_read(message, "b", &b); | |||
2896 | if (r < 0) { | |||
2897 | bus_log_parse_error(r); | |||
2898 | return 0; | |||
2899 | } | |||
2900 | ||||
2901 | if (b) | |||
2902 | return 0; | |||
2903 | ||||
2904 | /* systemd finished reloading, let's recheck all our sessions */ | |||
2905 | log_debug("System manager has been reloaded, rechecking sessions...")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/login/logind-dbus.c", 2905, __func__, "System manager has been reloaded, rechecking sessions..." ) : -abs(_e); }); | |||
2906 | ||||
2907 | HASHMAP_FOREACH(session, m->sessions, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((m->sessions), & (i), (void**)&(session), ((void*)0)); ) | |||
2908 | session_add_to_gc_queue(session); | |||
2909 | ||||
2910 | return 0; | |||
2911 | } | |||
2912 | ||||
2913 | int manager_send_changed(Manager *manager, const char *property, ...) { | |||
2914 | char **l; | |||
2915 | ||||
2916 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 2916, __PRETTY_FUNCTION__); } while (0); | |||
2917 | ||||
2918 | l = strv_from_stdarg_alloca(property)({ char **_l; if (!property) _l = (char**) &property; else { size_t _n; va_list _ap; _n = 1; __builtin_va_start(_ap, property ); while (__builtin_va_arg(_ap, char*)) _n++; __builtin_va_end (_ap); _l = ({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow (sizeof(char*), _n+1))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("!size_multiply_overflow(sizeof(char*), _n+1)"), "../src/login/logind-dbus.c" , 2918, __PRETTY_FUNCTION__); } while (0); (char**) __builtin_alloca (sizeof(char*)*(_n+1)); }); _l[_n = 0] = (char*) property; __builtin_va_start (_ap, property); for (;;) { _l[++_n] = __builtin_va_arg(_ap, char *); if (!_l[_n]) break; } __builtin_va_end(_ap); } _l; }); | |||
2919 | ||||
2920 | return sd_bus_emit_properties_changed_strv( | |||
2921 | manager->bus, | |||
2922 | "/org/freedesktop/login1", | |||
2923 | "org.freedesktop.login1.Manager", | |||
2924 | l); | |||
2925 | } | |||
2926 | ||||
2927 | static int strdup_job(sd_bus_message *reply, char **job) { | |||
2928 | const char *j; | |||
2929 | char *copy; | |||
2930 | int r; | |||
2931 | ||||
2932 | r = sd_bus_message_read(reply, "o", &j); | |||
2933 | if (r < 0) | |||
2934 | return r; | |||
2935 | ||||
2936 | copy = strdup(j); | |||
2937 | if (!copy) | |||
2938 | return -ENOMEM12; | |||
2939 | ||||
2940 | *job = copy; | |||
2941 | return 1; | |||
2942 | } | |||
2943 | ||||
2944 | int manager_start_scope( | |||
2945 | Manager *manager, | |||
2946 | const char *scope, | |||
2947 | pid_t pid, | |||
2948 | const char *slice, | |||
2949 | const char *description, | |||
2950 | const char *after, | |||
2951 | const char *after2, | |||
2952 | sd_bus_message *more_properties, | |||
2953 | sd_bus_error *error, | |||
2954 | char **job) { | |||
2955 | ||||
2956 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *m = NULL((void*)0), *reply = NULL((void*)0); | |||
2957 | int r; | |||
2958 | ||||
2959 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 2959, __PRETTY_FUNCTION__); } while (0); | |||
2960 | assert(scope)do { if ((__builtin_expect(!!(!(scope)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("scope"), "../src/login/logind-dbus.c", 2960 , __PRETTY_FUNCTION__); } while (0); | |||
2961 | assert(pid > 1)do { if ((__builtin_expect(!!(!(pid > 1)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("pid > 1"), "../src/login/logind-dbus.c" , 2961, __PRETTY_FUNCTION__); } while (0); | |||
2962 | assert(job)do { if ((__builtin_expect(!!(!(job)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("job"), "../src/login/logind-dbus.c", 2962 , __PRETTY_FUNCTION__); } while (0); | |||
2963 | ||||
2964 | r = sd_bus_message_new_method_call( | |||
2965 | manager->bus, | |||
2966 | &m, | |||
2967 | "org.freedesktop.systemd1", | |||
2968 | "/org/freedesktop/systemd1", | |||
2969 | "org.freedesktop.systemd1.Manager", | |||
2970 | "StartTransientUnit"); | |||
2971 | if (r < 0) | |||
2972 | return r; | |||
2973 | ||||
2974 | r = sd_bus_message_append(m, "ss", strempty(scope), "fail"); | |||
2975 | if (r < 0) | |||
2976 | return r; | |||
2977 | ||||
2978 | r = sd_bus_message_open_container(m, 'a', "(sv)"); | |||
2979 | if (r < 0) | |||
2980 | return r; | |||
2981 | ||||
2982 | if (!isempty(slice)) { | |||
2983 | r = sd_bus_message_append(m, "(sv)", "Slice", "s", slice); | |||
2984 | if (r < 0) | |||
2985 | return r; | |||
2986 | } | |||
2987 | ||||
2988 | if (!isempty(description)) { | |||
2989 | r = sd_bus_message_append(m, "(sv)", "Description", "s", description); | |||
2990 | if (r < 0) | |||
2991 | return r; | |||
2992 | } | |||
2993 | ||||
2994 | if (!isempty(after)) { | |||
2995 | r = sd_bus_message_append(m, "(sv)", "After", "as", 1, after); | |||
2996 | if (r < 0) | |||
2997 | return r; | |||
2998 | } | |||
2999 | ||||
3000 | if (!isempty(after2)) { | |||
3001 | r = sd_bus_message_append(m, "(sv)", "After", "as", 1, after2); | |||
3002 | if (r < 0) | |||
3003 | return r; | |||
3004 | } | |||
3005 | ||||
3006 | /* Make sure that the session shells are terminated with SIGHUP since bash and friends tend to ignore | |||
3007 | * SIGTERM */ | |||
3008 | r = sd_bus_message_append(m, "(sv)", "SendSIGHUP", "b", true1); | |||
3009 | if (r < 0) | |||
3010 | return r; | |||
3011 | ||||
3012 | r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, pid); | |||
3013 | if (r < 0) | |||
3014 | return r; | |||
3015 | ||||
3016 | /* disable TasksMax= for the session scope, rely on the slice setting for it */ | |||
3017 | r = sd_bus_message_append(m, "(sv)", "TasksMax", "t", (uint64_t)-1); | |||
3018 | if (r < 0) | |||
3019 | return bus_log_create_error(r); | |||
3020 | ||||
3021 | if (more_properties) { | |||
3022 | /* If TasksMax also appears here, it will overwrite the default value set above */ | |||
3023 | r = sd_bus_message_copy(m, more_properties, true1); | |||
3024 | if (r < 0) | |||
3025 | return r; | |||
3026 | } | |||
3027 | ||||
3028 | r = sd_bus_message_close_container(m); | |||
3029 | if (r < 0) | |||
3030 | return r; | |||
3031 | ||||
3032 | r = sd_bus_message_append(m, "a(sa(sv))", 0); | |||
3033 | if (r < 0) | |||
3034 | return r; | |||
3035 | ||||
3036 | r = sd_bus_call(manager->bus, m, 0, error, &reply); | |||
3037 | if (r < 0) | |||
3038 | return r; | |||
3039 | ||||
3040 | return strdup_job(reply, job); | |||
3041 | } | |||
3042 | ||||
3043 | int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job) { | |||
3044 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0); | |||
3045 | int r; | |||
3046 | ||||
3047 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 3047, __PRETTY_FUNCTION__); } while (0); | |||
3048 | assert(unit)do { if ((__builtin_expect(!!(!(unit)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit"), "../src/login/logind-dbus.c", 3048 , __PRETTY_FUNCTION__); } while (0); | |||
3049 | assert(job)do { if ((__builtin_expect(!!(!(job)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("job"), "../src/login/logind-dbus.c", 3049 , __PRETTY_FUNCTION__); } while (0); | |||
3050 | ||||
3051 | r = sd_bus_call_method( | |||
3052 | manager->bus, | |||
3053 | "org.freedesktop.systemd1", | |||
3054 | "/org/freedesktop/systemd1", | |||
3055 | "org.freedesktop.systemd1.Manager", | |||
3056 | "StartUnit", | |||
3057 | error, | |||
3058 | &reply, | |||
3059 | "ss", unit, "replace"); | |||
3060 | if (r < 0) | |||
3061 | return r; | |||
3062 | ||||
3063 | return strdup_job(reply, job); | |||
3064 | } | |||
3065 | ||||
3066 | int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job) { | |||
3067 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0); | |||
3068 | int r; | |||
3069 | ||||
3070 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 3070, __PRETTY_FUNCTION__); } while (0); | |||
3071 | assert(unit)do { if ((__builtin_expect(!!(!(unit)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit"), "../src/login/logind-dbus.c", 3071 , __PRETTY_FUNCTION__); } while (0); | |||
3072 | assert(job)do { if ((__builtin_expect(!!(!(job)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("job"), "../src/login/logind-dbus.c", 3072 , __PRETTY_FUNCTION__); } while (0); | |||
3073 | ||||
3074 | r = sd_bus_call_method( | |||
3075 | manager->bus, | |||
3076 | "org.freedesktop.systemd1", | |||
3077 | "/org/freedesktop/systemd1", | |||
3078 | "org.freedesktop.systemd1.Manager", | |||
3079 | "StopUnit", | |||
3080 | error, | |||
3081 | &reply, | |||
3082 | "ss", unit, "fail"); | |||
3083 | if (r < 0) { | |||
3084 | if (sd_bus_error_has_name(error, BUS_ERROR_NO_SUCH_UNIT"org.freedesktop.systemd1.NoSuchUnit") || | |||
3085 | sd_bus_error_has_name(error, BUS_ERROR_LOAD_FAILED"org.freedesktop.systemd1.LoadFailed")) { | |||
3086 | ||||
3087 | *job = NULL((void*)0); | |||
3088 | sd_bus_error_free(error); | |||
3089 | return 0; | |||
3090 | } | |||
3091 | ||||
3092 | return r; | |||
3093 | } | |||
3094 | ||||
3095 | return strdup_job(reply, job); | |||
3096 | } | |||
3097 | ||||
3098 | int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error) { | |||
3099 | _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0); | |||
3100 | int r; | |||
3101 | ||||
3102 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 3102, __PRETTY_FUNCTION__); } while (0); | |||
3103 | assert(scope)do { if ((__builtin_expect(!!(!(scope)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("scope"), "../src/login/logind-dbus.c", 3103 , __PRETTY_FUNCTION__); } while (0); | |||
3104 | ||||
3105 | path = unit_dbus_path_from_name(scope); | |||
3106 | if (!path) | |||
3107 | return -ENOMEM12; | |||
3108 | ||||
3109 | r = sd_bus_call_method( | |||
3110 | manager->bus, | |||
3111 | "org.freedesktop.systemd1", | |||
3112 | path, | |||
3113 | "org.freedesktop.systemd1.Scope", | |||
3114 | "Abandon", | |||
3115 | error, | |||
3116 | NULL((void*)0), | |||
3117 | NULL((void*)0)); | |||
3118 | if (r < 0) { | |||
3119 | if (sd_bus_error_has_name(error, BUS_ERROR_NO_SUCH_UNIT"org.freedesktop.systemd1.NoSuchUnit") || | |||
3120 | sd_bus_error_has_name(error, BUS_ERROR_LOAD_FAILED"org.freedesktop.systemd1.LoadFailed") || | |||
3121 | sd_bus_error_has_name(error, BUS_ERROR_SCOPE_NOT_RUNNING"org.freedesktop.systemd1.ScopeNotRunning")) { | |||
3122 | sd_bus_error_free(error); | |||
3123 | return 0; | |||
3124 | } | |||
3125 | ||||
3126 | return r; | |||
3127 | } | |||
3128 | ||||
3129 | return 1; | |||
3130 | } | |||
3131 | ||||
3132 | int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error) { | |||
3133 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 3133, __PRETTY_FUNCTION__); } while (0); | |||
3134 | assert(unit)do { if ((__builtin_expect(!!(!(unit)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit"), "../src/login/logind-dbus.c", 3134 , __PRETTY_FUNCTION__); } while (0); | |||
3135 | ||||
3136 | return sd_bus_call_method( | |||
3137 | manager->bus, | |||
3138 | "org.freedesktop.systemd1", | |||
3139 | "/org/freedesktop/systemd1", | |||
3140 | "org.freedesktop.systemd1.Manager", | |||
3141 | "KillUnit", | |||
3142 | error, | |||
3143 | NULL((void*)0), | |||
3144 | "ssi", unit, who == KILL_LEADER ? "main" : "all", signo); | |||
3145 | } | |||
3146 | ||||
3147 | int manager_unit_is_active(Manager *manager, const char *unit) { | |||
3148 | _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0}); | |||
3149 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0); | |||
3150 | _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0); | |||
3151 | const char *state; | |||
3152 | int r; | |||
3153 | ||||
3154 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 3154, __PRETTY_FUNCTION__); } while (0); | |||
3155 | assert(unit)do { if ((__builtin_expect(!!(!(unit)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unit"), "../src/login/logind-dbus.c", 3155 , __PRETTY_FUNCTION__); } while (0); | |||
3156 | ||||
3157 | path = unit_dbus_path_from_name(unit); | |||
3158 | if (!path) | |||
3159 | return -ENOMEM12; | |||
3160 | ||||
3161 | r = sd_bus_get_property( | |||
3162 | manager->bus, | |||
3163 | "org.freedesktop.systemd1", | |||
3164 | path, | |||
3165 | "org.freedesktop.systemd1.Unit", | |||
3166 | "ActiveState", | |||
3167 | &error, | |||
3168 | &reply, | |||
3169 | "s"); | |||
3170 | if (r < 0) { | |||
3171 | /* systemd might have droppped off momentarily, let's | |||
3172 | * not make this an error */ | |||
3173 | if (sd_bus_error_has_name(&error, SD_BUS_ERROR_NO_REPLY"org.freedesktop.DBus.Error.NoReply") || | |||
3174 | sd_bus_error_has_name(&error, SD_BUS_ERROR_DISCONNECTED"org.freedesktop.DBus.Error.Disconnected")) | |||
3175 | return true1; | |||
3176 | ||||
3177 | /* If the unit is already unloaded then it's not | |||
3178 | * active */ | |||
3179 | if (sd_bus_error_has_name(&error, BUS_ERROR_NO_SUCH_UNIT"org.freedesktop.systemd1.NoSuchUnit") || | |||
3180 | sd_bus_error_has_name(&error, BUS_ERROR_LOAD_FAILED"org.freedesktop.systemd1.LoadFailed")) | |||
3181 | return false0; | |||
3182 | ||||
3183 | return r; | |||
3184 | } | |||
3185 | ||||
3186 | r = sd_bus_message_read(reply, "s", &state); | |||
3187 | if (r < 0) | |||
3188 | return -EINVAL22; | |||
3189 | ||||
3190 | return !streq(state, "inactive")(strcmp((state),("inactive")) == 0) && !streq(state, "failed")(strcmp((state),("failed")) == 0); | |||
3191 | } | |||
3192 | ||||
3193 | int manager_job_is_active(Manager *manager, const char *path) { | |||
3194 | _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0}); | |||
3195 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0); | |||
3196 | int r; | |||
3197 | ||||
3198 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/login/logind-dbus.c" , 3198, __PRETTY_FUNCTION__); } while (0); | |||
3199 | assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path"), "../src/login/logind-dbus.c", 3199 , __PRETTY_FUNCTION__); } while (0); | |||
3200 | ||||
3201 | r = sd_bus_get_property( | |||
3202 | manager->bus, | |||
3203 | "org.freedesktop.systemd1", | |||
3204 | path, | |||
3205 | "org.freedesktop.systemd1.Job", | |||
3206 | "State", | |||
3207 | &error, | |||
3208 | &reply, | |||
3209 | "s"); | |||
3210 | if (r < 0) { | |||
3211 | if (sd_bus_error_has_name(&error, SD_BUS_ERROR_NO_REPLY"org.freedesktop.DBus.Error.NoReply") || | |||
3212 | sd_bus_error_has_name(&error, SD_BUS_ERROR_DISCONNECTED"org.freedesktop.DBus.Error.Disconnected")) | |||
3213 | return true1; | |||
3214 | ||||
3215 | if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_OBJECT"org.freedesktop.DBus.Error.UnknownObject")) | |||
3216 | return false0; | |||
3217 | ||||
3218 | return r; | |||
3219 | } | |||
3220 | ||||
3221 | /* We don't actually care about the state really. The fact | |||
3222 | * that we could read the job state is enough for us */ | |||
3223 | ||||
3224 | return true1; | |||
3225 | } |