… | |
… | |
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 | |
… | |
… | |
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 |
|
|
279 | #if USE_XGETDEFAULT |
|
|
280 | XrmDestroyDatabase (xrmdatabase); |
|
|
281 | #endif |
300 | #endif |
282 | |
301 | |
283 | displays.put (display); |
302 | displays.put (display); |
284 | |
303 | |
285 | scr_release (); |
304 | scr_release (); |
… | |
… | |
366 | } |
385 | } |
367 | |
386 | |
368 | void |
387 | void |
369 | rxvt_term::destroy_cb (time_watcher &w) |
388 | rxvt_term::destroy_cb (time_watcher &w) |
370 | { |
389 | { |
371 | SET_R (this); |
390 | make_current (); |
372 | |
391 | |
373 | delete this; |
392 | delete this; |
374 | } |
393 | } |
375 | |
394 | |
376 | /*----------------------------------------------------------------------*/ |
395 | /*----------------------------------------------------------------------*/ |
… | |
… | |
467 | /*----------------------------------------------------------------------*/ |
486 | /*----------------------------------------------------------------------*/ |
468 | bool |
487 | bool |
469 | rxvt_term::init (int argc, const char *const *argv) |
488 | rxvt_term::init (int argc, const char *const *argv) |
470 | { |
489 | { |
471 | SET_R (this); |
490 | SET_R (this); |
472 | |
|
|
473 | set_locale (""); |
491 | set_locale (""); |
|
|
492 | set_environ (envv); // few things in X do not call setlocale :( |
474 | |
493 | |
475 | if (!init_vars ()) |
494 | if (!init_vars ()) |
476 | return false; |
495 | return false; |
477 | |
496 | |
478 | init_secondary (); |
497 | init_secondary (); |
… | |
… | |
497 | |
516 | |
498 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
517 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
499 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
518 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
500 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
519 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
501 | { |
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 |
502 | rxvt_perl.init (); |
534 | rxvt_perl.init (); |
|
|
535 | setlocale (LC_CTYPE, curlocale); // perl init destroys current locale |
503 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
536 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
504 | } |
537 | } |
505 | #endif |
538 | #endif |
506 | |
539 | |
507 | create_windows (argc, argv); |
540 | create_windows (argc, argv); |
508 | |
541 | |
509 | dDisp; |
542 | dDisp; |
510 | |
543 | |
511 | init_xlocale (); |
544 | init_xlocale (); |
512 | |
545 | |
513 | scr_reset (); /* initialize screen */ |
546 | scr_reset (); // initialize screen |
514 | |
547 | |
515 | #if 0 |
548 | #if 0 |
516 | XSynchronize (disp, True); |
549 | XSynchronize (disp, True); |
517 | #endif |
550 | #endif |
518 | |
551 | |
… | |
… | |
590 | sw_int (this, &sig_handlers::sig_term) |
623 | sw_int (this, &sig_handlers::sig_term) |
591 | { |
624 | { |
592 | } |
625 | } |
593 | } sig_handlers; |
626 | } sig_handlers; |
594 | |
627 | |
|
|
628 | char **rxvt_environ; // startup environment |
|
|
629 | |
595 | void |
630 | void |
596 | rxvt_init () |
631 | rxvt_init () |
597 | { |
632 | { |
|
|
633 | rxvt_environ = environ; |
|
|
634 | |
598 | /* |
635 | /* |
599 | * Save and then give up any super-user privileges |
636 | * Save and then give up any super-user privileges |
600 | * 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. |
601 | * We should only need to be root in these cases: |
638 | * We should only need to be root in these cases: |
602 | * 1. write utmp entries on some systems |
639 | * 1. write utmp entries on some systems |
… | |
… | |
617 | |
654 | |
618 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
655 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
619 | // TODO: handle this with exceptions and tolerate the memory loss |
656 | // TODO: handle this with exceptions and tolerate the memory loss |
620 | XSetIOErrorHandler (rxvt_xioerror_handler); |
657 | XSetIOErrorHandler (rxvt_xioerror_handler); |
621 | |
658 | |
622 | #ifdef USE_XGETDEFAULT |
|
|
623 | XrmInitialize (); |
659 | XrmInitialize (); |
624 | #endif |
|
|
625 | } |
660 | } |
626 | |
661 | |
627 | /* ------------------------------------------------------------------------- * |
662 | /* ------------------------------------------------------------------------- * |
628 | * MEMORY ALLOCATION WRAPPERS * |
663 | * MEMORY ALLOCATION WRAPPERS * |
629 | * ------------------------------------------------------------------------- */ |
664 | * ------------------------------------------------------------------------- */ |
… | |
… | |
665 | * ------------------------------------------------------------------------- */ |
700 | * ------------------------------------------------------------------------- */ |
666 | /* take care of suid/sgid super-user (root) privileges */ |
701 | /* take care of suid/sgid super-user (root) privileges */ |
667 | void |
702 | void |
668 | rxvt_privileges (rxvt_privaction action) |
703 | rxvt_privileges (rxvt_privaction action) |
669 | { |
704 | { |
670 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
671 | static uid_t euid; |
|
|
672 | static gid_t egid; |
|
|
673 | #endif |
|
|
674 | |
|
|
675 | #if ! defined(__CYGWIN32__) |
705 | #if ! defined(__CYGWIN32__) |
676 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
706 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
677 | /* setreuid () is the poor man's setuid (), seteuid () */ |
707 | /* setreuid () is the poor man's setuid (), seteuid () */ |
678 | # define seteuid(a) setreuid(-1, (a)) |
708 | # define seteuid(a) setreuid(-1, (a)) |
679 | # define setegid(a) setregid(-1, (a)) |
709 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
685 | case IGNORE: |
715 | case IGNORE: |
686 | /* |
716 | /* |
687 | * 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 |
688 | * back to root later, as required |
718 | * back to root later, as required |
689 | */ |
719 | */ |
|
|
720 | setegid (getgid ()); |
690 | seteuid (getuid ()); |
721 | seteuid (getuid ()); |
691 | setegid (getgid ()); |
|
|
692 | break; |
722 | break; |
693 | case SAVE: |
723 | case SAVE: |
694 | euid = geteuid (); |
|
|
695 | egid = getegid (); |
724 | saved_egid = getegid (); |
|
|
725 | saved_euid = geteuid (); |
696 | break; |
726 | break; |
697 | case RESTORE: |
727 | case RESTORE: |
698 | seteuid (euid); |
|
|
699 | setegid (egid); |
728 | setegid (saved_egid); |
|
|
729 | seteuid (saved_euid); |
700 | break; |
730 | break; |
701 | } |
731 | } |
702 | # else |
732 | # else |
703 | switch (action) |
733 | switch (action) |
704 | { |
734 | { |
705 | case IGNORE: |
735 | case IGNORE: |
|
|
736 | setgid (getgid ()); |
706 | setuid (getuid ()); |
737 | setuid (getuid ()); |
707 | setgid (getgid ()); |
|
|
708 | /* FALLTHROUGH */ |
738 | /* FALLTHROUGH */ |
709 | case SAVE: |
739 | case SAVE: |
710 | /* FALLTHROUGH */ |
740 | /* FALLTHROUGH */ |
711 | case RESTORE: |
741 | case RESTORE: |
712 | break; |
742 | break; |
… | |
… | |
1428 | unsigned long fg, bg; |
1458 | unsigned long fg, bg; |
1429 | const char *p; |
1459 | const char *p; |
1430 | char **s; |
1460 | char **s; |
1431 | XIMStyles *xim_styles; |
1461 | XIMStyles *xim_styles; |
1432 | |
1462 | |
|
|
1463 | set_environ (envv); |
|
|
1464 | |
1433 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1465 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1434 | return false; |
1466 | return false; |
1435 | |
1467 | |
1436 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1468 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1437 | input_method = display->get_xim (locale, modifiers); |
1469 | input_method = display->get_xim (locale, modifiers); |
… | |
… | |
1602 | int i; |
1634 | int i; |
1603 | const char *p; |
1635 | const char *p; |
1604 | char **s; |
1636 | char **s; |
1605 | char buf[IMBUFSIZ]; |
1637 | char buf[IMBUFSIZ]; |
1606 | |
1638 | |
1607 | SET_R (this); |
1639 | make_current (); |
1608 | |
1640 | |
1609 | im_destroy (); |
1641 | im_destroy (); |
1610 | |
1642 | |
1611 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1643 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1612 | if (Input_Context) |
1644 | if (Input_Context) |