- initiate disconnect on timeout in NETWrite

- SCStore store now also context and macro state
- changed logging functionality (CompactCommandLog option)
This commit is contained in:
zolliker
2008-01-18 07:16:27 +00:00
parent 59cf229551
commit dbabdbee49

193
conman.c
View File

@ -96,6 +96,15 @@ extern pServer pServ;
static long lastIdent = 0; static long lastIdent = 0;
/*------------- sending connection (prevent double write when listening) ----*/ /*------------- sending connection (prevent double write when listening) ----*/
static SConnection *sendingConnection = NULL; static SConnection *sendingConnection = NULL;
/*------------- storing connection and context for later use ----*/
struct SCStore {
SConnection *pCon;
long ident;
int inMacro;
int inMacroSave;
int pushLevel;
commandContext cc;
};
/*===========================================================================*/ /*===========================================================================*/
static char *ConName(long ident) { static char *ConName(long ident) {
static char name[32]; static char name[32];
@ -383,7 +392,7 @@ extern pServer pServ;
free(pVictim->pSock); free(pVictim->pSock);
pVictim->pSock = NULL; pVictim->pSock = NULL;
} }
WriteToCommandLog("SYS> ", WriteToCommandLog("SYS>",
"ERROR: Erraneous deletion of used Connection stopped"); "ERROR: Erraneous deletion of used Connection stopped");
return; return;
} }
@ -400,7 +409,7 @@ extern pServer pServ;
root = GetHipadabaRoot(); root = GetHipadabaRoot();
if(root != NULL) if(root != NULL)
{ {
InternalRemoveHipadabaCallback(root,pVictim->ident); InternalRemoveHipadabaCallback(root,pVictim);
} }
/* /*
@ -416,7 +425,8 @@ extern pServer pServ;
} }
/* log the kill */ /* log the kill */
if(pVictim->pSock && pVictim->iLogin == 1) if(pVictim->pSock && pVictim->iLogin == 1 &&
(pVictim->iUserRights < 3 || !CompactCommandLog()) )
{ {
sprintf(pBueffel,"Deleting connection %d",pVictim->pSock->sockid); sprintf(pBueffel,"Deleting connection %d",pVictim->pSock->sockid);
WriteToCommandLog("SYS>",pBueffel); WriteToCommandLog("SYS>",pBueffel);
@ -640,8 +650,10 @@ static int doSockWrite(SConnection *self, char *buffer)
if(!iRet) if(!iRet)
{ {
SCnoSock(self); SCnoSock(self);
if(!self->listening && self->iLogin == 1){ if(!self->listening && self->iLogin == 1 &&
WriteToCommandLog("SYS> ","Connection broken on send"); (self->iUserRights < 3 || !CompactCommandLog()) )
{
WriteToCommandLog("SYS>","Connection broken on send");
} }
} }
} }
@ -705,18 +717,16 @@ static void writeToLogFiles(SConnection *self, char *buffer)
{ {
if(self->iMacro != 1) if(self->iMacro != 1)
{ {
sprintf(pBueffel,"To sock %d :",iRet);
sendingConnection = self; sendingConnection = self;
WriteToCommandLog(pBueffel,buffer); WriteToCommandLogId(NULL,iRet,buffer);
sendingConnection = NULL; sendingConnection = NULL;
} }
else else
{ {
if(iOut == eError || iOut == eWarning) if(iOut == eError || iOut == eWarning)
{ {
sprintf(pBueffel,"To sock %d :",iRet);
sendingConnection = self; sendingConnection = self;
WriteToCommandLog(pBueffel,buffer); WriteToCommandLogId(NULL,iRet,buffer);
sendingConnection = NULL; sendingConnection = NULL;
} }
} }
@ -780,18 +790,16 @@ static void writeToLogFiles(SConnection *self, char *buffer)
{ {
if(self->iMacro != 1) if(self->iMacro != 1)
{ {
sprintf(pBueffel,"To sock %d :",iRet);
sendingConnection = self; sendingConnection = self;
WriteToCommandLog(pBueffel,buffer); WriteToCommandLogId(NULL,iRet,buffer);
sendingConnection = NULL; sendingConnection = NULL;
} }
else else
{ {
if(iOut == eError || iOut == eWarning) if(iOut == eError || iOut == eWarning)
{ {
sprintf(pBueffel,"To sock %d :",iRet);
sendingConnection = self; sendingConnection = self;
WriteToCommandLog(pBueffel,buffer); WriteToCommandLogId(NULL,iRet,buffer);
sendingConnection = NULL; sendingConnection = NULL;
} }
} }
@ -865,9 +873,8 @@ static void writeToLogFiles(SConnection *self, char *buffer)
/* write to commandlog if user or manager privilege */ /* write to commandlog if user or manager privilege */
if(SCGetRights(self) <= usUser && self->iMacro != 1) if(SCGetRights(self) <= usUser && self->iMacro != 1)
{ {
sprintf(pBueffel,"To sock %d :",iRet);
sendingConnection = self; sendingConnection = self;
WriteToCommandLog(pBueffel,buffer); WriteToCommandLogId(NULL,iRet,buffer);
sendingConnection = NULL; sendingConnection = NULL;
} }
@ -1049,12 +1056,7 @@ pDynString SCEndBuffering(SConnection *pCon)
return 0; return 0;
} }
/* put into Serverlog */ /* log it for any case */
sprintf(pBueffel,"Next line intended for socket: %d",-10);
SICSLogWrite(pBueffel,eInternal);
SICSLogWrite(buffer,iOut);
/* log it for any case */
if(self->pSock) if(self->pSock)
{ {
iRet = self->pSock->sockid; iRet = self->pSock->sockid;
@ -1063,21 +1065,29 @@ pDynString SCEndBuffering(SConnection *pCon)
{ {
iRet = -10; iRet = -10;
} }
/* put into Serverlog */
sprintf(pBueffel,"Next line intended for socket: %d",iRet);
SICSLogWrite(pBueffel,eInternal);
SICSLogWrite(buffer,iOut);
/* write to commandlog if user or manager privilege */ /* write to commandlog if user or manager privilege */
if(SCGetRights(self) <= usUser) if(SCGetRights(self) <= usUser)
{ {
if(self->iMacro != 1) if(self->iMacro != 1)
{ {
sprintf(pBueffel,"To sock %d :",iRet); sendingConnection = self;
WriteToCommandLog(pBueffel,buffer); WriteToCommandLogId(NULL,iRet,buffer);
sendingConnection = NULL;
} }
else else
{ {
if(iOut == eError || iOut == eWarning) if(iOut == eError || iOut == eWarning)
{ {
sprintf(pBueffel,"To sock %d :",iRet); sendingConnection = self;
WriteToCommandLog(pBueffel,buffer); WriteToCommandLogId(NULL,iRet,buffer);
sendingConnection = NULL;
} }
} }
} }
@ -1459,8 +1469,7 @@ pDynString SCEndBuffering(SConnection *pCon)
SetStatus(eOld); SetStatus(eOld);
CostaLock(pCon->pStack); CostaLock(pCon->pStack);
strncpy(pResult,pPtr,iLen); strncpy(pResult,pPtr,iLen);
sprintf(pFrom,"Prompted from sock %2.2d: ", pCon->pSock->sockid); WriteToCommandLogId(" prompted>", pCon->pSock->sockid, pPtr);
WriteToCommandLog(pFrom,pPtr);
return 1; return 1;
} }
} }
@ -1560,14 +1569,6 @@ pDynString SCEndBuffering(SConnection *pCon)
/* print to command log if user or manager */ /* print to command log if user or manager */
if(SCGetRights(self) <= usUser) if(SCGetRights(self) <= usUser)
{ {
if(self->pSock != NULL)
{
sprintf(pBueffel,"sock %d>>",self->pSock->sockid);
}
else
{
strcat(pBueffel,"CONT or CRON>> ");
}
/* /*
* This is a fix to suppress cron messages in the success * This is a fix to suppress cron messages in the success
* case * case
@ -1575,7 +1576,12 @@ pDynString SCEndBuffering(SConnection *pCon)
if(SCGetWriteFunc(self) != SCNotWrite) if(SCGetWriteFunc(self) != SCNotWrite)
{ {
sendingConnection = self; sendingConnection = self;
WriteToCommandLog(pBueffel,pCommand); if(self->pSock != NULL)
{
WriteToCommandLogCmd(self->pSock->sockid, pCommand);
} else {
WriteToCommandLog("CRON>>",pCommand);
}
sendingConnection = NULL; sendingConnection = NULL;
} }
} }
@ -1620,6 +1626,7 @@ pDynString SCEndBuffering(SConnection *pCon)
int argc, char *argv[]) int argc, char *argv[])
{ {
char pBueffel[512]; char pBueffel[512];
char pHost[132];
int i, iRet; int i, iRet;
int iNum; int iNum;
@ -1779,10 +1786,19 @@ pDynString SCEndBuffering(SConnection *pCon)
SCWrite(pCon,pBueffel,eError); SCWrite(pCon,pBueffel,eError);
return 0; return 0;
} }
if (CompactCommandLog()) {
if (pCon->iUserRights < 3 || i < 3) {
NETInfo(pCon->pSock,pHost,sizeof pHost);
sprintf(pBueffel,"User %s from %s switched to %d privilege",
argv[2],pHost,i);
WriteToCommandLogId("SYS>",pCon->pSock->sockid,pBueffel);
}
} else {
sprintf(pBueffel,"User %s socket %d switched to %d privilege",
argv[2],pCon->pSock->sockid,i);
WriteToCommandLog("SYS>",pBueffel);
}
pCon->iUserRights = i; pCon->iUserRights = i;
sprintf(pBueffel,"User %s socket %d switched to %d privilege",
argv[2],pCon->pSock->sockid,i);
WriteToCommandLog("SYS>",pBueffel);
SCWrite(pCon,"Change of Authorisation Acknowledged",eWarning); SCWrite(pCon,"Change of Authorisation Acknowledged",eWarning);
return 1; return 1;
} }
@ -2035,6 +2051,11 @@ pDynString SCEndBuffering(SConnection *pCon)
{ {
return 0; return 0;
} }
if(self->pSock->iType == 0)
{
NetReadRemove(pServ->pReader,self->pSock);
self->iEnd = 1;
}
if(self->iEnd) if(self->iEnd)
{ {
@ -2102,11 +2123,21 @@ pDynString SCEndBuffering(SConnection *pCon)
self->iLogin = 1; self->iLogin = 1;
SCSetRights(self,iRet); SCSetRights(self,iRet);
pHost[0] = '\0'; pHost[0] = '\0';
NETInfo(self->pSock,pHost,131); if (CompactCommandLog()) {
sprintf(pBueffel,"Accepted connection %s on socket %d from %s", if (iRet < 3) {
ConName(self->ident), self->pSock->sockid, pHost); NETInfo(self->pSock,pHost,131);
SICSLogWrite(pBueffel,eInternal); sprintf(pBueffel,"Accepted connection %s from %s as %s",
WriteToCommandLog("SYS >", pBueffel); ConName(self->ident), pHost, pUser);
SICSLogWrite(pBueffel,eInternal);
WriteToCommandLogId("SYS>", self->pSock->sockid, pBueffel);
}
} else {
NETInfo(self->pSock,pHost,131);
sprintf(pBueffel,"Accepted connection %s on socket %d from %s",
ConName(self->ident), self->pSock->sockid, pHost);
SICSLogWrite(pBueffel,eInternal);
WriteToCommandLog("SYS >", pBueffel);
}
free(pPtr); free(pPtr);
return 1; return 1;
} }
@ -2208,25 +2239,79 @@ int SCActive(SConnection *self)
return 0; return 0;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
void SCSave(SCStore *con, SConnection *pCon) { SCStore SCSave(SConnection *pCon, SCStore oldStore) {
con->pCon = pCon; commandContext cc;
if (pCon) {
con->ident = pCon->ident; if (oldStore == NULL) {
oldStore = calloc(1,sizeof(*oldStore));
assert(oldStore);
} }
oldStore->pCon = pCon;
if (pCon) {
oldStore->ident = pCon->ident;
oldStore->inMacro = pCon->iMacro;
oldStore->cc = SCGetContext(pCon);
oldStore->pushLevel = 0;
}
return oldStore;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
SConnection *SCLoad(SCStore *con) { SConnection *SCLoad(SCStore conStore) {
SConnection *pCon; SConnection *pCon = NULL;
commandContext old;
pCon = con->pCon;
if (conStore) {
pCon = conStore->pCon;
}
if (pCon) { if (pCon) {
if (con->ident != pCon->ident) { if (conStore->ident != pCon->ident) {
con->pCon = NULL; /* connection is dead */ conStore->pCon = NULL; /* connection is dead */
pCon = NULL; pCon = NULL;
} }
} }
if (pCon) {
return pCon;
}
return pServ->dummyCon;
}
/*--------------------------------------------------------------------------*/
SConnection *SCStorePush(SCStore conStore) {
SConnection *pCon;
pCon = SCLoad(conStore);
if (conStore->pushLevel == 0) {
if (conStore->inMacro) {
conStore->inMacroSave = pCon->iMacro;
pCon->iMacro = conStore->inMacro;
}
}
conStore->pushLevel++;
SCPushContext2(pCon, conStore->cc);
return pCon; return pCon;
} }
/*--------------------------------------------------------------------------*/
void SCStorePop(SCStore conStore) {
SConnection *pCon;
pCon = SCLoad(conStore);
if (conStore->pushLevel > 0) {
SCPopContext(pCon);
conStore->pushLevel--;
if (conStore->pushLevel == 0) {
pCon->iMacro = conStore->inMacroSave;
}
}
}
/*--------------------------------------------------------------------------*/
int SCStoreConnected(SCStore conStore) {
return (conStore &&
conStore->pCon &&
conStore->pCon->ident == conStore->ident);
}
/*--------------------------------------------------------------------------*/
void SCStoreFree(SCStore conStore) {
free(conStore);
}
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
long SCTagContext(SConnection *self, char *tagName) long SCTagContext(SConnection *self, char *tagName)
{ {