Re: [hackers] [PATCH 1/3][sbase] chown: Ignore failure to find user/group name

From: Michael Forney <mforney_AT_mforney.org>
Date: Tue, 25 Jun 2019 15:44:57 -0700

On 2019-06-25, Richard Ipsum <richardipsum_AT_fastmail.co.uk> wrote:
> This fixes an error on OpenBSD,
>
> % chown 1000:1000 yes.c
> ./chown: getgrnam 1000: No such file or directory

POSIX says that if the entry cannot be found, errno shall not be
changed. Are you saying that OpenBSD doesn't behave this way?

> ---
> chown.c | 18 ++----------------
> 1 file changed, 2 insertions(+), 16 deletions(-)
>
> diff --git a/chown.c b/chown.c
> index d7dc8e0..748ce97 100644
> --- a/chown.c
> +++ b/chown.c
> _AT_@ -79,26 +79,12 @@ main(int argc, char *argv[])
> *group++ = '\0';
>
> if (owner && *owner) {
> - errno = 0;
> pw = getpwnam(owner);
> - if (pw) {
> - uid = pw->pw_uid;
> - } else {
> - if (errno)
> - eprintf("getpwnam %s:", owner);
> - uid = estrtonum(owner, 0, UINT_MAX);
> - }
> + uid = pw ? pw->pw_uid : estrtonum(owner, 0, UINT_MAX);

It looks like there is no error with getpwnam, only with getgrname, right?
Received on Wed Jun 26 2019 - 00:44:57 CEST

This archive was generated by hypermail 2.3.0 : Wed Jun 26 2019 - 00:48:24 CEST