OpenCoverage

sshpty.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/sshpty.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
16-
17-
18int-
19pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)-
20{-
21-
22 char *name;-
23 int i;-
24-
25 i = openpty(ptyfd, ttyfd, -
26 ((void *)0)-
27 , -
28 ((void *)0)-
29 , -
30 ((void *)0)-
31 );-
32 if (i < 0
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
33 error("openpty: %.100s", strerror(-
34 (*__errno_location ())-
35 ));-
36 return
never executed: return 0;
0;
never executed: return 0;
0
37 }-
38 name = ttyname(*ttyfd);-
39 if (!name
!nameDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
40 fatal("openpty returns device for which ttyname fails.");
never executed: fatal("openpty returns device for which ttyname fails.");
0
41-
42 strlcpy(namebuf, name, namebuflen);-
43 return
never executed: return 1;
1;
never executed: return 1;
0
44}-
45-
46-
47-
48void-
49pty_release(const char *tty)-
50{-
51-
52-
53-
54-
55-
56-
57}-
58-
59-
60-
61void-
62pty_make_controlling_tty(int *ttyfd, const char *tty)-
63{-
64 int fd;-
65-
66-
67-
68 fd = open(-
69 "/dev/tty"-
70 , -
71 02 -
72 | -
73 0400-
74 );-
75 if (fd >= 0
fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
76 (void) ioctl(fd, -
77 0x5422-
78 , -
79 ((void *)0)-
80 );-
81 close(fd);-
82 }
never executed: end of block
0
83-
84 if (setsid() < 0
setsid() < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
85 error("setsid: %.100s", strerror(
never executed: error("setsid: %.100s", strerror( (*__errno_location ()) ));
0
86 (*__errno_location ())
never executed: error("setsid: %.100s", strerror( (*__errno_location ()) ));
0
87 ));
never executed: error("setsid: %.100s", strerror( (*__errno_location ()) ));
0
88-
89-
90-
91-
92-
93 fd = open(-
94 "/dev/tty"-
95 , -
96 02 -
97 | -
98 0400-
99 );-
100 if (fd >= 0
fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
101 error("Failed to disconnect from controlling tty.");-
102 close(fd);-
103 }
never executed: end of block
0
104-
105-
106 debug("Setting controlling tty using TIOCSCTTY.");-
107 if (ioctl(*ttyfd,
ioctl(*ttyfd, ...oid *)0) ) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
108 0x540E
ioctl(*ttyfd, ...oid *)0) ) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
109 ,
ioctl(*ttyfd, ...oid *)0) ) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
110 ((void *)0)
ioctl(*ttyfd, ...oid *)0) ) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
111 ) < 0
ioctl(*ttyfd, ...oid *)0) ) < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
112 error("ioctl(TIOCSCTTY): %.100s", strerror(
never executed: error("ioctl(TIOCSCTTY): %.100s", strerror( (*__errno_location ()) ));
0
113 (*__errno_location ())
never executed: error("ioctl(TIOCSCTTY): %.100s", strerror( (*__errno_location ()) ));
0
114 ));
never executed: error("ioctl(TIOCSCTTY): %.100s", strerror( (*__errno_location ()) ));
0
115-
116-
117-
118-
119-
120 fd = open(tty, -
121 02-
122 );-
123 if (fd < 0
fd < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
124 error("%.100s: %.100s", tty, strerror(
never executed: error("%.100s: %.100s", tty, strerror( (*__errno_location ()) ));
0
125 (*__errno_location ())
never executed: error("%.100s: %.100s", tty, strerror( (*__errno_location ()) ));
0
126 ));
never executed: error("%.100s: %.100s", tty, strerror( (*__errno_location ()) ));
0
127 else-
128 close(fd);
never executed: close(fd);
0
129-
130-
131 fd = open(-
132 "/dev/tty"-
133 , -
134 01-
135 );-
136 if (fd < 0
fd < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
137 error("open /dev/tty failed - could not set controlling tty: %.100s",
never executed: error("open /dev/tty failed - could not set controlling tty: %.100s", strerror( (*__errno_location ()) ));
0
138 strerror(
never executed: error("open /dev/tty failed - could not set controlling tty: %.100s", strerror( (*__errno_location ()) ));
0
139 (*__errno_location ())
never executed: error("open /dev/tty failed - could not set controlling tty: %.100s", strerror( (*__errno_location ()) ));
0
140 ));
never executed: error("open /dev/tty failed - could not set controlling tty: %.100s", strerror( (*__errno_location ()) ));
0
141 else-
142 close(fd);
never executed: close(fd);
0
143}-
144-
145-
146-
147void-
148pty_change_window_size(int ptyfd, u_int row, u_int col,-
149 u_int xpixel, u_int ypixel)-
150{-
151 struct winsize w;-
152-
153-
154 w.ws_row = row;-
155 w.ws_col = col;-
156 w.ws_xpixel = xpixel;-
157 w.ws_ypixel = ypixel;-
158 (void) ioctl(ptyfd, -
159 0x5414-
160 , &w);-
161}
never executed: end of block
0
162-
163void-
164pty_setowner(struct passwd *pw, const char *tty)-
165{-
166 struct group *grp;-
167 gid_t gid;-
168 mode_t mode;-
169 struct stat st;-
170-
171-
172 grp = getgrnam("tty");-
173 gid = (
(grp != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
grp !=
(grp != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
174 ((void *)0)
(grp != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
175 )
(grp != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
? grp->gr_gid : pw->pw_gid;
0
176 mode = (
(grp != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
grp !=
(grp != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
177 ((void *)0)
(grp != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
178 )
(grp != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
? 0620 : 0600;
0
179-
180-
181-
182-
183-
184-
185 if (stat(tty, &st)
stat(tty, &st)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
186 fatal("stat(%.100s) failed: %.100s", tty,
never executed: fatal("stat(%.100s) failed: %.100s", tty, strerror( (*__errno_location ()) ));
0
187 strerror(
never executed: fatal("stat(%.100s) failed: %.100s", tty, strerror( (*__errno_location ()) ));
0
188 (*__errno_location ())
never executed: fatal("stat(%.100s) failed: %.100s", tty, strerror( (*__errno_location ()) ));
0
189 ));
never executed: fatal("stat(%.100s) failed: %.100s", tty, strerror( (*__errno_location ()) ));
0
190-
191-
192-
193-
194-
195 if (st.st_uid != pw->pw_uid
st.st_uid != pw->pw_uidDescription
TRUEnever evaluated
FALSEnever evaluated
|| st.st_gid != gid
st.st_gid != gidDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
196 if (chown(tty, pw->pw_uid, gid) < 0
chown(tty, pw-..._uid, gid) < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
197 if (-
198 (*
(*__errno_location ()) == 30Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ())
(*__errno_location ()) == 30Description
TRUEnever evaluated
FALSEnever evaluated
0
199 ==
(*__errno_location ()) == 30Description
TRUEnever evaluated
FALSEnever evaluated
0
200 30
(*__errno_location ()) == 30Description
TRUEnever evaluated
FALSEnever evaluated
0
201 &&-
202 (st.st_uid == pw->pw_uid
st.st_uid == pw->pw_uidDescription
TRUEnever evaluated
FALSEnever evaluated
|| st.st_uid == 0
st.st_uid == 0Description
TRUEnever evaluated
FALSEnever evaluated
))
0
203 debug("chown(%.100s, %u, %u) failed: %.100s",
never executed: debug("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
204 tty, (u_int)pw->pw_uid, (u_int)gid,
never executed: debug("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
205 strerror(
never executed: debug("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
206 (*__errno_location ())
never executed: debug("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
207 ));
never executed: debug("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
208 else-
209 fatal("chown(%.100s, %u, %u) failed: %.100s",
never executed: fatal("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
210 tty, (u_int)pw->pw_uid, (u_int)gid,
never executed: fatal("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
211 strerror(
never executed: fatal("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
212 (*__errno_location ())
never executed: fatal("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
213 ));
never executed: fatal("chown(%.100s, %u, %u) failed: %.100s", tty, (u_int)pw->pw_uid, (u_int)gid, strerror( (*__errno_location ()) ));
0
214 }-
215 }
never executed: end of block
0
216-
217 if ((
(st.st_mode & ... 3) )) != modeDescription
TRUEnever evaluated
FALSEnever evaluated
st.st_mode & (
(st.st_mode & ... 3) )) != modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
218 (0400|0200|0100)
(st.st_mode & ... 3) )) != modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
219 |
(st.st_mode & ... 3) )) != modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
220 ((0400|0200|0100) >> 3)
(st.st_mode & ... 3) )) != modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
221 |
(st.st_mode & ... 3) )) != modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
222 (((0400|0200|0100) >> 3) >> 3)
(st.st_mode & ... 3) )) != modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
223 )) != mode
(st.st_mode & ... 3) )) != modeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
224 if (chmod(tty, mode) < 0
chmod(tty, mode) < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
225 if (-
226 (*
(*__errno_location ()) == 30Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ())
(*__errno_location ()) == 30Description
TRUEnever evaluated
FALSEnever evaluated
0
227 ==
(*__errno_location ()) == 30Description
TRUEnever evaluated
FALSEnever evaluated
0
228 30
(*__errno_location ()) == 30Description
TRUEnever evaluated
FALSEnever evaluated
0
229 &&-
230 (
(st.st_mode & ... >> 3) )) == 0Description
TRUEnever evaluated
FALSEnever evaluated
st.st_mode & (
(st.st_mode & ... >> 3) )) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
231 (0400 >> 3)
(st.st_mode & ... >> 3) )) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
232 |
(st.st_mode & ... >> 3) )) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
233 ((0400 >> 3) >> 3)
(st.st_mode & ... >> 3) )) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
234 )) == 0
(st.st_mode & ... >> 3) )) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
235 debug("chmod(%.100s, 0%o) failed: %.100s",
never executed: debug("chmod(%.100s, 0%o) failed: %.100s", tty, (u_int)mode, strerror( (*__errno_location ()) ));
0
236 tty, (u_int)mode, strerror(
never executed: debug("chmod(%.100s, 0%o) failed: %.100s", tty, (u_int)mode, strerror( (*__errno_location ()) ));
0
237 (*__errno_location ())
never executed: debug("chmod(%.100s, 0%o) failed: %.100s", tty, (u_int)mode, strerror( (*__errno_location ()) ));
0
238 ));
never executed: debug("chmod(%.100s, 0%o) failed: %.100s", tty, (u_int)mode, strerror( (*__errno_location ()) ));
0
239 else-
240 fatal("chmod(%.100s, 0%o) failed: %.100s",
never executed: fatal("chmod(%.100s, 0%o) failed: %.100s", tty, (u_int)mode, strerror( (*__errno_location ()) ));
0
241 tty, (u_int)mode, strerror(
never executed: fatal("chmod(%.100s, 0%o) failed: %.100s", tty, (u_int)mode, strerror( (*__errno_location ()) ));
0
242 (*__errno_location ())
never executed: fatal("chmod(%.100s, 0%o) failed: %.100s", tty, (u_int)mode, strerror( (*__errno_location ()) ));
0
243 ));
never executed: fatal("chmod(%.100s, 0%o) failed: %.100s", tty, (u_int)mode, strerror( (*__errno_location ()) ));
0
244 }-
245 }
never executed: end of block
0
246}
never executed: end of block
0
247-
248-
249void-
250disconnect_controlling_tty(void)-
251{-
252-
253 int fd;-
254-
255 if ((
(fd = open( "/...| 0400 )) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
fd = open(
(fd = open( "/...| 0400 )) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
256 "/dev/tty"
(fd = open( "/...| 0400 )) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
257 ,
(fd = open( "/...| 0400 )) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
258 02
(fd = open( "/...| 0400 )) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
259 |
(fd = open( "/...| 0400 )) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
260 0400
(fd = open( "/...| 0400 )) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
261 )) >= 0
(fd = open( "/...| 0400 )) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
262 (void) ioctl(fd, -
263 0x5422-
264 , -
265 ((void *)0)-
266 );-
267 close(fd);-
268 }
never executed: end of block
0
269-
270}
never executed: end of block
0
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2