1 // SoftEther VPN Source Code - Developer Edition Master Branch 2 // Cedar Communication Module 3 4 5 // Account.h 6 // Header of Account.c 7 8 #ifndef ACCOUNT_H 9 #define ACCOUNT_H 10 11 #include "CedarType.h" 12 13 #include "Mayaqua/Encrypt.h" 14 15 #define USER_MAC_STR_PREFIX L"MAC:" 16 #define USER_IPV4_STR_PREFIX L"IPv4:" 17 18 // Policy item 19 struct POLICY_ITEM 20 { 21 UINT Index; 22 bool TypeInt; 23 bool AllowZero; 24 UINT MinValue; 25 UINT MaxValue; 26 UINT DefaultValue; 27 char *FormatStr; 28 }; 29 30 // Policy 31 struct POLICY 32 { 33 // For Ver 2.0 34 bool Access; // Grant access 35 bool DHCPFilter; // Filter DHCP packets (IPv4) 36 bool DHCPNoServer; // Prohibit the behavior of the DHCP server (IPv4) 37 bool DHCPForce; // Force DHCP-assigned IP address (IPv4) 38 bool NoBridge; // Prohibit the bridge behavior 39 bool NoRouting; // Prohibit the router behavior (IPv4) 40 bool CheckMac; // Prohibit the duplicate MAC address 41 bool CheckIP; // Prohibit a duplicate IP address (IPv4) 42 bool ArpDhcpOnly; // Prohibit the broadcast other than ARP, DHCP, ICMPv6 43 bool PrivacyFilter; // Privacy filter mode 44 bool NoServer; // Prohibit to operate as a TCP/IP server (IPv4) 45 bool NoBroadcastLimiter; // Not to limit the number of broadcast 46 bool MonitorPort; // Allow monitoring mode 47 UINT MaxConnection; // Maximum number of TCP connections 48 UINT TimeOut; // Communication time-out period 49 UINT MaxMac; // Maximum number of MAC address 50 UINT MaxIP; // Maximum number of IP address (IPv4) 51 UINT MaxUpload; // Upload bandwidth 52 UINT MaxDownload; // Download bandwidth 53 bool FixPassword; // User can not change password 54 UINT MultiLogins; // Multiple logins limit 55 bool NoQoS; // Prohibit the use of VoIP / QoS features 56 57 // For Ver 3.0 58 bool RSandRAFilter; // Filter the Router Solicitation / Advertising packet (IPv6) 59 bool RAFilter; // Filter the router advertisement packet (IPv6) 60 bool DHCPv6Filter; // Filter DHCP packets (IPv6) 61 bool DHCPv6NoServer; // Prohibit the behavior of the DHCP server (IPv6) 62 bool NoRoutingV6; // Prohibit the router behavior (IPv6) 63 bool CheckIPv6; // Prohibit the duplicate IP address (IPv6) 64 bool NoServerV6; // Prohibit to operate as a TCP/IP server (IPv6) 65 UINT MaxIPv6; // Maximum number of IP address (IPv6) 66 bool NoSavePassword; // Prohibit to save the password in the VPN Client 67 UINT AutoDisconnect; // Disconnect the VPN Client automatically at a certain period of time 68 bool FilterIPv4; // Filter all IPv4 packets 69 bool FilterIPv6; // Filter all IPv6 packets 70 bool FilterNonIP; // Filter all non-IP packets 71 bool NoIPv6DefaultRouterInRA; // Delete the default router specification from the IPv6 router advertisement 72 bool NoIPv6DefaultRouterInRAWhenIPv6; // Delete the default router specification from the IPv6 router advertisement (Enable IPv6 connection) 73 UINT VLanId; // Specify the VLAN ID 74 75 bool Ver3; // Whether version 3.0 76 }; 77 78 // Group 79 struct USERGROUP 80 { 81 LOCK *lock; // Lock 82 REF *ref; // Reference counter 83 char *Name; // Group name 84 wchar_t *RealName; // Display name 85 wchar_t *Note; // Note 86 POLICY *Policy; // Policy 87 TRAFFIC *Traffic; // Traffic data 88 }; 89 90 // User 91 struct USER 92 { 93 LOCK *lock; // Lock 94 REF *ref; // Reference counter 95 char *Name; // User name 96 wchar_t *RealName; // Real name 97 wchar_t *Note; // Note 98 char *GroupName; // Group name 99 USERGROUP *Group; // Group 100 UINT AuthType; // Authentication type 101 void *AuthData; // Authentication data 102 UINT64 CreatedTime; // Creation date and time 103 UINT64 UpdatedTime; // Updating date 104 UINT64 ExpireTime; // Expiration date 105 UINT64 LastLoginTime; // Last login time 106 UINT NumLogin; // Total number of logins 107 POLICY *Policy; // Policy 108 TRAFFIC *Traffic; // Traffic data 109 }; 110 111 // Password authentication data 112 struct AUTHPASSWORD 113 { 114 UCHAR HashedKey[SHA1_SIZE]; // Hashed passwords 115 UCHAR NtLmSecureHash[MD5_SIZE]; // Encrypted password for the NTLM 116 }; 117 118 // User certificate authentication data 119 struct AUTHUSERCERT 120 { 121 X *UserX; // X509 certificate for the user 122 }; 123 124 // Root certification authority authentication data 125 struct AUTHROOTCERT 126 { 127 X_SERIAL *Serial; // Serial number 128 wchar_t *CommonName; // CommonName 129 }; 130 131 // Radius authentication data 132 struct AUTHRADIUS 133 { 134 wchar_t *RadiusUsername; // User name in the Radius 135 }; 136 137 // Windows NT authentication data 138 struct AUTHNT 139 { 140 wchar_t *NtUsername; // User name on NT 141 }; 142 143 144 145 // Macro 146 #define POLICY_CURRENT_VERSION 3 147 #define NUM_POLICY_ITEM ((sizeof(POLICY) / sizeof(UINT)) - 1) 148 #define NUM_POLICY_ITEM_FOR_VER2 22 149 #define NUM_POLICY_ITEM_FOR_VER3 38 150 151 #define IS_POLICY_FOR_VER2(index) (((index) >= 0) && ((index) < NUM_POLICY_ITEM_FOR_VER2)) 152 #define IS_POLICY_FOR_VER3(index) (((index) >= 0) && ((index) < NUM_POLICY_ITEM_FOR_VER3)) 153 154 #define IS_POLICY_FOR_CURRENT_VER(index, ver) ((ver) >= 3 ? IS_POLICY_FOR_VER3(index) : IS_POLICY_FOR_VER2(index)) 155 156 #define POLICY_BOOL(p, i) (((bool *)(p))[(i)]) 157 #define POLICY_INT(p, i) (((UINT *)(p))[(i)]) 158 159 extern POLICY_ITEM policy_item[]; 160 161 162 163 164 // Function prototype 165 int CompareUserName(void *p1, void *p2); 166 int CompareGroupName(void *p1, void *p2); 167 void AcLock(HUB *h); 168 void AcUnlock(HUB *h); 169 USERGROUP *NewGroup(char *name, wchar_t *realname, wchar_t *note); 170 void ReleaseGroup(USERGROUP *g); 171 void CleanupGroup(USERGROUP *g); 172 USER *NewUser(char *name, wchar_t *realname, wchar_t *note, UINT authtype, void *authdata); 173 void ReleaseUser(USER *u); 174 void CleanupUser(USER *u); 175 void FreeAuthData(UINT authtype, void *authdata); 176 bool AcAddUser(HUB *h, USER *u); 177 bool AcAddGroup(HUB *h, USERGROUP *g); 178 USER *AcGetUser(HUB *h, char *name); 179 USERGROUP *AcGetGroup(HUB *h, char *name); 180 bool AcIsUser(HUB *h, char *name); 181 bool AcIsGroup(HUB *h, char *name); 182 bool AcDeleteUser(HUB *h, char *name); 183 bool AcDeleteGroup(HUB *h, char *name); 184 void JoinUserToGroup(USER *u, USERGROUP *g); 185 void SetUserTraffic(USER *u, TRAFFIC *t); 186 void SetGroupTraffic(USERGROUP *g, TRAFFIC *t); 187 void SetUserAuthData(USER *u, UINT authtype, void *authdata); 188 void *NewPasswordAuthData(char *username, char *password); 189 void *NewPasswordAuthDataRaw(UCHAR *hashed_password, UCHAR *ntlm_secure_hash); 190 void *NewUserCertAuthData(X *x); 191 void *NewRootCertAuthData(X_SERIAL *serial, wchar_t *common_name); 192 void *NewRadiusAuthData(wchar_t *username); 193 void *NewNTAuthData(wchar_t *username); 194 void HashPassword(void *dst, char *username, char *password); 195 POLICY *GetDefaultPolicy(); 196 POLICY *ClonePolicy(POLICY *policy); 197 void SetUserPolicy(USER *u, POLICY *policy); 198 void OverwritePolicy(POLICY **target, POLICY *p); 199 void SetGroupPolicy(USERGROUP *g, POLICY *policy); 200 POLICY *GetGroupPolicy(USERGROUP *g); 201 wchar_t *GetPolicyTitle(UINT id); 202 wchar_t *GetPolicyDescription(UINT id); 203 bool IsUserName(char *name); 204 void *CopyAuthData(void *authdata, UINT authtype); 205 UINT PolicyNum(); 206 bool PolicyIsSupportedForCascade(UINT i); 207 UINT PolicyStrToId(char *name); 208 char *PolicyIdToStr(UINT i); 209 POLICY_ITEM *GetPolicyItem(UINT id); 210 void GetPolicyValueRangeStr(wchar_t *str, UINT size, UINT id); 211 void FormatPolicyValue(wchar_t *str, UINT size, UINT id, UINT value); 212 bool GetUserMacAddressFromUserNote(UCHAR *mac, wchar_t *note); 213 UINT GetUserIPv4AddressFromUserNote32(wchar_t *note); 214 215 #endif // ACCOUNT_H 216