diff --git a/ChangeLog b/ChangeLog index 1d440729..594341ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21360,3 +21360,5 @@ classes. 2021-03-31 Fred Gleason * Modernized indentation style of all switch() statements in caed(8). +2021-03-31 Fred Gleason + * Added syslog messages for tracking connection states in caed(8). diff --git a/cae/cae.cpp b/cae/cae.cpp index dd97c074..fb83d68d 100644 --- a/cae/cae.cpp +++ b/cae/cae.cpp @@ -1740,6 +1740,10 @@ void MainObject::KillSocket(int ch) for(int i=0;ipeerAddress(ch).toString().toUtf8().constData(), + 0xFFFF&cae_server->peerPort(ch), + i,j,GetHandle(i,j)); unsigned len=0; switch(cae_driver[i]) { case RDStation::Hpi: @@ -1764,6 +1768,11 @@ void MainObject::KillSocket(int ch) record_owner[i][j]=-1; } if(play_owner[i][j]==ch) { + RDApplication::syslog(rd_config,LOG_DEBUG,"force unloading play context for connection %d [%s:%u]: Card: %d Stream: %d Handle: %d", + ch, + cae_server->peerAddress(ch).toString().toUtf8().constData(), + 0xFFFF&cae_server->peerPort(ch), + i,j,GetHandle(i,j)); switch(cae_driver[i]) { case RDStation::Hpi: hpiUnloadPlayback(i,j); diff --git a/cae/cae_server.cpp b/cae/cae_server.cpp index 7ad2bfd0..9140a812 100644 --- a/cae/cae_server.cpp +++ b/cae/cae_server.cpp @@ -2,7 +2,7 @@ // // Network server for caed(8). // -// (C) Copyright 2019 Fred Gleason +// (C) Copyright 2019-2021 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -160,7 +160,9 @@ void CaeServer::newConnectionData() cae_connections[sock->socketDescriptor()]=new CaeServerConnection(sock); RDApplication::syslog(cae_config,LOG_DEBUG, - "added connection %d",sock->socketDescriptor()); + "added connection %d [%s:%u]",sock->socketDescriptor(), + sock->peerAddress().toString().toUtf8().constData(), + 0xFFFF&sock->peerPort()); } @@ -190,12 +192,26 @@ void CaeServer::readyReadData(int id) void CaeServer::connectionClosedData(int id) { + QString logmsg= + QString().sprintf("removed connection %d [%s:%u]", + id, + peerAddress(id).toString().toUtf8().constData(), + 0xFFFF&peerPort(id)); + int priority=LOG_DEBUG; + if(!cae_connections.value(id)->authenticated) { + logmsg= + QString().sprintf("removed never authenticated connection %d [%s:%u]", + id, + peerAddress(id).toString().toUtf8().constData(), + 0xFFFF&peerPort(id)); + priority=LOG_WARNING; + } emit connectionDropped(id); cae_connections.value(id)->socket->disconnect(); delete cae_connections.value(id); cae_connections.remove(id); - RDApplication::syslog(cae_config,LOG_DEBUG,"removed connection %d",id); + RDApplication::syslog(cae_config,priority,"%s",logmsg.toUtf8().constData()); } @@ -203,6 +219,7 @@ bool CaeServer::ProcessCommand(int id,const QString &cmd) { CaeServerConnection *conn=cae_connections.value(id); bool ok=false; + QString cmdstr=cmd; QStringList f0=cmd.split(" ",QString::SkipEmptyParts); if(f0.size()==0) { @@ -227,10 +244,22 @@ bool CaeServer::ProcessCommand(int id,const QString &cmd) if((f0.size()==2)&&(f0.at(1)==cae_config->password())) { conn->authenticated=true; sendCommand(id,"PW +!"); + RDApplication::syslog(cae_config,LOG_DEBUG, + "PASSED authentication: connection %d [%s:%u]", + id, + peerAddress(id).toString().toUtf8().constData(), + 0xFFFF&peerPort(id)); } else { conn->authenticated=false; sendCommand(id,"PW -!"); + RDApplication::syslog(cae_config,LOG_WARNING, + "FAILED authentication: connection %d [%s:%u]", + id, + peerAddress(id).toString().toUtf8().constData(), + 0xFFFF&peerPort(id)); + connectionClosedData(id); + return true; } return false; } @@ -240,7 +269,14 @@ bool CaeServer::ProcessCommand(int id,const QString &cmd) // Authentication required to execute these! // if(!conn->authenticated) { - return false; + RDApplication::syslog(cae_config,LOG_WARNING, + "unauthenticated connection %d [%s:%u] sent command \"%s\"", + id, + peerAddress(id).toString().toUtf8().constData(), + 0xFFFF&peerPort(id), + cmdstr.toUtf8().constData()); + connectionClosedData(id); + return true; } bool was_processed=false; @@ -557,6 +593,12 @@ bool CaeServer::ProcessCommand(int id,const QString &cmd) if(!was_processed) { // Send generic error response sendCommand(id,f0.join(" ")+"-!"); + RDApplication::syslog(cae_config,LOG_WARNING, + "connection %d [%s:%u] sent unrecognized command \"%s\"", + id, + peerAddress(id).toString().toUtf8().constData(), + 0xFFFF&peerPort(id), + cmdstr.toUtf8().constData()); } return false;