version 1.22, 2015/01/16 06:40:08 |
version 1.23, 2015/05/19 16:03:19 |
|
|
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <limits.h> |
#include <limits.h> |
|
#include <login_cap.h> |
|
|
void current(void); |
void current(void); |
void pretty(struct passwd *); |
void pretty(struct passwd *); |
|
|
{ |
{ |
struct group *gr; |
struct group *gr; |
struct passwd *pw; |
struct passwd *pw; |
int Gflag, ch, gflag, nflag, pflag, rflag, uflag; |
int ch, cflag, Gflag, gflag, nflag, pflag, rflag, uflag; |
uid_t uid; |
uid_t uid; |
gid_t gid; |
gid_t gid; |
const char *opts; |
const char *opts; |
|
|
Gflag = gflag = nflag = pflag = rflag = uflag = 0; |
cflag = Gflag = gflag = nflag = pflag = rflag = uflag = 0; |
|
|
if (strcmp(getprogname(), "groups") == 0) { |
if (strcmp(getprogname(), "groups") == 0) { |
Gflag = 1; |
Gflag = 1; |
|
|
if (argc > 1) |
if (argc > 1) |
usage(); |
usage(); |
} else |
} else |
opts = "Ggnpru"; |
opts = "cGgnpru"; |
|
|
while ((ch = getopt(argc, argv, opts)) != -1) |
while ((ch = getopt(argc, argv, opts)) != -1) |
switch(ch) { |
switch(ch) { |
|
case 'c': |
|
cflag = 1; |
|
break; |
case 'G': |
case 'G': |
Gflag = 1; |
Gflag = 1; |
break; |
break; |
|
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
switch (Gflag + gflag + pflag + uflag) { |
switch (cflag + Gflag + gflag + pflag + uflag) { |
case 1: |
case 1: |
break; |
break; |
case 0: |
case 0: |
|
|
|
|
pw = *argv ? who(*argv) : NULL; |
pw = *argv ? who(*argv) : NULL; |
|
|
|
if (cflag) { |
|
if (pw == NULL) |
|
pw = getpwuid(getuid()); |
|
if (pw != NULL && pw->pw_class != NULL && *pw->pw_class != '\0') |
|
(void)printf("%s\n", pw->pw_class); |
|
else |
|
(void)printf("%s\n", LOGIN_DEFCLASS); |
|
exit(0); |
|
} |
|
|
if (gflag) { |
if (gflag) { |
gid = pw ? pw->pw_gid : rflag ? getgid() : getegid(); |
gid = pw ? pw->pw_gid : rflag ? getgid() : getegid(); |
if (nflag && (gr = getgrgid(gid))) |
if (nflag && (gr = getgrgid(gid))) |
|
|
(void)printf("groups\t"); |
(void)printf("groups\t"); |
group(NULL, 1); |
group(NULL, 1); |
} |
} |
|
if (pw != NULL && pw->pw_class != NULL && *pw->pw_class != '\0') |
|
(void)printf("class\t%s\n", pw->pw_class); |
} |
} |
|
|
void |
void |
|
|
(void)fprintf(stderr, "usage: whoami\n"); |
(void)fprintf(stderr, "usage: whoami\n"); |
} else { |
} else { |
(void)fprintf(stderr, "usage: id [user]\n"); |
(void)fprintf(stderr, "usage: id [user]\n"); |
|
(void)fprintf(stderr, " id -c [user]\n"); |
(void)fprintf(stderr, " id -G [-n] [user]\n"); |
(void)fprintf(stderr, " id -G [-n] [user]\n"); |
(void)fprintf(stderr, " id -g [-nr] [user]\n"); |
(void)fprintf(stderr, " id -g [-nr] [user]\n"); |
(void)fprintf(stderr, " id -p [user]\n"); |
(void)fprintf(stderr, " id -p [user]\n"); |