Skip to content

Commit

Permalink
fix: trying to fix dc issue
Browse files Browse the repository at this point in the history
  • Loading branch information
stowmyy committed Sep 4, 2024
1 parent 075187c commit 023142b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
19 changes: 15 additions & 4 deletions dropship/src/FirewallManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@

bool FirewallManager::AddFirewallRule(Endpoint* e, bool enabled)
{
return this->_windowsFirewall->add_rule(e, NET_FW_RULE_DIR_OUT, enabled, NET_FW_PROFILE2_ALL)
&& this->_windowsFirewall->add_rule(e, NET_FW_RULE_DIR_IN, enabled, NET_FW_PROFILE2_ALL);
if (this->_windowsFirewall->add_rule(e, NET_FW_RULE_DIR_OUT, enabled, NET_FW_PROFILE2_ALL)) {
if (this->_windowsFirewall->add_rule(e, NET_FW_RULE_DIR_IN, enabled, NET_FW_PROFILE2_ALL)) {
return true;
}
else {
printf("first failed");
this->_windowsFirewall->add_rule(e, NET_FW_RULE_DIR_OUT, !enabled, NET_FW_PROFILE2_ALL);
}
}

return false;
}


Expand Down Expand Up @@ -51,8 +60,10 @@ void FirewallManager::flushRules(std::vector<Endpoint>* endpoints)
printf("Adding rules..\n");
for (auto &e : *endpoints)
{
this->_windowsFirewall->add_rule(&e, NET_FW_RULE_DIR_OUT, false);
this->_windowsFirewall->add_rule(&e, NET_FW_RULE_DIR_IN, false);
//this->_windowsFirewall->add_rule(&e, NET_FW_RULE_DIR_OUT, false);
//this->_windowsFirewall->add_rule(&e, NET_FW_RULE_DIR_IN, false);

this->AddFirewallRule(&e, false);
}
printf("Added %d rules.\n", endpoints->size());

Expand Down
7 changes: 5 additions & 2 deletions dropship/src/_WindowsFirewallUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ class _WindowsFirewallUtil : public failable
}

// returns true if succeeded
bool add_rule(Endpoint* e, NET_FW_RULE_DIRECTION_ dir, bool enabled = false, NET_FW_PROFILE_TYPE2_ profile = NET_FW_PROFILE2_ALL)
bool add_rule(Endpoint* e, NET_FW_RULE_DIRECTION_ dir, bool enabled, NET_FW_PROFILE_TYPE2_ profile = NET_FW_PROFILE2_ALL)
{
//BSTR bstrRuleName = SysAllocString(std::wstring(e.title.begin(), e.title.end()).c_str());
BSTR bstrRuleName = _com_util::ConvertStringToBSTR(e->title.c_str());
Expand Down Expand Up @@ -772,6 +772,9 @@ class _WindowsFirewallUtil : public failable
bool ruleEnabled;
ruleEnabled = (__enabled != VARIANT_FALSE);

NET_FW_RULE_DIRECTION rule_direction;
pFwRule->get_Direction(&rule_direction);

const std::string s_ruleName (_bstr_t(ruleName, true));

for (auto& e : *endpoints)
Expand All @@ -786,7 +789,7 @@ class _WindowsFirewallUtil : public failable
if (endpointDominant)
{

printf(std::format("({0}) firewall: {1}, ui: {2} . Setting firewall rule to match UI state\n", s_ruleName, ruleEnabled ? "block" : "allow", e.active ? "selected" : "not selected").c_str());
printf(std::format("{3} ({0}) firewall: {1}, ui: {2} . Setting firewall rule to match UI state\n", s_ruleName, ruleEnabled ? "block" : "allow", e.active ? "selected" : "not selected", rule_direction == NET_FW_RULE_DIR_IN ? "IN" : "OUT").c_str());
if (FAILED(pFwRule->put_Enabled(e.active_desired_state ? VARIANT_FALSE : VARIANT_TRUE)))
{
printf("failed to write rule state\n");
Expand Down

0 comments on commit 023142b

Please sign in to comment.