Debian Codegraph @

sadmin/raregetty

raw
1 #!/usr/bin/perl
2 # SPDX-License-Identifier: MIT
3 #
4 # raregetty
5 # written by Jan Engelhardt, 2004-2007
6
7 chdir "/var/lib/empty";
8 chroot "/var/lib/empty";
9
10 use Getopt::Long;
11 use strict;
12
13 my($Clearscr, $Noreopen);
14 my $Defaulthost = "127.0.0.1";
15 my $Host = "*";
16
17 &Getopt::Long::Configure(qw(bundling pass_through));
18 &GetOptions(
19 "c" => \$Clearscr,
20 "d=s" => \$Defaulthost,
21 "h=s" => \$Host,
22 "n" => \$Noreopen,
23 );
24
25 my $Tty = pop @ARGV;
26 &query4ssh();
27
28 sub query4ssh ()
29 {
30 my $login;
31
32 &reopen_ttys();
33 $< = $> = 65534;
34
35 while ($login eq "") {
36 if ($Clearscr) {
37 print "\e[1;1H\e[2J";
38 }
39 print "login: ";
40 chomp($login = <STDIN>);
41 }
42
43 if ($Host eq "*") {
44 print "host [$Defaulthost]: ";
45 chomp($Host = <STDIN>);
46 if( $Host eq "") {
47 $Host = $Defaulthost;
48 }
49 }
50
51 exit(exec "ssh", $login."\@".$Host);
52 }
53
54 sub reopen_ttys ()
55 {
56 if (!$Noreopen) {
57 open(STDIN, "< /dev/$Tty");
58 open(STDOUT, "> /dev/$Tty");
59 open(STDERR, "> /dev/$Tty");
60 }
61 select((select(STDOUT), $| = 1)[0]);
62 select((select(STDERR), $| = 1)[0]);
63 return;
64 }