--- rxvt-unicode/src/ptytty.C 2006/01/17 18:06:14 1.45 +++ rxvt-unicode/src/ptytty.C 2006/01/19 16:43:36 1.50 @@ -69,7 +69,8 @@ static inline int get_pty_streams (int *fd_tty, char **ttydev) { -#ifdef NO_SETOWNER_TTYDEV +#if defined(HAVE_GRANTPT) && defined(HAVE_UNLOCKPT) +# if defined(PTYS_ARE_GETPT) || defined(PTYS_ARE_POSIX) || defined(PTYS_ARE_PTMX) int pfd; # if defined(PTYS_ARE_GETPT) @@ -90,6 +91,7 @@ close (pfd); } +# endif #endif return -1; @@ -278,7 +280,7 @@ { setsid (); -# if defined(PTYS_ARE_PTMX) && defined(I_PUSH) +#if defined(PTYS_ARE_PTMX) && defined(I_PUSH) /* * Push STREAMS modules: * ptem: pseudo-terminal hardware emulation module. @@ -296,15 +298,15 @@ * close () - on the master side which causes a hang up to be sent * through - Geoff Wing */ -# ifdef HAVE_ISASTREAM +# ifdef HAVE_ISASTREAM if (isastream (fd_tty) == 1) -# endif +# endif { ioctl (fd_tty, I_PUSH, "ptem"); ioctl (fd_tty, I_PUSH, "ldterm"); ioctl (fd_tty, I_PUSH, "ttcompat"); } -# endif +#endif ioctl (fd_tty, TIOCSCTTY, NULL); @@ -360,9 +362,6 @@ #endif } -///////////////////////////////////////////////////////////////////////////// - -#ifndef NO_SETOWNER_TTYDEV static struct ttyconf { gid_t gid; mode_t mode; @@ -381,59 +380,15 @@ #endif /* TTY_GID_SUPPORT */ { mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; - gid = getgid (); + gid = 0; } } } ttyconf; -///////////////////////////////////////////////////////////////////////////// - -void -rxvt_ptytty_unix::privileges (rxvt_privaction action) -{ - if (!name || !*name) - return; - - if (action == SAVE) - { -# ifndef RESET_TTY_TO_COMMON_DEFAULTS - /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ - if (lstat (name, &savestat) < 0) /* you lose out */ - ; - else -# endif - { - saved = true; - chown (name, getuid (), ttyconf.gid); /* fail silently */ - chmod (name, ttyconf.mode); -# ifdef HAVE_REVOKE - revoke (name); -# endif - } - } - else - { /* action == RESTORE */ -# ifndef RESET_TTY_TO_COMMON_DEFAULTS - if (saved) - { - chmod (name, savestat.st_mode); - chown (name, savestat.st_uid, savestat.st_gid); - } -# else - chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); - chown (name, 0, 0); -# endif - } -} -#endif - rxvt_ptytty_unix::rxvt_ptytty_unix () { pty = tty = -1; name = 0; -#ifndef NO_SETOWNER_TTYDEV - saved = false; -#endif #if UTMP_SUPPORT cmd_pid = 0; #endif @@ -450,12 +405,14 @@ void rxvt_ptytty_unix::put () { -#ifndef NO_SETOWNER_TTYDEV - privileges (RESTORE); -#endif + chmod (name, RESTORE_TTY_MODE); + chown (name, 0, ttyconf.gid); - if (pty >= 0) close (pty); close_tty (); + + if (pty >= 0) + close (pty); + free (name); pty = tty = -1; @@ -475,7 +432,11 @@ if (tty < 0) { #ifndef NO_SETOWNER_TTYDEV - privileges (SAVE); + chown (name, getuid (), ttyconf.gid); /* fail silently */ + chmod (name, ttyconf.mode); +# ifdef HAVE_REVOKE + revoke (name); +# endif #endif if ((tty = get_tty (name)) < 0) @@ -638,20 +599,18 @@ } else { - setgid (getegid ()); - setuid (geteuid ()); - // server, pty-helper sock_fd = sv[1]; for (int fd = 0; fd < 1023; fd++) - if (fd != sock_fd && fd != 1) + if (fd != sock_fd) close (fd); serve (); _exit (EXIT_SUCCESS); } } + #endif // a "factory" *g*