chromeos_firewalld_proxy.cc revision a9a0e8356b33ccac1f06ffb1cb8a601dca4d62f2
1// 2// Copyright (C) 2015 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17#include "shill/dbus/chromeos_firewalld_proxy.h" 18 19#include <string> 20#include <vector> 21 22#include "shill/logging.h" 23 24namespace shill { 25 26ChromeosFirewalldProxy::ChromeosFirewalldProxy( 27 const scoped_refptr<dbus::Bus>& bus) 28 : proxy_(new org::chromium::FirewalldProxy(bus)) { 29 // TODO(zqiu): register handler for service name owner changes, to 30 // automatically re-request VPN setup when firewalld is restarted. 31} 32 33ChromeosFirewalldProxy::~ChromeosFirewalldProxy() { 34 proxy_->ReleaseObjectProxy(base::Bind(&base::DoNothing)); 35} 36 37bool ChromeosFirewalldProxy::RequestVpnSetup( 38 const std::vector<std::string>& user_names, 39 const std::string& interface) { 40 // VPN already setup. 41 if (!user_names_.empty() || !interface_name_.empty()) { 42 LOG(ERROR) << "Already setup?"; 43 return false; 44 } 45 46 bool success = false; 47 chromeos::ErrorPtr error; 48 if (!proxy_->RequestVpnSetup(user_names, interface, &success, &error)) { 49 LOG(ERROR) << "Failed to request VPN setup: " << error->GetCode() 50 << " " << error->GetMessage(); 51 } 52 return success; 53} 54 55bool ChromeosFirewalldProxy::RemoveVpnSetup() { 56 // No VPN setup. 57 if (user_names_.empty() && interface_name_.empty()) { 58 return true; 59 } 60 61 chromeos::ErrorPtr error; 62 bool success = false; 63 if (!proxy_->RemoveVpnSetup(user_names_, interface_name_, &success, &error)) { 64 LOG(ERROR) << "Failed to remove VPN setup: " << error->GetCode() 65 << " " << error->GetMessage(); 66 } 67 user_names_.clear(); 68 interface_name_ = ""; 69 return success; 70} 71 72} // namespace shill 73