man/sd_seat_can_multi_session.3 \
man/sd_seat_can_tty.3 \
man/sd_seat_get_sessions.3 \
+ man/sd_session_is_remote.3 \
man/sd_session_get_class.3 \
man/sd_session_get_display.3 \
+ man/sd_session_get_remote_host.3 \
+ man/sd_session_get_remote_user.3 \
man/sd_session_get_seat.3 \
man/sd_session_get_service.3 \
man/sd_session_get_state.3 \
man/sd_seat_can_multi_session.3: man/sd_seat_get_active.3
man/sd_seat_can_tty.3: man/sd_seat_get_active.3
man/sd_seat_get_sessions.3: man/sd_seat_get_active.3
+man/sd_session_is_remote.3: man/sd_session_is_active.3
man/sd_session_get_class.3: man/sd_session_is_active.3
man/sd_session_get_display.3: man/sd_session_is_active.3
+man/sd_session_get_remote_host.3: man/sd_session_is_active.3
+man/sd_session_get_remote_user.3: man/sd_session_is_active.3
man/sd_session_get_seat.3: man/sd_session_is_active.3
man/sd_session_get_service.3: man/sd_session_is_active.3
man/sd_session_get_state.3: man/sd_session_is_active.3
man/sd_seat_get_sessions.html: man/sd_seat_get_active.html
$(html-alias)
+man/sd_session_is_remote.html: man/sd_session_is_active.html
+ $(html-alias)
+
man/sd_session_get_class.html: man/sd_session_is_active.html
$(html-alias)
man/sd_session_get_state.html: man/sd_session_is_active.html
$(html-alias)
+man/sd_session_get_remote_host.html: man/sd_session_is_active.html
+ $(html-alias)
+
+man/sd_session_get_remote_user.html: man/sd_session_is_active.html
+ $(html-alias)
+
man/sd_session_get_tty.html: man/sd_session_is_active.html
$(html-alias)
<paramdef>const char* <parameter>session</parameter></paramdef>
</funcprototype>
+ <funcprototype>
+ <funcdef>int <function>sd_session_is_remote</function></funcdef>
+ <paramdef>const char* <parameter>session</parameter></paramdef>
+ </funcprototype>
+
<funcprototype>
<funcdef>int <function>sd_session_get_state</function></funcdef>
<paramdef>const char* <parameter>session</parameter></paramdef>
<paramdef>char** <parameter>display</parameter></paramdef>
</funcprototype>
+ <funcprototype>
+ <funcdef>int <function>sd_session_get_remote_host</function></funcdef>
+ <paramdef>const char* <parameter>session</parameter></paramdef>
+ <paramdef>char** <parameter>remote_host</parameter></paramdef>
+ </funcprototype>
+
+ <funcprototype>
+ <funcdef>int <function>sd_session_get_remote_user</function></funcdef>
+ <paramdef>const char* <parameter>session</parameter></paramdef>
+ <paramdef>char** <parameter>remote_user</parameter></paramdef>
+ </funcprototype>
+
<funcprototype>
<funcdef>int <function>sd_session_get_tty</function></funcdef>
<paramdef>const char* <parameter>session</parameter></paramdef>
(i.e. currently in the foreground and available for
user input) or not.</para>
+ <para><function>sd_session_is_remote()</function> may
+ be used to determine whether the session identified by
+ the specified session identifier is a remote session
+ (i.e. its remote host is known) or not.</para>
+
<para><function>sd_session_get_state()</function> may
be used to determine the state of the session
identified by the specified session identifier. The
<citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
call after use.</para>
+ <para><function>sd_session_get_remote_host()</function>
+ may be used to determine the remote hostname of the
+ session identified by the specified session
+ identifier. The returned string needs to be
+ freed with the libc
+ <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+ call after use.</para>
+
+ <para><function>sd_session_get_remote_user()</function>
+ may be used to determine the remote username of the
+ session identified by the specified session
+ identifier. The returned string needs to be
+ freed with the libc
+ <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+ call after use. Note that this value is rarely known
+ to the system, and even then should not be relied on.</para>
+
<para><function>sd_session_get_tty()</function>
may be used to determine the TTY device of the
session identified by the specified session
<title>Return Value</title>
<para>If the test succeeds,
- <function>sd_session_is_active()</function> returns a
+ <function>sd_session_is_active()</function> and
+ <function>sd_session_is_remote()</function> return a
positive integer, if it fails 0. On success
<function>sd_session_get_state()</function>,
<function>sd_session_get_uid()</function>,
<function>sd_session_get_service()</function>,
<function>sd_session_get_type()</function>,
<function>sd_session_get_class()</function>,
- <function>sd_session_get_display()</function> and
+ <function>sd_session_get_display()</function>,
+ <function>sd_session_get_remote_user()</function>,
+ <function>sd_session_get_remote_host()</function> and
<function>sd_session_get_tty()</function> return 0 or
a positive integer. On failure, these calls return a
negative errno-style error code.</para>
<function>sd_session_get_service()</function>,
<function>sd_session_get_type()</function>,
<function>sd_session_get_class()</function>,
- <function>sd_session_get_display()</function> and
+ <function>sd_session_get_display()</function>,
+ <function>sd_session_get_remote_host()</function>,
+ <function>sd_session_get_remote_user()</function> and
<function>sd_session_get_tty()</function>
interfaces are available as shared library, which can
be compiled and linked to with the
global:
sd_session_get_vt;
} LIBSYSTEMD_LOGIN_205;
+
+LIBSYSTEMD_LOGIN_209 {
+global:
+ sd_session_is_remote;
+ sd_session_get_remote_user;
+ sd_session_get_remote_host;
+} LIBSYSTEMD_LOGIN_207;
return r;
}
+_public_ int sd_session_is_remote(const char *session) {
+ int r;
+ _cleanup_free_ char *p = NULL, *s = NULL;
+
+ r = file_of_session(session, &p);
+ if (r < 0)
+ return r;
+
+ r = parse_env_file(p, NEWLINE, "REMOTE", &s, NULL);
+ if (r < 0)
+ return r;
+
+ if (!s)
+ return -EIO;
+
+ r = parse_boolean(s);
+
+ return r;
+}
+
_public_ int sd_session_get_state(const char *session, char **state) {
_cleanup_free_ char *p = NULL, *s = NULL;
int r;
return session_get_string(session, "DISPLAY", display);
}
+_public_ int sd_session_get_remote_user(const char *session, char **remote_user) {
+ return session_get_string(session, "REMOTE_USER", remote_user);
+}
+
+_public_ int sd_session_get_remote_host(const char *session, char **remote_host) {
+ return session_get_string(session, "REMOTE_HOST", remote_host);
+}
+
static int file_of_seat(const char *seat, char **_p) {
char *p;
int r;
static void test_login(void) {
int r, k;
uid_t u, u2;
- char *seat, *type, *class, *display;
+ char *seat, *type, *class, *display, *remote_user, *remote_host;
char *session;
char *state;
char *session2;
assert_se(r >= 0);
printf("active = %s\n", yes_no(r));
+ r = sd_session_is_remote(session);
+ assert_se(r >= 0);
+ printf("remote = %s\n", yes_no(r));
+
r = sd_session_get_state(session, &state);
assert_se(r >= 0);
printf("state = %s\n", state);
printf("display = %s\n", display);
free(display);
+ assert_se(sd_session_get_remote_user(session, &remote_user) >= 0);
+ printf("remote_user = %s\n", remote_user);
+ free(remote_user);
+
+ assert_se(sd_session_get_remote_host(session, &remote_host) >= 0);
+ printf("remote_host = %s\n", remote_host);
+ free(remote_host);
+
assert_se(sd_session_get_seat(session, &seat) >= 0);
printf("seat = %s\n", seat);
* just return number of seats.*/
int sd_uid_get_seats(uid_t uid, int require_active, char ***seats);
-/* Return 1 if the session is a active. */
+/* Return 1 if the session is active. */
int sd_session_is_active(const char *session);
+/* Return 1 if the session is remote. */
+int sd_session_is_remote(const char *session);
+
/* Get state from session. Possible states: online, active, closing
* (This function is a more generic version of
* sd_session_is_active().) */
/* Determine the X11 display of this session. */
int sd_session_get_display(const char *session, char **display);
+/* Determine the remote host of this session. */
+int sd_session_get_remote_host(const char *session, char **remote_host);
+
+/* Determine the remote user of this session (if provided by PAM). */
+int sd_session_get_remote_user(const char *session, char **remote_user);
+
/* Determine the TTY of this session. */
int sd_session_get_tty(const char *session, char **display);