- Reworked the connection object and the IO system

- Reworked the support for TRICS
- Added a second generation motor
This commit is contained in:
koennecke
2009-02-03 08:05:39 +00:00
parent f6d595665e
commit 361ee9ebea
119 changed files with 16455 additions and 3674 deletions

160
telnet.c
View File

@ -91,7 +91,7 @@
NETWrite(pCon->pSock,pReply,2);
}
/*--------------------------------------------------------------------------*/
int TelnetTask(void *pData)
int TelnetTaskOld(void *pData)
{
pTelTask self = NULL;
char *pPtr = NULL;
@ -204,6 +204,134 @@
}
/* check for end */
if(self->pCon->iEnd)
{
if(SCActive(self->pCon))
{
return 1;
}
else
{
return 0;
}
}
return 1;
}
/*--------------------------------------------------------------------------*/
int TelnetTask(void *pData)
{
pTelTask self = NULL;
char *pPtr = NULL;
char *pLogin = NULL;
char *pUser = NULL, *pPasswd = NULL;
char pBuffer[512], pHost[131];
int iRet;
time_t shit;
self = (pTelTask)pData;
assert(self);
if(self->pCon->iEnd)
{
if(SCActive(self->pCon))
{
return 1;
}
else
{
return 0;
}
}
/* pop and execute */
iRet = CostaPop(self->pCon->pStack,&pPtr);
if(iRet)
{
if(pPtr)
{
if(self->iLogin) /* handle normal command */
{
/* check for logoff */
if(strstr(pPtr,"logoff") != NULL)
{
ANETclose(self->pCon->sockHandle);
free(pPtr);
self->pCon->iEnd = 1;
return 0;
}
/* invoke command */
CostaLock(self->pCon->pStack);
SCInvoke(self->pCon,pServ->pSics,pPtr);
CostaUnlock(self->pCon->pStack);
SendGA(self->pCon);
free(pPtr);
}
else /* handle login messages */
{
pLogin = strstr(pPtr,self->pLoginWord);
if(!pLogin)
{
SCWrite(self->pCon,
"------------------- Get Lost -------------------",
eError);
if(time(&shit) > self->tStart + LOGINWAIT)
{
SCWrite(self->pCon,
"I cannot stand your login attempts anymore!",
eError);
ANETclose(self->pCon->sockHandle);
self->pCon->iEnd = 1;
free(pPtr);
return 0;
}
free(pPtr);
return 1;
}
else /* check username / password */
{
pLogin += strlen(self->pLoginWord);
pUser = strtok(pLogin," \t");
pPasswd = strtok(NULL," \t\r\n");
iRet = IsValidUser(pUser,pPasswd);
if(iRet < 0)
{
sprintf(pBuffer,"SYSTEM ATTACK by %s / %s",pUser,
pPasswd);
SICSLogWrite(pBuffer,eInternal);
SCWrite(self->pCon,
"I do not know you, I do not let you in",eError);
SendGA(self->pCon);
free(pPtr);
return 1;
}
else
{
sprintf(pBuffer,"Accepted telnet connection on handle %d",
self->pCon->sockHandle);
SICSLogWrite(pBuffer,eInternal);
WriteToCommandLog("SYS >", pBuffer);
SendWelcome(self->pCon);
SCSetRights(self->pCon,iRet);
self->iLogin = 1;
SendGA(self->pCon);
free(pPtr);
return 1;
}
}
}
}
}
/* check for no commands but timeout on telnet */
if( !self->iLogin && (time(&shit) > self->tStart + LOGINWAIT) )
{
self->pCon->iEnd = 1;
ANETclose(self->pCon->sockHandle);
return 0;
}
/* check for end */
if(self->pCon->iEnd)
{
@ -273,16 +401,20 @@
return;
}
i = sscanf(pPtr,"%d",&iPort);
/*
if(i > 0)
{
pTelnet = NETOpenPort(iPort);
}
/* when we have a port have the NetReader listen and handle it */
if(pTelnet)
{
NetReadRegister(pServ->pReader,pTelnet, taccept, NULL);
}
*/
/* when we have a port have the NetReader listen and handle it */
NetReadInstallANETPort(pServ->pReader,taccept, iPort);
}
/*---------------------------------------------------------------------------*/
void KillTelnet(void)
@ -296,3 +428,27 @@
}
}
/*------------------------------------------------------------------------
Telnet is fully described in RFC-854. This implementation is very simple.
It just supports the NVT and no options. Implementation is via a state
machine with the state tStatus in the pItem structure. This is necessary
as single characters may be sent by telnet clients.
-------------------------------------------------------------------------*/
/* Telnet codes */
#define SE 240
#define NOP 241
#define DM 242 /* data mark */
#define BRK 243
#define IP 244
#define AO 245
#define AYT 246
#define EC 247
#define EL 248
#define GA 249
#define SB 250
#define WILL 251
#define WONT 252
#define DO 253
#define DONT 254
#define IAC 255
#define EOR 239