From f54118cd68329e1482c59734b665e6e66852b60a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 1 Apr 2019 19:04:13 +0200 Subject: [login] Add "--nouser" option to just ask for password --- src/hci/commands/login_cmd.c | 13 ++++++++++--- src/hci/tui/login_ui.c | 22 +++++++++++++++------- src/include/ipxe/login_ui.h | 2 +- 3 files changed, 26 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/hci/commands/login_cmd.c b/src/hci/commands/login_cmd.c index c9e196437..6ed76c6f2 100644 --- a/src/hci/commands/login_cmd.c +++ b/src/hci/commands/login_cmd.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -36,10 +37,16 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ /** "login" options */ -struct login_options {}; +struct login_options { + /** No Username */ + int nouser; +}; /** "login" option list */ -static struct option_descriptor login_opts[] = {}; +static struct option_descriptor login_opts[] = { + OPTION_DESC ( "nouser", 'n', no_argument, + struct login_options, nouser, parse_flag ), +}; /** "login" command descriptor */ static struct command_descriptor login_cmd = @@ -61,7 +68,7 @@ static int login_exec ( int argc, char **argv ) { return rc; /* Show login UI */ - if ( ( rc = login_ui() ) != 0 ) { + if ( ( rc = login_ui( opts.nouser ) ) != 0 ) { printf ( "Could not set credentials: %s\n", strerror ( rc ) ); return rc; diff --git a/src/hci/tui/login_ui.c b/src/hci/tui/login_ui.c index 3c55325d5..56fc2fa97 100644 --- a/src/hci/tui/login_ui.c +++ b/src/hci/tui/login_ui.c @@ -48,12 +48,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define EDITBOX_COL ( ( COLS / 2U ) - 10U ) #define EDITBOX_WIDTH 20U -int login_ui ( void ) { +int login_ui ( int nouser ) { char username[64]; char password[64]; struct edit_box username_box; struct edit_box password_box; - struct edit_box *current_box = &username_box; + struct edit_box *current_box = nouser ? &password_box : &username_box; int key; int rc = -EINPROGRESS; @@ -76,11 +76,15 @@ int login_ui ( void ) { color_set ( CPAIR_NORMAL, NULL ); erase(); attron ( A_BOLD ); - mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" ); + if ( ! nouser ) { + mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" ); + } mvprintw ( PASSWORD_LABEL_ROW, LABEL_COL, "Password:" ); attroff ( A_BOLD ); color_set ( CPAIR_EDIT, NULL ); - draw_editbox ( &username_box ); + if ( ! nouser ) { + draw_editbox ( &username_box ); + } draw_editbox ( &password_box ); /* Main loop */ @@ -94,11 +98,15 @@ int login_ui ( void ) { current_box = &password_box; break; case KEY_UP: - current_box = &username_box; + if ( ! nouser ) { + current_box = &username_box; + } break; case TAB: - current_box = ( ( current_box == &username_box ) ? - &password_box : &username_box ); + if ( ! nouser ) { + current_box = ( ( current_box == &username_box ) ? + &password_box : &username_box ); + } break; case KEY_ENTER: if ( current_box == &username_box ) { diff --git a/src/include/ipxe/login_ui.h b/src/include/ipxe/login_ui.h index 313e07349..07b1dd49e 100644 --- a/src/include/ipxe/login_ui.h +++ b/src/include/ipxe/login_ui.h @@ -9,6 +9,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); -extern int login_ui ( void ); +extern int login_ui ( int nouser ); #endif /* _IPXE_LOGIN_UI_H */ -- cgit v1.2.3-55-g7522