… | |
… | |
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 | |
… | |
… | |
464 | /*----------------------------------------------------------------------*/ |
479 | /*----------------------------------------------------------------------*/ |
465 | bool |
480 | bool |
466 | rxvt_term::init (int argc, const char *const *argv) |
481 | rxvt_term::init (int argc, const char *const *argv) |
467 | { |
482 | { |
468 | SET_R (this); |
483 | SET_R (this); |
|
|
484 | TEMP_ENV; // few things in X do not call setlocale :( |
469 | |
485 | |
470 | set_locale (""); |
486 | set_locale (""); |
471 | |
487 | |
472 | if (!init_vars ()) |
488 | if (!init_vars ()) |
473 | return false; |
489 | return false; |
… | |
… | |
487 | if (OPTION (Opt_scrollBar)) |
503 | if (OPTION (Opt_scrollBar)) |
488 | scrollBar.setIdle (); /* set existence for size calculations */ |
504 | scrollBar.setIdle (); /* set existence for size calculations */ |
489 | #endif |
505 | #endif |
490 | |
506 | |
491 | #if ENABLE_PERL |
507 | #if ENABLE_PERL |
|
|
508 | if (!rs[Rs_perl_ext_1]) |
|
|
509 | rs[Rs_perl_ext_1] = "default"; |
|
|
510 | |
492 | if (rs[Rs_perl_ext] && *rs[Rs_perl_ext]) |
511 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
512 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
513 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
493 | { |
514 | { |
|
|
515 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
516 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
|
|
517 | if (rxvt_tainted ()) |
|
|
518 | { |
|
|
519 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
|
|
520 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
521 | { |
|
|
522 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
|
|
523 | rs[Rs_perl_lib] = 0; |
|
|
524 | rs[Rs_perl_eval] = 0; |
|
|
525 | } |
|
|
526 | } |
|
|
527 | #endif |
494 | rxvt_perl.init (); |
528 | rxvt_perl.init (); |
495 | PERL_INVOKE ((this, HOOK_INIT, DT_END)); |
529 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
496 | } |
530 | } |
497 | #endif |
531 | #endif |
498 | |
532 | |
499 | create_windows (argc, argv); |
533 | create_windows (argc, argv); |
500 | |
534 | |
501 | dDisp; |
535 | dDisp; |
502 | |
536 | |
503 | init_xlocale (); |
537 | init_xlocale (); |
504 | |
538 | |
505 | scr_reset (); /* initialize screen */ |
539 | scr_reset (); // initialize screen |
506 | |
540 | |
507 | #if 0 |
541 | #if 0 |
508 | XSynchronize (disp, True); |
542 | XSynchronize (disp, True); |
509 | #endif |
543 | #endif |
510 | |
544 | |
… | |
… | |
532 | |
566 | |
533 | init_command (cmd_argv); |
567 | init_command (cmd_argv); |
534 | |
568 | |
535 | free (cmd_argv); |
569 | free (cmd_argv); |
536 | |
570 | |
|
|
571 | if (pty.pty >= 0) |
537 | pty_ev.start (pty.pty, EVENT_READ); |
572 | pty_ev.start (pty.pty, EVENT_READ); |
538 | |
573 | |
539 | check_ev.start (); |
574 | check_ev.start (); |
540 | |
575 | |
541 | PERL_INVOKE ((this, HOOK_START, DT_END)); |
576 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
542 | |
577 | |
543 | return true; |
578 | return true; |
544 | } |
579 | } |
545 | |
580 | |
546 | static struct sig_handlers |
581 | static struct sig_handlers |
… | |
… | |
607 | /* signal (SIGURG, SIG_DFL); */ |
642 | /* signal (SIGURG, SIG_DFL); */ |
608 | |
643 | |
609 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
644 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
610 | // TODO: handle this with exceptions and tolerate the memory loss |
645 | // TODO: handle this with exceptions and tolerate the memory loss |
611 | XSetIOErrorHandler (rxvt_xioerror_handler); |
646 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
647 | |
|
|
648 | XrmInitialize (); |
612 | } |
649 | } |
613 | |
650 | |
614 | /* ------------------------------------------------------------------------- * |
651 | /* ------------------------------------------------------------------------- * |
615 | * MEMORY ALLOCATION WRAPPERS * |
652 | * MEMORY ALLOCATION WRAPPERS * |
616 | * ------------------------------------------------------------------------- */ |
653 | * ------------------------------------------------------------------------- */ |
… | |
… | |
652 | * ------------------------------------------------------------------------- */ |
689 | * ------------------------------------------------------------------------- */ |
653 | /* take care of suid/sgid super-user (root) privileges */ |
690 | /* take care of suid/sgid super-user (root) privileges */ |
654 | void |
691 | void |
655 | rxvt_privileges (rxvt_privaction action) |
692 | rxvt_privileges (rxvt_privaction action) |
656 | { |
693 | { |
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__) |
694 | #if ! defined(__CYGWIN32__) |
663 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
695 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
664 | /* setreuid () is the poor man's setuid (), seteuid () */ |
696 | /* setreuid () is the poor man's setuid (), seteuid () */ |
665 | # define seteuid(a) setreuid(-1, (a)) |
697 | # define seteuid(a) setreuid(-1, (a)) |
666 | # define setegid(a) setregid(-1, (a)) |
698 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
676 | */ |
708 | */ |
677 | seteuid (getuid ()); |
709 | seteuid (getuid ()); |
678 | setegid (getgid ()); |
710 | setegid (getgid ()); |
679 | break; |
711 | break; |
680 | case SAVE: |
712 | case SAVE: |
681 | euid = geteuid (); |
713 | saved_euid = geteuid (); |
682 | egid = getegid (); |
714 | saved_egid = getegid (); |
683 | break; |
715 | break; |
684 | case RESTORE: |
716 | case RESTORE: |
685 | seteuid (euid); |
717 | seteuid (saved_euid); |
686 | setegid (egid); |
718 | setegid (saved_egid); |
687 | break; |
719 | break; |
688 | } |
720 | } |
689 | # else |
721 | # else |
690 | switch (action) |
722 | switch (action) |
691 | { |
723 | { |
… | |
… | |
923 | prop.height += lineSpace; |
955 | prop.height += lineSpace; |
924 | fs->set_prop (prop); |
956 | fs->set_prop (prop); |
925 | |
957 | |
926 | fwidth = prop.width; |
958 | fwidth = prop.width; |
927 | fheight = prop.height; |
959 | fheight = prop.height; |
928 | fbase = (*fs)[1]->ascent; |
960 | fbase = prop.ascent; |
929 | |
961 | |
930 | for (int style = 1; style < 4; style++) |
962 | for (int style = 1; style < 4; style++) |
931 | { |
963 | { |
932 | #if ENABLE_STYLES |
964 | #if ENABLE_STYLES |
933 | const char *res = rs[Rs_font + style]; |
965 | const char *res = rs[Rs_font + style]; |
… | |
… | |
1024 | i = atoi (color); |
1056 | i = atoi (color); |
1025 | |
1057 | |
1026 | if (i >= 8 && i <= 15) |
1058 | if (i >= 8 && i <= 15) |
1027 | { /* bright colors */ |
1059 | { /* bright colors */ |
1028 | i -= 8; |
1060 | i -= 8; |
1029 | # ifndef NO_BRIGHTCOLOR |
|
|
1030 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1061 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1031 | SET_PIXCOLOR (idx); |
1062 | SET_PIXCOLOR (idx); |
1032 | goto done; |
1063 | goto done; |
1033 | # endif |
|
|
1034 | } |
1064 | } |
1035 | |
1065 | |
1036 | if (i >= 0 && i <= 7) |
1066 | if (i >= 0 && i <= 7) |
1037 | { /* normal colors */ |
1067 | { /* normal colors */ |
1038 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1068 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
… | |
… | |
1222 | } |
1252 | } |
1223 | |
1253 | |
1224 | if (menubar_visible ()) |
1254 | if (menubar_visible ()) |
1225 | XMoveResizeWindow (disp, menuBar.win, |
1255 | XMoveResizeWindow (disp, menuBar.win, |
1226 | window_vt_x, 0, |
1256 | window_vt_x, 0, |
1227 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1257 | width, menuBar_TotalHeight ()); |
1228 | |
1258 | |
1229 | XMoveResizeWindow (disp, vt, |
1259 | XMoveResizeWindow (disp, vt, |
1230 | window_vt_x, window_vt_y, |
1260 | window_vt_x, window_vt_y, |
1231 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1261 | width, height); |
1232 | |
1262 | |
1233 | scr_clear (); |
1263 | scr_clear (); |
1234 | #ifdef XPM_BACKGROUND |
1264 | #ifdef XPM_BACKGROUND |
1235 | resize_pixmap (); |
1265 | resize_pixmap (); |
1236 | #endif |
1266 | #endif |
… | |
… | |
1416 | XRectangle rect, status_rect, needed_rect; |
1446 | XRectangle rect, status_rect, needed_rect; |
1417 | unsigned long fg, bg; |
1447 | unsigned long fg, bg; |
1418 | const char *p; |
1448 | const char *p; |
1419 | char **s; |
1449 | char **s; |
1420 | XIMStyles *xim_styles; |
1450 | XIMStyles *xim_styles; |
|
|
1451 | |
|
|
1452 | TEMP_ENV; |
1421 | |
1453 | |
1422 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1454 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1423 | return false; |
1455 | return false; |
1424 | |
1456 | |
1425 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1457 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |