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.179 by root, Mon Jan 16 08:48:09 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 ();
371} 377}
372 378
373void 379void
374rxvt_term::destroy_cb (time_watcher &w) 380rxvt_term::destroy_cb (time_watcher &w)
375{ 381{
376 SET_R (this); 382 make_current ();
377 383
378 delete this; 384 delete this;
379} 385}
380 386
381/*----------------------------------------------------------------------*/ 387/*----------------------------------------------------------------------*/
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);
477
478 set_locale (""); 483 set_locale ("");
484 set_environ (envv); // few things in X do not call setlocale :(
479 485
480 if (!init_vars ()) 486 if (!init_vars ())
481 return false; 487 return false;
482 488
483 init_secondary (); 489 init_secondary ();
502 508
503 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) 509 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
504 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) 510 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
505 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 511 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
506 { 512 {
507 bool tainted = false;
508
509#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) 513#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
510 // ignore some perl-related arguments if some bozo installed us set[ug]id 514 // ignore some perl-related arguments if some bozo installed us set[ug]id
511 if (getuid () != saved_euid || getgid () != saved_egid) 515 if (rxvt_tainted ())
512 { 516 {
513 tainted = true;
514
515 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) 517 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
516 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 518 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
517 { 519 {
518 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); 520 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
519 rs[Rs_perl_lib] = 0; 521 rs[Rs_perl_lib] = 0;
520 rs[Rs_perl_eval] = "our $tainted = 1"; 522 rs[Rs_perl_eval] = 0;
521 } 523 }
522 } 524 }
523#endif 525#endif
524 rxvt_perl.init (tainted); 526 rxvt_perl.init (this);
525 HOOK_INVOKE ((this, HOOK_INIT, DT_END)); 527 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
526 } 528 }
527#endif 529#endif
528 530
529 create_windows (argc, argv); 531 create_windows (argc, argv);
530 532
531 dDisp; 533 dDisp;
532 534
533 init_xlocale (); 535 init_xlocale ();
534 536
535 scr_reset (); /* initialize screen */ 537 scr_reset (); // initialize screen
536 538
537#if 0 539#if 0
538 XSynchronize (disp, True); 540 XSynchronize (disp, True);
539#endif 541#endif
540 542
612 sw_int (this, &sig_handlers::sig_term) 614 sw_int (this, &sig_handlers::sig_term)
613 { 615 {
614 } 616 }
615} sig_handlers; 617} sig_handlers;
616 618
619char **rxvt_environ; // startup environment
620
617void 621void
618rxvt_init () 622rxvt_init ()
619{ 623{
624 rxvt_environ = environ;
625
620 /* 626 /*
621 * Save and then give up any super-user privileges 627 * Save and then give up any super-user privileges
622 * If we need privileges in any area then we must specifically request it. 628 * If we need privileges in any area then we must specifically request it.
623 * We should only need to be root in these cases: 629 * We should only need to be root in these cases:
624 * 1. write utmp entries on some systems 630 * 1. write utmp entries on some systems
639 645
640 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 646 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
641 // TODO: handle this with exceptions and tolerate the memory loss 647 // TODO: handle this with exceptions and tolerate the memory loss
642 XSetIOErrorHandler (rxvt_xioerror_handler); 648 XSetIOErrorHandler (rxvt_xioerror_handler);
643 649
644#ifdef USE_XGETDEFAULT
645 XrmInitialize (); 650 XrmInitialize ();
646#endif
647} 651}
648 652
649/* ------------------------------------------------------------------------- * 653/* ------------------------------------------------------------------------- *
650 * MEMORY ALLOCATION WRAPPERS * 654 * MEMORY ALLOCATION WRAPPERS *
651 * ------------------------------------------------------------------------- */ 655 * ------------------------------------------------------------------------- */
702 case IGNORE: 706 case IGNORE:
703 /* 707 /*
704 * change effective uid/gid - not real uid/gid - so we can switch 708 * change effective uid/gid - not real uid/gid - so we can switch
705 * back to root later, as required 709 * back to root later, as required
706 */ 710 */
711 setegid (getgid ());
707 seteuid (getuid ()); 712 seteuid (getuid ());
708 setegid (getgid ());
709 break; 713 break;
710 case SAVE: 714 case SAVE:
715 saved_egid = getegid ();
711 saved_euid = geteuid (); 716 saved_euid = geteuid ();
712 saved_egid = getegid ();
713 break; 717 break;
714 case RESTORE: 718 case RESTORE:
719 setegid (saved_egid);
715 seteuid (saved_euid); 720 seteuid (saved_euid);
716 setegid (saved_egid);
717 break; 721 break;
718 } 722 }
719# else 723# else
720 switch (action) 724 switch (action)
721 { 725 {
722 case IGNORE: 726 case IGNORE:
727 setgid (getgid ());
723 setuid (getuid ()); 728 setuid (getuid ());
724 setgid (getgid ());
725 /* FALLTHROUGH */ 729 /* FALLTHROUGH */
726 case SAVE: 730 case SAVE:
727 /* FALLTHROUGH */ 731 /* FALLTHROUGH */
728 case RESTORE: 732 case RESTORE:
729 break; 733 break;
1445 unsigned long fg, bg; 1449 unsigned long fg, bg;
1446 const char *p; 1450 const char *p;
1447 char **s; 1451 char **s;
1448 XIMStyles *xim_styles; 1452 XIMStyles *xim_styles;
1449 1453
1454 set_environ (envv);
1455
1450 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1456 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1451 return false; 1457 return false;
1452 1458
1453 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1459 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1454 input_method = display->get_xim (locale, modifiers); 1460 input_method = display->get_xim (locale, modifiers);
1619 int i; 1625 int i;
1620 const char *p; 1626 const char *p;
1621 char **s; 1627 char **s;
1622 char buf[IMBUFSIZ]; 1628 char buf[IMBUFSIZ];
1623 1629
1624 SET_R (this); 1630 make_current ();
1625 1631
1626 im_destroy (); 1632 im_destroy ();
1627 1633
1628 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1634 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1629 if (Input_Context) 1635 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines