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

Appending the newline character '\n' is the right thing to do when you print a password to a tty or a text file.
But different tools process it differently. For example, cryptsetup strips the newline character, but systemd-cryptsetup with a password agent does not.
This commit allows to control the newline character with an option.
This commit is contained in:
Vladimir Stoiakin 2025-03-13 12:47:16 +03:00
parent 3196e47d51
commit 9bb6b3acdf
5 changed files with 16 additions and 7 deletions

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) {
/* 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
* leak via stale display buffers after we've exited */