From b23b74b9bd204ce432109f92f6dd5468e07daeba Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 20 Dec 2016 21:02:31 -0500 Subject: 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. --- parse.c | 30 ++++++------------------------ 1 file 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; -- cgit v1.2.3