version 1.11, 2004/01/11 21:55:06 |
version 1.12, 2004/06/21 17:36:31 |
|
|
/* Releases the tty. Its ownership is returned to root, and permissions to 0666. */ |
/* Releases the tty. Its ownership is returned to root, and permissions to 0666. */ |
|
|
void |
void |
pty_release(const char *ttyname) |
pty_release(const char *tty) |
{ |
{ |
if (chown(ttyname, (uid_t) 0, (gid_t) 0) < 0) |
if (chown(tty, (uid_t) 0, (gid_t) 0) < 0) |
error("chown %.100s 0 0 failed: %.100s", ttyname, strerror(errno)); |
error("chown %.100s 0 0 failed: %.100s", tty, strerror(errno)); |
if (chmod(ttyname, (mode_t) 0666) < 0) |
if (chmod(tty, (mode_t) 0666) < 0) |
error("chmod %.100s 0666 failed: %.100s", ttyname, strerror(errno)); |
error("chmod %.100s 0666 failed: %.100s", tty, strerror(errno)); |
} |
} |
|
|
/* Makes the tty the process's controlling tty and sets it to sane modes. */ |
/* Makes the tty the process's controlling tty and sets it to sane modes. */ |
|
|
void |
void |
pty_make_controlling_tty(int *ttyfd, const char *ttyname) |
pty_make_controlling_tty(int *ttyfd, const char *tty) |
{ |
{ |
int fd; |
int fd; |
|
|
|
|
if (ioctl(*ttyfd, TIOCSCTTY, NULL) < 0) |
if (ioctl(*ttyfd, TIOCSCTTY, NULL) < 0) |
error("ioctl(TIOCSCTTY): %.100s", strerror(errno)); |
error("ioctl(TIOCSCTTY): %.100s", strerror(errno)); |
#endif /* TIOCSCTTY */ |
#endif /* TIOCSCTTY */ |
fd = open(ttyname, O_RDWR); |
fd = open(tty, O_RDWR); |
if (fd < 0) |
if (fd < 0) |
error("%.100s: %.100s", ttyname, strerror(errno)); |
error("%.100s: %.100s", tty, strerror(errno)); |
else |
else |
close(fd); |
close(fd); |
|
|
|
|
} |
} |
|
|
void |
void |
pty_setowner(struct passwd *pw, const char *ttyname) |
pty_setowner(struct passwd *pw, const char *tty) |
{ |
{ |
struct group *grp; |
struct group *grp; |
gid_t gid; |
gid_t gid; |
|
|
* Warn but continue if filesystem is read-only and the uids match/ |
* Warn but continue if filesystem is read-only and the uids match/ |
* tty is owned by root. |
* tty is owned by root. |
*/ |
*/ |
if (stat(ttyname, &st)) |
if (stat(tty, &st)) |
fatal("stat(%.100s) failed: %.100s", ttyname, |
fatal("stat(%.100s) failed: %.100s", tty, |
strerror(errno)); |
strerror(errno)); |
|
|
if (st.st_uid != pw->pw_uid || st.st_gid != gid) { |
if (st.st_uid != pw->pw_uid || st.st_gid != gid) { |
if (chown(ttyname, pw->pw_uid, gid) < 0) { |
if (chown(tty, pw->pw_uid, gid) < 0) { |
if (errno == EROFS && |
if (errno == EROFS && |
(st.st_uid == pw->pw_uid || st.st_uid == 0)) |
(st.st_uid == pw->pw_uid || st.st_uid == 0)) |
debug("chown(%.100s, %u, %u) failed: %.100s", |
debug("chown(%.100s, %u, %u) failed: %.100s", |
ttyname, (u_int)pw->pw_uid, (u_int)gid, |
tty, (u_int)pw->pw_uid, (u_int)gid, |
strerror(errno)); |
strerror(errno)); |
else |
else |
fatal("chown(%.100s, %u, %u) failed: %.100s", |
fatal("chown(%.100s, %u, %u) failed: %.100s", |
ttyname, (u_int)pw->pw_uid, (u_int)gid, |
tty, (u_int)pw->pw_uid, (u_int)gid, |
strerror(errno)); |
strerror(errno)); |
} |
} |
} |
} |
|
|
if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) { |
if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) { |
if (chmod(ttyname, mode) < 0) { |
if (chmod(tty, mode) < 0) { |
if (errno == EROFS && |
if (errno == EROFS && |
(st.st_mode & (S_IRGRP | S_IROTH)) == 0) |
(st.st_mode & (S_IRGRP | S_IROTH)) == 0) |
debug("chmod(%.100s, 0%o) failed: %.100s", |
debug("chmod(%.100s, 0%o) failed: %.100s", |
ttyname, (u_int)mode, strerror(errno)); |
tty, (u_int)mode, strerror(errno)); |
else |
else |
fatal("chmod(%.100s, 0%o) failed: %.100s", |
fatal("chmod(%.100s, 0%o) failed: %.100s", |
ttyname, (u_int)mode, strerror(errno)); |
tty, (u_int)mode, strerror(errno)); |
} |
} |
} |
} |
} |
} |