diff options
Diffstat (limited to 'pty.c')
-rw-r--r-- | pty.c | 32 |
1 files changed, 29 insertions, 3 deletions
@@ -14,7 +14,7 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include "includes.h" | 16 | #include "includes.h" |
17 | RCSID("$Id: pty.c,v 1.11 1999/12/21 00:18:08 damien Exp $"); | 17 | RCSID("$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 | |||
188 | pty_release(const char *ttyname) | 188 | pty_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 | |||
263 | void | ||
264 | pty_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 | } | ||