Skip to contentSkip to conversation

src: report EPERM for non-root users

PATCH In review Pablo Neira Ayuso 2 participants 2 messages Dec 3, 2020 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 src: report EPERM for non-root users

$ /usr/sbin/nft list ruleset
Operation not permitted (you must be root)
---
 src/libnftables.c | 7 ++++++-
 src/netlink.c     | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)
src/libnftables.c +6 -1
index a180a9a30b3d..044365914747 100644
@@ -463,8 +463,13 @@ int nft_run_cmd_from_buffer(struct nft_ctx *nft, const char *buf)
 	parser_rc = rc;
 
 	rc = nft_evaluate(nft, &msgs, &cmds);
-	if (rc < 0)
+	if (rc < 0) {
+		if (errno == EPERM) {
+			fprintf(stderr, "%s (you must be root)\n",
+				strerror(errno));
+		}
 		goto err;
+	}
 
 	if (parser_rc) {
 		rc = parser_rc;
src/netlink.c +1 -1
index f8ac2b9e3665..2ea2d4457664 100644
@@ -635,7 +635,7 @@ int netlink_list_tables(struct netlink_ctx *ctx, const struct handle *h)
 		if (errno == EINTR)
 			return -1;
 
-		return 0;
+		return -1;
 	}
 
 	ctx->data = h;
Signature · 1 line
2.20.1