summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-12-20 21:02:31 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-12-20 21:02:31 -0500
commitb23b74b9bd204ce432109f92f6dd5468e07daeba (patch)
tree255a7602973908cb92fa01165e42fa5384c22888
parent8fad779ae21b1052268af0befa930c75d1dd780b (diff)
downloadbfs-b23b74b9bd204ce432109f92f6dd5468e07daeba.tar.xz
Don't check errno after get{gr,pw}nam()
Turns out it doesn't always keep errno 0, even if the only problem is a failed lookup. This was observed on a machine with Kerberos auth.
-rw-r--r--parse.c30
1 files changed, 6 insertions, 24 deletions
diff --git a/parse.c b/parse.c
index 1af73cb..cba9a29 100644
--- a/parse.c
+++ b/parse.c
@@ -991,31 +991,22 @@ static struct expr *parse_group(struct parser_state *state, int arg1, int arg2)
return NULL;
}
- const char *error;
-
- errno = 0;
struct group *grp = getgrnam(expr->sdata);
if (grp) {
expr->idata = grp->gr_gid;
- } else if (errno != 0) {
- error = strerror(errno);
- goto error;
} else if (isdigit(expr->sdata[0])) {
if (!parse_int(state, expr->sdata, &expr->idata, IF_LONG_LONG)) {
goto fail;
}
} else {
- error = "No such group";
- goto error;
+ pretty_error(state->cmdline->stderr_colors,
+ "error: %s %s: No such group.\n", arg, expr->sdata);
+ goto fail;
}
expr->cmp_flag = CMP_EXACT;
return expr;
-error:
- pretty_error(state->cmdline->stderr_colors,
- "error: %s %s: %s.\n", arg, expr->sdata, error);
-
fail:
free_expr(expr);
return NULL;
@@ -1046,31 +1037,22 @@ static struct expr *parse_user(struct parser_state *state, int arg1, int arg2) {
return NULL;
}
- const char *error;
-
- errno = 0;
struct passwd *pwd = getpwnam(expr->sdata);
if (pwd) {
expr->idata = pwd->pw_uid;
- } else if (errno != 0) {
- error = strerror(errno);
- goto error;
} else if (isdigit(expr->sdata[0])) {
if (!parse_int(state, expr->sdata, &expr->idata, IF_LONG_LONG)) {
goto fail;
}
} else {
- error = "No such user";
- goto error;
+ pretty_error(state->cmdline->stderr_colors,
+ "error: %s %s: No such user.\n", arg, expr->sdata);
+ goto fail;
}
expr->cmp_flag = CMP_EXACT;
return expr;
-error:
- pretty_error(state->cmdline->stderr_colors,
- "error: %s %s: %s.\n", arg, expr->sdata, error);
-
fail:
free_expr(expr);
return NULL;