ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
User.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2018 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 <set>
25 #include <vector>
26 
27 class CModules;
28 class CChan;
29 class CClient;
30 class CConfig;
31 class CFile;
32 class CIRCNetwork;
33 class CIRCSock;
34 class CUserTimer;
35 class CServer;
36 
37 class CUser {
38  public:
39  CUser(const CString& sUserName);
40  ~CUser();
41 
42  CUser(const CUser&) = delete;
43  CUser& operator=(const CUser&) = delete;
44 
45  bool ParseConfig(CConfig* Config, CString& sError);
46 
47  // TODO refactor this
48  enum eHashType {
52 
54  };
55 
56  // If you change the default hash here and in HASH_DEFAULT,
57  // don't forget CUtils::sDefaultHash!
58  // TODO refactor this
59  static CString SaltedHash(const CString& sPass, const CString& sSalt) {
60  return CUtils::SaltedSHA256Hash(sPass, sSalt);
61  }
62 
63  CConfig ToConfig() const;
64  bool CheckPass(const CString& sPass) const;
65  bool AddAllowedHost(const CString& sHostMask);
66  bool RemAllowedHost(const CString& sHostMask);
67  void ClearAllowedHosts();
68  bool IsHostAllowed(const CString& sHost) const;
69  bool IsValid(CString& sErrMsg, bool bSkipPass = false) const;
70  static bool IsValidUserName(const CString& sUserName);
71  static CString MakeCleanUserName(const CString& sUserName);
72 
73  // Modules
74  CModules& GetModules() { return *m_pModules; }
75  const CModules& GetModules() const { return *m_pModules; }
76  // !Modules
77 
78  // Networks
79  CIRCNetwork* AddNetwork(const CString& sNetwork, CString& sErrorRet);
80  bool DeleteNetwork(const CString& sNetwork);
81  bool AddNetwork(CIRCNetwork* pNetwork);
82  void RemoveNetwork(CIRCNetwork* pNetwork);
83  CIRCNetwork* FindNetwork(const CString& sNetwork) const;
84  const std::vector<CIRCNetwork*>& GetNetworks() const;
85  bool HasSpaceForNewNetwork() const;
86  // !Networks
87 
88  bool PutUser(const CString& sLine, CClient* pClient = nullptr,
89  CClient* pSkipClient = nullptr);
90  bool PutAllUser(const CString& sLine, CClient* pClient = nullptr,
91  CClient* pSkipClient = nullptr);
92  bool PutStatus(const CString& sLine, CClient* pClient = nullptr,
93  CClient* pSkipClient = nullptr);
94  bool PutStatusNotice(const CString& sLine, CClient* pClient = nullptr,
95  CClient* pSkipClient = nullptr);
96  bool PutModule(const CString& sModule, const CString& sLine,
97  CClient* pClient = nullptr, CClient* pSkipClient = nullptr);
98  bool PutModNotice(const CString& sModule, const CString& sLine,
99  CClient* pClient = nullptr,
100  CClient* pSkipClient = nullptr);
101 
102  bool IsUserAttached() const;
103  void UserConnected(CClient* pClient);
104  void UserDisconnected(CClient* pClient);
105 
106  CString GetLocalDCCIP() const;
107 
108  CString ExpandString(const CString& sStr) const;
109  CString& ExpandString(const CString& sStr, CString& sRet) const;
110 
111  CString AddTimestamp(const CString& sStr) const;
112  CString AddTimestamp(time_t tm, const CString& sStr) const;
113  CString AddTimestamp(timeval tv, const CString& sStr) const;
114 
115  void CloneNetworks(const CUser& User);
116  bool Clone(const CUser& User, CString& sErrorRet,
117  bool bCloneNetworks = true);
118  void BounceAllClients();
119 
120  void AddBytesRead(unsigned long long u) { m_uBytesRead += u; }
121  void AddBytesWritten(unsigned long long u) { m_uBytesWritten += u; }
122 
123  // Setters
124  void SetNick(const CString& s);
125  void SetAltNick(const CString& s);
126  void SetIdent(const CString& s);
127  void SetRealName(const CString& s);
128  void SetBindHost(const CString& s);
129  void SetDCCBindHost(const CString& s);
130  void SetPass(const CString& s, eHashType eHash, const CString& sSalt = "");
131  void SetMultiClients(bool b);
132  void SetDenyLoadMod(bool b);
133  void SetAdmin(bool b);
134  void SetDenySetBindHost(bool b);
135  bool SetStatusPrefix(const CString& s);
136  void SetDefaultChanModes(const CString& s);
137  void SetClientEncoding(const CString& s);
138  void SetQuitMsg(const CString& s);
139  bool AddCTCPReply(const CString& sCTCP, const CString& sReply);
140  bool DelCTCPReply(const CString& sCTCP);
142  bool SetBufferCount(unsigned int u, bool bForce = false);
143  bool SetChanBufferSize(unsigned int u, bool bForce = false);
144  bool SetQueryBufferSize(unsigned int u, bool bForce = false);
145  void SetAutoClearChanBuffer(bool b);
146  void SetAutoClearQueryBuffer(bool b);
147  bool SetLanguage(const CString& s);
148 
149  void SetBeingDeleted(bool b) { m_bBeingDeleted = b; }
154  void SetTimezone(const CString& s) { m_sTimezone = s; }
155  void SetJoinTries(unsigned int i) { m_uMaxJoinTries = i; }
156  void SetMaxJoins(unsigned int i) { m_uMaxJoins = i; }
157  void SetSkinName(const CString& s) { m_sSkinName = s; }
158  void SetMaxNetworks(unsigned int i) { m_uMaxNetworks = i; }
159  void SetMaxQueryBuffers(unsigned int i) { m_uMaxQueryBuffers = i; }
160  void SetNoTrafficTimeout(unsigned int i) { m_uNoTrafficTimeout = i; }
161  // !Setters
162 
163  // Getters
164  const std::vector<CClient*>& GetUserClients() const { return m_vClients; }
165  std::vector<CClient*> GetAllClients() const;
166  const CString& GetUserName() const;
167  const CString& GetCleanUserName() const;
168  const CString& GetNick(bool bAllowDefault = true) const;
169  const CString& GetAltNick(bool bAllowDefault = true) const;
170  const CString& GetIdent(bool bAllowDefault = true) const;
171  CString GetRealName() const;
172  const CString& GetBindHost() const;
173  const CString& GetDCCBindHost() const;
174  const CString& GetPass() const;
175  eHashType GetPassHashType() const;
176  const CString& GetPassSalt() const;
177  const std::set<CString>& GetAllowedHosts() const;
178  const CString& GetTimestampFormat() const;
179  const CString& GetClientEncoding() const;
180  bool GetTimestampAppend() const;
181  bool GetTimestampPrepend() const;
182 
183  const CString& GetUserPath() const;
184 
185  bool DenyLoadMod() const;
186  bool IsAdmin() const;
187  bool DenySetBindHost() const;
188  bool MultiClients() const;
189  bool AuthOnlyViaModule() const;
190  const CString& GetStatusPrefix() const;
191  const CString& GetDefaultChanModes() const;
193  unsigned int GetPingFrequency() const { return m_uNoTrafficTimeout / 2; }
195  unsigned int GetPingSlack() const { return m_uNoTrafficTimeout / 6; }
199  unsigned int GetNoTrafficTimeout() const { return m_uNoTrafficTimeout; }
200 
201  CString GetQuitMsg() const;
202  const MCString& GetCTCPReplies() const;
204  unsigned int GetBufferCount() const;
205  unsigned int GetChanBufferSize() const;
206  unsigned int GetQueryBufferSize() const;
207  bool AutoClearChanBuffer() const;
208  bool AutoClearQueryBuffer() const;
209  bool IsBeingDeleted() const { return m_bBeingDeleted; }
210  CString GetTimezone() const { return m_sTimezone; }
211  unsigned long long BytesRead() const;
212  unsigned long long BytesWritten() const;
213  unsigned int JoinTries() const { return m_uMaxJoinTries; }
214  unsigned int MaxJoins() const { return m_uMaxJoins; }
215  CString GetSkinName() const;
216  CString GetLanguage() const;
217  unsigned int MaxNetworks() const { return m_uMaxNetworks; }
218  unsigned int MaxQueryBuffers() const { return m_uMaxQueryBuffers; }
219  // !Getters
220 
221  protected:
235 
241 
242  // Paths
244  // !Paths
245 
248  bool m_bAdmin;
256 
257  CUserTimer* m_pUserTimer;
258 
259  std::vector<CIRCNetwork*> m_vIRCNetworks;
260  std::vector<CClient*> m_vClients;
261  std::set<CString> m_ssAllowedHosts;
262  unsigned int m_uChanBufferSize;
263  unsigned int m_uQueryBufferSize;
264  unsigned long long m_uBytesRead;
265  unsigned long long m_uBytesWritten;
266  unsigned int m_uMaxJoinTries;
267  unsigned int m_uMaxNetworks;
268  unsigned int m_uMaxQueryBuffers;
269  unsigned int m_uMaxJoins;
270  unsigned int m_uNoTrafficTimeout;
273 
275 
276  private:
277  void SetKeepBuffer(bool b) {
279  } // XXX compatibility crap, added in 0.207
280  bool LoadModule(const CString& sModName, const CString& sArgs,
281  const CString& sNotice, CString& sError);
282 };
283 
284 #endif // !ZNC_USER_H
void SetJoinTries(unsigned int i)
Definition: User.h:155
Definition: User.h:37
bool IsAdmin() const
eHashType GetPassHashType() const
bool IsBeingDeleted() const
Definition: User.h:209
void SetQuitMsg(const CString &s)
void SetRealName(const CString &s)
unsigned int m_uMaxJoinTries
Definition: User.h:266
bool m_bDenySetBindHost
Definition: User.h:249
CConfig ToConfig() const
const CString m_sUserName
Definition: User.h:222
const CString & GetBindHost() const
CString ExpandString(const CString &sStr) const
void SetBindHost(const CString &s)
const CString & GetStatusPrefix() const
bool m_bMultiClients
Definition: User.h:246
CString m_sTimezone
Definition: User.h:239
void SetTimezone(const CString &s)
Definition: User.h:154
CString m_sPassSalt
Definition: User.h:231
Definition: User.h:51
void SetTimestampAppend(bool b)
Definition: User.h:151
void SetDenySetBindHost(bool b)
void RemoveNetwork(CIRCNetwork *pNetwork)
CString GetSkinName() const
bool IsValid(CString &sErrMsg, bool bSkipPass=false) const
bool DelCTCPReply(const CString &sCTCP)
CString m_sTimestampFormat
Definition: User.h:238
static CString MakeCleanUserName(const CString &sUserName)
unsigned int GetNoTrafficTimeout() const
Timeout after which IRC connections are closed.
Definition: User.h:199
bool IsUserAttached() const
const CString & GetTimestampFormat() const
bool RemAllowedHost(const CString &sHostMask)
void AddBytesRead(unsigned long long u)
Definition: User.h:120
const CString & GetUserName() const
Definition: Client.h:99
bool m_bPrependTimestamp
Definition: User.h:254
Definition: User.h:49
std::vector< CIRCNetwork * > m_vIRCNetworks
Definition: User.h:259
CIRCNetwork * AddNetwork(const CString &sNetwork, CString &sErrorRet)
CString m_sStatusPrefix
Definition: User.h:232
MCString m_mssCTCPReplies
Definition: User.h:237
bool AutoClearChanBuffer() const
bool PutStatusNotice(const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
eHashType
Definition: User.h:48
bool MultiClients() const
void SetDCCBindHost(const CString &s)
void BounceAllClients()
Definition: Modules.h:1383
bool SetChanBufferSize(unsigned int u, bool bForce=false)
unsigned long long BytesWritten() const
bool AddAllowedHost(const CString &sHostMask)
unsigned int MaxJoins() const
Definition: User.h:214
CString m_sAltNick
Definition: User.h:225
const std::set< CString > & GetAllowedHosts() const
CString AddTimestamp(const CString &sStr) const
const CModules & GetModules() const
Definition: User.h:75
const CString & GetClientEncoding() const
CString m_sNick
Definition: User.h:224
Definition: User.h:53
unsigned int GetQueryBufferSize() const
void SetSkinName(const CString &s)
Definition: User.h:157
unsigned long long BytesRead() const
CString m_sRealName
Definition: User.h:227
bool PutStatus(const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
bool DeleteNetwork(const CString &sNetwork)
const CString & GetAltNick(bool bAllowDefault=true) const
CString m_sPass
Definition: User.h:230
CString m_sIdent
Definition: User.h:226
Definition: FileUtils.h:30
unsigned int MaxQueryBuffers() const
Definition: User.h:218
CString m_sLanguage
Definition: User.h:272
Definition: IRCNetwork.h:40
const MCString & GetCTCPReplies() const
CString m_sUserPath
Definition: User.h:243
void UserConnected(CClient *pClient)
void SetMultiClients(bool b)
CUserTimer * m_pUserTimer
Definition: User.h:257
bool m_bAutoClearChanBuffer
Definition: User.h:250
String class that is used inside ZNC.
Definition: ZNCString.h:68
bool m_bDenyLoadMod
Definition: User.h:247
const std::vector< CClient * > & GetUserClients() const
Definition: User.h:164
bool CheckPass(const CString &sPass) const
bool SetLanguage(const CString &s)
unsigned int m_uNoTrafficTimeout
Definition: User.h:270
const CString & GetDCCBindHost() const
CString GetLocalDCCIP() const
CString GetQuitMsg() const
const CString & GetDefaultChanModes() const
void SetAltNick(const CString &s)
bool SetStatusPrefix(const CString &s)
void SetAdmin(bool b)
unsigned int m_uMaxJoins
Definition: User.h:269
static bool IsValidUserName(const CString &sUserName)
std::set< CString > m_ssAllowedHosts
Definition: User.h:261
const std::vector< CIRCNetwork * > & GetNetworks() const
void SetDenyLoadMod(bool b)
void SetMaxNetworks(unsigned int i)
Definition: User.h:158
static CString SaltedSHA256Hash(const CString &sPass, const CString &sSalt)
void SetBeingDeleted(bool b)
Definition: User.h:149
unsigned int m_uMaxQueryBuffers
Definition: User.h:268
bool ParseConfig(CConfig *Config, CString &sError)
bool GetTimestampPrepend() const
bool m_bBeingDeleted
Definition: User.h:252
bool PutAllUser(const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
CString m_sClientEncoding
Definition: User.h:234
bool m_bAutoClearQueryBuffer
Definition: User.h:251
void SetNick(const CString &s)
void SetNoTrafficTimeout(unsigned int i)
Definition: User.h:160
const CString & GetPass() const
unsigned int GetChanBufferSize() const
void UserDisconnected(CClient *pClient)
unsigned int GetPingFrequency() const
How long must an IRC connection be idle before ZNC sends a ping.
Definition: User.h:193
CString GetRealName() const
CUser & operator=(const CUser &)=delete
void SetAutoClearChanBuffer(bool b)
unsigned int MaxNetworks() const
Definition: User.h:217
unsigned int m_uChanBufferSize
Definition: User.h:262
bool AddCTCPReply(const CString &sCTCP, const CString &sReply)
bool DenyLoadMod() const
CString m_sSkinName
Definition: User.h:271
bool m_bAdmin
Definition: User.h:248
bool m_bAppendTimestamp
Definition: User.h:253
void SetIdent(const CString &s)
CModules * m_pModules
Definition: User.h:274
CString GetLanguage() const
CUser(const CString &sUserName)
CString m_sQuitMsg
Definition: User.h:236
const CString m_sCleanUserName
Definition: User.h:223
A dictionary for strings.
Definition: ZNCString.h:595
const CString & GetNick(bool bAllowDefault=true) const
std::vector< CClient * > GetAllClients() const
void CloneNetworks(const CUser &User)
bool HasSpaceForNewNetwork() const
bool PutUser(const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
const CString & GetUserPath() const
unsigned int m_uMaxNetworks
Definition: User.h:267
bool Clone(const CUser &User, CString &sErrorRet, bool bCloneNetworks=true)
void SetTimestampFormat(const CString &s)
Definition: User.h:150
unsigned int GetPingSlack() const
Time between checks if PINGs need to be sent.
Definition: User.h:195
bool GetTimestampAppend() const
CString m_sBindHost
Definition: User.h:228
const CString & GetCleanUserName() const
bool AuthOnlyViaModule() const
void SetAutoClearQueryBuffer(bool b)
void SetPass(const CString &s, eHashType eHash, const CString &sSalt="")
eHashType m_eHashType
Definition: User.h:240
unsigned int GetBufferCount() const
unsigned long long m_uBytesWritten
Definition: User.h:265
CString m_sDefaultChanModes
Definition: User.h:233
void ClearAllowedHosts()
std::vector< CClient * > m_vClients
Definition: User.h:260
bool IsHostAllowed(const CString &sHost) const
void SetDefaultChanModes(const CString &s)
bool PutModule(const CString &sModule, const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
unsigned int JoinTries() const
Definition: User.h:213
bool PutModNotice(const CString &sModule, const CString &sLine, CClient *pClient=nullptr, CClient *pSkipClient=nullptr)
unsigned int m_uQueryBufferSize
Definition: User.h:263
bool DenySetBindHost() const
void SetClientEncoding(const CString &s)
CString GetTimezone() const
Definition: User.h:210
Definition: Server.h:23
static CString SaltedHash(const CString &sPass, const CString &sSalt)
Definition: User.h:59
void SetMaxQueryBuffers(unsigned int i)
Definition: User.h:159
void SetAuthOnlyViaModule(bool b)
Definition: User.h:153
void AddBytesWritten(unsigned long long u)
Definition: User.h:121
Definition: IRCSock.h:35
bool SetQueryBufferSize(unsigned int u, bool bForce=false)
const CString & GetIdent(bool bAllowDefault=true) const
CIRCNetwork * FindNetwork(const CString &sNetwork) const
Definition: Chan.h:34
unsigned long long m_uBytesRead
Definition: User.h:264
Definition: Config.h:36
void SetTimestampPrepend(bool b)
Definition: User.h:152
CModules & GetModules()
Definition: User.h:74
Definition: User.h:50
void SetMaxJoins(unsigned int i)
Definition: User.h:156
bool SetBufferCount(unsigned int u, bool bForce=false)
const CString & GetPassSalt() const
CString m_sDCCBindHost
Definition: User.h:229
bool AutoClearQueryBuffer() const
bool m_bAuthOnlyViaModule
Definition: User.h:255