X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnntp%2Fnntpconnection.cpp;h=b3eeecc583734ef824dcc2c111a0a01a58546768;hb=0574a75431d98ed64c5cc6291600bb3759b399a6;hp=078c1c3da4d1e815696d5758214ed757381ad2b9;hpb=52c0819bfc1d083c6e0738f75f0d7eeba521295a;p=fms.git diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index 078c1c3..b3eeecc 100644 --- a/src/nntp/nntpconnection.cpp +++ b/src/nntp/nntpconnection.cpp @@ -28,6 +28,7 @@ NNTPConnection::NNTPConnection(SOCKET sock) m_status.m_boardid=-1; m_status.m_messageid=-1; m_status.m_mode=MODE_NONE; + m_status.m_authenticated=false; Option::Instance()->Get("NNTPAllowPost",tempval); if(tempval=="true") @@ -68,6 +69,58 @@ const bool NNTPConnection::HandleArticleCommand(const NNTPCommand &command) return true; } +const bool NNTPConnection::HandleAuthInfoCommand(const NNTPCommand &command) +{ + if(command.m_arguments.size()<2) + { + SendBufferedLine("501 Syntax error"); + } + else if(m_status.m_authenticated==true) + { + SendBufferedLine("502 Command unavailable"); // not available when already authenticated + } + else + { + std::string arg=command.m_arguments[0]; + StringFunctions::UpperCase(arg,arg); + std::string name=""; + // get remaining args as part of the name since a name might have a space and the args are split on spaces + for(std::vector::const_iterator i=command.m_arguments.begin()+1; i!=command.m_arguments.end(); i++) + { + // we split on the space, so add it back + if(i!=command.m_arguments.begin()+1) + { + name+=" "; + } + name+=(*i); + } + if(arg=="USER") + { + LocalIdentity localid; + if(localid.Load(name)) + { + m_status.m_authuser=localid; + m_status.m_authenticated=true; + SendBufferedLine("281 Authentication accepted"); + } + else + { + SendBufferedLine("481 Authentication failed"); + } + } + else if(arg=="PASS") + { + SendBufferedLine("482 Authentication commands issued out of sequence"); // only require username + } + else + { + SendBufferedLine("501 Syntax error"); + } + } + + return true; +} + const bool NNTPConnection::HandleBodyCommand(const NNTPCommand &command) { SendArticleParts(command); @@ -80,7 +133,10 @@ const bool NNTPConnection::HandleCapabilitiesCommand(const NNTPCommand &command) SendBufferedLine("101 Capability list :"); SendBufferedLine("VERSION 2"); - SendBufferedLine("MODE-READER"); + if(m_status.m_authenticated==false) // RFC 4643 2.2 0 - don't advertise MODE-READER after authentication + { + SendBufferedLine("MODE-READER"); + } SendBufferedLine("READER"); SendBufferedLine("LIST OVERVIEW.FMT"); SendBufferedLine("OVER MSGID"); @@ -88,6 +144,10 @@ const bool NNTPConnection::HandleCapabilitiesCommand(const NNTPCommand &command) { SendBufferedLine("POST"); } + if(m_status.m_authenticated==false) + { + SendBufferedLine("AUTHINFO USER"); + } SendBufferedLine("."); return true; @@ -163,6 +223,10 @@ const bool NNTPConnection::HandleCommand(const NNTPCommand &command) { return HandleOverCommand(command); } + if(command.m_command=="AUTHINFO") + { + return HandleAuthInfoCommand(command); + } return false; } @@ -317,7 +381,7 @@ const bool NNTPConnection::HandleListCommand(const NNTPCommand &command) show=uwildmat((*i).GetBoardName().c_str(),arg2.c_str()); } - if(show==true) + if(show==true && (*i).GetSaveReceivedMessages()==true) { tempstr << (*i).GetBoardName() << " " << (*i).GetHighMessageID() << " " << (*i).GetLowMessageID() << " " << (m_status.m_allowpost ? "y" : "n"); SendBufferedLine(tempstr.str()); @@ -348,7 +412,7 @@ const bool NNTPConnection::HandleListCommand(const NNTPCommand &command) show=uwildmat((*i).GetBoardName().c_str(),arg2.c_str()); } - if(show==true) + if(show==true && (*i).GetSaveReceivedMessages()==true) { tempstr << (*i).GetBoardName() << "\t" << (*i).GetBoardDescription(); SendBufferedLine(tempstr.str()); @@ -559,9 +623,12 @@ const bool NNTPConnection::HandleNewGroupsCommand(const NNTPCommand &command) for(BoardList::iterator i=bl.begin(); i!=bl.end(); i++) { - std::ostringstream tempstr; - tempstr << (*i).GetBoardName() << " " << (*i).GetHighMessageID() << " " << (*i).GetLowMessageID() << " " << m_status.m_allowpost ? "y" : "n"; - SendBufferedLine(tempstr.str()); + if((*i).GetSaveReceivedMessages()==true) + { + std::ostringstream tempstr; + tempstr << (*i).GetBoardName() << " " << (*i).GetHighMessageID() << " " << (*i).GetLowMessageID() << " " << m_status.m_allowpost ? "y" : "n"; + SendBufferedLine(tempstr.str()); + } } SendBufferedLine("."); @@ -780,15 +847,24 @@ void NNTPConnection::HandlePostedMessage(const std::string &message) if(mess.ParseNNTPMessage(message)) { + // if we authenticated, set the username to the authenticated user + if(m_status.m_authenticated) + { + mess.SetFromName(m_status.m_authuser.GetName()); + } + // handle a messages posted to an adminboard if(mess.PostedToAdministrationBoard()==true) { mess.HandleAdministrationMessage(); } + if(mess.StartFreenetInsert()) + { + SendBufferedLine("240 Article received OK"); + } else { - mess.StartFreenetInsert(); + SendBufferedLine("441 Posting failed. Make sure the identity you are sending with exists!"); } - SendBufferedLine("240 Article received OK"); } else {