Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | int | - |
19 | pty_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 < 0TRUE | never evaluated | FALSE | never 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 (!nameTRUE | never evaluated | FALSE | never 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 | | - |
48 | void | - |
49 | pty_release(const char *tty) | - |
50 | { | - |
51 | | - |
52 | | - |
53 | | - |
54 | | - |
55 | | - |
56 | | - |
57 | } | - |
58 | | - |
59 | | - |
60 | | - |
61 | void | - |
62 | pty_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 >= 0TRUE | never evaluated | FALSE | never 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() < 0TRUE | never evaluated | FALSE | never 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 >= 0TRUE | never evaluated | FALSE | never 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, TRUE | never evaluated | FALSE | never evaluated |
| 0 |
108 | 0x540ETRUE | never evaluated | FALSE | never evaluated |
| 0 |
109 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
110 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
111 | ) < 0TRUE | never evaluated | FALSE | never 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 < 0TRUE | never evaluated | FALSE | never 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 < 0TRUE | never evaluated | FALSE | never 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 | | - |
147 | void | - |
148 | pty_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 | | - |
163 | void | - |
164 | pty_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 = (TRUE | never evaluated | FALSE | never evaluated |
grp != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
174 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
175 | )TRUE | never evaluated | FALSE | never evaluated |
? grp->gr_gid : pw->pw_gid; | 0 |
176 | mode = (TRUE | never evaluated | FALSE | never evaluated |
grp != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
177 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
178 | )TRUE | never evaluated | FALSE | never evaluated |
? 0620 : 0600; | 0 |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | | - |
185 | if (stat(tty, &st)TRUE | never evaluated | FALSE | never 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_uidTRUE | never evaluated | FALSE | never evaluated |
|| st.st_gid != gidTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
196 | if (chown(tty, pw->pw_uid, gid) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
197 | if ( | - |
198 | (*TRUE | never evaluated | FALSE | never evaluated |
__errno_location ()) TRUE | never evaluated | FALSE | never evaluated |
| 0 |
199 | == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
200 | 30TRUE | never evaluated | FALSE | never evaluated |
| 0 |
201 | && | - |
202 | (st.st_uid == pw->pw_uidTRUE | never evaluated | FALSE | never evaluated |
|| st.st_uid == 0TRUE | never evaluated | FALSE | never 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 ((TRUE | never evaluated | FALSE | never evaluated |
st.st_mode & (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
218 | (0400|0200|0100)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
219 | |TRUE | never evaluated | FALSE | never evaluated |
| 0 |
220 | ((0400|0200|0100) >> 3)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
221 | |TRUE | never evaluated | FALSE | never evaluated |
| 0 |
222 | (((0400|0200|0100) >> 3) >> 3)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
223 | )) != modeTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
224 | if (chmod(tty, mode) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
225 | if ( | - |
226 | (*TRUE | never evaluated | FALSE | never evaluated |
__errno_location ()) TRUE | never evaluated | FALSE | never evaluated |
| 0 |
227 | == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
228 | 30TRUE | never evaluated | FALSE | never evaluated |
| 0 |
229 | && | - |
230 | (TRUE | never evaluated | FALSE | never evaluated |
st.st_mode & (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
231 | (0400 >> 3) TRUE | never evaluated | FALSE | never evaluated |
| 0 |
232 | | TRUE | never evaluated | FALSE | never evaluated |
| 0 |
233 | ((0400 >> 3) >> 3)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
234 | )) == 0TRUE | never evaluated | FALSE | never 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 | | - |
249 | void | - |
250 | disconnect_controlling_tty(void) | - |
251 | { | - |
252 | | - |
253 | int fd; | - |
254 | | - |
255 | if ((TRUE | never evaluated | FALSE | never evaluated |
fd = open(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
256 | "/dev/tty"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
257 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
258 | 02 TRUE | never evaluated | FALSE | never evaluated |
| 0 |
259 | | TRUE | never evaluated | FALSE | never evaluated |
| 0 |
260 | 0400TRUE | never evaluated | FALSE | never evaluated |
| 0 |
261 | )) >= 0TRUE | never evaluated | FALSE | never 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 |
| | |