diff --git a/files/usr/share/man/id.man b/files/usr/share/man/id.man new file mode 100644 index 0000000..00c8e7c --- /dev/null +++ b/files/usr/share/man/id.man @@ -0,0 +1,15 @@ +SYNOPSIS + id [OPTIONS] + +DESCRIPTION + Print user and group information for the current process. + + The following options are available: + + -g, --group + print only the effective group ID + + -u, --user + print only the effective user ID + + --help display a help message and exit diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index cd15195..82c711f 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -1,5 +1,6 @@ # List of programs. set(PROGRAM_LIST + id.c stat.c false.c nice.c diff --git a/programs/id.c b/programs/id.c new file mode 100644 index 0000000..1189f41 --- /dev/null +++ b/programs/id.c @@ -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 +#include +#include + +int main(int argc, char **argv) +{ + if (argc == 1) { + printf("uid=%d gid=%d\n", getuid(), getgid()); + } 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", getuid()); + } else if (strncmp(argv[1], "-g", 2) == 0 || strncmp(argv[1], "--group", 7) == 0) { + printf("%d\n", getgid()); + } else { + printf("%s: invalid option '%s'\n", argv[0], argv[1]); + printf("Try '%s --help' for more information\n", argv[0]); + } + + return 0; +}