diff options
author | Ed Maste <emaste@FreeBSD.org> | 2021-02-14 21:00:25 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2021-02-14 21:00:25 +0000 |
commit | 0194e6d04277a638afac6c4a664d3bc6a0d944eb (patch) | |
tree | e97a6dcafc6763aea7c804e4e113c2750cb1400d /sshpty.c | |
parent | f02e39982452024dafcf0ea6e536ebff586ffce4 (diff) |
Vendor import of OpenSSH 8.1p1vendor/openssh/8.1p1
Diffstat (limited to 'sshpty.c')
-rw-r--r-- | sshpty.c | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: sshpty.c,v 1.31 2016/11/29 03:54:50 dtucker Exp $ */ +/* $OpenBSD: sshpty.c,v 1.34 2019/07/04 16:20:10 deraadt Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -68,7 +68,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen) int i; i = openpty(ptyfd, ttyfd, NULL, NULL, NULL); - if (i < 0) { + if (i == -1) { error("openpty: %.100s", strerror(errno)); return 0; } @@ -86,9 +86,9 @@ void pty_release(const char *tty) { #if !defined(__APPLE_PRIVPTY__) && !defined(HAVE_OPENPTY) - 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)); - if (chmod(tty, (mode_t) 0666) < 0) + if (chmod(tty, (mode_t) 0666) == -1) error("chmod %.100s 0666 failed: %.100s", tty, strerror(errno)); #endif /* !__APPLE_PRIVPTY__ && !HAVE_OPENPTY */ } @@ -108,7 +108,7 @@ pty_make_controlling_tty(int *ttyfd, const char *tty) close(fd); } #endif /* TIOCNOTTY */ - if (setsid() < 0) + if (setsid() == -1) error("setsid: %.100s", strerror(errno)); /* @@ -131,14 +131,14 @@ pty_make_controlling_tty(int *ttyfd, const char *tty) error("SETPGRP %s",strerror(errno)); #endif /* NEED_SETPGRP */ fd = open(tty, O_RDWR); - if (fd < 0) + if (fd == -1) error("%.100s: %.100s", tty, strerror(errno)); else close(fd); /* Verify that we now have a controlling tty. */ fd = open(_PATH_TTY, O_WRONLY); - if (fd < 0) + if (fd == -1) error("open /dev/tty failed - could not set controlling tty: %.100s", strerror(errno)); else @@ -171,6 +171,8 @@ pty_setowner(struct passwd *pw, const char *tty) /* Determine the group to make the owner of the tty. */ grp = getgrnam("tty"); + if (grp == NULL) + debug("%s: no tty group", __func__); gid = (grp != NULL) ? grp->gr_gid : pw->pw_gid; mode = (grp != NULL) ? 0620 : 0600; @@ -179,7 +181,7 @@ pty_setowner(struct passwd *pw, const char *tty) * Warn but continue if filesystem is read-only and the uids match/ * tty is owned by root. */ - if (stat(tty, &st)) + if (stat(tty, &st) == -1) fatal("stat(%.100s) failed: %.100s", tty, strerror(errno)); @@ -188,7 +190,7 @@ pty_setowner(struct passwd *pw, const char *tty) #endif 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 && (st.st_uid == pw->pw_uid || st.st_uid == 0)) debug("chown(%.100s, %u, %u) failed: %.100s", @@ -202,7 +204,7 @@ pty_setowner(struct passwd *pw, const char *tty) } if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) { - if (chmod(tty, mode) < 0) { + if (chmod(tty, mode) == -1) { if (errno == EROFS && (st.st_mode & (S_IRGRP | S_IROTH)) == 0) debug("chmod(%.100s, 0%o) failed: %.100s", |