]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/loginctl.c
Merge pull request #19766 from keszybz/fuzz-fixes
[thirdparty/systemd.git] / src / login / loginctl.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <errno.h>
4 #include <getopt.h>
5 #include <locale.h>
6 #include <unistd.h>
7
8 #include "sd-bus.h"
9
10 #include "alloc-util.h"
11 #include "bus-error.h"
12 #include "bus-locator.h"
13 #include "bus-map-properties.h"
14 #include "bus-print-properties.h"
15 #include "bus-unit-procs.h"
16 #include "cgroup-show.h"
17 #include "cgroup-util.h"
18 #include "format-table.h"
19 #include "log.h"
20 #include "logs-show.h"
21 #include "macro.h"
22 #include "main-func.h"
23 #include "memory-util.h"
24 #include "pager.h"
25 #include "parse-argument.h"
26 #include "parse-util.h"
27 #include "pretty-print.h"
28 #include "process-util.h"
29 #include "rlimit-util.h"
30 #include "sigbus.h"
31 #include "signal-util.h"
32 #include "spawn-polkit-agent.h"
33 #include "string-table.h"
34 #include "strv.h"
35 #include "sysfs-show.h"
36 #include "terminal-util.h"
37 #include "unit-name.h"
38 #include "user-util.h"
39 #include "verbs.h"
40
41 static char **arg_property = NULL;
42 static BusPrintPropertyFlags arg_print_flags = 0;
43 static bool arg_full = false;
44 static PagerFlags arg_pager_flags = 0;
45 static bool arg_legend = true;
46 static const char *arg_kill_who = NULL;
47 static int arg_signal = SIGTERM;
48 static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
49 static char *arg_host = NULL;
50 static bool arg_ask_password = true;
51 static unsigned arg_lines = 10;
52 static OutputMode arg_output = OUTPUT_SHORT;
53
54 STATIC_DESTRUCTOR_REGISTER(arg_property, strv_freep);
55
56 static OutputFlags get_output_flags(void) {
57
58 return
59 FLAGS_SET(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) * OUTPUT_SHOW_ALL |
60 (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
61 colors_enabled() * OUTPUT_COLOR;
62 }
63
64 static int get_session_path(sd_bus *bus, const char *session_id, sd_bus_error *error, char **path) {
65 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
66 int r;
67 char *ans;
68
69 r = bus_call_method(bus, bus_login_mgr, "GetSession", error, &reply, "s", session_id);
70 if (r < 0)
71 return r;
72
73 r = sd_bus_message_read(reply, "o", &ans);
74 if (r < 0)
75 return r;
76
77 ans = strdup(ans);
78 if (!ans)
79 return -ENOMEM;
80
81 *path = ans;
82 return 0;
83 }
84
85 static int show_table(Table *table, const char *word) {
86 int r;
87
88 assert(table);
89 assert(word);
90
91 if (table_get_rows(table) > 1 || OUTPUT_MODE_IS_JSON(arg_output)) {
92 r = table_set_sort(table, (size_t) 0);
93 if (r < 0)
94 return table_log_sort_error(r);
95
96 table_set_header(table, arg_legend);
97
98 if (OUTPUT_MODE_IS_JSON(arg_output))
99 r = table_print_json(table, NULL, output_mode_to_json_format_flags(arg_output) | JSON_FORMAT_COLOR_AUTO);
100 else
101 r = table_print(table, NULL);
102 if (r < 0)
103 return table_log_print_error(r);
104 }
105
106 if (arg_legend) {
107 if (table_get_rows(table) > 1)
108 printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word);
109 else
110 printf("No %s.\n", word);
111 }
112
113 return 0;
114 }
115
116 static int list_sessions(int argc, char *argv[], void *userdata) {
117 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
118 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
119 _cleanup_(table_unrefp) Table *table = NULL;
120 sd_bus *bus = userdata;
121 int r;
122
123 assert(bus);
124 assert(argv);
125
126 (void) pager_open(arg_pager_flags);
127
128 r = bus_call_method(bus, bus_login_mgr, "ListSessions", &error, &reply, NULL);
129 if (r < 0)
130 return log_error_errno(r, "Failed to list sessions: %s", bus_error_message(&error, r));
131
132 r = sd_bus_message_enter_container(reply, 'a', "(susso)");
133 if (r < 0)
134 return bus_log_parse_error(r);
135
136 table = table_new("session", "uid", "user", "seat", "tty");
137 if (!table)
138 return log_oom();
139
140 /* Right-align the first two fields (since they are numeric) */
141 (void) table_set_align_percent(table, TABLE_HEADER_CELL(0), 100);
142 (void) table_set_align_percent(table, TABLE_HEADER_CELL(1), 100);
143
144 for (;;) {
145 _cleanup_(sd_bus_error_free) sd_bus_error error_tty = SD_BUS_ERROR_NULL;
146 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply_tty = NULL;
147 const char *id, *user, *seat, *object, *tty = NULL;
148 uint32_t uid;
149
150 r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object);
151 if (r < 0)
152 return bus_log_parse_error(r);
153 if (r == 0)
154 break;
155
156 r = sd_bus_get_property(
157 bus,
158 "org.freedesktop.login1",
159 object,
160 "org.freedesktop.login1.Session",
161 "TTY",
162 &error_tty,
163 &reply_tty,
164 "s");
165 if (r < 0)
166 log_warning_errno(r, "Failed to get TTY for session %s: %s", id, bus_error_message(&error_tty, r));
167 else {
168 r = sd_bus_message_read(reply_tty, "s", &tty);
169 if (r < 0)
170 return bus_log_parse_error(r);
171 }
172
173 r = table_add_many(table,
174 TABLE_STRING, id,
175 TABLE_UID, (uid_t) uid,
176 TABLE_STRING, user,
177 TABLE_STRING, seat,
178 TABLE_STRING, strna(tty));
179 if (r < 0)
180 return table_log_add_error(r);
181 }
182
183 r = sd_bus_message_exit_container(reply);
184 if (r < 0)
185 return bus_log_parse_error(r);
186
187 return show_table(table, "sessions");
188 }
189
190 static int list_users(int argc, char *argv[], void *userdata) {
191 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
192 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
193 _cleanup_(table_unrefp) Table *table = NULL;
194 sd_bus *bus = userdata;
195 int r;
196
197 assert(bus);
198 assert(argv);
199
200 (void) pager_open(arg_pager_flags);
201
202 r = bus_call_method(bus, bus_login_mgr, "ListUsers", &error, &reply, NULL);
203 if (r < 0)
204 return log_error_errno(r, "Failed to list users: %s", bus_error_message(&error, r));
205
206 r = sd_bus_message_enter_container(reply, 'a', "(uso)");
207 if (r < 0)
208 return bus_log_parse_error(r);
209
210 table = table_new("uid", "user");
211 if (!table)
212 return log_oom();
213
214 (void) table_set_align_percent(table, TABLE_HEADER_CELL(0), 100);
215
216 for (;;) {
217 const char *user;
218 uint32_t uid;
219
220 r = sd_bus_message_read(reply, "(uso)", &uid, &user, NULL);
221 if (r < 0)
222 return bus_log_parse_error(r);
223 if (r == 0)
224 break;
225
226 r = table_add_many(table,
227 TABLE_UID, (uid_t) uid,
228 TABLE_STRING, user);
229 if (r < 0)
230 return table_log_add_error(r);
231 }
232
233 r = sd_bus_message_exit_container(reply);
234 if (r < 0)
235 return bus_log_parse_error(r);
236
237 return show_table(table, "users");
238 }
239
240 static int list_seats(int argc, char *argv[], void *userdata) {
241 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
242 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
243 _cleanup_(table_unrefp) Table *table = NULL;
244 sd_bus *bus = userdata;
245 int r;
246
247 assert(bus);
248 assert(argv);
249
250 (void) pager_open(arg_pager_flags);
251
252 r = bus_call_method(bus, bus_login_mgr, "ListSeats", &error, &reply, NULL);
253 if (r < 0)
254 return log_error_errno(r, "Failed to list seats: %s", bus_error_message(&error, r));
255
256 r = sd_bus_message_enter_container(reply, 'a', "(so)");
257 if (r < 0)
258 return bus_log_parse_error(r);
259
260 table = table_new("seat");
261 if (!table)
262 return log_oom();
263
264 for (;;) {
265 const char *seat;
266
267 r = sd_bus_message_read(reply, "(so)", &seat, NULL);
268 if (r < 0)
269 return bus_log_parse_error(r);
270 if (r == 0)
271 break;
272
273 r = table_add_cell(table, NULL, TABLE_STRING, seat);
274 if (r < 0)
275 return table_log_add_error(r);
276 }
277
278 r = sd_bus_message_exit_container(reply);
279 if (r < 0)
280 return bus_log_parse_error(r);
281
282 return show_table(table, "seats");
283 }
284
285 static int show_unit_cgroup(sd_bus *bus, const char *interface, const char *unit, pid_t leader) {
286 _cleanup_free_ char *cgroup = NULL;
287 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
288 unsigned c;
289 int r;
290
291 assert(bus);
292 assert(unit);
293
294 r = show_cgroup_get_unit_path_and_warn(bus, unit, &cgroup);
295 if (r < 0)
296 return r;
297
298 if (isempty(cgroup))
299 return 0;
300
301 c = columns();
302 if (c > 18)
303 c -= 18;
304 else
305 c = 0;
306
307 r = unit_show_processes(bus, unit, cgroup, "\t\t ", c, get_output_flags(), &error);
308 if (r == -EBADR) {
309
310 if (arg_transport == BUS_TRANSPORT_REMOTE)
311 return 0;
312
313 /* Fallback for older systemd versions where the GetUnitProcesses() call is not yet available */
314
315 if (cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, cgroup) != 0 && leader <= 0)
316 return 0;
317
318 show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER, cgroup, "\t\t ", c, &leader, leader > 0, get_output_flags());
319 } else if (r < 0)
320 return log_error_errno(r, "Failed to dump process list: %s", bus_error_message(&error, r));
321
322 return 0;
323 }
324
325 typedef struct SessionStatusInfo {
326 const char *id;
327 uid_t uid;
328 const char *name;
329 struct dual_timestamp timestamp;
330 unsigned vtnr;
331 const char *seat;
332 const char *tty;
333 const char *display;
334 bool remote;
335 const char *remote_host;
336 const char *remote_user;
337 const char *service;
338 pid_t leader;
339 const char *type;
340 const char *class;
341 const char *state;
342 const char *scope;
343 const char *desktop;
344 } SessionStatusInfo;
345
346 typedef struct UserStatusInfo {
347 uid_t uid;
348 bool linger;
349 const char *name;
350 struct dual_timestamp timestamp;
351 const char *state;
352 char **sessions;
353 const char *display;
354 const char *slice;
355 } UserStatusInfo;
356
357 typedef struct SeatStatusInfo {
358 const char *id;
359 const char *active_session;
360 char **sessions;
361 } SeatStatusInfo;
362
363 static void user_status_info_clear(UserStatusInfo *info) {
364 if (info) {
365 strv_free(info->sessions);
366 zero(*info);
367 }
368 }
369
370 static void seat_status_info_clear(SeatStatusInfo *info) {
371 if (info) {
372 strv_free(info->sessions);
373 zero(*info);
374 }
375 }
376
377 static int prop_map_first_of_struct(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
378 const char *contents;
379 int r;
380
381 r = sd_bus_message_peek_type(m, NULL, &contents);
382 if (r < 0)
383 return r;
384
385 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_STRUCT, contents);
386 if (r < 0)
387 return r;
388
389 r = sd_bus_message_read_basic(m, contents[0], userdata);
390 if (r < 0)
391 return r;
392
393 r = sd_bus_message_skip(m, contents+1);
394 if (r < 0)
395 return r;
396
397 r = sd_bus_message_exit_container(m);
398 if (r < 0)
399 return r;
400
401 return 0;
402 }
403
404 static int prop_map_sessions_strv(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
405 const char *name;
406 int r;
407
408 assert(bus);
409 assert(m);
410
411 r = sd_bus_message_enter_container(m, 'a', "(so)");
412 if (r < 0)
413 return r;
414
415 while ((r = sd_bus_message_read(m, "(so)", &name, NULL)) > 0) {
416 r = strv_extend(userdata, name);
417 if (r < 0)
418 return r;
419 }
420 if (r < 0)
421 return r;
422
423 return sd_bus_message_exit_container(m);
424 }
425
426 static int print_session_status_info(sd_bus *bus, const char *path, bool *new_line) {
427
428 static const struct bus_properties_map map[] = {
429 { "Id", "s", NULL, offsetof(SessionStatusInfo, id) },
430 { "Name", "s", NULL, offsetof(SessionStatusInfo, name) },
431 { "TTY", "s", NULL, offsetof(SessionStatusInfo, tty) },
432 { "Display", "s", NULL, offsetof(SessionStatusInfo, display) },
433 { "RemoteHost", "s", NULL, offsetof(SessionStatusInfo, remote_host) },
434 { "RemoteUser", "s", NULL, offsetof(SessionStatusInfo, remote_user) },
435 { "Service", "s", NULL, offsetof(SessionStatusInfo, service) },
436 { "Desktop", "s", NULL, offsetof(SessionStatusInfo, desktop) },
437 { "Type", "s", NULL, offsetof(SessionStatusInfo, type) },
438 { "Class", "s", NULL, offsetof(SessionStatusInfo, class) },
439 { "Scope", "s", NULL, offsetof(SessionStatusInfo, scope) },
440 { "State", "s", NULL, offsetof(SessionStatusInfo, state) },
441 { "VTNr", "u", NULL, offsetof(SessionStatusInfo, vtnr) },
442 { "Leader", "u", NULL, offsetof(SessionStatusInfo, leader) },
443 { "Remote", "b", NULL, offsetof(SessionStatusInfo, remote) },
444 { "Timestamp", "t", NULL, offsetof(SessionStatusInfo, timestamp.realtime) },
445 { "TimestampMonotonic", "t", NULL, offsetof(SessionStatusInfo, timestamp.monotonic) },
446 { "User", "(uo)", prop_map_first_of_struct, offsetof(SessionStatusInfo, uid) },
447 { "Seat", "(so)", prop_map_first_of_struct, offsetof(SessionStatusInfo, seat) },
448 {}
449 };
450
451 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
452 _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
453 char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
454 char since2[FORMAT_TIMESTAMP_MAX];
455 const char *s1, *s2;
456 SessionStatusInfo i = {};
457 int r;
458
459 r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, BUS_MAP_BOOLEAN_AS_BOOL, &error, &m, &i);
460 if (r < 0)
461 return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
462
463 if (*new_line)
464 printf("\n");
465
466 *new_line = true;
467
468 printf("%s - ", strna(i.id));
469
470 if (i.name)
471 printf("%s (%"PRIu32")\n", i.name, i.uid);
472 else
473 printf("%"PRIu32"\n", i.uid);
474
475 s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
476 s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
477
478 if (s1)
479 printf("\t Since: %s; %s\n", s2, s1);
480 else if (s2)
481 printf("\t Since: %s\n", s2);
482
483 if (i.leader > 0) {
484 _cleanup_free_ char *t = NULL;
485
486 printf("\t Leader: %"PRIu32, i.leader);
487
488 (void) get_process_comm(i.leader, &t);
489 if (t)
490 printf(" (%s)", t);
491
492 printf("\n");
493 }
494
495 if (!isempty(i.seat)) {
496 printf("\t Seat: %s", i.seat);
497
498 if (i.vtnr > 0)
499 printf("; vc%u", i.vtnr);
500
501 printf("\n");
502 }
503
504 if (i.tty)
505 printf("\t TTY: %s\n", i.tty);
506 else if (i.display)
507 printf("\t Display: %s\n", i.display);
508
509 if (i.remote_host && i.remote_user)
510 printf("\t Remote: %s@%s\n", i.remote_user, i.remote_host);
511 else if (i.remote_host)
512 printf("\t Remote: %s\n", i.remote_host);
513 else if (i.remote_user)
514 printf("\t Remote: user %s\n", i.remote_user);
515 else if (i.remote)
516 printf("\t Remote: Yes\n");
517
518 if (i.service) {
519 printf("\t Service: %s", i.service);
520
521 if (i.type)
522 printf("; type %s", i.type);
523
524 if (i.class)
525 printf("; class %s", i.class);
526
527 printf("\n");
528 } else if (i.type) {
529 printf("\t Type: %s", i.type);
530
531 if (i.class)
532 printf("; class %s", i.class);
533
534 printf("\n");
535 } else if (i.class)
536 printf("\t Class: %s\n", i.class);
537
538 if (!isempty(i.desktop))
539 printf("\t Desktop: %s\n", i.desktop);
540
541 if (i.state)
542 printf("\t State: %s\n", i.state);
543
544 if (i.scope) {
545 printf("\t Unit: %s\n", i.scope);
546 show_unit_cgroup(bus, "org.freedesktop.systemd1.Scope", i.scope, i.leader);
547
548 if (arg_transport == BUS_TRANSPORT_LOCAL)
549 show_journal_by_unit(
550 stdout,
551 i.scope,
552 NULL,
553 arg_output,
554 0,
555 i.timestamp.monotonic,
556 arg_lines,
557 0,
558 get_output_flags() | OUTPUT_BEGIN_NEWLINE,
559 SD_JOURNAL_LOCAL_ONLY,
560 true,
561 NULL);
562 }
563
564 return 0;
565 }
566
567 static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line) {
568
569 static const struct bus_properties_map map[] = {
570 { "Name", "s", NULL, offsetof(UserStatusInfo, name) },
571 { "Linger", "b", NULL, offsetof(UserStatusInfo, linger) },
572 { "Slice", "s", NULL, offsetof(UserStatusInfo, slice) },
573 { "State", "s", NULL, offsetof(UserStatusInfo, state) },
574 { "UID", "u", NULL, offsetof(UserStatusInfo, uid) },
575 { "Timestamp", "t", NULL, offsetof(UserStatusInfo, timestamp.realtime) },
576 { "TimestampMonotonic", "t", NULL, offsetof(UserStatusInfo, timestamp.monotonic) },
577 { "Display", "(so)", prop_map_first_of_struct, offsetof(UserStatusInfo, display) },
578 { "Sessions", "a(so)", prop_map_sessions_strv, offsetof(UserStatusInfo, sessions) },
579 {}
580 };
581
582 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
583 _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
584 char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
585 char since2[FORMAT_TIMESTAMP_MAX];
586 const char *s1, *s2;
587 _cleanup_(user_status_info_clear) UserStatusInfo i = {};
588 int r;
589
590 r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, BUS_MAP_BOOLEAN_AS_BOOL, &error, &m, &i);
591 if (r < 0)
592 return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
593
594 if (*new_line)
595 printf("\n");
596
597 *new_line = true;
598
599 if (i.name)
600 printf("%s (%"PRIu32")\n", i.name, i.uid);
601 else
602 printf("%"PRIu32"\n", i.uid);
603
604 s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
605 s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
606
607 if (s1)
608 printf("\t Since: %s; %s\n", s2, s1);
609 else if (s2)
610 printf("\t Since: %s\n", s2);
611
612 if (!isempty(i.state))
613 printf("\t State: %s\n", i.state);
614
615 if (!strv_isempty(i.sessions)) {
616 char **l;
617 printf("\tSessions:");
618
619 STRV_FOREACH(l, i.sessions)
620 printf(" %s%s",
621 streq_ptr(*l, i.display) ? "*" : "",
622 *l);
623
624 printf("\n");
625 }
626
627 printf("\t Linger: %s\n", yes_no(i.linger));
628
629 if (i.slice) {
630 printf("\t Unit: %s\n", i.slice);
631 show_unit_cgroup(bus, "org.freedesktop.systemd1.Slice", i.slice, 0);
632
633 show_journal_by_unit(
634 stdout,
635 i.slice,
636 NULL,
637 arg_output,
638 0,
639 i.timestamp.monotonic,
640 arg_lines,
641 0,
642 get_output_flags() | OUTPUT_BEGIN_NEWLINE,
643 SD_JOURNAL_LOCAL_ONLY,
644 true,
645 NULL);
646 }
647
648 return 0;
649 }
650
651 static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line) {
652
653 static const struct bus_properties_map map[] = {
654 { "Id", "s", NULL, offsetof(SeatStatusInfo, id) },
655 { "ActiveSession", "(so)", prop_map_first_of_struct, offsetof(SeatStatusInfo, active_session) },
656 { "Sessions", "a(so)", prop_map_sessions_strv, offsetof(SeatStatusInfo, sessions) },
657 {}
658 };
659
660 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
661 _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
662 _cleanup_(seat_status_info_clear) SeatStatusInfo i = {};
663 int r;
664
665 r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, 0, &error, &m, &i);
666 if (r < 0)
667 return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
668
669 if (*new_line)
670 printf("\n");
671
672 *new_line = true;
673
674 printf("%s\n", strna(i.id));
675
676 if (!strv_isempty(i.sessions)) {
677 char **l;
678 printf("\tSessions:");
679
680 STRV_FOREACH(l, i.sessions) {
681 if (streq_ptr(*l, i.active_session))
682 printf(" *%s", *l);
683 else
684 printf(" %s", *l);
685 }
686
687 printf("\n");
688 }
689
690 if (arg_transport == BUS_TRANSPORT_LOCAL) {
691 unsigned c;
692
693 c = columns();
694 if (c > 21)
695 c -= 21;
696 else
697 c = 0;
698
699 printf("\t Devices:\n");
700
701 show_sysfs(i.id, "\t\t ", c, get_output_flags());
702 }
703
704 return 0;
705 }
706
707 static int print_property(const char *name, const char *expected_value, sd_bus_message *m, BusPrintPropertyFlags flags) {
708 char type;
709 const char *contents;
710 int r;
711
712 assert(name);
713 assert(m);
714
715 r = sd_bus_message_peek_type(m, &type, &contents);
716 if (r < 0)
717 return r;
718
719 switch (type) {
720
721 case SD_BUS_TYPE_STRUCT:
722
723 if (contents[0] == SD_BUS_TYPE_STRING && STR_IN_SET(name, "Display", "Seat", "ActiveSession")) {
724 const char *s;
725
726 r = sd_bus_message_read(m, "(so)", &s, NULL);
727 if (r < 0)
728 return bus_log_parse_error(r);
729
730 bus_print_property_value(name, expected_value, flags, s);
731
732 return 1;
733
734 } else if (contents[0] == SD_BUS_TYPE_UINT32 && streq(name, "User")) {
735 uint32_t uid;
736
737 r = sd_bus_message_read(m, "(uo)", &uid, NULL);
738 if (r < 0)
739 return bus_log_parse_error(r);
740
741 if (!uid_is_valid(uid))
742 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
743 "Invalid user ID: " UID_FMT,
744 uid);
745
746 bus_print_property_valuef(name, expected_value, flags, UID_FMT, uid);
747 return 1;
748 }
749 break;
750
751 case SD_BUS_TYPE_ARRAY:
752
753 if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "Sessions")) {
754 const char *s;
755 bool space = false;
756
757 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(so)");
758 if (r < 0)
759 return bus_log_parse_error(r);
760
761 if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
762 printf("%s=", name);
763
764 while ((r = sd_bus_message_read(m, "(so)", &s, NULL)) > 0) {
765 printf("%s%s", space ? " " : "", s);
766 space = true;
767 }
768
769 if (space || !FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
770 printf("\n");
771
772 if (r < 0)
773 return bus_log_parse_error(r);
774
775 r = sd_bus_message_exit_container(m);
776 if (r < 0)
777 return bus_log_parse_error(r);
778
779 return 1;
780 }
781 break;
782 }
783
784 return 0;
785 }
786
787 static int show_properties(sd_bus *bus, const char *path, bool *new_line) {
788 int r;
789
790 assert(bus);
791 assert(path);
792 assert(new_line);
793
794 if (*new_line)
795 printf("\n");
796
797 *new_line = true;
798
799 r = bus_print_all_properties(
800 bus,
801 "org.freedesktop.login1",
802 path,
803 print_property,
804 arg_property,
805 arg_print_flags,
806 NULL);
807 if (r < 0)
808 return bus_log_parse_error(r);
809
810 return 0;
811 }
812
813 static int show_session(int argc, char *argv[], void *userdata) {
814 bool properties, new_line = false;
815 sd_bus *bus = userdata;
816 int r;
817 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
818 _cleanup_free_ char *path = NULL;
819
820 assert(bus);
821 assert(argv);
822
823 properties = !strstr(argv[0], "status");
824
825 (void) pager_open(arg_pager_flags);
826
827 if (argc <= 1) {
828 /* If no argument is specified inspect the manager itself */
829 if (properties)
830 return show_properties(bus, "/org/freedesktop/login1", &new_line);
831
832 return print_session_status_info(bus, "/org/freedesktop/login1/session/auto", &new_line);
833 }
834
835 for (int i = 1; i < argc; i++) {
836 r = get_session_path(bus, argv[i], &error, &path);
837 if (r < 0)
838 return log_error_errno(r, "Failed to get session path: %s", bus_error_message(&error, r));
839
840 if (properties)
841 r = show_properties(bus, path, &new_line);
842 else
843 r = print_session_status_info(bus, path, &new_line);
844
845 if (r < 0)
846 return r;
847 }
848
849 return 0;
850 }
851
852 static int show_user(int argc, char *argv[], void *userdata) {
853 bool properties, new_line = false;
854 sd_bus *bus = userdata;
855 int r;
856
857 assert(bus);
858 assert(argv);
859
860 properties = !strstr(argv[0], "status");
861
862 (void) pager_open(arg_pager_flags);
863
864 if (argc <= 1) {
865 /* If no argument is specified inspect the manager itself */
866 if (properties)
867 return show_properties(bus, "/org/freedesktop/login1", &new_line);
868
869 return print_user_status_info(bus, "/org/freedesktop/login1/user/self", &new_line);
870 }
871
872 for (int i = 1; i < argc; i++) {
873 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
874 _cleanup_(sd_bus_message_unrefp) sd_bus_message * reply = NULL;
875 const char *path = NULL;
876 uid_t uid;
877
878 r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL, 0);
879 if (r < 0)
880 return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
881
882 r = sd_bus_call_method(
883 bus,
884 "org.freedesktop.login1",
885 "/org/freedesktop/login1",
886 "org.freedesktop.login1.Manager",
887 "GetUser",
888 &error, &reply,
889 "u", (uint32_t) uid);
890 if (r < 0)
891 return log_error_errno(r, "Failed to get user: %s", bus_error_message(&error, r));
892
893 r = sd_bus_message_read(reply, "o", &path);
894 if (r < 0)
895 return bus_log_parse_error(r);
896
897 if (properties)
898 r = show_properties(bus, path, &new_line);
899 else
900 r = print_user_status_info(bus, path, &new_line);
901
902 if (r < 0)
903 return r;
904 }
905
906 return 0;
907 }
908
909 static int show_seat(int argc, char *argv[], void *userdata) {
910 bool properties, new_line = false;
911 sd_bus *bus = userdata;
912 int r;
913
914 assert(bus);
915 assert(argv);
916
917 properties = !strstr(argv[0], "status");
918
919 (void) pager_open(arg_pager_flags);
920
921 if (argc <= 1) {
922 /* If no argument is specified inspect the manager itself */
923 if (properties)
924 return show_properties(bus, "/org/freedesktop/login1", &new_line);
925
926 return print_seat_status_info(bus, "/org/freedesktop/login1/seat/auto", &new_line);
927 }
928
929 for (int i = 1; i < argc; i++) {
930 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
931 _cleanup_(sd_bus_message_unrefp) sd_bus_message * reply = NULL;
932 const char *path = NULL;
933
934 r = bus_call_method(bus, bus_login_mgr, "GetSeat", &error, &reply, "s", argv[i]);
935 if (r < 0)
936 return log_error_errno(r, "Failed to get seat: %s", bus_error_message(&error, r));
937
938 r = sd_bus_message_read(reply, "o", &path);
939 if (r < 0)
940 return bus_log_parse_error(r);
941
942 if (properties)
943 r = show_properties(bus, path, &new_line);
944 else
945 r = print_seat_status_info(bus, path, &new_line);
946
947 if (r < 0)
948 return r;
949 }
950
951 return 0;
952 }
953
954 static int activate(int argc, char *argv[], void *userdata) {
955 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
956 sd_bus *bus = userdata;
957 int r;
958
959 assert(bus);
960 assert(argv);
961
962 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
963
964 if (argc < 2) {
965 r = sd_bus_call_method(
966 bus,
967 "org.freedesktop.login1",
968 "/org/freedesktop/login1/session/auto",
969 "org.freedesktop.login1.Session",
970 streq(argv[0], "lock-session") ? "Lock" :
971 streq(argv[0], "unlock-session") ? "Unlock" :
972 streq(argv[0], "terminate-session") ? "Terminate" :
973 "Activate",
974 &error, NULL, NULL);
975 if (r < 0)
976 return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r));
977
978 return 0;
979 }
980
981 for (int i = 1; i < argc; i++) {
982
983 r = bus_call_method(
984 bus,
985 bus_login_mgr,
986 streq(argv[0], "lock-session") ? "LockSession" :
987 streq(argv[0], "unlock-session") ? "UnlockSession" :
988 streq(argv[0], "terminate-session") ? "TerminateSession" :
989 "ActivateSession",
990 &error, NULL,
991 "s", argv[i]);
992 if (r < 0)
993 return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r));
994 }
995
996 return 0;
997 }
998
999 static int kill_session(int argc, char *argv[], void *userdata) {
1000 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1001 sd_bus *bus = userdata;
1002 int r;
1003
1004 assert(bus);
1005 assert(argv);
1006
1007 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
1008
1009 if (!arg_kill_who)
1010 arg_kill_who = "all";
1011
1012 for (int i = 1; i < argc; i++) {
1013
1014 r = bus_call_method(
1015 bus,
1016 bus_login_mgr,
1017 "KillSession",
1018 &error, NULL,
1019 "ssi", argv[i], arg_kill_who, arg_signal);
1020 if (r < 0)
1021 return log_error_errno(r, "Could not kill session: %s", bus_error_message(&error, r));
1022 }
1023
1024 return 0;
1025 }
1026
1027 static int enable_linger(int argc, char *argv[], void *userdata) {
1028 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1029 sd_bus *bus = userdata;
1030 char* short_argv[3];
1031 bool b;
1032 int r;
1033
1034 assert(bus);
1035 assert(argv);
1036
1037 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
1038
1039 b = streq(argv[0], "enable-linger");
1040
1041 if (argc < 2) {
1042 /* No argument? Let's use an empty user name,
1043 * then logind will use our user. */
1044
1045 short_argv[0] = argv[0];
1046 short_argv[1] = (char*) "";
1047 short_argv[2] = NULL;
1048 argv = short_argv;
1049 argc = 2;
1050 }
1051
1052 for (int i = 1; i < argc; i++) {
1053 uid_t uid;
1054
1055 if (isempty(argv[i]))
1056 uid = UID_INVALID;
1057 else {
1058 r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL, 0);
1059 if (r < 0)
1060 return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
1061 }
1062
1063 r = bus_call_method(
1064 bus,
1065 bus_login_mgr,
1066 "SetUserLinger",
1067 &error, NULL,
1068 "ubb", (uint32_t) uid, b, true);
1069 if (r < 0)
1070 return log_error_errno(r, "Could not enable linger: %s", bus_error_message(&error, r));
1071 }
1072
1073 return 0;
1074 }
1075
1076 static int terminate_user(int argc, char *argv[], void *userdata) {
1077 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1078 sd_bus *bus = userdata;
1079 int r;
1080
1081 assert(bus);
1082 assert(argv);
1083
1084 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
1085
1086 for (int i = 1; i < argc; i++) {
1087 uid_t uid;
1088
1089 if (isempty(argv[i]))
1090 uid = getuid();
1091 else {
1092 const char *u = argv[i];
1093
1094 r = get_user_creds(&u, &uid, NULL, NULL, NULL, 0);
1095 if (r < 0)
1096 return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
1097 }
1098
1099 r = bus_call_method(bus, bus_login_mgr, "TerminateUser", &error, NULL, "u", (uint32_t) uid);
1100 if (r < 0)
1101 return log_error_errno(r, "Could not terminate user: %s", bus_error_message(&error, r));
1102 }
1103
1104 return 0;
1105 }
1106
1107 static int kill_user(int argc, char *argv[], void *userdata) {
1108 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1109 sd_bus *bus = userdata;
1110 int r;
1111
1112 assert(bus);
1113 assert(argv);
1114
1115 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
1116
1117 if (!arg_kill_who)
1118 arg_kill_who = "all";
1119
1120 for (int i = 1; i < argc; i++) {
1121 uid_t uid;
1122
1123 if (isempty(argv[i]))
1124 uid = getuid();
1125 else {
1126 const char *u = argv[i];
1127
1128 r = get_user_creds(&u, &uid, NULL, NULL, NULL, 0);
1129 if (r < 0)
1130 return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
1131 }
1132
1133 r = bus_call_method(
1134 bus,
1135 bus_login_mgr,
1136 "KillUser",
1137 &error, NULL,
1138 "ui", (uint32_t) uid, arg_signal);
1139 if (r < 0)
1140 return log_error_errno(r, "Could not kill user: %s", bus_error_message(&error, r));
1141 }
1142
1143 return 0;
1144 }
1145
1146 static int attach(int argc, char *argv[], void *userdata) {
1147 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1148 sd_bus *bus = userdata;
1149 int r;
1150
1151 assert(bus);
1152 assert(argv);
1153
1154 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
1155
1156 for (int i = 2; i < argc; i++) {
1157
1158 r = bus_call_method(
1159 bus,
1160 bus_login_mgr,
1161 "AttachDevice",
1162 &error, NULL,
1163 "ssb", argv[1], argv[i], true);
1164 if (r < 0)
1165 return log_error_errno(r, "Could not attach device: %s", bus_error_message(&error, r));
1166 }
1167
1168 return 0;
1169 }
1170
1171 static int flush_devices(int argc, char *argv[], void *userdata) {
1172 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1173 sd_bus *bus = userdata;
1174 int r;
1175
1176 assert(bus);
1177 assert(argv);
1178
1179 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
1180
1181 r = bus_call_method(bus, bus_login_mgr, "FlushDevices", &error, NULL, "b", true);
1182 if (r < 0)
1183 return log_error_errno(r, "Could not flush devices: %s", bus_error_message(&error, r));
1184
1185 return 0;
1186 }
1187
1188 static int lock_sessions(int argc, char *argv[], void *userdata) {
1189 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1190 sd_bus *bus = userdata;
1191 int r;
1192
1193 assert(bus);
1194 assert(argv);
1195
1196 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
1197
1198 r = bus_call_method(
1199 bus,
1200 bus_login_mgr,
1201 streq(argv[0], "lock-sessions") ? "LockSessions" : "UnlockSessions",
1202 &error, NULL,
1203 NULL);
1204 if (r < 0)
1205 return log_error_errno(r, "Could not lock sessions: %s", bus_error_message(&error, r));
1206
1207 return 0;
1208 }
1209
1210 static int terminate_seat(int argc, char *argv[], void *userdata) {
1211 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1212 sd_bus *bus = userdata;
1213 int r;
1214
1215 assert(bus);
1216 assert(argv);
1217
1218 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
1219
1220 for (int i = 1; i < argc; i++) {
1221
1222 r = bus_call_method(bus, bus_login_mgr, "TerminateSeat", &error, NULL, "s", argv[i]);
1223 if (r < 0)
1224 return log_error_errno(r, "Could not terminate seat: %s", bus_error_message(&error, r));
1225 }
1226
1227 return 0;
1228 }
1229
1230 static int help(int argc, char *argv[], void *userdata) {
1231 _cleanup_free_ char *link = NULL;
1232 int r;
1233
1234 (void) pager_open(arg_pager_flags);
1235
1236 r = terminal_urlify_man("loginctl", "1", &link);
1237 if (r < 0)
1238 return log_oom();
1239
1240 printf("%s [OPTIONS...] COMMAND ...\n\n"
1241 "%sSend control commands to or query the login manager.%s\n"
1242 "\nSession Commands:\n"
1243 " list-sessions List sessions\n"
1244 " session-status [ID...] Show session status\n"
1245 " show-session [ID...] Show properties of sessions or the manager\n"
1246 " activate [ID] Activate a session\n"
1247 " lock-session [ID...] Screen lock one or more sessions\n"
1248 " unlock-session [ID...] Screen unlock one or more sessions\n"
1249 " lock-sessions Screen lock all current sessions\n"
1250 " unlock-sessions Screen unlock all current sessions\n"
1251 " terminate-session ID... Terminate one or more sessions\n"
1252 " kill-session ID... Send signal to processes of a session\n"
1253 "\nUser Commands:\n"
1254 " list-users List users\n"
1255 " user-status [USER...] Show user status\n"
1256 " show-user [USER...] Show properties of users or the manager\n"
1257 " enable-linger [USER...] Enable linger state of one or more users\n"
1258 " disable-linger [USER...] Disable linger state of one or more users\n"
1259 " terminate-user USER... Terminate all sessions of one or more users\n"
1260 " kill-user USER... Send signal to processes of a user\n"
1261 "\nSeat Commands:\n"
1262 " list-seats List seats\n"
1263 " seat-status [NAME...] Show seat status\n"
1264 " show-seat [NAME...] Show properties of seats or the manager\n"
1265 " attach NAME DEVICE... Attach one or more devices to a seat\n"
1266 " flush-devices Flush all device associations\n"
1267 " terminate-seat NAME... Terminate all sessions on one or more seats\n"
1268 "\nOptions:\n"
1269 " -h --help Show this help\n"
1270 " --version Show package version\n"
1271 " --no-pager Do not pipe output into a pager\n"
1272 " --no-legend Do not show the headers and footers\n"
1273 " --no-ask-password Don't prompt for password\n"
1274 " -H --host=[USER@]HOST Operate on remote host\n"
1275 " -M --machine=CONTAINER Operate on local container\n"
1276 " -p --property=NAME Show only properties by this name\n"
1277 " -P NAME Equivalent to --value --property=NAME\n"
1278 " -a --all Show all properties, including empty ones\n"
1279 " --value When showing properties, only print the value\n"
1280 " -l --full Do not ellipsize output\n"
1281 " --kill-who=WHO Who to send signal to\n"
1282 " -s --signal=SIGNAL Which signal to send\n"
1283 " -n --lines=INTEGER Number of journal entries to show\n"
1284 " -o --output=STRING Change journal output mode (short, short-precise,\n"
1285 " short-iso, short-iso-precise, short-full,\n"
1286 " short-monotonic, short-unix, verbose, export,\n"
1287 " json, json-pretty, json-sse, json-seq, cat,\n"
1288 " with-unit)\n"
1289 "\nSee the %s for details.\n",
1290 program_invocation_short_name,
1291 ansi_highlight(),
1292 ansi_normal(),
1293 link);
1294
1295 return 0;
1296 }
1297
1298 static int parse_argv(int argc, char *argv[]) {
1299 enum {
1300 ARG_VERSION = 0x100,
1301 ARG_VALUE,
1302 ARG_NO_PAGER,
1303 ARG_NO_LEGEND,
1304 ARG_KILL_WHO,
1305 ARG_NO_ASK_PASSWORD,
1306 };
1307
1308 static const struct option options[] = {
1309 { "help", no_argument, NULL, 'h' },
1310 { "version", no_argument, NULL, ARG_VERSION },
1311 { "property", required_argument, NULL, 'p' },
1312 { "all", no_argument, NULL, 'a' },
1313 { "value", no_argument, NULL, ARG_VALUE },
1314 { "full", no_argument, NULL, 'l' },
1315 { "no-pager", no_argument, NULL, ARG_NO_PAGER },
1316 { "no-legend", no_argument, NULL, ARG_NO_LEGEND },
1317 { "kill-who", required_argument, NULL, ARG_KILL_WHO },
1318 { "signal", required_argument, NULL, 's' },
1319 { "host", required_argument, NULL, 'H' },
1320 { "machine", required_argument, NULL, 'M' },
1321 { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
1322 { "lines", required_argument, NULL, 'n' },
1323 { "output", required_argument, NULL, 'o' },
1324 {}
1325 };
1326
1327 int c, r;
1328
1329 assert(argc >= 0);
1330 assert(argv);
1331
1332 while ((c = getopt_long(argc, argv, "hp:P:als:H:M:n:o:", options, NULL)) >= 0)
1333
1334 switch (c) {
1335
1336 case 'h':
1337 return help(0, NULL, NULL);
1338
1339 case ARG_VERSION:
1340 return version();
1341
1342 case 'P':
1343 SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
1344 _fallthrough_;
1345
1346 case 'p': {
1347 r = strv_extend(&arg_property, optarg);
1348 if (r < 0)
1349 return log_oom();
1350
1351 /* If the user asked for a particular
1352 * property, show it to them, even if it is
1353 * empty. */
1354 SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
1355 break;
1356 }
1357
1358 case 'a':
1359 SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
1360 break;
1361
1362 case ARG_VALUE:
1363 SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
1364 break;
1365
1366 case 'l':
1367 arg_full = true;
1368 break;
1369
1370 case 'n':
1371 if (safe_atou(optarg, &arg_lines) < 0)
1372 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
1373 "Failed to parse lines '%s'", optarg);
1374 break;
1375
1376 case 'o':
1377 if (streq(optarg, "help")) {
1378 DUMP_STRING_TABLE(output_mode, OutputMode, _OUTPUT_MODE_MAX);
1379 return 0;
1380 }
1381
1382 arg_output = output_mode_from_string(optarg);
1383 if (arg_output < 0)
1384 return log_error_errno(arg_output, "Unknown output '%s'.", optarg);
1385
1386 if (OUTPUT_MODE_IS_JSON(arg_output))
1387 arg_legend = false;
1388
1389 break;
1390
1391 case ARG_NO_PAGER:
1392 arg_pager_flags |= PAGER_DISABLE;
1393 break;
1394
1395 case ARG_NO_LEGEND:
1396 arg_legend = false;
1397 break;
1398
1399 case ARG_NO_ASK_PASSWORD:
1400 arg_ask_password = false;
1401 break;
1402
1403 case ARG_KILL_WHO:
1404 arg_kill_who = optarg;
1405 break;
1406
1407 case 's':
1408 r = parse_signal_argument(optarg, &arg_signal);
1409 if (r <= 0)
1410 return r;
1411 break;
1412
1413 case 'H':
1414 arg_transport = BUS_TRANSPORT_REMOTE;
1415 arg_host = optarg;
1416 break;
1417
1418 case 'M':
1419 arg_transport = BUS_TRANSPORT_MACHINE;
1420 arg_host = optarg;
1421 break;
1422
1423 case '?':
1424 return -EINVAL;
1425
1426 default:
1427 assert_not_reached("Unhandled option");
1428 }
1429
1430 return 1;
1431 }
1432
1433 static int loginctl_main(int argc, char *argv[], sd_bus *bus) {
1434 static const Verb verbs[] = {
1435 { "help", VERB_ANY, VERB_ANY, 0, help },
1436 { "list-sessions", VERB_ANY, 1, VERB_DEFAULT, list_sessions },
1437 { "session-status", VERB_ANY, VERB_ANY, 0, show_session },
1438 { "show-session", VERB_ANY, VERB_ANY, 0, show_session },
1439 { "activate", VERB_ANY, 2, 0, activate },
1440 { "lock-session", VERB_ANY, VERB_ANY, 0, activate },
1441 { "unlock-session", VERB_ANY, VERB_ANY, 0, activate },
1442 { "lock-sessions", VERB_ANY, 1, 0, lock_sessions },
1443 { "unlock-sessions", VERB_ANY, 1, 0, lock_sessions },
1444 { "terminate-session", 2, VERB_ANY, 0, activate },
1445 { "kill-session", 2, VERB_ANY, 0, kill_session },
1446 { "list-users", VERB_ANY, 1, 0, list_users },
1447 { "user-status", VERB_ANY, VERB_ANY, 0, show_user },
1448 { "show-user", VERB_ANY, VERB_ANY, 0, show_user },
1449 { "enable-linger", VERB_ANY, VERB_ANY, 0, enable_linger },
1450 { "disable-linger", VERB_ANY, VERB_ANY, 0, enable_linger },
1451 { "terminate-user", 2, VERB_ANY, 0, terminate_user },
1452 { "kill-user", 2, VERB_ANY, 0, kill_user },
1453 { "list-seats", VERB_ANY, 1, 0, list_seats },
1454 { "seat-status", VERB_ANY, VERB_ANY, 0, show_seat },
1455 { "show-seat", VERB_ANY, VERB_ANY, 0, show_seat },
1456 { "attach", 3, VERB_ANY, 0, attach },
1457 { "flush-devices", VERB_ANY, 1, 0, flush_devices },
1458 { "terminate-seat", 2, VERB_ANY, 0, terminate_seat },
1459 {}
1460 };
1461
1462 return dispatch_verb(argc, argv, verbs, bus);
1463 }
1464
1465 static int run(int argc, char *argv[]) {
1466 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1467 int r;
1468
1469 setlocale(LC_ALL, "");
1470 log_setup();
1471
1472 /* The journal merging logic potentially needs a lot of fds. */
1473 (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE);
1474
1475 sigbus_install();
1476
1477 r = parse_argv(argc, argv);
1478 if (r <= 0)
1479 return r;
1480
1481 r = bus_connect_transport(arg_transport, arg_host, false, &bus);
1482 if (r < 0)
1483 return bus_log_connect_error(r);
1484
1485 (void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
1486
1487 return loginctl_main(argc, argv, bus);
1488 }
1489
1490 DEFINE_MAIN_FUNCTION(run);