… | |
… | |
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 | |
51 | vector<rxvt_term *> rxvt_term::termlist; |
56 | vector<rxvt_term *> rxvt_term::termlist; |
52 | |
57 | |
53 | static char curlocale[128], savelocale[128]; |
58 | static char curlocale[128], savelocale[128]; |
54 | |
59 | |
55 | bool |
60 | bool |
… | |
… | |
206 | pty.put (); |
211 | pty.put (); |
207 | } |
212 | } |
208 | |
213 | |
209 | rxvt_term::~rxvt_term () |
214 | rxvt_term::~rxvt_term () |
210 | { |
215 | { |
211 | PERL_INVOKE ((this, HOOK_DESTROY, DT_END)); |
216 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
212 | |
217 | |
213 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
218 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
214 | |
219 | |
215 | emergency_cleanup (); |
220 | emergency_cleanup (); |
216 | |
221 | |
… | |
… | |
273 | // TODO: free pixcolours, colours should become part of rxvt_display |
278 | // TODO: free pixcolours, colours should become part of rxvt_display |
274 | |
279 | |
275 | delete pix_colors_focused; |
280 | delete pix_colors_focused; |
276 | #if OFF_FOCUS_FADING |
281 | #if OFF_FOCUS_FADING |
277 | delete pix_colors_unfocused; |
282 | delete pix_colors_unfocused; |
|
|
283 | #endif |
|
|
284 | #if USE_XGETDEFAULT |
|
|
285 | XrmDestroyDatabase (xrmdatabase); |
278 | #endif |
286 | #endif |
279 | |
287 | |
280 | displays.put (display); |
288 | displays.put (display); |
281 | |
289 | |
282 | scr_release (); |
290 | scr_release (); |
… | |
… | |
487 | if (OPTION (Opt_scrollBar)) |
495 | if (OPTION (Opt_scrollBar)) |
488 | scrollBar.setIdle (); /* set existence for size calculations */ |
496 | scrollBar.setIdle (); /* set existence for size calculations */ |
489 | #endif |
497 | #endif |
490 | |
498 | |
491 | #if ENABLE_PERL |
499 | #if ENABLE_PERL |
|
|
500 | if (!rs[Rs_perl_ext_1]) |
|
|
501 | rs[Rs_perl_ext_1] = "default"; |
|
|
502 | |
492 | if (rs[Rs_perl_ext] && *rs[Rs_perl_ext]) |
503 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
504 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
505 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
493 | { |
506 | { |
|
|
507 | bool tainted = false; |
|
|
508 | |
|
|
509 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
510 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
|
|
511 | if (getuid () != saved_euid || getgid () != saved_egid) |
|
|
512 | { |
|
|
513 | tainted = true; |
|
|
514 | |
|
|
515 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
|
|
516 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
517 | { |
|
|
518 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
|
|
519 | rs[Rs_perl_lib] = 0; |
|
|
520 | rs[Rs_perl_eval] = "our $tainted = 1"; |
|
|
521 | } |
|
|
522 | } |
|
|
523 | #endif |
494 | rxvt_perl.init (); |
524 | rxvt_perl.init (tainted); |
495 | PERL_INVOKE ((this, HOOK_INIT, DT_END)); |
525 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
496 | } |
526 | } |
497 | #endif |
527 | #endif |
498 | |
528 | |
499 | create_windows (argc, argv); |
529 | create_windows (argc, argv); |
500 | |
530 | |
… | |
… | |
532 | |
562 | |
533 | init_command (cmd_argv); |
563 | init_command (cmd_argv); |
534 | |
564 | |
535 | free (cmd_argv); |
565 | free (cmd_argv); |
536 | |
566 | |
|
|
567 | if (pty.pty >= 0) |
537 | pty_ev.start (pty.pty, EVENT_READ); |
568 | pty_ev.start (pty.pty, EVENT_READ); |
538 | |
569 | |
539 | check_ev.start (); |
570 | check_ev.start (); |
540 | |
571 | |
541 | PERL_INVOKE ((this, HOOK_START, DT_END)); |
572 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
542 | |
573 | |
543 | return true; |
574 | return true; |
544 | } |
575 | } |
545 | |
576 | |
546 | static struct sig_handlers |
577 | static struct sig_handlers |
… | |
… | |
607 | /* signal (SIGURG, SIG_DFL); */ |
638 | /* signal (SIGURG, SIG_DFL); */ |
608 | |
639 | |
609 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
640 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
610 | // TODO: handle this with exceptions and tolerate the memory loss |
641 | // TODO: handle this with exceptions and tolerate the memory loss |
611 | XSetIOErrorHandler (rxvt_xioerror_handler); |
642 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
643 | |
|
|
644 | #ifdef USE_XGETDEFAULT |
|
|
645 | XrmInitialize (); |
|
|
646 | #endif |
612 | } |
647 | } |
613 | |
648 | |
614 | /* ------------------------------------------------------------------------- * |
649 | /* ------------------------------------------------------------------------- * |
615 | * MEMORY ALLOCATION WRAPPERS * |
650 | * MEMORY ALLOCATION WRAPPERS * |
616 | * ------------------------------------------------------------------------- */ |
651 | * ------------------------------------------------------------------------- */ |
… | |
… | |
652 | * ------------------------------------------------------------------------- */ |
687 | * ------------------------------------------------------------------------- */ |
653 | /* take care of suid/sgid super-user (root) privileges */ |
688 | /* take care of suid/sgid super-user (root) privileges */ |
654 | void |
689 | void |
655 | rxvt_privileges (rxvt_privaction action) |
690 | rxvt_privileges (rxvt_privaction action) |
656 | { |
691 | { |
657 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
658 | static uid_t euid; |
|
|
659 | static gid_t egid; |
|
|
660 | #endif |
|
|
661 | |
|
|
662 | #if ! defined(__CYGWIN32__) |
692 | #if ! defined(__CYGWIN32__) |
663 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
693 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
664 | /* setreuid () is the poor man's setuid (), seteuid () */ |
694 | /* setreuid () is the poor man's setuid (), seteuid () */ |
665 | # define seteuid(a) setreuid(-1, (a)) |
695 | # define seteuid(a) setreuid(-1, (a)) |
666 | # define setegid(a) setregid(-1, (a)) |
696 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
676 | */ |
706 | */ |
677 | seteuid (getuid ()); |
707 | seteuid (getuid ()); |
678 | setegid (getgid ()); |
708 | setegid (getgid ()); |
679 | break; |
709 | break; |
680 | case SAVE: |
710 | case SAVE: |
681 | euid = geteuid (); |
711 | saved_euid = geteuid (); |
682 | egid = getegid (); |
712 | saved_egid = getegid (); |
683 | break; |
713 | break; |
684 | case RESTORE: |
714 | case RESTORE: |
685 | seteuid (euid); |
715 | seteuid (saved_euid); |
686 | setegid (egid); |
716 | setegid (saved_egid); |
687 | break; |
717 | break; |
688 | } |
718 | } |
689 | # else |
719 | # else |
690 | switch (action) |
720 | switch (action) |
691 | { |
721 | { |
… | |
… | |
1024 | i = atoi (color); |
1054 | i = atoi (color); |
1025 | |
1055 | |
1026 | if (i >= 8 && i <= 15) |
1056 | if (i >= 8 && i <= 15) |
1027 | { /* bright colors */ |
1057 | { /* bright colors */ |
1028 | i -= 8; |
1058 | i -= 8; |
1029 | # ifndef NO_BRIGHTCOLOR |
|
|
1030 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1059 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1031 | SET_PIXCOLOR (idx); |
1060 | SET_PIXCOLOR (idx); |
1032 | goto done; |
1061 | goto done; |
1033 | # endif |
|
|
1034 | } |
1062 | } |
1035 | |
1063 | |
1036 | if (i >= 0 && i <= 7) |
1064 | if (i >= 0 && i <= 7) |
1037 | { /* normal colors */ |
1065 | { /* normal colors */ |
1038 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1066 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |