pty: set XDG_SEAT for childs
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 7 Oct 2012 15:22:26 +0000 (17:22 +0200)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 7 Oct 2012 15:24:52 +0000 (17:24 +0200)
Recent systemd was updated to parse XDG_SEAT in PAM so we can assign
logins to the correct seat.
This patch allows pty users to specify what seat they run on so the PTY
can correctly set the seat variable. If no seat is specified, then
XDG_SEAT is not set so we still allow non-seated logins.
Note that if kmscon_pty is run with XDG_SEAT set, this will also be set
for the client PTY so unset it if you don't want the environment to be
copied to the client (like any environment variable).

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/pty.c
src/pty.h

index bcd832f..b30cda0 100644 (file)
--- a/src/pty.c
+++ b/src/pty.c
@@ -60,6 +60,7 @@ struct kmscon_pty {
 
        char *term;
        char **argv;
+       char *seat;
 };
 
 int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb,
@@ -172,6 +173,22 @@ int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv)
        return 0;
 }
 
+int kmscon_pty_set_seat(struct kmscon_pty *pty, const char *seat)
+{
+       char *t;
+
+       if (!pty || !seat)
+               return -EINVAL;
+
+       t = strdup(seat);
+       if (!t)
+               return -ENOMEM;
+       free(pty->seat);
+       pty->seat = t;
+
+       return 0;
+}
+
 int kmscon_pty_get_fd(struct kmscon_pty *pty)
 {
        if (!pty)
@@ -222,7 +239,7 @@ static void pty_close(struct kmscon_pty *pty, bool user)
 }
 
 static void __attribute__((noreturn))
-exec_child(int pty_master, const char *term, char **argv)
+exec_child(int pty_master, const char *term, char **argv, const char *seat)
 {
        if (!term)
                term = "vt220";
@@ -230,6 +247,8 @@ exec_child(int pty_master, const char *term, char **argv)
                argv = (char*[]){ "/bin/sh", "-l", NULL };
 
        setenv("TERM", term, 1);
+       if (seat)
+               setenv("XDG_SEAT", seat, 1);
        execvp(argv[0], argv);
 
        log_err("failed to exec child %s: %m", argv[0]);
@@ -347,7 +366,7 @@ static int pty_spawn(struct kmscon_pty *pty, int master,
                return -errno;
        case 0:
                setup_child(master, &ws);
-               exec_child(pty->fd, pty->term, pty->argv);
+               exec_child(pty->fd, pty->term, pty->argv, pty->seat);
                exit(EXIT_FAILURE);
        default:
                pty->fd = master;
index b8eef09..6a35ec1 100644 (file)
--- a/src/pty.h
+++ b/src/pty.h
@@ -55,6 +55,7 @@ void kmscon_pty_ref(struct kmscon_pty *pty);
 void kmscon_pty_unref(struct kmscon_pty *pty);
 int kmscon_pty_set_term(struct kmscon_pty *pty, const char *term);
 int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv);
+int kmscon_pty_set_seat(struct kmscon_pty *pty, const char *seat);
 
 int kmscon_pty_get_fd(struct kmscon_pty *pty);
 void kmscon_pty_dispatch(struct kmscon_pty *pty);