From 38722cbd0705188b1930b938d3d3b54fed9726f1 Mon Sep 17 00:00:00 2001 From: sunsuwan Date: Mon, 24 Jul 2023 16:14:47 +0800 Subject: [PATCH] delete lease file when connection deleted Signed-off-by: sunsuwan --- NetworkManager.spec | 9 +- ...e-lease-file-when-connection-deleted.patch | 140 ++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 delete-lease-file-when-connection-deleted.patch diff --git a/NetworkManager.spec b/NetworkManager.spec index 35ef466..f608e5a 100644 --- a/NetworkManager.spec +++ b/NetworkManager.spec @@ -51,7 +51,7 @@ Name: NetworkManager Version: 1.32.12 Epoch: 1 -Release: 19 +Release: 20 Summary: Network Link Manager and User Applications License: GPLv2+ URL: https://www.gnome.org/projects/NetworkManager/ @@ -68,6 +68,7 @@ Patch6001: backport-libnm-fix-crash-on-failure-of-nm_vpn_plugin_info_new_ Patch6002: backport-core-reload-config-for-active-devices.patch Patch6003: backport-libnm-fix-warning-when-setting-wrong-ethtool-ternary-value.patch Patch6004: NetworkManager-Add-sw64-architecture.patch +Patch6005: delete-lease-file-when-connection-deleted.patch BuildRequires: gcc libtool pkgconfig automake autoconf intltool gettext-devel ppp-devel gnutls-devel BuildRequires: dbus-devel dbus-glib-devel glib2-devel gobject-introspection-devel jansson-devel @@ -508,6 +509,12 @@ fi %{_datadir}/gtk-doc/html/NetworkManager/* %changelog +* Mon Jul 24 2023 sunsuwan - 1:1.32.12-20 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:delete lease file when connection deleted + * Tue Jun 13 2023 gaoxingwang - 1:1.32.12-19 - Type:bugfix - CVE:NA diff --git a/delete-lease-file-when-connection-deleted.patch b/delete-lease-file-when-connection-deleted.patch new file mode 100644 index 0000000..4ac536f --- /dev/null +++ b/delete-lease-file-when-connection-deleted.patch @@ -0,0 +1,140 @@ +From 1c42631f72215ce02d8571c6d61ffae481744ce3 Mon Sep 17 00:00:00 2001 +From: gaoxingwang +Date: Sat, 17 Dec 2022 21:01:26 +0800 +Subject: [PATCH] delete lease file when connection deleted +Currently, the dhclient-uid-xxx.lease file generated in nmcli add/del mode will + not be deleted, which is unreasonable. In this deletion, only the specified + lease file is deleted in the nmcli del phase. + +Signed-off-by: gaoxingwang +Signed-off-by: liaichun +--- + src/nmcli/connections.c | 105 ++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 105 insertions(+) + +diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c +index 9f700ca..8f68c02 100644 +--- a/src/nmcli/connections.c ++++ b/src/nmcli/connections.c +@@ -8989,6 +8989,110 @@ delete_cb(GObject *con, GAsyncResult *result, gpointer user_data) + } + } + ++static const char * ++_addr_family_to_path_part(int addr_family) ++{ ++ nm_assert(NM_IN_SET(addr_family, AF_INET, AF_INET6)); ++ return (addr_family == AF_INET6) ? "6" : ""; ++} ++ ++static gboolean ++nm_dhcp_utils_get_leasefile_path(int addr_family, ++ const char *plugin_name, ++ const char *iface, ++ const char *uuid, ++ char ** out_leasefile_path) ++{ ++ gs_free char *rundir_path = NULL; ++ gs_free char *statedir_path = NULL; ++ ++ rundir_path = g_strdup_printf(NMRUNDIR "/%s%s-%s-%s.lease", ++ plugin_name, ++ _addr_family_to_path_part(addr_family), ++ uuid, ++ iface); ++ ++ if (g_file_test(rundir_path, G_FILE_TEST_EXISTS)) { ++ *out_leasefile_path = g_steal_pointer(&rundir_path); ++ return TRUE; ++ } ++ ++ statedir_path = g_strdup_printf(NMSTATEDIR "/%s%s-%s-%s.lease", ++ plugin_name, ++ _addr_family_to_path_part(addr_family), ++ uuid, ++ iface); ++ ++ if (g_file_test(statedir_path, G_FILE_TEST_EXISTS)) { ++ *out_leasefile_path = g_steal_pointer(&statedir_path); ++ return TRUE; ++ } ++ return FALSE; ++} ++ ++static char * ++get_dhclient_leasefile(int addr_family, const char *iface, const char *uuid, char **out_preferred_path) ++{ ++ gs_free char *path = NULL; ++ ++ if (nm_dhcp_utils_get_leasefile_path(addr_family, "dhclient", iface, uuid, &path)) { ++ NM_SET_OUT(out_preferred_path, g_strdup(path)); ++ return g_steal_pointer(&path); ++ } ++ ++ NM_SET_OUT(out_preferred_path, g_steal_pointer(&path)); ++ ++ /* If the leasefile we're looking for doesn't exist yet in the new location ++ * (eg, /var/lib/NetworkManager) then look in old locations to maintain ++ * backwards compatibility with external tools (like dracut) that put ++ * leasefiles there. ++ */ ++ ++ /* Old Debian, SUSE, and Mandriva location */ ++ g_free(path); ++ path = g_strdup_printf(LOCALSTATEDIR "/lib/dhcp/dhclient%s-%s-%s.lease", ++ _addr_family_to_path_part(addr_family), ++ uuid, ++ iface); ++ if (g_file_test(path, G_FILE_TEST_EXISTS)) ++ return g_steal_pointer(&path); ++ ++ /* Old Red Hat and Fedora location */ ++ g_free(path); ++ path = g_strdup_printf(LOCALSTATEDIR "/lib/dhclient/dhclient%s-%s-%s.lease", ++ _addr_family_to_path_part(addr_family), ++ uuid, ++ iface); ++ if (g_file_test(path, G_FILE_TEST_EXISTS)) ++ return g_steal_pointer(&path); ++ ++ /* Fail */ ++ return NULL; ++} ++ ++static void ++do_lease_file_delete(NMConnection *connection) ++{ ++ gs_free char *ip4_leasefile = NULL; ++ gs_free char *ip6_leasefile = NULL; ++ ip4_leasefile = get_dhclient_leasefile(AF_INET, ++ nm_connection_get_id(connection), ++ nm_connection_get_uuid(connection), ++ NULL); ++ ++ ip6_leasefile = get_dhclient_leasefile(AF_INET6, ++ nm_connection_get_id(connection), ++ nm_connection_get_uuid(connection), ++ NULL); ++ ++ if (ip4_leasefile) { ++ (void) unlink(ip4_leasefile); ++ } ++ if (ip6_leasefile) { ++ (void) unlink(ip6_leasefile); ++ } ++} ++ + static void + do_connection_delete(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) + { +@@ -9085,6 +9189,7 @@ do_connection_delete(const NMCCommand *cmd, NmCli *nmc, int argc, const char *co + info->cancellable, + delete_cb, + info); ++ do_lease_file_delete(found_cons->pdata[i]); + } + + finish: +-- +2.27.0 + -- Gitee