blob: 4cf3260fc2f2e6e073677ba70f6274ad299a4b1f [file] [log] [blame]
Gilad Arnold7db56bd2015-08-05 15:26:02 -07001// Copyright 2014 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
Jorge Lucangeli Obesac44ba52014-12-01 16:26:05 -080014
Gilad Arnold7db56bd2015-08-05 15:26:02 -070015#include "firewall_service.h"
Jorge Lucangeli Obesac44ba52014-12-01 16:26:05 -080016
Gilad Arnold7db56bd2015-08-05 15:26:02 -070017#include "dbus_interface.h"
18#include "iptables.h"
Jorge Lucangeli Obesac44ba52014-12-01 16:26:05 -080019
20namespace firewalld {
21
Alex Vakulenkofa9de932015-07-13 10:43:14 -070022FirewallService::FirewallService(
Alex Vakulenkoe478a112015-10-13 09:58:47 -070023 brillo::dbus_utils::ExportedObjectManager* object_manager)
Jorge Lucangeli Obes86208682014-12-05 15:28:04 -080024 : org::chromium::FirewalldAdaptor(&iptables_),
Alex Vakulenkofa9de932015-07-13 10:43:14 -070025 dbus_object_{object_manager, object_manager->GetBus(),
26 org::chromium::FirewalldAdaptor::GetObjectPath()} {}
Jorge Lucangeli Obesac44ba52014-12-01 16:26:05 -080027
28void FirewallService::RegisterAsync(const CompletionAction& callback) {
29 RegisterWithDBusObject(&dbus_object_);
Jorge Lucangeli Obes650d2292015-02-25 14:14:29 -080030
Daniel Eratdf78e332015-08-19 16:26:00 -060031#if !defined(__ANDROID__)
Jorge Lucangeli Obes650d2292015-02-25 14:14:29 -080032 // Track permission_broker's lifetime so that we can close firewall holes
33 // if/when permission_broker exits.
34 permission_broker_.reset(
35 new org::chromium::PermissionBroker::ObjectManagerProxy(
36 dbus_object_.GetBus()));
37 permission_broker_->SetPermissionBrokerRemovedCallback(
38 base::Bind(&FirewallService::OnPermissionBrokerRemoved,
39 weak_ptr_factory_.GetWeakPtr()));
Daniel Eratdf78e332015-08-19 16:26:00 -060040#endif // __ANDROID__
Jorge Lucangeli Obes650d2292015-02-25 14:14:29 -080041
Jorge Lucangeli Obesac44ba52014-12-01 16:26:05 -080042 dbus_object_.RegisterAsync(callback);
43}
44
Daniel Eratdf78e332015-08-19 16:26:00 -060045#if !defined(__ANDROID__)
Jorge Lucangeli Obes650d2292015-02-25 14:14:29 -080046void FirewallService::OnPermissionBrokerRemoved(const dbus::ObjectPath& path) {
47 LOG(INFO) << "permission_broker died, plugging all firewall holes";
48 iptables_.PlugAllHoles();
49}
Daniel Eratdf78e332015-08-19 16:26:00 -060050#endif // __ANDROID__
Jorge Lucangeli Obes650d2292015-02-25 14:14:29 -080051
Jorge Lucangeli Obesac44ba52014-12-01 16:26:05 -080052} // namespace firewalld