--- rxvt-unicode/src/main.C 2006/01/08 08:43:11 1.167 +++ rxvt-unicode/src/main.C 2006/01/16 06:37:52 1.177 @@ -53,6 +53,16 @@ static gid_t saved_egid; #endif +bool +rxvt_tainted () +{ +#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) + return getuid () != saved_euid || getgid () != saved_egid; +#else + return false; +#endif +} + vector rxvt_term::termlist; static char curlocale[128], savelocale[128]; @@ -68,7 +78,7 @@ return true; } -bool +void rxvt_push_locale (const char *locale) { strcpy (savelocale, curlocale); @@ -81,6 +91,14 @@ rxvt_set_locale (savelocale); } +void +rxvt_term::make_current () const +{ + SET_R (this); + rxvt_set_locale (locale); + set_environ (envv); +} + #if ENABLE_COMBINING class rxvt_composite_vec rxvt_composite; @@ -276,14 +294,10 @@ } // TODO: free pixcolours, colours should become part of rxvt_display - delete pix_colors_focused; #if OFF_FOCUS_FADING delete pix_colors_unfocused; #endif -#if USE_XGETDEFAULT - XrmDestroyDatabase (xrmdatabase); -#endif displays.put (display); @@ -373,7 +387,7 @@ void rxvt_term::destroy_cb (time_watcher &w) { - SET_R (this); + make_current (); delete this; } @@ -474,8 +488,8 @@ rxvt_term::init (int argc, const char *const *argv) { SET_R (this); - set_locale (""); + set_environ (envv); // few things in X do not call setlocale :( if (!init_vars ()) return false; @@ -504,24 +518,21 @@ || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) { - bool tainted = false; - #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) // ignore some perl-related arguments if some bozo installed us set[ug]id - if (getuid () != saved_euid || getgid () != saved_egid) + if (rxvt_tainted ()) { - tainted = true; - if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) { rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); - rs[Rs_perl_lib] = 0; - rs[Rs_perl_eval] = "our $tainted = 1"; + rs[Rs_perl_lib] = 0; + rs[Rs_perl_eval] = 0; } } #endif - rxvt_perl.init (tainted); + rxvt_perl.init (); + setlocale (LC_CTYPE, curlocale); // perl init destroys current locale HOOK_INVOKE ((this, HOOK_INIT, DT_END)); } #endif @@ -532,7 +543,7 @@ init_xlocale (); - scr_reset (); /* initialize screen */ + scr_reset (); // initialize screen #if 0 XSynchronize (disp, True); @@ -614,9 +625,13 @@ } } sig_handlers; +char **rxvt_environ; // startup environment + void rxvt_init () { + rxvt_environ = environ; + /* * Save and then give up any super-user privileges * If we need privileges in any area then we must specifically request it. @@ -641,9 +656,7 @@ // TODO: handle this with exceptions and tolerate the memory loss XSetIOErrorHandler (rxvt_xioerror_handler); -#ifdef USE_XGETDEFAULT XrmInitialize (); -#endif } /* ------------------------------------------------------------------------- * @@ -704,24 +717,24 @@ * change effective uid/gid - not real uid/gid - so we can switch * back to root later, as required */ - seteuid (getuid ()); setegid (getgid ()); + seteuid (getuid ()); break; case SAVE: - saved_euid = geteuid (); saved_egid = getegid (); + saved_euid = geteuid (); break; case RESTORE: - seteuid (saved_euid); setegid (saved_egid); + seteuid (saved_euid); break; } # else switch (action) { case IGNORE: - setuid (getuid ()); setgid (getgid ()); + setuid (getuid ()); /* FALLTHROUGH */ case SAVE: /* FALLTHROUGH */ @@ -1447,6 +1460,8 @@ char **s; XIMStyles *xim_styles; + set_environ (envv); + if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) return false; @@ -1621,7 +1636,7 @@ char **s; char buf[IMBUFSIZ]; - SET_R (this); + make_current (); im_destroy ();