Merge pull request #36 from fischerling/implement-id-separation

Implement user and group ID separation
This commit is contained in:
Enrico Fraccaroli
2024-02-29 13:58:04 -05:00
committed by GitHub
15 changed files with 211 additions and 43 deletions
+1
View File
@@ -1,5 +1,6 @@
# List of programs.
set(PROGRAM_LIST
id.c
stat.c
false.c
nice.c
+30
View File
@@ -0,0 +1,30 @@
/// @file id.c
/// @brief
/// @copyright (c) 2024 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include <sys/unistd.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
if (argc == 1) {
printf("uid=%d gid=%d\n", geteuid(), getegid());
} else if (strncmp(argv[1], "--help", 6) == 0) {
printf("Usage: %s [OPTION]\n", argv[0]);
printf("Print user and group information\n\n");
printf(" -g, --group print only the effective group ID");
printf(" -u, --user print only the effective user ID");
printf(" --help display this help and exit");
} else if (strncmp(argv[1], "-u", 2) == 0 || strncmp(argv[1], "--user", 6) == 0) {
printf("%d\n", geteuid());
} else if (strncmp(argv[1], "-g", 2) == 0 || strncmp(argv[1], "--group", 7) == 0) {
printf("%d\n", getegid());
} else {
printf("%s: invalid option '%s'\n", argv[0], argv[1]);
printf("Try '%s --help' for more information\n", argv[0]);
}
return 0;
}