--- rxvt-unicode/src/main.C 2005/12/31 17:16:17 1.154 +++ rxvt-unicode/src/main.C 2006/01/16 08:29:57 1.178 @@ -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 @@ -32,6 +32,8 @@ #include "../config.h" /* NECESSARY */ #include "rxvt.h" /* NECESSARY */ +#include "keyboard.h" +#include "rxvtperl.h" #include @@ -46,13 +48,24 @@ # include #endif -#ifdef KEYSYM_RESOURCE -# include "keyboard.h" +#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]; +static char curlocale[128], savelocale[128]; bool rxvt_set_locale (const char *locale) @@ -65,6 +78,19 @@ return true; } +void +rxvt_push_locale (const char *locale) +{ + strcpy (savelocale, curlocale); + rxvt_set_locale (locale); +} + +void +rxvt_pop_locale () +{ + rxvt_set_locale (savelocale); +} + #if ENABLE_COMBINING class rxvt_composite_vec rxvt_composite; @@ -197,6 +223,8 @@ rxvt_term::~rxvt_term () { + HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); + termlist.erase (find (termlist.begin (), termlist.end(), this)); emergency_cleanup (); @@ -258,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; @@ -352,7 +379,7 @@ void rxvt_term::destroy_cb (time_watcher &w) { - SET_R (this); + make_current (); delete this; } @@ -453,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; @@ -475,13 +502,40 @@ scrollBar.setIdle (); /* set existence for size calculations */ #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])) + { +#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 (); + setlocale (LC_CTYPE, curlocale); // perl init destroys current locale + HOOK_INVOKE ((this, HOOK_INIT, DT_END)); + } +#endif + create_windows (argc, argv); dDisp; init_xlocale (); - scr_reset (); /* initialize screen */ + scr_reset (); // initialize screen #if 0 XSynchronize (disp, True); @@ -513,10 +567,13 @@ free (cmd_argv); - pty_ev.start (pty.pty, EVENT_READ); + if (pty.pty >= 0) + pty_ev.start (pty.pty, EVENT_READ); check_ev.start (); + HOOK_INVOKE ((this, HOOK_START, DT_END)); + return true; } @@ -560,9 +617,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. @@ -586,6 +647,8 @@ old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); // TODO: handle this with exceptions and tolerate the memory loss XSetIOErrorHandler (rxvt_xioerror_handler); + + XrmInitialize (); } /* ------------------------------------------------------------------------- * @@ -631,11 +694,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 () */ @@ -651,24 +709,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 */ @@ -902,7 +960,7 @@ fwidth = prop.width; fheight = prop.height; - fbase = (*fs)[1]->ascent; + fbase = prop.ascent; for (int style = 1; style < 4; style++) { @@ -1003,11 +1061,9 @@ if (i >= 8 && i <= 15) { /* bright colors */ i -= 8; -# ifndef NO_BRIGHTCOLOR pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; SET_PIXCOLOR (idx); goto done; -# endif } if (i >= 0 && i <= 7) @@ -1201,11 +1257,11 @@ if (menubar_visible ()) XMoveResizeWindow (disp, menuBar.win, window_vt_x, 0, - TermWin_TotalWidth (), menuBar_TotalHeight ()); + width, menuBar_TotalHeight ()); XMoveResizeWindow (disp, vt, window_vt_x, window_vt_y, - TermWin_TotalWidth (), TermWin_TotalHeight ()); + width, height); scr_clear (); #ifdef XPM_BACKGROUND @@ -1396,6 +1452,8 @@ char **s; XIMStyles *xim_styles; + set_environ (envv); + if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) return false; @@ -1570,7 +1628,7 @@ char **s; char buf[IMBUFSIZ]; - SET_R (this); + make_current (); im_destroy ();