sshpty.c (76262) | sshpty.c (92559) |
---|---|
1/* 2 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * All rights reserved 5 * Allocating a pseudo-terminal, and making it the controlling tty. 6 * 7 * As far as I am concerned, the code I have written for this software 8 * can be used freely for any purpose. Any derived versions of this 9 * software must be clearly marked as such, and if the derived work is 10 * incompatible with the protocol description in the RFC file, it must be 11 * called by a name other than "ssh" or "Secure Shell". 12 */ 13 14#include "includes.h" | 1/* 2 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * All rights reserved 5 * Allocating a pseudo-terminal, and making it the controlling tty. 6 * 7 * As far as I am concerned, the code I have written for this software 8 * can be used freely for any purpose. Any derived versions of this 9 * software must be clearly marked as such, and if the derived work is 10 * incompatible with the protocol description in the RFC file, it must be 11 * called by a name other than "ssh" or "Secure Shell". 12 */ 13 14#include "includes.h" |
15RCSID("$OpenBSD: sshpty.c,v 1.1 2001/03/04 01:46:30 djm Exp $"); 16RCSID("$FreeBSD: head/crypto/openssh/sshpty.c 76262 2001-05-04 04:14:23Z green $"); | 15RCSID("$OpenBSD: sshpty.c,v 1.4 2001/12/19 07:18:56 deraadt Exp $"); 16RCSID("$FreeBSD: head/crypto/openssh/sshpty.c 92559 2002-03-18 10:09:43Z des $"); |
17 18#include <libutil.h> 19#include "sshpty.h" 20#include "log.h" 21 22/* Pty allocated with _getpty gets broken if we do I_PUSH:es to it. */ 23#if defined(HAVE__GETPTY) || defined(HAVE_OPENPTY) 24#undef HAVE_DEV_PTMX --- 102 unchanged lines hidden (view full) --- 127 } 128 name = ttyname(*ptyfd); 129 if (!name) 130 fatal("Open of /dev/ptc returns device for which ttyname fails."); 131 strlcpy(namebuf, name, namebuflen); 132 *ttyfd = open(name, O_RDWR | O_NOCTTY); 133 if (*ttyfd < 0) { 134 error("Could not open pty slave side %.100s: %.100s", | 17 18#include <libutil.h> 19#include "sshpty.h" 20#include "log.h" 21 22/* Pty allocated with _getpty gets broken if we do I_PUSH:es to it. */ 23#if defined(HAVE__GETPTY) || defined(HAVE_OPENPTY) 24#undef HAVE_DEV_PTMX --- 102 unchanged lines hidden (view full) --- 127 } 128 name = ttyname(*ptyfd); 129 if (!name) 130 fatal("Open of /dev/ptc returns device for which ttyname fails."); 131 strlcpy(namebuf, name, namebuflen); 132 *ttyfd = open(name, O_RDWR | O_NOCTTY); 133 if (*ttyfd < 0) { 134 error("Could not open pty slave side %.100s: %.100s", |
135 name, strerror(errno)); | 135 name, strerror(errno)); |
136 close(*ptyfd); 137 return 0; 138 } 139 return 1; 140#else /* HAVE_DEV_PTS_AND_PTC */ 141 /* BSD-style pty code. */ 142 char buf[64]; 143 int i; --- 76 unchanged lines hidden (view full) --- 220 error("%.100s: %.100s", ttyname, strerror(errno)); 221 else 222 close(fd); 223 224 /* Verify that we now have a controlling tty. */ 225 fd = open(_PATH_TTY, O_WRONLY); 226 if (fd < 0) 227 error("open /dev/tty failed - could not set controlling tty: %.100s", | 136 close(*ptyfd); 137 return 0; 138 } 139 return 1; 140#else /* HAVE_DEV_PTS_AND_PTC */ 141 /* BSD-style pty code. */ 142 char buf[64]; 143 int i; --- 76 unchanged lines hidden (view full) --- 220 error("%.100s: %.100s", ttyname, strerror(errno)); 221 else 222 close(fd); 223 224 /* Verify that we now have a controlling tty. */ 225 fd = open(_PATH_TTY, O_WRONLY); 226 if (fd < 0) 227 error("open /dev/tty failed - could not set controlling tty: %.100s", |
228 strerror(errno)); | 228 strerror(errno)); |
229 else { 230 close(fd); 231 } 232} 233 234/* Changes the window size associated with the pty. */ 235 236void 237pty_change_window_size(int ptyfd, int row, int col, | 229 else { 230 close(fd); 231 } 232} 233 234/* Changes the window size associated with the pty. */ 235 236void 237pty_change_window_size(int ptyfd, int row, int col, |
238 int xpixel, int ypixel) | 238 int xpixel, int ypixel) |
239{ 240 struct winsize w; 241 w.ws_row = row; 242 w.ws_col = col; 243 w.ws_xpixel = xpixel; 244 w.ws_ypixel = ypixel; 245 (void) ioctl(ptyfd, TIOCSWINSZ, &w); 246} --- 13 unchanged lines hidden (view full) --- 260 mode = S_IRUSR | S_IWUSR | S_IWGRP; 261 } else { 262 gid = pw->pw_gid; 263 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; 264 } 265 266 /* 267 * Change owner and mode of the tty as required. | 239{ 240 struct winsize w; 241 w.ws_row = row; 242 w.ws_col = col; 243 w.ws_xpixel = xpixel; 244 w.ws_ypixel = ypixel; 245 (void) ioctl(ptyfd, TIOCSWINSZ, &w); 246} --- 13 unchanged lines hidden (view full) --- 260 mode = S_IRUSR | S_IWUSR | S_IWGRP; 261 } else { 262 gid = pw->pw_gid; 263 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; 264 } 265 266 /* 267 * Change owner and mode of the tty as required. |
268 * Warn but continue if filesystem is read-only and the uids match. | 268 * Warn but continue if filesystem is read-only and the uids match/ 269 * tty is owned by root. |
269 */ 270 if (stat(ttyname, &st)) 271 fatal("stat(%.100s) failed: %.100s", ttyname, 272 strerror(errno)); 273 274 if (st.st_uid != pw->pw_uid || st.st_gid != gid) { 275 if (chown(ttyname, pw->pw_uid, gid) < 0) { | 270 */ 271 if (stat(ttyname, &st)) 272 fatal("stat(%.100s) failed: %.100s", ttyname, 273 strerror(errno)); 274 275 if (st.st_uid != pw->pw_uid || st.st_gid != gid) { 276 if (chown(ttyname, pw->pw_uid, gid) < 0) { |
276 if (errno == EROFS && st.st_uid == pw->pw_uid) | 277 if (errno == EROFS && 278 (st.st_uid == pw->pw_uid || st.st_uid == 0)) |
277 error("chown(%.100s, %d, %d) failed: %.100s", | 279 error("chown(%.100s, %d, %d) failed: %.100s", |
278 ttyname, pw->pw_uid, gid, 279 strerror(errno)); | 280 ttyname, pw->pw_uid, gid, 281 strerror(errno)); |
280 else 281 fatal("chown(%.100s, %d, %d) failed: %.100s", | 282 else 283 fatal("chown(%.100s, %d, %d) failed: %.100s", |
282 ttyname, pw->pw_uid, gid, 283 strerror(errno)); | 284 ttyname, pw->pw_uid, gid, 285 strerror(errno)); |
284 } 285 } 286 287 if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) { 288 if (chmod(ttyname, mode) < 0) { 289 if (errno == EROFS && 290 (st.st_mode & (S_IRGRP | S_IROTH)) == 0) 291 error("chmod(%.100s, 0%o) failed: %.100s", | 286 } 287 } 288 289 if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) { 290 if (chmod(ttyname, mode) < 0) { 291 if (errno == EROFS && 292 (st.st_mode & (S_IRGRP | S_IROTH)) == 0) 293 error("chmod(%.100s, 0%o) failed: %.100s", |
292 ttyname, mode, strerror(errno)); | 294 ttyname, mode, strerror(errno)); |
293 else 294 fatal("chmod(%.100s, 0%o) failed: %.100s", | 295 else 296 fatal("chmod(%.100s, 0%o) failed: %.100s", |
295 ttyname, mode, strerror(errno)); | 297 ttyname, mode, strerror(errno)); |
296 } 297 } 298} | 298 } 299 } 300} |