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.175 by root, Thu Jan 12 00:35:39 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}
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 ();
472/*----------------------------------------------------------------------*/ 478/*----------------------------------------------------------------------*/
473bool 479bool
474rxvt_term::init (int argc, const char *const *argv) 480rxvt_term::init (int argc, const char *const *argv)
475{ 481{
476 SET_R (this); 482 SET_R (this);
483 TEMP_ENV; // few things in X do not call setlocale :(
477 484
478 set_locale (""); 485 set_locale ("");
479 486
480 if (!init_vars ()) 487 if (!init_vars ())
481 return false; 488 return false;
502 509
503 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) 510 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
504 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) 511 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
505 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 512 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
506 { 513 {
507 bool tainted = false;
508
509#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) 514#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
510 // ignore some perl-related arguments if some bozo installed us set[ug]id 515 // ignore some perl-related arguments if some bozo installed us set[ug]id
511 if (getuid () != saved_euid || getgid () != saved_egid) 516 if (rxvt_tainted ())
512 { 517 {
513 tainted = true;
514
515 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) 518 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
516 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 519 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
517 { 520 {
518 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); 521 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
519 rs[Rs_perl_lib] = 0; 522 rs[Rs_perl_lib] = 0;
520 rs[Rs_perl_eval] = "our $tainted = 1"; 523 rs[Rs_perl_eval] = 0;
521 } 524 }
522 } 525 }
523#endif 526#endif
524 rxvt_perl.init (tainted); 527 rxvt_perl.init ();
528 setlocale (LC_CTYPE, curlocale); // perl init destroys this info
525 HOOK_INVOKE ((this, HOOK_INIT, DT_END)); 529 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
526 } 530 }
527#endif 531#endif
528 532
529 create_windows (argc, argv); 533 create_windows (argc, argv);
530 534
531 dDisp; 535 dDisp;
532 536
533 init_xlocale (); 537 init_xlocale ();
534 538
535 scr_reset (); /* initialize screen */ 539 scr_reset (); // initialize screen
536 540
537#if 0 541#if 0
538 XSynchronize (disp, True); 542 XSynchronize (disp, True);
539#endif 543#endif
540 544
612 sw_int (this, &sig_handlers::sig_term) 616 sw_int (this, &sig_handlers::sig_term)
613 { 617 {
614 } 618 }
615} sig_handlers; 619} sig_handlers;
616 620
621char **rxvt_environ; // startup environment
622
617void 623void
618rxvt_init () 624rxvt_init ()
619{ 625{
626 rxvt_environ = environ;
627
620 /* 628 /*
621 * Save and then give up any super-user privileges 629 * Save and then give up any super-user privileges
622 * 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.
623 * We should only need to be root in these cases: 631 * We should only need to be root in these cases:
624 * 1. write utmp entries on some systems 632 * 1. write utmp entries on some systems
639 647
640 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 648 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
641 // TODO: handle this with exceptions and tolerate the memory loss 649 // TODO: handle this with exceptions and tolerate the memory loss
642 XSetIOErrorHandler (rxvt_xioerror_handler); 650 XSetIOErrorHandler (rxvt_xioerror_handler);
643 651
644#ifdef USE_XGETDEFAULT
645 XrmInitialize (); 652 XrmInitialize ();
646#endif
647} 653}
648 654
649/* ------------------------------------------------------------------------- * 655/* ------------------------------------------------------------------------- *
650 * MEMORY ALLOCATION WRAPPERS * 656 * MEMORY ALLOCATION WRAPPERS *
651 * ------------------------------------------------------------------------- */ 657 * ------------------------------------------------------------------------- */
702 case IGNORE: 708 case IGNORE:
703 /* 709 /*
704 * 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
705 * back to root later, as required 711 * back to root later, as required
706 */ 712 */
713 setegid (getgid ());
707 seteuid (getuid ()); 714 seteuid (getuid ());
708 setegid (getgid ());
709 break; 715 break;
710 case SAVE: 716 case SAVE:
717 saved_egid = getegid ();
711 saved_euid = geteuid (); 718 saved_euid = geteuid ();
712 saved_egid = getegid ();
713 break; 719 break;
714 case RESTORE: 720 case RESTORE:
721 setegid (saved_egid);
715 seteuid (saved_euid); 722 seteuid (saved_euid);
716 setegid (saved_egid);
717 break; 723 break;
718 } 724 }
719# else 725# else
720 switch (action) 726 switch (action)
721 { 727 {
722 case IGNORE: 728 case IGNORE:
729 setgid (getgid ());
723 setuid (getuid ()); 730 setuid (getuid ());
724 setgid (getgid ());
725 /* FALLTHROUGH */ 731 /* FALLTHROUGH */
726 case SAVE: 732 case SAVE:
727 /* FALLTHROUGH */ 733 /* FALLTHROUGH */
728 case RESTORE: 734 case RESTORE:
729 break; 735 break;
1445 unsigned long fg, bg; 1451 unsigned long fg, bg;
1446 const char *p; 1452 const char *p;
1447 char **s; 1453 char **s;
1448 XIMStyles *xim_styles; 1454 XIMStyles *xim_styles;
1449 1455
1456 TEMP_ENV;
1457
1450 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1458 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1451 return false; 1459 return false;
1452 1460
1453 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1461 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1454 input_method = display->get_xim (locale, modifiers); 1462 input_method = display->get_xim (locale, modifiers);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines