… | |
… | |
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 | |
… | |
… | |
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); |
|
|
483 | TEMP_ENV; // few things in X do not call setlocale :( |
469 | |
484 | |
470 | set_locale (""); |
485 | set_locale (""); |
471 | |
486 | |
472 | if (!init_vars ()) |
487 | if (!init_vars ()) |
473 | return false; |
488 | return false; |
… | |
… | |
487 | if (OPTION (Opt_scrollBar)) |
502 | if (OPTION (Opt_scrollBar)) |
488 | scrollBar.setIdle (); /* set existence for size calculations */ |
503 | scrollBar.setIdle (); /* set existence for size calculations */ |
489 | #endif |
504 | #endif |
490 | |
505 | |
491 | #if ENABLE_PERL |
506 | #if ENABLE_PERL |
|
|
507 | if (!rs[Rs_perl_ext_1]) |
|
|
508 | rs[Rs_perl_ext_1] = "default"; |
|
|
509 | |
492 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
510 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
493 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
511 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
494 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
512 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
495 | { |
513 | { |
|
|
514 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
515 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
|
|
516 | if (rxvt_tainted ()) |
|
|
517 | { |
|
|
518 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
|
|
519 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
520 | { |
|
|
521 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
|
|
522 | rs[Rs_perl_lib] = 0; |
|
|
523 | rs[Rs_perl_eval] = 0; |
|
|
524 | } |
|
|
525 | } |
|
|
526 | #endif |
496 | rxvt_perl.init (); |
527 | rxvt_perl.init (); |
|
|
528 | setlocale (LC_CTYPE, curlocale); // perl init destroys this info |
497 | PERL_INVOKE ((this, HOOK_INIT, DT_END)); |
529 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
498 | } |
530 | } |
499 | #endif |
531 | #endif |
500 | |
532 | |
501 | create_windows (argc, argv); |
533 | create_windows (argc, argv); |
502 | |
534 | |
503 | dDisp; |
535 | dDisp; |
504 | |
536 | |
505 | init_xlocale (); |
537 | init_xlocale (); |
506 | |
538 | |
507 | scr_reset (); /* initialize screen */ |
539 | scr_reset (); // initialize screen |
508 | |
540 | |
509 | #if 0 |
541 | #if 0 |
510 | XSynchronize (disp, True); |
542 | XSynchronize (disp, True); |
511 | #endif |
543 | #endif |
512 | |
544 | |
… | |
… | |
534 | |
566 | |
535 | init_command (cmd_argv); |
567 | init_command (cmd_argv); |
536 | |
568 | |
537 | free (cmd_argv); |
569 | free (cmd_argv); |
538 | |
570 | |
|
|
571 | if (pty.pty >= 0) |
539 | pty_ev.start (pty.pty, EVENT_READ); |
572 | pty_ev.start (pty.pty, EVENT_READ); |
540 | |
573 | |
541 | check_ev.start (); |
574 | check_ev.start (); |
542 | |
575 | |
543 | PERL_INVOKE ((this, HOOK_START, DT_END)); |
576 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
544 | |
577 | |
545 | return true; |
578 | return true; |
546 | } |
579 | } |
547 | |
580 | |
548 | static struct sig_handlers |
581 | static struct sig_handlers |
… | |
… | |
583 | sw_int (this, &sig_handlers::sig_term) |
616 | sw_int (this, &sig_handlers::sig_term) |
584 | { |
617 | { |
585 | } |
618 | } |
586 | } sig_handlers; |
619 | } sig_handlers; |
587 | |
620 | |
|
|
621 | char **rxvt_environ; // startup environment |
|
|
622 | |
588 | void |
623 | void |
589 | rxvt_init () |
624 | rxvt_init () |
590 | { |
625 | { |
|
|
626 | rxvt_environ = environ; |
|
|
627 | |
591 | /* |
628 | /* |
592 | * Save and then give up any super-user privileges |
629 | * Save and then give up any super-user privileges |
593 | * If we need privileges in any area then we must specifically request it. |
630 | * If we need privileges in any area then we must specifically request it. |
594 | * We should only need to be root in these cases: |
631 | * We should only need to be root in these cases: |
595 | * 1. write utmp entries on some systems |
632 | * 1. write utmp entries on some systems |
… | |
… | |
609 | /* signal (SIGURG, SIG_DFL); */ |
646 | /* signal (SIGURG, SIG_DFL); */ |
610 | |
647 | |
611 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
648 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
612 | // TODO: handle this with exceptions and tolerate the memory loss |
649 | // TODO: handle this with exceptions and tolerate the memory loss |
613 | XSetIOErrorHandler (rxvt_xioerror_handler); |
650 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
651 | |
|
|
652 | XrmInitialize (); |
614 | } |
653 | } |
615 | |
654 | |
616 | /* ------------------------------------------------------------------------- * |
655 | /* ------------------------------------------------------------------------- * |
617 | * MEMORY ALLOCATION WRAPPERS * |
656 | * MEMORY ALLOCATION WRAPPERS * |
618 | * ------------------------------------------------------------------------- */ |
657 | * ------------------------------------------------------------------------- */ |
… | |
… | |
654 | * ------------------------------------------------------------------------- */ |
693 | * ------------------------------------------------------------------------- */ |
655 | /* take care of suid/sgid super-user (root) privileges */ |
694 | /* take care of suid/sgid super-user (root) privileges */ |
656 | void |
695 | void |
657 | rxvt_privileges (rxvt_privaction action) |
696 | rxvt_privileges (rxvt_privaction action) |
658 | { |
697 | { |
659 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
660 | static uid_t euid; |
|
|
661 | static gid_t egid; |
|
|
662 | #endif |
|
|
663 | |
|
|
664 | #if ! defined(__CYGWIN32__) |
698 | #if ! defined(__CYGWIN32__) |
665 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
699 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
666 | /* setreuid () is the poor man's setuid (), seteuid () */ |
700 | /* setreuid () is the poor man's setuid (), seteuid () */ |
667 | # define seteuid(a) setreuid(-1, (a)) |
701 | # define seteuid(a) setreuid(-1, (a)) |
668 | # define setegid(a) setregid(-1, (a)) |
702 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
674 | case IGNORE: |
708 | case IGNORE: |
675 | /* |
709 | /* |
676 | * change effective uid/gid - not real uid/gid - so we can switch |
710 | * change effective uid/gid - not real uid/gid - so we can switch |
677 | * back to root later, as required |
711 | * back to root later, as required |
678 | */ |
712 | */ |
|
|
713 | setegid (getgid ()); |
679 | seteuid (getuid ()); |
714 | seteuid (getuid ()); |
680 | setegid (getgid ()); |
|
|
681 | break; |
715 | break; |
682 | case SAVE: |
716 | case SAVE: |
683 | euid = geteuid (); |
|
|
684 | egid = getegid (); |
717 | saved_egid = getegid (); |
|
|
718 | saved_euid = geteuid (); |
685 | break; |
719 | break; |
686 | case RESTORE: |
720 | case RESTORE: |
687 | seteuid (euid); |
|
|
688 | setegid (egid); |
721 | setegid (saved_egid); |
|
|
722 | seteuid (saved_euid); |
689 | break; |
723 | break; |
690 | } |
724 | } |
691 | # else |
725 | # else |
692 | switch (action) |
726 | switch (action) |
693 | { |
727 | { |
694 | case IGNORE: |
728 | case IGNORE: |
|
|
729 | setgid (getgid ()); |
695 | setuid (getuid ()); |
730 | setuid (getuid ()); |
696 | setgid (getgid ()); |
|
|
697 | /* FALLTHROUGH */ |
731 | /* FALLTHROUGH */ |
698 | case SAVE: |
732 | case SAVE: |
699 | /* FALLTHROUGH */ |
733 | /* FALLTHROUGH */ |
700 | case RESTORE: |
734 | case RESTORE: |
701 | break; |
735 | break; |
… | |
… | |
1417 | unsigned long fg, bg; |
1451 | unsigned long fg, bg; |
1418 | const char *p; |
1452 | const char *p; |
1419 | char **s; |
1453 | char **s; |
1420 | XIMStyles *xim_styles; |
1454 | XIMStyles *xim_styles; |
1421 | |
1455 | |
|
|
1456 | TEMP_ENV; |
|
|
1457 | |
1422 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1458 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1423 | return false; |
1459 | return false; |
1424 | |
1460 | |
1425 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1461 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1426 | input_method = display->get_xim (locale, modifiers); |
1462 | input_method = display->get_xim (locale, modifiers); |