summaryrefslogtreecommitdiffstats
path: root/usr.bin/id
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2001-09-14 14:04:08 +0000
committerru <ru@FreeBSD.org>2001-09-14 14:04:08 +0000
commite177b37bfd6870effd6c9d3189a3c0e39ff60c2a (patch)
tree08a25d97660d0a79519561b54cdb886db707c783 /usr.bin/id
parent3a475bde7a6172b4006c8c6d7318d76b6d06e2a8 (diff)
downloadFreeBSD-src-e177b37bfd6870effd6c9d3189a3c0e39ff60c2a.zip
FreeBSD-src-e177b37bfd6870effd6c9d3189a3c0e39ff60c2a.tar.gz
Fold groups(1) and whoami(1) into id(1).
Diffstat (limited to 'usr.bin/id')
-rw-r--r--usr.bin/id/Makefile3
-rw-r--r--usr.bin/id/groups.sh39
-rw-r--r--usr.bin/id/id.c41
-rw-r--r--usr.bin/id/whoami.sh39
4 files changed, 35 insertions, 87 deletions
diff --git a/usr.bin/id/Makefile b/usr.bin/id/Makefile
index 6243d61..e505e7d 100644
--- a/usr.bin/id/Makefile
+++ b/usr.bin/id/Makefile
@@ -3,7 +3,8 @@
PROG= id
WARNS?= 2
-SCRIPTS=groups.sh whoami.sh
+LINKS= ${BINDIR}/id ${BINDIR}/groups
+LINKS+= ${BINDIR}/id ${BINDIR}/whoami
MAN= id.1 groups.1 whoami.1
.include <bsd.prog.mk>
diff --git a/usr.bin/id/groups.sh b/usr.bin/id/groups.sh
deleted file mode 100644
index b6350be..0000000
--- a/usr.bin/id/groups.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991, 1993
-# The Regents of the University of California. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the University of
-# California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# @(#)groups.sh 8.1 (Berkeley) 6/6/93
-# $FreeBSD$
-
-PATH=/bin:/usr/bin; export PATH
-
-exec id -Gn -- "$@"
diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c
index a18dc4a..c0936f3 100644
--- a/usr.bin/id/id.c
+++ b/usr.bin/id/id.c
@@ -65,6 +65,8 @@ void user __P((struct passwd *));
struct passwd *
who __P((char *));
+int isgroups, iswhoami;
+
int
main(argc, argv)
int argc;
@@ -73,9 +75,23 @@ main(argc, argv)
struct group *gr;
struct passwd *pw;
int Gflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag;
+ const char *myname;
Gflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0;
- while ((ch = getopt(argc, argv, "PGgnpru")) != -1)
+
+ myname = strrchr(argv[0], '/');
+ myname = (myname != NULL) ? myname + 1 : argv[0];
+ if (strcmp(myname, "groups") == 0) {
+ isgroups = 1;
+ Gflag = nflag = 1;
+ }
+ else if (strcmp(myname, "whoami") == 0) {
+ iswhoami = 1;
+ uflag = nflag = 1;
+ }
+
+ while ((ch = getopt(argc, argv,
+ (isgroups || iswhoami) ? "" : "PGgnpru")) != -1)
switch(ch) {
case 'G':
Gflag = 1;
@@ -105,6 +121,9 @@ main(argc, argv)
argc -= optind;
argv += optind;
+ if (iswhoami && argc > 0)
+ usage();
+
switch(Gflag + Pflag + gflag + pflag + uflag) {
case 1:
break;
@@ -347,12 +366,18 @@ pline(pw)
void
usage()
{
- (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n",
- "usage: id [user]",
- " id -G [-n] [user]",
- " id -P [user]",
- " id -g [-nr] [user]",
- " id -p [user]",
- " id -u [-nr] [user]");
+
+ if (isgroups)
+ (void)fprintf(stderr, "usage: groups [user]\n");
+ else if (iswhoami)
+ (void)fprintf(stderr, "usage: whoami\n");
+ else
+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n",
+ "usage: id [user]",
+ " id -G [-n] [user]",
+ " id -P [user]",
+ " id -g [-nr] [user]",
+ " id -p [user]",
+ " id -u [-nr] [user]");
exit(1);
}
diff --git a/usr.bin/id/whoami.sh b/usr.bin/id/whoami.sh
deleted file mode 100644
index 9b18bac..0000000
--- a/usr.bin/id/whoami.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991, 1993
-# The Regents of the University of California. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the University of
-# California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# @(#)whoami.sh 8.1 (Berkeley) 6/6/93
-# $FreeBSD$
-
-PATH=/bin:/usr/bin; export PATH
-
-exec id -un
OpenPOWER on IntegriCloud