[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.19 and 1.20

version 1.19, 2009/10/27 23:59:39 version 1.20, 2013/09/06 19:48:46
Line 31 
Line 31 
   
 #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>
Line 38 
Line 39 
 #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 *);
Line 56 
Line 56 
         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;
Line 85 
Line 102 
         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:
Line 96 
Line 113 
                 usage();                  usage();
         }          }
   
           if (strcmp(opts, "") != 0 && argc > 1)
                   usage();
   
         pw = *argv ? who(*argv) : NULL;          pw = *argv ? who(*argv) : NULL;
   
         if (gflag) {          if (gflag) {
Line 155 
Line 175 
                         (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);
Line 302 
Line 322 
 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);
 }  }

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20