Fold groups(1) and whoami(1) into id(1).

This commit is contained in:
Ruslan Ermilov 2001-09-14 14:04:08 +00:00
parent 631a876574
commit 4bf12cb91e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83452
4 changed files with 35 additions and 87 deletions

View File

@ -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>

View File

@ -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 -- "$@"

View File

@ -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);
}

View File

@ -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