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.176 by root, Thu Jan 12 01:30:53 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}
269 if (parent[0]) 284 if (parent[0])
270 XDestroyWindow (disp, parent[0]); 285 XDestroyWindow (disp, parent[0]);
271 } 286 }
272 287
273 // TODO: free pixcolours, colours should become part of rxvt_display 288 // TODO: free pixcolours, colours should become part of rxvt_display
274
275 delete pix_colors_focused; 289 delete pix_colors_focused;
276#if OFF_FOCUS_FADING 290#if OFF_FOCUS_FADING
277 delete pix_colors_unfocused; 291 delete pix_colors_unfocused;
278#endif 292#endif
279 293
464/*----------------------------------------------------------------------*/ 478/*----------------------------------------------------------------------*/
465bool 479bool
466rxvt_term::init (int argc, const char *const *argv) 480rxvt_term::init (int argc, const char *const *argv)
467{ 481{
468 SET_R (this); 482 SET_R (this);
483 set_environ (envv); // few things in X do not call setlocale :(
469 484
470 set_locale (""); 485 set_locale ("");
471 486
472 if (!init_vars ()) 487 if (!init_vars ())
473 return false; 488 return false;
494 509
495 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) 510 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
496 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) 511 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
497 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 512 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
498 { 513 {
514#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
515 // ignore some perl-related arguments if some bozo installed us set[ug]id
516 if (rxvt_tainted ())
517 {
518 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
519 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
520 {
521 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
522 rs[Rs_perl_lib] = 0;
523 rs[Rs_perl_eval] = 0;
524 }
525 }
526#endif
499 rxvt_perl.init (); 527 rxvt_perl.init ();
528 setlocale (LC_CTYPE, curlocale); // perl init destroys current locale
500 HOOK_INVOKE ((this, HOOK_INIT, DT_END)); 529 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
501 } 530 }
502#endif 531#endif
503 532
504 create_windows (argc, argv); 533 create_windows (argc, argv);
505 534
506 dDisp; 535 dDisp;
507 536
508 init_xlocale (); 537 init_xlocale ();
509 538
510 scr_reset (); /* initialize screen */ 539 scr_reset (); // initialize screen
511 540
512#if 0 541#if 0
513 XSynchronize (disp, True); 542 XSynchronize (disp, True);
514#endif 543#endif
515 544
587 sw_int (this, &sig_handlers::sig_term) 616 sw_int (this, &sig_handlers::sig_term)
588 { 617 {
589 } 618 }
590} sig_handlers; 619} sig_handlers;
591 620
621char **rxvt_environ; // startup environment
622
592void 623void
593rxvt_init () 624rxvt_init ()
594{ 625{
626 rxvt_environ = environ;
627
595 /* 628 /*
596 * Save and then give up any super-user privileges 629 * Save and then give up any super-user privileges
597 * 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.
598 * We should only need to be root in these cases: 631 * We should only need to be root in these cases:
599 * 1. write utmp entries on some systems 632 * 1. write utmp entries on some systems
613 /* signal (SIGURG, SIG_DFL); */ 646 /* signal (SIGURG, SIG_DFL); */
614 647
615 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 648 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
616 // TODO: handle this with exceptions and tolerate the memory loss 649 // TODO: handle this with exceptions and tolerate the memory loss
617 XSetIOErrorHandler (rxvt_xioerror_handler); 650 XSetIOErrorHandler (rxvt_xioerror_handler);
651
652 XrmInitialize ();
618} 653}
619 654
620/* ------------------------------------------------------------------------- * 655/* ------------------------------------------------------------------------- *
621 * MEMORY ALLOCATION WRAPPERS * 656 * MEMORY ALLOCATION WRAPPERS *
622 * ------------------------------------------------------------------------- */ 657 * ------------------------------------------------------------------------- */
658 * ------------------------------------------------------------------------- */ 693 * ------------------------------------------------------------------------- */
659/* take care of suid/sgid super-user (root) privileges */ 694/* take care of suid/sgid super-user (root) privileges */
660void 695void
661rxvt_privileges (rxvt_privaction action) 696rxvt_privileges (rxvt_privaction action)
662{ 697{
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__) 698#if ! defined(__CYGWIN32__)
669# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 699# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
670 /* setreuid () is the poor man's setuid (), seteuid () */ 700 /* setreuid () is the poor man's setuid (), seteuid () */
671# define seteuid(a) setreuid(-1, (a)) 701# define seteuid(a) setreuid(-1, (a))
672# define setegid(a) setregid(-1, (a)) 702# define setegid(a) setregid(-1, (a))
678 case IGNORE: 708 case IGNORE:
679 /* 709 /*
680 * 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
681 * back to root later, as required 711 * back to root later, as required
682 */ 712 */
713 setegid (getgid ());
683 seteuid (getuid ()); 714 seteuid (getuid ());
684 setegid (getgid ());
685 break; 715 break;
686 case SAVE: 716 case SAVE:
687 euid = geteuid ();
688 egid = getegid (); 717 saved_egid = getegid ();
718 saved_euid = geteuid ();
689 break; 719 break;
690 case RESTORE: 720 case RESTORE:
691 seteuid (euid);
692 setegid (egid); 721 setegid (saved_egid);
722 seteuid (saved_euid);
693 break; 723 break;
694 } 724 }
695# else 725# else
696 switch (action) 726 switch (action)
697 { 727 {
698 case IGNORE: 728 case IGNORE:
729 setgid (getgid ());
699 setuid (getuid ()); 730 setuid (getuid ());
700 setgid (getgid ());
701 /* FALLTHROUGH */ 731 /* FALLTHROUGH */
702 case SAVE: 732 case SAVE:
703 /* FALLTHROUGH */ 733 /* FALLTHROUGH */
704 case RESTORE: 734 case RESTORE:
705 break; 735 break;
1421 unsigned long fg, bg; 1451 unsigned long fg, bg;
1422 const char *p; 1452 const char *p;
1423 char **s; 1453 char **s;
1424 XIMStyles *xim_styles; 1454 XIMStyles *xim_styles;
1425 1455
1456 set_environ (envv);
1457
1426 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1458 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1427 return false; 1459 return false;
1428 1460
1429 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1461 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1430 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