ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/main.C
(Generate patch)

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.167 by root, Sun Jan 8 08:43:11 2006 UTC vs.
Revision 1.177 by root, Mon Jan 16 06:37:52 2006 UTC

51#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) 51#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
52static uid_t saved_euid; 52static uid_t saved_euid;
53static gid_t saved_egid; 53static gid_t saved_egid;
54#endif 54#endif
55 55
56bool
57rxvt_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
56vector<rxvt_term *> rxvt_term::termlist; 66vector<rxvt_term *> rxvt_term::termlist;
57 67
58static char curlocale[128], savelocale[128]; 68static char curlocale[128], savelocale[128];
59 69
60bool 70bool
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
71bool 81void
72rxvt_push_locale (const char *locale) 82rxvt_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}
77 87
78void 88void
79rxvt_pop_locale () 89rxvt_pop_locale ()
80{ 90{
81 rxvt_set_locale (savelocale); 91 rxvt_set_locale (savelocale);
92}
93
94void
95rxvt_term::make_current () const
96{
97 SET_R (this);
98 rxvt_set_locale (locale);
99 set_environ (envv);
82} 100}
83 101
84#if ENABLE_COMBINING 102#if ENABLE_COMBINING
85class rxvt_composite_vec rxvt_composite; 103class rxvt_composite_vec rxvt_composite;
86 104
274 if (parent[0]) 292 if (parent[0])
275 XDestroyWindow (disp, parent[0]); 293 XDestroyWindow (disp, parent[0]);
276 } 294 }
277 295
278 // TODO: free pixcolours, colours should become part of rxvt_display 296 // TODO: free pixcolours, colours should become part of rxvt_display
279
280 delete pix_colors_focused; 297 delete pix_colors_focused;
281#if OFF_FOCUS_FADING 298#if OFF_FOCUS_FADING
282 delete pix_colors_unfocused; 299 delete pix_colors_unfocused;
283#endif
284#if USE_XGETDEFAULT
285 XrmDestroyDatabase (xrmdatabase);
286#endif 300#endif
287 301
288 displays.put (display); 302 displays.put (display);
289 303
290 scr_release (); 304 scr_release ();
371} 385}
372 386
373void 387void
374rxvt_term::destroy_cb (time_watcher &w) 388rxvt_term::destroy_cb (time_watcher &w)
375{ 389{
376 SET_R (this); 390 make_current ();
377 391
378 delete this; 392 delete this;
379} 393}
380 394
381/*----------------------------------------------------------------------*/ 395/*----------------------------------------------------------------------*/
472/*----------------------------------------------------------------------*/ 486/*----------------------------------------------------------------------*/
473bool 487bool
474rxvt_term::init (int argc, const char *const *argv) 488rxvt_term::init (int argc, const char *const *argv)
475{ 489{
476 SET_R (this); 490 SET_R (this);
477
478 set_locale (""); 491 set_locale ("");
492 set_environ (envv); // few things in X do not call setlocale :(
479 493
480 if (!init_vars ()) 494 if (!init_vars ())
481 return false; 495 return false;
482 496
483 init_secondary (); 497 init_secondary ();
502 516
503 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) 517 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
504 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) 518 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
505 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 519 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
506 { 520 {
507 bool tainted = false;
508
509#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) 521#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
510 // ignore some perl-related arguments if some bozo installed us set[ug]id 522 // ignore some perl-related arguments if some bozo installed us set[ug]id
511 if (getuid () != saved_euid || getgid () != saved_egid) 523 if (rxvt_tainted ())
512 { 524 {
513 tainted = true;
514
515 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) 525 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
516 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 526 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
517 { 527 {
518 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); 528 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
519 rs[Rs_perl_lib] = 0; 529 rs[Rs_perl_lib] = 0;
520 rs[Rs_perl_eval] = "our $tainted = 1"; 530 rs[Rs_perl_eval] = 0;
521 } 531 }
522 } 532 }
523#endif 533#endif
524 rxvt_perl.init (tainted); 534 rxvt_perl.init ();
535 setlocale (LC_CTYPE, curlocale); // perl init destroys current locale
525 HOOK_INVOKE ((this, HOOK_INIT, DT_END)); 536 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
526 } 537 }
527#endif 538#endif
528 539
529 create_windows (argc, argv); 540 create_windows (argc, argv);
530 541
531 dDisp; 542 dDisp;
532 543
533 init_xlocale (); 544 init_xlocale ();
534 545
535 scr_reset (); /* initialize screen */ 546 scr_reset (); // initialize screen
536 547
537#if 0 548#if 0
538 XSynchronize (disp, True); 549 XSynchronize (disp, True);
539#endif 550#endif
540 551
612 sw_int (this, &sig_handlers::sig_term) 623 sw_int (this, &sig_handlers::sig_term)
613 { 624 {
614 } 625 }
615} sig_handlers; 626} sig_handlers;
616 627
628char **rxvt_environ; // startup environment
629
617void 630void
618rxvt_init () 631rxvt_init ()
619{ 632{
633 rxvt_environ = environ;
634
620 /* 635 /*
621 * Save and then give up any super-user privileges 636 * Save and then give up any super-user privileges
622 * 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.
623 * We should only need to be root in these cases: 638 * We should only need to be root in these cases:
624 * 1. write utmp entries on some systems 639 * 1. write utmp entries on some systems
639 654
640 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 655 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
641 // TODO: handle this with exceptions and tolerate the memory loss 656 // TODO: handle this with exceptions and tolerate the memory loss
642 XSetIOErrorHandler (rxvt_xioerror_handler); 657 XSetIOErrorHandler (rxvt_xioerror_handler);
643 658
644#ifdef USE_XGETDEFAULT
645 XrmInitialize (); 659 XrmInitialize ();
646#endif
647} 660}
648 661
649/* ------------------------------------------------------------------------- * 662/* ------------------------------------------------------------------------- *
650 * MEMORY ALLOCATION WRAPPERS * 663 * MEMORY ALLOCATION WRAPPERS *
651 * ------------------------------------------------------------------------- */ 664 * ------------------------------------------------------------------------- */
702 case IGNORE: 715 case IGNORE:
703 /* 716 /*
704 * 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
705 * back to root later, as required 718 * back to root later, as required
706 */ 719 */
720 setegid (getgid ());
707 seteuid (getuid ()); 721 seteuid (getuid ());
708 setegid (getgid ());
709 break; 722 break;
710 case SAVE: 723 case SAVE:
724 saved_egid = getegid ();
711 saved_euid = geteuid (); 725 saved_euid = geteuid ();
712 saved_egid = getegid ();
713 break; 726 break;
714 case RESTORE: 727 case RESTORE:
728 setegid (saved_egid);
715 seteuid (saved_euid); 729 seteuid (saved_euid);
716 setegid (saved_egid);
717 break; 730 break;
718 } 731 }
719# else 732# else
720 switch (action) 733 switch (action)
721 { 734 {
722 case IGNORE: 735 case IGNORE:
736 setgid (getgid ());
723 setuid (getuid ()); 737 setuid (getuid ());
724 setgid (getgid ());
725 /* FALLTHROUGH */ 738 /* FALLTHROUGH */
726 case SAVE: 739 case SAVE:
727 /* FALLTHROUGH */ 740 /* FALLTHROUGH */
728 case RESTORE: 741 case RESTORE:
729 break; 742 break;
1445 unsigned long fg, bg; 1458 unsigned long fg, bg;
1446 const char *p; 1459 const char *p;
1447 char **s; 1460 char **s;
1448 XIMStyles *xim_styles; 1461 XIMStyles *xim_styles;
1449 1462
1463 set_environ (envv);
1464
1450 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1465 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1451 return false; 1466 return false;
1452 1467
1453 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1468 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1454 input_method = display->get_xim (locale, modifiers); 1469 input_method = display->get_xim (locale, modifiers);
1619 int i; 1634 int i;
1620 const char *p; 1635 const char *p;
1621 char **s; 1636 char **s;
1622 char buf[IMBUFSIZ]; 1637 char buf[IMBUFSIZ];
1623 1638
1624 SET_R (this); 1639 make_current ();
1625 1640
1626 im_destroy (); 1641 im_destroy ();
1627 1642
1628 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1643 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1629 if (Input_Context) 1644 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines