id.c (77314) | id.c (83452) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)id.c 8.2 (Berkeley) 2/16/94"; 43#endif 44static const char rcsid[] = | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)id.c 8.2 (Berkeley) 2/16/94"; 43#endif 44static const char rcsid[] = |
45 "$FreeBSD: head/usr.bin/id/id.c 77314 2001-05-28 06:14:48Z dd $"; | 45 "$FreeBSD: head/usr.bin/id/id.c 83452 2001-09-14 14:04:08Z ru $"; |
46#endif /* not lint */ 47 48#include <sys/param.h> 49 50#include <err.h> 51#include <grp.h> 52#include <pwd.h> 53#include <stdio.h> --- 6 unchanged lines hidden (view full) --- 60void pline __P((struct passwd *)); 61void pretty __P((struct passwd *)); 62void group __P((struct passwd *, int)); 63void usage __P((void)); 64void user __P((struct passwd *)); 65struct passwd * 66 who __P((char *)); 67 | 46#endif /* not lint */ 47 48#include <sys/param.h> 49 50#include <err.h> 51#include <grp.h> 52#include <pwd.h> 53#include <stdio.h> --- 6 unchanged lines hidden (view full) --- 60void pline __P((struct passwd *)); 61void pretty __P((struct passwd *)); 62void group __P((struct passwd *, int)); 63void usage __P((void)); 64void user __P((struct passwd *)); 65struct passwd * 66 who __P((char *)); 67 |
68int isgroups, iswhoami; 69 |
|
68int 69main(argc, argv) 70 int argc; 71 char *argv[]; 72{ 73 struct group *gr; 74 struct passwd *pw; 75 int Gflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; | 70int 71main(argc, argv) 72 int argc; 73 char *argv[]; 74{ 75 struct group *gr; 76 struct passwd *pw; 77 int Gflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; |
78 const char *myname; |
|
76 77 Gflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; | 79 80 Gflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; |
78 while ((ch = getopt(argc, argv, "PGgnpru")) != -1) | 81 82 myname = strrchr(argv[0], '/'); 83 myname = (myname != NULL) ? myname + 1 : argv[0]; 84 if (strcmp(myname, "groups") == 0) { 85 isgroups = 1; 86 Gflag = nflag = 1; 87 } 88 else if (strcmp(myname, "whoami") == 0) { 89 iswhoami = 1; 90 uflag = nflag = 1; 91 } 92 93 while ((ch = getopt(argc, argv, 94 (isgroups || iswhoami) ? "" : "PGgnpru")) != -1) |
79 switch(ch) { 80 case 'G': 81 Gflag = 1; 82 break; 83 case 'P': 84 Pflag = 1; 85 break; 86 case 'g': --- 13 unchanged lines hidden (view full) --- 100 break; 101 case '?': 102 default: 103 usage(); 104 } 105 argc -= optind; 106 argv += optind; 107 | 95 switch(ch) { 96 case 'G': 97 Gflag = 1; 98 break; 99 case 'P': 100 Pflag = 1; 101 break; 102 case 'g': --- 13 unchanged lines hidden (view full) --- 116 break; 117 case '?': 118 default: 119 usage(); 120 } 121 argc -= optind; 122 argv += optind; 123 |
124 if (iswhoami && argc > 0) 125 usage(); 126 |
|
108 switch(Gflag + Pflag + gflag + pflag + uflag) { 109 case 1: 110 break; 111 case 0: 112 if (!nflag && !rflag) 113 break; 114 /* FALLTHROUGH */ 115 default: --- 226 unchanged lines hidden (view full) --- 342 (long)pw->pw_change, (long)pw->pw_expire, pw->pw_gecos, 343 pw->pw_dir, pw->pw_shell); 344} 345 346 347void 348usage() 349{ | 127 switch(Gflag + Pflag + gflag + pflag + uflag) { 128 case 1: 129 break; 130 case 0: 131 if (!nflag && !rflag) 132 break; 133 /* FALLTHROUGH */ 134 default: --- 226 unchanged lines hidden (view full) --- 361 (long)pw->pw_change, (long)pw->pw_expire, pw->pw_gecos, 362 pw->pw_dir, pw->pw_shell); 363} 364 365 366void 367usage() 368{ |
350 (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", 351 "usage: id [user]", 352 " id -G [-n] [user]", 353 " id -P [user]", 354 " id -g [-nr] [user]", 355 " id -p [user]", 356 " id -u [-nr] [user]"); | 369 370 if (isgroups) 371 (void)fprintf(stderr, "usage: groups [user]\n"); 372 else if (iswhoami) 373 (void)fprintf(stderr, "usage: whoami\n"); 374 else 375 (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", 376 "usage: id [user]", 377 " id -G [-n] [user]", 378 " id -P [user]", 379 " id -g [-nr] [user]", 380 " id -p [user]", 381 " id -u [-nr] [user]"); |
357 exit(1); 358} | 382 exit(1); 383} |