// Search adapter with the name struct WP_ADAPTER *Win32EthSearch(char *name) { UINT i; UINT id; char simple_name[MAX_SIZE]; WP_ADAPTER *ret = NULL; id = Win32EthGetNameAndIdFromCombinedName(simple_name, sizeof(simple_name), name); if (id != 0) { UINT num_match = 0; // Search with ID when ID is specified for (i = 0;i < LIST_NUM(eth_list);i++) { WP_ADAPTER *a = LIST_DATA(eth_list, i); if (a->Id != 0 && a->Id == id) { ret = a; num_match++; } } if (num_match >= 2) { // If the ID matches to 2 or more devices, search with the name for (i = 0;i < LIST_NUM(eth_list);i++) { WP_ADAPTER *a = LIST_DATA(eth_list, i); if (a->Id != 0 && a->Id == id) { if (StrCmpi(a->Title, name) == 0) { ret = a; break; } } } } } else { // Search with name when ID is not specified for (i = 0;i < LIST_NUM(eth_list);i++) { WP_ADAPTER *a = LIST_DATA(eth_list, i); if (StrCmpi(a->Title, name) == 0) { ret = a; break; } } } return ret; }
// Convert the data type string to an integer value UINT CfgStrToType(char *str) { if (!StrCmpi(str, TAG_INT)) return ITEM_TYPE_INT; if (!StrCmpi(str, TAG_INT64)) return ITEM_TYPE_INT64; if (!StrCmpi(str, TAG_BYTE)) return ITEM_TYPE_BYTE; if (!StrCmpi(str, TAG_STRING)) return ITEM_TYPE_STRING; if (!StrCmpi(str, TAG_BOOL)) return ITEM_TYPE_BOOL; return 0; }
// Remove duplications from the token list TOKEN_LIST *UniqueToken(TOKEN_LIST *t) { UINT i, num, j, n; TOKEN_LIST *ret; // Validate arguments if (t == NULL) { return NULL; } num = 0; for (i = 0;i < t->NumTokens;i++) { bool exists = false; for (j = 0;j < i;j++) { if (StrCmpi(t->Token[j], t->Token[i]) == 0) { exists = true; break; } } if (exists == false) { num++; } } ret = ZeroMalloc(sizeof(TOKEN_LIST)); ret->Token = ZeroMalloc(sizeof(char *) * num); ret->NumTokens = num; n = 0; for (i = 0;i < t->NumTokens;i++) { bool exists = false; for (j = 0;j < i;j++) { if (StrCmpi(t->Token[j], t->Token[i]) == 0) { exists = true; break; } } if (exists == false) { ret->Token[n++] = CopyStr(t->Token[i]); } } return ret; }
// メモリデバッグメニュー void MemoryDebugMenu() { char tmp[MAX_SIZE]; TOKEN_LIST *t; char *cmd; Print("Mayaqua Kernel Memory Debug Tools\n" "Copyright (C) SoftEther Corporation. All Rights Reserved.\n\n"); g_memcheck = false; while (true) { Print("debug>"); GetLine(tmp, sizeof(tmp)); t = ParseToken(tmp, " \t"); if (t->NumTokens == 0) { FreeToken(t); DebugPrintAllObjects(); continue; } cmd = t->Token[0]; if (!StrCmpi(cmd, "?")) { DebugPrintCommandList(); } else if (!StrCmpi(cmd, "a")) { DebugPrintAllObjects(); } else if (!StrCmpi(cmd, "i")) { if (t->NumTokens == 1) { Print("Usage: i <obj_id>\n\n"); } else { DebugPrintObjectInfo(ToInt(t->Token[1])); } } else if (!StrCmpi(cmd, "q")) { break; } else if (ToInt(cmd) != 0) { DebugPrintObjectInfo(ToInt(t->Token[0])); } else { Print("Command Not Found,\n\n"); } FreeToken(t); } FreeToken(t); g_memcheck = true; }
// str が key で終了するかどうかチェック bool EndWith(char *str, char *key) { UINT str_len; UINT key_len; // 引数チェック if (str == NULL || key == NULL) { return false; } // 比較 str_len = StrLen(str); key_len = StrLen(key); if (str_len < key_len) { return false; } if (StrCmpi(str + (str_len - key_len), key) == 0) { return true; } else { return false; } }
// Search an entry IPTABLES_ENTRY *SearchIpTables(IPTABLES_STATE *s, char *chain, IP *src_ip, IP *dest_ip, UINT mark) { char ip_str1[64]; char ip_str2[64]; char mark_str1[64]; char mark_str2[64]; UINT i; if (s == NULL || chain == NULL || src_ip == NULL || dest_ip == NULL || mark == 0) { return NULL; } IPToStr(ip_str1, sizeof(ip_str1), src_ip); IPToStr(ip_str2, sizeof(ip_str2), dest_ip); ToStr(mark_str1, mark); Format(mark_str2, sizeof(mark_str2), "%x", mark); for (i = 0;i < LIST_NUM(s->EntryList);i++) { IPTABLES_ENTRY *e = LIST_DATA(s->EntryList, i); if (StrCmpi(e->Chain, chain) == 0) { if (InStr(e->ConditionAndArgs, ip_str1) && InStr(e->ConditionAndArgs, ip_str2) && (InStr(e->ConditionAndArgs, mark_str1) || InStr(e->ConditionAndArgs, mark_str2))) { return e; } } } return NULL; }
// Check whether the str ends with the key bool EndWith(char *str, char *key) { UINT str_len; UINT key_len; // Validate arguments if (str == NULL || key == NULL) { return false; } // Comparison str_len = StrLen(str); key_len = StrLen(key); if (str_len < key_len) { return false; } if (StrCmpi(str + (str_len - key_len), key) == 0) { return true; } else { return false; } }
// Load the string from the table char *GetTableStr(char *name) { TABLE *t; // Validate arguments if (name == NULL) { return ""; } #ifdef OS_WIN32 if (StrCmpi(name, "DEFAULT_FONT") == 0) { if (_II("LANG") == 2) { UINT os_type = GetOsType(); if (OS_IS_WINDOWS_9X(os_type) || GET_KETA(os_type, 100) <= 4) { // Use the SimSun font in Windows 9x, Windows NT 4.0, Windows 2000, Windows XP, and Windows Server 2003 return "SimSun"; } } } #endif // OS_WIN32 // Search t = FindTable(name); if (t == NULL) { //Debug("%s: ANSI STRING NOT FOUND\n", name); return ""; } return t->str; }
// Main function void MainFunction(char *cmd) { char tmp[MAX_SIZE]; bool first = true; bool exit_now = false; while (true) { if (first && StrLen(cmd) != 0 && g_memcheck == false) { first = false; StrCpy(tmp, sizeof(tmp), cmd); exit_now = true; Print("%s\n", cmd); } else { _exit(0); } Trim(tmp); if (StrLen(tmp) != 0) { UINT i, num; bool b = false; TOKEN_LIST *token = ParseCmdLine(tmp); char *cmd = token->Token[0]; num = sizeof(test_list) / sizeof(TEST_LIST); for (i = 0;i < num;i++) { if (!StrCmpi(test_list[i].command_str, cmd)) { char **arg = Malloc(sizeof(char *) * (token->NumTokens - 1)); UINT j; for (j = 0;j < token->NumTokens - 1;j++) { arg[j] = CopyStr(token->Token[j + 1]); } test_list[i].proc(token->NumTokens - 1, arg); for (j = 0;j < token->NumTokens - 1;j++) { Free(arg[j]); } Free(arg); b = true; _exit(1); break; } } FreeToken(token); if (exit_now) { break; } } } }
// Get the candidates list of of the real command name whose abbreviation matches to the command specified by the user TOKEN_LIST *GetRealnameCandidate(char *input_name, TOKEN_LIST *real_name_list) { TOKEN_LIST *ret; LIST *o; UINT i; bool ok = false; // Validate arguments if (input_name == NULL || real_name_list == NULL) { return NullToken(); } o = NewListFast(NULL); for (i = 0;i < real_name_list->NumTokens;i++) { char *name = real_name_list->Token[i]; // Search for an exact match with the highest priority first if (StrCmpi(name, input_name) == 0) { Insert(o, name); ok = true; break; } } if (ok == false) { // If there is no command to exact match, check whether it matches to a short form command for (i = 0;i < real_name_list->NumTokens;i++) { char *name = real_name_list->Token[i]; if (IsOmissionName(input_name, name) || IsNameInRealName(input_name, name)) { // A abbreviation is found Insert(o, name); ok = true; } } } if (ok) { // One or more candidate is found ret = ListToTokenList(o); } else { ret = NullToken(); } ReleaseList(o); return ret; }
// Delete a local-bridge bool DeleteLocalBridge(CEDAR *c, char *hubname, char *devicename) { bool ret = false; // Validate arguments if (c == NULL || hubname == NULL || devicename == NULL) { return false; } LockList(c->HubList); { LockList(c->LocalBridgeList); { UINT i; for (i = 0;i < LIST_NUM(c->LocalBridgeList);i++) { LOCALBRIDGE *br = LIST_DATA(c->LocalBridgeList, i); if (StrCmpi(br->HubName, hubname) == 0) { if (StrCmpi(br->DeviceName, devicename) == 0) { if (br->Bridge != NULL) { BrFreeBridge(br->Bridge); br->Bridge = NULL; } Delete(c->LocalBridgeList, br); Free(br); ret = true; break; } } } } UnlockList(c->LocalBridgeList); } UnlockList(c->HubList); return ret; }
// Get the proxy server settings from the registry string of IE bool GetProxyServerNameAndPortFromIeProxyRegStr(char *name, UINT name_size, UINT *port, char *str, char *server_type) { #ifdef OS_WIN32 TOKEN_LIST *t; UINT i; bool ret = false; // Validate arguments if (name == NULL || port == NULL || str == NULL || server_type == NULL) { return false; } t = ParseToken(str, ";"); for (i = 0;i < t->NumTokens;i++) { char *s = t->Token[i]; UINT i; Trim(s); i = SearchStrEx(s, "=", 0, false); if (i != INFINITE) { char tmp[MAX_PATH]; StrCpy(name, name_size, s); name[i] = 0; if (StrCmpi(name, server_type) == 0) { char *host; StrCpy(tmp, sizeof(tmp), s + i + 1); if (ParseHostPort(tmp, &host, port, 0)) { StrCpy(name, name_size, host); Free(host); if (*port != 0) { ret = true; } break; } } } } FreeToken(t); return ret; #else // OS_WIN32 return true; #endif // OS_WIN32 }
// Set current configuration to VPN Azure client void AcApplyCurrentConfig(AZURE_CLIENT *ac, DDNS_CLIENT_STATUS *ddns_status) { bool disconnect_now = false; SOCK *disconnect_sock = NULL; // Validate arguments if (ac == NULL) { return; } // Get current DDNS configuration Lock(ac->Lock); { if (ddns_status != NULL) { if (StrCmpi(ac->DDnsStatus.CurrentHostName, ddns_status->CurrentHostName) != 0) { // If host name is changed, disconnect current data connection disconnect_now = true; } if (Cmp(&ac->DDnsStatus.InternetSetting, &ddns_status->InternetSetting, sizeof(INTERNET_SETTING)) != 0) { // If proxy setting is changed, disconnect current data connection disconnect_now = true; } Copy(&ac->DDnsStatus, ddns_status, sizeof(DDNS_CLIENT_STATUS)); } if (ac->IsEnabled == false) { // If VPN Azure client is disabled, disconnect current data connection disconnect_now = true; } if (disconnect_now) { if (ac->CurrentSock != NULL) { disconnect_sock = ac->CurrentSock; AddRef(disconnect_sock->ref); } } } Unlock(ac->Lock); if (disconnect_sock != NULL) { Disconnect(disconnect_sock); ReleaseSock(disconnect_sock); } Set(ac->Event); }
// Comparison function of the adapter list int SuCmpAdaterList(void *p1, void *p2) { int r; SU_ADAPTER_LIST *a1, *a2; if (p1 == NULL || p2 == NULL) { return 0; } a1 = *(SU_ADAPTER_LIST **)p1; a2 = *(SU_ADAPTER_LIST **)p2; if (a1 == NULL || a2 == NULL) { return 0; } r = StrCmpi(a1->SortKey, a2->SortKey); if (r != 0) { return 0; } return StrCmpi(a1->Guid, a2->Guid); }
// Search a secure object by the name SEC_OBJ *FindSecObject(SECURE *sec, char *name, UINT type) { LIST *o; UINT i; SEC_OBJ *ret = NULL; // Validate arguments if (sec == NULL) { return NULL; } if (name == NULL) { sec->Error = SEC_ERROR_BAD_PARAMETER; return NULL; } if (sec->SessionCreated == false) { sec->Error = SEC_ERROR_NO_SESSION; return 0; } // Enumeration o = EnumSecObject(sec); if (o == NULL) { return NULL; } for (i = 0;i < LIST_NUM(o);i++) { SEC_OBJ *obj = LIST_DATA(o, i); if (obj->Type == type || type == INFINITE) { if (StrCmpi(obj->Name, name) == 0) { ret = CloneSecObject(obj); break; } } } FreeEnumSecObject(o); if (ret == NULL) { sec->Error = SEC_ERROR_OBJ_NOT_FOUND; } return ret; }
// Initialize net service list void InitNetSvcList(CEDAR *cedar) { char filename[MAX_PATH] = "/etc/services"; BUF *b; // Validate arguments if (cedar == NULL) { return; } #ifdef OS_WIN32 Format(filename, sizeof(filename), "%s\\drivers\\etc\\services", MsGetSystem32Dir()); #endif cedar->NetSvcList = NewList(CompareNetSvc); b = ReadDump(filename); if (b == NULL) { return; } while (true) { char *s = CfgReadNextLine(b); if (s == NULL) { break; } Trim(s); if (s[0] != '#') { TOKEN_LIST *t = ParseToken(s, " \t/"); if (t->NumTokens >= 3) { NETSVC *n = ZeroMalloc(sizeof(NETSVC)); n->Name = CopyStr(t->Token[0]); n->Udp = (StrCmpi(t->Token[2], "udp") == 0 ? true : false); n->Port = ToInt(t->Token[1]); Add(cedar->NetSvcList, n); } FreeToken(t); } Free(s); } FreeBuf(b); }
// Comparison function of the item names int CmpItemName(void *p1, void *p2) { ITEM *f1, *f2; if (p1 == NULL || p2 == NULL) { return 0; } f1 = *(ITEM **)p1; f2 = *(ITEM **)p2; if (f1 == NULL || f2 == NULL) { return 0; } return StrCmpi(f1->Name, f2->Name); }
// Comparison function of the folder names int CmpFolderName(void *p1, void *p2) { FOLDER *f1, *f2; if (p1 == NULL || p2 == NULL) { return 0; } f1 = *(FOLDER **)p1; f2 = *(FOLDER **)p2; if (f1 == NULL || f2 == NULL) { return 0; } return StrCmpi(f1->Name, f2->Name); }
static SysVar *FindSysVar(char const *name) { int top=NUMSYSVARS-1, bottom=0; int mid=(top + bottom) / 2; int r; while (top >= bottom) { r = StrCmpi(name, SysVarArr[mid].name); if (!r) return &SysVarArr[mid]; else if (r>0) bottom = mid+1; else top = mid-1; mid = (top+bottom) / 2; } return NULL; }
// A function that compares the table name int CmpTableName(void *p1, void *p2) { TABLE *t1, *t2; if (p1 == NULL || p2 == NULL) { return 0; } t1 = *(TABLE **)p1; t2 = *(TABLE **)p2; if (t1 == NULL || t2 == NULL) { return 0; } return StrCmpi(t1->name, t2->name); }
// Comparison of the VLAN list entries int UnixCompareVLan(void *p1, void *p2) { UNIX_VLAN_LIST *v1, *v2; if (p1 == NULL || p2 == NULL) { return 0; } v1 = *(UNIX_VLAN_LIST **)p1; v2 = *(UNIX_VLAN_LIST **)p2; if (v1 == NULL || v2 == NULL) { return 0; } return StrCmpi(v1->Name, v2->Name); }
// PACK のソート関数 int ComparePackName(void *p1, void *p2) { ELEMENT *o1, *o2; if (p1 == NULL || p2 == NULL) { return 0; } o1 = *(ELEMENT **)p1; o2 = *(ELEMENT **)p2; if (o1 == NULL || o2 == NULL) { return 0; } return StrCmpi(o1->name, o2->name); }
// L3SW comparison function int CmpL3Sw(void *p1, void *p2) { L3SW *s1, *s2; if (p1 == NULL || p2 == NULL) { return 0; } s1 = *(L3SW **)p1; s2 = *(L3SW **)p2; if (s1 == NULL || s2 == NULL) { return 0; } return StrCmpi(s1->Name, s2->Name); }
// Interface comparison function int CmpL3If(void *p1, void *p2) { L3IF *f1, *f2; if (p1 == NULL || p2 == NULL) { return 0; } f1 = *(L3IF **)p1; f2 = *(L3IF **)p2; if (f1 == NULL || f2 == NULL) { return 0; } return StrCmpi(f1->HubName, f2->HubName); }
// Compare Ethernet device list int CmpRpcEnumEthVLan(void *p1, void *p2) { RPC_ENUM_ETH_VLAN_ITEM *v1, *v2; if (p1 == NULL || p2 == NULL) { return 0; } v1 = *((RPC_ENUM_ETH_VLAN_ITEM **)p1); v2 = *((RPC_ENUM_ETH_VLAN_ITEM **)p2); if (v1 == NULL || v2 == NULL) { return 0; } return StrCmpi(v1->DeviceName, v2->DeviceName); }
// Comparison function of the device int ElCompareDevice(void *p1, void *p2) { EL_DEVICE *d1, *d2; // Validate arguments if (p1 == NULL || p2 == NULL) { return 0; } d1 = *(EL_DEVICE **)p1; d2 = *(EL_DEVICE **)p2; if (d1 == NULL || d2 == NULL) { return 0; } return StrCmpi(d1->DeviceName, d2->DeviceName); }
// Compare user names (for sort) int CompareUserName(void *p1, void *p2) { USER *u1, *u2; // Validate arguments if (p1 == NULL || p2 == NULL) { return 0; } u1 = *(USER **)p1; u2 = *(USER **)p2; if (u1 == NULL || u2 == NULL) { return 0; } return StrCmpi(u1->Name, u2->Name); }
// Get whether hidden password is changed in UI bool IsHiddenPasswordChanged(char *str) { // Validate arguments if (str == NULL) { return true; } if (StrCmpi(str, HIDDEN_PASSWORD) == 0) { return true; } else { return false; } }
// Get registry key of the network class data by GUID bool GetClassRegKeyWin32(char *key, UINT key_size, char *short_key, UINT short_key_size, char *guid) { TOKEN_LIST *t; bool ret = false; UINT i; // Validate arguments if (key == NULL || short_key == NULL || guid == NULL) { return false; } t = MsRegEnumKey(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"); if (t == NULL) { return false; } for (i = 0;i < t->NumTokens;i++) { char keyname[MAX_SIZE]; char *value; Format(keyname, sizeof(keyname), "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s", t->Token[i]); value = MsRegReadStr(REG_LOCAL_MACHINE, keyname, "NetCfgInstanceId"); if (StrCmpi(value, guid) == 0) { ret = true; StrCpy(key, key_size, keyname); Format(short_key, short_key_size, "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s", t->Token[i]); } Free(value); } FreeToken(t); return ret; }
// Compare the name of WP_ADAPTER int CompareWpAdapter(void *p1, void *p2) { int i; WP_ADAPTER *a1, *a2; if (p1 == NULL || p2 == NULL) { return 0; } a1 = *(WP_ADAPTER **)p1; a2 = *(WP_ADAPTER **)p2; if (a1 == NULL || a2 == NULL) { return 0; } i = StrCmpi(a1->Title, a2->Title); return i; }