Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/sshpty.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,17 @@ pty_setowner(struct passwd *pw, const char *tty_name)
{
struct group *grp;
gid_t gid;
gid_t nogroup_gid;
mode_t mode;
struct stat st;

/* get nogroup's gid */
grp = getgrnam("nogroup");
if (grp)
nogroup_gid = grp->gr_gid;
else
nogroup_gid = -1;

/* Determine the group to make the owner of the tty. */
grp = getgrnam("tty");
if (grp) {
Expand All @@ -382,7 +390,8 @@ pty_setowner(struct passwd *pw, const char *tty_name)

/* Allow either "tty" gid or user's own gid. On Linux with openpty()
* this varies depending on the devpts mount options */
if (st.st_uid != pw->pw_uid || !(st.st_gid == gid || st.st_gid == pw->pw_gid)) {
if (st.st_uid != pw->pw_uid ||
!(st.st_gid == gid || st.st_gid == nogroup_gid || st.st_gid == pw->pw_gid)) {
if (chown(tty_name, pw->pw_uid, gid) < 0) {
if (errno == EROFS &&
(st.st_uid == pw->pw_uid || st.st_uid == 0)) {
Expand Down