… | |
… | |
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 | |
… | |
… | |
269 | if (parent[0]) |
284 | if (parent[0]) |
270 | XDestroyWindow (disp, parent[0]); |
285 | XDestroyWindow (disp, parent[0]); |
271 | } |
286 | } |
272 | |
287 | |
273 | // TODO: free pixcolours, colours should become part of rxvt_display |
288 | // TODO: free pixcolours, colours should become part of rxvt_display |
274 | |
|
|
275 | delete pix_colors_focused; |
289 | delete pix_colors_focused; |
276 | #if OFF_FOCUS_FADING |
290 | #if OFF_FOCUS_FADING |
277 | delete pix_colors_unfocused; |
291 | delete pix_colors_unfocused; |
278 | #endif |
292 | #endif |
279 | |
293 | |
… | |
… | |
363 | } |
377 | } |
364 | |
378 | |
365 | void |
379 | void |
366 | rxvt_term::destroy_cb (time_watcher &w) |
380 | rxvt_term::destroy_cb (time_watcher &w) |
367 | { |
381 | { |
368 | SET_R (this); |
382 | make_current (); |
369 | |
383 | |
370 | delete this; |
384 | delete this; |
371 | } |
385 | } |
372 | |
386 | |
373 | /*----------------------------------------------------------------------*/ |
387 | /*----------------------------------------------------------------------*/ |
… | |
… | |
464 | /*----------------------------------------------------------------------*/ |
478 | /*----------------------------------------------------------------------*/ |
465 | bool |
479 | bool |
466 | rxvt_term::init (int argc, const char *const *argv) |
480 | rxvt_term::init (int argc, const char *const *argv) |
467 | { |
481 | { |
468 | SET_R (this); |
482 | SET_R (this); |
469 | |
|
|
470 | set_locale (""); |
483 | set_locale (""); |
|
|
484 | set_environ (envv); // few things in X do not call setlocale :( |
471 | |
485 | |
472 | if (!init_vars ()) |
486 | if (!init_vars ()) |
473 | return false; |
487 | return false; |
474 | |
488 | |
475 | init_secondary (); |
489 | init_secondary (); |
… | |
… | |
487 | if (OPTION (Opt_scrollBar)) |
501 | if (OPTION (Opt_scrollBar)) |
488 | scrollBar.setIdle (); /* set existence for size calculations */ |
502 | scrollBar.setIdle (); /* set existence for size calculations */ |
489 | #endif |
503 | #endif |
490 | |
504 | |
491 | #if ENABLE_PERL |
505 | #if ENABLE_PERL |
|
|
506 | if (!rs[Rs_perl_ext_1]) |
|
|
507 | rs[Rs_perl_ext_1] = "default"; |
|
|
508 | |
492 | if (rs[Rs_perl_ext] && *rs[Rs_perl_ext]) |
509 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
510 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
511 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
493 | { |
512 | { |
|
|
513 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
514 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
|
|
515 | if (rxvt_tainted ()) |
|
|
516 | { |
|
|
517 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
|
|
518 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
519 | { |
|
|
520 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
|
|
521 | rs[Rs_perl_lib] = 0; |
|
|
522 | rs[Rs_perl_eval] = 0; |
|
|
523 | } |
|
|
524 | } |
|
|
525 | #endif |
494 | rxvt_perl.init (); |
526 | rxvt_perl.init (); |
|
|
527 | setlocale (LC_CTYPE, curlocale); // perl init destroys current locale |
495 | PERL_INVOKE ((this, HOOK_INIT, DT_END)); |
528 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
496 | } |
529 | } |
497 | #endif |
530 | #endif |
498 | |
531 | |
499 | create_windows (argc, argv); |
532 | create_windows (argc, argv); |
500 | |
533 | |
501 | dDisp; |
534 | dDisp; |
502 | |
535 | |
503 | init_xlocale (); |
536 | init_xlocale (); |
504 | |
537 | |
505 | scr_reset (); /* initialize screen */ |
538 | scr_reset (); // initialize screen |
506 | |
539 | |
507 | #if 0 |
540 | #if 0 |
508 | XSynchronize (disp, True); |
541 | XSynchronize (disp, True); |
509 | #endif |
542 | #endif |
510 | |
543 | |
… | |
… | |
532 | |
565 | |
533 | init_command (cmd_argv); |
566 | init_command (cmd_argv); |
534 | |
567 | |
535 | free (cmd_argv); |
568 | free (cmd_argv); |
536 | |
569 | |
|
|
570 | if (pty.pty >= 0) |
537 | pty_ev.start (pty.pty, EVENT_READ); |
571 | pty_ev.start (pty.pty, EVENT_READ); |
538 | |
572 | |
539 | check_ev.start (); |
573 | check_ev.start (); |
540 | |
574 | |
541 | PERL_INVOKE ((this, HOOK_START, DT_END)); |
575 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
542 | |
576 | |
543 | return true; |
577 | return true; |
544 | } |
578 | } |
545 | |
579 | |
546 | static struct sig_handlers |
580 | static struct sig_handlers |
… | |
… | |
581 | sw_int (this, &sig_handlers::sig_term) |
615 | sw_int (this, &sig_handlers::sig_term) |
582 | { |
616 | { |
583 | } |
617 | } |
584 | } sig_handlers; |
618 | } sig_handlers; |
585 | |
619 | |
|
|
620 | char **rxvt_environ; // startup environment |
|
|
621 | |
586 | void |
622 | void |
587 | rxvt_init () |
623 | rxvt_init () |
588 | { |
624 | { |
|
|
625 | rxvt_environ = environ; |
|
|
626 | |
589 | /* |
627 | /* |
590 | * Save and then give up any super-user privileges |
628 | * Save and then give up any super-user privileges |
591 | * If we need privileges in any area then we must specifically request it. |
629 | * If we need privileges in any area then we must specifically request it. |
592 | * We should only need to be root in these cases: |
630 | * We should only need to be root in these cases: |
593 | * 1. write utmp entries on some systems |
631 | * 1. write utmp entries on some systems |
… | |
… | |
607 | /* signal (SIGURG, SIG_DFL); */ |
645 | /* signal (SIGURG, SIG_DFL); */ |
608 | |
646 | |
609 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
647 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
610 | // TODO: handle this with exceptions and tolerate the memory loss |
648 | // TODO: handle this with exceptions and tolerate the memory loss |
611 | XSetIOErrorHandler (rxvt_xioerror_handler); |
649 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
650 | |
|
|
651 | XrmInitialize (); |
612 | } |
652 | } |
613 | |
653 | |
614 | /* ------------------------------------------------------------------------- * |
654 | /* ------------------------------------------------------------------------- * |
615 | * MEMORY ALLOCATION WRAPPERS * |
655 | * MEMORY ALLOCATION WRAPPERS * |
616 | * ------------------------------------------------------------------------- */ |
656 | * ------------------------------------------------------------------------- */ |
… | |
… | |
652 | * ------------------------------------------------------------------------- */ |
692 | * ------------------------------------------------------------------------- */ |
653 | /* take care of suid/sgid super-user (root) privileges */ |
693 | /* take care of suid/sgid super-user (root) privileges */ |
654 | void |
694 | void |
655 | rxvt_privileges (rxvt_privaction action) |
695 | rxvt_privileges (rxvt_privaction action) |
656 | { |
696 | { |
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__) |
697 | #if ! defined(__CYGWIN32__) |
663 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
698 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
664 | /* setreuid () is the poor man's setuid (), seteuid () */ |
699 | /* setreuid () is the poor man's setuid (), seteuid () */ |
665 | # define seteuid(a) setreuid(-1, (a)) |
700 | # define seteuid(a) setreuid(-1, (a)) |
666 | # define setegid(a) setregid(-1, (a)) |
701 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
672 | case IGNORE: |
707 | case IGNORE: |
673 | /* |
708 | /* |
674 | * change effective uid/gid - not real uid/gid - so we can switch |
709 | * change effective uid/gid - not real uid/gid - so we can switch |
675 | * back to root later, as required |
710 | * back to root later, as required |
676 | */ |
711 | */ |
|
|
712 | setegid (getgid ()); |
677 | seteuid (getuid ()); |
713 | seteuid (getuid ()); |
678 | setegid (getgid ()); |
|
|
679 | break; |
714 | break; |
680 | case SAVE: |
715 | case SAVE: |
681 | euid = geteuid (); |
|
|
682 | egid = getegid (); |
716 | saved_egid = getegid (); |
|
|
717 | saved_euid = geteuid (); |
683 | break; |
718 | break; |
684 | case RESTORE: |
719 | case RESTORE: |
685 | seteuid (euid); |
|
|
686 | setegid (egid); |
720 | setegid (saved_egid); |
|
|
721 | seteuid (saved_euid); |
687 | break; |
722 | break; |
688 | } |
723 | } |
689 | # else |
724 | # else |
690 | switch (action) |
725 | switch (action) |
691 | { |
726 | { |
692 | case IGNORE: |
727 | case IGNORE: |
|
|
728 | setgid (getgid ()); |
693 | setuid (getuid ()); |
729 | setuid (getuid ()); |
694 | setgid (getgid ()); |
|
|
695 | /* FALLTHROUGH */ |
730 | /* FALLTHROUGH */ |
696 | case SAVE: |
731 | case SAVE: |
697 | /* FALLTHROUGH */ |
732 | /* FALLTHROUGH */ |
698 | case RESTORE: |
733 | case RESTORE: |
699 | break; |
734 | break; |
… | |
… | |
1024 | i = atoi (color); |
1059 | i = atoi (color); |
1025 | |
1060 | |
1026 | if (i >= 8 && i <= 15) |
1061 | if (i >= 8 && i <= 15) |
1027 | { /* bright colors */ |
1062 | { /* bright colors */ |
1028 | i -= 8; |
1063 | i -= 8; |
1029 | # ifndef NO_BRIGHTCOLOR |
|
|
1030 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1064 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1031 | SET_PIXCOLOR (idx); |
1065 | SET_PIXCOLOR (idx); |
1032 | goto done; |
1066 | goto done; |
1033 | # endif |
|
|
1034 | } |
1067 | } |
1035 | |
1068 | |
1036 | if (i >= 0 && i <= 7) |
1069 | if (i >= 0 && i <= 7) |
1037 | { /* normal colors */ |
1070 | { /* normal colors */ |
1038 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1071 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
… | |
… | |
1222 | } |
1255 | } |
1223 | |
1256 | |
1224 | if (menubar_visible ()) |
1257 | if (menubar_visible ()) |
1225 | XMoveResizeWindow (disp, menuBar.win, |
1258 | XMoveResizeWindow (disp, menuBar.win, |
1226 | window_vt_x, 0, |
1259 | window_vt_x, 0, |
1227 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1260 | width, menuBar_TotalHeight ()); |
1228 | |
1261 | |
1229 | XMoveResizeWindow (disp, vt, |
1262 | XMoveResizeWindow (disp, vt, |
1230 | window_vt_x, window_vt_y, |
1263 | window_vt_x, window_vt_y, |
1231 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1264 | width, height); |
1232 | |
1265 | |
1233 | scr_clear (); |
1266 | scr_clear (); |
1234 | #ifdef XPM_BACKGROUND |
1267 | #ifdef XPM_BACKGROUND |
1235 | resize_pixmap (); |
1268 | resize_pixmap (); |
1236 | #endif |
1269 | #endif |
… | |
… | |
1416 | XRectangle rect, status_rect, needed_rect; |
1449 | XRectangle rect, status_rect, needed_rect; |
1417 | unsigned long fg, bg; |
1450 | unsigned long fg, bg; |
1418 | const char *p; |
1451 | const char *p; |
1419 | char **s; |
1452 | char **s; |
1420 | XIMStyles *xim_styles; |
1453 | XIMStyles *xim_styles; |
|
|
1454 | |
|
|
1455 | set_environ (envv); |
1421 | |
1456 | |
1422 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1457 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1423 | return false; |
1458 | return false; |
1424 | |
1459 | |
1425 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1460 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
… | |
… | |
1591 | int i; |
1626 | int i; |
1592 | const char *p; |
1627 | const char *p; |
1593 | char **s; |
1628 | char **s; |
1594 | char buf[IMBUFSIZ]; |
1629 | char buf[IMBUFSIZ]; |
1595 | |
1630 | |
1596 | SET_R (this); |
1631 | make_current (); |
1597 | |
1632 | |
1598 | im_destroy (); |
1633 | im_destroy (); |
1599 | |
1634 | |
1600 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1635 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1601 | if (Input_Context) |
1636 | if (Input_Context) |