From bb4d81a4fae4069b3aebc4a13a92bdf6cb2547f1 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 11 Jun 2023 22:32:14 +0300 Subject: [PATCH] Userspace: Add basic id that prints {,e}{uid,gid} of the current proc --- userspace/CMakeLists.txt | 1 + userspace/id/CMakeLists.txt | 16 ++++++++++++++++ userspace/id/main.cpp | 7 +++++++ 3 files changed, 24 insertions(+) create mode 100644 userspace/id/CMakeLists.txt create mode 100644 userspace/id/main.cpp diff --git a/userspace/CMakeLists.txt b/userspace/CMakeLists.txt index f4deddbf..0ce1bf16 100644 --- a/userspace/CMakeLists.txt +++ b/userspace/CMakeLists.txt @@ -5,6 +5,7 @@ project(userspace CXX) set(USERSPACE_PROJECTS cat echo + id init ls Shell diff --git a/userspace/id/CMakeLists.txt b/userspace/id/CMakeLists.txt new file mode 100644 index 00000000..1cf2c33d --- /dev/null +++ b/userspace/id/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.26) + +project(id CXX) + +set(SOURCES + main.cpp +) + +add_executable(id ${SOURCES}) +target_compile_options(id PUBLIC -O2 -g) +target_link_libraries(id PUBLIC libc) + +add_custom_target(id-install + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/id ${BANAN_BIN}/ + DEPENDS id +) diff --git a/userspace/id/main.cpp b/userspace/id/main.cpp new file mode 100644 index 00000000..567be574 --- /dev/null +++ b/userspace/id/main.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main() +{ + printf("uid %u, gid %u, euid %u, egid %u\n", getuid(), getgid(), geteuid(), getegid()); +}