Merge branch 'newline' into 'master'

unl0kr: add the CLI option to avoid suffixing a password with a newline character

Closes #44

See merge request postmarketOS/buffybox!40
This commit is contained in:
Johannes Marbach
2025-03-16 18:32:49 +00:00
5 changed files with 16 additions and 7 deletions

View File

@@ -44,6 +44,8 @@ password is printed to STDOUT. All other output happens on STDERR.
* 3 - counterclockwise orientation (270 degrees) * 3 - counterclockwise orientation (270 degrees)
*-h, --help* *-h, --help*
Print this message and exit. Print this message and exit.
*-n*
Do not append a newline character to a password.
*-v, --verbose* *-v, --verbose*
Enable more detailed logging output on STDERR. Enable more detailed logging output on STDERR.
*-V, --version* *-V, --version*

View File

@@ -45,6 +45,7 @@ static void init_opts(ul_cli_opts *opts) {
opts->y_offset = 0; opts->y_offset = 0;
opts->dpi = 0; opts->dpi = 0;
opts->rotation = LV_DISPLAY_ROTATION_0; opts->rotation = LV_DISPLAY_ROTATION_0;
opts->newline = true;
opts->verbose = false; opts->verbose = false;
} }
@@ -77,6 +78,7 @@ static void print_usage() {
" * 2 - upside down orientation (180 degrees)\n" " * 2 - upside down orientation (180 degrees)\n"
" * 3 - counterclockwise orientation (270 degrees)\n" " * 3 - counterclockwise orientation (270 degrees)\n"
" -h, --help Print this message and exit\n" " -h, --help Print this message and exit\n"
" -n Do not append a newline character to a password\n"
" -v, --verbose Enable more detailed logging output on STDERR\n" " -v, --verbose Enable more detailed logging output on STDERR\n"
" -V, --version Print the unl0kr version and exit\n"); " -V, --version Print the unl0kr version and exit\n");
/*-------------------------------- 78 CHARS --------------------------------*/ /*-------------------------------- 78 CHARS --------------------------------*/
@@ -103,7 +105,7 @@ void ul_cli_parse_opts(int argc, char *argv[], ul_cli_opts *opts) {
int opt, index = 0; int opt, index = 0;
while ((opt = getopt_long(argc, argv, "C:g:d:r:hvV", long_opts, &index)) != -1) { while ((opt = getopt_long(argc, argv, "C:g:d:r:hnvV", long_opts, &index)) != -1) {
switch (opt) { switch (opt) {
case 'C': case 'C':
opts->config_files = realloc(opts->config_files, (opts->num_config_files + 1) * sizeof(char *)); opts->config_files = realloc(opts->config_files, (opts->num_config_files + 1) * sizeof(char *));
@@ -153,6 +155,9 @@ void ul_cli_parse_opts(int argc, char *argv[], ul_cli_opts *opts) {
case 'h': case 'h':
print_usage(); print_usage();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'n':
opts->newline = false;
break;
case 'v': case 'v':
opts->verbose = true; opts->verbose = true;
break; break;

View File

@@ -30,6 +30,8 @@ typedef struct {
int dpi; int dpi;
/* Display rotation */ /* Display rotation */
lv_display_rotation_t rotation; lv_display_rotation_t rotation;
/* If true, append a newline character to a password */
bool newline;
/* Verbose mode. If true, provide more detailed logging output on STDERR. */ /* Verbose mode. If true, provide more detailed logging output on STDERR. */
bool verbose; bool verbose;
} ul_cli_opts; } ul_cli_opts;

View File

@@ -337,7 +337,7 @@ static void textarea_ready_cb(lv_event_t *event) {
static void print_password_and_exit(lv_obj_t *textarea) { static void print_password_and_exit(lv_obj_t *textarea) {
/* Print the password to STDOUT */ /* Print the password to STDOUT */
printf("%s\n", lv_textarea_get_text(textarea)); printf(cli_opts.newline? "%s\n" : "%s", lv_textarea_get_text(textarea));
/* Clear the screen so that when the password field was unobscured, it cannot /* Clear the screen so that when the password field was unobscured, it cannot
* leak via stale display buffers after we've exited */ * leak via stale display buffers after we've exited */

View File

@@ -418,7 +418,7 @@ int exec_unl0kr(char** ret_password)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
execl(UNL0KR_BINARY, "unl0kr", (char*) 0); execl(UNL0KR_BINARY, UNL0KR_BINARY, "-n", (char*) 0);
perror("exec() is failed"); perror("exec() is failed");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);