… | |
… | |
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. |
… | |
… | |
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
31 | *---------------------------------------------------------------------*/ |
31 | *---------------------------------------------------------------------*/ |
32 | |
32 | |
33 | #include "../config.h" /* NECESSARY */ |
33 | #include "../config.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
|
|
35 | #include "keyboard.h" |
|
|
36 | #include "rxvtperl.h" |
35 | |
37 | |
36 | #include <limits> |
38 | #include <limits> |
37 | |
39 | |
38 | #include <csignal> |
40 | #include <csignal> |
39 | #include <cstring> |
41 | #include <cstring> |
… | |
… | |
44 | |
46 | |
45 | #ifdef HAVE_TERMIOS_H |
47 | #ifdef HAVE_TERMIOS_H |
46 | # include <termios.h> |
48 | # include <termios.h> |
47 | #endif |
49 | #endif |
48 | |
50 | |
49 | #ifdef KEYSYM_RESOURCE |
51 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
50 | # include "keyboard.h" |
52 | static uid_t saved_euid; |
|
|
53 | static gid_t saved_egid; |
51 | #endif |
54 | #endif |
52 | |
55 | |
53 | vector<rxvt_term *> rxvt_term::termlist; |
56 | vector<rxvt_term *> rxvt_term::termlist; |
54 | |
57 | |
55 | static char curlocale[128]; |
58 | static char curlocale[128], savelocale[128]; |
56 | |
59 | |
57 | bool |
60 | bool |
58 | rxvt_set_locale (const char *locale) |
61 | rxvt_set_locale (const char *locale) |
59 | { |
62 | { |
60 | if (!locale || !strncmp (locale, curlocale, 128)) |
63 | if (!locale || !strncmp (locale, curlocale, 128)) |
61 | return false; |
64 | return false; |
62 | |
65 | |
63 | strncpy (curlocale, locale, 128); |
66 | strncpy (curlocale, locale, 128); |
64 | setlocale (LC_CTYPE, curlocale); |
67 | setlocale (LC_CTYPE, curlocale); |
65 | return true; |
68 | return true; |
|
|
69 | } |
|
|
70 | |
|
|
71 | bool |
|
|
72 | rxvt_push_locale (const char *locale) |
|
|
73 | { |
|
|
74 | strcpy (savelocale, curlocale); |
|
|
75 | rxvt_set_locale (locale); |
|
|
76 | } |
|
|
77 | |
|
|
78 | void |
|
|
79 | rxvt_pop_locale () |
|
|
80 | { |
|
|
81 | rxvt_set_locale (savelocale); |
66 | } |
82 | } |
67 | |
83 | |
68 | #if ENABLE_COMBINING |
84 | #if ENABLE_COMBINING |
69 | class rxvt_composite_vec rxvt_composite; |
85 | class rxvt_composite_vec rxvt_composite; |
70 | |
86 | |
… | |
… | |
195 | pty.put (); |
211 | pty.put (); |
196 | } |
212 | } |
197 | |
213 | |
198 | rxvt_term::~rxvt_term () |
214 | rxvt_term::~rxvt_term () |
199 | { |
215 | { |
|
|
216 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
|
|
217 | |
200 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
218 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
201 | |
219 | |
202 | emergency_cleanup (); |
220 | emergency_cleanup (); |
203 | |
221 | |
204 | #if ENABLE_STYLES |
222 | #if ENABLE_STYLES |
… | |
… | |
260 | // TODO: free pixcolours, colours should become part of rxvt_display |
278 | // TODO: free pixcolours, colours should become part of rxvt_display |
261 | |
279 | |
262 | delete pix_colors_focused; |
280 | delete pix_colors_focused; |
263 | #if OFF_FOCUS_FADING |
281 | #if OFF_FOCUS_FADING |
264 | delete pix_colors_unfocused; |
282 | delete pix_colors_unfocused; |
|
|
283 | #endif |
|
|
284 | #if USE_XGETDEFAULT |
|
|
285 | XrmDestroyDatabase (xrmdatabase); |
265 | #endif |
286 | #endif |
266 | |
287 | |
267 | displays.put (display); |
288 | displays.put (display); |
268 | |
289 | |
269 | scr_release (); |
290 | scr_release (); |
… | |
… | |
473 | #ifdef HAVE_SCROLLBARS |
494 | #ifdef HAVE_SCROLLBARS |
474 | if (OPTION (Opt_scrollBar)) |
495 | if (OPTION (Opt_scrollBar)) |
475 | scrollBar.setIdle (); /* set existence for size calculations */ |
496 | scrollBar.setIdle (); /* set existence for size calculations */ |
476 | #endif |
497 | #endif |
477 | |
498 | |
|
|
499 | #if ENABLE_PERL |
|
|
500 | if (!rs[Rs_perl_ext_1]) |
|
|
501 | rs[Rs_perl_ext_1] = "default"; |
|
|
502 | |
|
|
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])) |
|
|
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 |
|
|
524 | rxvt_perl.init (tainted); |
|
|
525 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
526 | } |
|
|
527 | #endif |
|
|
528 | |
478 | create_windows (argc, argv); |
529 | create_windows (argc, argv); |
479 | |
530 | |
480 | dDisp; |
531 | dDisp; |
481 | |
532 | |
482 | init_xlocale (); |
533 | init_xlocale (); |
… | |
… | |
511 | |
562 | |
512 | init_command (cmd_argv); |
563 | init_command (cmd_argv); |
513 | |
564 | |
514 | free (cmd_argv); |
565 | free (cmd_argv); |
515 | |
566 | |
|
|
567 | if (pty.pty >= 0) |
516 | pty_ev.start (pty.pty, EVENT_READ); |
568 | pty_ev.start (pty.pty, EVENT_READ); |
517 | |
569 | |
518 | check_ev.start (); |
570 | check_ev.start (); |
|
|
571 | |
|
|
572 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
519 | |
573 | |
520 | return true; |
574 | return true; |
521 | } |
575 | } |
522 | |
576 | |
523 | static struct sig_handlers |
577 | static struct sig_handlers |
… | |
… | |
584 | /* signal (SIGURG, SIG_DFL); */ |
638 | /* signal (SIGURG, SIG_DFL); */ |
585 | |
639 | |
586 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
640 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
587 | // TODO: handle this with exceptions and tolerate the memory loss |
641 | // TODO: handle this with exceptions and tolerate the memory loss |
588 | XSetIOErrorHandler (rxvt_xioerror_handler); |
642 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
643 | |
|
|
644 | #ifdef USE_XGETDEFAULT |
|
|
645 | XrmInitialize (); |
|
|
646 | #endif |
589 | } |
647 | } |
590 | |
648 | |
591 | /* ------------------------------------------------------------------------- * |
649 | /* ------------------------------------------------------------------------- * |
592 | * MEMORY ALLOCATION WRAPPERS * |
650 | * MEMORY ALLOCATION WRAPPERS * |
593 | * ------------------------------------------------------------------------- */ |
651 | * ------------------------------------------------------------------------- */ |
… | |
… | |
629 | * ------------------------------------------------------------------------- */ |
687 | * ------------------------------------------------------------------------- */ |
630 | /* take care of suid/sgid super-user (root) privileges */ |
688 | /* take care of suid/sgid super-user (root) privileges */ |
631 | void |
689 | void |
632 | rxvt_privileges (rxvt_privaction action) |
690 | rxvt_privileges (rxvt_privaction action) |
633 | { |
691 | { |
634 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
635 | static uid_t euid; |
|
|
636 | static gid_t egid; |
|
|
637 | #endif |
|
|
638 | |
|
|
639 | #if ! defined(__CYGWIN32__) |
692 | #if ! defined(__CYGWIN32__) |
640 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
693 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
641 | /* setreuid () is the poor man's setuid (), seteuid () */ |
694 | /* setreuid () is the poor man's setuid (), seteuid () */ |
642 | # define seteuid(a) setreuid(-1, (a)) |
695 | # define seteuid(a) setreuid(-1, (a)) |
643 | # define setegid(a) setregid(-1, (a)) |
696 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
653 | */ |
706 | */ |
654 | seteuid (getuid ()); |
707 | seteuid (getuid ()); |
655 | setegid (getgid ()); |
708 | setegid (getgid ()); |
656 | break; |
709 | break; |
657 | case SAVE: |
710 | case SAVE: |
658 | euid = geteuid (); |
711 | saved_euid = geteuid (); |
659 | egid = getegid (); |
712 | saved_egid = getegid (); |
660 | break; |
713 | break; |
661 | case RESTORE: |
714 | case RESTORE: |
662 | seteuid (euid); |
715 | seteuid (saved_euid); |
663 | setegid (egid); |
716 | setegid (saved_egid); |
664 | break; |
717 | break; |
665 | } |
718 | } |
666 | # else |
719 | # else |
667 | switch (action) |
720 | switch (action) |
668 | { |
721 | { |
… | |
… | |
900 | prop.height += lineSpace; |
953 | prop.height += lineSpace; |
901 | fs->set_prop (prop); |
954 | fs->set_prop (prop); |
902 | |
955 | |
903 | fwidth = prop.width; |
956 | fwidth = prop.width; |
904 | fheight = prop.height; |
957 | fheight = prop.height; |
905 | fbase = (*fs)[1]->ascent; |
958 | fbase = prop.ascent; |
906 | |
959 | |
907 | for (int style = 1; style < 4; style++) |
960 | for (int style = 1; style < 4; style++) |
908 | { |
961 | { |
909 | #if ENABLE_STYLES |
962 | #if ENABLE_STYLES |
910 | const char *res = rs[Rs_font + style]; |
963 | const char *res = rs[Rs_font + style]; |
… | |
… | |
1001 | i = atoi (color); |
1054 | i = atoi (color); |
1002 | |
1055 | |
1003 | if (i >= 8 && i <= 15) |
1056 | if (i >= 8 && i <= 15) |
1004 | { /* bright colors */ |
1057 | { /* bright colors */ |
1005 | i -= 8; |
1058 | i -= 8; |
1006 | # ifndef NO_BRIGHTCOLOR |
|
|
1007 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1059 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1008 | SET_PIXCOLOR (idx); |
1060 | SET_PIXCOLOR (idx); |
1009 | goto done; |
1061 | goto done; |
1010 | # endif |
|
|
1011 | } |
1062 | } |
1012 | |
1063 | |
1013 | if (i >= 0 && i <= 7) |
1064 | if (i >= 0 && i <= 7) |
1014 | { /* normal colors */ |
1065 | { /* normal colors */ |
1015 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1066 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
… | |
… | |
1199 | } |
1250 | } |
1200 | |
1251 | |
1201 | if (menubar_visible ()) |
1252 | if (menubar_visible ()) |
1202 | XMoveResizeWindow (disp, menuBar.win, |
1253 | XMoveResizeWindow (disp, menuBar.win, |
1203 | window_vt_x, 0, |
1254 | window_vt_x, 0, |
1204 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1255 | width, menuBar_TotalHeight ()); |
1205 | |
1256 | |
1206 | XMoveResizeWindow (disp, vt, |
1257 | XMoveResizeWindow (disp, vt, |
1207 | window_vt_x, window_vt_y, |
1258 | window_vt_x, window_vt_y, |
1208 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1259 | width, height); |
1209 | |
1260 | |
1210 | scr_clear (); |
1261 | scr_clear (); |
1211 | #ifdef XPM_BACKGROUND |
1262 | #ifdef XPM_BACKGROUND |
1212 | resize_pixmap (); |
1263 | resize_pixmap (); |
1213 | #endif |
1264 | #endif |