Quellcode durchsuchen

!2 fix add firewall not right

chenliangyu vor 4 Monaten
Ursprung
Commit
911b632d49
2 geänderte Dateien mit 35 neuen und 6 gelöschten Zeilen
  1. 26 6
      Framework/spbase/sp_firewallControl.cpp
  2. 9 0
      Module/mod_guiconsole/mod_guiconsole.cpp

+ 26 - 6
Framework/spbase/sp_firewallControl.cpp

@@ -166,7 +166,15 @@ bool FirewallController::AddFirewallRule(
     }
 
     rule->Release();
-    return SUCCEEDED(hr);
+    if (hr == S_OK) {
+        return true;  // 明确表示成功
+    } else if (hr == E_ACCESSDENIED) {
+        // 处理权限错误
+        return false;
+    }
+    else {
+        return false;
+    }
 }
 
 bool FirewallController::DeleteFirewallRule(const std::wstring& ruleName) {
@@ -179,7 +187,15 @@ bool FirewallController::DeleteFirewallRule(const std::wstring& ruleName) {
     hr = rules->Remove(_bstr_t(ruleName.c_str()));
     rules->Release();
 
-    return SUCCEEDED(hr);
+    if (hr == S_OK) {
+        return true;  // 明确表示成功
+    } else if (hr == E_ACCESSDENIED) {
+        // 处理权限错误
+        return false;
+    }
+    else{
+        return false;
+    }
 }
 
 bool FirewallController::CleanupRulesExceptWhitelist(
@@ -284,18 +300,22 @@ bool sp_AddFirewallRuleByPath(const char *pszPath)
     std::string header = firstLevelDir + "_" + lastDir;
 	std::map<std::string, std::string> firewallRule;
 	firewallRule[header + "_guardian"] = inputPath + "\\bin\\guardian.exe";
-	firewallRule[header + "_sphost"] = inputPath + "\\bin\\\\sphost.exe";
-	firewallRule[header + "_spshell"] = inputPath + "\\bin\\\\spshell.exe";
-	firewallRule[header + "_cefclient"] = inputPath + "\\bin\\\\Chromium\\cefclient.exe";
+	firewallRule[header + "_sphost"] = inputPath + "\\bin\\sphost.exe";
+	firewallRule[header + "_spshell"] = inputPath + "\\bin\\spshell.exe";
+	firewallRule[header + "_cefclient"] = inputPath + "\\bin\\Chromium\\cefclient.exe";
 
+    FirewallController::Initialize();
 	for(auto &it : firewallRule)
 	{
-		bool ret = sp_AddFirewallRule(it.first.c_str(), it.second.c_str());
+        std::wstring ruleNameW = charToWstring(it.first.c_str());
+        std::wstring appPathW = charToWstring(it.second.c_str());
+        bool ret = FirewallController::AddFirewallRule(ruleNameW, appPathW, FirewallRuleDirection::Inbound, FirewallRuleAction::Allow);
 		DbgWithLink(ret ? LOG_LEVEL_DEBUG : LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)
 			("Add firewall rule %s. firstLevelDir: %s, ruleName: %s, path: %s", ret ? "success" : "failed",
 			 firstLevelDir.c_str(), it.first.c_str(), it.second.c_str());
 		returnRet = returnRet && ret;
 	}
+    FirewallController::Shutdown();
 	return returnRet ? Error_Succeed : Error_Bug;
 }
 

+ 9 - 0
Module/mod_guiconsole/mod_guiconsole.cpp

@@ -1075,6 +1075,15 @@ void CGUIConsoleSession::Handle_ReservedCall(SpReqAnsContext<GUIConsoleService_R
 		}
 		ctx->Answer(ErrorCodeEnum::Error_Succeed);
 	}
+	else if(ctx->Req.reqType == "test_firewall")
+	{
+		CSimpleStringA rootVerPath;
+		ErrorCodeEnum rc = m_pEntity->GetFunction()->GetPath("RootVer", rootVerPath);//获取version根路径
+		CSimpleStringA strNewVerPath = CSimpleStringA::Format("%s" "\\" "%s", rootVerPath.GetData(), "7.5.1.1");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SetNewVersionPathToFirewall path = %s", strNewVerPath.GetData());
+		m_pEntity->GetFunction()->SetNewPathToFirewall(strNewVerPath);
+		ctx->Answer(ErrorCodeEnum::Error_Succeed);
+	}
 
 	
 }