diff options
author | Anton Kling <anton@kling.gg> | 2024-12-09 21:01:08 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-12-09 21:01:08 +0100 |
commit | 77be4a54bcc65b74c3b10f60a936a71117c3c274 (patch) | |
tree | c56159c89379cbcc1f3a6146be507e7cc25132d0 /userland/minibox/utilities/lock.c | |
parent | 0d2f1ff5ca366f9ba18a349f5e06295f264c5da4 (diff) |
lock: Add lock utility
Diffstat (limited to 'userland/minibox/utilities/lock.c')
-rw-r--r-- | userland/minibox/utilities/lock.c | 44 |
1 files changed, 44 insertions, 0 deletions
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 <dirent.h> +#include <fcntl.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +int lock_main(int argc, char **argv) { + if (argc < 2) { + fprintf("Usage: %s <password>", 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; +} |