… | |
… | |
11 | * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> |
11 | * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> |
12 | * - extensive modifications |
12 | * - extensive modifications |
13 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
13 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
14 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
14 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
15 | * - extensive modifications |
15 | * - extensive modifications |
16 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
16 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
17 | * |
17 | * |
18 | * This program is free software; you can redistribute it and/or modify |
18 | * This program is free software; you can redistribute it and/or modify |
19 | * it under the terms of the GNU General Public License as published by |
19 | * it under the terms of the GNU General Public License as published by |
20 | * the Free Software Foundation; either version 2 of the License, or |
20 | * the Free Software Foundation; either version 2 of the License, or |
21 | * (at your option) any later version. |
21 | * (at your option) any later version. |
… | |
… | |
46 | |
46 | |
47 | #ifdef HAVE_TERMIOS_H |
47 | #ifdef HAVE_TERMIOS_H |
48 | # include <termios.h> |
48 | # include <termios.h> |
49 | #endif |
49 | #endif |
50 | |
50 | |
|
|
51 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
52 | static uid_t saved_euid; |
|
|
53 | static gid_t saved_egid; |
|
|
54 | #endif |
|
|
55 | |
|
|
56 | bool |
|
|
57 | rxvt_tainted () |
|
|
58 | { |
|
|
59 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
60 | return getuid () != saved_euid || getgid () != saved_egid; |
|
|
61 | #else |
|
|
62 | return false; |
|
|
63 | #endif |
|
|
64 | } |
|
|
65 | |
51 | vector<rxvt_term *> rxvt_term::termlist; |
66 | vector<rxvt_term *> rxvt_term::termlist; |
52 | |
67 | |
53 | static char curlocale[128], savelocale[128]; |
68 | static char curlocale[128], savelocale[128]; |
54 | |
69 | |
55 | bool |
70 | bool |
… | |
… | |
61 | strncpy (curlocale, locale, 128); |
76 | strncpy (curlocale, locale, 128); |
62 | setlocale (LC_CTYPE, curlocale); |
77 | setlocale (LC_CTYPE, curlocale); |
63 | return true; |
78 | return true; |
64 | } |
79 | } |
65 | |
80 | |
66 | bool |
81 | void |
67 | rxvt_push_locale (const char *locale) |
82 | rxvt_push_locale (const char *locale) |
68 | { |
83 | { |
69 | strcpy (savelocale, curlocale); |
84 | strcpy (savelocale, curlocale); |
70 | rxvt_set_locale (locale); |
85 | rxvt_set_locale (locale); |
71 | } |
86 | } |
… | |
… | |
206 | pty.put (); |
221 | pty.put (); |
207 | } |
222 | } |
208 | |
223 | |
209 | rxvt_term::~rxvt_term () |
224 | rxvt_term::~rxvt_term () |
210 | { |
225 | { |
211 | PERL_INVOKE ((this, HOOK_DESTROY, DT_END)); |
226 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
212 | |
227 | |
213 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
228 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
214 | |
229 | |
215 | emergency_cleanup (); |
230 | emergency_cleanup (); |
216 | |
231 | |
… | |
… | |
487 | if (OPTION (Opt_scrollBar)) |
502 | if (OPTION (Opt_scrollBar)) |
488 | scrollBar.setIdle (); /* set existence for size calculations */ |
503 | scrollBar.setIdle (); /* set existence for size calculations */ |
489 | #endif |
504 | #endif |
490 | |
505 | |
491 | #if ENABLE_PERL |
506 | #if ENABLE_PERL |
|
|
507 | if (!rs[Rs_perl_ext_1]) |
|
|
508 | rs[Rs_perl_ext_1] = "default"; |
|
|
509 | |
492 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
510 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
493 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
511 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
494 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
512 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
495 | { |
513 | { |
|
|
514 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
515 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
|
|
516 | if (rxvt_tainted ()) |
|
|
517 | { |
|
|
518 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
|
|
519 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
520 | { |
|
|
521 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
|
|
522 | rs[Rs_perl_lib] = 0; |
|
|
523 | rs[Rs_perl_eval] = 0; |
|
|
524 | } |
|
|
525 | } |
|
|
526 | #endif |
496 | rxvt_perl.init (); |
527 | rxvt_perl.init (); |
497 | PERL_INVOKE ((this, HOOK_INIT, DT_END)); |
528 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
498 | } |
529 | } |
499 | #endif |
530 | #endif |
500 | |
531 | |
501 | create_windows (argc, argv); |
532 | create_windows (argc, argv); |
502 | |
533 | |
… | |
… | |
534 | |
565 | |
535 | init_command (cmd_argv); |
566 | init_command (cmd_argv); |
536 | |
567 | |
537 | free (cmd_argv); |
568 | free (cmd_argv); |
538 | |
569 | |
|
|
570 | if (pty.pty >= 0) |
539 | pty_ev.start (pty.pty, EVENT_READ); |
571 | pty_ev.start (pty.pty, EVENT_READ); |
540 | |
572 | |
541 | check_ev.start (); |
573 | check_ev.start (); |
542 | |
574 | |
543 | PERL_INVOKE ((this, HOOK_START, DT_END)); |
575 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
544 | |
576 | |
545 | return true; |
577 | return true; |
546 | } |
578 | } |
547 | |
579 | |
548 | static struct sig_handlers |
580 | static struct sig_handlers |
… | |
… | |
609 | /* signal (SIGURG, SIG_DFL); */ |
641 | /* signal (SIGURG, SIG_DFL); */ |
610 | |
642 | |
611 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
643 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
612 | // TODO: handle this with exceptions and tolerate the memory loss |
644 | // TODO: handle this with exceptions and tolerate the memory loss |
613 | XSetIOErrorHandler (rxvt_xioerror_handler); |
645 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
646 | |
|
|
647 | XrmInitialize (); |
614 | } |
648 | } |
615 | |
649 | |
616 | /* ------------------------------------------------------------------------- * |
650 | /* ------------------------------------------------------------------------- * |
617 | * MEMORY ALLOCATION WRAPPERS * |
651 | * MEMORY ALLOCATION WRAPPERS * |
618 | * ------------------------------------------------------------------------- */ |
652 | * ------------------------------------------------------------------------- */ |
… | |
… | |
654 | * ------------------------------------------------------------------------- */ |
688 | * ------------------------------------------------------------------------- */ |
655 | /* take care of suid/sgid super-user (root) privileges */ |
689 | /* take care of suid/sgid super-user (root) privileges */ |
656 | void |
690 | void |
657 | rxvt_privileges (rxvt_privaction action) |
691 | rxvt_privileges (rxvt_privaction action) |
658 | { |
692 | { |
659 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
660 | static uid_t euid; |
|
|
661 | static gid_t egid; |
|
|
662 | #endif |
|
|
663 | |
|
|
664 | #if ! defined(__CYGWIN32__) |
693 | #if ! defined(__CYGWIN32__) |
665 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
694 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
666 | /* setreuid () is the poor man's setuid (), seteuid () */ |
695 | /* setreuid () is the poor man's setuid (), seteuid () */ |
667 | # define seteuid(a) setreuid(-1, (a)) |
696 | # define seteuid(a) setreuid(-1, (a)) |
668 | # define setegid(a) setregid(-1, (a)) |
697 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
678 | */ |
707 | */ |
679 | seteuid (getuid ()); |
708 | seteuid (getuid ()); |
680 | setegid (getgid ()); |
709 | setegid (getgid ()); |
681 | break; |
710 | break; |
682 | case SAVE: |
711 | case SAVE: |
683 | euid = geteuid (); |
712 | saved_euid = geteuid (); |
684 | egid = getegid (); |
713 | saved_egid = getegid (); |
685 | break; |
714 | break; |
686 | case RESTORE: |
715 | case RESTORE: |
687 | seteuid (euid); |
716 | seteuid (saved_euid); |
688 | setegid (egid); |
717 | setegid (saved_egid); |
689 | break; |
718 | break; |
690 | } |
719 | } |
691 | # else |
720 | # else |
692 | switch (action) |
721 | switch (action) |
693 | { |
722 | { |