ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/proxy.C
(Generate patch)

Comparing rxvt-unicode/src/proxy.C (file contents):
Revision 1.4 by root, Tue Feb 7 05:32:47 2006 UTC vs.
Revision 1.10 by sf-exg, Wed Jul 21 08:46:13 2010 UTC

21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software 22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *---------------------------------------------------------------------*/ 24 *---------------------------------------------------------------------*/
25 25
26#include "../config.h" 26#include "config.h"
27 27
28#include "ptytty.h" 28#include "ptytty.h"
29 29
30#include <cstdio>
31#include <cstring>
30#include <csignal> 32#include <csignal>
31 33
32#include <sys/types.h> 34#include <sys/types.h>
33#include <sys/socket.h> 35#include <sys/socket.h>
34#include <unistd.h> 36#include <unistd.h>
35#include <fcntl.h> 37#include <fcntl.h>
38#include <errno.h>
36 39
37// helper/proxy support 40// helper/proxy support
38 41
39#if PTYTTY_HELPER 42#if PTYTTY_HELPER
40 43
123 126
124ptytty_proxy::~ptytty_proxy () 127ptytty_proxy::~ptytty_proxy ()
125{ 128{
126 if (id) 129 if (id)
127 { 130 {
131 close_tty ();
132
133 if (pty >= 0)
134 close (pty);
135
128 NEED_TOKEN; 136 NEED_TOKEN;
129 137
130 command cmd; 138 command cmd;
131 139
132 cmd.type = command::destroy; 140 cmd.type = command::destroy;
290#endif 298#endif
291 return new ptytty_unix; 299 return new ptytty_unix;
292} 300}
293 301
294void 302void
303ptytty::sanitise_stdfd ()
304{
305 // sanitise stdin/stdout/stderr to point to *something*.
306 for (int fd = 0; fd <= 2; ++fd)
307 if (fcntl (fd, F_GETFL) < 0 && errno == EBADF)
308 {
309 int fd2 = open ("/dev/tty", fd ? O_WRONLY : O_RDONLY);
310
311 if (fd2 < 0)
312 fd2 = open ("/dev/null", fd ? O_WRONLY : O_RDONLY);
313
314 if (fd2 != fd)
315 abort ();
316 }
317}
318
319void
295ptytty::init () 320ptytty::init ()
296{ 321{
322 sanitise_stdfd ();
323
297 uid_t uid = getuid (); 324 uid_t uid = getuid ();
298 gid_t gid = getgid (); 325 gid_t gid = getgid ();
299 326
300 // before doing anything else, check for setuid/setgid operation, 327 // before doing anything else, check for setuid/setgid operation,
301 // start the helper process and drop privileges 328 // start the helper process and drop privileges
302 if (uid != geteuid () 329 if (uid != geteuid ()
303 || gid != getegid ()) 330 || gid != getegid ())
304 { 331 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines