--- rxvt-unicode/src/main.C 2006/01/17 12:22:59 1.184 +++ rxvt-unicode/src/main.C 2006/01/17 15:41:33 1.186 @@ -211,10 +211,6 @@ if (cmd_pid) kill (-cmd_pid, SIGHUP); -#ifdef UTMP_SUPPORT - privileged_utmp (RESTORE); -#endif - delete pty; pty = 0; } @@ -602,6 +598,38 @@ void rxvt_init () { + uid_t uid = getuid (); + gid_t gid = getgid (); + + // before doing anything else, check for setuid/setgid operation, + // start the helper process and drop privileges + if (uid != geteuid () + || 1 //D + || gid != getegid ()) + { +#if PTYTTY_HELPER + rxvt_ptytty_server (); +#else + rxvt_warn ("running setuid/setgid without pty helper compiled in, continuing unprivileged.\n"); +#endif + + // drop privileges +#if HAVE_SETRESUID + setresgid (gid, gid, gid); + setresuid (uid, uid, uid); +#elif HAVE_SETREUID + setregid (gid, gid); + setreuid (uid, uid); +#elif HAVE_SETUID + setgid (gid); + setuid (uid); +#endif + + if (uid != geteuid () + || gid != getegid ()) + rxvt_fatal ("unable to drop privileges, aborting.\n"); + } + rxvt_environ = environ; /* @@ -717,24 +745,6 @@ #endif } -#ifdef UTMP_SUPPORT -void -rxvt_term::privileged_utmp (rxvt_privaction action) -{ - if (OPTION (Opt_utmpInhibit)) - return; - - rxvt_privileges (RESTORE); - - if (action == SAVE) - pty->login (cmd_pid, OPTION (Opt_loginShell), rs[Rs_display_name]); - else - pty->logout (); - - rxvt_privileges (IGNORE); -} -#endif - /*----------------------------------------------------------------------*/ /* * window size/position calculcations for XSizeHint and other storage.