Changeset 16 for trunk/software
- Timestamp:
- Nov 21, 2024, 12:09:38 PM (7 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/tty/readtty_command.c
r15 r16 10 10 #include <sys/ioctl.h> 11 11 #include <sys/select.h> 12 #include <pwd.h> 13 #include <grp.h> 12 14 13 15 volatile int quit; … … 79 81 if (argc != 2) 80 82 usage(); 83 if (*argv[1] == 'P') { 84 /* check if user is in group wheel or sudo */ 85 gid_t mygroups[64]; 86 int ngroups = 64; 87 struct passwd *pwp = getpwuid(getuid()); 88 if (pwp == NULL) { 89 err(1, "getpwuid(%d)", getuid()); 90 } 91 if ((i = getgrouplist(pwp->pw_name, pwp->pw_gid, mygroups, &ngroups)) 92 != 0) { 93 fprintf(stderr, "getgrouplist(%s,%d) fail: %d %d\n", 94 pwp->pw_name, pwp->pw_gid, i, ngroups); 95 exit(1); 96 } 97 for (i = 0; i < ngroups; i++) { 98 struct group *grpp = getgrgid(mygroups[i]); 99 if (grpp == NULL) { 100 err(1, "getgrgid(%d)", mygroups[i]); 101 } 102 if (strcmp(grpp->gr_name, "wheel") == 0 || 103 strcmp(grpp->gr_name, "sudo") == 0) { 104 break; 105 } 106 } 107 if (i == ngroups) { 108 errx(1, "command %s: permission denied", argv[1]); 109 } 110 } 81 111 82 112 d = open(argv[0], O_RDWR | O_NOCTTY | O_NONBLOCK, 0);
Note: See TracChangeset
for help on using the changeset viewer.