mirror of
https://github.com/znc/znc.git
synced 2026-08-09 10:23:14 +02:00
Add clang-format configuration.
For now, it uses tabs like before, to make the diff easier to read/check. One of following commits will switch it to spaces.
This commit is contained in:
+37
-33
@@ -21,33 +21,34 @@ using std::map;
|
||||
class CIMAPAuthMod;
|
||||
|
||||
class CIMAPSock : public CSocket {
|
||||
public:
|
||||
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();
|
||||
: 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");
|
||||
m_spAuth->RefuseLogin(
|
||||
"IMAP server is down, please try again later");
|
||||
}
|
||||
}
|
||||
|
||||
void ReadLine(const CString& sLine) override;
|
||||
private:
|
||||
protected:
|
||||
CIMAPAuthMod* m_pIMAPMod;
|
||||
bool m_bSentLogin;
|
||||
bool m_bSentReply;
|
||||
|
||||
private:
|
||||
protected:
|
||||
CIMAPAuthMod* m_pIMAPMod;
|
||||
bool m_bSentLogin;
|
||||
bool m_bSentReply;
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
};
|
||||
|
||||
|
||||
class CIMAPAuthMod : public CModule {
|
||||
public:
|
||||
public:
|
||||
MODCONSTRUCTOR(CIMAPAuthMod) {
|
||||
m_Cache.SetTTL(60000);
|
||||
m_sServer = "localhost";
|
||||
@@ -57,13 +58,11 @@ public:
|
||||
|
||||
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
|
||||
return true; // use defaults
|
||||
}
|
||||
|
||||
m_sServer = sArgs.Token(0);
|
||||
@@ -87,12 +86,15 @@ public:
|
||||
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
|
||||
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())) {
|
||||
if (pUser &&
|
||||
m_Cache.HasItem(CString(Auth->GetUsername() + ":" +
|
||||
Auth->GetPassword()).MD5())) {
|
||||
DEBUG("+++ Found in cache");
|
||||
Auth->AcceptLogin(*pUser);
|
||||
return HALT;
|
||||
@@ -104,22 +106,19 @@ public:
|
||||
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
|
||||
private:
|
||||
private:
|
||||
// Settings
|
||||
CString m_sServer;
|
||||
unsigned short m_uPort;
|
||||
bool m_bSSL;
|
||||
CString m_sUserFormat;
|
||||
CString m_sServer;
|
||||
unsigned short m_uPort;
|
||||
bool m_bSSL;
|
||||
CString m_sUserFormat;
|
||||
// !Settings
|
||||
|
||||
TCacheMap<CString> m_Cache;
|
||||
@@ -140,13 +139,17 @@ void CIMAPSock::ReadLine(const CString& sLine) {
|
||||
}
|
||||
}
|
||||
|
||||
Write("AUTH LOGIN " + sUsername + " " + m_spAuth->GetPassword() + "\r\n");
|
||||
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);
|
||||
m_pIMAPMod->CacheLogin(CString(m_spAuth->GetUsername() + ":" + m_spAuth->GetPassword()).MD5()); // Use MD5 so passes don't sit in memory in plain text
|
||||
m_pIMAPMod->CacheLogin(
|
||||
CString(m_spAuth->GetUsername() + ":" + m_spAuth->GetPassword())
|
||||
.MD5()); // Use MD5 so passes don't sit in memory in plain
|
||||
// text
|
||||
DEBUG("+++ Successful IMAP lookup");
|
||||
} else {
|
||||
m_spAuth->RefuseLogin("Invalid Password");
|
||||
@@ -158,7 +161,8 @@ void CIMAPSock::ReadLine(const CString& sLine) {
|
||||
}
|
||||
}
|
||||
|
||||
template<> void TModInfo<CIMAPAuthMod>(CModInfo& Info) {
|
||||
template <>
|
||||
void TModInfo<CIMAPAuthMod>(CModInfo& Info) {
|
||||
Info.SetWikiPage("imapauth");
|
||||
Info.SetHasArgs(true);
|
||||
Info.SetArgsHelpText("[ server [+]port [ UserFormatString ] ]");
|
||||
|
||||
Reference in New Issue
Block a user