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.165 by root, Sun Jan 8 00:20:12 2006 UTC vs.
Revision 1.177 by root, Mon Jan 16 06:37:52 2006 UTC

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__)
52static uid_t saved_euid;
53static gid_t saved_egid;
54#endif
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
51vector<rxvt_term *> rxvt_term::termlist; 66vector<rxvt_term *> rxvt_term::termlist;
52 67
53static char curlocale[128], savelocale[128]; 68static char curlocale[128], savelocale[128];
54 69
55bool 70bool
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
66bool 81void
67rxvt_push_locale (const char *locale) 82rxvt_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
73void 88void
74rxvt_pop_locale () 89rxvt_pop_locale ()
75{ 90{
76 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);
77} 100}
78 101
79#if ENABLE_COMBINING 102#if ENABLE_COMBINING
80class rxvt_composite_vec rxvt_composite; 103class 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 300#endif
279 301
363} 385}
364 386
365void 387void
366rxvt_term::destroy_cb (time_watcher &w) 388rxvt_term::destroy_cb (time_watcher &w)
367{ 389{
368 SET_R (this); 390 make_current ();
369 391
370 delete this; 392 delete this;
371} 393}
372 394
373/*----------------------------------------------------------------------*/ 395/*----------------------------------------------------------------------*/
464/*----------------------------------------------------------------------*/ 486/*----------------------------------------------------------------------*/
465bool 487bool
466rxvt_term::init (int argc, const char *const *argv) 488rxvt_term::init (int argc, const char *const *argv)
467{ 489{
468 SET_R (this); 490 SET_R (this);
469
470 set_locale (""); 491 set_locale ("");
492 set_environ (envv); // few things in X do not call setlocale :(
471 493
472 if (!init_vars ()) 494 if (!init_vars ())
473 return false; 495 return false;
474 496
475 init_secondary (); 497 init_secondary ();
494 516
495 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) 517 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
496 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) 518 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
497 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 519 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
498 { 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
499 rxvt_perl.init (); 534 rxvt_perl.init ();
535 setlocale (LC_CTYPE, curlocale); // perl init destroys current locale
500 HOOK_INVOKE ((this, HOOK_INIT, DT_END)); 536 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
501 } 537 }
502#endif 538#endif
503 539
504 create_windows (argc, argv); 540 create_windows (argc, argv);
505 541
506 dDisp; 542 dDisp;
507 543
508 init_xlocale (); 544 init_xlocale ();
509 545
510 scr_reset (); /* initialize screen */ 546 scr_reset (); // initialize screen
511 547
512#if 0 548#if 0
513 XSynchronize (disp, True); 549 XSynchronize (disp, True);
514#endif 550#endif
515 551
587 sw_int (this, &sig_handlers::sig_term) 623 sw_int (this, &sig_handlers::sig_term)
588 { 624 {
589 } 625 }
590} sig_handlers; 626} sig_handlers;
591 627
628char **rxvt_environ; // startup environment
629
592void 630void
593rxvt_init () 631rxvt_init ()
594{ 632{
633 rxvt_environ = environ;
634
595 /* 635 /*
596 * Save and then give up any super-user privileges 636 * Save and then give up any super-user privileges
597 * 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.
598 * We should only need to be root in these cases: 638 * We should only need to be root in these cases:
599 * 1. write utmp entries on some systems 639 * 1. write utmp entries on some systems
613 /* signal (SIGURG, SIG_DFL); */ 653 /* signal (SIGURG, SIG_DFL); */
614 654
615 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 655 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
616 // TODO: handle this with exceptions and tolerate the memory loss 656 // TODO: handle this with exceptions and tolerate the memory loss
617 XSetIOErrorHandler (rxvt_xioerror_handler); 657 XSetIOErrorHandler (rxvt_xioerror_handler);
658
659 XrmInitialize ();
618} 660}
619 661
620/* ------------------------------------------------------------------------- * 662/* ------------------------------------------------------------------------- *
621 * MEMORY ALLOCATION WRAPPERS * 663 * MEMORY ALLOCATION WRAPPERS *
622 * ------------------------------------------------------------------------- */ 664 * ------------------------------------------------------------------------- */
658 * ------------------------------------------------------------------------- */ 700 * ------------------------------------------------------------------------- */
659/* take care of suid/sgid super-user (root) privileges */ 701/* take care of suid/sgid super-user (root) privileges */
660void 702void
661rxvt_privileges (rxvt_privaction action) 703rxvt_privileges (rxvt_privaction action)
662{ 704{
663#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
664 static uid_t euid;
665 static gid_t egid;
666#endif
667
668#if ! defined(__CYGWIN32__) 705#if ! defined(__CYGWIN32__)
669# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 706# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
670 /* setreuid () is the poor man's setuid (), seteuid () */ 707 /* setreuid () is the poor man's setuid (), seteuid () */
671# define seteuid(a) setreuid(-1, (a)) 708# define seteuid(a) setreuid(-1, (a))
672# define setegid(a) setregid(-1, (a)) 709# define setegid(a) setregid(-1, (a))
678 case IGNORE: 715 case IGNORE:
679 /* 716 /*
680 * 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
681 * back to root later, as required 718 * back to root later, as required
682 */ 719 */
720 setegid (getgid ());
683 seteuid (getuid ()); 721 seteuid (getuid ());
684 setegid (getgid ());
685 break; 722 break;
686 case SAVE: 723 case SAVE:
687 euid = geteuid ();
688 egid = getegid (); 724 saved_egid = getegid ();
725 saved_euid = geteuid ();
689 break; 726 break;
690 case RESTORE: 727 case RESTORE:
691 seteuid (euid);
692 setegid (egid); 728 setegid (saved_egid);
729 seteuid (saved_euid);
693 break; 730 break;
694 } 731 }
695# else 732# else
696 switch (action) 733 switch (action)
697 { 734 {
698 case IGNORE: 735 case IGNORE:
736 setgid (getgid ());
699 setuid (getuid ()); 737 setuid (getuid ());
700 setgid (getgid ());
701 /* FALLTHROUGH */ 738 /* FALLTHROUGH */
702 case SAVE: 739 case SAVE:
703 /* FALLTHROUGH */ 740 /* FALLTHROUGH */
704 case RESTORE: 741 case RESTORE:
705 break; 742 break;
1421 unsigned long fg, bg; 1458 unsigned long fg, bg;
1422 const char *p; 1459 const char *p;
1423 char **s; 1460 char **s;
1424 XIMStyles *xim_styles; 1461 XIMStyles *xim_styles;
1425 1462
1463 set_environ (envv);
1464
1426 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1465 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1427 return false; 1466 return false;
1428 1467
1429 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1468 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1430 input_method = display->get_xim (locale, modifiers); 1469 input_method = display->get_xim (locale, modifiers);
1595 int i; 1634 int i;
1596 const char *p; 1635 const char *p;
1597 char **s; 1636 char **s;
1598 char buf[IMBUFSIZ]; 1637 char buf[IMBUFSIZ];
1599 1638
1600 SET_R (this); 1639 make_current ();
1601 1640
1602 im_destroy (); 1641 im_destroy ();
1603 1642
1604 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1643 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1605 if (Input_Context) 1644 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines