summaryrefslogtreecommitdiffstats
path: root/pty.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-03-02 23:30:53 +1100
committerDamien Miller <djm@mindrot.org>2000-03-02 23:30:53 +1100
commitc7d8dbbb0dfdeb3f854d58c9bf084db2b72ded77 (patch)
treec3a6eec5473e66ea866bdfd3aa4055325eb63177 /pty.c
parenta22ba0152cebff060be2de75ce2ab52a2442ea73 (diff)
- Applied pty cleanup patch from markus.friedl@informatik.uni-erlangen.de
Diffstat (limited to 'pty.c')
-rw-r--r--pty.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/pty.c b/pty.c
index b3a0535e..de6f751d 100644
--- a/pty.c
+++ b/pty.c
@@ -14,7 +14,7 @@
*/
#include "includes.h"
-RCSID("$Id: pty.c,v 1.11 1999/12/21 00:18:08 damien Exp $");
+RCSID("$Id: pty.c,v 1.12 2000/03/02 12:30:53 damien Exp $");
#ifdef HAVE_UTIL_H
# include <util.h>
@@ -188,9 +188,9 @@ void
pty_release(const char *ttyname)
{
if (chown(ttyname, (uid_t) 0, (gid_t) 0) < 0)
- debug("chown %.100s 0 0 failed: %.100s", ttyname, strerror(errno));
+ error("chown %.100s 0 0 failed: %.100s", ttyname, strerror(errno));
if (chmod(ttyname, (mode_t) 0666) < 0)
- debug("chmod %.100s 0666 failed: %.100s", ttyname, strerror(errno));
+ error("chmod %.100s 0666 failed: %.100s", ttyname, strerror(errno));
}
/* Makes the tty the processes controlling tty and sets it to sane modes. */
@@ -259,3 +259,29 @@ pty_change_window_size(int ptyfd, int row, int col,
w.ws_ypixel = ypixel;
(void) ioctl(ptyfd, TIOCSWINSZ, &w);
}
+
+void
+pty_setowner(struct passwd *pw, const char *ttyname)
+{
+ struct group *grp;
+ gid_t gid;
+ mode_t mode;
+
+ /* Determine the group to make the owner of the tty. */
+ grp = getgrnam("tty");
+ if (grp) {
+ gid = grp->gr_gid;
+ mode = S_IRUSR | S_IWUSR | S_IWGRP;
+ } else {
+ gid = pw->pw_gid;
+ mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
+ }
+
+ /* Change ownership of the tty. */
+ if (chown(ttyname, pw->pw_uid, gid) < 0)
+ fatal("chown(%.100s, %d, %d) failed: %.100s",
+ ttyname, pw->pw_uid, gid, strerror(errno));
+ if (chmod(ttyname, mode) < 0)
+ fatal("chmod(%.100s, 0%o) failed: %.100s",
+ ttyname, mode, strerror(errno));
+}