-
Notifications
You must be signed in to change notification settings - Fork 0
/
cap_sasl.cpp
108 lines (87 loc) · 2.77 KB
/
cap_sasl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
Implements SASL Authentication capability for charybdis family ircds
At present this only implements the PLAIN (base64) mechanism,
and as such should be used in conjunction with SSL where security is a
concern.
Usage: "LoadModule cap_sasl <accountname> <passsword>"
TODO: support for the more secure DH-BLOWFISH mechanism
(C)2010 Mike Quin
Licensed under the GNU General Public License
*/
#include "Modules.h"
#include "User.h"
#include "IRCSock.h"
class CSASLMod : public CModule {
public:
MODCONSTRUCTOR(CSASLMod) {}
virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
if (sArgs.Token(0).empty()){
m_sAccount=GetNV("SASL_Account");
} else {
m_sAccount=sArgs.Token(0);
SetNV("SASL_Account", m_sAccount);
}
if (sArgs.Token(1).empty()){
m_sPass=GetNV("SASL_Password");
} else {
m_sPass=sArgs.Token(1);
SetNV("SASL_Password", m_sPass);
}
SetArgs("");
return true;
}
virtual void OnModCommand(const CString& sCommand)
{
CString sCmdName = sCommand.Token(0).AsLower();
if (sCmdName == "set") {
CString sAccount = sCommand.Token(1);
CString sPass = sCommand.Token(2, true);
m_sPass = sPass;
m_sAccount = sAccount;
SetNV("SASL_Password", m_sPass);
SetNV("SASL_Account", m_sAccount);
PutModule("Password set");
} else if (sCmdName == "clear") {
m_sPass = "";
DelNV("SASL_Password");
DelNV("SASL_Account");
} else {
PutModule("Commands: set <accountname> <password>, clear");
}
}
virtual ~CSASLMod() {}
virtual bool OnServerCapAvailable(const CString& sCap) {
return sCap == "sasl";
}
virtual void OnServerCapResult(const CString& sCap, const bool state) {
CIRCSock *pIRCSock = GetUser()->GetIRCSock();
if (!pIRCSock)
return;
if (state == true && sCap == "sasl" && !m_sAccount.empty() && !m_sPass.empty() ) {
pIRCSock->PauseCap();
PutIRC("AUTHENTICATE PLAIN");
}
}
virtual EModRet OnRaw(CString &sLine) {
CIRCSock *pIRCSock = GetUser()->GetIRCSock();
if (!pIRCSock)
return CONTINUE;
if (sLine.Equals("AUTHENTICATE +") && !m_sAccount.empty() && !m_sPass.empty()) {
CString authdata = m_sAccount + '\0' + m_sAccount + '\0' + m_sPass;
authdata.Base64Encode();
// sasldata.Base64Encode();
PutIRC("AUTHENTICATE " + authdata);
} else if (sLine.Token(1).Equals("903") ||
sLine.Token(1).Equals("904") ||
sLine.Token(1).Equals("905") ||
sLine.Token(1).Equals("906") ||
sLine.Token(1).Equals("907") ) {
pIRCSock->ResumeCap();
}
return CONTINUE;
}
private:
CString m_sAccount;
CString m_sPass;
};
MODULEDEFS(CSASLMod, "Adds support for sasl authentication capability")