| 1 |
<?xml version='1.0'?> <!--*-nxml-*--> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="sd-login" conditional='HAVE_PAM' |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>sd-login</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
|
| 14 |
<refmeta> |
| 15 |
<refentrytitle>sd-login</refentrytitle> |
| 16 |
<manvolnum>3</manvolnum> |
| 17 |
</refmeta> |
| 18 |
|
| 19 |
<refnamediv> |
| 20 |
<refname>sd-login</refname> |
| 21 |
<refpurpose>APIs for |
| 22 |
tracking logins</refpurpose> |
| 23 |
</refnamediv> |
| 24 |
|
| 25 |
<refsynopsisdiv> |
| 26 |
<funcsynopsis> |
| 27 |
<funcsynopsisinfo>#include <systemd/sd-login.h></funcsynopsisinfo> |
| 28 |
</funcsynopsis> |
| 29 |
|
| 30 |
<cmdsynopsis> |
| 31 |
<command>pkg-config --cflags --libs libsystemd</command> |
| 32 |
</cmdsynopsis> |
| 33 |
</refsynopsisdiv> |
| 34 |
|
| 35 |
<refsect1> |
| 36 |
<title>Description</title> |
| 37 |
|
| 38 |
<para><filename>sd-login.h</filename> is part of |
| 39 |
<citerefentry><refentrytitle>libsystemd</refentrytitle><manvolnum>3</manvolnum></citerefentry> and |
| 40 |
provides APIs to introspect and monitor seat, login session, and user status information on the local |
| 41 |
system.</para> |
| 42 |
|
| 43 |
<para>Note that these APIs only allow purely passive access and |
| 44 |
monitoring of seats, sessions, and users. To actively make changes |
| 45 |
to the seat configuration, terminate login sessions, or switch |
| 46 |
session on a seat you need to utilize the D-Bus API of |
| 47 |
systemd-logind instead.</para> |
| 48 |
|
| 49 |
<para>These functions synchronously access data in |
| 50 |
<filename>/proc/</filename>, <filename>/sys/fs/cgroup/</filename> |
| 51 |
and <filename>/run/</filename>. All of these are virtual file |
| 52 |
systems, hence the runtime cost of the accesses is relatively |
| 53 |
cheap.</para> |
| 54 |
|
| 55 |
<para>It is possible (and often a very good choice) to mix calls |
| 56 |
to the synchronous interface of <filename>sd-login.h</filename> |
| 57 |
with the asynchronous D-Bus interface of systemd-logind. However, |
| 58 |
if this is done you need to think a bit about possible races since |
| 59 |
the stream of events from D-Bus and from |
| 60 |
<filename>sd-login.h</filename> interfaces such as the login |
| 61 |
monitor are asynchronous and not ordered against each |
| 62 |
other.</para> |
| 63 |
|
| 64 |
<para>If the functions return string arrays, these are generally |
| 65 |
<constant>NULL</constant>-terminated and need to be freed by the |
| 66 |
caller with the libc |
| 67 |
<citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 68 |
call after use, including the strings referenced therein. |
| 69 |
Similarly, individual strings returned need to be freed, as |
| 70 |
well.</para> |
| 71 |
|
| 72 |
<para>As a special exception, instead of an empty string array |
| 73 |
<constant>NULL</constant> may be returned, which should be treated |
| 74 |
equivalent to an empty string array.</para> |
| 75 |
|
| 76 |
<para>See |
| 77 |
<citerefentry><refentrytitle>sd_pid_get_session</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 78 |
<citerefentry><refentrytitle>sd_uid_get_state</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 79 |
<citerefentry><refentrytitle>sd_session_is_active</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 80 |
<citerefentry><refentrytitle>sd_seat_get_active</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 81 |
<citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 82 |
<citerefentry><refentrytitle>sd_login_monitor_new</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 83 |
for more information about the functions |
| 84 |
implemented.</para> |
| 85 |
</refsect1> |
| 86 |
|
| 87 |
<refsect1> |
| 88 |
<title>Definition of Terms</title> |
| 89 |
|
| 90 |
<variablelist> |
| 91 |
<varlistentry> |
| 92 |
<term>seat</term> |
| 93 |
|
| 94 |
<listitem><para>A seat consists of all hardware devices assigned to a specific |
| 95 |
workplace. It consists of at least one graphics device, and usually also includes |
| 96 |
keyboard, mouse. It can also include video cameras, sound cards and more. Seats |
| 97 |
are identified by seat names, which are strings (<= 255 characters), that start |
| 98 |
with the four characters <literal>seat</literal> followed by at least one |
| 99 |
character from the range [a-zA-Z0-9], <literal>_</literal> and |
| 100 |
<literal>-</literal>. They are suitable for use as file names. Seat names may or |
| 101 |
may not be stable and may be reused if a seat becomes available again. |
| 102 |
</para> |
| 103 |
|
| 104 |
<xi:include href="version-info.xml" xpointer="v235"/></listitem> |
| 105 |
</varlistentry> |
| 106 |
|
| 107 |
<varlistentry> |
| 108 |
<term>session</term> |
| 109 |
|
| 110 |
<listitem><para>A session is defined by the time a user is logged in until they |
| 111 |
log out. A session is bound to one or no seats (the latter for 'virtual' ssh |
| 112 |
logins). Multiple sessions can be attached to the same seat, but only one of them |
| 113 |
can be active, the others are in the background. A session is identified by a |
| 114 |
short string.</para> |
| 115 |
|
| 116 |
<para> |
| 117 |
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 118 |
ensures that audit sessions are identical to systemd sessions, and uses the audit |
| 119 |
session ID as session ID in systemd (if auditing is enabled). In general the |
| 120 |
session identifier is a short string consisting only of [a-zA-Z0-9], |
| 121 |
<literal>_</literal> and <literal>-</literal>, suitable for use as a file name. |
| 122 |
Session IDs are unique on the local machine and are |
| 123 |
never reused as long as the machine is online. A user (the way we know it on UNIX) |
| 124 |
corresponds to the person using a computer. A single user can have multiple |
| 125 |
sessions open at the same time. A user is identified by a numeric user id (UID) or |
| 126 |
a user name (a string). A multi-session system allows multiple user sessions on |
| 127 |
the same seat at the same time. A multi-seat system allows multiple independent |
| 128 |
seats that can be individually and simultaneously used by different users.</para> |
| 129 |
|
| 130 |
<xi:include href="version-info.xml" xpointer="v235"/> |
| 131 |
</listitem> |
| 132 |
</varlistentry> |
| 133 |
</variablelist> |
| 134 |
|
| 135 |
<para>All hardware devices that are eligible to being assigned to a seat, are assigned |
| 136 |
to one. A device can be assigned to only one seat at a time. If a device is not |
| 137 |
assigned to any particular other seat it is implicitly assigned to the special default |
| 138 |
seat called <literal>seat0</literal>.</para> |
| 139 |
|
| 140 |
<para>Note that hardware like printers, hard disks or network cards is generally not |
| 141 |
assigned to a specific seat. They are available to all seats equally. (Well, with one |
| 142 |
exception: USB sticks can be assigned to a seat.)</para> |
| 143 |
|
| 144 |
<para><literal>seat0</literal> always exists.</para> |
| 145 |
</refsect1> |
| 146 |
|
| 147 |
<refsect1> |
| 148 |
<title>udev Rules</title> |
| 149 |
|
| 150 |
<para>Assignment of hardware devices to seats is managed inside the udev database, via |
| 151 |
settings on the devices:</para> |
| 152 |
|
| 153 |
<variablelist class='udev-directives'> |
| 154 |
<varlistentry> |
| 155 |
<term>Tag <literal>seat</literal></term> |
| 156 |
|
| 157 |
<listitem><para>When set, a device is eligible to be assigned to a seat. This tag |
| 158 |
is set for graphics devices, mice, keyboards, video cards, sound cards and |
| 159 |
more. Note that some devices like sound cards consist of multiple subdevices |
| 160 |
(i.e. a PCM for input and another one for output). This tag will be set only for |
| 161 |
the originating device, not for the individual subdevices. A UI for configuring |
| 162 |
assignment of devices to seats should enumerate and subscribe to all devices with |
| 163 |
this tag set and show them in the UI. Note that USB hubs can be assigned to a seat |
| 164 |
as well, in which case all (current and future) devices plugged into it will also |
| 165 |
be assigned to the same seat (unless they are explicitly assigned to another |
| 166 |
seat). |
| 167 |
</para> |
| 168 |
|
| 169 |
<xi:include href="version-info.xml" xpointer="v235"/></listitem> |
| 170 |
</varlistentry> |
| 171 |
|
| 172 |
<varlistentry> |
| 173 |
<term>Tag <literal>master-of-seat</literal></term> |
| 174 |
|
| 175 |
<listitem><para>When set, this device is enough for a seat to be considered |
| 176 |
existent. This tag is usually set for the framebuffer device of graphics cards. A |
| 177 |
seat hence consists of an arbitrary number of devices marked with the |
| 178 |
<literal>seat</literal> tag, but (at least) one of these devices needs to be |
| 179 |
tagged with <literal>master-of-seat</literal> before the seat is actually |
| 180 |
considered to be around.</para> |
| 181 |
|
| 182 |
<xi:include href="version-info.xml" xpointer="v235"/></listitem> |
| 183 |
</varlistentry> |
| 184 |
|
| 185 |
<varlistentry> |
| 186 |
<term>Tag <literal>uaccess</literal></term> |
| 187 |
|
| 188 |
<listitem><para>When set, access to this device is tied to an active seat. |
| 189 |
As the session on the seat becomes active or inactive, access to the device |
| 190 |
is updated accordingly.</para></listitem> |
| 191 |
</varlistentry> |
| 192 |
|
| 193 |
<varlistentry> |
| 194 |
<term>Tag <literal>xaccess-*</literal></term> |
| 195 |
|
| 196 |
<listitem><para>When <literal>xaccess-<replaceable>ID</replaceable></literal> |
| 197 |
is set, access to this device is granted to sessions created with |
| 198 |
<literal><replaceable>ID</replaceable></literal> listed in <literal>ExtraDeviceAccess</literal>. |
| 199 |
As the sessions with some <literal>ExtraDeviceAccess</literal> open and close, |
| 200 |
access to the device is updated accordingly.</para> |
| 201 |
|
| 202 |
<xi:include href="version-info.xml" xpointer="v260"/></listitem> |
| 203 |
</varlistentry> |
| 204 |
|
| 205 |
<varlistentry> |
| 206 |
<term>Property <varname>ID_SEAT</varname></term> |
| 207 |
|
| 208 |
<listitem><para>This property specifies the name of the seat a specific device is |
| 209 |
assigned to. If not set the device is assigned to <literal>seat0</literal>. Also, |
| 210 |
to speed up enumeration of hardware belonging to a specific seat, the seat is also |
| 211 |
set as tag on the device. I.e. if the property |
| 212 |
<varname>ID_SEAT=seat-waldo</varname> is set for a device, the tag |
| 213 |
<literal>seat-waldo</literal> will be set as well. Note that if a device is |
| 214 |
assigned to <literal>seat0</literal>, it will usually not carry such a tag and you |
| 215 |
need to enumerate all devices and check the <varname>ID_SEAT</varname> property |
| 216 |
manually. Again, if a device is assigned to seat0 this is visible on the device in |
| 217 |
two ways: with a property <varname>ID_SEAT=seat0</varname> and with no property |
| 218 |
<varname>ID_SEAT</varname> set for it at all.</para> |
| 219 |
|
| 220 |
<xi:include href="version-info.xml" xpointer="v235"/></listitem> |
| 221 |
</varlistentry> |
| 222 |
|
| 223 |
<varlistentry> |
| 224 |
<term>Property <varname>ID_AUTOSEAT</varname></term> |
| 225 |
|
| 226 |
<listitem><para>When set to <literal>1</literal>, this device automatically |
| 227 |
generates a new and independent seat, which is named after the path of the |
| 228 |
device. This is set for specialized USB hubs like the Pluggable devices, which when |
| 229 |
plugged in should create a hotplug seat without further configuration.</para> |
| 230 |
|
| 231 |
<xi:include href="version-info.xml" xpointer="v235"/> |
| 232 |
</listitem> |
| 233 |
</varlistentry> |
| 234 |
|
| 235 |
<varlistentry> |
| 236 |
<term>Property <varname>ID_FOR_SEAT</varname></term> |
| 237 |
|
| 238 |
<listitem><para>When creating additional (manual) seats starting from a graphics |
| 239 |
device this is a good choice to name the seat after. It is created from the path |
| 240 |
of the device. This is useful in UIs for configuring seats: as soon as you create |
| 241 |
a new seat from a graphics device, read this property and prefix it with |
| 242 |
<literal>seat-</literal> and use it as name for the seat.</para> |
| 243 |
|
| 244 |
<xi:include href="version-info.xml" xpointer="v235"/></listitem> |
| 245 |
</varlistentry> |
| 246 |
</variablelist> |
| 247 |
|
| 248 |
<para>A seat exists only and exclusively because a properly tagged device with the |
| 249 |
right <varname>ID_SEAT</varname> property exists. Besides udev rules there is no |
| 250 |
persistent data about seats stored on disk.</para> |
| 251 |
|
| 252 |
<para>Note that |
| 253 |
<citerefentry><refentrytitle>systemd-logind</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 254 |
manages ACLs on a number of device classes, to allow user code to access the device |
| 255 |
nodes attached to a seat as long as the user has an active session on it. This is |
| 256 |
mostly transparent to applications. As mentioned above, for certain user software it |
| 257 |
might be a good idea to watch whether they can access device nodes instead of thinking |
| 258 |
about seats.</para> |
| 259 |
</refsect1> |
| 260 |
|
| 261 |
<xi:include href="libsystemd-pkgconfig.xml" /> |
| 262 |
|
| 263 |
<refsect1> |
| 264 |
<title>See Also</title> |
| 265 |
<para><simplelist type="inline"> |
| 266 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 267 |
<member><citerefentry><refentrytitle>sd_pid_get_session</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 268 |
<member><citerefentry><refentrytitle>sd_uid_get_state</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 269 |
<member><citerefentry><refentrytitle>sd_session_is_active</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 270 |
<member><citerefentry><refentrytitle>sd_seat_get_active</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 271 |
<member><citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 272 |
<member><citerefentry><refentrytitle>sd_login_monitor_new</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 273 |
<member><citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 274 |
<member><citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 275 |
</simplelist></para> |
| 276 |
|
| 277 |
<para> |
| 278 |
<ulink url="https://www.freedesktop.org/wiki/Software/systemd/multiseat">Multi-Seat on Linux</ulink> |
| 279 |
may also be of historical interest. |
| 280 |
</para> |
| 281 |
</refsect1> |
| 282 |
</refentry> |