… | |
… | |
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 | } |
72 | |
87 | |
73 | void |
88 | void |
74 | rxvt_pop_locale () |
89 | rxvt_pop_locale () |
75 | { |
90 | { |
76 | rxvt_set_locale (savelocale); |
91 | rxvt_set_locale (savelocale); |
|
|
92 | } |
|
|
93 | |
|
|
94 | void |
|
|
95 | rxvt_term::make_current () const |
|
|
96 | { |
|
|
97 | SET_R (this); |
|
|
98 | rxvt_set_locale (locale); |
|
|
99 | set_environ (envv); |
77 | } |
100 | } |
78 | |
101 | |
79 | #if ENABLE_COMBINING |
102 | #if ENABLE_COMBINING |
80 | class rxvt_composite_vec rxvt_composite; |
103 | class rxvt_composite_vec rxvt_composite; |
81 | |
104 | |
… | |
… | |
206 | pty.put (); |
229 | pty.put (); |
207 | } |
230 | } |
208 | |
231 | |
209 | rxvt_term::~rxvt_term () |
232 | rxvt_term::~rxvt_term () |
210 | { |
233 | { |
211 | PERL_INVOKE ((this, HOOK_DESTROY, DT_END)); |
234 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
212 | |
235 | |
213 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
236 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
214 | |
237 | |
215 | emergency_cleanup (); |
238 | emergency_cleanup (); |
216 | |
239 | |
… | |
… | |
269 | if (parent[0]) |
292 | if (parent[0]) |
270 | XDestroyWindow (disp, parent[0]); |
293 | XDestroyWindow (disp, parent[0]); |
271 | } |
294 | } |
272 | |
295 | |
273 | // TODO: free pixcolours, colours should become part of rxvt_display |
296 | // TODO: free pixcolours, colours should become part of rxvt_display |
274 | |
|
|
275 | delete pix_colors_focused; |
297 | delete pix_colors_focused; |
276 | #if OFF_FOCUS_FADING |
298 | #if OFF_FOCUS_FADING |
277 | delete pix_colors_unfocused; |
299 | delete pix_colors_unfocused; |
278 | #endif |
300 | #endif |
279 | |
301 | |
… | |
… | |
363 | } |
385 | } |
364 | |
386 | |
365 | void |
387 | void |
366 | rxvt_term::destroy_cb (time_watcher &w) |
388 | rxvt_term::destroy_cb (time_watcher &w) |
367 | { |
389 | { |
368 | SET_R (this); |
390 | make_current (); |
369 | |
391 | |
370 | delete this; |
392 | delete this; |
371 | } |
393 | } |
372 | |
394 | |
373 | /*----------------------------------------------------------------------*/ |
395 | /*----------------------------------------------------------------------*/ |
… | |
… | |
464 | /*----------------------------------------------------------------------*/ |
486 | /*----------------------------------------------------------------------*/ |
465 | bool |
487 | bool |
466 | rxvt_term::init (int argc, const char *const *argv) |
488 | rxvt_term::init (int argc, const char *const *argv) |
467 | { |
489 | { |
468 | SET_R (this); |
490 | SET_R (this); |
469 | |
|
|
470 | set_locale (""); |
491 | set_locale (""); |
|
|
492 | set_environ (envv); // few things in X do not call setlocale :( |
471 | |
493 | |
472 | if (!init_vars ()) |
494 | if (!init_vars ()) |
473 | return false; |
495 | return false; |
474 | |
496 | |
475 | init_secondary (); |
497 | init_secondary (); |
… | |
… | |
487 | if (OPTION (Opt_scrollBar)) |
509 | if (OPTION (Opt_scrollBar)) |
488 | scrollBar.setIdle (); /* set existence for size calculations */ |
510 | scrollBar.setIdle (); /* set existence for size calculations */ |
489 | #endif |
511 | #endif |
490 | |
512 | |
491 | #if ENABLE_PERL |
513 | #if ENABLE_PERL |
|
|
514 | if (!rs[Rs_perl_ext_1]) |
|
|
515 | rs[Rs_perl_ext_1] = "default"; |
|
|
516 | |
|
|
517 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
518 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
519 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
520 | { |
|
|
521 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
522 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
|
|
523 | if (rxvt_tainted ()) |
|
|
524 | { |
|
|
525 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
|
|
526 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
527 | { |
|
|
528 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
|
|
529 | rs[Rs_perl_lib] = 0; |
|
|
530 | rs[Rs_perl_eval] = 0; |
|
|
531 | } |
|
|
532 | } |
|
|
533 | #endif |
492 | rxvt_perl.init (); |
534 | rxvt_perl.init (); |
493 | #endif |
535 | setlocale (LC_CTYPE, curlocale); // perl init destroys current locale |
494 | |
|
|
495 | PERL_INVOKE ((this, HOOK_INIT, DT_END)); |
536 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
537 | } |
|
|
538 | #endif |
496 | |
539 | |
497 | create_windows (argc, argv); |
540 | create_windows (argc, argv); |
498 | |
541 | |
499 | dDisp; |
542 | dDisp; |
500 | |
543 | |
501 | init_xlocale (); |
544 | init_xlocale (); |
502 | |
545 | |
503 | scr_reset (); /* initialize screen */ |
546 | scr_reset (); // initialize screen |
504 | |
547 | |
505 | #if 0 |
548 | #if 0 |
506 | XSynchronize (disp, True); |
549 | XSynchronize (disp, True); |
507 | #endif |
550 | #endif |
508 | |
551 | |
… | |
… | |
530 | |
573 | |
531 | init_command (cmd_argv); |
574 | init_command (cmd_argv); |
532 | |
575 | |
533 | free (cmd_argv); |
576 | free (cmd_argv); |
534 | |
577 | |
|
|
578 | if (pty.pty >= 0) |
535 | pty_ev.start (pty.pty, EVENT_READ); |
579 | pty_ev.start (pty.pty, EVENT_READ); |
536 | |
580 | |
537 | check_ev.start (); |
581 | check_ev.start (); |
538 | |
582 | |
539 | PERL_INVOKE ((this, HOOK_START, DT_END)); |
583 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
540 | |
584 | |
541 | return true; |
585 | return true; |
542 | } |
586 | } |
543 | |
587 | |
544 | static struct sig_handlers |
588 | static struct sig_handlers |
… | |
… | |
579 | sw_int (this, &sig_handlers::sig_term) |
623 | sw_int (this, &sig_handlers::sig_term) |
580 | { |
624 | { |
581 | } |
625 | } |
582 | } sig_handlers; |
626 | } sig_handlers; |
583 | |
627 | |
|
|
628 | char **rxvt_environ; // startup environment |
|
|
629 | |
584 | void |
630 | void |
585 | rxvt_init () |
631 | rxvt_init () |
586 | { |
632 | { |
|
|
633 | rxvt_environ = environ; |
|
|
634 | |
587 | /* |
635 | /* |
588 | * Save and then give up any super-user privileges |
636 | * Save and then give up any super-user privileges |
589 | * 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. |
590 | * We should only need to be root in these cases: |
638 | * We should only need to be root in these cases: |
591 | * 1. write utmp entries on some systems |
639 | * 1. write utmp entries on some systems |
… | |
… | |
605 | /* signal (SIGURG, SIG_DFL); */ |
653 | /* signal (SIGURG, SIG_DFL); */ |
606 | |
654 | |
607 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
655 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
608 | // TODO: handle this with exceptions and tolerate the memory loss |
656 | // TODO: handle this with exceptions and tolerate the memory loss |
609 | XSetIOErrorHandler (rxvt_xioerror_handler); |
657 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
658 | |
|
|
659 | XrmInitialize (); |
610 | } |
660 | } |
611 | |
661 | |
612 | /* ------------------------------------------------------------------------- * |
662 | /* ------------------------------------------------------------------------- * |
613 | * MEMORY ALLOCATION WRAPPERS * |
663 | * MEMORY ALLOCATION WRAPPERS * |
614 | * ------------------------------------------------------------------------- */ |
664 | * ------------------------------------------------------------------------- */ |
… | |
… | |
650 | * ------------------------------------------------------------------------- */ |
700 | * ------------------------------------------------------------------------- */ |
651 | /* take care of suid/sgid super-user (root) privileges */ |
701 | /* take care of suid/sgid super-user (root) privileges */ |
652 | void |
702 | void |
653 | rxvt_privileges (rxvt_privaction action) |
703 | rxvt_privileges (rxvt_privaction action) |
654 | { |
704 | { |
655 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
656 | static uid_t euid; |
|
|
657 | static gid_t egid; |
|
|
658 | #endif |
|
|
659 | |
|
|
660 | #if ! defined(__CYGWIN32__) |
705 | #if ! defined(__CYGWIN32__) |
661 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
706 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
662 | /* setreuid () is the poor man's setuid (), seteuid () */ |
707 | /* setreuid () is the poor man's setuid (), seteuid () */ |
663 | # define seteuid(a) setreuid(-1, (a)) |
708 | # define seteuid(a) setreuid(-1, (a)) |
664 | # define setegid(a) setregid(-1, (a)) |
709 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
670 | case IGNORE: |
715 | case IGNORE: |
671 | /* |
716 | /* |
672 | * change effective uid/gid - not real uid/gid - so we can switch |
717 | * change effective uid/gid - not real uid/gid - so we can switch |
673 | * back to root later, as required |
718 | * back to root later, as required |
674 | */ |
719 | */ |
|
|
720 | setegid (getgid ()); |
675 | seteuid (getuid ()); |
721 | seteuid (getuid ()); |
676 | setegid (getgid ()); |
|
|
677 | break; |
722 | break; |
678 | case SAVE: |
723 | case SAVE: |
679 | euid = geteuid (); |
|
|
680 | egid = getegid (); |
724 | saved_egid = getegid (); |
|
|
725 | saved_euid = geteuid (); |
681 | break; |
726 | break; |
682 | case RESTORE: |
727 | case RESTORE: |
683 | seteuid (euid); |
|
|
684 | setegid (egid); |
728 | setegid (saved_egid); |
|
|
729 | seteuid (saved_euid); |
685 | break; |
730 | break; |
686 | } |
731 | } |
687 | # else |
732 | # else |
688 | switch (action) |
733 | switch (action) |
689 | { |
734 | { |
690 | case IGNORE: |
735 | case IGNORE: |
|
|
736 | setgid (getgid ()); |
691 | setuid (getuid ()); |
737 | setuid (getuid ()); |
692 | setgid (getgid ()); |
|
|
693 | /* FALLTHROUGH */ |
738 | /* FALLTHROUGH */ |
694 | case SAVE: |
739 | case SAVE: |
695 | /* FALLTHROUGH */ |
740 | /* FALLTHROUGH */ |
696 | case RESTORE: |
741 | case RESTORE: |
697 | break; |
742 | break; |
… | |
… | |
921 | prop.height += lineSpace; |
966 | prop.height += lineSpace; |
922 | fs->set_prop (prop); |
967 | fs->set_prop (prop); |
923 | |
968 | |
924 | fwidth = prop.width; |
969 | fwidth = prop.width; |
925 | fheight = prop.height; |
970 | fheight = prop.height; |
926 | fbase = (*fs)[1]->ascent; |
971 | fbase = prop.ascent; |
927 | |
972 | |
928 | for (int style = 1; style < 4; style++) |
973 | for (int style = 1; style < 4; style++) |
929 | { |
974 | { |
930 | #if ENABLE_STYLES |
975 | #if ENABLE_STYLES |
931 | const char *res = rs[Rs_font + style]; |
976 | const char *res = rs[Rs_font + style]; |
… | |
… | |
1022 | i = atoi (color); |
1067 | i = atoi (color); |
1023 | |
1068 | |
1024 | if (i >= 8 && i <= 15) |
1069 | if (i >= 8 && i <= 15) |
1025 | { /* bright colors */ |
1070 | { /* bright colors */ |
1026 | i -= 8; |
1071 | i -= 8; |
1027 | # ifndef NO_BRIGHTCOLOR |
|
|
1028 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1072 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1029 | SET_PIXCOLOR (idx); |
1073 | SET_PIXCOLOR (idx); |
1030 | goto done; |
1074 | goto done; |
1031 | # endif |
|
|
1032 | } |
1075 | } |
1033 | |
1076 | |
1034 | if (i >= 0 && i <= 7) |
1077 | if (i >= 0 && i <= 7) |
1035 | { /* normal colors */ |
1078 | { /* normal colors */ |
1036 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1079 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
… | |
… | |
1220 | } |
1263 | } |
1221 | |
1264 | |
1222 | if (menubar_visible ()) |
1265 | if (menubar_visible ()) |
1223 | XMoveResizeWindow (disp, menuBar.win, |
1266 | XMoveResizeWindow (disp, menuBar.win, |
1224 | window_vt_x, 0, |
1267 | window_vt_x, 0, |
1225 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1268 | width, menuBar_TotalHeight ()); |
1226 | |
1269 | |
1227 | XMoveResizeWindow (disp, vt, |
1270 | XMoveResizeWindow (disp, vt, |
1228 | window_vt_x, window_vt_y, |
1271 | window_vt_x, window_vt_y, |
1229 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1272 | width, height); |
1230 | |
1273 | |
1231 | scr_clear (); |
1274 | scr_clear (); |
1232 | #ifdef XPM_BACKGROUND |
1275 | #ifdef XPM_BACKGROUND |
1233 | resize_pixmap (); |
1276 | resize_pixmap (); |
1234 | #endif |
1277 | #endif |
… | |
… | |
1414 | XRectangle rect, status_rect, needed_rect; |
1457 | XRectangle rect, status_rect, needed_rect; |
1415 | unsigned long fg, bg; |
1458 | unsigned long fg, bg; |
1416 | const char *p; |
1459 | const char *p; |
1417 | char **s; |
1460 | char **s; |
1418 | XIMStyles *xim_styles; |
1461 | XIMStyles *xim_styles; |
|
|
1462 | |
|
|
1463 | set_environ (envv); |
1419 | |
1464 | |
1420 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1465 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1421 | return false; |
1466 | return false; |
1422 | |
1467 | |
1423 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1468 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
… | |
… | |
1589 | int i; |
1634 | int i; |
1590 | const char *p; |
1635 | const char *p; |
1591 | char **s; |
1636 | char **s; |
1592 | char buf[IMBUFSIZ]; |
1637 | char buf[IMBUFSIZ]; |
1593 | |
1638 | |
1594 | SET_R (this); |
1639 | make_current (); |
1595 | |
1640 | |
1596 | im_destroy (); |
1641 | im_destroy (); |
1597 | |
1642 | |
1598 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1643 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1599 | if (Input_Context) |
1644 | if (Input_Context) |