diff --git a/conman.c b/conman.c index b778188f..8f7aa792 100644 --- a/conman.c +++ b/conman.c @@ -96,6 +96,15 @@ extern pServer pServ; static long lastIdent = 0; /*------------- sending connection (prevent double write when listening) ----*/ 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 name[32]; @@ -383,7 +392,7 @@ extern pServer pServ; free(pVictim->pSock); pVictim->pSock = NULL; } - WriteToCommandLog("SYS> ", + WriteToCommandLog("SYS>", "ERROR: Erraneous deletion of used Connection stopped"); return; } @@ -400,7 +409,7 @@ extern pServer pServ; root = GetHipadabaRoot(); if(root != NULL) { - InternalRemoveHipadabaCallback(root,pVictim->ident); + InternalRemoveHipadabaCallback(root,pVictim); } /* @@ -416,7 +425,8 @@ extern pServer pServ; } /* 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); WriteToCommandLog("SYS>",pBueffel); @@ -640,8 +650,10 @@ static int doSockWrite(SConnection *self, char *buffer) if(!iRet) { SCnoSock(self); - if(!self->listening && self->iLogin == 1){ - WriteToCommandLog("SYS> ","Connection broken on send"); + if(!self->listening && self->iLogin == 1 && + (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) { - sprintf(pBueffel,"To sock %d :",iRet); sendingConnection = self; - WriteToCommandLog(pBueffel,buffer); + WriteToCommandLogId(NULL,iRet,buffer); sendingConnection = NULL; } else { if(iOut == eError || iOut == eWarning) { - sprintf(pBueffel,"To sock %d :",iRet); sendingConnection = self; - WriteToCommandLog(pBueffel,buffer); + WriteToCommandLogId(NULL,iRet,buffer); sendingConnection = NULL; } } @@ -780,18 +790,16 @@ static void writeToLogFiles(SConnection *self, char *buffer) { if(self->iMacro != 1) { - sprintf(pBueffel,"To sock %d :",iRet); sendingConnection = self; - WriteToCommandLog(pBueffel,buffer); + WriteToCommandLogId(NULL,iRet,buffer); sendingConnection = NULL; } else { if(iOut == eError || iOut == eWarning) { - sprintf(pBueffel,"To sock %d :",iRet); sendingConnection = self; - WriteToCommandLog(pBueffel,buffer); + WriteToCommandLogId(NULL,iRet,buffer); sendingConnection = NULL; } } @@ -865,9 +873,8 @@ static void writeToLogFiles(SConnection *self, char *buffer) /* write to commandlog if user or manager privilege */ if(SCGetRights(self) <= usUser && self->iMacro != 1) { - sprintf(pBueffel,"To sock %d :",iRet); sendingConnection = self; - WriteToCommandLog(pBueffel,buffer); + WriteToCommandLogId(NULL,iRet,buffer); sendingConnection = NULL; } @@ -1049,12 +1056,7 @@ pDynString SCEndBuffering(SConnection *pCon) return 0; } - /* put into Serverlog */ - sprintf(pBueffel,"Next line intended for socket: %d",-10); - SICSLogWrite(pBueffel,eInternal); - - SICSLogWrite(buffer,iOut); - /* log it for any case */ + /* log it for any case */ if(self->pSock) { iRet = self->pSock->sockid; @@ -1063,21 +1065,29 @@ pDynString SCEndBuffering(SConnection *pCon) { 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 */ if(SCGetRights(self) <= usUser) { if(self->iMacro != 1) { - sprintf(pBueffel,"To sock %d :",iRet); - WriteToCommandLog(pBueffel,buffer); + sendingConnection = self; + WriteToCommandLogId(NULL,iRet,buffer); + sendingConnection = NULL; } else { if(iOut == eError || iOut == eWarning) { - sprintf(pBueffel,"To sock %d :",iRet); - WriteToCommandLog(pBueffel,buffer); + sendingConnection = self; + WriteToCommandLogId(NULL,iRet,buffer); + sendingConnection = NULL; } } } @@ -1459,8 +1469,7 @@ pDynString SCEndBuffering(SConnection *pCon) SetStatus(eOld); CostaLock(pCon->pStack); strncpy(pResult,pPtr,iLen); - sprintf(pFrom,"Prompted from sock %2.2d: ", pCon->pSock->sockid); - WriteToCommandLog(pFrom,pPtr); + WriteToCommandLogId(" prompted>", pCon->pSock->sockid, pPtr); return 1; } } @@ -1560,14 +1569,6 @@ pDynString SCEndBuffering(SConnection *pCon) /* print to command log if user or manager */ 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 * case @@ -1575,7 +1576,12 @@ pDynString SCEndBuffering(SConnection *pCon) if(SCGetWriteFunc(self) != SCNotWrite) { sendingConnection = self; - WriteToCommandLog(pBueffel,pCommand); + if(self->pSock != NULL) + { + WriteToCommandLogCmd(self->pSock->sockid, pCommand); + } else { + WriteToCommandLog("CRON>>",pCommand); + } sendingConnection = NULL; } } @@ -1620,6 +1626,7 @@ pDynString SCEndBuffering(SConnection *pCon) int argc, char *argv[]) { char pBueffel[512]; + char pHost[132]; int i, iRet; int iNum; @@ -1779,10 +1786,19 @@ pDynString SCEndBuffering(SConnection *pCon) SCWrite(pCon,pBueffel,eError); 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; - 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); return 1; } @@ -2035,6 +2051,11 @@ pDynString SCEndBuffering(SConnection *pCon) { return 0; } + if(self->pSock->iType == 0) + { + NetReadRemove(pServ->pReader,self->pSock); + self->iEnd = 1; + } if(self->iEnd) { @@ -2102,11 +2123,21 @@ pDynString SCEndBuffering(SConnection *pCon) self->iLogin = 1; SCSetRights(self,iRet); pHost[0] = '\0'; - 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); + if (CompactCommandLog()) { + if (iRet < 3) { + NETInfo(self->pSock,pHost,131); + sprintf(pBueffel,"Accepted connection %s from %s as %s", + 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); return 1; } @@ -2208,25 +2239,79 @@ int SCActive(SConnection *self) return 0; } /*--------------------------------------------------------------------------*/ -void SCSave(SCStore *con, SConnection *pCon) { - con->pCon = pCon; - if (pCon) { - con->ident = pCon->ident; +SCStore SCSave(SConnection *pCon, SCStore oldStore) { + commandContext cc; + + 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 *pCon; - - pCon = con->pCon; +SConnection *SCLoad(SCStore conStore) { + SConnection *pCon = NULL; + commandContext old; + + if (conStore) { + pCon = conStore->pCon; + } if (pCon) { - if (con->ident != pCon->ident) { - con->pCon = NULL; /* connection is dead */ + if (conStore->ident != pCon->ident) { + conStore->pCon = NULL; /* connection is dead */ 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; } +/*--------------------------------------------------------------------------*/ +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) {