Blame SOURCES/0006-sysprep-remove-system-local-NetworkManager-connectio.patch

7f3188
From 6f8c270b3fb7b5b3109d2553fef38f128b6137ac Mon Sep 17 00:00:00 2001
7f3188
From: Laszlo Ersek <lersek@redhat.com>
7f3188
Date: Thu, 2 Dec 2021 14:10:06 +0100
7f3188
Subject: [PATCH] sysprep: remove system-local NetworkManager connection
7f3188
 profiles (keyfiles)
7f3188
7f3188
Add a simple (default) operation to remove
7f3188
7f3188
  /etc/NetworkManager/system-connections/*.nmconnection
7f3188
7f3188
which arguably carry stale information after the initial creation of the
7f3188
system disk image.
7f3188
7f3188
Note: no side effect callback is invoked. Before commit 576f1541a20c
7f3188
("sysprep: Use customize module for customizing the guest after
7f3188
sysprepping.", 2014-03-25), the "delete" operation had been native to
7f3188
virt-sysprep ("sysprep/sysprep_operation_delete.ml"), and it didn't invoke
7f3188
side effects. In said commit, "delete" was delegated to virt-customize,
7f3188
and that was when "side_effects#created_file" was introduced (most likely)
7f3188
as a catch-all. (We still have the "XXX Did we?" comment today.)
7f3188
7f3188
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1980922
7f3188
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
7f3188
Message-Id: <20211202131006.12774-1-lersek@redhat.com>
7f3188
Acked-by: Richard W.M. Jones <rjones@redhat.com>
7f3188
(cherry picked from commit 903819ecf480bcefec108bdbd7e9bdec1b3b5a49)
7f3188
---
7f3188
 sysprep/Makefile.am                     |  1 +
7f3188
 sysprep/sysprep_operation_net_nmconn.ml | 43 +++++++++++++++++++++++++
7f3188
 2 files changed, 44 insertions(+)
7f3188
 create mode 100644 sysprep/sysprep_operation_net_nmconn.ml
7f3188
7f3188
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
7f3188
index d32ab20e..561a71ae 100644
7f3188
--- a/sysprep/Makefile.am
7f3188
+++ b/sysprep/Makefile.am
7f3188
@@ -52,6 +52,7 @@ operations = \
7f3188
 	mail_spool \
7f3188
 	net_hostname \
7f3188
 	net_hwaddr \
7f3188
+	net_nmconn \
7f3188
 	pacct_log \
7f3188
 	package_manager_cache \
7f3188
 	pam_data \
7f3188
diff --git a/sysprep/sysprep_operation_net_nmconn.ml b/sysprep/sysprep_operation_net_nmconn.ml
7f3188
new file mode 100644
7f3188
index 00000000..2d8667f1
7f3188
--- /dev/null
7f3188
+++ b/sysprep/sysprep_operation_net_nmconn.ml
7f3188
@@ -0,0 +1,43 @@
7f3188
+(* virt-sysprep
7f3188
+ * Copyright (C) 2012-2021 Red Hat Inc.
7f3188
+ *
7f3188
+ * This program is free software; you can redistribute it and/or modify
7f3188
+ * it under the terms of the GNU General Public License as published by
7f3188
+ * the Free Software Foundation; either version 2 of the License, or
7f3188
+ * (at your option) any later version.
7f3188
+ *
7f3188
+ * This program is distributed in the hope that it will be useful,
7f3188
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
7f3188
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7f3188
+ * GNU General Public License for more details.
7f3188
+ *
7f3188
+ * You should have received a copy of the GNU General Public License along
7f3188
+ * with this program; if not, write to the Free Software Foundation, Inc.,
7f3188
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
7f3188
+ *)
7f3188
+
7f3188
+open Common_gettext.Gettext
7f3188
+open Sysprep_operation
7f3188
+
7f3188
+let glob = "/etc/NetworkManager/system-connections/*.nmconnection"
7f3188
+
7f3188
+let net_nmconn_perform (g : Guestfs.guestfs) root side_effects =
7f3188
+  let typ = g#inspect_get_type root in
7f3188
+  let distro = g#inspect_get_distro root in
7f3188
+  match typ, distro with
7f3188
+  | "linux", ("fedora"|"rhel"|"centos"|"scientificlinux"|"oraclelinux"|
7f3188
+              "redhat-based") -> Array.iter g#rm_f (g#glob_expand glob)
7f3188
+  | _ -> ()
7f3188
+
7f3188
+let op = {
7f3188
+  defaults with
7f3188
+    name = "net-nmconn";
7f3188
+    enabled_by_default = true;
7f3188
+    heading = s_"Remove system-local NetworkManager connection profiles \
7f3188
+      (keyfiles)";
7f3188
+    pod_description = Some (s_"On Fedora and Red Hat Enterprise Linux, remove \
7f3188
+      the C<" ^ glob ^ "> files.");
7f3188
+    perform_on_filesystems = Some net_nmconn_perform;
7f3188
+}
7f3188
+
7f3188
+let () = register_operation op
7f3188
-- 
7f3188
2.31.1
7f3188