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.47 by root, Thu Jan 19 10:27:27 2006 UTC vs.
Revision 1.49 by ayin, Thu Jan 19 16:40:42 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
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); 411 if (pty >= 0) close (pty);
458 close_tty (); 412 close_tty ();
459 free (name); 413 free (name);
460 414
473 427
474 /* get slave (tty) */ 428 /* get slave (tty) */
475 if (tty < 0) 429 if (tty < 0)
476 { 430 {
477#ifndef NO_SETOWNER_TTYDEV 431#ifndef NO_SETOWNER_TTYDEV
478 privileges (SAVE); 432 chown (name, getuid (), ttyconf.gid); /* fail silently */
433 chmod (name, ttyconf.mode);
434# ifdef HAVE_REVOKE
435 revoke (name);
436# endif
479#endif 437#endif
480 438
481 if ((tty = get_tty (name)) < 0) 439 if ((tty = get_tty (name)) < 0)
482 { 440 {
483 put (); 441 put ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines