diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-11-22 07:57:30 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-11-22 07:57:30 +0100 |
commit | d10cd71d3758e56ed7d59e42ec9392fed2573937 (patch) | |
tree | 9afeeb343974009b4fc12572fabd8b92b3858b98 /src | |
parent | m (diff) | |
download | libpassphrase-d10cd71d3758e56ed7d59e42ec9392fed2573937.tar.gz libpassphrase-d10cd71d3758e56ed7d59e42ec9392fed2573937.tar.bz2 libpassphrase-d10cd71d3758e56ed7d59e42ec9392fed2573937.tar.xz |
fix chmod and chown of tty device files
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/cerberus.c | 12 | ||||
-rw-r--r-- | src/cerberus.h | 1 | ||||
-rw-r--r-- | src/security.c | 4 |
3 files changed, 15 insertions, 2 deletions
diff --git a/src/cerberus.c b/src/cerberus.c index f20e600..e52a48f 100644 --- a/src/cerberus.c +++ b/src/cerberus.c @@ -53,6 +53,8 @@ char* passphrase = NULL; */ int main(int argc, char** argv) { + char* tty_device = ttyname(STDIN_FILENO); + do_login(argc, argv); /* Ignore signals */ @@ -63,6 +65,16 @@ int main(int argc, char** argv) while ((wait(NULL) == -1) && (errno == EINTR)) ; + /* Regain access to the terminal */ + if (tty_device) + { + int fd = open(tty_device, O_RDWR | O_NONBLOCK); + if (fd) + dup2(fd, 0); + dup2(fd, 1); + dup2(fd, 2); + } + /* Reset terminal ownership and mode */ chown_tty(0, tty_group, 0); diff --git a/src/cerberus.h b/src/cerberus.h index 5851524..69df492 100644 --- a/src/cerberus.h +++ b/src/cerberus.h @@ -28,6 +28,7 @@ #include <errno.h> #include <stropts.h> #include <termios.h> +#include <fcntl.h> #include <sys/wait.h> #include <sys/ioctl.h> #include <sys/types.h> diff --git a/src/security.c b/src/security.c index 3abd7b4..eb4bd3c 100644 --- a/src/security.c +++ b/src/security.c @@ -132,8 +132,8 @@ void chown_tty(uid_t owner, gid_t group, char with_fail) vcs -= VCS_LEN; vcsa -= VCSA_LEN; - strcpy(vcs, VCS); - strcpy(vcsa, VCSA); + strncpy(vcs, VCS, VCS_LEN); + strncpy(vcsa, VCSA, VCSA_LEN); #ifdef OWN_VCS if (chown(vcs, owner, group) && with_fail) fail("chown"); |