New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SASL Authentication for Clients #1573
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1308,6 +1308,14 @@ class CModule { | |
*/ | ||
virtual void OnClientCapRequest(CClient* pClient, const CString& sCap, | ||
bool bState); | ||
virtual EModRet OnSaslServerChallenge(const CString& sMechanism, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New module callbacks need couple of lines in modules/mod{perl,python}/functions.in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any comments? While other comments are good to have, these are mandatory - module hooks are the most important part of ZNC API |
||
CString& sResponse); | ||
virtual EModRet OnClientSaslAuthenticate(const CString& sMechanism, | ||
const CString& sBuffer, | ||
CString& sUser, | ||
CString& sMechanismResponse, | ||
bool& bAuthenticationSuccess); | ||
virtual void OnGetSaslMechanisms(SCString& ssMechanisms); | ||
|
||
/** Called when a module is going to be loaded. | ||
* @param sModName name of the module. | ||
|
@@ -1587,6 +1595,15 @@ class CModules : public std::vector<CModule*>, private CCoreTranslationMixin { | |
bool IsClientCapSupported(CClient* pClient, const CString& sCap, | ||
bool bState); | ||
bool OnClientCapRequest(CClient* pClient, const CString& sCap, bool bState); | ||
bool OnSaslServerChallenge(const CString& sMechanism, | ||
CString& sResponse); | ||
bool OnClientSaslAuthenticate(const CString& sMechanism, | ||
const CString& sBuffer, | ||
CString& sUser, | ||
CString& sResponse, | ||
bool& bAuthenticationSuccess); | ||
bool OnGetSaslMechanisms(SCString& ssMechanisms); | ||
|
||
bool OnModuleLoading(const CString& sModName, const CString& sArgs, | ||
CModInfo::EModuleType eType, bool& bSuccess, | ||
CString& sRetMsg); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2004-2018 ZNC, see the NOTICE file for details. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <znc/User.h> | ||
#include <znc/znc.h> | ||
|
||
class CSASLMechanismPlain : public CModule { | ||
public: | ||
MODCONSTRUCTOR(CSASLMechanismPlain) { AddHelpCommand(); } | ||
|
||
EModRet OnClientSaslAuthenticate(const CString& sMechanism, | ||
const CString& sBuffer, CString& sUser, | ||
CString& sMechanismResponse, | ||
bool& bAuthenticationSuccess) override { | ||
if (!sMechanism.Equals("PLAIN")) { | ||
return CONTINUE; | ||
} | ||
|
||
bAuthenticationSuccess = false; | ||
|
||
CString sNullSeparator = std::string("\0", 1); | ||
auto sAuthzId = sBuffer.Token(0, false, sNullSeparator); | ||
auto sAuthcId = sBuffer.Token(1, false, sNullSeparator); | ||
auto sPassword = sBuffer.Token(2, false, sNullSeparator); | ||
|
||
if (sAuthzId.empty()) sAuthzId = sAuthcId; | ||
|
||
auto pUser = CZNC::Get().FindUser(sAuthcId); | ||
|
||
if (!sAuthcId.empty() && !sPassword.empty()) { | ||
if (pUser->CheckPass(sPassword)) { | ||
bAuthenticationSuccess = true; | ||
sUser = sAuthcId; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. run clang-format |
||
} | ||
|
||
return HALTMODS; | ||
} | ||
|
||
void OnGetSaslMechanisms(SCString& ssMechanisms) override { | ||
ssMechanisms.insert("PLAIN"); | ||
} | ||
}; | ||
|
||
template <> | ||
void TModInfo<CSASLMechanismPlain>(CModInfo& Info) { | ||
Info.SetWikiPage("saslplain"); | ||
} | ||
|
||
GLOBALMODULEDEFS( | ||
CSASLMechanismPlain, | ||
t_s("Allows users to authenticate via the PLAIN SASL mechanism.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment would help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps more of a question, given the code style below with
OnCTCPMessage
, the acronym is capitalised. Should we do the same here?