diff options
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; +} |