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>] [day] [month] [year] [list]
Message-Id: <1419545758-11200-1-git-send-email-shahar@stratoscale.com>
Date:	Fri, 26 Dec 2014 00:15:58 +0200
From:	Shahar Lev <shahar@...atoscale.com>
To:	netdev@...r.kernel.org
Cc:	Shahar Lev <shahar@...atoscale.com>
Subject: [PATCH] ipnetns: fix exec for netns not in NETNS_RUN_DIR

Enabling "ip netns exec" to be run with a net namespace
specified by a file path rather than a filename under /var/run/nets.

Signed-off-by: Shahar Lev <shahar@...atoscale.com>
---
 ip/ipnetns.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 1c8aa02..5310d0c 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -66,7 +66,7 @@ static int usage(void)
 	exit(-1);
 }
 
-int get_netns_fd(const char *name)
+static int get_netns_fd_flags(const char *name, int flags)
 {
 	char pathbuf[MAXPATHLEN];
 	const char *path, *ptr;
@@ -78,7 +78,12 @@ int get_netns_fd(const char *name)
 			NETNS_RUN_DIR, name );
 		path = pathbuf;
 	}
-	return open(path, O_RDONLY);
+	return open(path, flags);
+}
+
+int get_netns_fd(const char *name)
+{
+	return get_netns_fd_flags(name, O_RDONLY);
 }
 
 static int netns_list(int argc, char **argv)
@@ -135,7 +140,6 @@ static int netns_exec(int argc, char **argv)
 	 * aware, and execute a program in that environment.
 	 */
 	const char *name, *cmd;
-	char net_path[MAXPATHLEN];
 	int netns;
 
 	if (argc < 1) {
@@ -149,8 +153,7 @@ static int netns_exec(int argc, char **argv)
 
 	name = argv[0];
 	cmd = argv[1];
-	snprintf(net_path, sizeof(net_path), "%s/%s", NETNS_RUN_DIR, name);
-	netns = open(net_path, O_RDONLY | O_CLOEXEC);
+	netns = get_netns_fd_flags(name, O_RDONLY | O_CLOEXEC);
 	if (netns < 0) {
 		fprintf(stderr, "Cannot open network namespace \"%s\": %s\n",
 			name, strerror(errno));
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ