mirror of
https://github.com/znc/znc.git
synced 2026-08-07 09:22:55 +02:00
clang-format: switch tabs to spaces
I like tabs, but I have to admit that spaces make source code more consistent, because every editor/viewer tends to render tabs differently :(
This commit is contained in:
+105
-105
@@ -22,150 +22,150 @@ class CIMAPAuthMod;
|
||||
|
||||
class CIMAPSock : public CSocket {
|
||||
public:
|
||||
CIMAPSock(CIMAPAuthMod* pModule, std::shared_ptr<CAuthBase> Auth)
|
||||
: CSocket((CModule*)pModule), m_spAuth(Auth) {
|
||||
m_pIMAPMod = pModule;
|
||||
m_bSentReply = false;
|
||||
m_bSentLogin = false;
|
||||
EnableReadLine();
|
||||
}
|
||||
CIMAPSock(CIMAPAuthMod* pModule, std::shared_ptr<CAuthBase> Auth)
|
||||
: CSocket((CModule*)pModule), m_spAuth(Auth) {
|
||||
m_pIMAPMod = pModule;
|
||||
m_bSentReply = false;
|
||||
m_bSentLogin = false;
|
||||
EnableReadLine();
|
||||
}
|
||||
|
||||
virtual ~CIMAPSock() {
|
||||
if (!m_bSentReply) {
|
||||
m_spAuth->RefuseLogin(
|
||||
"IMAP server is down, please try again later");
|
||||
}
|
||||
}
|
||||
virtual ~CIMAPSock() {
|
||||
if (!m_bSentReply) {
|
||||
m_spAuth->RefuseLogin(
|
||||
"IMAP server is down, please try again later");
|
||||
}
|
||||
}
|
||||
|
||||
void ReadLine(const CString& sLine) override;
|
||||
void ReadLine(const CString& sLine) override;
|
||||
|
||||
private:
|
||||
protected:
|
||||
CIMAPAuthMod* m_pIMAPMod;
|
||||
bool m_bSentLogin;
|
||||
bool m_bSentReply;
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
CIMAPAuthMod* m_pIMAPMod;
|
||||
bool m_bSentLogin;
|
||||
bool m_bSentReply;
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
};
|
||||
|
||||
class CIMAPAuthMod : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CIMAPAuthMod) {
|
||||
m_Cache.SetTTL(60000);
|
||||
m_sServer = "localhost";
|
||||
m_uPort = 143;
|
||||
m_bSSL = false;
|
||||
}
|
||||
MODCONSTRUCTOR(CIMAPAuthMod) {
|
||||
m_Cache.SetTTL(60000);
|
||||
m_sServer = "localhost";
|
||||
m_uPort = 143;
|
||||
m_bSSL = false;
|
||||
}
|
||||
|
||||
virtual ~CIMAPAuthMod() {}
|
||||
virtual ~CIMAPAuthMod() {}
|
||||
|
||||
bool OnBoot() override { return true; }
|
||||
bool OnBoot() override { return true; }
|
||||
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
if (sArgs.Trim_n().empty()) {
|
||||
return true; // use defaults
|
||||
}
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
if (sArgs.Trim_n().empty()) {
|
||||
return true; // use defaults
|
||||
}
|
||||
|
||||
m_sServer = sArgs.Token(0);
|
||||
CString sPort = sArgs.Token(1);
|
||||
m_sUserFormat = sArgs.Token(2);
|
||||
m_sServer = sArgs.Token(0);
|
||||
CString sPort = sArgs.Token(1);
|
||||
m_sUserFormat = sArgs.Token(2);
|
||||
|
||||
if (sPort.Left(1) == "+") {
|
||||
m_bSSL = true;
|
||||
sPort.LeftChomp();
|
||||
}
|
||||
if (sPort.Left(1) == "+") {
|
||||
m_bSSL = true;
|
||||
sPort.LeftChomp();
|
||||
}
|
||||
|
||||
unsigned short uPort = sPort.ToUShort();
|
||||
unsigned short uPort = sPort.ToUShort();
|
||||
|
||||
if (uPort) {
|
||||
m_uPort = uPort;
|
||||
}
|
||||
if (uPort) {
|
||||
m_uPort = uPort;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) override {
|
||||
CUser* pUser = CZNC::Get().FindUser(Auth->GetUsername());
|
||||
EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) override {
|
||||
CUser* pUser = CZNC::Get().FindUser(Auth->GetUsername());
|
||||
|
||||
if (!pUser) {
|
||||
// @todo Will want to do some sort of && !m_bAllowCreate in the
|
||||
// future
|
||||
Auth->RefuseLogin("Invalid User - Halting IMAP Lookup");
|
||||
return HALT;
|
||||
}
|
||||
if (!pUser) {
|
||||
// @todo Will want to do some sort of && !m_bAllowCreate in the
|
||||
// future
|
||||
Auth->RefuseLogin("Invalid User - Halting IMAP Lookup");
|
||||
return HALT;
|
||||
}
|
||||
|
||||
if (pUser &&
|
||||
m_Cache.HasItem(CString(Auth->GetUsername() + ":" +
|
||||
Auth->GetPassword()).MD5())) {
|
||||
DEBUG("+++ Found in cache");
|
||||
Auth->AcceptLogin(*pUser);
|
||||
return HALT;
|
||||
}
|
||||
if (pUser &&
|
||||
m_Cache.HasItem(CString(Auth->GetUsername() + ":" +
|
||||
Auth->GetPassword()).MD5())) {
|
||||
DEBUG("+++ Found in cache");
|
||||
Auth->AcceptLogin(*pUser);
|
||||
return HALT;
|
||||
}
|
||||
|
||||
CIMAPSock* pSock = new CIMAPSock(this, Auth);
|
||||
pSock->Connect(m_sServer, m_uPort, m_bSSL, 20);
|
||||
CIMAPSock* pSock = new CIMAPSock(this, Auth);
|
||||
pSock->Connect(m_sServer, m_uPort, m_bSSL, 20);
|
||||
|
||||
return HALT;
|
||||
}
|
||||
return HALT;
|
||||
}
|
||||
|
||||
void OnModCommand(const CString& sLine) override {}
|
||||
void OnModCommand(const CString& sLine) override {}
|
||||
|
||||
void CacheLogin(const CString& sLogin) { m_Cache.AddItem(sLogin); }
|
||||
void CacheLogin(const CString& sLogin) { m_Cache.AddItem(sLogin); }
|
||||
|
||||
// Getters
|
||||
const CString& GetUserFormat() const { return m_sUserFormat; }
|
||||
// !Getters
|
||||
// Getters
|
||||
const CString& GetUserFormat() const { return m_sUserFormat; }
|
||||
// !Getters
|
||||
private:
|
||||
// Settings
|
||||
CString m_sServer;
|
||||
unsigned short m_uPort;
|
||||
bool m_bSSL;
|
||||
CString m_sUserFormat;
|
||||
// !Settings
|
||||
// Settings
|
||||
CString m_sServer;
|
||||
unsigned short m_uPort;
|
||||
bool m_bSSL;
|
||||
CString m_sUserFormat;
|
||||
// !Settings
|
||||
|
||||
TCacheMap<CString> m_Cache;
|
||||
TCacheMap<CString> m_Cache;
|
||||
};
|
||||
|
||||
void CIMAPSock::ReadLine(const CString& sLine) {
|
||||
if (!m_bSentLogin) {
|
||||
CString sUsername = m_spAuth->GetUsername();
|
||||
m_bSentLogin = true;
|
||||
if (!m_bSentLogin) {
|
||||
CString sUsername = m_spAuth->GetUsername();
|
||||
m_bSentLogin = true;
|
||||
|
||||
const CString& sFormat = m_pIMAPMod->GetUserFormat();
|
||||
const CString& sFormat = m_pIMAPMod->GetUserFormat();
|
||||
|
||||
if (!sFormat.empty()) {
|
||||
if (sFormat.find('%') != CString::npos) {
|
||||
sUsername = sFormat.Replace_n("%", sUsername);
|
||||
} else {
|
||||
sUsername += sFormat;
|
||||
}
|
||||
}
|
||||
if (!sFormat.empty()) {
|
||||
if (sFormat.find('%') != CString::npos) {
|
||||
sUsername = sFormat.Replace_n("%", sUsername);
|
||||
} else {
|
||||
sUsername += sFormat;
|
||||
}
|
||||
}
|
||||
|
||||
Write("AUTH LOGIN " + sUsername + " " + m_spAuth->GetPassword() +
|
||||
"\r\n");
|
||||
} else if (sLine.Left(5) == "AUTH ") {
|
||||
CUser* pUser = CZNC::Get().FindUser(m_spAuth->GetUsername());
|
||||
Write("AUTH LOGIN " + sUsername + " " + m_spAuth->GetPassword() +
|
||||
"\r\n");
|
||||
} else if (sLine.Left(5) == "AUTH ") {
|
||||
CUser* pUser = CZNC::Get().FindUser(m_spAuth->GetUsername());
|
||||
|
||||
if (pUser && sLine.StartsWith("AUTH OK")) {
|
||||
m_spAuth->AcceptLogin(*pUser);
|
||||
// Use MD5 so passes don't sit in memory in plain text
|
||||
m_pIMAPMod->CacheLogin(CString(m_spAuth->GetUsername() + ":" +
|
||||
m_spAuth->GetPassword()).MD5());
|
||||
DEBUG("+++ Successful IMAP lookup");
|
||||
} else {
|
||||
m_spAuth->RefuseLogin("Invalid Password");
|
||||
DEBUG("--- FAILED IMAP lookup");
|
||||
}
|
||||
if (pUser && sLine.StartsWith("AUTH OK")) {
|
||||
m_spAuth->AcceptLogin(*pUser);
|
||||
// Use MD5 so passes don't sit in memory in plain text
|
||||
m_pIMAPMod->CacheLogin(CString(m_spAuth->GetUsername() + ":" +
|
||||
m_spAuth->GetPassword()).MD5());
|
||||
DEBUG("+++ Successful IMAP lookup");
|
||||
} else {
|
||||
m_spAuth->RefuseLogin("Invalid Password");
|
||||
DEBUG("--- FAILED IMAP lookup");
|
||||
}
|
||||
|
||||
m_bSentReply = true;
|
||||
Close();
|
||||
}
|
||||
m_bSentReply = true;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void TModInfo<CIMAPAuthMod>(CModInfo& Info) {
|
||||
Info.SetWikiPage("imapauth");
|
||||
Info.SetHasArgs(true);
|
||||
Info.SetArgsHelpText("[ server [+]port [ UserFormatString ] ]");
|
||||
Info.SetWikiPage("imapauth");
|
||||
Info.SetHasArgs(true);
|
||||
Info.SetArgsHelpText("[ server [+]port [ UserFormatString ] ]");
|
||||
}
|
||||
|
||||
GLOBALMODULEDEFS(CIMAPAuthMod, "Allow users to authenticate via IMAP.")
|
||||
|
||||
Reference in New Issue
Block a user