Using perl with Inetd

I have a perl script I want to run on port 23, my evential goal is to
have a script anonymous users can telnet to so they can sign up an
account on a server.

Before anyone worries about security, this is a NetBSD box that's on a
local network at my place of work, it's not publically accessable.

So far I've just written a very simple test script, a proof of concept
of you will, I don't like running before I can walk :)

I've called my script telnet.pl and have put the following in
/etc/inetd.conf:

telnet stream tcp nowait root /root/bin/telnet.pl
telnet.pl

Here is the script itself:

#!/usr/pkg/bin/perl

$|=1;
print ("Y/n: ");
my $choice = <STDIN>;
chomp($choice);
if ($choice =~ /\r$/) { chop $choice; }
if ($choice eq "y") {
print ("OK");
} else {
print ("No match");
}
print("\n");
print("Debugging: \$choice = \"$choice\"\n");
exit(0);

If I run it from the command line, it does what you'd expect it to:

Y/n: y
OK
Debugging: $choice = "y"

However, when run from telnet, you get this:

Y/n: y
No match
Debugging: $choice = "y"

Any assistance will be greatfully recieved!

Ben
Ben Brown [ Di, 27 September 2005 12:16 ] [ ID #986348 ]

Re: Using perl with Inetd

Ben Brown <ben [at] 427.org.uk> wrote in comp.lang.perl.misc:
> I have a perl script I want to run on port 23, my evential goal is to
> have a script anonymous users can telnet to so they can sign up an
> account on a server.
>
> Before anyone worries about security, this is a NetBSD box that's on a
> local network at my place of work, it's not publically accessable.
>
> So far I've just written a very simple test script, a proof of concept
> of you will, I don't like running before I can walk :)
>
> I've called my script telnet.pl and have put the following in
> /etc/inetd.conf:
>
> telnet stream tcp nowait root /root/bin/telnet.pl
> telnet.pl
>
> Here is the script itself:
>
> #!/usr/pkg/bin/perl
>
> $|=1;
> print ("Y/n: ");
> my $choice = <STDIN>;
> chomp($choice);
> if ($choice =~ /\r$/) { chop $choice; }
> if ($choice eq "y") {
> print ("OK");
> } else {
> print ("No match");
> }
> print("\n");
> print("Debugging: \$choice = \"$choice\"\n");
> exit(0);
>
> If I run it from the command line, it does what you'd expect it to:
>
> Y/n: y
> OK
> Debugging: $choice = "y"
>
> However, when run from telnet, you get this:
>
> Y/n: y
> No match
> Debugging: $choice = "y"

You probably get different line feeds from what you expect. Try (untested)

$choice =~ s/\s+$//;

to verify.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
anno4000 [ Di, 27 September 2005 12:36 ] [ ID #986349 ]

Re: Using perl with Inetd

Ben Brown <ben [at] 427.org.uk> wrote in comp.lang.perl.misc:
> I have a perl script I want to run on port 23, my evential goal is to
> have a script anonymous users can telnet to so they can sign up an
> account on a server.
>
> Before anyone worries about security, this is a NetBSD box that's on a
> local network at my place of work, it's not publically accessable.
>
> So far I've just written a very simple test script, a proof of concept
> of you will, I don't like running before I can walk :)
>
> I've called my script telnet.pl and have put the following in
> /etc/inetd.conf:
>
> telnet stream tcp nowait root /root/bin/telnet.pl
> telnet.pl
>
> Here is the script itself:
>
> #!/usr/pkg/bin/perl
>
> $|=1;
> print ("Y/n: ");
> my $choice = <STDIN>;
> chomp($choice);
> if ($choice =~ /\r$/) { chop $choice; }
> if ($choice eq "y") {
> print ("OK");
> } else {
> print ("No match");
> }
> print("\n");
> print("Debugging: \$choice = \"$choice\"\n");
> exit(0);
>
> If I run it from the command line, it does what you'd expect it to:
>
> Y/n: y
> OK
> Debugging: $choice = "y"
>
> However, when run from telnet, you get this:
>
> Y/n: y
> No match
> Debugging: $choice = "y"

You probably get different line feeds from what you expect. Try (untested)

$choice =~ s/\s+$//;

to verify.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
anno4000 [ Di, 27 September 2005 12:36 ] [ ID #986401 ]

Re: Using perl with Inetd

On Tue, 27 Sep 2005 11:16:34 +0100,
Ben Brown <ben [at] 427.org.uk> wrote:


>
> However, when run from telnet, you get this:
>
> Y/n: y
> No match
> Debugging: $choice = "y"
>
> Any assistance will be greatfully recieved!
>

You sure $choice doesn't contain invisible characters? These characters
could come from the telnet client doing protocol negotiation.

Villy
Villy Kruse [ Di, 27 September 2005 12:37 ] [ ID #986402 ]

Re: Using perl with Inetd

Villy Kruse wrote:
> On Tue, 27 Sep 2005 11:16:34 +0100,
> Ben Brown <ben [at] 427.org.uk> wrote:
>
>
>
>>However, when run from telnet, you get this:
>>
>>Y/n: y
>>No match
>>Debugging: $choice = "y"
>>
>>Any assistance will be greatfully recieved!
>>
>
>
> You sure $choice doesn't contain invisible characters? These characters
> could come from the telnet client doing protocol negotiation.
>
> Villy

I'm pretty sure that it does have invisible characters, it's trying to
find out what they are I'm having trouble with.

I've tried $choice =~ s/\s+$//; but it's still the same.

Cheers,

Ben
Ben Brown [ Mi, 28 September 2005 12:41 ] [ ID #988471 ]

Re: Using perl with Inetd

On Wed, 28 Sep 2005 11:41:20 +0100,
Ben Brown <nospam [at] 427.thetrash.org.uk> wrote:


>
> I'm pretty sure that it does have invisible characters, it's trying to
> find out what they are I'm having trouble with.
>
> I've tried $choice =~ s/\s+$//; but it's still the same.
>


For example unpack the string:

print unpack('H*', $choice), "\n";

Villy
Villy Kruse [ Mi, 28 September 2005 13:23 ] [ ID #988475 ]

Re: Using perl with Inetd

Villy Kruse wrote:
> On Wed, 28 Sep 2005 11:41:20 +0100,
> Ben Brown <nospam [at] 427.thetrash.org.uk> wrote:
>
>
>
>>I'm pretty sure that it does have invisible characters, it's trying to
>>find out what they are I'm having trouble with.
>>
>>I've tried $choice =~ s/\s+$//; but it's still the same.
>>
>
>
>
> For example unpack the string:
>
> print unpack('H*', $choice), "\n";
>
> Villy

Thanks for that. Using that it shows that the following is being added
by telnet at the start of the variable:

fffb25fffd26fffb26fffd03fffb18fffb1ffffb20fffb21fffb22fffb27 fffd05

Any ideas how to strip this out?
Ben Brown [ Mi, 28 September 2005 14:04 ] [ ID #988478 ]

Re: Using perl with Inetd

Ben Brown <nospam [at] 427.thetrash.org.uk> wrote:
> Villy Kruse wrote:


>> You sure $choice doesn't contain invisible characters?

> I'm pretty sure that it does have invisible characters, it's trying to
> find out what they are I'm having trouble with.


Then write code that will look for them for you.

Something like:

foreach my $char (split //, $choice) {
my $chnum = ord($char);

next if $chnum >= 32 && $chnum <= 126; # "normal" ASCII

my $hex = sprintf '0x%X', $chnum;
my $oct = sprintf '0%o', $chnum;
print "$chnum $oct ($hex)\n";
}


--
Tad McClellan SGML consulting
tadmc [at] augustmail.com Perl programming
Fort Worth, Texas
Tad McClellan [ Mi, 28 September 2005 14:30 ] [ ID #988485 ]
Perl » alt.perl » Using perl with Inetd

Vorheriges Thema: perl inside batch files?
Nächstes Thema: Website scraper