curproc() isn't needed in id(1)
This commit is contained in:
parent
dac77d3089
commit
fd8c3b6438
60
id.c
60
id.c
@ -10,7 +10,6 @@
|
||||
#include "util.h"
|
||||
|
||||
static void user(struct passwd *pw);
|
||||
static void curproc(void);
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
@ -28,12 +27,17 @@ main(int argc, char *argv[])
|
||||
usage();
|
||||
} ARGEND;
|
||||
|
||||
errno = 0;
|
||||
switch (argc) {
|
||||
case 0:
|
||||
curproc();
|
||||
pw = getpwuid(getuid());
|
||||
if (errno != 0)
|
||||
eprintf("getpwuid %d:", getuid());
|
||||
else if (!pw)
|
||||
eprintf("getpwuid %d: no such user\n", getuid());
|
||||
user(pw);
|
||||
break;
|
||||
case 1:
|
||||
errno = 0;
|
||||
pw = getpwnam(argv[0]);
|
||||
if (errno != 0)
|
||||
eprintf("getpwnam %s:", argv[0]);
|
||||
@ -73,53 +77,3 @@ user(struct passwd *pw)
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void
|
||||
curproc(void)
|
||||
{
|
||||
struct passwd *pw;
|
||||
struct group *gr;
|
||||
uid_t uid, euid;
|
||||
gid_t gid, egid, groups[NGROUPS_MAX];
|
||||
int ngroups;
|
||||
int i;
|
||||
|
||||
/* Print uid/euid info */
|
||||
uid = getuid();
|
||||
printf("uid=%u", uid);
|
||||
if (!(pw = getpwuid(uid)))
|
||||
eprintf("getpwuid:");
|
||||
printf("(%s)", pw->pw_name);
|
||||
if ((euid = geteuid()) != uid) {
|
||||
printf(" euid=%u", euid);
|
||||
if (!(pw = getpwuid(euid)))
|
||||
eprintf("getpwuid:");
|
||||
printf("(%s)", pw->pw_name);
|
||||
}
|
||||
|
||||
/* Print gid/egid info */
|
||||
gid = getgid();
|
||||
printf(" gid=%u", gid);
|
||||
if (!(gr = getgrgid(gid)))
|
||||
eprintf("getgrgid:");
|
||||
printf("(%s)", gr->gr_name);
|
||||
if ((egid = getegid()) != gid) {
|
||||
printf(" egid=%u", egid);
|
||||
if (!(gr = getgrgid(egid)))
|
||||
eprintf("getgrgid:");
|
||||
printf("(%s)", gr->gr_name);
|
||||
}
|
||||
|
||||
/* Print groups */
|
||||
ngroups = getgroups(NGROUPS_MAX, groups);
|
||||
if (ngroups < 0)
|
||||
eprintf("getgroups:");
|
||||
for (i = 0; i < ngroups; i++) {
|
||||
gid = groups[i];
|
||||
printf("%s%u", !i ? " groups=" : ",", gid);
|
||||
if (!(gr = getgrgid(gid)))
|
||||
eprintf("getgrgid:");
|
||||
printf("(%s)", gr->gr_name);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user