Account.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. // SoftEther VPN Source Code - Stable Edition Repository
  2. // Cedar Communication Module
  3. //
  4. // SoftEther VPN Server, Client and Bridge are free software under the Apache License, Version 2.0.
  5. //
  6. // Copyright (c) Daiyuu Nobori.
  7. // Copyright (c) SoftEther VPN Project, University of Tsukuba, Japan.
  8. // Copyright (c) SoftEther Corporation.
  9. // Copyright (c) all contributors on SoftEther VPN project in GitHub.
  10. //
  11. // All Rights Reserved.
  12. //
  13. // http://www.softether.org/
  14. //
  15. // This stable branch is officially managed by Daiyuu Nobori, the owner of SoftEther VPN Project.
  16. // Pull requests should be sent to the Developer Edition Master Repository on https://github.com/SoftEtherVPN/SoftEtherVPN
  17. //
  18. // License: The Apache License, Version 2.0
  19. // https://www.apache.org/licenses/LICENSE-2.0
  20. //
  21. // DISCLAIMER
  22. // ==========
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. // SOFTWARE.
  31. //
  32. // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN, UNDER
  33. // JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY, MERGE, PUBLISH,
  34. // DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS SOFTWARE, THAT ANY
  35. // JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS SOFTWARE OR ITS CONTENTS,
  36. // AGAINST US (SOFTETHER PROJECT, SOFTETHER CORPORATION, DAIYUU NOBORI OR OTHER
  37. // SUPPLIERS), OR ANY JURIDICAL DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND
  38. // OF USING, COPYING, MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING,
  39. // AND/OR SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
  40. // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO EXCLUSIVE
  41. // JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO, JAPAN. YOU MUST WAIVE
  42. // ALL DEFENSES OF LACK OF PERSONAL JURISDICTION AND FORUM NON CONVENIENS.
  43. // PROCESS MAY BE SERVED ON EITHER PARTY IN THE MANNER AUTHORIZED BY APPLICABLE
  44. // LAW OR COURT RULE.
  45. //
  46. // USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS YOU HAVE
  47. // A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY CRIMINAL LAWS OR CIVIL
  48. // RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS SOFTWARE IN OTHER COUNTRIES IS
  49. // COMPLETELY AT YOUR OWN RISK. THE SOFTETHER VPN PROJECT HAS DEVELOPED AND
  50. // DISTRIBUTED THIS SOFTWARE TO COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING
  51. // CIVIL RIGHTS INCLUDING PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER
  52. // COUNTRIES' LAWS OR CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES.
  53. // WE HAVE NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR
  54. // INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+ COUNTRIES
  55. // AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE WORLD, WITH
  56. // DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY COUNTRIES' LAWS, REGULATIONS
  57. // AND CIVIL RIGHTS TO MAKE THE SOFTWARE COMPLY WITH ALL COUNTRIES' LAWS BY THE
  58. // PROJECT. EVEN IF YOU WILL BE SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A
  59. // PUBLIC SERVANT IN YOUR COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE
  60. // LIABLE TO RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL
  61. // RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT JUST A
  62. // STATEMENT FOR WARNING AND DISCLAIMER.
  63. //
  64. // READ AND UNDERSTAND THE 'WARNING.TXT' FILE BEFORE USING THIS SOFTWARE.
  65. // SOME SOFTWARE PROGRAMS FROM THIRD PARTIES ARE INCLUDED ON THIS SOFTWARE WITH
  66. // LICENSE CONDITIONS WHICH ARE DESCRIBED ON THE 'THIRD_PARTY.TXT' FILE.
  67. //
  68. //
  69. // SOURCE CODE CONTRIBUTION
  70. // ------------------------
  71. //
  72. // Your contribution to SoftEther VPN Project is much appreciated.
  73. // Please send patches to us through GitHub.
  74. // Read the SoftEther VPN Patch Acceptance Policy in advance:
  75. // http://www.softether.org/5-download/src/9.patch
  76. //
  77. //
  78. // DEAR SECURITY EXPERTS
  79. // ---------------------
  80. //
  81. // If you find a bug or a security vulnerability please kindly inform us
  82. // about the problem immediately so that we can fix the security problem
  83. // to protect a lot of users around the world as soon as possible.
  84. //
  85. // Our e-mail address for security reports is:
  86. // softether-vpn-security [at] softether.org
  87. //
  88. // Please note that the above e-mail address is not a technical support
  89. // inquiry address. If you need technical assistance, please visit
  90. // http://www.softether.org/ and ask your question on the users forum.
  91. //
  92. // Thank you for your cooperation.
  93. //
  94. //
  95. // NO MEMORY OR RESOURCE LEAKS
  96. // ---------------------------
  97. //
  98. // The memory-leaks and resource-leaks verification under the stress
  99. // test has been passed before release this source code.
  100. // Account.h
  101. // Header of Account.c
  102. #ifndef ACCOUNT_H
  103. #define ACCOUNT_H
  104. // Policy item
  105. struct POLICY_ITEM
  106. {
  107. UINT Index;
  108. bool TypeInt;
  109. bool AllowZero;
  110. UINT MinValue;
  111. UINT MaxValue;
  112. UINT DefaultValue;
  113. char *FormatStr;
  114. };
  115. // Policy
  116. struct POLICY
  117. {
  118. // For Ver 2.0
  119. bool Access; // Grant access
  120. bool DHCPFilter; // Filter DHCP packets (IPv4)
  121. bool DHCPNoServer; // Prohibit the behavior of the DHCP server (IPv4)
  122. bool DHCPForce; // Force DHCP-assigned IP address (IPv4)
  123. bool NoBridge; // Prohibit the bridge behavior
  124. bool NoRouting; // Prohibit the router behavior (IPv4)
  125. bool CheckMac; // Prohibit the duplicate MAC address
  126. bool CheckIP; // Prohibit a duplicate IP address (IPv4)
  127. bool ArpDhcpOnly; // Prohibit the broadcast other than ARP, DHCP, ICMPv6
  128. bool PrivacyFilter; // Privacy filter mode
  129. bool NoServer; // Prohibit to operate as a TCP/IP server (IPv4)
  130. bool NoBroadcastLimiter; // Not to limit the number of broadcast
  131. bool MonitorPort; // Allow monitoring mode
  132. UINT MaxConnection; // Maximum number of TCP connections
  133. UINT TimeOut; // Communication time-out period
  134. UINT MaxMac; // Maximum number of MAC address
  135. UINT MaxIP; // Maximum number of IP address (IPv4)
  136. UINT MaxUpload; // Upload bandwidth
  137. UINT MaxDownload; // Download bandwidth
  138. bool FixPassword; // User can not change password
  139. UINT MultiLogins; // Multiple logins limit
  140. bool NoQoS; // Prohibit the use of VoIP / QoS features
  141. // For Ver 3.0
  142. bool RSandRAFilter; // Filter the Router Solicitation / Advertising packet (IPv6)
  143. bool RAFilter; // Filter the router advertisement packet (IPv6)
  144. bool DHCPv6Filter; // Filter DHCP packets (IPv6)
  145. bool DHCPv6NoServer; // Prohibit the behavior of the DHCP server (IPv6)
  146. bool NoRoutingV6; // Prohibit the router behavior (IPv6)
  147. bool CheckIPv6; // Prohibit the duplicate IP address (IPv6)
  148. bool NoServerV6; // Prohibit to operate as a TCP/IP server (IPv6)
  149. UINT MaxIPv6; // Maximum number of IP address (IPv6)
  150. bool NoSavePassword; // Prohibit to save the password in the VPN Client
  151. UINT AutoDisconnect; // Disconnect the VPN Client automatically at a certain period of time
  152. bool FilterIPv4; // Filter all IPv4 packets
  153. bool FilterIPv6; // Filter all IPv6 packets
  154. bool FilterNonIP; // Filter all non-IP packets
  155. bool NoIPv6DefaultRouterInRA; // Delete the default router specification from the IPv6 router advertisement
  156. bool NoIPv6DefaultRouterInRAWhenIPv6; // Delete the default router specification from the IPv6 router advertisement (Enable IPv6 connection)
  157. UINT VLanId; // Specify the VLAN ID
  158. bool Ver3; // Whether version 3.0
  159. };
  160. // Group
  161. struct USERGROUP
  162. {
  163. LOCK *lock; // Lock
  164. REF *ref; // Reference counter
  165. char *Name; // Group name
  166. wchar_t *RealName; // Display name
  167. wchar_t *Note; // Note
  168. POLICY *Policy; // Policy
  169. TRAFFIC *Traffic; // Traffic data
  170. };
  171. // User
  172. struct USER
  173. {
  174. LOCK *lock; // Lock
  175. REF *ref; // Reference counter
  176. char *Name; // User name
  177. wchar_t *RealName; // Real name
  178. wchar_t *Note; // Note
  179. char *GroupName; // Group name
  180. USERGROUP *Group; // Group
  181. UINT AuthType; // Authentication type
  182. void *AuthData; // Authentication data
  183. UINT64 CreatedTime; // Creation date and time
  184. UINT64 UpdatedTime; // Updating date
  185. UINT64 ExpireTime; // Expiration date
  186. UINT64 LastLoginTime; // Last login time
  187. UINT NumLogin; // Total number of logins
  188. POLICY *Policy; // Policy
  189. TRAFFIC *Traffic; // Traffic data
  190. };
  191. // Password authentication data
  192. struct AUTHPASSWORD
  193. {
  194. UCHAR HashedKey[SHA1_SIZE]; // Hashed passwords
  195. UCHAR NtLmSecureHash[MD5_SIZE]; // Encrypted password for the NTLM
  196. };
  197. // User certificate authentication data
  198. struct AUTHUSERCERT
  199. {
  200. X *UserX; // X509 certificate for the user
  201. };
  202. // Root certification authority authentication data
  203. struct AUTHROOTCERT
  204. {
  205. X_SERIAL *Serial; // Serial number
  206. wchar_t *CommonName; // CommonName
  207. };
  208. // Radius authentication data
  209. struct AUTHRADIUS
  210. {
  211. wchar_t *RadiusUsername; // User name in the Radius
  212. };
  213. // Windows NT authentication data
  214. struct AUTHNT
  215. {
  216. wchar_t *NtUsername; // User name on NT
  217. };
  218. // Macro
  219. #define POLICY_CURRENT_VERSION 3
  220. #define NUM_POLICY_ITEM ((sizeof(POLICY) / sizeof(UINT)) - 1)
  221. #define NUM_POLICY_ITEM_FOR_VER2 22
  222. #define NUM_POLICY_ITEM_FOR_VER3 38
  223. #define IS_POLICY_FOR_VER2(index) (((index) >= 0) && ((index) < NUM_POLICY_ITEM_FOR_VER2))
  224. #define IS_POLICY_FOR_VER3(index) (((index) >= 0) && ((index) < NUM_POLICY_ITEM_FOR_VER3))
  225. #define IS_POLICY_FOR_CURRENT_VER(index, ver) ((ver) >= 3 ? IS_POLICY_FOR_VER3(index) : IS_POLICY_FOR_VER2(index))
  226. #define POLICY_BOOL(p, i) (((bool *)(p))[(i)])
  227. #define POLICY_INT(p, i) (((UINT *)(p))[(i)])
  228. extern POLICY_ITEM policy_item[];
  229. // Function prototype
  230. int CompareUserName(void *p1, void *p2);
  231. int CompareGroupName(void *p1, void *p2);
  232. void AcLock(HUB *h);
  233. void AcUnlock(HUB *h);
  234. USERGROUP *NewGroup(char *name, wchar_t *realname, wchar_t *note);
  235. void ReleaseGroup(USERGROUP *g);
  236. void CleanupGroup(USERGROUP *g);
  237. USER *NewUser(char *name, wchar_t *realname, wchar_t *note, UINT authtype, void *authdata);
  238. void ReleaseUser(USER *u);
  239. void CleanupUser(USER *u);
  240. void FreeAuthData(UINT authtype, void *authdata);
  241. bool AcAddUser(HUB *h, USER *u);
  242. bool AcAddGroup(HUB *h, USERGROUP *g);
  243. USER *AcGetUser(HUB *h, char *name);
  244. USERGROUP *AcGetGroup(HUB *h, char *name);
  245. bool AcIsUser(HUB *h, char *name);
  246. bool AcIsGroup(HUB *h, char *name);
  247. bool AcDeleteUser(HUB *h, char *name);
  248. bool AcDeleteGroup(HUB *h, char *name);
  249. void JoinUserToGroup(USER *u, USERGROUP *g);
  250. void SetUserTraffic(USER *u, TRAFFIC *t);
  251. void SetGroupTraffic(USERGROUP *g, TRAFFIC *t);
  252. void AddUserTraffic(USER *u, TRAFFIC *diff);
  253. void AddGroupTraffic(USERGROUP *g, TRAFFIC *diff);
  254. void SetUserAuthData(USER *u, UINT authtype, void *authdata);
  255. void *NewPasswordAuthData(char *username, char *password);
  256. void *NewPasswordAuthDataRaw(UCHAR *hashed_password, UCHAR *ntlm_secure_hash);
  257. void *NewUserCertAuthData(X *x);
  258. void *NewRootCertAuthData(X_SERIAL *serial, wchar_t *common_name);
  259. void *NewRadiusAuthData(wchar_t *username);
  260. void *NewNTAuthData(wchar_t *username);
  261. void HashPassword(void *dst, char *username, char *password);
  262. POLICY *GetDefaultPolicy();
  263. POLICY *ClonePolicy(POLICY *policy);
  264. void SetUserPolicy(USER *u, POLICY *policy);
  265. void OverwritePolicy(POLICY **target, POLICY *p);
  266. POLICY *GetUserPolicy(USER *u);
  267. void SetGroupPolicy(USERGROUP *g, POLICY *policy);
  268. POLICY *GetGroupPolicy(USERGROUP *g);
  269. wchar_t *GetPolicyTitle(UINT id);
  270. wchar_t *GetPolicyDescription(UINT id);
  271. bool IsUserName(char *name);
  272. void *CopyAuthData(void *authdata, UINT authtype);
  273. UINT PolicyNum();
  274. bool PolicyIsSupportedForCascade(UINT i);
  275. UINT PolicyStrToId(char *name);
  276. char *PolicyIdToStr(UINT i);
  277. POLICY_ITEM *GetPolicyItem(UINT id);
  278. void GetPolicyValueRangeStr(wchar_t *str, UINT size, UINT id);
  279. void FormatPolicyValue(wchar_t *str, UINT size, UINT id, UINT value);
  280. char *NormalizePolicyName(char *name);
  281. #endif // ACCOUNT_H