--- rxvt-unicode/src/main.C 2006/01/06 02:11:15 1.163 +++ rxvt-unicode/src/main.C 2006/01/16 08:48:09 1.179 @@ -13,7 +13,7 @@ * Copyright (c) 1997,1998 Oezguer Kesim * Copyright (c) 1998-2001 Geoff Wing * - extensive modifications - * Copyright (c) 2003-2004 Marc Lehmann + * Copyright (c) 2003-2006 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,6 +48,21 @@ # include #endif +#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) +static uid_t saved_euid; +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]; @@ -63,7 +78,7 @@ return true; } -bool +void rxvt_push_locale (const char *locale) { strcpy (savelocale, curlocale); @@ -271,7 +286,6 @@ } // TODO: free pixcolours, colours should become part of rxvt_display - delete pix_colors_focused; #if OFF_FOCUS_FADING delete pix_colors_unfocused; @@ -365,7 +379,7 @@ void rxvt_term::destroy_cb (time_watcher &w) { - SET_R (this); + make_current (); delete this; } @@ -466,8 +480,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; @@ -489,11 +503,27 @@ #endif #if ENABLE_PERL + if (!rs[Rs_perl_ext_1]) + rs[Rs_perl_ext_1] = "default"; + if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) { - rxvt_perl.init (); +#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) + // ignore some perl-related arguments if some bozo installed us set[ug]id + if (rxvt_tainted ()) + { + 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] = 0; + } + } +#endif + rxvt_perl.init (this); HOOK_INVOKE ((this, HOOK_INIT, DT_END)); } #endif @@ -504,7 +534,7 @@ init_xlocale (); - scr_reset (); /* initialize screen */ + scr_reset (); // initialize screen #if 0 XSynchronize (disp, True); @@ -586,9 +616,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. @@ -612,6 +646,8 @@ old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); // TODO: handle this with exceptions and tolerate the memory loss XSetIOErrorHandler (rxvt_xioerror_handler); + + XrmInitialize (); } /* ------------------------------------------------------------------------- * @@ -657,11 +693,6 @@ void rxvt_privileges (rxvt_privaction action) { -#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) - static uid_t euid; - static gid_t egid; -#endif - #if ! defined(__CYGWIN32__) # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) /* setreuid () is the poor man's setuid (), seteuid () */ @@ -677,24 +708,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: - euid = geteuid (); - egid = getegid (); + saved_egid = getegid (); + saved_euid = geteuid (); break; case RESTORE: - seteuid (euid); - setegid (egid); + setegid (saved_egid); + seteuid (saved_euid); break; } # else switch (action) { case IGNORE: - setuid (getuid ()); setgid (getgid ()); + setuid (getuid ()); /* FALLTHROUGH */ case SAVE: /* FALLTHROUGH */ @@ -1420,6 +1451,8 @@ char **s; XIMStyles *xim_styles; + set_environ (envv); + if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) return false; @@ -1594,7 +1627,7 @@ char **s; char buf[IMBUFSIZ]; - SET_R (this); + make_current (); im_destroy ();