id.c (159008) | id.c (162571) |
---|---|
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 --- 29 unchanged lines hidden (view full) --- 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)id.c 8.2 (Berkeley) 2/16/94"; 43#endif 44#endif /* not lint */ 45#include <sys/cdefs.h> | 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 --- 29 unchanged lines hidden (view full) --- 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)id.c 8.2 (Berkeley) 2/16/94"; 43#endif 44#endif /* not lint */ 45#include <sys/cdefs.h> |
46__FBSDID("$FreeBSD: head/usr.bin/id/id.c 159008 2006-05-28 12:32:30Z stefanf $"); | 46__FBSDID("$FreeBSD: head/usr.bin/id/id.c 162571 2006-09-23 12:30:31Z rwatson $"); |
47 48#include <sys/param.h> 49#include <sys/mac.h> 50 | 47 48#include <sys/param.h> 49#include <sys/mac.h> 50 |
51#ifdef USE_BSM_AUDIT 52#include <bsm/audit.h> 53#endif 54 |
|
51#include <err.h> 52#include <errno.h> 53#include <grp.h> 54#include <pwd.h> 55#include <stdio.h> 56#include <stdlib.h> 57#include <string.h> 58#include <unistd.h> 59 60void id_print(struct passwd *, int, int, int); 61void pline(struct passwd *); 62void pretty(struct passwd *); | 55#include <err.h> 56#include <errno.h> 57#include <grp.h> 58#include <pwd.h> 59#include <stdio.h> 60#include <stdlib.h> 61#include <string.h> 62#include <unistd.h> 63 64void id_print(struct passwd *, int, int, int); 65void pline(struct passwd *); 66void pretty(struct passwd *); |
67void auditid(void); |
|
63void group(struct passwd *, int); 64void maclabel(void); 65void usage(void); 66struct passwd *who(char *); 67 68int isgroups, iswhoami; 69 70int 71main(int argc, char *argv[]) 72{ 73 struct group *gr; 74 struct passwd *pw; 75 int Gflag, Mflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; | 68void group(struct passwd *, int); 69void maclabel(void); 70void usage(void); 71struct passwd *who(char *); 72 73int isgroups, iswhoami; 74 75int 76main(int argc, char *argv[]) 77{ 78 struct group *gr; 79 struct passwd *pw; 80 int Gflag, Mflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; |
81 int aflag; |
|
76 const char *myname; 77 78 Gflag = Mflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; | 82 const char *myname; 83 84 Gflag = Mflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; |
85 aflag = 0; |
|
79 80 myname = strrchr(argv[0], '/'); 81 myname = (myname != NULL) ? myname + 1 : argv[0]; 82 if (strcmp(myname, "groups") == 0) { 83 isgroups = 1; 84 Gflag = nflag = 1; 85 } 86 else if (strcmp(myname, "whoami") == 0) { 87 iswhoami = 1; 88 uflag = nflag = 1; 89 } 90 91 while ((ch = getopt(argc, argv, | 86 87 myname = strrchr(argv[0], '/'); 88 myname = (myname != NULL) ? myname + 1 : argv[0]; 89 if (strcmp(myname, "groups") == 0) { 90 isgroups = 1; 91 Gflag = nflag = 1; 92 } 93 else if (strcmp(myname, "whoami") == 0) { 94 iswhoami = 1; 95 uflag = nflag = 1; 96 } 97 98 while ((ch = getopt(argc, argv, |
92 (isgroups || iswhoami) ? "" : "PGMgnpru")) != -1) | 99 (isgroups || iswhoami) ? "" : "PGMagnpru")) != -1) |
93 switch(ch) { 94 case 'G': 95 Gflag = 1; 96 break; 97 case 'M': 98 Mflag = 1; 99 break; 100 case 'P': 101 Pflag = 1; 102 break; | 100 switch(ch) { 101 case 'G': 102 Gflag = 1; 103 break; 104 case 'M': 105 Mflag = 1; 106 break; 107 case 'P': 108 Pflag = 1; 109 break; |
110 case 'a': 111 aflag = 1; 112 break; |
|
103 case 'g': 104 gflag = 1; 105 break; 106 case 'n': 107 nflag = 1; 108 break; 109 case 'p': 110 pflag = 1; --- 9 unchanged lines hidden (view full) --- 120 usage(); 121 } 122 argc -= optind; 123 argv += optind; 124 125 if (iswhoami && argc > 0) 126 usage(); 127 | 113 case 'g': 114 gflag = 1; 115 break; 116 case 'n': 117 nflag = 1; 118 break; 119 case 'p': 120 pflag = 1; --- 9 unchanged lines hidden (view full) --- 130 usage(); 131 } 132 argc -= optind; 133 argv += optind; 134 135 if (iswhoami && argc > 0) 136 usage(); 137 |
128 switch(Gflag + Pflag + gflag + pflag + uflag) { | 138 switch(Gflag + Mflag + Pflag + aflag + gflag + pflag + uflag) { |
129 case 1: 130 break; 131 case 0: 132 if (!nflag && !rflag) 133 break; 134 /* FALLTHROUGH */ 135 default: 136 usage(); 137 } 138 139 pw = *argv ? who(*argv) : NULL; 140 141 if (Mflag && pw != NULL) 142 usage(); 143 | 139 case 1: 140 break; 141 case 0: 142 if (!nflag && !rflag) 143 break; 144 /* FALLTHROUGH */ 145 default: 146 usage(); 147 } 148 149 pw = *argv ? who(*argv) : NULL; 150 151 if (Mflag && pw != NULL) 152 usage(); 153 |
154#ifdef USE_BSM_AUDIT 155 if (aflag) { 156 auditid(); 157 exit(0); 158 } 159#else 160 if (aflag) 161 usage(); 162#endif 163 |
|
144 if (gflag) { 145 id = pw ? pw->pw_gid : rflag ? getgid() : getegid(); 146 if (nflag && (gr = getgrgid(id))) 147 (void)printf("%s\n", gr->gr_name); 148 else 149 (void)printf("%u\n", id); 150 exit(0); 151 } --- 121 unchanged lines hidden (view full) --- 273 fmt = ", %u"; 274 if ((gr = getgrgid(gid))) 275 printf("(%s)", gr->gr_name); 276 lastgid = gid; 277 } 278 printf("\n"); 279} 280 | 164 if (gflag) { 165 id = pw ? pw->pw_gid : rflag ? getgid() : getegid(); 166 if (nflag && (gr = getgrgid(id))) 167 (void)printf("%s\n", gr->gr_name); 168 else 169 (void)printf("%u\n", id); 170 exit(0); 171 } --- 121 unchanged lines hidden (view full) --- 293 fmt = ", %u"; 294 if ((gr = getgrgid(gid))) 295 printf("(%s)", gr->gr_name); 296 lastgid = gid; 297 } 298 printf("\n"); 299} 300 |
301#ifdef USE_BSM_AUDIT |
|
281void | 302void |
303auditid(void) 304{ 305 auditinfo_t auditinfo; 306 307 if (getaudit(&auditinfo) < 0) 308 err(-1, "getauditinfo"); 309 printf("auid=%d\n", auditinfo.ai_auid); 310 printf("mask.success=0x%08x\n", auditinfo.ai_mask.am_success); 311 printf("mask.failure=0x%08x\n", auditinfo.ai_mask.am_failure); 312 printf("termid.port=0x%08x\n", auditinfo.ai_termid.port); 313 printf("asid=%d\n", auditinfo.ai_asid); 314} 315#endif 316 317void |
|
282group(struct passwd *pw, int nflag) 283{ 284 struct group *gr; 285 int cnt, id, lastid, ngroups; 286 gid_t groups[NGROUPS + 1]; 287 const char *fmt; 288 289 if (pw) { --- 87 unchanged lines hidden (view full) --- 377usage(void) 378{ 379 380 if (isgroups) 381 (void)fprintf(stderr, "usage: groups [user]\n"); 382 else if (iswhoami) 383 (void)fprintf(stderr, "usage: whoami\n"); 384 else | 318group(struct passwd *pw, int nflag) 319{ 320 struct group *gr; 321 int cnt, id, lastid, ngroups; 322 gid_t groups[NGROUPS + 1]; 323 const char *fmt; 324 325 if (pw) { --- 87 unchanged lines hidden (view full) --- 413usage(void) 414{ 415 416 if (isgroups) 417 (void)fprintf(stderr, "usage: groups [user]\n"); 418 else if (iswhoami) 419 (void)fprintf(stderr, "usage: whoami\n"); 420 else |
385 (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", | 421 (void)fprintf(stderr, "%s\n%s\n%s\n%s%s\n%s\n%s\n%s\n", |
386 "usage: id [user]", 387 " id -G [-n] [user]", 388 " id -M", 389 " id -P [user]", | 422 "usage: id [user]", 423 " id -G [-n] [user]", 424 " id -M", 425 " id -P [user]", |
426#ifdef USE_BSM_AUDIT 427 " id -a\n", 428#else 429 "", 430#endif |
|
390 " id -g [-nr] [user]", 391 " id -p [user]", 392 " id -u [-nr] [user]"); 393 exit(1); 394} | 431 " id -g [-nr] [user]", 432 " id -p [user]", 433 " id -u [-nr] [user]"); 434 exit(1); 435} |