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