… | |
… | |
51 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
51 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
52 | static uid_t saved_euid; |
52 | static uid_t saved_euid; |
53 | static gid_t saved_egid; |
53 | static gid_t saved_egid; |
54 | #endif |
54 | #endif |
55 | |
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 | |
56 | vector<rxvt_term *> rxvt_term::termlist; |
66 | vector<rxvt_term *> rxvt_term::termlist; |
57 | |
67 | |
58 | static char curlocale[128], savelocale[128]; |
68 | static char curlocale[128], savelocale[128]; |
59 | |
69 | |
60 | bool |
70 | bool |
… | |
… | |
66 | strncpy (curlocale, locale, 128); |
76 | strncpy (curlocale, locale, 128); |
67 | setlocale (LC_CTYPE, curlocale); |
77 | setlocale (LC_CTYPE, curlocale); |
68 | return true; |
78 | return true; |
69 | } |
79 | } |
70 | |
80 | |
71 | bool |
81 | void |
72 | rxvt_push_locale (const char *locale) |
82 | rxvt_push_locale (const char *locale) |
73 | { |
83 | { |
74 | strcpy (savelocale, curlocale); |
84 | strcpy (savelocale, curlocale); |
75 | rxvt_set_locale (locale); |
85 | rxvt_set_locale (locale); |
76 | } |
86 | } |
… | |
… | |
274 | if (parent[0]) |
284 | if (parent[0]) |
275 | XDestroyWindow (disp, parent[0]); |
285 | XDestroyWindow (disp, parent[0]); |
276 | } |
286 | } |
277 | |
287 | |
278 | // TODO: free pixcolours, colours should become part of rxvt_display |
288 | // TODO: free pixcolours, colours should become part of rxvt_display |
279 | |
|
|
280 | delete pix_colors_focused; |
289 | delete pix_colors_focused; |
281 | #if OFF_FOCUS_FADING |
290 | #if OFF_FOCUS_FADING |
282 | delete pix_colors_unfocused; |
291 | delete pix_colors_unfocused; |
283 | #endif |
|
|
284 | #if USE_XGETDEFAULT |
|
|
285 | XrmDestroyDatabase (xrmdatabase); |
|
|
286 | #endif |
292 | #endif |
287 | |
293 | |
288 | displays.put (display); |
294 | displays.put (display); |
289 | |
295 | |
290 | scr_release (); |
296 | scr_release (); |
… | |
… | |
473 | bool |
479 | bool |
474 | rxvt_term::init (int argc, const char *const *argv) |
480 | rxvt_term::init (int argc, const char *const *argv) |
475 | { |
481 | { |
476 | SET_R (this); |
482 | SET_R (this); |
477 | |
483 | |
|
|
484 | const char **cmd_argv; |
|
|
485 | |
|
|
486 | { |
|
|
487 | TEMP_ENV; // few things in X do not call setlocale :( |
|
|
488 | |
478 | set_locale (""); |
489 | set_locale (""); |
479 | |
490 | |
480 | if (!init_vars ()) |
491 | if (!init_vars ()) |
481 | return false; |
492 | return false; |
482 | |
493 | |
483 | init_secondary (); |
494 | init_secondary (); |
484 | |
495 | |
485 | const char **cmd_argv = init_resources (argc, argv); |
496 | cmd_argv = init_resources (argc, argv); |
486 | |
497 | |
487 | #ifdef KEYSYM_RESOURCE |
498 | #ifdef KEYSYM_RESOURCE |
488 | keyboard->register_done (); |
499 | keyboard->register_done (); |
489 | #endif |
500 | #endif |
490 | |
501 | |
491 | #if MENUBAR_MAX |
502 | #if MENUBAR_MAX |
492 | menubar_read (rs[Rs_menu]); |
503 | menubar_read (rs[Rs_menu]); |
493 | #endif |
504 | #endif |
494 | #ifdef HAVE_SCROLLBARS |
505 | #ifdef HAVE_SCROLLBARS |
495 | if (OPTION (Opt_scrollBar)) |
506 | if (OPTION (Opt_scrollBar)) |
496 | scrollBar.setIdle (); /* set existence for size calculations */ |
507 | scrollBar.setIdle (); /* set existence for size calculations */ |
497 | #endif |
508 | #endif |
|
|
509 | } |
498 | |
510 | |
499 | #if ENABLE_PERL |
511 | #if ENABLE_PERL |
500 | if (!rs[Rs_perl_ext_1]) |
512 | if (!rs[Rs_perl_ext_1]) |
501 | rs[Rs_perl_ext_1] = "default"; |
513 | rs[Rs_perl_ext_1] = "default"; |
502 | |
514 | |
503 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
515 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
504 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
516 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
505 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
517 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
506 | { |
518 | { |
507 | bool tainted = false; |
|
|
508 | |
|
|
509 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
519 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
510 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
520 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
511 | if (getuid () != saved_euid || getgid () != saved_egid) |
521 | if (rxvt_tainted ()) |
512 | { |
522 | { |
513 | tainted = true; |
|
|
514 | |
|
|
515 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
523 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
516 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
524 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
517 | { |
525 | { |
518 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
526 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
519 | rs[Rs_perl_lib] = 0; |
527 | rs[Rs_perl_lib] = 0; |
520 | rs[Rs_perl_eval] = "our $tainted = 1"; |
528 | rs[Rs_perl_eval] = 0; |
521 | } |
529 | } |
522 | } |
530 | } |
523 | #endif |
531 | #endif |
524 | rxvt_perl.init (tainted); |
532 | rxvt_perl.init (); |
|
|
533 | setlocale (LC_CTYPE, curlocale); // perl destroys this info |
525 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
534 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
526 | } |
535 | } |
527 | #endif |
536 | #endif |
528 | |
537 | |
|
|
538 | { |
|
|
539 | TEMP_ENV; |
|
|
540 | |
529 | create_windows (argc, argv); |
541 | create_windows (argc, argv); |
530 | |
542 | |
531 | dDisp; |
543 | dDisp; |
532 | |
544 | |
533 | init_xlocale (); |
545 | init_xlocale (); |
534 | |
546 | |
535 | scr_reset (); /* initialize screen */ |
547 | scr_reset (); // initialize screen |
536 | |
548 | |
537 | #if 0 |
549 | #if 0 |
538 | XSynchronize (disp, True); |
550 | XSynchronize (disp, True); |
539 | #endif |
551 | #endif |
540 | |
552 | |
541 | #ifdef HAVE_SCROLLBARS |
553 | #ifdef HAVE_SCROLLBARS |
542 | if (OPTION (Opt_scrollBar)) |
554 | if (OPTION (Opt_scrollBar)) |
543 | resize_scrollbar (); /* create and map scrollbar */ |
555 | resize_scrollbar (); /* create and map scrollbar */ |
544 | #endif |
556 | #endif |
545 | #if (MENUBAR_MAX) |
557 | #if (MENUBAR_MAX) |
546 | if (menubar_visible ()) |
558 | if (menubar_visible ()) |
547 | XMapWindow (disp, menuBar.win); |
559 | XMapWindow (disp, menuBar.win); |
548 | #endif |
560 | #endif |
549 | #ifdef TRANSPARENT |
561 | #ifdef TRANSPARENT |
550 | if (OPTION (Opt_transparent)) |
562 | if (OPTION (Opt_transparent)) |
551 | { |
563 | { |
552 | XSelectInput (disp, display->root, PropertyChangeMask); |
564 | XSelectInput (disp, display->root, PropertyChangeMask); |
553 | check_our_parents (); |
565 | check_our_parents (); |
554 | rootwin_ev.start (display, display->root); |
566 | rootwin_ev.start (display, display->root); |
555 | } |
567 | } |
556 | #endif |
568 | #endif |
557 | |
569 | |
558 | XMapWindow (disp, vt); |
570 | XMapWindow (disp, vt); |
559 | XMapWindow (disp, parent[0]); |
571 | XMapWindow (disp, parent[0]); |
560 | |
572 | |
561 | set_colorfgbg (); |
573 | set_colorfgbg (); |
562 | |
574 | |
563 | init_command (cmd_argv); |
575 | init_command (cmd_argv); |
564 | |
576 | |
565 | free (cmd_argv); |
577 | free (cmd_argv); |
566 | |
578 | |
567 | if (pty.pty >= 0) |
579 | if (pty.pty >= 0) |
568 | pty_ev.start (pty.pty, EVENT_READ); |
580 | pty_ev.start (pty.pty, EVENT_READ); |
569 | |
581 | |
570 | check_ev.start (); |
582 | check_ev.start (); |
571 | |
583 | |
572 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
584 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
|
|
585 | } |
573 | |
586 | |
574 | return true; |
587 | return true; |
575 | } |
588 | } |
576 | |
589 | |
577 | static struct sig_handlers |
590 | static struct sig_handlers |
… | |
… | |
639 | |
652 | |
640 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
653 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
641 | // TODO: handle this with exceptions and tolerate the memory loss |
654 | // TODO: handle this with exceptions and tolerate the memory loss |
642 | XSetIOErrorHandler (rxvt_xioerror_handler); |
655 | XSetIOErrorHandler (rxvt_xioerror_handler); |
643 | |
656 | |
644 | #ifdef USE_XGETDEFAULT |
|
|
645 | XrmInitialize (); |
657 | XrmInitialize (); |
646 | #endif |
|
|
647 | } |
658 | } |
648 | |
659 | |
649 | /* ------------------------------------------------------------------------- * |
660 | /* ------------------------------------------------------------------------- * |
650 | * MEMORY ALLOCATION WRAPPERS * |
661 | * MEMORY ALLOCATION WRAPPERS * |
651 | * ------------------------------------------------------------------------- */ |
662 | * ------------------------------------------------------------------------- */ |
… | |
… | |
702 | case IGNORE: |
713 | case IGNORE: |
703 | /* |
714 | /* |
704 | * change effective uid/gid - not real uid/gid - so we can switch |
715 | * change effective uid/gid - not real uid/gid - so we can switch |
705 | * back to root later, as required |
716 | * back to root later, as required |
706 | */ |
717 | */ |
|
|
718 | setegid (getgid ()); |
707 | seteuid (getuid ()); |
719 | seteuid (getuid ()); |
708 | setegid (getgid ()); |
|
|
709 | break; |
720 | break; |
710 | case SAVE: |
721 | case SAVE: |
|
|
722 | saved_egid = getegid (); |
711 | saved_euid = geteuid (); |
723 | saved_euid = geteuid (); |
712 | saved_egid = getegid (); |
|
|
713 | break; |
724 | break; |
714 | case RESTORE: |
725 | case RESTORE: |
|
|
726 | setegid (saved_egid); |
715 | seteuid (saved_euid); |
727 | seteuid (saved_euid); |
716 | setegid (saved_egid); |
|
|
717 | break; |
728 | break; |
718 | } |
729 | } |
719 | # else |
730 | # else |
720 | switch (action) |
731 | switch (action) |
721 | { |
732 | { |
722 | case IGNORE: |
733 | case IGNORE: |
|
|
734 | setgid (getgid ()); |
723 | setuid (getuid ()); |
735 | setuid (getuid ()); |
724 | setgid (getgid ()); |
|
|
725 | /* FALLTHROUGH */ |
736 | /* FALLTHROUGH */ |
726 | case SAVE: |
737 | case SAVE: |
727 | /* FALLTHROUGH */ |
738 | /* FALLTHROUGH */ |
728 | case RESTORE: |
739 | case RESTORE: |
729 | break; |
740 | break; |
… | |
… | |
1445 | unsigned long fg, bg; |
1456 | unsigned long fg, bg; |
1446 | const char *p; |
1457 | const char *p; |
1447 | char **s; |
1458 | char **s; |
1448 | XIMStyles *xim_styles; |
1459 | XIMStyles *xim_styles; |
1449 | |
1460 | |
|
|
1461 | TEMP_ENV; |
|
|
1462 | |
1450 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1463 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1451 | return false; |
1464 | return false; |
1452 | |
1465 | |
1453 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1466 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1454 | input_method = display->get_xim (locale, modifiers); |
1467 | input_method = display->get_xim (locale, modifiers); |