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-2014 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 _USER_H
18 #define _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  bool ParseConfig(CConfig* Config, CString& sError);
43 
44  // TODO refactor this
45  enum eHashType {
49 
51  };
52 
53  // If you change the default hash here and in HASH_DEFAULT,
54  // don't forget CUtils::sDefaultHash!
55  // TODO refactor this
56  static CString SaltedHash(const CString& sPass, const CString& sSalt) {
57  return CUtils::SaltedSHA256Hash(sPass, sSalt);
58  }
59 
60  CConfig ToConfig();
61  bool CheckPass(const CString& sPass) const;
62  bool AddAllowedHost(const CString& sHostMask);
63  bool IsHostAllowed(const CString& sHostMask) const;
64  bool IsValid(CString& sErrMsg, bool bSkipPass = false) const;
65  static bool IsValidUserName(const CString& sUserName);
66  static CString MakeCleanUserName(const CString& sUserName);
67 
68  // Modules
69  CModules& GetModules() { return *m_pModules; }
70  const CModules& GetModules() const { return *m_pModules; }
71  // !Modules
72 
73  // Networks
74  CIRCNetwork* AddNetwork(const CString &sNetwork, CString& sErrorRet);
75  bool DeleteNetwork(const CString& sNetwork);
76  bool AddNetwork(CIRCNetwork *pNetwork);
77  void RemoveNetwork(CIRCNetwork *pNetwork);
78  CIRCNetwork* FindNetwork(const CString& sNetwork) const;
79  const std::vector<CIRCNetwork*>& GetNetworks() const;
80  bool HasSpaceForNewNetwork() const;
81  // !Networks
82 
83  bool PutUser(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
84  bool PutAllUser(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
85  bool PutStatus(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
86  bool PutStatusNotice(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
87  bool PutModule(const CString& sModule, const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
88  bool PutModNotice(const CString& sModule, const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
89 
90  bool IsUserAttached() const;
91  void UserConnected(CClient* pClient);
92  void UserDisconnected(CClient* pClient);
93 
95 
96  CString ExpandString(const CString& sStr) const;
97  CString& ExpandString(const CString& sStr, CString& sRet) const;
98 
99  CString AddTimestamp(const CString& sStr) const;
100  CString AddTimestamp(time_t tm, const CString& sStr) const;
101 
102  void CloneNetworks(const CUser& User);
103  bool Clone(const CUser& User, CString& sErrorRet, bool bCloneNetworks = true);
104  void BounceAllClients();
105 
106  void AddBytesRead(unsigned long long u) { m_uBytesRead += u; }
107  void AddBytesWritten(unsigned long long u) { m_uBytesWritten += u; }
108 
109  // Setters
110  void SetNick(const CString& s);
111  void SetAltNick(const CString& s);
112  void SetIdent(const CString& s);
113  void SetRealName(const CString& s);
114  void SetBindHost(const CString& s);
115  void SetDCCBindHost(const CString& s);
116  void SetPass(const CString& s, eHashType eHash, const CString& sSalt = "");
117  void SetMultiClients(bool b);
118  void SetDenyLoadMod(bool b);
119  void SetAdmin(bool b);
120  void SetDenySetBindHost(bool b);
121  bool SetStatusPrefix(const CString& s);
122  void SetDefaultChanModes(const CString& s);
123  void SetClientEncoding(const CString& s);
124  void SetQuitMsg(const CString& s);
125  bool AddCTCPReply(const CString& sCTCP, const CString& sReply);
126  bool DelCTCPReply(const CString& sCTCP);
127  bool SetBufferCount(unsigned int u, bool bForce = false);
128  void SetAutoClearChanBuffer(bool b);
129 
130  void SetBeingDeleted(bool b) { m_bBeingDeleted = b; }
134  void SetTimezone(const CString& s) { m_sTimezone = s; }
135  void SetJoinTries(unsigned int i) { m_uMaxJoinTries = i; }
136  void SetMaxJoins(unsigned int i) { m_uMaxJoins = i; }
137  void SetSkinName(const CString& s) { m_sSkinName = s; }
138  void SetMaxNetworks(unsigned int i) { m_uMaxNetworks = i; }
139  // !Setters
140 
141  // Getters
142  std::vector<CClient*>& GetUserClients() { return m_vClients; }
143  std::vector<CClient*> GetAllClients();
144  const CString& GetUserName() const;
145  const CString& GetCleanUserName() const;
146  const CString& GetNick(bool bAllowDefault = true) const;
147  const CString& GetAltNick(bool bAllowDefault = true) const;
148  const CString& GetIdent(bool bAllowDefault = true) const;
149  const CString& GetRealName() const;
150  const CString& GetBindHost() const;
151  const CString& GetDCCBindHost() const;
152  const CString& GetPass() const;
153  eHashType GetPassHashType() const;
154  const CString& GetPassSalt() const;
155  const std::set<CString>& GetAllowedHosts() const;
156  const CString& GetTimestampFormat() const;
157  const CString& GetClientEncoding() const;
158  bool GetTimestampAppend() const;
159  bool GetTimestampPrepend() const;
160 
161  const CString& GetUserPath() const;
162 
163  bool DenyLoadMod() const;
164  bool IsAdmin() const;
165  bool DenySetBindHost() const;
166  bool MultiClients() const;
167  const CString& GetStatusPrefix() const;
168  const CString& GetDefaultChanModes() const;
169 
170  CString GetQuitMsg() const;
171  const MCString& GetCTCPReplies() const;
172  unsigned int GetBufferCount() const;
173  bool AutoClearChanBuffer() const;
174  bool IsBeingDeleted() const { return m_bBeingDeleted; }
175  CString GetTimezone() const { return m_sTimezone; }
176  unsigned long long BytesRead() const { return m_uBytesRead; }
177  unsigned long long BytesWritten() const { return m_uBytesWritten; }
178  unsigned int JoinTries() const { return m_uMaxJoinTries; }
179  unsigned int MaxJoins() const { return m_uMaxJoins; }
180  CString GetSkinName() const;
181  unsigned int MaxNetworks() const { return m_uMaxNetworks; }
182  // !Getters
183 
184 protected:
198 
204 
205  // Paths
207  // !Paths
208 
211  bool m_bAdmin;
217 
218  CUserTimer* m_pUserTimer;
219 
220  std::vector<CIRCNetwork*> m_vIRCNetworks;
221  std::vector<CClient*> m_vClients;
222  std::set<CString> m_ssAllowedHosts;
223  unsigned int m_uBufferCount;
224  unsigned long long m_uBytesRead;
225  unsigned long long m_uBytesWritten;
226  unsigned int m_uMaxJoinTries;
227  unsigned int m_uMaxNetworks;
228  unsigned int m_uMaxJoins;
230 
232 
233 private:
234  void SetKeepBuffer(bool b) { SetAutoClearChanBuffer(!b); } // XXX compatibility crap, added in 0.207
235 };
236 
237 #endif // !_USER_H
void SetJoinTries(unsigned int i)
Definition: User.h:135
bool IsHostAllowed(const CString &sHostMask) const
Definition: User.h:37
bool IsAdmin() const
eHashType GetPassHashType() const
bool IsBeingDeleted() const
Definition: User.h:174
void SetQuitMsg(const CString &s)
void SetRealName(const CString &s)
unsigned int m_uMaxJoinTries
Definition: User.h:226
bool m_bDenySetBindHost
Definition: User.h:212
const CString m_sUserName
Definition: User.h:185
bool PutModNotice(const CString &sModule, const CString &sLine, CClient *pClient=NULL, CClient *pSkipClient=NULL)
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:209
bool PutAllUser(const CString &sLine, CClient *pClient=NULL, CClient *pSkipClient=NULL)
CString m_sTimezone
Definition: User.h:202
void SetTimezone(const CString &s)
Definition: User.h:134
CString m_sPassSalt
Definition: User.h:194
Definition: User.h:48
void SetTimestampAppend(bool b)
Definition: User.h:132
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:201
static CString MakeCleanUserName(const CString &sUserName)
CConfig ToConfig()
bool IsUserAttached() const
const CString & GetTimestampFormat() const
void AddBytesRead(unsigned long long u)
Definition: User.h:106
const CString & GetUserName() const
Definition: Client.h:84
bool m_bPrependTimestamp
Definition: User.h:216
Definition: User.h:46
std::vector< CIRCNetwork * > m_vIRCNetworks
Definition: User.h:220
CIRCNetwork * AddNetwork(const CString &sNetwork, CString &sErrorRet)
CString m_sStatusPrefix
Definition: User.h:195
MCString m_mssCTCPReplies
Definition: User.h:200
bool AutoClearChanBuffer() const
eHashType
Definition: User.h:45
bool MultiClients() const
void SetDCCBindHost(const CString &s)
bool PutUser(const CString &sLine, CClient *pClient=NULL, CClient *pSkipClient=NULL)
void BounceAllClients()
Definition: Modules.h:1066
unsigned long long BytesWritten() const
Definition: User.h:177
bool AddAllowedHost(const CString &sHostMask)
unsigned int MaxJoins() const
Definition: User.h:179
std::vector< CClient * > GetAllClients()
CString m_sAltNick
Definition: User.h:188
const std::set< CString > & GetAllowedHosts() const
CString AddTimestamp(const CString &sStr) const
const CModules & GetModules() const
Definition: User.h:70
const CString & GetClientEncoding() const
CString m_sNick
Definition: User.h:187
Definition: User.h:50
void SetSkinName(const CString &s)
Definition: User.h:137
unsigned long long BytesRead() const
Definition: User.h:176
CString m_sRealName
Definition: User.h:190
bool DeleteNetwork(const CString &sNetwork)
const CString & GetAltNick(bool bAllowDefault=true) const
CString m_sPass
Definition: User.h:193
CString m_sIdent
Definition: User.h:189
Definition: FileUtils.h:30
Definition: IRCNetwork.h:36
const MCString & GetCTCPReplies() const
CString m_sUserPath
Definition: User.h:206
void UserConnected(CClient *pClient)
void SetMultiClients(bool b)
CUserTimer * m_pUserTimer
Definition: User.h:218
bool m_bAutoClearChanBuffer
Definition: User.h:213
String class that is used inside ZNC.
Definition: ZNCString.h:67
bool m_bDenyLoadMod
Definition: User.h:210
std::vector< CClient * > & GetUserClients()
Definition: User.h:142
bool CheckPass(const CString &sPass) const
const CString & GetDCCBindHost() 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:228
static bool IsValidUserName(const CString &sUserName)
std::set< CString > m_ssAllowedHosts
Definition: User.h:222
const std::vector< CIRCNetwork * > & GetNetworks() const
void SetDenyLoadMod(bool b)
void SetMaxNetworks(unsigned int i)
Definition: User.h:138
static CString SaltedSHA256Hash(const CString &sPass, const CString &sSalt)
void SetBeingDeleted(bool b)
Definition: User.h:130
bool PutModule(const CString &sModule, const CString &sLine, CClient *pClient=NULL, CClient *pSkipClient=NULL)
bool ParseConfig(CConfig *Config, CString &sError)
bool GetTimestampPrepend() const
bool m_bBeingDeleted
Definition: User.h:214
CString m_sClientEncoding
Definition: User.h:197
void SetNick(const CString &s)
const CString & GetPass() const
void UserDisconnected(CClient *pClient)
void SetAutoClearChanBuffer(bool b)
unsigned int MaxNetworks() const
Definition: User.h:181
bool AddCTCPReply(const CString &sCTCP, const CString &sReply)
bool DenyLoadMod() const
CString m_sSkinName
Definition: User.h:229
bool m_bAdmin
Definition: User.h:211
bool m_bAppendTimestamp
Definition: User.h:215
void SetIdent(const CString &s)
CModules * m_pModules
Definition: User.h:231
CUser(const CString &sUserName)
CString m_sQuitMsg
Definition: User.h:199
const CString m_sCleanUserName
Definition: User.h:186
A dictionary for strings.
Definition: ZNCString.h:538
const CString & GetNick(bool bAllowDefault=true) const
void CloneNetworks(const CUser &User)
bool HasSpaceForNewNetwork() const
const CString & GetUserPath() const
unsigned int m_uMaxNetworks
Definition: User.h:227
bool Clone(const CUser &User, CString &sErrorRet, bool bCloneNetworks=true)
void SetTimestampFormat(const CString &s)
Definition: User.h:131
bool GetTimestampAppend() const
CString m_sBindHost
Definition: User.h:191
const CString & GetCleanUserName() const
void SetPass(const CString &s, eHashType eHash, const CString &sSalt="")
eHashType m_eHashType
Definition: User.h:203
unsigned int GetBufferCount() const
unsigned long long m_uBytesWritten
Definition: User.h:225
CString m_sDefaultChanModes
Definition: User.h:196
std::vector< CClient * > m_vClients
Definition: User.h:221
void SetDefaultChanModes(const CString &s)
unsigned int JoinTries() const
Definition: User.h:178
bool PutStatus(const CString &sLine, CClient *pClient=NULL, CClient *pSkipClient=NULL)
bool DenySetBindHost() const
unsigned int m_uBufferCount
Definition: User.h:223
void SetClientEncoding(const CString &s)
CString GetTimezone() const
Definition: User.h:175
Definition: Server.h:23
static CString SaltedHash(const CString &sPass, const CString &sSalt)
Definition: User.h:56
void AddBytesWritten(unsigned long long u)
Definition: User.h:107
Definition: IRCSock.h:33
const CString & GetIdent(bool bAllowDefault=true) const
CIRCNetwork * FindNetwork(const CString &sNetwork) const
bool PutStatusNotice(const CString &sLine, CClient *pClient=NULL, CClient *pSkipClient=NULL)
Definition: Chan.h:34
unsigned long long m_uBytesRead
Definition: User.h:224
Definition: Config.h:36
void SetTimestampPrepend(bool b)
Definition: User.h:133
CModules & GetModules()
Definition: User.h:69
const CString & GetRealName() const
CString GetLocalDCCIP()
Definition: User.h:47
void SetMaxJoins(unsigned int i)
Definition: User.h:136
bool SetBufferCount(unsigned int u, bool bForce=false)
const CString & GetPassSalt() const
CString m_sDCCBindHost
Definition: User.h:192