version 1.31, 2016/11/29 03:54:50 |
version 1.32, 2019/06/28 13:35:04 |
|
|
int i; |
int i; |
|
|
i = openpty(ptyfd, ttyfd, buf, NULL, NULL); |
i = openpty(ptyfd, ttyfd, buf, NULL, NULL); |
if (i < 0) { |
if (i == -1) { |
error("openpty: %.100s", strerror(errno)); |
error("openpty: %.100s", strerror(errno)); |
return 0; |
return 0; |
} |
} |
|
|
void |
void |
pty_release(const char *tty) |
pty_release(const char *tty) |
{ |
{ |
if (chown(tty, (uid_t) 0, (gid_t) 0) < 0) |
if (chown(tty, (uid_t) 0, (gid_t) 0) == -1) |
error("chown %.100s 0 0 failed: %.100s", tty, strerror(errno)); |
error("chown %.100s 0 0 failed: %.100s", tty, strerror(errno)); |
if (chmod(tty, (mode_t) 0666) < 0) |
if (chmod(tty, (mode_t) 0666) == -1) |
error("chmod %.100s 0666 failed: %.100s", tty, strerror(errno)); |
error("chmod %.100s 0666 failed: %.100s", tty, strerror(errno)); |
} |
} |
|
|
|
|
close(fd); |
close(fd); |
} |
} |
#endif /* TIOCNOTTY */ |
#endif /* TIOCNOTTY */ |
if (setsid() < 0) |
if (setsid() == -1) |
error("setsid: %.100s", strerror(errno)); |
error("setsid: %.100s", strerror(errno)); |
|
|
/* |
/* |
|
|
/* Make it our controlling tty. */ |
/* Make it our controlling tty. */ |
#ifdef TIOCSCTTY |
#ifdef TIOCSCTTY |
debug("Setting controlling tty using TIOCSCTTY."); |
debug("Setting controlling tty using TIOCSCTTY."); |
if (ioctl(*ttyfd, TIOCSCTTY, NULL) < 0) |
if (ioctl(*ttyfd, TIOCSCTTY, NULL) == -1) |
error("ioctl(TIOCSCTTY): %.100s", strerror(errno)); |
error("ioctl(TIOCSCTTY): %.100s", strerror(errno)); |
#endif /* TIOCSCTTY */ |
#endif /* TIOCSCTTY */ |
fd = open(tty, O_RDWR); |
fd = open(tty, O_RDWR); |
if (fd < 0) |
if (fd == -1) |
error("%.100s: %.100s", tty, strerror(errno)); |
error("%.100s: %.100s", tty, strerror(errno)); |
else |
else |
close(fd); |
close(fd); |
|
|
/* Verify that we now have a controlling tty. */ |
/* Verify that we now have a controlling tty. */ |
fd = open(_PATH_TTY, O_WRONLY); |
fd = open(_PATH_TTY, O_WRONLY); |
if (fd < 0) |
if (fd == -1) |
error("open /dev/tty failed - could not set controlling tty: %.100s", |
error("open /dev/tty failed - could not set controlling tty: %.100s", |
strerror(errno)); |
strerror(errno)); |
else |
else |
|
|
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(tty, pw->pw_uid, gid) < 0) { |
if (chown(tty, pw->pw_uid, gid) == -1) { |
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", |
|
|
} |
} |
|
|
if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) { |
if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) { |
if (chmod(tty, mode) < 0) { |
if (chmod(tty, mode) == -1) { |
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", |