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.164 by root, Fri Jan 6 05:37:59 2006 UTC vs.
Revision 1.178 by root, Mon Jan 16 08:29:57 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
363} 377}
364 378
365void 379void
366rxvt_term::destroy_cb (time_watcher &w) 380rxvt_term::destroy_cb (time_watcher &w)
367{ 381{
368 SET_R (this); 382 make_current ();
369 383
370 delete this; 384 delete this;
371} 385}
372 386
373/*----------------------------------------------------------------------*/ 387/*----------------------------------------------------------------------*/
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);
469
470 set_locale (""); 483 set_locale ("");
484 set_environ (envv); // few things in X do not call setlocale :(
471 485
472 if (!init_vars ()) 486 if (!init_vars ())
473 return false; 487 return false;
474 488
475 init_secondary (); 489 init_secondary ();
487 if (OPTION (Opt_scrollBar)) 501 if (OPTION (Opt_scrollBar))
488 scrollBar.setIdle (); /* set existence for size calculations */ 502 scrollBar.setIdle (); /* set existence for size calculations */
489#endif 503#endif
490 504
491#if ENABLE_PERL 505#if ENABLE_PERL
506 if (!rs[Rs_perl_ext_1])
507 rs[Rs_perl_ext_1] = "default";
508
492 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) 509 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
493 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) 510 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
494 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 511 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
495 { 512 {
513#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
514 // ignore some perl-related arguments if some bozo installed us set[ug]id
515 if (rxvt_tainted ())
516 {
517 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
518 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
519 {
520 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
521 rs[Rs_perl_lib] = 0;
522 rs[Rs_perl_eval] = 0;
523 }
524 }
525#endif
496 rxvt_perl.init (); 526 rxvt_perl.init ();
527 setlocale (LC_CTYPE, curlocale); // perl init destroys current locale
497 HOOK_INVOKE ((this, HOOK_INIT, DT_END)); 528 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
498 } 529 }
499#endif 530#endif
500 531
501 create_windows (argc, argv); 532 create_windows (argc, argv);
502 533
503 dDisp; 534 dDisp;
504 535
505 init_xlocale (); 536 init_xlocale ();
506 537
507 scr_reset (); /* initialize screen */ 538 scr_reset (); // initialize screen
508 539
509#if 0 540#if 0
510 XSynchronize (disp, True); 541 XSynchronize (disp, True);
511#endif 542#endif
512 543
584 sw_int (this, &sig_handlers::sig_term) 615 sw_int (this, &sig_handlers::sig_term)
585 { 616 {
586 } 617 }
587} sig_handlers; 618} sig_handlers;
588 619
620char **rxvt_environ; // startup environment
621
589void 622void
590rxvt_init () 623rxvt_init ()
591{ 624{
625 rxvt_environ = environ;
626
592 /* 627 /*
593 * Save and then give up any super-user privileges 628 * Save and then give up any super-user privileges
594 * If we need privileges in any area then we must specifically request it. 629 * If we need privileges in any area then we must specifically request it.
595 * We should only need to be root in these cases: 630 * We should only need to be root in these cases:
596 * 1. write utmp entries on some systems 631 * 1. write utmp entries on some systems
610 /* signal (SIGURG, SIG_DFL); */ 645 /* signal (SIGURG, SIG_DFL); */
611 646
612 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 647 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
613 // TODO: handle this with exceptions and tolerate the memory loss 648 // TODO: handle this with exceptions and tolerate the memory loss
614 XSetIOErrorHandler (rxvt_xioerror_handler); 649 XSetIOErrorHandler (rxvt_xioerror_handler);
650
651 XrmInitialize ();
615} 652}
616 653
617/* ------------------------------------------------------------------------- * 654/* ------------------------------------------------------------------------- *
618 * MEMORY ALLOCATION WRAPPERS * 655 * MEMORY ALLOCATION WRAPPERS *
619 * ------------------------------------------------------------------------- */ 656 * ------------------------------------------------------------------------- */
655 * ------------------------------------------------------------------------- */ 692 * ------------------------------------------------------------------------- */
656/* take care of suid/sgid super-user (root) privileges */ 693/* take care of suid/sgid super-user (root) privileges */
657void 694void
658rxvt_privileges (rxvt_privaction action) 695rxvt_privileges (rxvt_privaction action)
659{ 696{
660#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
661 static uid_t euid;
662 static gid_t egid;
663#endif
664
665#if ! defined(__CYGWIN32__) 697#if ! defined(__CYGWIN32__)
666# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 698# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
667 /* setreuid () is the poor man's setuid (), seteuid () */ 699 /* setreuid () is the poor man's setuid (), seteuid () */
668# define seteuid(a) setreuid(-1, (a)) 700# define seteuid(a) setreuid(-1, (a))
669# define setegid(a) setregid(-1, (a)) 701# define setegid(a) setregid(-1, (a))
675 case IGNORE: 707 case IGNORE:
676 /* 708 /*
677 * change effective uid/gid - not real uid/gid - so we can switch 709 * change effective uid/gid - not real uid/gid - so we can switch
678 * back to root later, as required 710 * back to root later, as required
679 */ 711 */
712 setegid (getgid ());
680 seteuid (getuid ()); 713 seteuid (getuid ());
681 setegid (getgid ());
682 break; 714 break;
683 case SAVE: 715 case SAVE:
684 euid = geteuid ();
685 egid = getegid (); 716 saved_egid = getegid ();
717 saved_euid = geteuid ();
686 break; 718 break;
687 case RESTORE: 719 case RESTORE:
688 seteuid (euid);
689 setegid (egid); 720 setegid (saved_egid);
721 seteuid (saved_euid);
690 break; 722 break;
691 } 723 }
692# else 724# else
693 switch (action) 725 switch (action)
694 { 726 {
695 case IGNORE: 727 case IGNORE:
728 setgid (getgid ());
696 setuid (getuid ()); 729 setuid (getuid ());
697 setgid (getgid ());
698 /* FALLTHROUGH */ 730 /* FALLTHROUGH */
699 case SAVE: 731 case SAVE:
700 /* FALLTHROUGH */ 732 /* FALLTHROUGH */
701 case RESTORE: 733 case RESTORE:
702 break; 734 break;
1418 unsigned long fg, bg; 1450 unsigned long fg, bg;
1419 const char *p; 1451 const char *p;
1420 char **s; 1452 char **s;
1421 XIMStyles *xim_styles; 1453 XIMStyles *xim_styles;
1422 1454
1455 set_environ (envv);
1456
1423 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1457 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1424 return false; 1458 return false;
1425 1459
1426 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1460 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1427 input_method = display->get_xim (locale, modifiers); 1461 input_method = display->get_xim (locale, modifiers);
1592 int i; 1626 int i;
1593 const char *p; 1627 const char *p;
1594 char **s; 1628 char **s;
1595 char buf[IMBUFSIZ]; 1629 char buf[IMBUFSIZ];
1596 1630
1597 SET_R (this); 1631 make_current ();
1598 1632
1599 im_destroy (); 1633 im_destroy ();
1600 1634
1601 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1635 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1602 if (Input_Context) 1636 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines