Add "-P" display the id as a password file entry.

Submitted by:	terry
This commit is contained in:
David E. O'Brien 1998-08-21 06:47:58 +00:00
parent 1eab1be09e
commit bd7061056e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=38468
2 changed files with 40 additions and 6 deletions

View File

@ -33,7 +33,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)id.1 8.1 (Berkeley) 6/6/93
.\" $Id: id.1,v 1.3 1997/06/23 04:02:57 steve Exp $
.\" $Id: id.1,v 1.4 1998/02/28 21:37:54 alex Exp $
.\"
.Dd June 6, 1993
.Dt ID 1
@ -48,6 +48,9 @@
.Fl G Op Fl n
.Op Ar user
.Nm id
.Fl P
.Op Ar user
.Nm id
.Fl g Op Fl nr
.Op Ar user
.Nm id
@ -74,6 +77,8 @@ The options are as follows:
.It Fl G
Display the different group IDs (effective, real and supplementary)
as white-space separated numbers, in no particular order.
.It Fl P
Display the id as a password file entry.
.It Fl g
Display the effective group ID as a number.
.It Fl n

View File

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)id.c 8.2 (Berkeley) 2/16/94";
#endif
static const char rcsid[] =
"$Id: id.c,v 1.5 1997/07/15 09:48:49 charnier Exp $";
"$Id: id.c,v 1.6 1998/02/18 17:35:16 steve Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -56,6 +56,7 @@ static const char rcsid[] =
#include <unistd.h>
void current __P((void));
void pline __P((struct passwd *));
void pretty __P((struct passwd *));
void group __P((struct passwd *, int));
void usage __P((void));
@ -70,14 +71,17 @@ main(argc, argv)
{
struct group *gr;
struct passwd *pw;
int Gflag, ch, gflag, id, nflag, pflag, rflag, uflag;
int Gflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag;
Gflag = gflag = nflag = pflag = rflag = uflag = 0;
while ((ch = getopt(argc, argv, "Ggnpru")) != -1)
Gflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0;
while ((ch = getopt(argc, argv, "PGgnpru")) != -1)
switch(ch) {
case 'G':
Gflag = 1;
break;
case 'P':
Pflag = 1;
break;
case 'g':
gflag = 1;
break;
@ -100,7 +104,7 @@ main(argc, argv)
argc -= optind;
argv += optind;
switch(Gflag + gflag + pflag + uflag) {
switch(Gflag + Pflag + gflag + pflag + uflag) {
case 1:
break;
case 0:
@ -136,6 +140,11 @@ main(argc, argv)
exit(0);
}
if (Pflag) {
pline(pw);
exit(0);
}
if (pflag) {
pretty(pw);
exit(0);
@ -314,6 +323,26 @@ who(u)
/* NOTREACHED */
}
void
pline(pw)
struct passwd *pw;
{
struct group *gr;
u_int eid, rid;
char *login;
if (!pw) {
if ((pw = getpwuid(rid = getuid())) == NULL)
err(1, "getpwuid");
}
(void)printf("%s:%s:%d:%d:%s:%d:%d:%s:%s:%s\n", pw->pw_name,
pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_class,
pw->pw_change, pw->pw_expire, pw->pw_gecos,
pw->pw_dir, pw->pw_shell);
}
void
usage()
{