… | |
… | |
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]; |
58 | static char curlocale[128], savelocale[128]; |
54 | |
59 | |
55 | bool |
60 | bool |
56 | rxvt_set_locale (const char *locale) |
61 | rxvt_set_locale (const char *locale) |
57 | { |
62 | { |
58 | if (!locale || !strncmp (locale, curlocale, 128)) |
63 | if (!locale || !strncmp (locale, curlocale, 128)) |
59 | return false; |
64 | return false; |
60 | |
65 | |
61 | strncpy (curlocale, locale, 128); |
66 | strncpy (curlocale, locale, 128); |
62 | setlocale (LC_CTYPE, curlocale); |
67 | setlocale (LC_CTYPE, curlocale); |
63 | 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); |
64 | } |
82 | } |
65 | |
83 | |
66 | #if ENABLE_COMBINING |
84 | #if ENABLE_COMBINING |
67 | class rxvt_composite_vec rxvt_composite; |
85 | class rxvt_composite_vec rxvt_composite; |
68 | |
86 | |
… | |
… | |
193 | pty.put (); |
211 | pty.put (); |
194 | } |
212 | } |
195 | |
213 | |
196 | rxvt_term::~rxvt_term () |
214 | rxvt_term::~rxvt_term () |
197 | { |
215 | { |
198 | PERL_INVOKE ((this, HOOK_DESTROY, DT_END)); |
216 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
199 | |
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 | |
… | |
… | |
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 (); |
… | |
… | |
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 | |
478 | #if ENABLE_PERL |
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 |
479 | rxvt_perl.init (); |
524 | rxvt_perl.init (tainted); |
480 | #endif |
|
|
481 | |
|
|
482 | PERL_INVOKE ((this, HOOK_INIT, DT_END)); |
525 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
526 | } |
|
|
527 | #endif |
483 | |
528 | |
484 | create_windows (argc, argv); |
529 | create_windows (argc, argv); |
485 | |
530 | |
486 | dDisp; |
531 | dDisp; |
487 | |
532 | |
… | |
… | |
517 | |
562 | |
518 | init_command (cmd_argv); |
563 | init_command (cmd_argv); |
519 | |
564 | |
520 | free (cmd_argv); |
565 | free (cmd_argv); |
521 | |
566 | |
|
|
567 | if (pty.pty >= 0) |
522 | pty_ev.start (pty.pty, EVENT_READ); |
568 | pty_ev.start (pty.pty, EVENT_READ); |
523 | |
569 | |
524 | check_ev.start (); |
570 | check_ev.start (); |
525 | |
571 | |
526 | PERL_INVOKE ((this, HOOK_START, DT_END)); |
572 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
527 | |
573 | |
528 | return true; |
574 | return true; |
529 | } |
575 | } |
530 | |
576 | |
531 | static struct sig_handlers |
577 | static struct sig_handlers |
… | |
… | |
592 | /* signal (SIGURG, SIG_DFL); */ |
638 | /* signal (SIGURG, SIG_DFL); */ |
593 | |
639 | |
594 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
640 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
595 | // TODO: handle this with exceptions and tolerate the memory loss |
641 | // TODO: handle this with exceptions and tolerate the memory loss |
596 | XSetIOErrorHandler (rxvt_xioerror_handler); |
642 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
643 | |
|
|
644 | #ifdef USE_XGETDEFAULT |
|
|
645 | XrmInitialize (); |
|
|
646 | #endif |
597 | } |
647 | } |
598 | |
648 | |
599 | /* ------------------------------------------------------------------------- * |
649 | /* ------------------------------------------------------------------------- * |
600 | * MEMORY ALLOCATION WRAPPERS * |
650 | * MEMORY ALLOCATION WRAPPERS * |
601 | * ------------------------------------------------------------------------- */ |
651 | * ------------------------------------------------------------------------- */ |
… | |
… | |
637 | * ------------------------------------------------------------------------- */ |
687 | * ------------------------------------------------------------------------- */ |
638 | /* take care of suid/sgid super-user (root) privileges */ |
688 | /* take care of suid/sgid super-user (root) privileges */ |
639 | void |
689 | void |
640 | rxvt_privileges (rxvt_privaction action) |
690 | rxvt_privileges (rxvt_privaction action) |
641 | { |
691 | { |
642 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
643 | static uid_t euid; |
|
|
644 | static gid_t egid; |
|
|
645 | #endif |
|
|
646 | |
|
|
647 | #if ! defined(__CYGWIN32__) |
692 | #if ! defined(__CYGWIN32__) |
648 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
693 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
649 | /* setreuid () is the poor man's setuid (), seteuid () */ |
694 | /* setreuid () is the poor man's setuid (), seteuid () */ |
650 | # define seteuid(a) setreuid(-1, (a)) |
695 | # define seteuid(a) setreuid(-1, (a)) |
651 | # define setegid(a) setregid(-1, (a)) |
696 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
661 | */ |
706 | */ |
662 | seteuid (getuid ()); |
707 | seteuid (getuid ()); |
663 | setegid (getgid ()); |
708 | setegid (getgid ()); |
664 | break; |
709 | break; |
665 | case SAVE: |
710 | case SAVE: |
666 | euid = geteuid (); |
711 | saved_euid = geteuid (); |
667 | egid = getegid (); |
712 | saved_egid = getegid (); |
668 | break; |
713 | break; |
669 | case RESTORE: |
714 | case RESTORE: |
670 | seteuid (euid); |
715 | seteuid (saved_euid); |
671 | setegid (egid); |
716 | setegid (saved_egid); |
672 | break; |
717 | break; |
673 | } |
718 | } |
674 | # else |
719 | # else |
675 | switch (action) |
720 | switch (action) |
676 | { |
721 | { |
… | |
… | |
908 | prop.height += lineSpace; |
953 | prop.height += lineSpace; |
909 | fs->set_prop (prop); |
954 | fs->set_prop (prop); |
910 | |
955 | |
911 | fwidth = prop.width; |
956 | fwidth = prop.width; |
912 | fheight = prop.height; |
957 | fheight = prop.height; |
913 | fbase = (*fs)[1]->ascent; |
958 | fbase = prop.ascent; |
914 | |
959 | |
915 | for (int style = 1; style < 4; style++) |
960 | for (int style = 1; style < 4; style++) |
916 | { |
961 | { |
917 | #if ENABLE_STYLES |
962 | #if ENABLE_STYLES |
918 | const char *res = rs[Rs_font + style]; |
963 | const char *res = rs[Rs_font + style]; |
… | |
… | |
1009 | i = atoi (color); |
1054 | i = atoi (color); |
1010 | |
1055 | |
1011 | if (i >= 8 && i <= 15) |
1056 | if (i >= 8 && i <= 15) |
1012 | { /* bright colors */ |
1057 | { /* bright colors */ |
1013 | i -= 8; |
1058 | i -= 8; |
1014 | # ifndef NO_BRIGHTCOLOR |
|
|
1015 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1059 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1016 | SET_PIXCOLOR (idx); |
1060 | SET_PIXCOLOR (idx); |
1017 | goto done; |
1061 | goto done; |
1018 | # endif |
|
|
1019 | } |
1062 | } |
1020 | |
1063 | |
1021 | if (i >= 0 && i <= 7) |
1064 | if (i >= 0 && i <= 7) |
1022 | { /* normal colors */ |
1065 | { /* normal colors */ |
1023 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1066 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
… | |
… | |
1207 | } |
1250 | } |
1208 | |
1251 | |
1209 | if (menubar_visible ()) |
1252 | if (menubar_visible ()) |
1210 | XMoveResizeWindow (disp, menuBar.win, |
1253 | XMoveResizeWindow (disp, menuBar.win, |
1211 | window_vt_x, 0, |
1254 | window_vt_x, 0, |
1212 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1255 | width, menuBar_TotalHeight ()); |
1213 | |
1256 | |
1214 | XMoveResizeWindow (disp, vt, |
1257 | XMoveResizeWindow (disp, vt, |
1215 | window_vt_x, window_vt_y, |
1258 | window_vt_x, window_vt_y, |
1216 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1259 | width, height); |
1217 | |
1260 | |
1218 | scr_clear (); |
1261 | scr_clear (); |
1219 | #ifdef XPM_BACKGROUND |
1262 | #ifdef XPM_BACKGROUND |
1220 | resize_pixmap (); |
1263 | resize_pixmap (); |
1221 | #endif |
1264 | #endif |