function_name
stringlengths
1
80
function
stringlengths
14
10.6k
comment
stringlengths
12
8.02k
normalized_comment
stringlengths
6
6.55k
SiWriteUserList
void SiWriteUserList(FOLDER *f, LIST *o) { // Validate arguments if (f == NULL || o == NULL) { return; } LockList(o); { UINT i; for (i = 0;i < LIST_NUM(o);i++) { USER *u = LIST_DATA(o, i); SiWriteUserCfg(CfgCreateFolder(f, u->Name), u); } } UnlockList(o); }
/* Write the user list*/
Write the user list
SiLoadUserList
void SiLoadUserList(HUB *h, FOLDER *f) { TOKEN_LIST *t; UINT i; char *name; // Validate arguments if (f == NULL || h == NULL) { return; } t = CfgEnumFolderToTokenList(f); for (i = 0;i < t->NumTokens;i++) { FOLDER *ff; name = t->Token[i]; ff = CfgGetFolder(f, name); SiLoadUserCfg(h, ff); } FreeToken(t); }
/* Read the user list*/
Read the user list
SiWriteGroupCfg
void SiWriteGroupCfg(FOLDER *f, USERGROUP *g) { // Validate arguments if (f == NULL || g == NULL) { return; } Lock(g->lock); { CfgAddUniStr(f, "RealName", g->RealName); CfgAddUniStr(f, "Note", g->Note); if (g->Policy != NULL) { SiWritePolicyCfg(CfgCreateFolder(f, "Policy"), g->Policy, false); } SiWriteTraffic(f, "Traffic", g->Traffic); } Unlock(g->lock); }
/* Write the group information*/
Write the group information
SiWriteGroupList
void SiWriteGroupList(FOLDER *f, LIST *o) { // Validate arguments if (f == NULL || o == NULL) { return; } LockList(o); { UINT i; for (i = 0;i < LIST_NUM(o);i++) { USERGROUP *g = LIST_DATA(o, i); SiWriteGroupCfg(CfgCreateFolder(f, g->Name), g); } } UnlockList(o); }
/* Write the group list*/
Write the group list
SiLoadGroupList
void SiLoadGroupList(HUB *h, FOLDER *f) { TOKEN_LIST *t; UINT i; char *name; // Validate arguments if (f == NULL || h == NULL) { return; } t = CfgEnumFolderToTokenList(f); for (i = 0;i < t->NumTokens;i++) { name = t->Token[i]; SiLoadGroupCfg(h, CfgGetFolder(f, name)); } FreeToken(t); }
/* Read the group List*/
Read the group List
SiWriteCertList
void SiWriteCertList(FOLDER *f, LIST *o) { // Validate arguments if (f == NULL || o == NULL) { return; } LockList(o); { UINT i; X *x; for (i = 0;i < LIST_NUM(o);i++) { char name[MAX_SIZE]; BUF *b; x = LIST_DATA(o, i); Format(name, sizeof(name), "Cert%u", i); b = XToBuf(x, false); if (b != NULL) { CfgAddBuf(CfgCreateFolder(f, name), "X509", b); FreeBuf(b); } } } UnlockList(o); }
/* Write the certificates list*/
Write the certificates list
SiWriteHubDb
void SiWriteHubDb(FOLDER *f, HUBDB *db, bool no_save_ac_list) { // Validate arguments if (f == NULL || db == NULL) { return; } SiWriteUserList(CfgCreateFolder(f, "UserList"), db->UserList); SiWriteGroupList(CfgCreateFolder(f, "GroupList"), db->GroupList); SiWriteCertList(CfgCreateFolder(f, "CertList"), db->RootCertList); SiWriteCrlList(CfgCreateFolder(f, "CrlList"), db->CrlList); if (no_save_ac_list == false) { SiWriteAcList(CfgCreateFolder(f, "IPAccessControlList"), db->AcList); } }
/* Write the database*/
Write the database
SiLoadHubDb
void SiLoadHubDb(HUB *h, FOLDER *f) { // Validate arguments if (f == NULL || h == NULL) { return; } SiLoadGroupList(h, CfgGetFolder(f, "GroupList")); SiLoadUserList(h, CfgGetFolder(f, "UserList")); if (h->HubDb != NULL) { SiLoadCertList(h->HubDb->RootCertList, CfgGetFolder(f, "CertList")); SiLoadCrlList(h->HubDb->CrlList, CfgGetFolder(f, "CrlList")); SiLoadAcList(h->HubDb->AcList, CfgGetFolder(f, "IPAccessControlList")); } }
/* Read the database*/
Read the database
SiWriteHubLogCfg
void SiWriteHubLogCfg(FOLDER *f, HUB_LOG *g) { SiWriteHubLogCfgEx(f, g, false); }
/* Write the logging options*/
Write the logging options
SiLoadSecureNAT
void SiLoadSecureNAT(HUB *h, FOLDER *f) { VH_OPTION o; // Validate arguments if (h == NULL || f == NULL) { return; } // Read the VH_OPTION NiLoadVhOptionEx(&o, f); // Set the VH_OPTION Copy(h->SecureNATOption, &o, sizeof(VH_OPTION)); EnableSecureNAT(h, CfgGetBool(f, "Disabled") ? false : true); }
/* Read the SecureNAT configuration*/
Read the SecureNAT configuration
SiLoadL3Switchs
void SiLoadL3Switchs(SERVER *s, FOLDER *f) { UINT i; TOKEN_LIST *t; CEDAR *c; // Validate arguments if (s == NULL || f == NULL) { return; } c = s->Cedar; t = CfgEnumFolderToTokenList(f); if (t != NULL) { for (i = 0;i < t->NumTokens;i++) { char *name = t->Token[i]; L3SW *sw = L3AddSw(c, name); SiLoadL3SwitchCfg(sw, CfgGetFolder(f, name)); ReleaseL3Sw(sw); } } FreeToken(t); }
/* Read the Virtual Layer 3 switch list*/
Read the Virtual Layer 3 switch list
SiWriteL3Switchs
void SiWriteL3Switchs(FOLDER *f, SERVER *s) { UINT i; FOLDER *folder; CEDAR *c; // Validate arguments if (f == NULL || s == NULL) { return; } c = s->Cedar; LockList(c->L3SwList); { for (i = 0;i < LIST_NUM(c->L3SwList);i++) { L3SW *sw = LIST_DATA(c->L3SwList, i); Lock(sw->lock); { folder = CfgCreateFolder(f, sw->Name); SiWriteL3SwitchCfg(folder, sw); } Unlock(sw->lock); } } UnlockList(c->L3SwList); }
/* Write the Virtual Layer 3 switch list*/
Write the Virtual Layer 3 switch list
SiWriteLicenseManager
void SiWriteLicenseManager(FOLDER *f, SERVER *s) { }
/* Write the license list*/
Write the license list
SiLoadLicenseManager
void SiLoadLicenseManager(SERVER *s, FOLDER *f) { }
/* Read the license list*/
Read the license list
SiLoadGlobalParamItem
void SiLoadGlobalParamItem(UINT id, UINT value) { // Validate arguments if (id == 0) { return; } vpn_global_parameters[id] = value; }
/* Load global param itesm*/
Load global param itesm
SiLoadTraffic
void SiLoadTraffic(FOLDER *parent, char *name, TRAFFIC *t) { FOLDER *f; // Validate arguments if (t != NULL) { Zero(t, sizeof(TRAFFIC)); } if (parent == NULL || name == NULL || t == NULL) { return; } f = CfgGetFolder(parent, name); if (f == NULL) { return; } SiLoadTrafficInner(f, "SendTraffic", &t->Send); SiLoadTrafficInner(f, "RecvTraffic", &t->Recv); }
/* Read the traffic information*/
Read the traffic information
SiWriteTraffic
void SiWriteTraffic(FOLDER *parent, char *name, TRAFFIC *t) { FOLDER *f; // Validate arguments if (parent == NULL || name == NULL || t == NULL) { return; } f = CfgCreateFolder(parent, name); SiWriteTrafficInner(f, "SendTraffic", &t->Send); SiWriteTrafficInner(f, "RecvTraffic", &t->Recv); }
/* Write the traffic information*/
Write the traffic information
SiSaverThread
void SiSaverThread(THREAD *thread, void *param) { SERVER *s = (SERVER *)param; // Validate arguments if (thread == NULL || param == NULL) { return; } while (s->Halt == false) { // Save to the configuration file if (s->NoMoreSave == false) { SiWriteConfigurationFile(s); } Wait(s->SaveHaltEvent, s->AutoSaveConfigSpan); } }
/* Thread for writing configuration file*/
Thread for writing configuration file
StInit
void StInit() { if (server_lock != NULL) { return; } server_lock = NewLock(); }
/* Initialize the StXxx related function*/
Initialize the StXxx related function
StFree
void StFree() { DeleteLock(server_lock); server_lock = NULL; }
/* Release the StXxx related function*/
Release the StXxx related function
StStartServer
void StStartServer(bool bridge) { Lock(server_lock); { if (server != NULL) { // It has already started Unlock(server_lock); return; } // Create a server server = SiNewServer(bridge); } Unlock(server_lock); // StartCedarLog(); }
/* Start the server*/
Start the server
StStopServer
void StStopServer() { Lock(server_lock); { if (server == NULL) { // Not started Unlock(server_lock); return; } // Release the server SiReleaseServer(server); server = NULL; } Unlock(server_lock); StopCedarLog(); }
/* Stop the server*/
Stop the server
SiRebootServerThread
void SiRebootServerThread(THREAD *thread, void *param) { // Validate arguments if (thread == NULL) { return; } if (server == NULL) { return; } // Stop the server StStopServer(); // Start the server StStartServer((bool)param); }
/* Thread to restart the server*/
Thread to restart the server
SiRebootServer
void SiRebootServer(bool bridge) { SiRebootServerEx(bridge, false); }
/* Restart the server*/
Restart the server
SiApplySpecialListenerStatus
void SiApplySpecialListenerStatus(SERVER *s) { // Validate arguments if (s == NULL) { return; } if (s->DynListenerDns != NULL) { *s->DynListenerDns->EnablePtr = s->EnableVpnOverDns; ApplyDynamicListener(s->DynListenerDns); } if (s->DynListenerIcmp != NULL) { *s->DynListenerIcmp->EnablePtr = s->EnableVpnOverIcmp; ApplyDynamicListener(s->DynListenerIcmp); } }
/* Set the state of the special listener*/
Set the state of the special listener
SiReleaseServer
void SiReleaseServer(SERVER *s) { // Validate arguments if (s == NULL) { return; } if (Release(s->ref) == 0) { SiCleanupServer(s); } }
/* Release the server*/
Release the server
SiGetMemberSelectorUrl
bool SiGetMemberSelectorUrl(char *url, UINT url_size) { BUF *b; bool ret = false; // Validate arguments if (url == NULL) { return false; } b = ReadDump(MEMBER_SELECTOR_TXT_FILENAME); if (b == NULL) { return false; } while (true) { char *line = CfgReadNextLine(b); if (line == NULL) { break; } Trim(line); if (IsEmptyStr(line) == false && ret == false) { StrCpy(url, url_size, line); ret = true; } Free(line); } FreeBuf(b); return ret; }
/* Get the URL of the member selector*/
Get the URL of the member selector
SiCalledReadLogFile
PACK *SiCalledReadLogFile(SERVER *s, PACK *p) { RPC_READ_LOG_FILE t; PACK *ret; char filepath[MAX_PATH]; UINT offset; // Validate arguments if (s == NULL || p == NULL) { return NULL; } PackGetStr(p, "FilePath", filepath, sizeof(filepath)); offset = PackGetInt(p, "Offset"); Zero(&t, sizeof(t)); SiReadLocalLogFile(s, filepath, offset, &t); ret = NewPack(); OutRpcReadLogFile(ret, &t); FreeRpcReadLogFile(&t); return ret; }
/* Receive a log file reading directive*/
Receive a log file reading directive
SiCalledEnumLogFileList
PACK *SiCalledEnumLogFileList(SERVER *s, PACK *p) { RPC_ENUM_LOG_FILE t; PACK *ret; char hubname[MAX_HUBNAME_LEN + 1]; // Validate arguments if (s == NULL || p == NULL) { return NULL; } PackGetStr(p, "HubName", hubname, sizeof(hubname)); Zero(&t, sizeof(t)); SiEnumLocalLogFileList(s, hubname, &t); ret = NewPack(); OutRpcEnumLogFile(ret, &t); FreeRpcEnumLogFile(&t); return ret; }
/* Receive a log file enumeration directive*/
Receive a log file enumeration directive
SiCalledGetSessionStatus
PACK *SiCalledGetSessionStatus(SERVER *s, PACK *p) { RPC_SESSION_STATUS t; ADMIN a; PACK *ret; // Validate arguments if (s == NULL || p == NULL) { return NULL; } Zero(&t, sizeof(t)); InRpcSessionStatus(&t, p); Zero(&a, sizeof(a)); a.Server = s; a.ServerAdmin = true; if (StGetSessionStatus(&a, &t) != ERR_NO_ERROR) { FreeRpcSessionStatus(&t); return NULL; } ret = NewPack(); OutRpcSessionStatus(ret, &t); FreeRpcSessionStatus(&t); return ret; }
/* Receive a session information directive*/
Receive a session information directive
SiCalledEnumIpTable
PACK *SiCalledEnumIpTable(SERVER *s, PACK *p) { char hubname[MAX_HUBNAME_LEN + 1]; RPC_ENUM_IP_TABLE t; PACK *ret; // Validate arguments if (s == NULL || p == NULL) { return NewPack(); } if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false) { return NewPack(); } Zero(&t, sizeof(t)); SiEnumIpTable(s, hubname, &t); ret = NewPack(); OutRpcEnumIpTable(ret, &t); FreeRpcEnumIpTable(&t); return ret; }
/* IP table enumeration directive*/
IP table enumeration directive
SiCalledEnumMacTable
PACK *SiCalledEnumMacTable(SERVER *s, PACK *p) { char hubname[MAX_HUBNAME_LEN + 1]; RPC_ENUM_MAC_TABLE t; PACK *ret; // Validate arguments if (s == NULL || p == NULL) { return NewPack(); } if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false) { return NewPack(); } Zero(&t, sizeof(t)); SiEnumMacTable(s, hubname, &t); ret = NewPack(); OutRpcEnumMacTable(ret, &t); FreeRpcEnumMacTable(&t); return ret; }
/* MAC table enumeration directive*/
MAC table enumeration directive
SiCalledEnumSession
PACK *SiCalledEnumSession(SERVER *s, PACK *p) { char hubname[MAX_HUBNAME_LEN + 1]; RPC_ENUM_SESSION t; PACK *ret; // Validate arguments if (s == NULL || p == NULL) { return NewPack(); } if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false) { return NewPack(); } Zero(&t, sizeof(t)); SiEnumLocalSession(s, hubname, &t); ret = NewPack(); OutRpcEnumSession(ret, &t); FreeRpcEnumSession(&t); return ret; }
/* Receive a session enumeration directive*/
Receive a session enumeration directive
SiStartFarmControl
void SiStartFarmControl(SERVER *s) { // Validate arguments if (s == NULL || s->ServerType != SERVER_TYPE_FARM_CONTROLLER) { return; } s->FarmControlThreadHaltEvent = NewEvent(); s->FarmControlThread = NewThread(SiFarmControlThread, s); }
/* Start the farm controling*/
Start the farm controling
SiStopFarmControl
void SiStopFarmControl(SERVER *s) { // Validate arguments if (s == NULL || s->ServerType != SERVER_TYPE_FARM_CONTROLLER) { return; } Set(s->FarmControlThreadHaltEvent); WaitThread(s->FarmControlThread, INFINITE); ReleaseEvent(s->FarmControlThreadHaltEvent); ReleaseThread(s->FarmControlThread); }
/* Stop the farm controling*/
Stop the farm controling
SiCallGetSessionStatus
bool SiCallGetSessionStatus(SERVER *s, FARM_MEMBER *f, RPC_SESSION_STATUS *t) { PACK *p; // Validate arguments if (s == NULL || f == NULL) { return false; } p = NewPack(); OutRpcSessionStatus(p, t); FreeRpcSessionStatus(t); Zero(t, sizeof(RPC_SESSION_STATUS)); p = SiCallTask(f, p, "getsessionstatus"); if (p == NULL) { return false; } InRpcSessionStatus(t, p); FreePack(p); return true; }
/* Send a session information directive*/
Send a session information directive
SiCallReadLogFile
bool SiCallReadLogFile(SERVER *s, FARM_MEMBER *f, RPC_READ_LOG_FILE *t) { PACK *p; // Validate arguments if (s == NULL || f == NULL) { return false; } p = NewPack(); OutRpcReadLogFile(p, t); FreeRpcReadLogFile(t); Zero(t, sizeof(RPC_READ_LOG_FILE)); p = SiCallTask(f, p, "readlogfile"); if (p == NULL) { return false; } InRpcReadLogFile(t, p); FreePack(p); return true; }
/* Log file reading directive*/
Log file reading directive
SiCallEnumLogFileList
bool SiCallEnumLogFileList(SERVER *s, FARM_MEMBER *f, RPC_ENUM_LOG_FILE *t, char *hubname) { PACK *p; // Validate arguments if (s == NULL || f == NULL) { return false; } p = NewPack(); OutRpcEnumLogFile(p, t); FreeRpcEnumLogFile(t); Zero(t, sizeof(RPC_ENUM_LOG_FILE)); PackAddStr(p, "HubName", hubname); p = SiCallTask(f, p, "enumlogfilelist"); if (p == NULL) { return false; } InRpcEnumLogFile(t, p); FreePack(p); return true; }
/* Log file enumeration directive*/
Log file enumeration directive
SiCallUpdateHub
void SiCallUpdateHub(SERVER *s, FARM_MEMBER *f, HUB *h) { PACK *p; // Validate arguments if (s == NULL || f == NULL) { return; } if (f->Me == false) { p = NewPack(); SiPackAddCreateHub(p, h); p = SiCallTask(f, p, "updatehub"); FreePack(p); } }
/* Submit a HUB update directive*/
Submit a HUB update directive
SiCallDeleteMacTable
void SiCallDeleteMacTable(SERVER *s, FARM_MEMBER *f, char *hubname, UINT key) { PACK *p; // Validate arguments if (s == NULL || f == NULL || hubname == NULL) { return; } p = NewPack(); PackAddStr(p, "HubName", hubname); PackAddInt(p, "Key", key); p = SiCallTask(f, p, "deletemactable"); FreePack(p); }
/* Send a MAC address deletion directive*/
Send a MAC address deletion directive
SiCallDeleteIpTable
void SiCallDeleteIpTable(SERVER *s, FARM_MEMBER *f, char *hubname, UINT key) { PACK *p; // Validate arguments if (s == NULL || f == NULL || hubname == NULL) { return; } p = NewPack(); PackAddStr(p, "HubName", hubname); PackAddInt(p, "Key", key); p = SiCallTask(f, p, "deleteiptable"); FreePack(p); }
/* Send an IP address delete directive*/
Send an IP address delete directive
SiCallDeleteSession
void SiCallDeleteSession(SERVER *s, FARM_MEMBER *f, char *hubname, char *session_name) { PACK *p; // Validate arguments if (s == NULL || f == NULL || hubname == NULL || session_name == NULL) { return; } p = NewPack(); PackAddStr(p, "HubName", hubname); PackAddStr(p, "SessionName", session_name); p = SiCallTask(f, p, "deletesession"); FreePack(p); }
/* Send a session deletion directive*/
Send a session deletion directive
SiCallGetNatStatus
void SiCallGetNatStatus(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_NAT_STATUS *t) { PACK *p; // Validate arguments if (s == NULL || f == NULL || hubname == NULL || t == NULL) { return; } p = NewPack(); PackAddStr(p, "HubName", hubname); p = SiCallTask(f, p, "getnatstatus"); Zero(t, sizeof(RPC_NAT_STATUS)); InRpcNatStatus(t, p); FreePack(p); }
/* Send a SecureNAT status acquisition directive*/
Send a SecureNAT status acquisition directive
SiCallEnumDhcp
void SiCallEnumDhcp(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_DHCP *t) { PACK *p; // Validate arguments if (s == NULL || f == NULL || hubname == NULL || t == NULL) { return; } p = NewPack(); PackAddStr(p, "HubName", hubname); p = SiCallTask(f, p, "enumdhcp"); Zero(t, sizeof(RPC_ENUM_DHCP)); InRpcEnumDhcp(t, p); FreePack(p); }
/* Submit a DHCP entry enumeration directive*/
Submit a DHCP entry enumeration directive
SiCallEnumNat
void SiCallEnumNat(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_NAT *t) { PACK *p; // Validate arguments if (s == NULL || f == NULL || hubname == NULL || t == NULL) { return; } p = NewPack(); PackAddStr(p, "HubName", hubname); p = SiCallTask(f, p, "enumnat"); Zero(t, sizeof(RPC_ENUM_NAT)); InRpcEnumNat(t, p); FreePack(p); }
/* Submit a NAT entry enumeration directive */
Submit a NAT entry enumeration directive
SiNumAccessFromPack
UINT SiNumAccessFromPack(PACK *p) { // Validate arguments if (p == NULL) { return 0; } return PackGetIndexCount(p, "Active"); }
/* Get number of access contained in the PACK*/
Get number of access contained in the PACK
SiAccessListToPack
void SiAccessListToPack(PACK *p, LIST *o) { // Validate arguments if (p == NULL || o == NULL) { return; } LockList(o); { UINT i; for (i = 0;i < LIST_NUM(o);i++) { ACCESS *a = LIST_DATA(o, i); SiAccessToPack(p, a, i, LIST_NUM(o)); } } UnlockList(o); }
/* Convert the PACK to an access list*/
Convert the PACK to an access list
SiExecTask
PACK *SiExecTask(FARM_MEMBER *f, PACK *p) { FARM_TASK *t; // Validate arguments if (f == NULL || p == NULL) { return NULL; } t = SiFarmServPostTask(f, p); if (t == NULL) { return NULL; } return SiFarmServWaitTask(t); }
/* Execute the task*/
Execute the task
SiFarmServWaitTask
PACK *SiFarmServWaitTask(FARM_TASK *t) { PACK *response; // Validate arguments if (t == NULL) { return NULL; } Wait(t->CompleteEvent, INFINITE); ReleaseEvent(t->CompleteEvent); FreePack(t->Request); response = t->Response; Free(t); if (PackGetInt(response, "succeed") == 0) { // Task calling fails for any reason FreePack(response); return NULL; } return response; }
/* Wait for task results*/
Wait for task results
CompareHubList
int CompareHubList(void *p1, void *p2) { HUB_LIST *h1, *h2; if (p1 == NULL || p2 == NULL) { return 0; } h1 = *(HUB_LIST **)p1; h2 = *(HUB_LIST **)p2; if (h1 == NULL || h2 == NULL) { return 0; } return StrCmpi(h1->Name, h2->Name); }
/* Search in HUB list*/
Search in HUB list
SiStopConnectToController
void SiStopConnectToController(FARM_CONTROLLER *f) { // Validate arguments if (f == NULL) { return; } f->Halt = true; // Stop the connection Lock(f->lock); { Disconnect(f->Sock); } Unlock(f->lock); Set(f->HaltEvent); // Wait for the thread termination WaitThread(f->Thread, INFINITE); ReleaseThread(f->Thread); DeleteLock(f->lock); ReleaseEvent(f->HaltEvent); Free(f); }
/* Disconnect the connection to the controller*/
Disconnect the connection to the controller
SiStartConnectToController
FARM_CONTROLLER *SiStartConnectToController(SERVER *s) { FARM_CONTROLLER *f; THREAD *t; // Validate arguments if (s == NULL) { return NULL; } f = ZeroMalloc(sizeof(FARM_CONTROLLER)); f->Server = s; f->LastError = ERR_TRYING_TO_CONNECT; f->HaltEvent = NewEvent(); f->lock = NewLock(); t = NewThread(SiConnectToControllerThread, f); WaitThreadInit(t); ReleaseThread(t); return f; }
/* Start a connection to the controller*/
Start a connection to the controller
SiGetCurrentRegion
void SiGetCurrentRegion(CEDAR *c, char *region, UINT region_size) { ClearStr(region, region_size); // Validate arguments if (c == NULL || region == NULL) { return; } Lock(c->CurrentRegionLock); { StrCpy(region, region_size, c->CurrentRegion); } Unlock(c->CurrentRegionLock); if (IsEmptyStr(region)) { if (GetCurrentLangId() == SE_LANG_JAPANESE) { StrCpy(region, region_size, "JP"); } else if (GetCurrentLangId() == SE_LANG_CHINESE_ZH) { StrCpy(region, region_size, "CN"); } } }
/* Get the current version*/
Get the current version
SiUpdateCurrentRegion
void SiUpdateCurrentRegion(CEDAR *c, char *region, bool force_update) { bool changed = false; // Validate arguments if (c == NULL) { return; } if (IsEmptyStr(region) == false) { Lock(c->CurrentRegionLock); { if (StrCmpi(c->CurrentRegion, region) != 0) { StrCpy(c->CurrentRegion, sizeof(c->CurrentRegion), region); changed = true; } } Unlock(c->CurrentRegionLock); } if (force_update) { changed = true; } if (changed) { FlushServerCaps(c->Server); } }
/* Update the current region*/
Update the current region
SiNewServer
SERVER *SiNewServer(bool bridge) { return SiNewServerEx(bridge, false, false); }
/* Create a server*/
Create a server
FreeIPCAsync
void FreeIPCAsync(IPC_ASYNC *a) { // Validate arguments if (a == NULL) { return; } TubeDisconnect(a->TubeForDisconnect); WaitThread(a->Thread, INFINITE); ReleaseThread(a->Thread); if (a->Ipc != NULL) { FreeIPC(a->Ipc); a->Ipc = NULL; } if (a->SockEvent != NULL) { ReleaseSockEvent(a->SockEvent); } ReleaseCedar(a->Cedar); ReleaseTube(a->TubeForDisconnect); if (a->Param.ClientCertificate != NULL) { FreeX(a->Param.ClientCertificate); } Free(a); }
/* Release the IPC asynchronous connection object*/
Release the IPC asynchronous connection object
NewIPCByParam
IPC *NewIPCByParam(CEDAR *cedar, IPC_PARAM *param, UINT *error_code) { IPC *ipc; // Validate arguments if (cedar == NULL || param == NULL) { return NULL; } ipc = NewIPC(cedar, param->ClientName, param->Postfix, param->HubName, param->UserName, param->Password, error_code, &param->ClientIp, param->ClientPort, &param->ServerIp, param->ServerPort, param->ClientHostname, param->CryptName, param->BridgeMode, param->Mss, NULL, param->ClientCertificate, param->Layer); return ipc; }
/* Start a new IPC connection by specifying the parameter structure*/
Start a new IPC connection by specifying the parameter structure
NewIPCBySock
IPC *NewIPCBySock(CEDAR *cedar, SOCK *s, void *mac_address) { IPC *ipc; // Validate arguments if (cedar == NULL || mac_address == NULL || s == NULL) { return NULL; } ipc = ZeroMalloc(sizeof(IPC)); ipc->Cedar = cedar; AddRef(cedar->ref); ipc->Sock = s; AddRef(s->ref); Copy(ipc->MacAddress, mac_address, 6); ipc->Interrupt = NewInterruptManager(); // Create an ARP table ipc->ArpTable = NewList(IPCCmpArpTable); // Create an IPv4 reception queue ipc->IPv4ReceivedQueue = NewQueue(); ipc->FlushList = NewTubeFlushList(); return ipc; }
/* Create a new IPC based on SOCK*/
Create a new IPC based on SOCK
IsIPCConnected
bool IsIPCConnected(IPC *ipc) { // Validate arguments if (ipc == NULL) { return false; } if (IsTubeConnected(ipc->Sock->RecvTube) == false || IsTubeConnected(ipc->Sock->SendTube) == false) { return false; } return true; }
/* Get whether the IPC is connected*/
Get whether the IPC is connected
IPCSetSockEventWhenRecvL2Packet
void IPCSetSockEventWhenRecvL2Packet(IPC *ipc, SOCK_EVENT *e) { // Validate arguments if (ipc == NULL || e == NULL) { return; } JoinSockToSockEvent(ipc->Sock, e); }
/* Get to hit the SOCK_EVENT when a new data has arrived in the IPC*/
Get to hit the SOCK_EVENT when a new data has arrived in the IPC
IPCDhcpSetConditionalUserClass
void IPCDhcpSetConditionalUserClass(IPC *ipc, DHCP_OPTION_LIST *req) { HUB *hub; hub = GetHub(ipc->Cedar, ipc->HubName); if (hub == NULL) { return; } if (hub->Option && hub->Option->UseHubNameAsDhcpUserClassOption) { StrCpy(req->UserClass, sizeof(req->UserClass), ipc->HubName); } ReleaseHub(hub); }
/* Set User Class option if corresponding Virtual Hub optin is set*/
Set User Class option if corresponding Virtual Hub optin is set
IPCDhcpFreeIP
void IPCDhcpFreeIP(IPC *ipc, IP *dhcp_server) { DHCP_OPTION_LIST req; UINT tran_id = Rand32(); // Validate arguments if (ipc == NULL || dhcp_server == NULL) { return; } Zero(&req, sizeof(req)); req.Opcode = DHCP_RELEASE; req.ServerAddress = IPToUINT(dhcp_server); IPCDhcpSetConditionalUserClass(ipc, &req); FreeDHCPv4Data(IPCSendDhcpRequest(ipc, NULL, tran_id, &req, 0, 0, NULL)); }
/* Release the IP address from the DHCP server*/
Release the IP address from the DHCP server
IPCDhcpRenewIP
void IPCDhcpRenewIP(IPC *ipc, IP *dhcp_server) { DHCP_OPTION_LIST req; UINT tran_id = Rand32(); // Validate arguments if (ipc == NULL || dhcp_server == NULL) { return; } // Send a DHCP Request Zero(&req, sizeof(req)); req.Opcode = DHCP_REQUEST; StrCpy(req.Hostname, sizeof(req.Hostname), ipc->ClientHostname); req.RequestedIp = IPToUINT(&ipc->ClientIPAddress); IPCDhcpSetConditionalUserClass(ipc, &req); FreeDHCPv4Data(IPCSendDhcpRequest(ipc, dhcp_server, tran_id, &req, 0, 0, NULL)); }
/* Update the IP address using the DHCP*/
Update the IP address using the DHCP
IsValidUnicastMacAddress
bool IsValidUnicastMacAddress(UCHAR *mac) { // Validate arguments if (mac == NULL) { return false; } if (mac[0] & 0x01) { return false; } if (IsZero(mac, 6)) { return false; } return true; }
/* Identify whether the MAC address is a normal unicast address*/
Identify whether the MAC address is a normal unicast address
IsValidUnicastIPAddress4
bool IsValidUnicastIPAddress4(IP *ip) { UINT i; // Validate arguments if (IsIP4(ip) == false) { return false; } if (IsZeroIP(ip)) { return false; } if (ip->addr[0] >= 224 && ip->addr[0] <= 239) { // IPv4 Multicast return false; } for (i = 0;i < 4;i++) { if (ip->addr[i] != 255) { return true; } } return false; }
/* Identify whether the IP address is a normal unicast address*/
Identify whether the IP address is a normal unicast address
IPCProcessInterrupts
void IPCProcessInterrupts(IPC *ipc) { // Validate arguments if (ipc == NULL) { return; } FlushTubeFlushList(ipc->FlushList); }
/* Interrupt process (This is called periodically)*/
Interrupt process (This is called periodically)
IPCProcessL3Events
void IPCProcessL3Events(IPC *ipc) { IPCProcessL3EventsEx(ipc, 0); }
/* Process the L3 event by the IPC*/
Process the L3 event by the IPC
IPCSendIPv4WithDestMacAddr
void IPCSendIPv4WithDestMacAddr(IPC *ipc, void *data, UINT size, UCHAR *dest_mac_addr) { UCHAR tmp[1514]; // Validate arguments if (ipc == NULL || data == NULL || size < 20 || size > 1500 || dest_mac_addr == NULL) { return; } // Destination Copy(tmp + 0, dest_mac_addr, 6); // Source Copy(tmp + 6, ipc->MacAddress, 6); // Protocol number WRITE_USHORT(tmp + 12, MAC_PROTO_IPV4); // Data Copy(tmp + 14, data, size); // Send IPCSendL2(ipc, tmp, size + 14); }
/* Send an IPv4 packet with a specified destination MAC address*/
Send an IPv4 packet with a specified destination MAC address
IPCFlushArpTable
void IPCFlushArpTable(IPC *ipc) { IPCFlushArpTableEx(ipc, 0); }
/* Remove old ARP table entries*/
Remove old ARP table entries
IPCSearchArpTable
IPC_ARP *IPCSearchArpTable(IPC *ipc, IP *ip) { IPC_ARP t; IPC_ARP *a; // Validate arguments if (ipc == NULL || ip == NULL) { return NULL; } Copy(&t.Ip, ip, sizeof(IP)); a = Search(ipc->ArpTable, &t); return a; }
/* Search the ARP table*/
Search the ARP table
IPCFreeARP
void IPCFreeARP(IPC_ARP *a) { BLOCK *b; // Validate arguments if (a == NULL) { return; } while (true) { b = GetNext(a->PacketQueue); if (b == NULL) { break; } FreeBlock(b); } ReleaseQueue(a->PacketQueue); Free(a); }
/* Release the ARP entry*/
Release the ARP entry
IPCNewARP
IPC_ARP *IPCNewARP(IP *ip, UCHAR *mac_address) { IPC_ARP *a; // Validate arguments if (ip == NULL) { return NULL; } a = ZeroMalloc(sizeof(IPC_ARP)); Copy(&a->Ip, ip, sizeof(IP)); if (mac_address != NULL) { Copy(a->MacAddress, mac_address, 6); a->Resolved = true; a->ExpireTime = Tick64() + (UINT64)IPC_ARP_LIFETIME; } else { a->GiveupTime = Tick64() + (UINT64)IPC_ARP_GIVEUPTIME; } a->PacketQueue = NewQueueFast(); return a; }
/* Create a new ARP entry*/
Create a new ARP entry
IPCCmpArpTable
int IPCCmpArpTable(void *p1, void *p2) { IPC_ARP *a1, *a2; // Validate arguments if (p1 == NULL || p2 == NULL) { return 0; } a1 = *(IPC_ARP **)p1; a2 = *(IPC_ARP **)p2; if (a1 == NULL || a2 == NULL) { return 0; } return CmpIpAddr(&a1->Ip, &a2->Ip); }
/* Compare ARP entries*/
Compare ARP entries
IPCSendL2
void IPCSendL2(IPC *ipc, void *data, UINT size) { // Validate arguments if (ipc == NULL || data == NULL || size == 0) { return; } if (ipc->Sock == NULL) { return; } TubeSendEx(ipc->Sock->SendTube, data, size, NULL, true); AddTubeToFlushList(ipc->FlushList, ipc->Sock->SendTube); }
/* Send an Ethernet packet (client -> server)*/
Send an Ethernet packet (client -> server)
IPCRecvIPv4
BLOCK *IPCRecvIPv4(IPC *ipc) { BLOCK *b; // Validate arguments if (ipc == NULL) { return NULL; } b = GetNext(ipc->IPv4ReceivedQueue); return b; }
/* Receive an IPv4 packet (server -> client)*/
Receive an IPv4 packet (server -> client)
IPCRecvL2
BLOCK *IPCRecvL2(IPC *ipc) { TUBEDATA *d; BLOCK *b; // Validate arguments if (ipc == NULL) { return NULL; } if (ipc->Sock == NULL) { return NULL; } d = TubeRecvAsync(ipc->Sock->RecvTube); if (d == NULL) { return NULL; } b = NewBlock(d->Data, d->DataSize, 0); Free(d->Header); Free(d); return b; }
/* Receive an Ethernet packet (server -> client)*/
Receive an Ethernet packet (server -> client)
IPsecWin7Free
void IPsecWin7Free(IPSEC_WIN7 *w) { // Validate arguments if (w == NULL) { return; } if (w->hEngine != NULL) { api->FwpmEngineClose0(w->hEngine); } if (w->hDriverFile != NULL && w->hDriverFile != INVALID_HANDLE_VALUE) { CloseHandle(w->hDriverFile); } Free(w); }
/* Release the module*/
Release the module
IPsecWin7InitDriver
bool IPsecWin7InitDriver() { bool ret; void *lock = MsInitGlobalLock("IPsecWin7InitDriver", false); void *p = MsDisableWow64FileSystemRedirection(); MsGlobalLock(lock); { ret = IPsecWin7InitDriverInner(); } MsGlobalUnlock(lock); MsFreeGlobalLock(lock); MsRestoreWow64FileSystemRedirection(p); Debug("IPsecWin7InitDriver: %u\n", ret); return ret; }
/* Initialize and start the driver*/
Initialize and start the driver
SetCurrentIPsecWin7DriverBuild
void SetCurrentIPsecWin7DriverBuild() { MsRegWriteInt(REG_LOCAL_MACHINE, IPSEC_WIN7_DRIVER_REGKEY, (MsIsWindows10() ? IPSEC_WIN7_DRIVER_BUILDNUMBER_WIN10 : IPSEC_WIN7_DRIVER_BUILDNUMBER), CEDAR_VERSION_BUILD); }
/* Write the build number of the current driver*/
Write the build number of the current driver
GetCurrentIPsecWin7DriverBuild
UINT GetCurrentIPsecWin7DriverBuild() { return MsRegReadInt(REG_LOCAL_MACHINE, IPSEC_WIN7_DRIVER_REGKEY, (MsIsWindows10() ? IPSEC_WIN7_DRIVER_BUILDNUMBER_WIN10 : IPSEC_WIN7_DRIVER_BUILDNUMBER)); }
/* Get the build number of the current driver*/
Get the build number of the current driver
GetRecvPeapMessage
bool GetRecvPeapMessage(EAP_CLIENT *e, EAP_MESSAGE *msg) { BUF *b; bool ret = false; if (e == NULL) { return false; } if (e->SslPipe == NULL) { return false; } b = ReadFifoAll(e->SslPipe->SslInOut->RecvFifo); if (b->Size >= 1) { Zero(msg, sizeof(EAP_MESSAGE)); msg->Len = Endian16(b->Size + 4); Copy(&msg->Type, b->Buf, MIN(b->Size, 1501)); ret = true; } FreeBuf(b); return ret; }
/* Get a received PEAP message (unencrypted)*/
Get a received PEAP message (unencrypted)
EapSendPacket
bool EapSendPacket(EAP_CLIENT *e, RADIUS_PACKET *r) { BUF *b; bool ret = false; if (e == NULL || r == NULL) { return false; } b = GenerateRadiusPacket(r, e->SharedSecret); if (b != NULL) { UINT r = SendTo(e->UdpSock, &e->ServerIp, e->ServerPort, b->Buf, b->Size); if (!(r == 0 && e->UdpSock->IgnoreSendErr == false)) { ret = true; } FreeBuf(b); } return ret; }
/* Send a RADIUS packet*/
Send a RADIUS packet
ReleaseEapClient
void ReleaseEapClient(EAP_CLIENT *e) { if (e == NULL) { return; } if (Release(e->Ref) == 0) { CleanupEapClient(e); } }
/* Free a EAP client*/
Free a EAP client
NewRadiusAvp
RADIUS_AVP *NewRadiusAvp(UCHAR type, UINT vendor_id, UCHAR vendor_code, void *data, UINT size) { RADIUS_AVP *p = ZeroMalloc(sizeof(RADIUS_AVP)); p->Type = type; p->VendorId = vendor_id; p->VendorCode = vendor_code; p->DataSize = (UCHAR)size; Copy(p->Data, data, (UCHAR)size); if (size >= 256) { Debug("!! size = %u\n", size); } return p; }
/* New RADIUS AVP value*/
New RADIUS AVP value
NewRadiusPacket
RADIUS_PACKET *NewRadiusPacket(UCHAR code, UCHAR packet_id) { RADIUS_PACKET *r = ZeroMalloc(sizeof(RADIUS_PACKET)); r->Code = code; r->PacketId = packet_id; r->AvpList = NewListFast(NULL); return r; }
/* New RADIUS packet*/
New RADIUS packet
GetRadiusAvp
RADIUS_AVP *GetRadiusAvp(RADIUS_PACKET *p, UCHAR type) { UINT i; if (p == NULL) { return NULL; } for (i = 0;i < LIST_NUM(p->AvpList);i++) { RADIUS_AVP *avp = LIST_DATA(p->AvpList, i); if (avp->Type == type) { return avp; } } return NULL; }
/* Get RADIUS AVP*/
Get RADIUS AVP
FreeRadiusPacket
void FreeRadiusPacket(RADIUS_PACKET *p) { UINT i; if (p == NULL) { return; } if (p->AvpList != NULL) { for (i = 0;i < LIST_NUM(p->AvpList);i++) { RADIUS_AVP *a = LIST_DATA(p->AvpList, i); Free(a); } ReleaseList(p->AvpList); } Free(p->Parse_EapMessage); Free(p); }
/* Free a RADIUS packet*/
Free a RADIUS packet
RadiusCreateUserPassword
BUF *RadiusCreateUserPassword(void *data, UINT size) { BUF *b; UCHAR code, sz; // Validate arguments if (size != 0 && data == NULL || size >= 253) { return NULL; } b = NewBuf(); code = 2; sz = 2 + (UCHAR)size; WriteBuf(b, &code, 1); WriteBuf(b, &sz, 1); WriteBuf(b, data, size); return b; }
/* Create a password attribute for Radius*/
Create a password attribute for Radius
RadiusCreateNasId
BUF *RadiusCreateNasId(char *name) { BUF *b; UCHAR code, size; // Validate arguments if (name == NULL) { return NULL; } if (StrLen(name) == 0 || StrLen(name) >= 128) { return NULL; } b = NewBuf(); code = 32; size = 2 + (UCHAR)StrLen(name); WriteBuf(b, &code, 1); WriteBuf(b, &size, 1); WriteBuf(b, name, StrLen(name)); return b; }
/* Generate an ID attribute of Nas*/
Generate an ID attribute of Nas
RadiusCreateUserName
BUF *RadiusCreateUserName(wchar_t *username) { BUF *b; UCHAR code, size; UCHAR utf8[254]; // Validate arguments if (username == NULL) { return NULL; } // Convert the user name to a Unicode string UniToStr(utf8, sizeof(utf8), username); utf8[253] = 0; b = NewBuf(); code = 1; size = 2 + (UCHAR)StrLen(utf8); WriteBuf(b, &code, 1); WriteBuf(b, &size, 1); WriteBuf(b, utf8, StrLen(utf8)); return b; }
/* Create a user name attribute for Radius*/
Create a user name attribute for Radius
SmProxyDlgInit
void SmProxyDlgInit(HWND hWnd, INTERNET_SETTING *t) { // Validate arguments if (hWnd == NULL || t == NULL) { return; } Check(hWnd, R_DIRECT_TCP, t->ProxyType == PROXY_DIRECT); Check(hWnd, R_HTTPS, t->ProxyType == PROXY_HTTP); Check(hWnd, R_SOCKS, t->ProxyType == PROXY_SOCKS); Check(hWnd, R_SOCKS5, t->ProxyType == PROXY_SOCKS5); SmProxyDlgUpdate(hWnd, t); }
/* Proxy Settings dialog initialization*/
Proxy Settings dialog initialization
SmProxyDlgUpdate
void SmProxyDlgUpdate(HWND hWnd, INTERNET_SETTING *t) { bool ok = false; // Validate arguments if (hWnd == NULL || t == NULL) { return; } if (t->ProxyType == PROXY_DIRECT) { ok = true; } else { if (IsEmptyStr(t->ProxyHostName) == false && t->ProxyPort != 0) { ok = true; } } SetEnable(hWnd, IDOK, ok); SetEnable(hWnd, B_PROXY_CONFIG, !IsChecked(hWnd, R_DIRECT_TCP)); }
/* Proxy Settings dialog update*/
Proxy Settings dialog update
SmProxy
bool SmProxy(HWND hWnd, INTERNET_SETTING *t) { // Validate arguments if (t == NULL) { return false; } return Dialog(hWnd, D_SM_PROXY, SmProxyDlg, t); }
/* Proxy Settings generic dialog*/
Proxy Settings generic dialog
SmAzureSetStatus
void SmAzureSetStatus(HWND hWnd, SM_AZURE *a) { RPC_AZURE_STATUS st; // Validate arguments if (hWnd == NULL || a == NULL) { return; } Zero(&st, sizeof(st)); st.IsEnabled = IsChecked(hWnd, R_ENABLE); if (CALL(hWnd, ScSetAzureStatus(a->s->Rpc, &st)) == false) { EndDialog(hWnd, 0); return; } SmAzureDlgRefresh(hWnd, a); }
/* Set the status*/
Set the status
SmAzure
void SmAzure(HWND hWnd, SM_SERVER *s, bool on_setup) { SM_AZURE a; // Validate arguments if (s == NULL) { return; } Zero(&a, sizeof(a)); a.s = s; a.OnSetup = on_setup; Dialog(hWnd, D_SM_AZURE, SmAzureDlg, &a); }
/* VPN Azure Setup screen*/
VPN Azure Setup screen
SmVmBridgeDlg
UINT SmVmBridgeDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param) { switch (msg) { case WM_INITDIALOG: DlgFont(hWnd, S_TITLE, 14, true); SetIcon(hWnd, 0, ICO_NIC_ONLINE); break; case WM_COMMAND: switch (wParam) { case IDOK: case IDCANCEL: Close(hWnd); break; } break; case WM_CLOSE: EndDialog(hWnd, 0); break; } return 0; }
/* Notification screen about the bridge in VM*/
Notification screen about the bridge in VM
SmSpecialListener
void SmSpecialListener(HWND hWnd, SM_SERVER *s) { // Validate arguments if (s == NULL) { return; } Dialog(hWnd, D_SM_SPECIALLISTENER, SmSpecialListenerDlg, s); }
/* Setting screen of VPN over ICMP, etc.*/
Setting screen of VPN over ICMP, etc.
SmOpenVpn
void SmOpenVpn(HWND hWnd, SM_SERVER *s) { // Validate arguments if (s == NULL) { return; } Dialog(hWnd, D_SM_OPENVPN, SmOpenVpnDlg, s); }
/* Open the OpenVPN dialog */
Open the OpenVPN dialog
SmEtherIpId
bool SmEtherIpId(HWND hWnd, SM_ETHERIP_ID *t) { // Validate arguments if (t == NULL) { return false; } if (Dialog(hWnd, D_SM_ETHERIP_ID, SmEtherIpIdDlg, t) == 0) { return false; } return true; }
/* Open the EtherIP ID edit dialog*/
Open the EtherIP ID edit dialog
SmEtherIpIdDlg
UINT SmEtherIpIdDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param) { SM_ETHERIP_ID *t = (SM_ETHERIP_ID *)param; // Validate arguments if (hWnd == NULL) { return 0; } switch (msg) { case WM_INITDIALOG: SmEtherIpIdDlgInit(hWnd, t); break; case WM_COMMAND: switch (LOWORD(wParam)) { case E_ID: case L_HUBNAME: case E_USERNAME: SmEtherIpIdDlgUpdate(hWnd, t); break; } switch (wParam) { case IDOK: SmEtherIpIdDlgOnOk(hWnd, t); break; case IDCANCEL: Close(hWnd); break; } break; case WM_CLOSE: EndDialog(hWnd, 0); break; } return 0; }
/* EtherIP ID edit dialog procedure*/
EtherIP ID edit dialog procedure