🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages Started by Colin B Maharaj Fri, 22 Jun 2007 09:43
Telnet Server just a note and a proposal
#994
Author: Colin B Maharaj
Date: Fri, 22 Jun 2007 09:43
41 lines
2380 bytes
Hi all I had been struggling with the IdTelnetServer all week.
By default, the windows Telnet client echos what you type on screen.

What happens next is that is when you try to authenticate, naturally
the username ands password gets echoed to the screen along with your 
entire session.

What I did was this in the onconnect.....

//---------------------------------------------------------------------------
void __fastcall TDataModule1::TelnetConnect(TIdPeerThread *AThread)
{
   unsigned char s[4];
   s[0]=(unsigned char)255;
   s[1]=(unsigned char)254;
   s[2]=(unsigned char)1;
   s[3]=NULL;
   AThread->Connection->Write(s);
   Sleep(250);
   AThread->Connection->ReadBuffer(s, 3);
   AnsiString init="Connected to Server. You have 3 Login Attempts...\r\n";
   AThread->Connection->WriteLn(init);
}
//---------------------------------------------------------------------------

Those three characters are telnet protocol commands that tell
the telnet client not to echo characters. Check the RFC.

The ReadBuffer command is required because the three characters
that comprise the command gets echoed into the password field
for some reason.

What I want to propose is to do this in the original indy source, or 
have an option echo on/off in the property editor.

BTW: I use Indy 9.0.50 on BCB6 Ent. And I do not have Indy 10 maybe
one of you folks can test to see if it has the same issue.

(just my 2 cents)
Colin B Maharaj
Trinidad, WI.
Re: Telnet Server just a note and a proposal
#995
Author: Colin B Maharaj
Date: Fri, 22 Jun 2007 10:03
66 lines
3353 bytes
opps!
Change unsigned char s[4] to just char s[4] like this.....

//---------------------------------------------------------------------------
void __fastcall TDataModule1::TelnetConnect(TIdPeerThread *AThread)
{
   char s[4];
   s[0]=(unsigned char)255;
   s[1]=(unsigned char)254;
   s[2]=(unsigned char)1;
   s[3]=NULL;
   AThread->Connection->Write(s);
   Sleep(250);
   AThread->Connection->ReadBuffer(s, 3);
   AnsiString init="Connected to Server. You have 3 Login Attempts...\r\n";
   AThread->Connection->WriteLn(init);
}
//---------------------------------------------------------------------------



Colin B Maharaj wrote:
> Hi all I had been struggling with the IdTelnetServer all week.
> By default, the windows Telnet client echos what you type on screen.
> 
> What happens next is that is when you try to authenticate, naturally
> the username ands password gets echoed to the screen along with your 
> entire session.
> 
> What I did was this in the onconnect.....
> 
> //--------------------------------------------------------------------------- 
> 
> void __fastcall TDataModule1::TelnetConnect(TIdPeerThread *AThread)
> {
>   unsigned char s[4];
>   s[0]=(unsigned char)255;
>   s[1]=(unsigned char)254;
>   s[2]=(unsigned char)1;
>   s[3]=NULL;
>   AThread->Connection->Write(s);
>   Sleep(250);
>   AThread->Connection->ReadBuffer(s, 3);
>   AnsiString init="Connected to Server. You have 3 Login Attempts...\r\n";
>   AThread->Connection->WriteLn(init);
> }
> //--------------------------------------------------------------------------- 
> 
> 
> Those three characters are telnet protocol commands that tell
> the telnet client not to echo characters. Check the RFC.
> 
> The ReadBuffer command is required because the three characters
> that comprise the command gets echoed into the password field
> for some reason.
> 
> What I want to propose is to do this in the original indy source, or 
> have an option echo on/off in the property editor.
> 
> BTW: I use Indy 9.0.50 on BCB6 Ent. And I do not have Indy 10 maybe
> one of you folks can test to see if it has the same issue.
> 
> (just my 2 cents)
> Colin B Maharaj
> Trinidad, WI.
> 
Re: Telnet Server just a note and a proposal
#1004
Author: Remy Lebeau (TeamB)
Date: Fri, 22 Jun 2007 17:33
87 lines
3738 bytes
"Colin B Maharaj" <noreply@myhost.com> wrote in message
news:467b99a3$1@newsgroups.borland.com...

> What I did was this in the onconnect.....

Echoing is a negotiated property.  But you are ignoring the negotiated
reply to know whether the echoing was actually turned off or not.

Use the OnNegotiate event instead of the OnConnect event directly.
OnNegotiate is triggered automatically after the OnConnect event
handler exits.  That would be a better place to send your WONT
request.

The only caveat is that TIdTelnetServer always echoes back login
characters unconditionally.  To get around that, you won't be able to
use the OnAuthentication event at all.  In the OnNegotiate event, you
can send your own login prompts and then read back the replies,
echoing only if needed.

For example (untested):

    void __fastcall TForm1::IdTelnetServer1Negotiate(TIdPeerThread
*AThread)
    {
        unsigned char s[3];
        bool ClientIsEchoing = true;

        s[0] = 0xFF; // IAC
        s[1] = 0xFE; // DONT
        s[2] = 0x01; // ECHO

        AThread->Connection->WriteBuffer(s, 3);

        AThread->Connection->ReadBuffer(s, 3);
        if( (s[0] == 0xFF) && (s[2] == 0x01) )
        {
            switch( s[1] )
            {
                case 0xFC: // WONT
                    // echoing is disabled
                    ClientIsEchoing = false;
                    break;
                case 0xFB: // WILL
                    // echoing is still enabled
                    ClientIsEchoing = true;
                    break;
                default
                    // unexpected reply ...
                    break;
        }
        else
            // unexpected reply ...

        AThread->Connection->WriteLn("Connected to Server. You have 3
Login Attempts...\r\n");

        for(int i = 0; i < IdTelnetServer1->LoginAttempts; ++i)
        {
            AThread->Connection->Write("Username: ");
            ((TIdTelnetPeerThread*)AThread)->TelnetData->Username =
AThread->Connection->InputLn("", !ClientIsEchoing);

            AThread->Connection->Write("Password: ");
            ((TIdTelnetPeerThread*)AThread)->TelnetData->Password =
AThread->Connection->InputLn("*", !ClientIsEchoing);

            AThread->Connection->WriteLn();

            if( username/password is ok )
                return;

            AThread->Connection->WriteLn("Not logged in!");
        }

        throw EIdException("Max logins");
    }

> BTW: I use Indy 9.0.50 on BCB6 Ent. And I do not have Indy 10
> maybe one of you folks can test to see if it has the same issue.

TIdTelnetServer in Indy 10 works the exact same way that it does in
Indy 9.


Gambit
Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads