Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | Session *session_new(void); | - |
24 | void session_set_fds(struct ssh *, Session *, int, int, int, int, int); | - |
25 | void session_pty_cleanup(Session *); | - |
26 | void session_proctitle(Session *); | - |
27 | int session_setup_x11fwd(struct ssh *, Session *); | - |
28 | int do_exec_pty(struct ssh *, Session *, const char *); | - |
29 | int do_exec_no_pty(struct ssh *, Session *, const char *); | - |
30 | int do_exec(struct ssh *, Session *, const char *); | - |
31 | void do_login(struct ssh *, Session *, const char *); | - |
32 | void do_child(struct ssh *, Session *, const char *); | - |
33 | | - |
34 | | - |
35 | | - |
36 | void do_motd(void); | - |
37 | int check_quietlogin(Session *, const char *); | - |
38 | | - |
39 | static void do_authenticated2(struct ssh *, Authctxt *); | - |
40 | | - |
41 | static int session_pty_req(struct ssh *, Session *); | - |
42 | | - |
43 | | - |
44 | extern ServerOptions options; | - |
45 | extern char *__progname; | - |
46 | extern int debug_flag; | - |
47 | extern u_int utmp_len; | - |
48 | extern int startup_pipe; | - |
49 | extern void destroy_sensitive_data(void); | - |
50 | extern struct sshbuf *loginmsg; | - |
51 | extern struct sshauthopt *auth_opts; | - |
52 | char *tun_fwd_ifnames; | - |
53 | | - |
54 | | - |
55 | const char *original_command = | - |
56 | ((void *)0) | - |
57 | ; | - |
58 | | - |
59 | | - |
60 | static int sessions_first_unused = -1; | - |
61 | static int sessions_nalloc = 0; | - |
62 | static Session *sessions = | - |
63 | ((void *)0) | - |
64 | ; | - |
65 | static int is_child = 0; | - |
66 | static int in_chroot = 0; | - |
67 | | - |
68 | | - |
69 | static char *auth_info_file = | - |
70 | ((void *)0) | - |
71 | ; | - |
72 | | - |
73 | | - |
74 | static char *auth_sock_name = | - |
75 | ((void *)0) | - |
76 | ; | - |
77 | static char *auth_sock_dir = | - |
78 | ((void *)0) | - |
79 | ; | - |
80 | | - |
81 | | - |
82 | | - |
83 | static void | - |
84 | auth_sock_cleanup_proc(struct passwd *pw) | - |
85 | { | - |
86 | if (auth_sock_name != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
87 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
88 | ) { | - |
89 | temporarily_use_uid(pw); | - |
90 | unlink(auth_sock_name); | - |
91 | rmdir(auth_sock_dir); | - |
92 | auth_sock_name = | - |
93 | ((void *)0) | - |
94 | ; | - |
95 | restore_uid(); | - |
96 | } never executed: end of block | 0 |
97 | } never executed: end of block | 0 |
98 | | - |
99 | static int | - |
100 | auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw) | - |
101 | { | - |
102 | Channel *nc; | - |
103 | int sock = -1; | - |
104 | | - |
105 | if (auth_sock_name != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
106 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
107 | ) { | - |
108 | error("authentication forwarding requested twice."); | - |
109 | return never executed: return 0; 0;never executed: return 0; | 0 |
110 | } | - |
111 | | - |
112 | | - |
113 | temporarily_use_uid(pw); | - |
114 | | - |
115 | | - |
116 | auth_sock_dir = xstrdup("/tmp/ssh-XXXXXXXXXX"); | - |
117 | | - |
118 | | - |
119 | if (mkdtemp(auth_sock_dir) == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
120 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
121 | ) { | - |
122 | packet_send_debug("Agent forwarding disabled: " | - |
123 | "mkdtemp() failed: %.100s", strerror( | - |
124 | (*__errno_location ()) | - |
125 | )); | - |
126 | restore_uid(); | - |
127 | free(auth_sock_dir); | - |
128 | auth_sock_dir = | - |
129 | ((void *)0) | - |
130 | ; | - |
131 | goto never executed: goto authsock_err; authsock_err;never executed: goto authsock_err; | 0 |
132 | } | - |
133 | | - |
134 | xasprintf(&auth_sock_name, "%s/agent.%ld", | - |
135 | auth_sock_dir, (long) getpid()); | - |
136 | | - |
137 | | - |
138 | sock = unix_listener(auth_sock_name, 128, 0); | - |
139 | | - |
140 | | - |
141 | restore_uid(); | - |
142 | | - |
143 | | - |
144 | if (sock < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
145 | goto never executed: goto authsock_err; authsock_err;never executed: goto authsock_err; | 0 |
146 | | - |
147 | | - |
148 | nc = channel_new(ssh, "auth socket", | - |
149 | 6, sock, sock, -1, | - |
150 | (4*(16*1024)), (16*1024), | - |
151 | 0, "auth socket", 1); | - |
152 | nc->path = xstrdup(auth_sock_name); | - |
153 | return never executed: return 1; 1;never executed: return 1; | 0 |
154 | | - |
155 | authsock_err: | - |
156 | free(auth_sock_name); | - |
157 | if (auth_sock_dir != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
158 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
159 | ) { | - |
160 | rmdir(auth_sock_dir); | - |
161 | free(auth_sock_dir); | - |
162 | } never executed: end of block | 0 |
163 | if (sock != -1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
164 | close(sock); never executed: close(sock); | 0 |
165 | auth_sock_name = | - |
166 | ((void *)0) | - |
167 | ; | - |
168 | auth_sock_dir = | - |
169 | ((void *)0) | - |
170 | ; | - |
171 | return never executed: return 0; 0;never executed: return 0; | 0 |
172 | } | - |
173 | | - |
174 | static void | - |
175 | display_loginmsg(void) | - |
176 | { | - |
177 | int r; | - |
178 | | - |
179 | if (sshbuf_len(loginmsg) == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
180 | return; never executed: return; | 0 |
181 | if ((TRUE | never evaluated | FALSE | never evaluated |
r = sshbuf_put_u8(loginmsg, 0)) != 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
182 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); never executed: fatal("%s: buffer error: %s", __func__, ssh_err(r)); | 0 |
183 | printf("%s", (char *)sshbuf_ptr(loginmsg)); | - |
184 | sshbuf_reset(loginmsg); | - |
185 | } never executed: end of block | 0 |
186 | | - |
187 | static void | - |
188 | prepare_auth_info_file(struct passwd *pw, struct sshbuf *info) | - |
189 | { | - |
190 | int fd = -1, success = 0; | - |
191 | | - |
192 | if (!options.expose_userauth_infoTRUE | never evaluated | FALSE | never evaluated |
|| info == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
193 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
194 | ) | - |
195 | return; never executed: return; | 0 |
196 | | - |
197 | temporarily_use_uid(pw); | - |
198 | auth_info_file = xstrdup("/tmp/sshauth.XXXXXXXXXXXXXXX"); | - |
199 | if ((TRUE | never evaluated | FALSE | never evaluated |
fd = mkstemp(auth_info_file)) == -1TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
200 | error("%s: mkstemp: %s", __func__, strerror( | - |
201 | (*__errno_location ()) | - |
202 | )); | - |
203 | goto never executed: goto out; out;never executed: goto out; | 0 |
204 | } | - |
205 | if (atomicio((ssize_t (*)(int, void *, size_t))write, fd, sshbuf_mutable_ptr(info),TRUE | never evaluated | FALSE | never evaluated |
| 0 |
206 | sshbuf_len(info)) != sshbuf_len(info)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
207 | error("%s: write: %s", __func__, strerror( | - |
208 | (*__errno_location ()) | - |
209 | )); | - |
210 | goto never executed: goto out; out;never executed: goto out; | 0 |
211 | } | - |
212 | if (close(fd) != 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
213 | error("%s: close: %s", __func__, strerror( | - |
214 | (*__errno_location ()) | - |
215 | )); | - |
216 | goto never executed: goto out; out;never executed: goto out; | 0 |
217 | } | - |
218 | success = 1; | - |
219 | out: code before this statement never executed: out: | 0 |
220 | if (!successTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
221 | if (fd != -1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
222 | close(fd); never executed: close(fd); | 0 |
223 | free(auth_info_file); | - |
224 | auth_info_file = | - |
225 | ((void *)0) | - |
226 | ; | - |
227 | } never executed: end of block | 0 |
228 | restore_uid(); | - |
229 | } never executed: end of block | 0 |
230 | | - |
231 | static void | - |
232 | set_fwdpermit_from_authopts(struct ssh *ssh, const struct sshauthopt *opts) | - |
233 | { | - |
234 | char *tmp, *cp, *host; | - |
235 | int port; | - |
236 | size_t i; | - |
237 | | - |
238 | if ((TRUE | never evaluated | FALSE | never evaluated |
options.allow_tcp_forwarding & (1<<1)) != 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
239 | channel_clear_permission(ssh, 0x101, (1<<1)); | - |
240 | for (i = 0; i < auth_opts->npermitopenTRUE | never evaluated | FALSE | never evaluated |
; i++) { | 0 |
241 | tmp = cp = xstrdup(auth_opts->permitopen[i]); | - |
242 | | - |
243 | if ((TRUE | never evaluated | FALSE | never evaluated |
host = hpdelim(&cp)) == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
244 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
245 | ) | - |
246 | fatal("%s: internal error: hpdelim", __func__); never executed: fatal("%s: internal error: hpdelim", __func__); | 0 |
247 | host = cleanhostname(host); | - |
248 | if (cp == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
249 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
250 | || (TRUE | never evaluated | FALSE | never evaluated |
port = permitopen_port(cp)) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
251 | fatal("%s: internal error: permitopen port", never executed: fatal("%s: internal error: permitopen port", __func__); | 0 |
252 | __func__); never executed: fatal("%s: internal error: permitopen port", __func__); | 0 |
253 | channel_add_permission(ssh, | - |
254 | 0x101, (1<<1), host, port); | - |
255 | free(tmp); | - |
256 | } never executed: end of block | 0 |
257 | } never executed: end of block | 0 |
258 | if ((TRUE | never evaluated | FALSE | never evaluated |
options.allow_tcp_forwarding & (1)) != 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
259 | channel_clear_permission(ssh, 0x101, (1)); | - |
260 | for (i = 0; i < auth_opts->npermitlistenTRUE | never evaluated | FALSE | never evaluated |
; i++) { | 0 |
261 | tmp = cp = xstrdup(auth_opts->permitlisten[i]); | - |
262 | | - |
263 | if ((TRUE | never evaluated | FALSE | never evaluated |
host = hpdelim(&cp)) == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
264 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
265 | ) | - |
266 | fatal("%s: internal error: hpdelim", __func__); never executed: fatal("%s: internal error: hpdelim", __func__); | 0 |
267 | host = cleanhostname(host); | - |
268 | if (cp == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
269 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
270 | || (TRUE | never evaluated | FALSE | never evaluated |
port = permitopen_port(cp)) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
271 | fatal("%s: internal error: permitlisten port", never executed: fatal("%s: internal error: permitlisten port", __func__); | 0 |
272 | __func__); never executed: fatal("%s: internal error: permitlisten port", __func__); | 0 |
273 | channel_add_permission(ssh, | - |
274 | 0x101, (1), host, port); | - |
275 | free(tmp); | - |
276 | } never executed: end of block | 0 |
277 | } never executed: end of block | 0 |
278 | } never executed: end of block | 0 |
279 | | - |
280 | void | - |
281 | do_authenticated(struct ssh *ssh, Authctxt *authctxt) | - |
282 | { | - |
283 | setproctitle("%s", authctxt->pw->pw_name); | - |
284 | | - |
285 | auth_log_authopts("active", auth_opts, 0); | - |
286 | | - |
287 | | - |
288 | | - |
289 | set_fwdpermit_from_authopts(ssh, auth_opts); | - |
290 | | - |
291 | if (!auth_opts->permit_port_forwarding_flagTRUE | never evaluated | FALSE | never evaluated |
|| | 0 |
292 | options.disable_forwardingTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
293 | channel_disable_admin(ssh, (1<<1)); | - |
294 | channel_disable_admin(ssh, (1)); | - |
295 | } never executed: end of block else { | 0 |
296 | if ((TRUE | never evaluated | FALSE | never evaluated |
options.allow_tcp_forwarding & (1<<1)) == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
297 | channel_disable_admin(ssh, (1<<1)); never executed: channel_disable_admin(ssh, (1<<1)); | 0 |
298 | else | - |
299 | channel_permit_all(ssh, (1<<1)); never executed: channel_permit_all(ssh, (1<<1)); | 0 |
300 | if ((TRUE | never evaluated | FALSE | never evaluated |
options.allow_tcp_forwarding & (1)) == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
301 | channel_disable_admin(ssh, (1)); never executed: channel_disable_admin(ssh, (1)); | 0 |
302 | else | - |
303 | channel_permit_all(ssh, (1)); never executed: channel_permit_all(ssh, (1)); | 0 |
304 | } | - |
305 | auth_debug_send(); | - |
306 | | - |
307 | prepare_auth_info_file(authctxt->pw, authctxt->session_info); | - |
308 | | - |
309 | do_authenticated2(ssh, authctxt); | - |
310 | | - |
311 | do_cleanup(ssh, authctxt); | - |
312 | } never executed: end of block | 0 |
313 | | - |
314 | | - |
315 | static int | - |
316 | xauth_valid_string(const char *s) | - |
317 | { | - |
318 | size_t i; | - |
319 | | - |
320 | for (i = 0; s[i] != '\0'TRUE | never evaluated | FALSE | never evaluated |
; i++) { | 0 |
321 | if (!TRUE | never evaluated | FALSE | never evaluated |
| 0 |
322 | ((*__ctype_b_loc ())[(int) ((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
323 | (u_char)s[i]TRUE | never evaluated | FALSE | never evaluated |
| 0 |
324 | ))] & (unsigned short int) _ISalnum)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
325 | && | - |
326 | s[i] != '.'TRUE | never evaluated | FALSE | never evaluated |
&& s[i] != ':'TRUE | never evaluated | FALSE | never evaluated |
&& s[i] != '/'TRUE | never evaluated | FALSE | never evaluated |
&& | 0 |
327 | s[i] != '-'TRUE | never evaluated | FALSE | never evaluated |
&& s[i] != '_'TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
328 | return never executed: return 0; 0;never executed: return 0; | 0 |
329 | } never executed: end of block | 0 |
330 | return never executed: return 1; 1;never executed: return 1; | 0 |
331 | } | - |
332 | | - |
333 | | - |
334 | | - |
335 | | - |
336 | | - |
337 | | - |
338 | | - |
339 | int | - |
340 | do_exec_no_pty(struct ssh *ssh, Session *s, const char *command) | - |
341 | { | - |
342 | pid_t pid; | - |
343 | | - |
344 | int pin[2], pout[2], perr[2]; | - |
345 | | - |
346 | if (s == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
347 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
348 | ) | - |
349 | fatal("do_exec_no_pty: no session"); never executed: fatal("do_exec_no_pty: no session"); | 0 |
350 | | - |
351 | | - |
352 | if (pipe(pin) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
353 | error("%s: pipe in: %.100s", __func__, strerror( | - |
354 | (*__errno_location ()) | - |
355 | )); | - |
356 | return never executed: return -1; -1;never executed: return -1; | 0 |
357 | } | - |
358 | if (pipe(pout) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
359 | error("%s: pipe out: %.100s", __func__, strerror( | - |
360 | (*__errno_location ()) | - |
361 | )); | - |
362 | close(pin[0]); | - |
363 | close(pin[1]); | - |
364 | return never executed: return -1; -1;never executed: return -1; | 0 |
365 | } | - |
366 | if (pipe(perr) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
367 | error("%s: pipe err: %.100s", __func__, | - |
368 | strerror( | - |
369 | (*__errno_location ()) | - |
370 | )); | - |
371 | close(pin[0]); | - |
372 | close(pin[1]); | - |
373 | close(pout[0]); | - |
374 | close(pout[1]); | - |
375 | return never executed: return -1; -1;never executed: return -1; | 0 |
376 | } | - |
377 | session_proctitle(s); | - |
378 | | - |
379 | | - |
380 | switch ((pid = fork())) { | - |
381 | case never executed: case -1: -1:never executed: case -1: | 0 |
382 | error("%s: fork: %.100s", __func__, strerror( | - |
383 | (*__errno_location ()) | - |
384 | )); | - |
385 | | - |
386 | close(pin[0]); | - |
387 | close(pin[1]); | - |
388 | close(pout[0]); | - |
389 | close(pout[1]); | - |
390 | close(perr[0]); | - |
391 | close(perr[1]); | - |
392 | | - |
393 | | - |
394 | | - |
395 | | - |
396 | | - |
397 | | - |
398 | return never executed: return -1; -1;never executed: return -1; | 0 |
399 | case never executed: case 0: 0:never executed: case 0: | 0 |
400 | is_child = 1; | - |
401 | | - |
402 | | - |
403 | | - |
404 | | - |
405 | | - |
406 | if (setsid() < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
407 | error("setsid failed: %.100s", strerror( never executed: error("setsid failed: %.100s", strerror( (*__errno_location ()) )); | 0 |
408 | (*__errno_location ()) never executed: error("setsid failed: %.100s", strerror( (*__errno_location ()) )); | 0 |
409 | )); never executed: error("setsid failed: %.100s", strerror( (*__errno_location ()) )); | 0 |
410 | | - |
411 | | - |
412 | | - |
413 | | - |
414 | | - |
415 | | - |
416 | close(pin[1]); | - |
417 | if (dup2(pin[0], 0) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
418 | perror("dup2 stdin"); never executed: perror("dup2 stdin"); | 0 |
419 | close(pin[0]); | - |
420 | | - |
421 | | - |
422 | close(pout[0]); | - |
423 | if (dup2(pout[1], 1) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
424 | perror("dup2 stdout"); never executed: perror("dup2 stdout"); | 0 |
425 | close(pout[1]); | - |
426 | | - |
427 | | - |
428 | close(perr[0]); | - |
429 | if (dup2(perr[1], 2) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
430 | perror("dup2 stderr"); never executed: perror("dup2 stderr"); | 0 |
431 | close(perr[1]); | - |
432 | do_child(ssh, s, command); | - |
433 | | - |
434 | default never executed: default: :never executed: default: code before this statement never executed: default: | 0 |
435 | break; never executed: break; | 0 |
436 | } | - |
437 | | - |
438 | | - |
439 | | - |
440 | | - |
441 | | - |
442 | s->pid = pid; | - |
443 | | - |
444 | ssh_packet_set_interactive(active_state, (s->display != | - |
445 | ((void *)0) | - |
446 | ), (options.ip_qos_interactive), (options.ip_qos_bulk)) | - |
447 | ; | - |
448 | | - |
449 | | - |
450 | | - |
451 | | - |
452 | | - |
453 | | - |
454 | sshbuf_reset(loginmsg); | - |
455 | | - |
456 | | - |
457 | | - |
458 | close(pin[0]); | - |
459 | close(pout[1]); | - |
460 | close(perr[1]); | - |
461 | | - |
462 | session_set_fds(ssh, s, pin[1], pout[0], perr[0], | - |
463 | s->is_subsystem, 0); | - |
464 | return never executed: return 0; 0;never executed: return 0; | 0 |
465 | } | - |
466 | | - |
467 | | - |
468 | | - |
469 | | - |
470 | | - |
471 | | - |
472 | | - |
473 | int | - |
474 | do_exec_pty(struct ssh *ssh, Session *s, const char *command) | - |
475 | { | - |
476 | int fdout, ptyfd, ttyfd, ptymaster; | - |
477 | pid_t pid; | - |
478 | | - |
479 | if (s == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
480 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
481 | ) | - |
482 | fatal("do_exec_pty: no session"); never executed: fatal("do_exec_pty: no session"); | 0 |
483 | ptyfd = s->ptyfd; | - |
484 | ttyfd = s->ttyfd; | - |
485 | if ((TRUE | never evaluated | FALSE | never evaluated |
fdout = dup(ptyfd)) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
486 | error("%s: dup #1: %s", __func__, strerror( | - |
487 | (*__errno_location ()) | - |
488 | )); | - |
489 | close(ttyfd); | - |
490 | close(ptyfd); | - |
491 | return never executed: return -1; -1;never executed: return -1; | 0 |
492 | } | - |
493 | | - |
494 | if ((TRUE | never evaluated | FALSE | never evaluated |
ptymaster = dup(ptyfd)) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
495 | error("%s: dup #2: %s", __func__, strerror( | - |
496 | (*__errno_location ()) | - |
497 | )); | - |
498 | close(ttyfd); | - |
499 | close(ptyfd); | - |
500 | close(fdout); | - |
501 | return never executed: return -1; -1;never executed: return -1; | 0 |
502 | } | - |
503 | | - |
504 | | - |
505 | switch ((pid = fork())) { | - |
506 | case never executed: case -1: -1:never executed: case -1: | 0 |
507 | error("%s: fork: %.100s", __func__, strerror( | - |
508 | (*__errno_location ()) | - |
509 | )); | - |
510 | close(fdout); | - |
511 | close(ptymaster); | - |
512 | close(ttyfd); | - |
513 | close(ptyfd); | - |
514 | return never executed: return -1; -1;never executed: return -1; | 0 |
515 | case never executed: case 0: 0:never executed: case 0: | 0 |
516 | is_child = 1; | - |
517 | | - |
518 | close(fdout); | - |
519 | close(ptymaster); | - |
520 | | - |
521 | | - |
522 | close(ptyfd); | - |
523 | | - |
524 | | - |
525 | pty_make_controlling_tty(&ttyfd, s->tty); | - |
526 | | - |
527 | | - |
528 | if (dup2(ttyfd, 0) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
529 | error("dup2 stdin: %s", strerror( never executed: error("dup2 stdin: %s", strerror( (*__errno_location ()) )); | 0 |
530 | (*__errno_location ()) never executed: error("dup2 stdin: %s", strerror( (*__errno_location ()) )); | 0 |
531 | )); never executed: error("dup2 stdin: %s", strerror( (*__errno_location ()) )); | 0 |
532 | if (dup2(ttyfd, 1) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
533 | error("dup2 stdout: %s", strerror( never executed: error("dup2 stdout: %s", strerror( (*__errno_location ()) )); | 0 |
534 | (*__errno_location ()) never executed: error("dup2 stdout: %s", strerror( (*__errno_location ()) )); | 0 |
535 | )); never executed: error("dup2 stdout: %s", strerror( (*__errno_location ()) )); | 0 |
536 | if (dup2(ttyfd, 2) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
537 | error("dup2 stderr: %s", strerror( never executed: error("dup2 stderr: %s", strerror( (*__errno_location ()) )); | 0 |
538 | (*__errno_location ()) never executed: error("dup2 stderr: %s", strerror( (*__errno_location ()) )); | 0 |
539 | )); never executed: error("dup2 stderr: %s", strerror( (*__errno_location ()) )); | 0 |
540 | | - |
541 | | - |
542 | close(ttyfd); | - |
543 | | - |
544 | | - |
545 | | - |
546 | do_login(ssh, s, command); | - |
547 | | - |
548 | | - |
549 | | - |
550 | | - |
551 | | - |
552 | do_child(ssh, s, command); | - |
553 | | - |
554 | default never executed: default: :never executed: default: code before this statement never executed: default: | 0 |
555 | break; never executed: break; | 0 |
556 | } | - |
557 | | - |
558 | | - |
559 | | - |
560 | | - |
561 | | - |
562 | s->pid = pid; | - |
563 | | - |
564 | | - |
565 | close(ttyfd); | - |
566 | | - |
567 | | - |
568 | s->ptymaster = ptymaster; | - |
569 | ssh_packet_set_interactive(active_state, (1), (options.ip_qos_interactive), (options.ip_qos_bulk)) | - |
570 | ; | - |
571 | session_set_fds(ssh, s, ptyfd, fdout, -1, 1, 1); | - |
572 | return never executed: return 0; 0;never executed: return 0; | 0 |
573 | } | - |
574 | int | - |
575 | do_exec(struct ssh *ssh, Session *s, const char *command) | - |
576 | { | - |
577 | int ret; | - |
578 | const char *forced = | - |
579 | ((void *)0) | - |
580 | , *tty = | - |
581 | ((void *)0) | - |
582 | ; | - |
583 | char session_type[1024]; | - |
584 | | - |
585 | if (options.adm_forced_commandTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
586 | original_command = command; | - |
587 | command = options.adm_forced_command; | - |
588 | forced = "(config)"; | - |
589 | } never executed: end of block else if (auth_opts->force_command != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
590 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
591 | ) { | - |
592 | original_command = command; | - |
593 | command = auth_opts->force_command; | - |
594 | forced = "(key-option)"; | - |
595 | } never executed: end of block | 0 |
596 | if (forced != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
597 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
598 | ) { | - |
599 | if ((!TRUE | never evaluated | FALSE | never evaluated |
| 0 |
600 | (__extension__ (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
601 | sizeof("internal-sftp") - 1TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
602 | )TRUE | never evaluated | FALSE | never evaluated |
&& ((__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
603 | commandTRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
604 | )TRUE | never evaluated | FALSE | never evaluated |
&& strlen (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
605 | commandTRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
606 | ) < ((size_t) (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
607 | sizeof("internal-sftp") - 1TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
608 | ))TRUE | never evaluated | FALSE | never evaluated |
) || (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
609 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
610 | )TRUE | never evaluated | FALSE | never evaluated |
&& strlen (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
611 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
612 | ) < ((size_t) (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
613 | sizeof("internal-sftp") - 1TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
614 | ))TRUE | never evaluated | FALSE | never evaluated |
)) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
615 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
616 | ) && __builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
617 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
618 | ) && (__s1_len = __builtin_strlen (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
619 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
620 | ), __s2_len = __builtin_strlen (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
621 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
622 | ), (!((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
623 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
624 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
625 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
626 | ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
627 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
628 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
629 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
630 | ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
631 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
632 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
633 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
634 | ) : (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
635 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
636 | ) && ((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
637 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
638 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
639 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
640 | ) == 1) && (__s1_len = __builtin_strlen (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
641 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
642 | ), __s1_len < 4) ? (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
643 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
644 | ) && ((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
645 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
646 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
647 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
648 | ) == 1) ? __builtin_strcmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
649 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
650 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
651 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
652 | ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
653 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
654 | ); int __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
655 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
656 | ))[0] - __s2[0]); if (__s1_len > 0TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) { __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
657 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
658 | ))[1] - __s2[1]); if (__s1_len > 1TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) { __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
659 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
660 | ))[2] - __s2[2]); if (__s1_len > 2TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) __result = (((const unsigned char *) (const char *) (never executed: __result = (((const unsigned char *) (const char *) ( command ))[3] - __s2[3]); | 0 |
661 | commandTRUE | never evaluated | FALSE | never evaluated |
never executed: __result = (((const unsigned char *) (const char *) ( command ))[3] - __s2[3]); | 0 |
662 | ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
663 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
664 | ) && ((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
665 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
666 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
667 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
668 | ) == 1) && (__s2_len = __builtin_strlen (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
669 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
670 | ), __s2_len < 4) ? (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
671 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
672 | ) && ((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
673 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
674 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
675 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
676 | ) == 1) ? __builtin_strcmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
677 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
678 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
679 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
680 | ) : -(__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
681 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
682 | ); int __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
683 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
684 | ))[0] - __s2[0]); if (__s2_len > 0TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) { __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
685 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
686 | ))[1] - __s2[1]); if (__s2_len > 1TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) { __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
687 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
688 | ))[2] - __s2[2]); if (__s2_len > 2TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) __result = (((const unsigned char *) (const char *) (never executed: __result = (((const unsigned char *) (const char *) ( "internal-sftp" ))[3] - __s2[3]); | 0 |
689 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
never executed: __result = (((const unsigned char *) (const char *) ( "internal-sftp" ))[3] - __s2[3]); | 0 |
690 | ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
691 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
692 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
693 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
694 | )))); }) : strncmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
695 | commandTRUE | never evaluated | FALSE | never evaluated |
| 0 |
696 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
697 | "internal-sftp"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
698 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
699 | sizeof("internal-sftp") - 1TRUE | never evaluated | FALSE | never evaluated |
| 0 |
700 | )))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
701 | && (command[sizeof("internal-sftp") - 1] == '\0'TRUE | never evaluated | FALSE | never evaluated |
|| command[sizeof("internal-sftp") - 1] == ' 'TRUE | never evaluated | FALSE | never evaluated |
|| command[sizeof("internal-sftp") - 1] == '\t'TRUE | never evaluated | FALSE | never evaluated |
))) { | 0 |
702 | s->is_subsystem = s->is_subsystemTRUE | never evaluated | FALSE | never evaluated |
? | 0 |
703 | 2 : 3; | - |
704 | } never executed: end of block else if (s->is_subsystemTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
705 | s->is_subsystem = 1; never executed: s->is_subsystem = 1; | 0 |
706 | snprintf(session_type, sizeof(session_type), | - |
707 | "forced-command %s '%.900s'", forced, command); | - |
708 | } never executed: end of block else if (s->is_subsystemTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
709 | snprintf(session_type, sizeof(session_type), | - |
710 | "subsystem '%.900s'", s->subsys); | - |
711 | } never executed: end of block else if (command == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
712 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
713 | ) { | - |
714 | snprintf(session_type, sizeof(session_type), "shell"); | - |
715 | } never executed: end of block else { | 0 |
716 | | - |
717 | snprintf(session_type, sizeof(session_type), "command"); | - |
718 | } never executed: end of block | 0 |
719 | | - |
720 | if (s->ttyfd != -1TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
721 | tty = s->tty; | - |
722 | if ( | - |
723 | (TRUE | never evaluated | FALSE | never evaluated |
__extension__ (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
724 | 5TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
725 | )TRUE | never evaluated | FALSE | never evaluated |
&& ((__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
726 | ttyTRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
727 | )TRUE | never evaluated | FALSE | never evaluated |
&& strlen (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
728 | ttyTRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
729 | ) < ((size_t) (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
730 | 5TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
731 | ))TRUE | never evaluated | FALSE | never evaluated |
) || (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
732 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
733 | )TRUE | never evaluated | FALSE | never evaluated |
&& strlen (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
734 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
735 | ) < ((size_t) (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
736 | 5TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
737 | ))TRUE | never evaluated | FALSE | never evaluated |
)) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
738 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
739 | ) && __builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
740 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
741 | ) && (__s1_len = __builtin_strlen (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
742 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
743 | ), __s2_len = __builtin_strlen (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
744 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
745 | ), (!((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
746 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
747 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
748 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
749 | ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
750 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
751 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
752 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
753 | ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
754 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
755 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
756 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
757 | ) : (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
758 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
759 | ) && ((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
760 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
761 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
762 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
763 | ) == 1) && (__s1_len = __builtin_strlen (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
764 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
765 | ), __s1_len < 4) ? (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
766 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
767 | ) && ((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
768 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
769 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
770 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
771 | ) == 1) ? __builtin_strcmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
772 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
773 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
774 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
775 | ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
776 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
777 | ); int __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
778 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
779 | ))[0] - __s2[0]); if (__s1_len > 0TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) { __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
780 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
781 | ))[1] - __s2[1]); if (__s1_len > 1TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) { __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
782 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
783 | ))[2] - __s2[2]); if (__s1_len > 2TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) __result = (((const unsigned char *) (const char *) (never executed: __result = (((const unsigned char *) (const char *) ( tty ))[3] - __s2[3]); | 0 |
784 | ttyTRUE | never evaluated | FALSE | never evaluated |
never executed: __result = (((const unsigned char *) (const char *) ( tty ))[3] - __s2[3]); | 0 |
785 | ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
786 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
787 | ) && ((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
788 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
789 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
790 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
791 | ) == 1) && (__s2_len = __builtin_strlen (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
792 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
793 | ), __s2_len < 4) ? (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
794 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
795 | ) && ((size_t)(const void *)((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
796 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
797 | ) + 1) - (size_t)(const void *)(TRUE | never evaluated | FALSE | never evaluated |
| 0 |
798 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
799 | ) == 1) ? __builtin_strcmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
800 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
801 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
802 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
803 | ) : -(__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
804 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
805 | ); int __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
806 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
807 | ))[0] - __s2[0]); if (__s2_len > 0TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) { __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
808 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
809 | ))[1] - __s2[1]); if (__s2_len > 1TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) { __result = (((const unsigned char *) (const char *) (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
810 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
811 | ))[2] - __s2[2]); if (__s2_len > 2TRUE | never evaluated | FALSE | never evaluated |
&& __result == 0TRUE | never evaluated | FALSE | never evaluated |
) __result = (((const unsigned char *) (const char *) (never executed: __result = (((const unsigned char *) (const char *) ( "/dev/" ))[3] - __s2[3]); | 0 |
812 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
never executed: __result = (((const unsigned char *) (const char *) ( "/dev/" ))[3] - __s2[3]); | 0 |
813 | ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
814 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
815 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
816 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
817 | )))); }) : strncmp (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
818 | ttyTRUE | never evaluated | FALSE | never evaluated |
| 0 |
819 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
820 | "/dev/"TRUE | never evaluated | FALSE | never evaluated |
| 0 |
821 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
822 | 5TRUE | never evaluated | FALSE | never evaluated |
| 0 |
823 | ))) TRUE | never evaluated | FALSE | never evaluated |
| 0 |
824 | == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
825 | tty += 5; never executed: tty += 5; | 0 |
826 | } never executed: end of block | 0 |
827 | | - |
828 | verbose("Starting session: %s%s%s for %s from %.200s port %d id %d", | - |
829 | session_type, | - |
830 | tty == | - |
831 | ((void *)0) | - |
832 | ? "" : " on ", | - |
833 | tty == | - |
834 | ((void *)0) | - |
835 | ? "" : tty, | - |
836 | s->pw->pw_name, | - |
837 | ssh_remote_ipaddr(ssh), | - |
838 | ssh_remote_port(ssh), | - |
839 | s->self); | - |
840 | if (s->ttyfd != -1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
841 | ret = do_exec_pty(ssh, s, command); never executed: ret = do_exec_pty(ssh, s, command); | 0 |
842 | else | - |
843 | ret = do_exec_no_pty(ssh, s, command); never executed: ret = do_exec_no_pty(ssh, s, command); | 0 |
844 | | - |
845 | original_command = | - |
846 | ((void *)0) | - |
847 | ; | - |
848 | | - |
849 | | - |
850 | | - |
851 | | - |
852 | | - |
853 | | - |
854 | sshbuf_reset(loginmsg); | - |
855 | | - |
856 | return never executed: return ret; ret;never executed: return ret; | 0 |
857 | } | - |
858 | | - |
859 | | - |
860 | void | - |
861 | do_login(struct ssh *ssh, Session *s, const char *command) | - |
862 | { | - |
863 | socklen_t fromlen; | - |
864 | struct sockaddr_storage from; | - |
865 | struct passwd * pw = s->pw; | - |
866 | pid_t pid = getpid(); | - |
867 | | - |
868 | | - |
869 | | - |
870 | | - |
871 | | - |
872 | memset(&from, 0, sizeof(from)); | - |
873 | fromlen = sizeof(from); | - |
874 | if (ssh_packet_connection_is_on_socket(active_state)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
875 | if (getpeername(ssh_packet_get_connection_in(active_state),TRUE | never evaluated | FALSE | never evaluated |
| 0 |
876 | (struct sockaddr *)&from, &fromlen) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
877 | debug("getpeername: %.100s", strerror( | - |
878 | (*__errno_location ()) | - |
879 | )); | - |
880 | cleanup_exit(255); | - |
881 | } never executed: end of block | 0 |
882 | } never executed: end of block | 0 |
883 | | - |
884 | | - |
885 | if (!use_privsepTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
886 | record_login(pid, s->tty, pw->pw_name, pw->pw_uid, never executed: record_login(pid, s->tty, pw->pw_name, pw->pw_uid, session_get_remote_name_or_ip(ssh, utmp_len, options.use_dns), (struct sockaddr *)&from, fromlen); | 0 |
887 | session_get_remote_name_or_ip(ssh, utmp_len, never executed: record_login(pid, s->tty, pw->pw_name, pw->pw_uid, session_get_remote_name_or_ip(ssh, utmp_len, options.use_dns), (struct sockaddr *)&from, fromlen); | 0 |
888 | options.use_dns), never executed: record_login(pid, s->tty, pw->pw_name, pw->pw_uid, session_get_remote_name_or_ip(ssh, utmp_len, options.use_dns), (struct sockaddr *)&from, fromlen); | 0 |
889 | (struct sockaddr *)&from, fromlen); never executed: record_login(pid, s->tty, pw->pw_name, pw->pw_uid, session_get_remote_name_or_ip(ssh, utmp_len, options.use_dns), (struct sockaddr *)&from, fromlen); | 0 |
890 | if (check_quietlogin(s, command)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
891 | return; never executed: return; | 0 |
892 | | - |
893 | display_loginmsg(); | - |
894 | | - |
895 | do_motd(); | - |
896 | } never executed: end of block | 0 |
897 | | - |
898 | | - |
899 | | - |
900 | | - |
901 | void | - |
902 | do_motd(void) | - |
903 | { | - |
904 | FILE *f; | - |
905 | char buf[256]; | - |
906 | | - |
907 | if (options.print_motdTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
908 | | - |
909 | | - |
910 | | - |
911 | | - |
912 | f = fopen("/etc/motd", "r"); | - |
913 | | - |
914 | if (fTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
915 | while (fgets(buf, sizeof(buf), f)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
916 | fputs(buf, never executed: fputs(buf, stdout ); | 0 |
917 | stdout never executed: fputs(buf, stdout ); | 0 |
918 | ); never executed: fputs(buf, stdout ); | 0 |
919 | fclose(f); | - |
920 | } never executed: end of block | 0 |
921 | } never executed: end of block | 0 |
922 | } never executed: end of block | 0 |
923 | | - |
924 | | - |
925 | | - |
926 | | - |
927 | | - |
928 | int | - |
929 | check_quietlogin(Session *s, const char *command) | - |
930 | { | - |
931 | char buf[256]; | - |
932 | struct passwd *pw = s->pw; | - |
933 | struct stat st; | - |
934 | | - |
935 | | - |
936 | if (command != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
937 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
938 | ) | - |
939 | return never executed: return 1; 1;never executed: return 1; | 0 |
940 | snprintf(buf, sizeof(buf), "%.200s/.hushlogin", pw->pw_dir); | - |
941 | | - |
942 | | - |
943 | | - |
944 | | - |
945 | if (stat(buf, &st) >= 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
946 | return never executed: return 1; 1;never executed: return 1; | 0 |
947 | | - |
948 | return never executed: return 0; 0;never executed: return 0; | 0 |
949 | } | - |
950 | static void | - |
951 | read_environment_file(char ***env, u_int *envsize, | - |
952 | const char *filename, const char *whitelist) | - |
953 | { | - |
954 | FILE *f; | - |
955 | char *line = | - |
956 | ((void *)0) | - |
957 | , *cp, *value; | - |
958 | size_t linesize = 0; | - |
959 | u_int lineno = 0; | - |
960 | | - |
961 | f = fopen(filename, "r"); | - |
962 | if (!fTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
963 | return; never executed: return; | 0 |
964 | | - |
965 | while (getline(&line, &linesize, f) != -1TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
966 | if (++TRUE | never evaluated | FALSE | never evaluated |
lineno > 1000TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
967 | fatal("Too many lines in environment file %s", filename); never executed: fatal("Too many lines in environment file %s", filename); | 0 |
968 | for (cp = line; *TRUE | never evaluated | FALSE | never evaluated |
cp == ' 'TRUE | never evaluated | FALSE | never evaluated |
|| *TRUE | never evaluated | FALSE | never evaluated |
cp == '\t'TRUE | never evaluated | FALSE | never evaluated |
; cp++) | 0 |
969 | ; never executed: ; | 0 |
970 | if (!*cpTRUE | never evaluated | FALSE | never evaluated |
|| *TRUE | never evaluated | FALSE | never evaluated |
cp == '#'TRUE | never evaluated | FALSE | never evaluated |
|| *TRUE | never evaluated | FALSE | never evaluated |
cp == '\n'TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
971 | continue; never executed: continue; | 0 |
972 | | - |
973 | cp[ | - |
974 | __builtin_strcspn ( | - |
975 | cp | - |
976 | , | - |
977 | "\n" | - |
978 | ) | - |
979 | ] = '\0'; | - |
980 | | - |
981 | value = | - |
982 | (__extension__ (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
983 | '='TRUE | never evaluated | FALSE | never evaluated |
| 0 |
984 | )TRUE | never evaluated | FALSE | never evaluated |
&& !__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
985 | cpTRUE | never evaluated | FALSE | never evaluated |
| 0 |
986 | )TRUE | never evaluated | FALSE | never evaluated |
&& (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
987 | '='TRUE | never evaluated | FALSE | never evaluated |
| 0 |
988 | ) == '\0'TRUE | never evaluated | FALSE | never evaluated |
? (char *) __rawmemchr ( | 0 |
989 | cp | - |
990 | , | - |
991 | '=' | - |
992 | ) : __builtin_strchr ( | - |
993 | cp | - |
994 | , | - |
995 | '=' | - |
996 | ))) | - |
997 | ; | - |
998 | if (value == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
999 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1000 | ) { | - |
1001 | fprintf( | - |
1002 | stderr | - |
1003 | , "Bad line %u in %.100s\n", lineno, | - |
1004 | filename); | - |
1005 | continue; never executed: continue; | 0 |
1006 | } | - |
1007 | | - |
1008 | | - |
1009 | | - |
1010 | | - |
1011 | *value = '\0'; | - |
1012 | value++; | - |
1013 | if (whitelist != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1014 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1015 | && | - |
1016 | match_pattern_list(cp, whitelist, 0) != 1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1017 | continue; never executed: continue; | 0 |
1018 | child_set_env(env, envsize, cp, value); | - |
1019 | } never executed: end of block | 0 |
1020 | free(line); | - |
1021 | fclose(f); | - |
1022 | } never executed: end of block | 0 |
1023 | static void | - |
1024 | copy_environment_blacklist(char **source, char ***env, u_int *envsize, | - |
1025 | const char *blacklist) | - |
1026 | { | - |
1027 | char *var_name, *var_val; | - |
1028 | int i; | - |
1029 | | - |
1030 | if (source == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1031 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1032 | ) | - |
1033 | return; never executed: return; | 0 |
1034 | | - |
1035 | for(i = 0; source[i] != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1036 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1037 | ; i++) { | - |
1038 | var_name = xstrdup(source[i]); | - |
1039 | if ((TRUE | never evaluated | FALSE | never evaluated |
var_val = strstr(var_name, "=")) == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1040 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1041 | ) { | - |
1042 | free(var_name); | - |
1043 | continue; never executed: continue; | 0 |
1044 | } | - |
1045 | *var_val++ = '\0'; | - |
1046 | | - |
1047 | if (blacklist == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1048 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1049 | || | - |
1050 | match_pattern_list(var_name, blacklist, 0) != 1TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1051 | debug3("Copy environment: %s=%s", var_name, var_val); | - |
1052 | child_set_env(env, envsize, var_name, var_val); | - |
1053 | } never executed: end of block | 0 |
1054 | | - |
1055 | free(var_name); | - |
1056 | } never executed: end of block | 0 |
1057 | } never executed: end of block | 0 |
1058 | | - |
1059 | void | - |
1060 | copy_environment(char **source, char ***env, u_int *envsize) | - |
1061 | { | - |
1062 | copy_environment_blacklist(source, env, envsize, | - |
1063 | ((void *)0) | - |
1064 | ); | - |
1065 | } never executed: end of block | 0 |
1066 | | - |
1067 | static char ** | - |
1068 | do_setup_env(struct ssh *ssh, Session *s, const char *shell) | - |
1069 | { | - |
1070 | char buf[256]; | - |
1071 | size_t n; | - |
1072 | u_int i, envsize; | - |
1073 | char *ocp, *cp, *value, **env, *laddr; | - |
1074 | struct passwd *pw = s->pw; | - |
1075 | | - |
1076 | char *path = | - |
1077 | ((void *)0) | - |
1078 | ; | - |
1079 | | - |
1080 | | - |
1081 | | - |
1082 | envsize = 100; | - |
1083 | env = xcalloc(envsize, sizeof(char *)); | - |
1084 | env[0] = | - |
1085 | ((void *)0) | - |
1086 | ; | - |
1087 | for (i = 0; i < s->num_envTRUE | never evaluated | FALSE | never evaluated |
; i++) | 0 |
1088 | child_set_env(&env, &envsize, s->env[i].name, s->env[i].val); never executed: child_set_env(&env, &envsize, s->env[i].name, s->env[i].val); | 0 |
1089 | | - |
1090 | child_set_env(&env, &envsize, "USER", pw->pw_name); | - |
1091 | child_set_env(&env, &envsize, "LOGNAME", pw->pw_name); | - |
1092 | | - |
1093 | | - |
1094 | | - |
1095 | child_set_env(&env, &envsize, "HOME", pw->pw_dir); | - |
1096 | if (path == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1097 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1098 | || *TRUE | never evaluated | FALSE | never evaluated |
path == '\0'TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1099 | child_set_env(&env, &envsize, "PATH", | - |
1100 | s->pw->pw_uid == 0 ? "/usr/bin:/bin:/usr/sbin:/sbin:/var/tmp/openssh-test/bin" : "/usr/bin:/bin:/usr/sbin:/sbin:/var/tmp/openssh-test/bin"); | - |
1101 | } never executed: end of block | 0 |
1102 | | - |
1103 | | - |
1104 | | - |
1105 | snprintf(buf, sizeof buf, "%.200s/%.50s", | - |
1106 | "/var/mail" | - |
1107 | , pw->pw_name); | - |
1108 | child_set_env(&env, &envsize, "MAIL", buf); | - |
1109 | | - |
1110 | | - |
1111 | child_set_env(&env, &envsize, "SHELL", shell); | - |
1112 | | - |
1113 | if (getenv("TZ")TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1114 | child_set_env(&env, &envsize, "TZ", getenv("TZ")); never executed: child_set_env(&env, &envsize, "TZ", getenv("TZ")); | 0 |
1115 | if (s->termTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1116 | child_set_env(&env, &envsize, "TERM", s->term); never executed: child_set_env(&env, &envsize, "TERM", s->term); | 0 |
1117 | if (s->displayTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1118 | child_set_env(&env, &envsize, "DISPLAY", s->display); never executed: child_set_env(&env, &envsize, "DISPLAY", s->display); | 0 |
1119 | | - |
1120 | | - |
1121 | | - |
1122 | | - |
1123 | | - |
1124 | | - |
1125 | { | - |
1126 | char *cp; | - |
1127 | | - |
1128 | if ((TRUE | never evaluated | FALSE | never evaluated |
cp = getenv("KRB5CCNAME")) != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1129 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1130 | ) | - |
1131 | child_set_env(&env, &envsize, "KRB5CCNAME", cp); never executed: child_set_env(&env, &envsize, "KRB5CCNAME", cp); | 0 |
1132 | } | - |
1133 | if (auth_sock_name != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1134 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1135 | ) | - |
1136 | child_set_env(&env, &envsize, "SSH_AUTH_SOCK", never executed: child_set_env(&env, &envsize, "SSH_AUTH_SOCK", auth_sock_name); | 0 |
1137 | auth_sock_name); never executed: child_set_env(&env, &envsize, "SSH_AUTH_SOCK", auth_sock_name); | 0 |
1138 | | - |
1139 | | - |
1140 | | - |
1141 | if (options.permit_user_envTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1142 | for (n = 0 ; n < auth_opts->nenvTRUE | never evaluated | FALSE | never evaluated |
; n++) { | 0 |
1143 | ocp = xstrdup(auth_opts->env[n]); | - |
1144 | cp = | - |
1145 | (__extension__ (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1146 | '='TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1147 | )TRUE | never evaluated | FALSE | never evaluated |
&& !__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1148 | ocpTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1149 | )TRUE | never evaluated | FALSE | never evaluated |
&& (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1150 | '='TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1151 | ) == '\0'TRUE | never evaluated | FALSE | never evaluated |
? (char *) __rawmemchr ( | 0 |
1152 | ocp | - |
1153 | , | - |
1154 | '=' | - |
1155 | ) : __builtin_strchr ( | - |
1156 | ocp | - |
1157 | , | - |
1158 | '=' | - |
1159 | ))) | - |
1160 | ; | - |
1161 | if (*TRUE | never evaluated | FALSE | never evaluated |
cp == '='TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1162 | *cp = '\0'; | - |
1163 | | - |
1164 | if (options.permit_user_env_whitelist == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1165 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1166 | || | - |
1167 | match_pattern_list(ocp,TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1168 | options.permit_user_env_whitelist, 0) == 1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1169 | child_set_env(&env, &envsize, never executed: child_set_env(&env, &envsize, ocp, cp + 1); | 0 |
1170 | ocp, cp + 1); never executed: child_set_env(&env, &envsize, ocp, cp + 1); | 0 |
1171 | } never executed: end of block | 0 |
1172 | free(ocp); | - |
1173 | } never executed: end of block | 0 |
1174 | } never executed: end of block | 0 |
1175 | | - |
1176 | | - |
1177 | if (options.permit_user_envTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1178 | snprintf(buf, sizeof buf, "%.200s/.ssh/environment", | - |
1179 | pw->pw_dir); | - |
1180 | read_environment_file(&env, &envsize, buf, | - |
1181 | options.permit_user_env_whitelist); | - |
1182 | } never executed: end of block | 0 |
1183 | for (i = 0; i < options.num_setenvTRUE | never evaluated | FALSE | never evaluated |
; i++) { | 0 |
1184 | cp = xstrdup(options.setenv[i]); | - |
1185 | if ((TRUE | never evaluated | FALSE | never evaluated |
value = TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1186 | (__extension__ (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1187 | '='TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1188 | )TRUE | never evaluated | FALSE | never evaluated |
&& !__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1189 | cpTRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1190 | )TRUE | never evaluated | FALSE | never evaluated |
&& (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1191 | '='TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1192 | ) == '\0'TRUE | never evaluated | FALSE | never evaluated |
? (char *) __rawmemchr (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1193 | cpTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1194 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1195 | '='TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1196 | ) : __builtin_strchr (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1197 | cpTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1198 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1199 | '='TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1200 | )))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1201 | ) == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1202 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1203 | ) { | - |
1204 | | - |
1205 | fatal("Invalid config SetEnv: %s", options.setenv[i]); | - |
1206 | } never executed: end of block | 0 |
1207 | *value++ = '\0'; | - |
1208 | child_set_env(&env, &envsize, cp, value); | - |
1209 | } never executed: end of block | 0 |
1210 | | - |
1211 | | - |
1212 | snprintf(buf, sizeof buf, "%.50s %d %d", | - |
1213 | ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), | - |
1214 | ssh_local_port(ssh)); | - |
1215 | child_set_env(&env, &envsize, "SSH_CLIENT", buf); | - |
1216 | | - |
1217 | laddr = get_local_ipaddr(ssh_packet_get_connection_in(active_state)); | - |
1218 | snprintf(buf, sizeof buf, "%.50s %d %.50s %d", | - |
1219 | ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), | - |
1220 | laddr, ssh_local_port(ssh)); | - |
1221 | free(laddr); | - |
1222 | child_set_env(&env, &envsize, "SSH_CONNECTION", buf); | - |
1223 | | - |
1224 | if (tun_fwd_ifnames != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1225 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1226 | ) | - |
1227 | child_set_env(&env, &envsize, "SSH_TUNNEL", tun_fwd_ifnames); never executed: child_set_env(&env, &envsize, "SSH_TUNNEL", tun_fwd_ifnames); | 0 |
1228 | if (auth_info_file != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1229 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1230 | ) | - |
1231 | child_set_env(&env, &envsize, "SSH_USER_AUTH", auth_info_file); never executed: child_set_env(&env, &envsize, "SSH_USER_AUTH", auth_info_file); | 0 |
1232 | if (s->ttyfd != -1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1233 | child_set_env(&env, &envsize, "SSH_TTY", s->tty); never executed: child_set_env(&env, &envsize, "SSH_TTY", s->tty); | 0 |
1234 | if (original_commandTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1235 | child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND", never executed: child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND", original_command); | 0 |
1236 | original_command); never executed: child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND", original_command); | 0 |
1237 | | - |
1238 | if (debug_flagTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1239 | | - |
1240 | fprintf( | - |
1241 | stderr | - |
1242 | , "Environment:\n"); | - |
1243 | for (i = 0; env[i]TRUE | never evaluated | FALSE | never evaluated |
; i++) | 0 |
1244 | fprintf( never executed: fprintf( stderr , " %.200s\n", env[i]); | 0 |
1245 | stderr never executed: fprintf( stderr , " %.200s\n", env[i]); | 0 |
1246 | , " %.200s\n", env[i]); never executed: fprintf( stderr , " %.200s\n", env[i]); | 0 |
1247 | } never executed: end of block | 0 |
1248 | return never executed: return env; env;never executed: return env; | 0 |
1249 | } | - |
1250 | | - |
1251 | | - |
1252 | | - |
1253 | | - |
1254 | | - |
1255 | static void | - |
1256 | do_rc_files(struct ssh *ssh, Session *s, const char *shell) | - |
1257 | { | - |
1258 | FILE *f = | - |
1259 | ((void *)0) | - |
1260 | ; | - |
1261 | char cmd[1024]; | - |
1262 | int do_xauth; | - |
1263 | struct stat st; | - |
1264 | | - |
1265 | do_xauth = | - |
1266 | s->display != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1267 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1268 | && s->auth_proto != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1269 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1270 | && s->auth_data != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1271 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1272 | ; | - |
1273 | | - |
1274 | | - |
1275 | if (!s->is_subsystemTRUE | never evaluated | FALSE | never evaluated |
&& options.adm_forced_command == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1276 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1277 | && | - |
1278 | auth_opts->permit_user_rcTRUE | never evaluated | FALSE | never evaluated |
&& options.permit_user_rcTRUE | never evaluated | FALSE | never evaluated |
&& | 0 |
1279 | stat(".ssh" "/rc", &st) >= 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1280 | snprintf(cmd, sizeof cmd, "%s -c '%s %s'", | - |
1281 | shell, | - |
1282 | "/bin/sh" | - |
1283 | , ".ssh" "/rc"); | - |
1284 | if (debug_flagTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1285 | fprintf( never executed: fprintf( stderr , "Running %s\n", cmd); | 0 |
1286 | stderr never executed: fprintf( stderr , "Running %s\n", cmd); | 0 |
1287 | , "Running %s\n", cmd); never executed: fprintf( stderr , "Running %s\n", cmd); | 0 |
1288 | f = popen(cmd, "w"); | - |
1289 | if (fTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1290 | if (do_xauthTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1291 | fprintf(f, "%s %s\n", s->auth_proto, never executed: fprintf(f, "%s %s\n", s->auth_proto, s->auth_data); | 0 |
1292 | s->auth_data); never executed: fprintf(f, "%s %s\n", s->auth_proto, s->auth_data); | 0 |
1293 | pclose(f); | - |
1294 | } never executed: end of block else | 0 |
1295 | fprintf( never executed: fprintf( stderr , "Could not run %s\n", ".ssh" "/rc"); | 0 |
1296 | stderr never executed: fprintf( stderr , "Could not run %s\n", ".ssh" "/rc"); | 0 |
1297 | , "Could not run %s\n", never executed: fprintf( stderr , "Could not run %s\n", ".ssh" "/rc"); | 0 |
1298 | ".ssh" "/rc"); never executed: fprintf( stderr , "Could not run %s\n", ".ssh" "/rc"); | 0 |
1299 | } else if (stat("/var/tmp/openssh-test/etc" "/sshrc", &st) >= 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1300 | if (debug_flagTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1301 | fprintf( never executed: fprintf( stderr , "Running %s %s\n", "/bin/sh" , "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1302 | stderr never executed: fprintf( stderr , "Running %s %s\n", "/bin/sh" , "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1303 | , "Running %s %s\n", never executed: fprintf( stderr , "Running %s %s\n", "/bin/sh" , "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1304 | "/bin/sh" never executed: fprintf( stderr , "Running %s %s\n", "/bin/sh" , "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1305 | , never executed: fprintf( stderr , "Running %s %s\n", "/bin/sh" , "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1306 | "/var/tmp/openssh-test/etc" "/sshrc"); never executed: fprintf( stderr , "Running %s %s\n", "/bin/sh" , "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1307 | f = popen( | - |
1308 | "/bin/sh" | - |
1309 | " " "/var/tmp/openssh-test/etc" "/sshrc", "w"); | - |
1310 | if (fTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1311 | if (do_xauthTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1312 | fprintf(f, "%s %s\n", s->auth_proto, never executed: fprintf(f, "%s %s\n", s->auth_proto, s->auth_data); | 0 |
1313 | s->auth_data); never executed: fprintf(f, "%s %s\n", s->auth_proto, s->auth_data); | 0 |
1314 | pclose(f); | - |
1315 | } never executed: end of block else | 0 |
1316 | fprintf( never executed: fprintf( stderr , "Could not run %s\n", "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1317 | stderr never executed: fprintf( stderr , "Could not run %s\n", "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1318 | , "Could not run %s\n", never executed: fprintf( stderr , "Could not run %s\n", "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1319 | "/var/tmp/openssh-test/etc" "/sshrc"); never executed: fprintf( stderr , "Could not run %s\n", "/var/tmp/openssh-test/etc" "/sshrc"); | 0 |
1320 | } else if (do_xauthTRUE | never evaluated | FALSE | never evaluated |
&& options.xauth_location != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1321 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1322 | ) { | - |
1323 | | - |
1324 | if (debug_flagTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1325 | fprintf( | - |
1326 | stderr | - |
1327 | , | - |
1328 | "Running %.500s remove %.100s\n", | - |
1329 | options.xauth_location, s->auth_display); | - |
1330 | fprintf( | - |
1331 | stderr | - |
1332 | , | - |
1333 | "%.500s add %.100s %.100s %.100s\n", | - |
1334 | options.xauth_location, s->auth_display, | - |
1335 | s->auth_proto, s->auth_data); | - |
1336 | } never executed: end of block | 0 |
1337 | snprintf(cmd, sizeof cmd, "%s -q -", | - |
1338 | options.xauth_location); | - |
1339 | f = popen(cmd, "w"); | - |
1340 | if (fTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1341 | fprintf(f, "remove %s\n", | - |
1342 | s->auth_display); | - |
1343 | fprintf(f, "add %s %s %s\n", | - |
1344 | s->auth_display, s->auth_proto, | - |
1345 | s->auth_data); | - |
1346 | pclose(f); | - |
1347 | } never executed: end of block else { | 0 |
1348 | fprintf( | - |
1349 | stderr | - |
1350 | , "Could not run %s\n", | - |
1351 | cmd); | - |
1352 | } never executed: end of block | 0 |
1353 | } | - |
1354 | } never executed: end of block | 0 |
1355 | | - |
1356 | static void | - |
1357 | do_nologin(struct passwd *pw) | - |
1358 | { | - |
1359 | FILE *f = | - |
1360 | ((void *)0) | - |
1361 | ; | - |
1362 | char buf[1024], *nl, *def_nl = | - |
1363 | "/etc/nologin" | - |
1364 | ; | - |
1365 | struct stat sb; | - |
1366 | | - |
1367 | | - |
1368 | | - |
1369 | | - |
1370 | | - |
1371 | | - |
1372 | if (pw->pw_uid == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1373 | return; never executed: return; | 0 |
1374 | nl = def_nl; | - |
1375 | | - |
1376 | if (stat(nl, &sb) == -1TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1377 | if (nl != def_nlTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1378 | free(nl); never executed: free(nl); | 0 |
1379 | return; never executed: return; | 0 |
1380 | } | - |
1381 | | - |
1382 | | - |
1383 | logit("User %.100s not allowed because %s exists", pw->pw_name, nl); | - |
1384 | if ((TRUE | never evaluated | FALSE | never evaluated |
f = fopen(nl, "r")) != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1385 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1386 | ) { | - |
1387 | while (fgets(buf, sizeof(buf), f)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1388 | fputs(buf, never executed: fputs(buf, stderr ); | 0 |
1389 | stderr never executed: fputs(buf, stderr ); | 0 |
1390 | ); never executed: fputs(buf, stderr ); | 0 |
1391 | fclose(f); | - |
1392 | } never executed: end of block | 0 |
1393 | exit(254); never executed: exit(254); | 0 |
1394 | } | - |
1395 | | - |
1396 | | - |
1397 | | - |
1398 | | - |
1399 | | - |
1400 | static void | - |
1401 | safely_chroot(const char *path, uid_t uid) | - |
1402 | { | - |
1403 | const char *cp; | - |
1404 | char component[ | - |
1405 | 4096 | - |
1406 | ]; | - |
1407 | struct stat st; | - |
1408 | | - |
1409 | if (*TRUE | never evaluated | FALSE | never evaluated |
path != '/'TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1410 | fatal("chroot path does not begin at root"); never executed: fatal("chroot path does not begin at root"); | 0 |
1411 | if (strlen(path) >= sizeof(component)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1412 | fatal("chroot path too long"); never executed: fatal("chroot path too long"); | 0 |
1413 | | - |
1414 | | - |
1415 | | - |
1416 | | - |
1417 | | - |
1418 | for (cp = path; cp != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1419 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1420 | ;) { | - |
1421 | if ((TRUE | never evaluated | FALSE | never evaluated |
cp = TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1422 | (__extension__ (__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1423 | '/'TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1424 | )TRUE | never evaluated | FALSE | never evaluated |
&& !__builtin_constant_p (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1425 | cpTRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1426 | )TRUE | never evaluated | FALSE | never evaluated |
&& (TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1427 | '/'TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1428 | ) == '\0'TRUE | never evaluated | FALSE | never evaluated |
? (char *) __rawmemchr (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1429 | cpTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1430 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1431 | '/'TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1432 | ) : __builtin_strchr (TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1433 | cpTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1434 | , TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1435 | '/'TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1436 | )))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1437 | ) == TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1438 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1439 | ) | - |
1440 | strlcpy(component, path, sizeof(component)); never executed: strlcpy(component, path, sizeof(component)); | 0 |
1441 | else { | - |
1442 | cp++; | - |
1443 | memcpy(component, path, cp - path); | - |
1444 | component[cp - path] = '\0'; | - |
1445 | } never executed: end of block | 0 |
1446 | | - |
1447 | debug3("%s: checking '%s'", __func__, component); | - |
1448 | | - |
1449 | if (stat(component, &st) != 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1450 | fatal("%s: stat(\"%s\"): %s", __func__, never executed: fatal("%s: stat(\"%s\"): %s", __func__, component, strerror( (*__errno_location ()) )); | 0 |
1451 | component, strerror( never executed: fatal("%s: stat(\"%s\"): %s", __func__, component, strerror( (*__errno_location ()) )); | 0 |
1452 | (*__errno_location ()) never executed: fatal("%s: stat(\"%s\"): %s", __func__, component, strerror( (*__errno_location ()) )); | 0 |
1453 | )); never executed: fatal("%s: stat(\"%s\"): %s", __func__, component, strerror( (*__errno_location ()) )); | 0 |
1454 | if (st.st_uid != 0TRUE | never evaluated | FALSE | never evaluated |
|| (TRUE | never evaluated | FALSE | never evaluated |
st.st_mode & 022) != 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1455 | fatal("bad ownership or modes for chroot " never executed: fatal("bad ownership or modes for chroot " "directory %s\"%s\"", cp == ((void *)0) ? "" : "component ", component); | 0 |
1456 | "directory %s\"%s\"", never executed: fatal("bad ownership or modes for chroot " "directory %s\"%s\"", cp == ((void *)0) ? "" : "component ", component); | 0 |
1457 | cp == never executed: fatal("bad ownership or modes for chroot " "directory %s\"%s\"", cp == ((void *)0) ? "" : "component ", component); | 0 |
1458 | ((void *)0) never executed: fatal("bad ownership or modes for chroot " "directory %s\"%s\"", cp == ((void *)0) ? "" : "component ", component); | 0 |
1459 | ? "" : "component ", component); never executed: fatal("bad ownership or modes for chroot " "directory %s\"%s\"", cp == ((void *)0) ? "" : "component ", component); | 0 |
1460 | if (!TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1461 | ((((TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1462 | st.st_modeTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1463 | )) & 0170000) == (0040000))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1464 | ) | - |
1465 | fatal("chroot path %s\"%s\" is not a directory", never executed: fatal("chroot path %s\"%s\" is not a directory", cp == ((void *)0) ? "" : "component ", component); | 0 |
1466 | cp == never executed: fatal("chroot path %s\"%s\" is not a directory", cp == ((void *)0) ? "" : "component ", component); | 0 |
1467 | ((void *)0) never executed: fatal("chroot path %s\"%s\" is not a directory", cp == ((void *)0) ? "" : "component ", component); | 0 |
1468 | ? "" : "component ", component); never executed: fatal("chroot path %s\"%s\" is not a directory", cp == ((void *)0) ? "" : "component ", component); | 0 |
1469 | | - |
1470 | } never executed: end of block | 0 |
1471 | | - |
1472 | if (chdir(path) == -1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1473 | fatal("Unable to chdir to chroot path \"%s\": " never executed: fatal("Unable to chdir to chroot path \"%s\": " "%s", path, strerror( (*__errno_location ()) )); | 0 |
1474 | "%s", path, strerror( never executed: fatal("Unable to chdir to chroot path \"%s\": " "%s", path, strerror( (*__errno_location ()) )); | 0 |
1475 | (*__errno_location ()) never executed: fatal("Unable to chdir to chroot path \"%s\": " "%s", path, strerror( (*__errno_location ()) )); | 0 |
1476 | )); never executed: fatal("Unable to chdir to chroot path \"%s\": " "%s", path, strerror( (*__errno_location ()) )); | 0 |
1477 | if (chroot(path) == -1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1478 | fatal("chroot(\"%s\"): %s", path, strerror( never executed: fatal("chroot(\"%s\"): %s", path, strerror( (*__errno_location ()) )); | 0 |
1479 | (*__errno_location ()) never executed: fatal("chroot(\"%s\"): %s", path, strerror( (*__errno_location ()) )); | 0 |
1480 | )); never executed: fatal("chroot(\"%s\"): %s", path, strerror( (*__errno_location ()) )); | 0 |
1481 | if (chdir("/") == -1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1482 | fatal("%s: chdir(/) after chroot: %s", never executed: fatal("%s: chdir(/) after chroot: %s", __func__, strerror( (*__errno_location ()) )); | 0 |
1483 | __func__, strerror( never executed: fatal("%s: chdir(/) after chroot: %s", __func__, strerror( (*__errno_location ()) )); | 0 |
1484 | (*__errno_location ()) never executed: fatal("%s: chdir(/) after chroot: %s", __func__, strerror( (*__errno_location ()) )); | 0 |
1485 | )); never executed: fatal("%s: chdir(/) after chroot: %s", __func__, strerror( (*__errno_location ()) )); | 0 |
1486 | verbose("Changed root directory to \"%s\"", path); | - |
1487 | } never executed: end of block | 0 |
1488 | | - |
1489 | | - |
1490 | void | - |
1491 | do_setusercontext(struct passwd *pw) | - |
1492 | { | - |
1493 | char uidstr[32], *chroot_path, *tmp; | - |
1494 | | - |
1495 | platform_setusercontext(pw); | - |
1496 | | - |
1497 | if (platform_privileged_uidswap()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1498 | | - |
1499 | | - |
1500 | | - |
1501 | | - |
1502 | | - |
1503 | | - |
1504 | | - |
1505 | if (setlogin(pw->pw_name) < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1506 | error("setlogin failed: %s", strerror( never executed: error("setlogin failed: %s", strerror( (*__errno_location ()) )); | 0 |
1507 | (*__errno_location ()) never executed: error("setlogin failed: %s", strerror( (*__errno_location ()) )); | 0 |
1508 | )); never executed: error("setlogin failed: %s", strerror( (*__errno_location ()) )); | 0 |
1509 | if (setgid(pw->pw_gid) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1510 | perror("setgid"); | - |
1511 | exit(1); never executed: exit(1); | 0 |
1512 | } | - |
1513 | | - |
1514 | if (initgroups(pw->pw_name, pw->pw_gid) < 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1515 | perror("initgroups"); | - |
1516 | exit(1); never executed: exit(1); | 0 |
1517 | } | - |
1518 | endgrent(); | - |
1519 | | - |
1520 | | - |
1521 | platform_setusercontext_post_groups(pw); | - |
1522 | | - |
1523 | if (!in_chrootTRUE | never evaluated | FALSE | never evaluated |
&& options.chroot_directory != TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1524 | ((void *)0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1525 | && | - |
1526 | strcasecmp(options.chroot_directory, "none") != 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1527 | tmp = tilde_expand_filename(options.chroot_directory, | - |
1528 | pw->pw_uid); | - |
1529 | snprintf(uidstr, sizeof(uidstr), "%llu", | - |
1530 | (unsigned long long)pw->pw_uid); | - |
1531 | chroot_path = percent_expand(tmp, "h", pw->pw_dir, | - |
1532 | "u", pw->pw_name, "U", uidstr, (char *) | - |
1533 | ((void *)0) | - |
1534 | ); | - |
1535 | safely_chroot(chroot_path, pw->pw_uid); | - |
1536 | free(tmp); | - |
1537 | free(chroot_path); | - |
1538 | | - |
1539 | free(options.chroot_directory); | - |
1540 | options.chroot_directory = | - |
1541 | ((void *)0) | - |
1542 | ; | - |
1543 | in_chroot = 1; | - |
1544 | } never executed: end of block | 0 |
1545 | permanently_set_uid(pw); | - |
1546 | | - |
1547 | } never executed: end of block else if ( |