[BACK]Return to id.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / id

Diff for /src/usr.bin/id/id.c between version 1.22 and 1.23

version 1.22, 2015/01/16 06:40:08 version 1.23, 2015/05/19 16:03:19
Line 38 
Line 38 
 #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 *);
Line 52 
Line 53 
 {  {
         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;
Line 72 
Line 73 
                 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;
Line 101 
Line 105 
         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:
Line 117 
Line 121 
   
         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)))
Line 190 
Line 204 
                 (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
Line 325 
Line 341 
                 (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");

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23