diff options
author | Damien Miller <djm@mindrot.org> | 1999-12-07 15:38:31 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 1999-12-07 15:38:31 +1100 |
commit | 037a0dc0835bb5a442bdcbeecdd5baed723f0b45 (patch) | |
tree | d02954d57ac437fd036e3e9544f24559ca8f0f0f /pty.c | |
parent | eabf3417bc73ca9546a3ed489cd809ffdf303853 (diff) |
- Merged more OpenBSD changes:
- [atomicio.c authfd.c scp.c serverloop.c ssh.h sshconnect.c sshd.c]
move atomicio into it's own file. wrap all socket write()s which
were doing write(sock, buf, len) != len, with atomicio() calls.
- [auth-skey.c]
fd leak
- [authfile.c]
properly name fd variable
- [channels.c]
display great hatred towards strcpy
- [pty.c pty.h sshd.c]
use openpty() if it exists (it does on BSD4_4)
- [tildexpand.c]
check for ~ expansion past MAXPATHLEN
- Modified helper.c to use new atomicio function.
- Reformat Makefile a little
- Moved RC4 routines from rc4.[ch] into helper.c
- Added autoconf code to detect /dev/ptmx (Solaris) and /dev/ptc (AIX)
Diffstat (limited to 'pty.c')
-rw-r--r-- | pty.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -14,7 +14,7 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include "includes.h" | 16 | #include "includes.h" |
17 | RCSID("$Id: pty.c,v 1.5 1999/11/25 00:54:59 damien Exp $"); | 17 | RCSID("$Id: pty.c,v 1.6 1999/12/07 04:38:32 damien Exp $"); |
18 | 18 | ||
19 | #include "pty.h" | 19 | #include "pty.h" |
20 | #include "ssh.h" | 20 | #include "ssh.h" |
@@ -40,17 +40,19 @@ RCSID("$Id: pty.c,v 1.5 1999/11/25 00:54:59 damien Exp $"); | |||
40 | */ | 40 | */ |
41 | 41 | ||
42 | int | 42 | int |
43 | pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) | 43 | pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen) |
44 | { | 44 | { |
45 | #ifdef HAVE_OPENPTY | 45 | #if defined(HAVE_OPENPTY) || defined(BSD4_4) |
46 | /* openpty(3) exists in OSF/1 and some other os'es */ | 46 | /* openpty(3) exists in OSF/1 and some other os'es */ |
47 | char buf[64]; | ||
47 | int i; | 48 | int i; |
48 | 49 | ||
49 | i = openpty(ptyfd, ttyfd, namebuf, NULL, NULL); | 50 | i = openpty(ptyfd, ttyfd, buf, NULL, NULL); |
50 | if (i < 0) { | 51 | if (i < 0) { |
51 | error("openpty: %.100s", strerror(errno)); | 52 | error("openpty: %.100s", strerror(errno)); |
52 | return 0; | 53 | return 0; |
53 | } | 54 | } |
55 | strlcpy(namebuf, buf, namebuflen); /* possible truncation */ | ||
54 | return 1; | 56 | return 1; |
55 | #else /* HAVE_OPENPTY */ | 57 | #else /* HAVE_OPENPTY */ |
56 | #ifdef HAVE__GETPTY | 58 | #ifdef HAVE__GETPTY |
@@ -65,7 +67,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) | |||
65 | error("_getpty: %.100s", strerror(errno)); | 67 | error("_getpty: %.100s", strerror(errno)); |
66 | return 0; | 68 | return 0; |
67 | } | 69 | } |
68 | strcpy(namebuf, slave); | 70 | strlcpy(namebuf, slave, namebuflen); |
69 | /* Open the slave side. */ | 71 | /* Open the slave side. */ |
70 | *ttyfd = open(namebuf, O_RDWR | O_NOCTTY); | 72 | *ttyfd = open(namebuf, O_RDWR | O_NOCTTY); |
71 | if (*ttyfd < 0) { | 73 | if (*ttyfd < 0) { |
@@ -99,7 +101,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) | |||
99 | pts = ptsname(ptm); | 101 | pts = ptsname(ptm); |
100 | if (pts == NULL) | 102 | if (pts == NULL) |
101 | error("Slave pty side name could not be obtained."); | 103 | error("Slave pty side name could not be obtained."); |
102 | strcpy(namebuf, pts); | 104 | strlcpy(namebuf, pts, namebuflen); |
103 | *ptyfd = ptm; | 105 | *ptyfd = ptm; |
104 | 106 | ||
105 | /* Open the slave side. */ | 107 | /* Open the slave side. */ |
@@ -130,7 +132,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) | |||
130 | name = ttyname(*ptyfd); | 132 | name = ttyname(*ptyfd); |
131 | if (!name) | 133 | if (!name) |
132 | fatal("Open of /dev/ptc returns device for which ttyname fails."); | 134 | fatal("Open of /dev/ptc returns device for which ttyname fails."); |
133 | strcpy(namebuf, name); | 135 | strlcpy(namebuf, name, namebuflen); |
134 | *ttyfd = open(name, O_RDWR | O_NOCTTY); | 136 | *ttyfd = open(name, O_RDWR | O_NOCTTY); |
135 | if (*ttyfd < 0) { | 137 | if (*ttyfd < 0) { |
136 | error("Could not open pty slave side %.100s: %.100s", | 138 | error("Could not open pty slave side %.100s: %.100s", |
@@ -154,8 +156,8 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) | |||
154 | *ptyfd = open(buf, O_RDWR | O_NOCTTY); | 156 | *ptyfd = open(buf, O_RDWR | O_NOCTTY); |
155 | if (*ptyfd < 0) | 157 | if (*ptyfd < 0) |
156 | continue; | 158 | continue; |
157 | snprintf(namebuf, sizeof buf, "/dev/tty%c%c", ptymajors[i / num_minors], | 159 | snprintf(namebuf, sizeof namebuflen, "/dev/tty%c%c", |
158 | ptyminors[i % num_minors]); | 160 | ptymajors[i / num_minors], ptyminors[i % num_minors]); |
159 | 161 | ||
160 | /* Open the slave side. */ | 162 | /* Open the slave side. */ |
161 | *ttyfd = open(namebuf, O_RDWR | O_NOCTTY); | 163 | *ttyfd = open(namebuf, O_RDWR | O_NOCTTY); |