diff options
author | Mantas MikulÄ—nas <grawity@gmail.com> | 2013-12-22 02:48:46 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-21 22:02:57 -0500 |
commit | 5b04fe60004e7c5cd5a43648ede3e6a965e70b8c (patch) | |
tree | 8af2bf059a7aef482afbe3376f64ffc798e17114 /src | |
parent | bee7e928990fd8a0c5909c2022a2b9eede557c81 (diff) |
libsystemd-login: add sd_session_get_remote_{host, user}
Diffstat (limited to 'src')
-rw-r--r-- | src/login/libsystemd-login.sym | 7 | ||||
-rw-r--r-- | src/login/sd-login.c | 28 | ||||
-rw-r--r-- | src/login/test-login.c | 14 | ||||
-rw-r--r-- | src/systemd/sd-login.h | 11 |
4 files changed, 58 insertions, 2 deletions
diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym index 54aa91c609..1d3398253c 100644 --- a/src/login/libsystemd-login.sym +++ b/src/login/libsystemd-login.sym @@ -85,3 +85,10 @@ LIBSYSTEMD_LOGIN_207 { 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; diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 2930b8751f..c795765620 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -254,6 +254,26 @@ _public_ int sd_session_is_active(const char *session) { 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; @@ -364,6 +384,14 @@ _public_ int sd_session_get_display(const char *session, char **display) { 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; diff --git a/src/login/test-login.c b/src/login/test-login.c index 228ddb2933..ce88af80f0 100644 --- a/src/login/test-login.c +++ b/src/login/test-login.c @@ -30,7 +30,7 @@ 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; @@ -71,6 +71,10 @@ static void test_login(void) { 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); @@ -92,6 +96,14 @@ static void test_login(void) { 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); diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h index a230aff4c5..6de6932a75 100644 --- a/src/systemd/sd-login.h +++ b/src/systemd/sd-login.h @@ -95,9 +95,12 @@ int sd_uid_get_sessions(uid_t uid, int require_active, char ***sessions); * 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().) */ @@ -121,6 +124,12 @@ int sd_session_get_class(const char *session, char **clazz); /* 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); |