Skip to contentSkip to conversation

main: consolidate EPERM to non-root users

PATCH In review Pablo Neira Ayuso 2 participants 2 messages Apr 9 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v2 1/5 main: consolidate EPERM to non-root users

Move the check added by 3cfb9e4b3e40 ("src: report EPERM for non-root users") to the main function.

EPERM is also possible when removing a ruleset that is owned by a process, tone it down to suggest that root is maybe needed.

---
v2: handle EPERM from main, per Florian.
I'm not resending the entire series at this stage, patch 2/5, 3/5, 4/5 and 5/5 got no changes.

 src/libnftables.c | 7 +------
 src/main.c        | 2 ++
 2 files changed, 3 insertions(+), 6 deletions(-)
src/libnftables.c +1 -6
index 66b03a1170bb..bc42c32de889 100644
@@ -630,13 +630,8 @@ 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 (errno == EPERM) {
-			fprintf(stderr, "%s (you must be root)\n",
-				strerror(errno));
-		}
+	if (rc < 0)
 		goto err;
-	}
 
 	if (parser_rc) {
 		rc = parser_rc;
src/main.c +2 -0
index 29b0533dee7c..4cb51ff7f5fe 100644
@@ -548,6 +548,8 @@ int main(int argc, char * const *argv)
 		goto out_fail;
 	}
 
+	if (rc && errno == EPERM)
+		 fprintf(stderr, "Error: %s (perhaps you must be root?)\n", strerror(errno));
 out:
 	nft_ctx_free(nft);
 	return rc;
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 2 lines · Pablo Neira Ayuso

Move the check added by 3cfb9e4b3e40 ("src: report EPERM for non-root users") to the main function.

Thanks!