summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilad Arnold <garnold@google.com>2015-08-05 15:26:02 -0700
committerGilad Arnold <garnold@google.com>2015-08-13 13:13:56 -0700
commit7db56bd4c91a516637995b9bf75241cb0c323bf9 (patch)
treed68435428a04e8f433367eef7e0c1e70b1df3048
parentb4f3e0edd0e8c502d137bf7aa3ebfabf0be46183 (diff)
downloadfirewalld-7db56bd4c91a516637995b9bf75241cb0c323bf9.tar.gz
Build firewalld in Android.
* Drop firewalld/ prefix from #include paths. * Rename the DBus interface definition to have a .dbus.xml suffix; needed for it to be picked up by the build infrastructure. * Add __BRILLO__ preprocessor symbol for conditionally: 1) Removing support for Permission Broker (currently not available and no concrete porting plan yet). 2) Disable dropping privileges in minijail invocations (yet to be figured out). 3) Adapting DBus bindings header paths (slightly different). 4) Adapting helper utility paths (iptables, iproute2). 5) Making punching of IPv6 firewall rules optional and autodetected. * Re-license everything to AOSP and add NOTICE and MODULE_LICENSE_APACHE2. * Added Android.mk for building all the targets we need, including init.firewalld.rc with proper SELinux attributes (when supported). Bug: 22827985 Change-Id: I05f74f80f95f689b4bbf60a2708e76ef5495b96e
-rw-r--r--Android.mk82
-rw-r--r--MODULE_LICENSE_APACHE20
-rw-r--r--NOTICE190
-rw-r--r--dbus_bindings/org.chromium.Firewalld.dbus.xml (renamed from dbus_bindings/org.chromium.Firewalld.xml)0
-rw-r--r--dbus_interface.h16
-rw-r--r--firewall_daemon.cc18
-rw-r--r--firewall_daemon.h20
-rw-r--r--firewall_service.cc30
-rw-r--r--firewall_service.h30
-rw-r--r--firewalld.conf18
-rw-r--r--firewalld.gyp2
-rw-r--r--iptables.cc58
-rw-r--r--iptables.h30
-rw-r--r--iptables_unittest.cc22
-rw-r--r--main.cc18
-rw-r--r--mock_iptables.cc18
-rw-r--r--mock_iptables.h18
-rw-r--r--run_all_tests.cc16
18 files changed, 519 insertions, 67 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..03b9e3a
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,82 @@
+#
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+# Definitions applying to all targets. Be sure to $(eval) this last.
+define firewalld_common
+ LOCAL_CPP_EXTENSION := .cc
+ LOCAL_RTTI_FLAG := -frtti
+ LOCAL_CLANG := true
+ LOCAL_SRC_FILES += \
+ dbus_bindings/dbus-service-config.json \
+ dbus_bindings/org.chromium.Firewalld.dbus.xml
+ LOCAL_SHARED_LIBRARIES += \
+ libchrome \
+ libchrome-dbus \
+ libchromeos \
+ libchromeos-dbus \
+ libchromeos-minijail \
+ libdbus \
+ libminijail
+ LOCAL_CFLAGS += -D__BRILLO__ -Wall -Werror -Wno-unused-parameter
+ LOCAL_CPPFLAGS += -Wno-sign-promo
+endef
+
+# === libfirewalld (static library) ===
+include $(CLEAR_VARS)
+LOCAL_MODULE := libfirewalld
+LOCAL_SRC_FILES := \
+ firewall_daemon.cc \
+ firewall_service.cc \
+ iptables.cc
+$(eval $(firewalld_common))
+include $(BUILD_STATIC_TEST_LIBRARY)
+
+# === firewalld ===
+include $(CLEAR_VARS)
+LOCAL_MODULE := firewalld
+LOCAL_REQUIRED_MODULES := init.firewalld.rc
+LOCAL_SRC_FILES := \
+ main.cc
+LOCAL_STATIC_LIBRARIES := libfirewalld
+LOCAL_C_INCLUDES += external/gtest/include
+$(eval $(firewalld_common))
+include $(BUILD_EXECUTABLE)
+
+# === init.firewalld.rc ===
+include $(CLEAR_VARS)
+LOCAL_MODULE := init.firewalld.rc
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_PATH := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_INITRCD)
+
+ifdef INITRC_TEMPLATE
+include $(BUILD_SYSTEM)/base_rules.mk
+
+$(LOCAL_BUILT_MODULE): $(INITRC_TEMPLATE)
+ $(call generate-initrc-file,firewalld,,net_admin net_raw)
+endif
+
+# === unittest ===
+include $(CLEAR_VARS)
+LOCAL_MODULE := firewalld_unittest
+LOCAL_SRC_FILES := \
+ iptables_unittest.cc \
+ mock_iptables.cc \
+ run_all_tests.cc
+LOCAL_STATIC_LIBRARIES := libfirewalld libgmock
+$(eval $(firewalld_common))
+include $(BUILD_NATIVE_TEST)
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..a849a94
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2014-2015, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/dbus_bindings/org.chromium.Firewalld.xml b/dbus_bindings/org.chromium.Firewalld.dbus.xml
index 97ea215..97ea215 100644
--- a/dbus_bindings/org.chromium.Firewalld.xml
+++ b/dbus_bindings/org.chromium.Firewalld.dbus.xml
diff --git a/dbus_interface.h b/dbus_interface.h
index 9ba2fb2..829d666 100644
--- a/dbus_interface.h
+++ b/dbus_interface.h
@@ -1,6 +1,16 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef FIREWALLD_DBUS_INTERFACE_H_
#define FIREWALLD_DBUS_INTERFACE_H_
diff --git a/firewall_daemon.cc b/firewall_daemon.cc
index d693403..691dcd2 100644
--- a/firewall_daemon.cc
+++ b/firewall_daemon.cc
@@ -1,8 +1,18 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
-#include "firewalld/firewall_daemon.h"
+#include "firewall_daemon.h"
#include <string>
diff --git a/firewall_daemon.h b/firewall_daemon.h
index 19debf4..5183420 100644
--- a/firewall_daemon.h
+++ b/firewall_daemon.h
@@ -1,6 +1,16 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef FIREWALLD_FIREWALL_DAEMON_H_
#define FIREWALLD_FIREWALL_DAEMON_H_
@@ -9,8 +19,8 @@
#include <chromeos/daemons/dbus_daemon.h>
#include <chromeos/dbus/async_event_sequencer.h>
-#include "firewalld/dbus_interface.h"
-#include "firewalld/firewall_service.h"
+#include "dbus_interface.h"
+#include "firewall_service.h"
using chromeos::dbus_utils::AsyncEventSequencer;
diff --git a/firewall_service.cc b/firewall_service.cc
index 6b2c4d4..648684a 100644
--- a/firewall_service.cc
+++ b/firewall_service.cc
@@ -1,11 +1,21 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "firewalld/firewall_service.h"
-
-#include "firewalld/dbus_interface.h"
-#include "firewalld/iptables.h"
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "firewall_service.h"
+
+#include "dbus_interface.h"
+#include "iptables.h"
namespace firewalld {
@@ -18,6 +28,7 @@ FirewallService::FirewallService(
void FirewallService::RegisterAsync(const CompletionAction& callback) {
RegisterWithDBusObject(&dbus_object_);
+#if !defined(__BRILLO__)
// Track permission_broker's lifetime so that we can close firewall holes
// if/when permission_broker exits.
permission_broker_.reset(
@@ -26,13 +37,16 @@ void FirewallService::RegisterAsync(const CompletionAction& callback) {
permission_broker_->SetPermissionBrokerRemovedCallback(
base::Bind(&FirewallService::OnPermissionBrokerRemoved,
weak_ptr_factory_.GetWeakPtr()));
+#endif // __BRILLO__
dbus_object_.RegisterAsync(callback);
}
+#if !defined(__BRILLO__)
void FirewallService::OnPermissionBrokerRemoved(const dbus::ObjectPath& path) {
LOG(INFO) << "permission_broker died, plugging all firewall holes";
iptables_.PlugAllHoles();
}
+#endif // __BRILLO__
} // namespace firewalld
diff --git a/firewall_service.h b/firewall_service.h
index ba91f6d..72551ac 100644
--- a/firewall_service.h
+++ b/firewall_service.h
@@ -1,6 +1,16 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef FIREWALLD_FIREWALL_SERVICE_H_
#define FIREWALLD_FIREWALL_SERVICE_H_
@@ -11,10 +21,14 @@
#include <base/memory/weak_ptr.h>
#include <chromeos/dbus/dbus_object.h>
-#include "permission_broker/dbus-proxies.h"
+#if defined(__BRILLO__)
+# include "dbus_bindings/adaptors.h"
+#else
+# include "permission_broker/dbus-proxies.h"
+# include "firewalld/dbus_adaptor/org.chromium.Firewalld.h"
+#endif // __BRILLO__
-#include "firewalld/dbus_adaptor/org.chromium.Firewalld.h"
-#include "firewalld/iptables.h"
+#include "iptables.h"
using CompletionAction =
chromeos::dbus_utils::AsyncEventSequencer::CompletionAction;
@@ -31,11 +45,15 @@ class FirewallService : public org::chromium::FirewalldAdaptor {
void RegisterAsync(const CompletionAction& callback);
private:
+#if !defined(__BRILLO__)
void OnPermissionBrokerRemoved(const dbus::ObjectPath& path);
+#endif // __BRILLO__
chromeos::dbus_utils::DBusObject dbus_object_;
+#if !defined(__BRILLO__)
std::unique_ptr<org::chromium::PermissionBroker::ObjectManagerProxy>
permission_broker_;
+#endif // __BRILLO__
IpTables iptables_;
base::WeakPtrFactory<FirewallService> weak_ptr_factory_{this};
diff --git a/firewalld.conf b/firewalld.conf
index eb2020d..bfa521a 100644
--- a/firewalld.conf
+++ b/firewalld.conf
@@ -1,6 +1,18 @@
-# Copyright 2015 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
+#
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
description "Firewall daemon"
author "chromium-os-dev@chromium.org"
diff --git a/firewalld.gyp b/firewalld.gyp
index ffb7773..8a1a985 100644
--- a/firewalld.gyp
+++ b/firewalld.gyp
@@ -38,7 +38,7 @@
'dbus_adaptors_out_dir': 'include/firewalld/dbus_adaptor',
},
'sources': [
- 'dbus_bindings/org.chromium.Firewalld.xml',
+ 'dbus_bindings/org.chromium.Firewalld.dbus.xml',
],
'includes': ['../common-mk/generate-dbus-adaptors.gypi'],
},
diff --git a/iptables.cc b/iptables.cc
index 2357fcb..23a12e1 100644
--- a/iptables.cc
+++ b/iptables.cc
@@ -1,8 +1,18 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "firewalld/iptables.h"
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "iptables.h"
#include <linux/capability.h>
@@ -17,12 +27,17 @@
#include <chromeos/process.h>
namespace {
+#if defined(__BRILLO__)
+const char kIpTablesPath[] = "/system/bin/iptables";
+const char kIp6TablesPath[] = "/system/bin/ip6tables";
+const char kIpPath[] = "/system/bin/ip";
+#else
const char kIpTablesPath[] = "/sbin/iptables";
const char kIp6TablesPath[] = "/sbin/ip6tables";
-
const char kIpPath[] = "/bin/ip";
-
const char kUnprivilegedUser[] = "nobody";
+#endif // __BRILLO__
+
const uint64_t kIpTablesCapMask =
CAP_TO_MASK(CAP_NET_ADMIN) | CAP_TO_MASK(CAP_NET_RAW);
@@ -57,6 +72,12 @@ bool IsValidInterfaceName(const std::string& iface) {
namespace firewalld {
+IpTables::IpTables() {
+#if defined(__BRILLO__)
+ ip6_enabled_ = false;
+#endif // __BRILLO__
+}
+
IpTables::~IpTables() {
// Plug all holes when destructed.
PlugAllHoles();
@@ -184,11 +205,22 @@ bool IpTables::AddAcceptRules(ProtocolEnum protocol,
LOG(ERROR) << "Could not add ACCEPT rule using '" << kIpTablesPath << "'";
return false;
}
- if (!AddAcceptRule(kIp6TablesPath, protocol, port, interface)) {
- LOG(ERROR) << "Could not add ACCEPT rule using '" << kIp6TablesPath << "'";
+
+ if (AddAcceptRule(kIp6TablesPath, protocol, port, interface)) {
+ // This worked, record this fact and insist that it works thereafter.
+ ip6_enabled_ = true;
+ } else if (ip6_enabled_) {
+ // It's supposed to work, fail.
+ LOG(ERROR) << "Could not add ACCEPT rule using '" << kIp6TablesPath
+ << "', aborting operation";
DeleteAcceptRule(kIpTablesPath, protocol, port, interface);
return false;
+ } else {
+ // It never worked, just ignore it.
+ LOG(WARNING) << "Could not add ACCEPT rule using '" << kIp6TablesPath
+ << "', ignoring";
}
+
return true;
}
@@ -197,8 +229,8 @@ bool IpTables::DeleteAcceptRules(ProtocolEnum protocol,
const std::string& interface) {
bool ip4_success = DeleteAcceptRule(kIpTablesPath, protocol, port,
interface);
- bool ip6_success = DeleteAcceptRule(kIp6TablesPath, protocol, port,
- interface);
+ bool ip6_success = !ip6_enabled_ || DeleteAcceptRule(kIp6TablesPath, protocol,
+ port, interface);
return ip4_success && ip6_success;
}
@@ -348,7 +380,11 @@ int IpTables::ExecvNonRoot(const std::vector<std::string>& argv,
uint64_t capmask) {
chromeos::Minijail* m = chromeos::Minijail::GetInstance();
minijail* jail = m->New();
+#if !defined(__BRILLO__)
+ // TODO(garnold) This needs to be re-enabled once we figure out which
+ // unprivileged user we want to use.
m->DropRoot(jail, kUnprivilegedUser, kUnprivilegedUser);
+#endif // __BRILLO__
m->UseCapabilities(jail, capmask);
std::vector<char*> args;
diff --git a/iptables.h b/iptables.h
index af3e4b6..3e69305 100644
--- a/iptables.h
+++ b/iptables.h
@@ -1,6 +1,16 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef FIREWALLD_IPTABLES_H_
#define FIREWALLD_IPTABLES_H_
@@ -15,7 +25,11 @@
#include <base/macros.h>
#include <chromeos/errors/error.h>
-#include "firewalld/dbus_adaptor/org.chromium.Firewalld.h"
+#if defined(__BRILLO__)
+# include "dbus_bindings/adaptors.h"
+#else
+# include "firewalld/dbus_adaptor/org.chromium.Firewalld.h"
+#endif // __BRILLO__
namespace firewalld {
@@ -25,7 +39,7 @@ class IpTables : public org::chromium::FirewalldInterface {
public:
typedef std::pair<uint16_t, std::string> Hole;
- IpTables() = default;
+ IpTables();
~IpTables();
// D-Bus methods.
@@ -91,6 +105,12 @@ class IpTables : public org::chromium::FirewalldInterface {
std::set<Hole> tcp_holes_;
std::set<Hole> udp_holes_;
+ // Tracks whether IPv6 filtering is enabled. If set to |true| (the default),
+ // then it is required to be working. If |false|, then adding of IPv6 rules is
+ // still attempted but not mandatory; however, if it is successful even once,
+ // then it'll be changed to |true| and enforced thereafter.
+ bool ip6_enabled_ = true;
+
DISALLOW_COPY_AND_ASSIGN(IpTables);
};
diff --git a/iptables_unittest.cc b/iptables_unittest.cc
index 8c95414..45dfe04 100644
--- a/iptables_unittest.cc
+++ b/iptables_unittest.cc
@@ -1,12 +1,22 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "firewalld/iptables.h"
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "iptables.h"
#include <gtest/gtest.h>
-#include "firewalld/mock_iptables.h"
+#include "mock_iptables.h"
namespace firewalld {
diff --git a/main.cc b/main.cc
index 33dcd5c..322e1ab 100644
--- a/main.cc
+++ b/main.cc
@@ -1,11 +1,21 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include <base/command_line.h>
#include <chromeos/syslog_logging.h>
-#include "firewalld/firewall_daemon.h"
+#include "firewall_daemon.h"
using firewalld::FirewallDaemon;
diff --git a/mock_iptables.cc b/mock_iptables.cc
index d9cd7f6..767637f 100644
--- a/mock_iptables.cc
+++ b/mock_iptables.cc
@@ -1,8 +1,18 @@
-// Copyright 2015 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
-#include "firewalld/mock_iptables.h"
+#include "mock_iptables.h"
namespace firewalld {
diff --git a/mock_iptables.h b/mock_iptables.h
index 1ce291a..4f87892 100644
--- a/mock_iptables.h
+++ b/mock_iptables.h
@@ -1,6 +1,16 @@
-// Copyright 2015 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef FIREWALLD_MOCK_IPTABLES_H_
#define FIREWALLD_MOCK_IPTABLES_H_
@@ -10,7 +20,7 @@
#include <base/macros.h>
#include <gmock/gmock.h>
-#include "firewalld/iptables.h"
+#include "iptables.h"
namespace firewalld {
diff --git a/run_all_tests.cc b/run_all_tests.cc
index 914165e..b3137cf 100644
--- a/run_all_tests.cc
+++ b/run_all_tests.cc
@@ -1,6 +1,16 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include <gtest/gtest.h>