This removes the custom tcp wrappers by emptying the /etc/hosts.*
configuration files.
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
sysprep/Makefile.am | 1 +
sysprep/sysprep_operation_tcp_wrapper.ml | 52 ++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
create mode 100644 sysprep/sysprep_operation_tcp_wrapper.ml
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index eb372aa..aa49605 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -67,6 +67,7 @@ operations = \
ssh_hostkeys \
ssh_userdir \
sssd_db_log \
+ tcp_wrapper \
tmp_files \
udev_persistent_net \
user_account \
diff --git a/sysprep/sysprep_operation_tcp_wrapper.ml
b/sysprep/sysprep_operation_tcp_wrapper.ml
new file mode 100644
index 0000000..77f1e0a
--- /dev/null
+++ b/sysprep/sysprep_operation_tcp_wrapper.ml
@@ -0,0 +1,52 @@
+(* virt-sysprep
+ * Copyright (C) 2013 Fujitsu Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Sysprep_operation
+open Common_gettext.Gettext
+
+module G = Guestfs
+
+let tcp_wrapper_perform g root =
+ let typ = g#inspect_get_type root in
+ if typ <> "windows" then (
+ let paths = [ "/etc/hosts.atm";
+ "/etc/hosts.allow";
+ "/etc/hosts.deny"; ] in
+ List.iter (
+ fun path ->
+ (try g#rm path with G.Error _ -> ());
+ (try g#touch path with G.Error _ -> ());
+ ) paths;
+ [ `Created_files ]
+ )
+ else []
+
+let op = {
+ defaults with
+ name = "tcp-wrapper";
+ enabled_by_default = false;
+ heading = s_"Remove the custom tcp wrappers";
+ pod_description = Some (s_"\
+This removes the custom tcp wrappers by emptying C</etc/hosts.*>.
+
+Note this is I<not> enabled by default since it may expose guests
+to exploits. Use with care.");
+ perform_on_filesystems = Some tcp_wrapper_perform;
+}
+
+let () = register_operation op
--
1.8.4.27.g0a41de8