From 30189186e9ac5925ac62e82df4fc47b3ed9b6228 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Sat, 29 Oct 2022 20:13:30 -0400 Subject: [PATCH] Utilities: Add nologin application This adds the `nologin` application to the system. This application will look for `/etc/nologin`. If it is present, it will display the message in the file. Otherwise, it will display an error about the current account being unavailable. --- Userland/Utilities/CMakeLists.txt | 1 + Userland/Utilities/nologin.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Userland/Utilities/nologin.cpp diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 634f4832e8b..6f04ebb49df 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -165,6 +165,7 @@ target_link_libraries(mount LibMain) target_link_libraries(nc LibMain) target_link_libraries(netstat LibMain) target_link_libraries(nl LibMain) +target_link_libraries(nologin LibMain) target_link_libraries(notify LibGUI LibMain) target_link_libraries(nproc LibMain) target_link_libraries(ntpquery LibMain) diff --git a/Userland/Utilities/nologin.cpp b/Userland/Utilities/nologin.cpp new file mode 100644 index 00000000000..9e58726712b --- /dev/null +++ b/Userland/Utilities/nologin.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022, Beckett Normington + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +ErrorOr serenity_main(Main::Arguments) +{ + TRY(Core::System::pledge("stdio rpath"sv)); + + auto file_or_error = Core::Stream::File::open("/etc/nologin"sv, Core::Stream::OpenMode::Read); + if (file_or_error.is_error()) { + outln("This account is currently not available."sv); + } else { + auto message_from_file = TRY(file_or_error.value()->read_all()); + out(message_from_file); + } + + return 1; +}