lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 19 Jul 2023 20:51:01 +0200
From: Gioele Barabucci <gioele@...rio.it>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <stephen@...workplumber.org>,
	Gioele Barabucci <gioele@...rio.it>
Subject: [iproute2 17/22] lib/rt_names: Read rt_protos.d/* from /etc and /usr

Signed-off-by: Gioele Barabucci <gioele@...rio.it>
---
 lib/rt_names.c | 44 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/lib/rt_names.c b/lib/rt_names.c
index 4f38fcbe..d9c48813 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -12,6 +12,7 @@
 #include <string.h>
 #include <sys/time.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <dirent.h>
 #include <limits.h>
 #include <errno.h>
@@ -165,13 +166,12 @@ static void rtnl_rtprot_initialize(void)
 		rtnl_tab_initialize(CONF_USR_DIR "/rt_protos",
 		                    rtnl_rtprot_tab, 256);
 
-	d = opendir(CONF_ETC_DIR "/rt_protos.d");
-	if (!d)
-		return;
-
-	while ((de = readdir(d)) != NULL) {
+	/* load /usr/lib/iproute2/foo.d/X, unless /etc/iproute2/foo.d/X exists */
+	d = opendir(CONF_USR_DIR "/rt_protos.d");
+	while (d && (de = readdir(d)) != NULL) {
 		char path[PATH_MAX];
 		size_t len;
+		struct stat sb;
 
 		if (*de->d_name == '.')
 			continue;
@@ -183,11 +183,43 @@ static void rtnl_rtprot_initialize(void)
 		if (strcmp(de->d_name + len - 5, ".conf"))
 			continue;
 
+		/* only consider filenames not present in /etc */
+		snprintf(path, sizeof(path), CONF_USR_DIR "/rt_protos.d/%s",
+		         de->d_name);
+		if (lstat(path, &sb) == 0)
+			continue;
+
+		/* load the conf file in /usr */
 		snprintf(path, sizeof(path), CONF_ETC_DIR "/rt_protos.d/%s",
 			 de->d_name);
 		rtnl_tab_initialize(path, rtnl_rtprot_tab, 256);
 	}
-	closedir(d);
+	if (d)
+		closedir(d);
+
+	/* load /etc/iproute2/foo.d/X */
+	d = opendir(CONF_ETC_DIR "/rt_protos.d");
+	while (d && (de = readdir(d)) != NULL) {
+		char path[PATH_MAX];
+		size_t len;
+
+		if (*de->d_name == '.')
+			continue;
+
+		/* only consider filenames ending in '.conf' */
+		len = strlen(de->d_name);
+		if (len <= 5)
+			continue;
+		if (strcmp(de->d_name + len - 5, ".conf"))
+			continue;
+
+		/* load the conf file in /etc */
+		snprintf(path, sizeof(path), CONF_USR_DIR "/rt_protos.d/%s",
+			 de->d_name);
+		rtnl_tab_initialize(path, rtnl_rtprot_tab, 256);
+	}
+	if (d)
+		closedir(d);
 }
 
 const char *rtnl_rtprot_n2a(int id, char *buf, int len)
-- 
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ