… | |
… | |
72 | int pfd; |
72 | int pfd; |
73 | |
73 | |
74 | #ifdef PTYS_ARE_OPENPTY |
74 | #ifdef PTYS_ARE_OPENPTY |
75 | char tty_name[sizeof "/dev/pts/????\0"]; |
75 | char tty_name[sizeof "/dev/pts/????\0"]; |
76 | |
76 | |
77 | rxvt_privileges(RESTORE); |
|
|
78 | int res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); |
77 | int res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); |
79 | rxvt_privileges(IGNORE); |
|
|
80 | |
78 | |
81 | if (res != -1) |
79 | if (res != -1) |
82 | { |
80 | { |
83 | *ttydev = strdup (tty_name); |
81 | *ttydev = strdup (tty_name); |
84 | return pfd; |
82 | return pfd; |
… | |
… | |
344 | rxvt_ptytty_unix::privileges (rxvt_privaction action) |
342 | rxvt_ptytty_unix::privileges (rxvt_privaction action) |
345 | { |
343 | { |
346 | if (!name || !*name) |
344 | if (!name || !*name) |
347 | return; |
345 | return; |
348 | |
346 | |
349 | rxvt_privileges (RESTORE); |
|
|
350 | |
|
|
351 | if (action == SAVE) |
347 | if (action == SAVE) |
352 | { |
348 | { |
353 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
349 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
354 | /* 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 */ |
355 | if (lstat (name, &savestat) < 0) /* you lose out */ |
351 | if (lstat (name, &savestat) < 0) /* you lose out */ |
… | |
… | |
377 | 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)); |
378 | chown (name, 0, 0); |
374 | chown (name, 0, 0); |
379 | # endif |
375 | # endif |
380 | |
376 | |
381 | } |
377 | } |
382 | |
|
|
383 | rxvt_privileges (IGNORE); |
|
|
384 | } |
378 | } |
385 | #endif |
379 | #endif |
386 | |
380 | |
387 | rxvt_ptytty_unix::rxvt_ptytty_unix () |
381 | rxvt_ptytty_unix::rxvt_ptytty_unix () |
388 | { |
382 | { |
… | |
… | |
396 | #endif |
390 | #endif |
397 | } |
391 | } |
398 | |
392 | |
399 | rxvt_ptytty_unix::~rxvt_ptytty_unix () |
393 | rxvt_ptytty_unix::~rxvt_ptytty_unix () |
400 | { |
394 | { |
|
|
395 | #if UTMP_SUPPORT |
401 | logout (); |
396 | logout (); |
|
|
397 | #endif |
402 | put (); |
398 | put (); |
403 | } |
399 | } |
404 | |
400 | |
405 | void |
401 | void |
406 | rxvt_ptytty_unix::put () |
402 | rxvt_ptytty_unix::put () |
… | |
… | |
461 | |
457 | |
462 | struct rxvt_ptytty_proxy : zero_initialized, rxvt_ptytty |
458 | struct rxvt_ptytty_proxy : zero_initialized, rxvt_ptytty |
463 | { |
459 | { |
464 | rxvt_ptytty *id; |
460 | rxvt_ptytty *id; |
465 | |
461 | |
466 | rxvt_ptytty_proxy (); |
|
|
467 | ~rxvt_ptytty_proxy (); |
462 | ~rxvt_ptytty_proxy (); |
468 | |
463 | |
469 | bool get (); |
464 | bool get (); |
470 | void login (int cmd_pid, bool login_shell, const char *hostname); |
465 | void login (int cmd_pid, bool login_shell, const char *hostname); |
471 | }; |
466 | }; |
… | |
… | |
544 | write (sock_fd, &cmd.id, sizeof (cmd.id)); |
539 | write (sock_fd, &cmd.id, sizeof (cmd.id)); |
545 | } |
540 | } |
546 | } |
541 | } |
547 | else if (cmd.type == command::login) |
542 | else if (cmd.type == command::login) |
548 | { |
543 | { |
|
|
544 | #if UTMP_SUPPORT |
549 | if (find (ptys.begin (), ptys.end (), cmd.id)) |
545 | if (find (ptys.begin (), ptys.end (), cmd.id)) |
550 | { |
546 | { |
551 | cmd.hostname[sizeof (cmd.hostname) - 1] = 0; |
547 | cmd.hostname[sizeof (cmd.hostname) - 1] = 0; |
552 | cmd.id->login (cmd.cmd_pid, cmd.login_shell, cmd.hostname); |
548 | cmd.id->login (cmd.cmd_pid, cmd.login_shell, cmd.hostname); |
553 | } |
549 | } |
554 | else printf ("xxx hiya login no match %p\n", cmd.id); |
550 | #endif |
555 | } |
551 | } |
556 | else if (cmd.type == command::destroy) |
552 | else if (cmd.type == command::destroy) |
557 | { |
553 | { |
558 | rxvt_ptytty **pty = find (ptys.begin (), ptys.end (), cmd.id); |
554 | rxvt_ptytty **pty = find (ptys.begin (), ptys.end (), cmd.id); |
559 | |
555 | |
560 | if (*pty) |
556 | if (pty) |
561 | { |
557 | { |
|
|
558 | delete *pty; |
562 | ptys.erase (pty); |
559 | ptys.erase (pty); |
563 | delete *pty; |
|
|
564 | } |
560 | } |
565 | else printf ("xxx hiya destroy no match %p\n", cmd.id); |
|
|
566 | } |
561 | } |
567 | else |
562 | else |
568 | break; |
563 | break; |
569 | } |
564 | } |
570 | |
565 | |
… | |
… | |
592 | close (sv[1]); |
587 | close (sv[1]); |
593 | fcntl (sock_fd, F_SETFD, FD_CLOEXEC); |
588 | fcntl (sock_fd, F_SETFD, FD_CLOEXEC); |
594 | } |
589 | } |
595 | else |
590 | else |
596 | { |
591 | { |
|
|
592 | setgid (getegid ()); |
|
|
593 | setuid (geteuid ()); |
|
|
594 | |
597 | // server, pty-helper |
595 | // server, pty-helper |
598 | sock_fd = sv[1]; |
596 | sock_fd = sv[1]; |
599 | |
597 | |
600 | close (sv[0]);//D |
|
|
601 | // for (int fd = 0; fd < 1023; fd++) |
598 | for (int fd = 0; fd < 1023; fd++) |
602 | // if (fd != sock_fd) |
599 | if (fd != sock_fd && fd != 1) |
603 | // close (fd); |
600 | close (fd); |
604 | |
601 | |
605 | serve (); |
602 | serve (); |
606 | _exit (EXIT_SUCCESS); |
603 | _exit (EXIT_SUCCESS); |
607 | } |
604 | } |
608 | } |
605 | } |
… | |
… | |
612 | rxvt_ptytty * |
609 | rxvt_ptytty * |
613 | rxvt_new_ptytty () |
610 | rxvt_new_ptytty () |
614 | { |
611 | { |
615 | #if PTYTTY_HELPER |
612 | #if PTYTTY_HELPER |
616 | if (pid > 0) |
613 | if (pid > 0) |
617 | { |
|
|
618 | // use helper process |
614 | // use helper process |
619 | return new rxvt_ptytty_proxy; |
615 | return new rxvt_ptytty_proxy; |
620 | } |
|
|
621 | else |
616 | else |
622 | #endif |
617 | #endif |
623 | return new rxvt_ptytty_unix; |
618 | return new rxvt_ptytty_unix; |
624 | } |
619 | } |
625 | |
620 | |