1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id="sd_uid_get_state" conditional='HAVE_PAM'>
27 <title>sd_uid_get_state</title>
28 <productname>systemd</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>sd_uid_get_state</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_uid_get_state</refname>
47 <refname>sd_uid_is_on_seat</refname>
48 <refname>sd_uid_get_sessions</refname>
49 <refname>sd_uid_get_seats</refname>
50 <refname>sd_uid_get_display</refname>
51 <refpurpose>Determine login state of a specific Unix user ID</refpurpose>
56 <funcsynopsisinfo>#include <systemd/sd-login.h></funcsynopsisinfo>
59 <funcdef>int <function>sd_uid_get_state</function></funcdef>
60 <paramdef>uid_t <parameter>uid</parameter></paramdef>
61 <paramdef>char **<parameter>state</parameter></paramdef>
65 <funcdef>int <function>sd_uid_is_on_seat</function></funcdef>
66 <paramdef>uid_t <parameter>uid</parameter></paramdef>
67 <paramdef>int <parameter>require_active</parameter></paramdef>
68 <paramdef>const char *<parameter>seat</parameter></paramdef>
72 <funcdef>int <function>sd_uid_get_sessions</function></funcdef>
73 <paramdef>uid_t <parameter>uid</parameter></paramdef>
74 <paramdef>int <parameter>require_active</parameter></paramdef>
75 <paramdef>char ***<parameter>sessions</parameter></paramdef>
79 <funcdef>int <function>sd_uid_get_seats</function></funcdef>
80 <paramdef>uid_t <parameter>uid</parameter></paramdef>
81 <paramdef>int <parameter>require_active</parameter></paramdef>
82 <paramdef>char ***<parameter>seats</parameter></paramdef>
86 <funcdef>int <function>sd_uid_get_display</function></funcdef>
87 <paramdef>uid_t <parameter>uid</parameter></paramdef>
88 <paramdef>char **<parameter>session</parameter></paramdef>
94 <title>Description</title>
96 <para><function>sd_uid_get_state()</function> may be
97 used to determine the login state of a specific Unix
98 user identifier. The following states are currently
99 known: <literal>offline</literal> (user not logged in
100 at all), <literal>lingering</literal> (user not logged
101 in, but some user services running),
102 <literal>online</literal> (user logged in, but not
103 active, i.e. has no session in the foreground),
104 <literal>active</literal> (user logged in, and has at
105 least one active session, i.e. one session in the
106 foreground), <literal>closing</literal> (user not
107 logged in, and not lingering, but some processes are
108 still around). In the future additional states might
109 be defined, client code should be written to be robust
110 in regards to additional state strings being
111 returned. The returned string needs to be freed with
113 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
114 call after use.</para>
116 <para><function>sd_uid_is_on_seat()</function> may be
117 used to determine whether a specific user is logged in
118 or active on a specific seat. Accepts a Unix user
119 identifier and a seat identifier string as
120 parameters. The <parameter>require_active</parameter>
121 parameter is a boolean value. If non-zero (true), this
122 function will test if the user is active (i.e. has a
123 session that is in the foreground and accepting user
124 input) on the specified seat, otherwise (false) only
125 if the user is logged in (and possibly inactive) on
126 the specified seat.</para>
128 <para><function>sd_uid_get_sessions()</function> may
129 be used to determine the current sessions of the
130 specified user. Accepts a Unix user identifier as
131 parameter. The <parameter>require_active</parameter>
132 parameter controls whether the returned list shall
133 consist of only those sessions where the user is
134 currently active (> 0), where the user is currently
135 online but possibly inactive (= 0), or
136 logged in at all but possibly closing the session (< 0). The call returns a
137 <constant>NULL</constant> terminated string array of session identifiers in
138 <parameter>sessions</parameter> which needs to be
139 freed by the caller with the libc
140 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
141 call after use, including all the strings
142 referenced. If the string array parameter is passed as
143 <constant>NULL</constant>, the array will not be filled in, but the return
144 code still indicates the number of current
145 sessions. Note that instead of an empty array <constant>NULL</constant> may
146 be returned and should be considered equivalent to an
149 <para>Similarly, <function>sd_uid_get_seats()</function>
150 may be used to determine the list of seats on which
151 the user currently has sessions. Similar semantics
152 apply, however note that the user may have
153 multiple sessions on the same seat as well as sessions
154 with no attached seat and hence the number of entries
155 in the returned array may differ from the one returned
156 by <function>sd_uid_get_sessions()</function>.</para>
158 <para><function>sd_uid_get_display()</function>
159 returns the name of the "primary" session of a user.
160 If the user has graphical sessions, it will be the
161 oldest graphical session. Otherwise, it will be the
162 oldest open session.</para>
166 <title>Return Value</title>
169 <function>sd_uid_get_state()</function> returns 0 or a
170 positive integer. If the test succeeds,
171 <function>sd_uid_is_on_seat()</function> returns a
172 positive integer; if it fails,
173 0. <function>sd_uid_get_sessions()</function> and
174 <function>sd_uid_get_seats()</function> return the
175 number of entries in the returned arrays.
176 <function>sd_uid_get_display()</function> returns
177 a non-negative code on success. On failure,
178 these calls return a negative errno-style error
185 <para>Functions described here are available as a
186 shared library, and can be compiled and linked to
188 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
193 <title>History</title>
195 <function>sd_uid_get_state()</function>,
196 <function>sd_uid_is_on_seat()</function>,
197 <function>sd_uid_get_sessions()</function>,
198 and <function>sd_uid_get_seats()</function> functions
199 were added in systemd-31.
201 <para><function>sd_uid_get_display()</function> was
202 added in systemd-213.</para>
206 <title>See Also</title>
209 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
210 <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
211 <citerefentry><refentrytitle>sd_pid_get_owner_uid</refentrytitle><manvolnum>3</manvolnum></citerefentry>