… | |
… | |
72 | int pfd; |
72 | int pfd; |
73 | |
73 | |
74 | #ifdef PTYS_ARE_OPENPTY |
74 | #ifdef PTYS_ARE_OPENPTY |
75 | char tty_name[sizeof "/dev/pts/????\0"]; |
75 | char tty_name[sizeof "/dev/pts/????\0"]; |
76 | |
76 | |
77 | rxvt_privileges(RESTORE); |
|
|
78 | int res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); |
77 | int res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); |
79 | rxvt_privileges(IGNORE); |
|
|
80 | |
78 | |
81 | if (res != -1) |
79 | if (res != -1) |
82 | { |
80 | { |
83 | *ttydev = strdup (tty_name); |
81 | *ttydev = strdup (tty_name); |
84 | return pfd; |
82 | return pfd; |
… | |
… | |
344 | rxvt_ptytty_unix::privileges (rxvt_privaction action) |
342 | rxvt_ptytty_unix::privileges (rxvt_privaction action) |
345 | { |
343 | { |
346 | if (!name || !*name) |
344 | if (!name || !*name) |
347 | return; |
345 | return; |
348 | |
346 | |
349 | rxvt_privileges (RESTORE); |
|
|
350 | |
|
|
351 | if (action == SAVE) |
347 | if (action == SAVE) |
352 | { |
348 | { |
353 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
349 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
354 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
350 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
355 | if (lstat (name, &savestat) < 0) /* you lose out */ |
351 | if (lstat (name, &savestat) < 0) /* you lose out */ |
… | |
… | |
377 | chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
373 | chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
378 | chown (name, 0, 0); |
374 | chown (name, 0, 0); |
379 | # endif |
375 | # endif |
380 | |
376 | |
381 | } |
377 | } |
382 | |
|
|
383 | rxvt_privileges (IGNORE); |
|
|
384 | } |
378 | } |
385 | #endif |
379 | #endif |
386 | |
380 | |
387 | rxvt_ptytty_unix::rxvt_ptytty_unix () |
381 | rxvt_ptytty_unix::rxvt_ptytty_unix () |
388 | { |
382 | { |
… | |
… | |
461 | |
455 | |
462 | struct rxvt_ptytty_proxy : zero_initialized, rxvt_ptytty |
456 | struct rxvt_ptytty_proxy : zero_initialized, rxvt_ptytty |
463 | { |
457 | { |
464 | rxvt_ptytty *id; |
458 | rxvt_ptytty *id; |
465 | |
459 | |
466 | rxvt_ptytty_proxy (); |
|
|
467 | ~rxvt_ptytty_proxy (); |
460 | ~rxvt_ptytty_proxy (); |
468 | |
461 | |
469 | bool get (); |
462 | bool get (); |
470 | void login (int cmd_pid, bool login_shell, const char *hostname); |
463 | void login (int cmd_pid, bool login_shell, const char *hostname); |
471 | }; |
464 | }; |
… | |
… | |
549 | if (find (ptys.begin (), ptys.end (), cmd.id)) |
542 | if (find (ptys.begin (), ptys.end (), cmd.id)) |
550 | { |
543 | { |
551 | cmd.hostname[sizeof (cmd.hostname) - 1] = 0; |
544 | cmd.hostname[sizeof (cmd.hostname) - 1] = 0; |
552 | cmd.id->login (cmd.cmd_pid, cmd.login_shell, cmd.hostname); |
545 | cmd.id->login (cmd.cmd_pid, cmd.login_shell, cmd.hostname); |
553 | } |
546 | } |
554 | else printf ("xxx hiya login no match %p\n", cmd.id); |
|
|
555 | } |
547 | } |
556 | else if (cmd.type == command::destroy) |
548 | else if (cmd.type == command::destroy) |
557 | { |
549 | { |
558 | rxvt_ptytty **pty = find (ptys.begin (), ptys.end (), cmd.id); |
550 | rxvt_ptytty **pty = find (ptys.begin (), ptys.end (), cmd.id); |
559 | |
551 | |
560 | if (*pty) |
552 | if (*pty) |
561 | { |
553 | { |
562 | ptys.erase (pty); |
554 | ptys.erase (pty); |
563 | delete *pty; |
555 | delete *pty; |
564 | } |
556 | } |
565 | else printf ("xxx hiya destroy no match %p\n", cmd.id); |
|
|
566 | } |
557 | } |
567 | else |
558 | else |
568 | break; |
559 | break; |
569 | } |
560 | } |
570 | |
561 | |
… | |
… | |
592 | close (sv[1]); |
583 | close (sv[1]); |
593 | fcntl (sock_fd, F_SETFD, FD_CLOEXEC); |
584 | fcntl (sock_fd, F_SETFD, FD_CLOEXEC); |
594 | } |
585 | } |
595 | else |
586 | else |
596 | { |
587 | { |
|
|
588 | setgid (getegid ()); |
|
|
589 | setuid (geteuid ()); |
|
|
590 | |
597 | // server, pty-helper |
591 | // server, pty-helper |
598 | sock_fd = sv[1]; |
592 | sock_fd = sv[1]; |
599 | |
593 | |
600 | close (sv[0]);//D |
|
|
601 | // for (int fd = 0; fd < 1023; fd++) |
594 | for (int fd = 0; fd < 1023; fd++) |
602 | // if (fd != sock_fd) |
595 | if (fd != sock_fd) |
603 | // close (fd); |
596 | close (fd); |
604 | |
597 | |
605 | serve (); |
598 | serve (); |
606 | _exit (EXIT_SUCCESS); |
599 | _exit (EXIT_SUCCESS); |
607 | } |
600 | } |
608 | } |
601 | } |
… | |
… | |
612 | rxvt_ptytty * |
605 | rxvt_ptytty * |
613 | rxvt_new_ptytty () |
606 | rxvt_new_ptytty () |
614 | { |
607 | { |
615 | #if PTYTTY_HELPER |
608 | #if PTYTTY_HELPER |
616 | if (pid > 0) |
609 | if (pid > 0) |
617 | { |
|
|
618 | // use helper process |
610 | // use helper process |
619 | return new rxvt_ptytty_proxy; |
611 | return new rxvt_ptytty_proxy; |
620 | } |
|
|
621 | else |
612 | else |
622 | #endif |
613 | #endif |
623 | return new rxvt_ptytty_unix; |
614 | return new rxvt_ptytty_unix; |
624 | } |
615 | } |
625 | |
616 | |