diff options
| author | Ken Chen <cken@google.com> | 2020-12-04 00:08:54 +0800 |
|---|---|---|
| committer | Ken Chen <cken@google.com> | 2020-12-09 07:55:03 +0800 |
| commit | d15bcfcd60943db076f997985ca39dcb6165b6f1 (patch) | |
| tree | 61e8b0b2c419399fa3c33b38ab7a57ef9a4e7c5e /server/NetworkController.cpp | |
| parent | 0ace8435a817bfcf89656983504f02eb97f5e540 (diff) | |
Move appliesToUser() from VirtualNetwork to Network
Make funtion generic for followed physical network use case.
Test: atest
Change-Id: I30f61815a2626068a99c4b4bd77bea8b2c16bd47
Diffstat (limited to 'server/NetworkController.cpp')
| -rw-r--r-- | server/NetworkController.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/server/NetworkController.cpp b/server/NetworkController.cpp index 20ef9ebb..4bb4ff1e 100644 --- a/server/NetworkController.cpp +++ b/server/NetworkController.cpp @@ -751,11 +751,10 @@ Network* NetworkController::getNetworkLocked(unsigned netId) const { } VirtualNetwork* NetworkController::getVirtualNetworkForUserLocked(uid_t uid) const { - for (const auto& entry : mNetworks) { - if (entry.second->getType() == Network::VIRTUAL) { - VirtualNetwork* virtualNetwork = static_cast<VirtualNetwork*>(entry.second); - if (virtualNetwork->appliesToUser(uid)) { - return virtualNetwork; + for (const auto& [_, network] : mNetworks) { + if (network->getType() == Network::VIRTUAL) { + if (network->appliesToUser(uid)) { + return static_cast<VirtualNetwork*>(network); } } } @@ -788,7 +787,7 @@ int NetworkController::checkUserNetworkAccessLocked(uid_t uid, unsigned netId) c } // If the UID wants to use a VPN, it can do so if and only if the VPN applies to the UID. if (network->getType() == Network::VIRTUAL) { - return static_cast<VirtualNetwork*>(network)->appliesToUser(uid) ? 0 : -EPERM; + return network->appliesToUser(uid) ? 0 : -EPERM; } // If a VPN applies to the UID, and the VPN is secure (i.e., not bypassable), then the UID can // only select a different network if it has the ability to protect its sockets. |
