version 1.19, 2009/10/27 23:59:39 |
version 1.20, 2013/09/06 19:48:46 |
|
|
|
|
#include <sys/param.h> |
#include <sys/param.h> |
|
|
|
#include <err.h> |
#include <errno.h> |
#include <errno.h> |
#include <grp.h> |
#include <grp.h> |
#include <pwd.h> |
#include <pwd.h> |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <err.h> |
|
|
|
void current(void); |
void current(void); |
void pretty(struct passwd *); |
void pretty(struct passwd *); |
|
|
int Gflag, ch, gflag, nflag, pflag, rflag, uflag; |
int Gflag, ch, gflag, nflag, pflag, rflag, uflag; |
uid_t uid; |
uid_t uid; |
gid_t gid; |
gid_t gid; |
|
const char *opts; |
|
|
Gflag = gflag = nflag = pflag = rflag = uflag = 0; |
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) { |
switch(ch) { |
case 'G': |
case 'G': |
Gflag = 1; |
Gflag = 1; |
|
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
switch(Gflag + gflag + pflag + uflag) { |
switch (Gflag + gflag + pflag + uflag) { |
case 1: |
case 1: |
break; |
break; |
case 0: |
case 0: |
|
|
usage(); |
usage(); |
} |
} |
|
|
|
if (strcmp(opts, "") != 0 && argc > 1) |
|
usage(); |
|
|
pw = *argv ? who(*argv) : NULL; |
pw = *argv ? who(*argv) : NULL; |
|
|
if (gflag) { |
if (gflag) { |
|
|
(void)printf("uid\t%s\n", pw->pw_name); |
(void)printf("uid\t%s\n", pw->pw_name); |
else |
else |
(void)printf("uid\t%u\n", rid); |
(void)printf("uid\t%u\n", rid); |
|
|
if ((eid = geteuid()) != rid) { |
if ((eid = geteuid()) != rid) { |
if ((pw = getpwuid(eid))) |
if ((pw = getpwuid(eid))) |
(void)printf("euid\t%s\n", pw->pw_name); |
(void)printf("euid\t%s\n", pw->pw_name); |
|
|
void |
void |
usage(void) |
usage(void) |
{ |
{ |
(void)fprintf(stderr, "usage: id [user]\n" |
if (strcmp(getprogname(), "groups") == 0) { |
" id -G [-n] [user]\n" |
(void)fprintf(stderr, "usage: groups [user]\n"); |
" id -g [-nr] [user]\n" |
} else if (strcmp(getprogname(), "whoami") == 0) { |
" id -p [user]\n" |
(void)fprintf(stderr, "usage: whoami\n"); |
" id -u [-nr] [user]\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); |
exit(1); |
} |
} |