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.5 by ayin, Tue Jan 16 18:25:51 2007 UTC vs.
Revision 1.11 by root, Mon Feb 21 07:41:02 2011 UTC

4/*----------------------------------------------------------------------* 4/*----------------------------------------------------------------------*
5 * File: proxy.C 5 * File: proxy.C
6 *----------------------------------------------------------------------* 6 *----------------------------------------------------------------------*
7 * 7 *
8 * All portions of code are copyright by their respective author/s. 8 * All portions of code are copyright by their respective author/s.
9 * Copyright (c) 2006 Marc Lehmann <pcg@goof.com> 9 * Copyright (c) 2006 Marc Lehmann <schmorp@schmorp.de>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
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)
128 close (pty); 134 close (pty);
129 135
130 NEED_TOKEN; 136 NEED_TOKEN;
131 137
132 command cmd; 138 command cmd;
133 139
292#endif 298#endif
293 return new ptytty_unix; 299 return new ptytty_unix;
294} 300}
295 301
296void 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
297ptytty::init () 320ptytty::init ()
298{ 321{
322 sanitise_stdfd ();
323
299 uid_t uid = getuid (); 324 uid_t uid = getuid ();
300 gid_t gid = getgid (); 325 gid_t gid = getgid ();
301 326
302 // before doing anything else, check for setuid/setgid operation, 327 // before doing anything else, check for setuid/setgid operation,
303 // start the helper process and drop privileges 328 // start the helper process and drop privileges
304 if (uid != geteuid () 329 if (uid != geteuid ()
305 || gid != getegid ()) 330 || gid != getegid ())
306 { 331 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines