From 77be4a54bcc65b74c3b10f60a936a71117c3c274 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Mon, 9 Dec 2024 21:01:08 +0100 Subject: lock: Add lock utility --- userland/minibox/utilities/lock.c | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 userland/minibox/utilities/lock.c (limited to 'userland/minibox/utilities/lock.c') diff --git a/userland/minibox/utilities/lock.c b/userland/minibox/utilities/lock.c new file mode 100644 index 0000000..027038d --- /dev/null +++ b/userland/minibox/utilities/lock.c @@ -0,0 +1,44 @@ +#include "include.h" +#include +#include +#include +#include +#include + +int lock_main(int argc, char **argv) { + if (argc < 2) { + fprintf("Usage: %s ", argv[0] ? argv[0] : "lock"); + return 1; + } + char *password = argv[1]; + size_t buffer_length = strlen(password) + 1; + char *buffer = malloc(buffer_length); + + int should_exit = 0; + size_t i = 0; + for (;;) { + char c; + if (0 == read(STDIN_FILENO, &c, 1)) { + break; + } + if ('\n' == c) { + break; + } + if (i > buffer_length) { + should_exit = 1; + continue; + } + buffer[i] = c; + i++; + } + buffer[i] = '\0'; + + if (should_exit) { + return 1; + } + + if (0 != strcmp(password, buffer)) { + return 1; + } + return 0; +} -- cgit v1.2.3