[Toybox] [PATCH] login: chown() of current terminal

William Djupström william at deepztream.com
Sun Feb 3 14:20:09 PST 2019


currently, login leaves the owner and permissions of the controlling tty
intact, likely only writable by root, which means other programs such as
gpg-agent can't run pinentry-curses on that tty.

The attached patch changes the uid and gid to the user login in, and
sets the mode to 600. I'm not sure if this is the best settings, or if
the way util-linux does it is preffered, changing only the owner uid,
and the mode, not the gid.
-------------- next part --------------
>From 20febf96d27b9f09439abf90e2814aad9557cc76 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?William=20Djupstr=C3=B6m?= <william at deepztream.com>
Date: Sun, 3 Feb 2019 23:01:09 +0100
Subject: [PATCH] login: chown() of current terminal

---
 toys/other/login.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/toys/other/login.c b/toys/other/login.c
index 7f9559aa..8c0a35c9 100644
--- a/toys/other/login.c
+++ b/toys/other/login.c
@@ -134,6 +134,9 @@ void login_main(void)
     return;
   }
 
+  chown(ttyname(tty), pwd->pw_uid, pwd->pw_gid);
+  chmod(ttyname(tty), S_IRUSR | S_IWUSR);
+
   xsetuser(pwd);
 
   if (chdir(pwd->pw_dir)) printf("bad $HOME: %s\n", pwd->pw_dir);
-- 
2.20.1



More information about the Toybox mailing list