]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/logind-session.h
polkit: simplify bus_verify_polkit_async() + drop auth-by-cap dbus feature
[thirdparty/systemd.git] / src / login / logind-session.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 typedef struct Session Session;
5 typedef enum KillWho KillWho;
6
7 #include "list.h"
8 #include "login-util.h"
9 #include "logind-user.h"
10 #include "pidref.h"
11 #include "string-util.h"
12
13 typedef enum SessionState {
14 SESSION_OPENING, /* Session scope is being created */
15 SESSION_ONLINE, /* Logged in */
16 SESSION_ACTIVE, /* Logged in and in the fg */
17 SESSION_CLOSING, /* Logged out, but scope is still there */
18 _SESSION_STATE_MAX,
19 _SESSION_STATE_INVALID = -EINVAL,
20 } SessionState;
21
22 typedef enum SessionClass {
23 SESSION_USER,
24 SESSION_GREETER,
25 SESSION_LOCK_SCREEN,
26 SESSION_BACKGROUND,
27 _SESSION_CLASS_MAX,
28 _SESSION_CLASS_INVALID = -EINVAL,
29 } SessionClass;
30
31 typedef enum SessionType {
32 SESSION_UNSPECIFIED,
33 SESSION_TTY,
34 SESSION_X11,
35 SESSION_WAYLAND,
36 SESSION_MIR,
37 SESSION_WEB,
38 _SESSION_TYPE_MAX,
39 _SESSION_TYPE_INVALID = -EINVAL,
40 } SessionType;
41
42 #define SESSION_TYPE_IS_GRAPHICAL(type) IN_SET(type, SESSION_X11, SESSION_WAYLAND, SESSION_MIR)
43
44 enum KillWho {
45 KILL_LEADER,
46 KILL_ALL,
47 _KILL_WHO_MAX,
48 _KILL_WHO_INVALID = -EINVAL,
49 };
50
51 typedef enum TTYValidity {
52 TTY_FROM_PAM,
53 TTY_FROM_UTMP,
54 TTY_UTMP_INCONSISTENT, /* may happen on ssh sessions with multiplexed TTYs */
55 _TTY_VALIDITY_MAX,
56 _TTY_VALIDITY_INVALID = -EINVAL,
57 } TTYValidity;
58
59 struct Session {
60 Manager *manager;
61
62 const char *id;
63 unsigned position;
64 SessionType type;
65 SessionType original_type;
66 SessionClass class;
67
68 char *state_file;
69
70 User *user;
71
72 dual_timestamp timestamp;
73
74 char *display;
75 char *tty;
76 TTYValidity tty_validity;
77
78 bool remote;
79 char *remote_user;
80 char *remote_host;
81 char *service;
82 char *desktop;
83
84 char *scope;
85 char *scope_job;
86
87 Seat *seat;
88 unsigned vtnr;
89 int vtfd;
90
91 PidRef leader;
92 uint32_t audit_id;
93
94 int fifo_fd;
95 char *fifo_path;
96
97 sd_event_source *fifo_event_source;
98 sd_event_source *leader_pidfd_event_source;
99
100 bool idle_hint;
101 dual_timestamp idle_hint_timestamp;
102
103 bool locked_hint;
104
105 bool in_gc_queue:1;
106 bool started:1;
107 bool stopping:1;
108
109 bool was_active:1;
110
111 sd_bus_message *create_message;
112
113 /* Set up when a client requested to release the session via the bus */
114 sd_event_source *timer_event_source;
115
116 char *controller;
117 Hashmap *devices;
118 sd_bus_track *track;
119
120 sd_event_source *stop_on_idle_event_source;
121
122 LIST_FIELDS(Session, sessions_by_user);
123 LIST_FIELDS(Session, sessions_by_seat);
124
125 LIST_FIELDS(Session, gc_queue);
126 };
127
128 int session_new(Session **ret, Manager *m, const char *id);
129 Session* session_free(Session *s);
130
131 DEFINE_TRIVIAL_CLEANUP_FUNC(Session *, session_free);
132
133 void session_set_user(Session *s, User *u);
134 int session_set_leader_consume(Session *s, PidRef _leader);
135 bool session_may_gc(Session *s, bool drop_not_started);
136 void session_add_to_gc_queue(Session *s);
137 int session_activate(Session *s);
138 bool session_is_active(Session *s);
139 int session_get_idle_hint(Session *s, dual_timestamp *t);
140 int session_set_idle_hint(Session *s, bool b);
141 int session_get_locked_hint(Session *s);
142 void session_set_locked_hint(Session *s, bool b);
143 void session_set_type(Session *s, SessionType t);
144 int session_set_display(Session *s, const char *display);
145 int session_set_tty(Session *s, const char *tty);
146 int session_create_fifo(Session *s);
147 int session_watch_pidfd(Session *s);
148 int session_start(Session *s, sd_bus_message *properties, sd_bus_error *error);
149 int session_stop(Session *s, bool force);
150 int session_finalize(Session *s);
151 int session_release(Session *s);
152 int session_save(Session *s);
153 int session_load(Session *s);
154 int session_kill(Session *s, KillWho who, int signo);
155
156 SessionState session_get_state(Session *u);
157
158 const char* session_state_to_string(SessionState t) _const_;
159 SessionState session_state_from_string(const char *s) _pure_;
160
161 const char* session_type_to_string(SessionType t) _const_;
162 SessionType session_type_from_string(const char *s) _pure_;
163
164 const char* session_class_to_string(SessionClass t) _const_;
165 SessionClass session_class_from_string(const char *s) _pure_;
166
167 const char *kill_who_to_string(KillWho k) _const_;
168 KillWho kill_who_from_string(const char *s) _pure_;
169
170 const char* tty_validity_to_string(TTYValidity t) _const_;
171 TTYValidity tty_validity_from_string(const char *s) _pure_;
172
173 void session_leave_vt(Session *s);
174
175 bool session_is_controller(Session *s, const char *sender);
176 int session_set_controller(Session *s, const char *sender, bool force, bool prepare);
177 void session_drop_controller(Session *s);
178
179 static inline bool SESSION_IS_SELF(const char *name) {
180 return isempty(name) || streq(name, "self");
181 }
182
183 static inline bool SESSION_IS_AUTO(const char *name) {
184 return streq_ptr(name, "auto");
185 }