Permalink
Browse files

Fix logging in with PASS after USER

First, we set m_sUser to the argument of USER. Later, when the PASS came in, the
username which was specified here (user/network:pass) was ignored, because
m_sUser was already set ("if (m_sUser.empty() &&" in ParseAuthLine).

The fix is to ignore if m_sUser was already set when parsing "PASS". Since this
means that the handling of PASS and USER becomes even more different, this
commit removes CClient::ParseAuthLine() again.

(The check for m_sUser.empty() can't just be dropped, because if USER comes in
after PASS, we should use the user name from PASS and ignore the USER one)

Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information...
1 parent 9c9e40a commit 10c33112c4db33f088c103c3987a83ebdd56ed32 @psychon psychon committed Aug 29, 2011
Showing with 22 additions and 23 deletions.
  1. +22 −22 Client.cpp
  2. +0 −1 Client.h
View
@@ -69,25 +69,6 @@ CClient::~CClient() {
}
}
-void CClient::ParseAuthLine(CString sLine, bool bPassword) {
- // bPassword ? [user[/network]:]password : user[/network]
-
- if (bPassword) {
- if (sLine.find(":") == CString::npos) {
- m_sPass = sLine;
- sLine = "";
- } else {
- m_sPass = sLine.Token(1, true, ":");
- sLine = sLine.Token(0, false, ":");
- }
- }
-
- if (m_sUser.empty() && !sLine.empty()) {
- m_sUser = sLine.Token(0, false, "/");
- m_sNetwork = sLine.Token(1, true, "/");
- }
-}
-
void CClient::ReadLine(const CString& sData) {
CString sLine = sData;
@@ -118,7 +99,20 @@ void CClient::ReadLine(const CString& sData) {
sAuthLine.LeftChomp();
}
- ParseAuthLine(sAuthLine, true);
+ // [user[/network]:]password
+ if (sAuthLine.find(":") == CString::npos) {
+ m_sPass = sAuthLine;
+ sAuthLine = "";
+ } else {
+ m_sPass = sAuthLine.Token(1, true, ":");
+ sAuthLine = sAuthLine.Token(0, false, ":");
+ }
+
+ if (!sAuthLine.empty()) {
+ m_sUser = sAuthLine.Token(0, false, "/");
+ m_sNetwork = sAuthLine.Token(1, true, "/");
+ }
+
AuthUser();
return; // Don't forward this msg. ZNC has already registered us.
}
@@ -137,9 +131,15 @@ void CClient::ReadLine(const CString& sData) {
}
} else if (sCommand.Equals("USER")) {
if (!IsAttached()) {
- ParseAuthLine(sLine.Token(1));
- m_bGotUser = true;
+ // user[/network]
+ CString sAuthLine = sLine.Token(1);
+
+ if (m_sUser.empty() && !sAuthLine.empty()) {
+ m_sUser = sAuthLine.Token(0, false, "/");
+ m_sNetwork = sAuthLine.Token(1, true, "/");
+ }
+ m_bGotUser = true;
if (m_bGotPass) {
AuthUser();
} else {
View
@@ -122,7 +122,6 @@ class CClient : public CZNCSock {
bool SendMotd();
void HelpUser();
void AuthUser();
- void ParseAuthLine(CString sLine, bool bPassword = false);
virtual void Connected();
virtual void Timeout();
virtual void Disconnected();

0 comments on commit 10c3311

Please sign in to comment.