… | |
… | |
209 | void rxvt_term::emergency_cleanup () |
209 | void rxvt_term::emergency_cleanup () |
210 | { |
210 | { |
211 | if (cmd_pid) |
211 | if (cmd_pid) |
212 | kill (-cmd_pid, SIGHUP); |
212 | kill (-cmd_pid, SIGHUP); |
213 | |
213 | |
214 | #ifdef UTMP_SUPPORT |
214 | delete pty; pty = 0; |
215 | privileged_utmp (RESTORE); |
|
|
216 | #endif |
|
|
217 | |
|
|
218 | pty.put (); |
|
|
219 | } |
215 | } |
220 | |
216 | |
221 | rxvt_term::~rxvt_term () |
217 | rxvt_term::~rxvt_term () |
222 | { |
218 | { |
223 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
219 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
… | |
… | |
509 | rxvt_perl.init (this); |
505 | rxvt_perl.init (this); |
510 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
506 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
511 | } |
507 | } |
512 | #endif |
508 | #endif |
513 | |
509 | |
|
|
510 | pty = rxvt_new_ptytty (); |
|
|
511 | |
514 | create_windows (argc, argv); |
512 | create_windows (argc, argv); |
515 | |
513 | |
516 | dDisp; |
514 | dDisp; |
517 | |
515 | |
518 | init_xlocale (); |
516 | init_xlocale (); |
… | |
… | |
543 | |
541 | |
544 | init_command (cmd_argv); |
542 | init_command (cmd_argv); |
545 | |
543 | |
546 | free (cmd_argv); |
544 | free (cmd_argv); |
547 | |
545 | |
548 | if (pty.pty >= 0) |
546 | if (pty->pty >= 0) |
549 | pty_ev.start (pty.pty, EVENT_READ); |
547 | pty_ev.start (pty->pty, EVENT_READ); |
550 | |
548 | |
551 | check_ev.start (); |
549 | check_ev.start (); |
552 | |
550 | |
553 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
551 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
554 | |
552 | |
… | |
… | |
598 | char **rxvt_environ; // startup environment |
596 | char **rxvt_environ; // startup environment |
599 | |
597 | |
600 | void |
598 | void |
601 | rxvt_init () |
599 | rxvt_init () |
602 | { |
600 | { |
|
|
601 | uid_t uid = getuid (); |
|
|
602 | gid_t gid = getgid (); |
|
|
603 | |
|
|
604 | // before doing anything else, check for setuid/setgid operation, |
|
|
605 | // start the helper process and drop privileges |
|
|
606 | if (uid != geteuid () |
|
|
607 | || 1 //D |
|
|
608 | || gid != getegid ()) |
|
|
609 | { |
|
|
610 | #if PTYTTY_HELPER |
|
|
611 | rxvt_ptytty_server (); |
|
|
612 | #else |
|
|
613 | rxvt_warn ("running setuid/setgid without pty helper compiled in, continuing unprivileged.\n"); |
|
|
614 | #endif |
|
|
615 | |
|
|
616 | // drop privileges |
|
|
617 | #if HAVE_SETRESUID |
|
|
618 | setresgid (gid, gid, gid); |
|
|
619 | setresuid (uid, uid, uid); |
|
|
620 | #elif HAVE_SETREUID |
|
|
621 | setregid (gid, gid); |
|
|
622 | setreuid (uid, uid); |
|
|
623 | #elif HAVE_SETUID |
|
|
624 | setgid (gid); |
|
|
625 | setuid (uid); |
|
|
626 | #endif |
|
|
627 | |
|
|
628 | if (uid != geteuid () |
|
|
629 | || gid != getegid ()) |
|
|
630 | rxvt_fatal ("unable to drop privileges, aborting.\n"); |
|
|
631 | } |
|
|
632 | |
603 | rxvt_environ = environ; |
633 | rxvt_environ = environ; |
604 | |
634 | |
605 | /* |
635 | /* |
606 | * Save and then give up any super-user privileges |
636 | * Save and then give up any super-user privileges |
607 | * If we need privileges in any area then we must specifically request it. |
637 | * If we need privileges in any area then we must specifically request it. |
… | |
… | |
713 | } |
743 | } |
714 | # endif |
744 | # endif |
715 | #endif |
745 | #endif |
716 | } |
746 | } |
717 | |
747 | |
718 | #ifdef UTMP_SUPPORT |
|
|
719 | void |
|
|
720 | rxvt_term::privileged_utmp (rxvt_privaction action) |
|
|
721 | { |
|
|
722 | if (OPTION (Opt_utmpInhibit)) |
|
|
723 | return; |
|
|
724 | |
|
|
725 | rxvt_privileges (RESTORE); |
|
|
726 | |
|
|
727 | if (action == SAVE) |
|
|
728 | pty.login (cmd_pid, OPTION (Opt_loginShell), rs[Rs_display_name]); |
|
|
729 | else |
|
|
730 | pty.logout (); |
|
|
731 | |
|
|
732 | rxvt_privileges (IGNORE); |
|
|
733 | } |
|
|
734 | #endif |
|
|
735 | |
|
|
736 | /*----------------------------------------------------------------------*/ |
748 | /*----------------------------------------------------------------------*/ |
737 | /* |
749 | /* |
738 | * window size/position calculcations for XSizeHint and other storage. |
750 | * window size/position calculcations for XSizeHint and other storage. |
739 | * if width/height are non-zero then override calculated width/height |
751 | * if width/height are non-zero then override calculated width/height |
740 | */ |
752 | */ |
… | |
… | |
873 | * Called after a window size change. |
885 | * Called after a window size change. |
874 | */ |
886 | */ |
875 | void |
887 | void |
876 | rxvt_term::tt_winch () |
888 | rxvt_term::tt_winch () |
877 | { |
889 | { |
878 | if (pty.pty < 0) |
890 | if (pty->pty < 0) |
879 | return; |
891 | return; |
880 | |
892 | |
881 | struct winsize ws; |
893 | struct winsize ws; |
882 | |
894 | |
883 | ws.ws_col = ncol; |
895 | ws.ws_col = ncol; |
884 | ws.ws_row = nrow; |
896 | ws.ws_row = nrow; |
885 | ws.ws_xpixel = width; |
897 | ws.ws_xpixel = width; |
886 | ws.ws_ypixel = height; |
898 | ws.ws_ypixel = height; |
887 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
899 | (void)ioctl (pty->pty, TIOCSWINSZ, &ws); |
888 | |
900 | |
889 | #if 0 |
901 | #if 0 |
890 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
902 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
891 | if (cmd_pid) /* force through to the command */ |
903 | if (cmd_pid) /* force through to the command */ |
892 | kill (-cmd_pid, SIGWINCH); |
904 | kill (-cmd_pid, SIGWINCH); |