Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip pty chown if it is group owned by nogroup #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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