summaryrefslogtreecommitdiff
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 b3a0535ee..de6f751d8 100644
--- a/pty.c
+++ b/pty.c
@@ -14,7 +14,7 @@
14 */ 14 */
15 15
16#include "includes.h" 16#include "includes.h"
17RCSID("$Id: pty.c,v 1.11 1999/12/21 00:18:08 damien Exp $"); 17RCSID("$Id: pty.c,v 1.12 2000/03/02 12:30:53 damien Exp $");
18 18
19#ifdef HAVE_UTIL_H 19#ifdef HAVE_UTIL_H
20# include <util.h> 20# include <util.h>
@@ -188,9 +188,9 @@ void
188pty_release(const char *ttyname) 188pty_release(const char *ttyname)
189{ 189{
190 if (chown(ttyname, (uid_t) 0, (gid_t) 0) < 0) 190 if (chown(ttyname, (uid_t) 0, (gid_t) 0) < 0)
191 debug("chown %.100s 0 0 failed: %.100s", ttyname, strerror(errno)); 191 error("chown %.100s 0 0 failed: %.100s", ttyname, strerror(errno));
192 if (chmod(ttyname, (mode_t) 0666) < 0) 192 if (chmod(ttyname, (mode_t) 0666) < 0)
193 debug("chmod %.100s 0666 failed: %.100s", ttyname, strerror(errno)); 193 error("chmod %.100s 0666 failed: %.100s", ttyname, strerror(errno));
194} 194}
195 195
196/* Makes the tty the processes controlling tty and sets it to sane modes. */ 196/* 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,
259 w.ws_ypixel = ypixel; 259 w.ws_ypixel = ypixel;
260 (void) ioctl(ptyfd, TIOCSWINSZ, &w); 260 (void) ioctl(ptyfd, TIOCSWINSZ, &w);
261} 261}
262
263void
264pty_setowner(struct passwd *pw, const char *ttyname)
265{
266 struct group *grp;
267 gid_t gid;
268 mode_t mode;
269
270 /* Determine the group to make the owner of the tty. */
271 grp = getgrnam("tty");
272 if (grp) {
273 gid = grp->gr_gid;
274 mode = S_IRUSR | S_IWUSR | S_IWGRP;
275 } else {
276 gid = pw->pw_gid;
277 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
278 }
279
280 /* Change ownership of the tty. */
281 if (chown(ttyname, pw->pw_uid, gid) < 0)
282 fatal("chown(%.100s, %d, %d) failed: %.100s",
283 ttyname, pw->pw_uid, gid, strerror(errno));
284 if (chmod(ttyname, mode) < 0)
285 fatal("chmod(%.100s, 0%o) failed: %.100s",
286 ttyname, mode, strerror(errno));
287}