Home | History | Annotate | Download | only in dbus
      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 
     24 namespace shill {
     25 
     26 ChromeosFirewalldProxy::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 
     33 ChromeosFirewalldProxy::~ChromeosFirewalldProxy() {}
     34 
     35 bool ChromeosFirewalldProxy::RequestVpnSetup(
     36     const std::vector<std::string>& user_names,
     37     const std::string& interface) {
     38   // VPN already setup.
     39   if (!user_names_.empty() || !interface_name_.empty()) {
     40     LOG(ERROR) << "Already setup?";
     41     return false;
     42   }
     43 
     44   bool success = false;
     45   brillo::ErrorPtr error;
     46   if (!proxy_->RequestVpnSetup(user_names, interface, &success, &error)) {
     47     LOG(ERROR) << "Failed to request VPN setup: " << error->GetCode()
     48                << " " << error->GetMessage();
     49   }
     50   return success;
     51 }
     52 
     53 bool ChromeosFirewalldProxy::RemoveVpnSetup() {
     54   // No VPN setup.
     55   if (user_names_.empty() && interface_name_.empty()) {
     56     return true;
     57   }
     58 
     59   brillo::ErrorPtr error;
     60   bool success = false;
     61   if (!proxy_->RemoveVpnSetup(user_names_, interface_name_, &success, &error)) {
     62     LOG(ERROR) << "Failed to remove VPN setup: " << error->GetCode()
     63                << " " << error->GetMessage();
     64   }
     65   user_names_.clear();
     66   interface_name_ = "";
     67   return success;
     68 }
     69 
     70 }  // namespace shill
     71