summaryrefslogtreecommitdiff
path: root/sshpty.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2019-10-09 22:59:48 +0100
committerColin Watson <cjwatson@debian.org>2019-10-09 22:59:48 +0100
commit4213eec74e74de6310c27a40c3e9759a08a73996 (patch)
treee97a6dcafc6763aea7c804e4e113c2750cb1400d /sshpty.c
parent102062f825fb26a74295a1c089c00c4c4c76b68a (diff)
parentcdf1d0a9f5d18535e0a18ff34860e81a6d83aa5c (diff)
Import openssh_8.1p1.orig.tar.gz
Diffstat (limited to 'sshpty.c')
-rw-r--r--sshpty.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/sshpty.c b/sshpty.c
index 4da84d05f..bce09e255 100644
--- a/sshpty.c
+++ b/sshpty.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshpty.c,v 1.31 2016/11/29 03:54:50 dtucker Exp $ */ 1/* $OpenBSD: sshpty.c,v 1.34 2019/07/04 16:20:10 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * 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)
68 int i; 68 int i;
69 69
70 i = openpty(ptyfd, ttyfd, NULL, NULL, NULL); 70 i = openpty(ptyfd, ttyfd, NULL, NULL, NULL);
71 if (i < 0) { 71 if (i == -1) {
72 error("openpty: %.100s", strerror(errno)); 72 error("openpty: %.100s", strerror(errno));
73 return 0; 73 return 0;
74 } 74 }
@@ -86,9 +86,9 @@ void
86pty_release(const char *tty) 86pty_release(const char *tty)
87{ 87{
88#if !defined(__APPLE_PRIVPTY__) && !defined(HAVE_OPENPTY) 88#if !defined(__APPLE_PRIVPTY__) && !defined(HAVE_OPENPTY)
89 if (chown(tty, (uid_t) 0, (gid_t) 0) < 0) 89 if (chown(tty, (uid_t) 0, (gid_t) 0) == -1)
90 error("chown %.100s 0 0 failed: %.100s", tty, strerror(errno)); 90 error("chown %.100s 0 0 failed: %.100s", tty, strerror(errno));
91 if (chmod(tty, (mode_t) 0666) < 0) 91 if (chmod(tty, (mode_t) 0666) == -1)
92 error("chmod %.100s 0666 failed: %.100s", tty, strerror(errno)); 92 error("chmod %.100s 0666 failed: %.100s", tty, strerror(errno));
93#endif /* !__APPLE_PRIVPTY__ && !HAVE_OPENPTY */ 93#endif /* !__APPLE_PRIVPTY__ && !HAVE_OPENPTY */
94} 94}
@@ -108,7 +108,7 @@ pty_make_controlling_tty(int *ttyfd, const char *tty)
108 close(fd); 108 close(fd);
109 } 109 }
110#endif /* TIOCNOTTY */ 110#endif /* TIOCNOTTY */
111 if (setsid() < 0) 111 if (setsid() == -1)
112 error("setsid: %.100s", strerror(errno)); 112 error("setsid: %.100s", strerror(errno));
113 113
114 /* 114 /*
@@ -131,14 +131,14 @@ pty_make_controlling_tty(int *ttyfd, const char *tty)
131 error("SETPGRP %s",strerror(errno)); 131 error("SETPGRP %s",strerror(errno));
132#endif /* NEED_SETPGRP */ 132#endif /* NEED_SETPGRP */
133 fd = open(tty, O_RDWR); 133 fd = open(tty, O_RDWR);
134 if (fd < 0) 134 if (fd == -1)
135 error("%.100s: %.100s", tty, strerror(errno)); 135 error("%.100s: %.100s", tty, strerror(errno));
136 else 136 else
137 close(fd); 137 close(fd);
138 138
139 /* Verify that we now have a controlling tty. */ 139 /* Verify that we now have a controlling tty. */
140 fd = open(_PATH_TTY, O_WRONLY); 140 fd = open(_PATH_TTY, O_WRONLY);
141 if (fd < 0) 141 if (fd == -1)
142 error("open /dev/tty failed - could not set controlling tty: %.100s", 142 error("open /dev/tty failed - could not set controlling tty: %.100s",
143 strerror(errno)); 143 strerror(errno));
144 else 144 else
@@ -171,6 +171,8 @@ pty_setowner(struct passwd *pw, const char *tty)
171 171
172 /* Determine the group to make the owner of the tty. */ 172 /* Determine the group to make the owner of the tty. */
173 grp = getgrnam("tty"); 173 grp = getgrnam("tty");
174 if (grp == NULL)
175 debug("%s: no tty group", __func__);
174 gid = (grp != NULL) ? grp->gr_gid : pw->pw_gid; 176 gid = (grp != NULL) ? grp->gr_gid : pw->pw_gid;
175 mode = (grp != NULL) ? 0620 : 0600; 177 mode = (grp != NULL) ? 0620 : 0600;
176 178
@@ -179,7 +181,7 @@ pty_setowner(struct passwd *pw, const char *tty)
179 * Warn but continue if filesystem is read-only and the uids match/ 181 * Warn but continue if filesystem is read-only and the uids match/
180 * tty is owned by root. 182 * tty is owned by root.
181 */ 183 */
182 if (stat(tty, &st)) 184 if (stat(tty, &st) == -1)
183 fatal("stat(%.100s) failed: %.100s", tty, 185 fatal("stat(%.100s) failed: %.100s", tty,
184 strerror(errno)); 186 strerror(errno));
185 187
@@ -188,7 +190,7 @@ pty_setowner(struct passwd *pw, const char *tty)
188#endif 190#endif
189 191
190 if (st.st_uid != pw->pw_uid || st.st_gid != gid) { 192 if (st.st_uid != pw->pw_uid || st.st_gid != gid) {
191 if (chown(tty, pw->pw_uid, gid) < 0) { 193 if (chown(tty, pw->pw_uid, gid) == -1) {
192 if (errno == EROFS && 194 if (errno == EROFS &&
193 (st.st_uid == pw->pw_uid || st.st_uid == 0)) 195 (st.st_uid == pw->pw_uid || st.st_uid == 0))
194 debug("chown(%.100s, %u, %u) failed: %.100s", 196 debug("chown(%.100s, %u, %u) failed: %.100s",
@@ -202,7 +204,7 @@ pty_setowner(struct passwd *pw, const char *tty)
202 } 204 }
203 205
204 if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) { 206 if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) {
205 if (chmod(tty, mode) < 0) { 207 if (chmod(tty, mode) == -1) {
206 if (errno == EROFS && 208 if (errno == EROFS &&
207 (st.st_mode & (S_IRGRP | S_IROTH)) == 0) 209 (st.st_mode & (S_IRGRP | S_IROTH)) == 0)
208 debug("chmod(%.100s, 0%o) failed: %.100s", 210 debug("chmod(%.100s, 0%o) failed: %.100s",