[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] Add more diagnostics for advanced error reporting
From: |
Bodo Eggert |
Subject: |
[PATCH 3/3] Add more diagnostics for advanced error reporting |
Date: |
Tue, 26 Sep 2023 17:09:24 +0200 |
"Permissions" like "rwr" or "asd" generate an appropriate message. Also a
completely missing permission string is reported as such.
---
tools/parse.c | 25 +++++++++++++++++++------
tools/setfacl.c | 14 ++++++++++----
2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/tools/parse.c b/tools/parse.c
index 6f12ec6..24eff9e 100644
--- a/tools/parse.c
+++ b/tools/parse.c
@@ -50,6 +50,8 @@ char *advanced_errors[] = {
"Error while looking up user",
"Group not found",
"Error while looking up group",
+ "Invalid permission string",
+ "Missing permissions",
};
static int
@@ -200,6 +202,8 @@ accept:
4: Error while looking up user
5: Group not found
6: Error while looking up group
+ 7: Invalid permission string
+ 8: Missing permissions
*/
cmd_t
@@ -313,7 +317,7 @@ user_entry:
if (parse_mode & SEQ_PARSE_NO_PERM)
return cmd;
else
- *err_ret = 1;
+ *err_ret = 8;
goto fail;
}
if (!(parse_mode & SEQ_PARSE_WITH_PERM))
@@ -336,7 +340,7 @@ user_entry:
switch(**text_p) {
case 'r': /* read */
if (cmd->c_perm & CMD_PERM_READ) {
- *err_ret = 1;
+ *err_ret = 7;
goto fail;
}
cmd->c_perm |= CMD_PERM_READ;
@@ -344,7 +348,7 @@ user_entry:
case 'w': /* write */
if (cmd->c_perm & CMD_PERM_WRITE) {
- *err_ret = 1;
+ *err_ret = 7;
goto fail;
}
cmd->c_perm |= CMD_PERM_WRITE;
@@ -352,7 +356,7 @@ user_entry:
case 'x': /* execute */
if (cmd->c_perm & CMD_PERM_EXECUTE) {
- *err_ret = 1;
+ *err_ret = 7;
goto fail;
}
cmd->c_perm |= CMD_PERM_EXECUTE;
@@ -362,7 +366,7 @@ user_entry:
entries already have execute permissions
set */
if (cmd->c_perm & CMD_PERM_COND_EXECUTE) {
- *err_ret = 1;
+ *err_ret = 7;
goto fail;
}
cmd->c_perm |= CMD_PERM_COND_EXECUTE;
@@ -372,9 +376,18 @@ user_entry:
/* ignore */
break;
+ case '0' ... '9':
+ case 'a' ... 'q':
+ case 's' ... 'v':
+ case 'y' ... 'z':
+ case 'A' ... 'W':
+ case 'Y' ... 'Z':
+ *err_ret = 7;
+ goto fail;
+
default:
if (perm_chars == 0) {
- *err_ret = 1;
+ *err_ret = 7;
goto fail;
}
return cmd;
diff --git a/tools/setfacl.c b/tools/setfacl.c
index df9695a..9dddbf4 100644
--- a/tools/setfacl.c
+++ b/tools/setfacl.c
@@ -499,10 +499,16 @@ int main(int argc, char *argv[])
seq_cmd, parse_mode,
&err_ret) != 0) {
if (which < 0 ||
(size_t) which >= strlen(optarg)) {
- fprintf(stderr, _(
- "%s: Option "
- "-%c incomplete\n"),
- progname, opt);
+ if (err_ret > 1)
+ fprintf(stderr, _(
+ "%s: Option "
+ "-%c incomplete
(%s)\n"),
+ progname, opt,
advanced_errors[err_ret]);
+ else
+ fprintf(stderr, _(
+ "%s: Option "
+ "-%c
incomplete\n"),
+ progname, opt);
} else {
fprintf(stderr, _(
"%s: Option "
--
2.42.0