… | |
… | |
2 | * File: ptytty.C |
2 | * File: ptytty.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> |
6 | * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> |
7 | * Copyright (c) 2004 Marc Lehmann <pcg@goof.com> |
7 | * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com> |
8 | * |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
12 | * (at your option) any later version. |
… | |
… | |
76 | int pfd; |
76 | int pfd; |
77 | |
77 | |
78 | #ifdef PTYS_ARE_OPENPTY |
78 | #ifdef PTYS_ARE_OPENPTY |
79 | char tty_name[sizeof "/dev/pts/????\0"]; |
79 | char tty_name[sizeof "/dev/pts/????\0"]; |
80 | |
80 | |
|
|
81 | rxvt_privileges(RESTORE); |
81 | if (openpty (&pfd, fd_tty, tty_name, NULL, NULL) != -1) |
82 | int res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); |
|
|
83 | rxvt_privileges(IGNORE); |
|
|
84 | |
|
|
85 | if (res != -1) |
82 | { |
86 | { |
83 | *ttydev = strdup (tty_name); |
87 | *ttydev = strdup (tty_name); |
84 | return pfd; |
88 | return pfd; |
85 | } |
89 | } |
86 | #endif |
90 | #endif |
… | |
… | |
90 | if (*ttydev != NULL) |
94 | if (*ttydev != NULL) |
91 | return pfd; |
95 | return pfd; |
92 | #endif |
96 | #endif |
93 | |
97 | |
94 | #ifdef PTYS_ARE_GETPTY |
98 | #ifdef PTYS_ARE_GETPTY |
95 | |
|
|
96 | char *ptydev; |
99 | char *ptydev; |
97 | |
100 | |
98 | while ((ptydev = getpty ()) != NULL) |
101 | while ((ptydev = getpty ()) != NULL) |
99 | if ((pfd = open (ptydev, O_RDWR | O_NOCTTY, 0)) >= 0) |
102 | if ((pfd = open (ptydev, O_RDWR | O_NOCTTY, 0)) >= 0) |
100 | { |
103 | { |
… | |
… | |
334 | } ttyconf; |
337 | } ttyconf; |
335 | |
338 | |
336 | void |
339 | void |
337 | rxvt_ptytty::privileges (rxvt_privaction action) |
340 | rxvt_ptytty::privileges (rxvt_privaction action) |
338 | { |
341 | { |
339 | if (tty < 0) |
342 | if (!name || !*name) |
340 | return; |
343 | return; |
341 | |
344 | |
342 | rxvt_privileges (RESTORE); |
345 | rxvt_privileges (RESTORE); |
343 | |
346 | |
344 | if (action == SAVE) |
347 | if (action == SAVE) |
345 | { |
348 | { |
346 | //next_tty_action = RESTORE; |
|
|
347 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
349 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
348 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
350 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
349 | if (lstat (name, &savestat) < 0) /* you lose out */ |
351 | if (lstat (name, &savestat) < 0) /* you lose out */ |
350 | ;//next_tty_action = IGNORE; |
352 | ; |
351 | else |
353 | else |
352 | # endif |
354 | # endif |
353 | { |
355 | { |
|
|
356 | saved = true; |
354 | chown (name, getuid (), ttyconf.gid); /* fail silently */ |
357 | chown (name, getuid (), ttyconf.gid); /* fail silently */ |
355 | chmod (name, ttyconf.mode); |
358 | chmod (name, ttyconf.mode); |
356 | # ifdef HAVE_REVOKE |
359 | # ifdef HAVE_REVOKE |
357 | revoke (name); |
360 | revoke (name); |
358 | # endif |
361 | # endif |
359 | } |
362 | } |
360 | } |
363 | } |
361 | else |
364 | else |
362 | { /* action == RESTORE */ |
365 | { /* action == RESTORE */ |
363 | //next_tty_action = IGNORE; |
|
|
364 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
366 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
367 | if (saved) |
|
|
368 | { |
365 | chmod (name, savestat.st_mode); |
369 | chmod (name, savestat.st_mode); |
366 | chown (name, savestat.st_uid, savestat.st_gid); |
370 | chown (name, savestat.st_uid, savestat.st_gid); |
|
|
371 | } |
367 | # else |
372 | # else |
368 | chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
373 | chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
369 | chown (name, 0, 0); |
374 | chown (name, 0, 0); |
370 | # endif |
375 | # endif |
371 | |
376 | |
… | |
… | |
377 | |
382 | |
378 | rxvt_ptytty::rxvt_ptytty () |
383 | rxvt_ptytty::rxvt_ptytty () |
379 | { |
384 | { |
380 | pty = tty = -1; |
385 | pty = tty = -1; |
381 | name = 0; |
386 | name = 0; |
|
|
387 | #ifndef NO_SETOWNER_TTYDEV |
|
|
388 | saved = false; |
|
|
389 | #endif |
382 | } |
390 | } |
383 | |
391 | |
384 | rxvt_ptytty::~rxvt_ptytty () |
392 | rxvt_ptytty::~rxvt_ptytty () |
385 | { |
393 | { |
386 | put (); |
394 | put (); |
… | |
… | |
388 | |
396 | |
389 | void |
397 | void |
390 | |
398 | |
391 | rxvt_ptytty::close_tty () |
399 | rxvt_ptytty::close_tty () |
392 | { |
400 | { |
393 | if (tty >= 0) close (tty); |
401 | if (tty < 0) |
|
|
402 | return; |
|
|
403 | |
|
|
404 | close (tty); |
394 | tty = -1; |
405 | tty = -1; |
395 | } |
406 | } |
396 | |
407 | |
397 | void |
408 | void |
398 | rxvt_ptytty::put () |
409 | rxvt_ptytty::put () |
399 | { |
410 | { |
400 | #ifndef NO_SETOWNER_TTYDEV |
411 | #ifndef NO_SETOWNER_TTYDEV |
401 | if (tty >= 0) |
|
|
402 | privileges (RESTORE); |
412 | privileges (RESTORE); |
403 | #endif |
413 | #endif |
404 | |
414 | |
405 | if (pty >= 0) close (pty); |
415 | if (pty >= 0) close (pty); |
406 | close_tty (); |
416 | close_tty (); |
407 | free (name); |
417 | free (name); |
… | |
… | |
444 | |
454 | |
445 | void |
455 | void |
446 | rxvt_ptytty::set_utf8_mode (bool on) |
456 | rxvt_ptytty::set_utf8_mode (bool on) |
447 | { |
457 | { |
448 | #ifdef IUTF8 |
458 | #ifdef IUTF8 |
449 | if (pty != -1) |
459 | if (pty < 0) |
450 | { |
460 | return; |
|
|
461 | |
451 | struct termios tio; |
462 | struct termios tio; |
452 | |
463 | |
453 | if (tcgetattr (pty, &tio) != -1) |
464 | if (tcgetattr (pty, &tio) != -1) |
|
|
465 | { |
|
|
466 | tcflag_t new_cflag = tio.c_iflag; |
|
|
467 | |
|
|
468 | if (on) |
|
|
469 | new_cflag |= IUTF8; |
|
|
470 | else |
|
|
471 | new_cflag &= ~IUTF8; |
|
|
472 | |
|
|
473 | if (new_cflag != tio.c_iflag) |
454 | { |
474 | { |
455 | tcflag_t new_cflag = tio.c_iflag; |
|
|
456 | |
|
|
457 | if (on) |
|
|
458 | new_cflag |= IUTF8; |
|
|
459 | else |
|
|
460 | new_cflag &= ~IUTF8; |
|
|
461 | |
|
|
462 | if (new_cflag != tio.c_iflag) |
|
|
463 | { |
|
|
464 | tio.c_iflag = new_cflag; |
475 | tio.c_iflag = new_cflag; |
465 | tcsetattr (pty, TCSANOW, &tio); |
476 | tcsetattr (pty, TCSANOW, &tio); |
466 | } |
|
|
467 | } |
477 | } |
468 | } |
478 | } |
469 | #endif |
479 | #endif |
470 | } |
480 | } |
471 | |
481 | |