ZNC trunk
Loading...
Searching...
No Matches
User.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 ZNC, see the NOTICE file for details.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ZNC_USER_H
18#define ZNC_USER_H
19
20#include <znc/zncconfig.h>
21#include <znc/Utils.h>
22#include <znc/Buffer.h>
23#include <znc/Nick.h>
24#include <znc/Translation.h>
25#include <set>
26#include <vector>
27
28class CModules;
29class CChan;
30class CClient;
31class CConfig;
32class CFile;
33class CIRCNetwork;
34class CIRCSock;
35class CUserTimer;
36class CServer;
37
39 public:
40 CUser(const CString& sUsername);
42
43 CUser(const CUser&) = delete;
44 CUser& operator=(const CUser&) = delete;
45
46 bool ParseConfig(CConfig* Config, CString& sError);
47
48 enum eHashType {
53
54 // This should be kept in sync with CUtils::SaltedHash
55#if ZNC_HAVE_ARGON
57#else
59#endif
60 };
61
62 static CString SaltedHash(const CString& sPass, const CString& sSalt) {
63 return CUtils::SaltedHash(sPass, sSalt);
64 }
65
68 bool CheckPass(const CString& sPass);
69 bool AddAllowedHost(const CString& sHostMask);
70 bool RemAllowedHost(const CString& sHostMask);
72 bool IsHostAllowed(const CString& sHost) const;
73 bool IsValid(CString& sErrMsg, bool bSkipPass = false) const;
74 static bool IsValidUsername(const CString& sUsername);
76 static bool IsValidUserName(const CString& sUsername);
77 static CString MakeCleanUsername(const CString& sUsername);
79 static CString MakeCleanUserName(const CString& sUsername);
80
81 // Modules
83 const CModules& GetModules() const { return *m_pModules; }
84 // !Modules
85
86 // Networks
87 CIRCNetwork* AddNetwork(const CString& sNetwork, CString& sErrorRet);
88 bool DeleteNetwork(const CString& sNetwork);
89 bool AddNetwork(CIRCNetwork* pNetwork);
90 void RemoveNetwork(CIRCNetwork* pNetwork);
91 CIRCNetwork* FindNetwork(const CString& sNetwork) const;
92 const std::vector<CIRCNetwork*>& GetNetworks() const;
94 // !Networks
95
96 bool PutUser(const CString& sLine, CClient* pClient = nullptr,
97 CClient* pSkipClient = nullptr);
98 bool PutStatus(const CString& sLine, CClient* pClient = nullptr,
99 CClient* pSkipClient = nullptr);
100 bool PutStatusNotice(const CString& sLine, CClient* pClient = nullptr,
101 CClient* pSkipClient = nullptr);
102 bool PutModule(const CString& sModule, const CString& sLine,
103 CClient* pClient = nullptr, CClient* pSkipClient = nullptr);
104 bool PutModNotice(const CString& sModule, const CString& sLine,
105 CClient* pClient = nullptr,
106 CClient* pSkipClient = nullptr);
107
108 bool IsUserAttached() const;
109 void UserConnected(CClient* pClient);
110 void UserDisconnected(CClient* pClient);
111
113
114 CString ExpandString(const CString& sStr) const;
115 CString& ExpandString(const CString& sStr, CString& sRet) const;
116
117 CString AddTimestamp(const CString& sStr) const;
118 CString AddTimestamp(time_t tm, const CString& sStr) const;
119 CString AddTimestamp(timeval tv, const CString& sStr) const;
120
121 void CloneNetworks(const CUser& User);
122 bool Clone(const CUser& User, CString& sErrorRet,
123 bool bCloneNetworks = true);
125
126 void AddBytesRead(unsigned long long u) { m_uBytesRead += u; }
127 void AddBytesWritten(unsigned long long u) { m_uBytesWritten += u; }
128
129 // Setters
130 void SetNick(const CString& s);
131 void SetAltNick(const CString& s);
132 void SetIdent(const CString& s);
133 void SetRealName(const CString& s);
134 void SetBindHost(const CString& s);
135 void SetDCCBindHost(const CString& s);
136 void SetPass(const CString& s, eHashType eHash, const CString& sSalt = "");
137 void SetMultiClients(bool b);
138 void SetDenyLoadMod(bool b);
139 void SetAdmin(bool b);
140 void SetDenySetBindHost(bool b);
141 void SetDenySetIdent(bool b);
142 void SetDenySetNetwork(bool b);
143 void SetDenySetRealName(bool b);
144 void SetDenySetQuitMsg(bool b);
146 bool SetStatusPrefix(const CString& s);
149 void SetQuitMsg(const CString& s);
150 bool AddCTCPReply(const CString& sCTCP, const CString& sReply);
151 bool DelCTCPReply(const CString& sCTCP);
153 bool SetBufferCount(unsigned int u, bool bForce = false);
154 bool SetChanBufferSize(unsigned int u, bool bForce = false);
155 bool SetQueryBufferSize(unsigned int u, bool bForce = false);
158 bool SetLanguage(const CString& s);
159
160 void SetBeingDeleted(bool b) { m_bBeingDeleted = b; }
165 void SetTimezone(const CString& s) { m_sTimezone = s; }
166 void SetJoinTries(unsigned int i) { m_uMaxJoinTries = i; }
167 void SetMaxJoins(unsigned int i) { m_uMaxJoins = i; }
168 void SetSkinName(const CString& s) { m_sSkinName = s; }
169 void SetMaxNetworks(unsigned int i) { m_uMaxNetworks = i; }
170 void SetMaxQueryBuffers(unsigned int i) { m_uMaxQueryBuffers = i; }
171 void SetNoTrafficTimeout(unsigned int i) { m_uNoTrafficTimeout = i; }
172 // !Setters
173
174 // Getters
175 const std::vector<CClient*>& GetUserClients() const { return m_vClients; }
176 std::vector<CClient*> GetAllClients() const;
178 const CString& GetUserName() const;
179 const CString& GetUsername() const;
180 const CString& GetCleanUserName() const;
181 const CString& GetNick(bool bAllowDefault = true) const;
182 const CString& GetAltNick(bool bAllowDefault = true) const;
183 const CString& GetIdent(bool bAllowDefault = true) const;
185 const CString& GetBindHost() const;
186 const CString& GetDCCBindHost() const;
187 const CString& GetPass() const;
189 const CString& GetPassSalt() const;
190 const std::set<CString>& GetAllowedHosts() const;
193 bool GetTimestampAppend() const;
195
196 const CString& GetUserPath() const;
197
198 bool DenyLoadMod() const;
199 bool IsAdmin() const;
200 bool DenySetBindHost() const;
201 bool DenySetIdent() const;
202 bool DenySetNetwork() const;
203 bool DenySetRealName() const;
204 bool DenySetQuitMsg() const;
205 bool DenySetCTCPReplies() const;
206 bool MultiClients() const;
207 bool AuthOnlyViaModule() const;
208 const CString& GetStatusPrefix() const;
211 unsigned int GetPingFrequency() const { return m_uNoTrafficTimeout / 2; }
213 unsigned int GetPingSlack() const { return m_uNoTrafficTimeout / 6; }
217 unsigned int GetNoTrafficTimeout() const { return m_uNoTrafficTimeout; }
218
220 const MCString& GetCTCPReplies() const;
222 unsigned int GetBufferCount() const;
223 unsigned int GetChanBufferSize() const;
224 unsigned int GetQueryBufferSize() const;
227 bool IsBeingDeleted() const { return m_bBeingDeleted; }
228 CString GetTimezone() const { return m_sTimezone; }
229 unsigned long long BytesRead() const;
230 unsigned long long BytesWritten() const;
231 unsigned int JoinTries() const { return m_uMaxJoinTries; }
232 unsigned int MaxJoins() const { return m_uMaxJoins; }
235 unsigned int MaxNetworks() const { return m_uMaxNetworks; }
236 unsigned int MaxQueryBuffers() const { return m_uMaxQueryBuffers; }
237 // !Getters
238
239 protected:
253
259
260 // Paths
262 // !Paths
263
279
280 CUserTimer* m_pUserTimer;
281
282 std::vector<CIRCNetwork*> m_vIRCNetworks;
283 std::vector<CClient*> m_vClients;
284 std::set<CString> m_ssAllowedHosts;
285 unsigned int m_uChanBufferSize;
286 unsigned int m_uQueryBufferSize;
287 unsigned long long m_uBytesRead;
288 unsigned long long m_uBytesWritten;
289 unsigned int m_uMaxJoinTries;
290 unsigned int m_uMaxNetworks;
291 unsigned int m_uMaxQueryBuffers;
292 unsigned int m_uMaxJoins;
296
298
299 private:
300 void SetKeepBuffer(bool b) {
302 } // XXX compatibility crap, added in 0.207
303 bool LoadModule(const CString& sModName, const CString& sArgs,
304 const CString& sNotice, CString& sError);
305};
306
307#endif // !ZNC_USER_H
Definition Chan.h:35
Definition Client.h:99
Definition Config.h:36
Definition Translation.h:103
Definition FileUtils.h:30
Definition IRCNetwork.h:40
Definition IRCSock.h:35
Definition Modules.h:1543
Definition Server.h:23
String class that is used inside ZNC.
Definition ZNCString.h:50
Definition User.h:38
MCString m_mssCTCPReplies
Definition User.h:255
void SetBeingDeleted(bool b)
Definition User.h:160
void SetAutoClearQueryBuffer(bool b)
const CString & GetTimestampFormat() const
const CString m_sUsername
Definition User.h:240
void SetDenySetBindHost(bool b)
bool DenySetCTCPReplies() const
CUserTimer * m_pUserTimer
Definition User.h:280
const CString & GetBindHost() const
CString m_sDCCBindHost
Definition User.h:247
bool DenySetBindHost() const
const std::vector< CIRCNetwork * > & GetNetworks() const
CConfig ToConfig() const
const CString & GetAltNick(bool bAllowDefault=true) const
unsigned long long m_uBytesWritten
Definition User.h:288
const CString & GetUserPath() const
void SetDCCBindHost(const CString &s)
bool m_bDenySetCTCPReplies
Definition User.h:272
const CModules & GetModules() const
Definition User.h:83
bool PutUser(const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
void SetPass(const CString &s, eHashType eHash, const CString &sSalt="")
const CString & GetUserName() const
CUser & operator=(const CUser &)=delete
unsigned int m_uNoTrafficTimeout
Definition User.h:293
static bool IsValidUserName(const CString &sUsername)
bool m_bAutoClearChanBuffer
Definition User.h:273
CUser(const CUser &)=delete
unsigned int GetPingSlack() const
Time between checks if PINGs need to be sent.
Definition User.h:213
bool m_bDenySetBindHost
Definition User.h:267
bool AuthOnlyViaModule() const
CString m_sDefaultChanModes
Definition User.h:251
CString GetLocalDCCIP() const
const CString & GetIdent(bool bAllowDefault=true) const
void BounceAllClients()
void SetDenySetNetwork(bool b)
bool DenyLoadMod() const
const CString & GetCleanUserName() const
unsigned long long BytesWritten() const
void SetAutoClearChanBuffer(bool b)
void SetDefaultChanModes(const CString &s)
void SetTimestampFormat(const CString &s)
Definition User.h:161
bool AutoClearQueryBuffer() const
CString m_sLanguage
Definition User.h:295
std::set< CString > m_ssAllowedHosts
Definition User.h:284
const CString & GetDefaultChanModes() const
bool m_bAdmin
Definition User.h:266
unsigned long long m_uBytesRead
Definition User.h:287
std::vector< CClient * > m_vClients
Definition User.h:283
bool CheckPass(const CString &sPass)
Checks password, may upgrade the hash method.
bool IsValid(CString &sErrMsg, bool bSkipPass=false) const
static CString MakeCleanUsername(const CString &sUsername)
void SetNick(const CString &s)
bool m_bMultiClients
Definition User.h:264
bool SetChanBufferSize(unsigned int u, bool bForce=false)
bool m_bAuthOnlyViaModule
Definition User.h:278
void ClearAllowedHosts()
unsigned int MaxQueryBuffers() const
Definition User.h:236
bool m_bDenyLoadMod
Definition User.h:265
bool IsHostAllowed(const CString &sHost) const
bool AddAllowedHost(const CString &sHostMask)
const CString & GetPassSalt() const
bool SetBufferCount(unsigned int u, bool bForce=false)
const CString & GetDCCBindHost() const
bool HasSpaceForNewNetwork() const
bool m_bDenySetIdent
Definition User.h:268
void AddBytesWritten(unsigned long long u)
Definition User.h:127
CUser(const CString &sUsername)
bool m_bPrependTimestamp
Definition User.h:277
CString m_sTimezone
Definition User.h:257
const CString & GetStatusPrefix() const
CString m_sUserPath
Definition User.h:261
void SetDenySetRealName(bool b)
bool Clone(const CUser &User, CString &sErrorRet, bool bCloneNetworks=true)
void SetAltNick(const CString &s)
bool AddNetwork(CIRCNetwork *pNetwork)
void SetRealName(const CString &s)
void SetMultiClients(bool b)
bool DeleteNetwork(const CString &sNetwork)
void SetDenySetCTCPReplies(bool b)
bool PutModNotice(const CString &sModule, const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
bool GetTimestampPrepend() const
bool DenySetIdent() const
bool AddCTCPReply(const CString &sCTCP, const CString &sReply)
void AddBytesRead(unsigned long long u)
Definition User.h:126
CString AddTimestamp(time_t tm, const CString &sStr) const
bool m_bDenySetNetwork
Definition User.h:269
CString m_sPassSalt
Definition User.h:249
const CString & GetPass() const
void SetClientEncoding(const CString &s)
const std::set< CString > & GetAllowedHosts() const
const CString m_sCleanUsername
Definition User.h:241
CString AddTimestamp(const CString &sStr) const
const CString & GetUsername() const
unsigned int GetNoTrafficTimeout() const
Timeout after which IRC connections are closed.
Definition User.h:217
void RemoveNetwork(CIRCNetwork *pNetwork)
unsigned int m_uMaxJoinTries
Definition User.h:289
void SetTimezone(const CString &s)
Definition User.h:165
CString m_sTimestampFormat
Definition User.h:256
CString ExpandString(const CString &sStr) const
unsigned int m_uMaxJoins
Definition User.h:292
bool DenySetQuitMsg() const
std::vector< CIRCNetwork * > m_vIRCNetworks
Definition User.h:282
unsigned int GetChanBufferSize() const
bool m_bAppendTimestamp
Definition User.h:276
void SetDenySetIdent(bool b)
unsigned int m_uMaxNetworks
Definition User.h:290
void SetMaxQueryBuffers(unsigned int i)
Definition User.h:170
void SetJoinTries(unsigned int i)
Definition User.h:166
CString GetQuitMsg() const
bool PutStatusNotice(const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
CString GetRealName() const
unsigned int m_uMaxQueryBuffers
Definition User.h:291
bool m_bBeingDeleted
Definition User.h:275
unsigned long long BytesRead() const
bool DenySetNetwork() const
static CString SaltedHash(const CString &sPass, const CString &sSalt)
Definition User.h:62
bool DelCTCPReply(const CString &sCTCP)
CString GetSkinName() const
CString m_sAltNick
Definition User.h:243
static bool IsValidUsername(const CString &sUsername)
const CString & GetNick(bool bAllowDefault=true) const
bool PutStatus(const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
void CloneNetworks(const CUser &User)
void SetMaxNetworks(unsigned int i)
Definition User.h:169
unsigned int GetQueryBufferSize() const
CModules & GetModules()
Definition User.h:82
unsigned int GetPingFrequency() const
How long must an IRC connection be idle before ZNC sends a ping.
Definition User.h:211
CString m_sIdent
Definition User.h:244
unsigned int m_uChanBufferSize
Definition User.h:285
CString & ExpandString(const CString &sStr, CString &sRet) const
CString m_sNick
Definition User.h:242
unsigned int MaxNetworks() const
Definition User.h:235
CString m_sRealName
Definition User.h:245
bool AutoClearChanBuffer() const
const MCString & GetCTCPReplies() const
void SetQuitMsg(const CString &s)
void SetNoTrafficTimeout(unsigned int i)
Definition User.h:171
void SetSkinName(const CString &s)
Definition User.h:168
unsigned int MaxJoins() const
Definition User.h:232
void SetTimestampAppend(bool b)
Definition User.h:162
CString m_sPass
Definition User.h:248
bool IsBeingDeleted() const
Definition User.h:227
void SetBindHost(const CString &s)
std::vector< CClient * > GetAllClients() const
CString GetLanguage() const
CIRCNetwork * AddNetwork(const CString &sNetwork, CString &sErrorRet)
CString m_sBindHost
Definition User.h:246
unsigned int m_uQueryBufferSize
Definition User.h:286
CString m_sSkinName
Definition User.h:294
bool IsUserAttached() const
CString AddTimestamp(timeval tv, const CString &sStr) const
bool IsAdmin() const
void UserConnected(CClient *pClient)
void SetIdent(const CString &s)
CString GetTimezone() const
Definition User.h:228
unsigned int JoinTries() const
Definition User.h:231
bool m_bDenySetQuitMsg
Definition User.h:271
bool SetQueryBufferSize(unsigned int u, bool bForce=false)
void SetMaxJoins(unsigned int i)
Definition User.h:167
bool SetStatusPrefix(const CString &s)
void SetDenyLoadMod(bool b)
bool PutModule(const CString &sModule, const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
bool ParseConfig(CConfig *Config, CString &sError)
bool DenySetRealName() const
void UserDisconnected(CClient *pClient)
bool SetLanguage(const CString &s)
const std::vector< CClient * > & GetUserClients() const
Definition User.h:175
bool m_bDenySetRealName
Definition User.h:270
CModules * m_pModules
Definition User.h:297
bool RemAllowedHost(const CString &sHostMask)
CString m_sClientEncoding
Definition User.h:252
unsigned int GetBufferCount() const
bool MultiClients() const
bool GetTimestampAppend() const
eHashType m_eHashType
Definition User.h:258
eHashType
Definition User.h:48
@ HASH_SHA256
Definition User.h:51
@ HASH_MD5
Definition User.h:50
@ HASH_ARGON2ID
Definition User.h:52
@ HASH_DEFAULT
Definition User.h:58
@ HASH_NONE
Definition User.h:49
void SetDenySetQuitMsg(bool b)
CIRCNetwork * FindNetwork(const CString &sNetwork) const
bool m_bAutoClearQueryBuffer
Definition User.h:274
void SetAuthOnlyViaModule(bool b)
Definition User.h:164
CString m_sQuitMsg
Definition User.h:254
void SetTimestampPrepend(bool b)
Definition User.h:163
void SetAdmin(bool b)
const CString & GetClientEncoding() const
CString m_sStatusPrefix
Definition User.h:250
eHashType GetPassHashType() const
static CString MakeCleanUserName(const CString &sUsername)
static CString SaltedHash(const CString &sPass, const CString &sSalt)
A dictionary for strings.
Definition ZNCString.h:577