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

Comparing rxvt-unicode/src/ptytty.C (file contents):
Revision 1.45 by root, Tue Jan 17 18:06:14 2006 UTC vs.
Revision 1.50 by root, Thu Jan 19 16:43:36 2006 UTC

67 * fd_tty _may_ also be set to an open fd to the slave device 67 * fd_tty _may_ also be set to an open fd to the slave device
68 */ 68 */
69static inline int 69static inline int
70get_pty_streams (int *fd_tty, char **ttydev) 70get_pty_streams (int *fd_tty, char **ttydev)
71{ 71{
72#ifdef NO_SETOWNER_TTYDEV 72#if defined(HAVE_GRANTPT) && defined(HAVE_UNLOCKPT)
73# if defined(PTYS_ARE_GETPT) || defined(PTYS_ARE_POSIX) || defined(PTYS_ARE_PTMX)
73 int pfd; 74 int pfd;
74 75
75# if defined(PTYS_ARE_GETPT) 76# if defined(PTYS_ARE_GETPT)
76 pfd = getpt(); 77 pfd = getpt();
77# elif defined(PTYS_ARE_POSIX) 78# elif defined(PTYS_ARE_POSIX)
88 return pfd; 89 return pfd;
89 } 90 }
90 91
91 close (pfd); 92 close (pfd);
92 } 93 }
94# endif
93#endif 95#endif
94 96
95 return -1; 97 return -1;
96} 98}
97 99
276static int 278static int
277control_tty (int fd_tty) 279control_tty (int fd_tty)
278{ 280{
279 setsid (); 281 setsid ();
280 282
281# if defined(PTYS_ARE_PTMX) && defined(I_PUSH) 283#if defined(PTYS_ARE_PTMX) && defined(I_PUSH)
282 /* 284 /*
283 * Push STREAMS modules: 285 * Push STREAMS modules:
284 * ptem: pseudo-terminal hardware emulation module. 286 * ptem: pseudo-terminal hardware emulation module.
285 * ldterm: standard terminal line discipline. 287 * ldterm: standard terminal line discipline.
286 * ttcompat: V7, 4BSD and XENIX STREAMS compatibility module. 288 * ttcompat: V7, 4BSD and XENIX STREAMS compatibility module.
294 * documentation is really unclear about whether it is any close () on 296 * documentation is really unclear about whether it is any close () on
295 * the master side or the last close () - i.e. a proper STREAMS dismantling 297 * the master side or the last close () - i.e. a proper STREAMS dismantling
296 * close () - on the master side which causes a hang up to be sent 298 * close () - on the master side which causes a hang up to be sent
297 * through - Geoff Wing 299 * through - Geoff Wing
298 */ 300 */
299# ifdef HAVE_ISASTREAM 301# ifdef HAVE_ISASTREAM
300 if (isastream (fd_tty) == 1) 302 if (isastream (fd_tty) == 1)
301# endif 303# endif
302 { 304 {
303 ioctl (fd_tty, I_PUSH, "ptem"); 305 ioctl (fd_tty, I_PUSH, "ptem");
304 ioctl (fd_tty, I_PUSH, "ldterm"); 306 ioctl (fd_tty, I_PUSH, "ldterm");
305 ioctl (fd_tty, I_PUSH, "ttcompat"); 307 ioctl (fd_tty, I_PUSH, "ttcompat");
306 } 308 }
307# endif 309#endif
308 310
309 ioctl (fd_tty, TIOCSCTTY, NULL); 311 ioctl (fd_tty, TIOCSCTTY, NULL);
310 312
311 int fd = open ("/dev/tty", O_WRONLY); 313 int fd = open ("/dev/tty", O_WRONLY);
312 if (fd < 0) 314 if (fd < 0)
358 } 360 }
359 } 361 }
360#endif 362#endif
361} 363}
362 364
363/////////////////////////////////////////////////////////////////////////////
364
365#ifndef NO_SETOWNER_TTYDEV
366static struct ttyconf { 365static struct ttyconf {
367 gid_t gid; 366 gid_t gid;
368 mode_t mode; 367 mode_t mode;
369 368
370 ttyconf () 369 ttyconf ()
379 } 378 }
380 else 379 else
381#endif /* TTY_GID_SUPPORT */ 380#endif /* TTY_GID_SUPPORT */
382 { 381 {
383 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; 382 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
384 gid = getgid (); 383 gid = 0;
385 } 384 }
386 } 385 }
387} ttyconf; 386} ttyconf;
388
389/////////////////////////////////////////////////////////////////////////////
390
391void
392rxvt_ptytty_unix::privileges (rxvt_privaction action)
393{
394 if (!name || !*name)
395 return;
396
397 if (action == SAVE)
398 {
399# ifndef RESET_TTY_TO_COMMON_DEFAULTS
400 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */
401 if (lstat (name, &savestat) < 0) /* you lose out */
402 ;
403 else
404# endif
405 {
406 saved = true;
407 chown (name, getuid (), ttyconf.gid); /* fail silently */
408 chmod (name, ttyconf.mode);
409# ifdef HAVE_REVOKE
410 revoke (name);
411# endif
412 }
413 }
414 else
415 { /* action == RESTORE */
416# ifndef RESET_TTY_TO_COMMON_DEFAULTS
417 if (saved)
418 {
419 chmod (name, savestat.st_mode);
420 chown (name, savestat.st_uid, savestat.st_gid);
421 }
422# else
423 chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
424 chown (name, 0, 0);
425# endif
426 }
427}
428#endif
429 387
430rxvt_ptytty_unix::rxvt_ptytty_unix () 388rxvt_ptytty_unix::rxvt_ptytty_unix ()
431{ 389{
432 pty = tty = -1; 390 pty = tty = -1;
433 name = 0; 391 name = 0;
434#ifndef NO_SETOWNER_TTYDEV
435 saved = false;
436#endif
437#if UTMP_SUPPORT 392#if UTMP_SUPPORT
438 cmd_pid = 0; 393 cmd_pid = 0;
439#endif 394#endif
440} 395}
441 396
448} 403}
449 404
450void 405void
451rxvt_ptytty_unix::put () 406rxvt_ptytty_unix::put ()
452{ 407{
453#ifndef NO_SETOWNER_TTYDEV 408 chmod (name, RESTORE_TTY_MODE);
454 privileges (RESTORE); 409 chown (name, 0, ttyconf.gid);
455#endif
456 410
457 if (pty >= 0) close (pty);
458 close_tty (); 411 close_tty ();
412
413 if (pty >= 0)
414 close (pty);
415
459 free (name); 416 free (name);
460 417
461 pty = tty = -1; 418 pty = tty = -1;
462 name = 0; 419 name = 0;
463} 420}
473 430
474 /* get slave (tty) */ 431 /* get slave (tty) */
475 if (tty < 0) 432 if (tty < 0)
476 { 433 {
477#ifndef NO_SETOWNER_TTYDEV 434#ifndef NO_SETOWNER_TTYDEV
478 privileges (SAVE); 435 chown (name, getuid (), ttyconf.gid); /* fail silently */
436 chmod (name, ttyconf.mode);
437# ifdef HAVE_REVOKE
438 revoke (name);
439# endif
479#endif 440#endif
480 441
481 if ((tty = get_tty (name)) < 0) 442 if ((tty = get_tty (name)) < 0)
482 { 443 {
483 put (); 444 put ();
636 close (sv[1]); 597 close (sv[1]);
637 fcntl (sock_fd, F_SETFD, FD_CLOEXEC); 598 fcntl (sock_fd, F_SETFD, FD_CLOEXEC);
638 } 599 }
639 else 600 else
640 { 601 {
641 setgid (getegid ());
642 setuid (geteuid ());
643
644 // server, pty-helper 602 // server, pty-helper
645 sock_fd = sv[1]; 603 sock_fd = sv[1];
646 604
647 for (int fd = 0; fd < 1023; fd++) 605 for (int fd = 0; fd < 1023; fd++)
648 if (fd != sock_fd && fd != 1) 606 if (fd != sock_fd)
649 close (fd); 607 close (fd);
650 608
651 serve (); 609 serve ();
652 _exit (EXIT_SUCCESS); 610 _exit (EXIT_SUCCESS);
653 } 611 }
654} 612}
613
655#endif 614#endif
656 615
657// a "factory" *g* 616// a "factory" *g*
658rxvt_ptytty * 617rxvt_ptytty *
659rxvt_new_ptytty () 618rxvt_new_ptytty ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines