From 6acee58ff11645500868d4b86e7470293c478f57 Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Sat, 11 May 2019 18:39:54 -0500 Subject: bin/chown: make buildable via libbsd --- bin/chown/chown.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'bin/chown') diff --git a/bin/chown/chown.c b/bin/chown/chown.c index ee46eee..51cf3f3 100644 --- a/bin/chown/chown.c +++ b/bin/chown/chown.c @@ -29,20 +29,6 @@ * SUCH DAMAGE. */ -#include -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994, 2003\ - The Regents of the University of California. All rights reserved."); -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)chown.c 8.8 (Berkeley) 4/4/94"; -#else -__RCSID("$NetBSD: chown.c,v 1.8 2012/10/24 01:12:51 enami Exp $"); -#endif -#endif /* not lint */ - #include #include @@ -56,6 +42,7 @@ __RCSID("$NetBSD: chown.c,v 1.8 2012/10/24 01:12:51 enami Exp $"); #include #include #include +#include #include #include #include @@ -63,7 +50,7 @@ __RCSID("$NetBSD: chown.c,v 1.8 2012/10/24 01:12:51 enami Exp $"); static void a_gid(const char *); static void a_uid(const char *); static id_t id(const char *, const char *); -__dead static void usage(void); +static void usage(void); static uid_t uid; static gid_t gid; @@ -164,14 +151,6 @@ main(int argc, char **argv) *cp++ = '\0'; a_gid(cp); } -#ifdef SUPPORT_DOT - else if ((cp = strrchr(*argv, '.')) != NULL) { - if (uid_from_user(*argv, &uid) == -1) { - *cp++ = '\0'; - a_gid(cp); - } - } -#endif a_uid(*argv); } else a_gid(*argv); @@ -264,10 +243,14 @@ a_gid(const char *s) static void a_uid(const char *s) { + struct passwd *pw; if (*s == '\0') /* Argument was "[:.]gid". */ return; - if (*s == '#' || uid_from_user(s, &uid) == -1) { + pw = *s == '#' ? NULL : getpwnam(s); + if (pw == NULL) { uid = id(s, "user"); + } else { + uid = pw->pw_uid; } return; } -- cgit v1.2.3-70-g09d2