summaryrefslogtreecommitdiff
path: root/bin/chown/chown.c
diff options
context:
space:
mode:
authorKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-11 18:39:54 -0500
committerKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-11 18:39:54 -0500
commit6acee58ff11645500868d4b86e7470293c478f57 (patch)
tree7bb0005e3237b9759cceb8b6bd226ce29aeaf60f /bin/chown/chown.c
parent51b081b4a0cf3da4d325aeb395e8157f0634f1e0 (diff)
downloaduserland-6acee58ff11645500868d4b86e7470293c478f57.tar.gz
userland-6acee58ff11645500868d4b86e7470293c478f57.tar.bz2
userland-6acee58ff11645500868d4b86e7470293c478f57.tar.xz
userland-6acee58ff11645500868d4b86e7470293c478f57.zip
bin/chown: make buildable via libbsd
Diffstat (limited to 'bin/chown/chown.c')
-rw-r--r--bin/chown/chown.c31
1 files changed, 7 insertions, 24 deletions
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 <sys/cdefs.h>
-#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 <sys/types.h>
#include <sys/stat.h>
@@ -56,6 +42,7 @@ __RCSID("$NetBSD: chown.c,v 1.8 2012/10/24 01:12:51 enami Exp $");
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <bsd/stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
@@ -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;
}