summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorOkan Demirmen <okan@cvs.openbsd.org>2013-09-06 19:48:47 +0000
committerOkan Demirmen <okan@cvs.openbsd.org>2013-09-06 19:48:47 +0000
commit899bf929460602235359a3d205d0e91fae3544e9 (patch)
tree495c0d833b859df1420193daf4bc8706796b0505 /usr.bin
parentbc23a9b3e6bdf0d746f65ad457049b06e8709f37 (diff)
teach id(1) about whoami(1) and groups(1) run modes; removes shell wrappers
OK millert@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/id/Makefile9
-rw-r--r--usr.bin/id/groups.sh5
-rw-r--r--usr.bin/id/id.c46
-rw-r--r--usr.bin/id/whoami.sh5
4 files changed, 39 insertions, 26 deletions
diff --git a/usr.bin/id/Makefile b/usr.bin/id/Makefile
index 8c0f9461f5d..3554b0185d5 100644
--- a/usr.bin/id/Makefile
+++ b/usr.bin/id/Makefile
@@ -1,12 +1,9 @@
-# $OpenBSD: Makefile,v 1.4 1997/04/27 20:56:45 millert Exp $
+# $OpenBSD: Makefile,v 1.5 2013/09/06 19:48:46 okan Exp $
PROG= id
MAN= id.1 groups.1 whoami.1
-afterinstall:
- ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
- ${.CURDIR}/groups.sh ${DESTDIR}/usr/bin/groups
- ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
- ${.CURDIR}/whoami.sh ${DESTDIR}/usr/bin/whoami
+LINKS= ${BINDIR}/id ${BINDIR}/groups \
+ ${BINDIR}/id ${BINDIR}/whoami
.include <bsd.prog.mk>
diff --git a/usr.bin/id/groups.sh b/usr.bin/id/groups.sh
deleted file mode 100644
index fc3d0eeffd0..00000000000
--- a/usr.bin/id/groups.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh -
-# $OpenBSD: groups.sh,v 1.4 2001/06/20 20:50:27 pjanzen Exp $
-# Public domain.
-
-exec /usr/bin/id -Gn $*
diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c
index 690a1e0f0a6..ec63a27e78d 100644
--- a/usr.bin/id/id.c
+++ b/usr.bin/id/id.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: id.c,v 1.19 2009/10/27 23:59:39 deraadt Exp $ */
+/* $OpenBSD: id.c,v 1.20 2013/09/06 19:48:46 okan Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -31,6 +31,7 @@
#include <sys/param.h>
+#include <err.h>
#include <errno.h>
#include <grp.h>
#include <pwd.h>
@@ -38,7 +39,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <err.h>
void current(void);
void pretty(struct passwd *);
@@ -56,9 +56,26 @@ main(int argc, char *argv[])
int Gflag, ch, gflag, nflag, pflag, rflag, uflag;
uid_t uid;
gid_t gid;
+ const char *opts;
Gflag = gflag = nflag = pflag = rflag = uflag = 0;
- while ((ch = getopt(argc, argv, "Ggnpru")) != -1)
+
+ if (strcmp(getprogname(), "groups") == 0) {
+ Gflag = 1;
+ nflag = 1;
+ opts = "";
+ if (argc > 2)
+ usage();
+ } else if (strcmp(getprogname(), "whoami") == 0) {
+ uflag = 1;
+ nflag = 1;
+ opts = "";
+ if (argc > 1)
+ usage();
+ } else
+ opts = "Ggnpru";
+
+ while ((ch = getopt(argc, argv, opts)) != -1)
switch(ch) {
case 'G':
Gflag = 1;
@@ -85,7 +102,7 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- switch(Gflag + gflag + pflag + uflag) {
+ switch (Gflag + gflag + pflag + uflag) {
case 1:
break;
case 0:
@@ -96,6 +113,9 @@ main(int argc, char *argv[])
usage();
}
+ if (strcmp(opts, "") != 0 && argc > 1)
+ usage();
+
pw = *argv ? who(*argv) : NULL;
if (gflag) {
@@ -155,7 +175,7 @@ pretty(struct passwd *pw)
(void)printf("uid\t%s\n", pw->pw_name);
else
(void)printf("uid\t%u\n", rid);
-
+
if ((eid = geteuid()) != rid) {
if ((pw = getpwuid(eid)))
(void)printf("euid\t%s\n", pw->pw_name);
@@ -302,10 +322,16 @@ who(char *u)
void
usage(void)
{
- (void)fprintf(stderr, "usage: id [user]\n"
- " id -G [-n] [user]\n"
- " id -g [-nr] [user]\n"
- " id -p [user]\n"
- " id -u [-nr] [user]\n");
+ if (strcmp(getprogname(), "groups") == 0) {
+ (void)fprintf(stderr, "usage: groups [user]\n");
+ } else if (strcmp(getprogname(), "whoami") == 0) {
+ (void)fprintf(stderr, "usage: whoami\n");
+ } else {
+ (void)fprintf(stderr, "usage: id [user]\n");
+ (void)fprintf(stderr, " id -G [-n] [user]\n");
+ (void)fprintf(stderr, " id -g [-nr] [user]\n");
+ (void)fprintf(stderr, " id -p [user]\n");
+ (void)fprintf(stderr, " id -u [-nr] [user]\n");
+ }
exit(1);
}
diff --git a/usr.bin/id/whoami.sh b/usr.bin/id/whoami.sh
deleted file mode 100644
index c08f478d838..00000000000
--- a/usr.bin/id/whoami.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh -
-# $OpenBSD: whoami.sh,v 1.4 1999/09/25 17:21:38 pjanzen Exp $
-# Public domain
-
-exec /usr/bin/id -un