diff options
author | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2018-06-20 10:45:56 +1000 |
---|---|---|
committer | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2018-12-03 14:48:41 +1100 |
commit | 07f6db7fc29a93fae3213af18371cccb17e0276a (patch) | |
tree | e6306f75ae6cb0e863d9c096d0a7a56140657634 /ui/ncurses/nc-plugin.c | |
parent | 9011b958364f2af965a33681e7375f079ba75d02 (diff) | |
download | talos-petitboot-07f6db7fc29a93fae3213af18371cccb17e0276a.tar.gz talos-petitboot-07f6db7fc29a93fae3213af18371cccb17e0276a.zip |
ui/ncurses: Add nc-auth and authenticate when required.
When the user tries to perform actions that require authentication a new
subscreen 'nc-auth' is launched which accepts a password and will send
an authentication request before performing the action.
This also adds a button in nc-config which launches an nc-auth screen
allowing the user to set or change the system password.
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'ui/ncurses/nc-plugin.c')
-rw-r--r-- | ui/ncurses/nc-plugin.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/ui/ncurses/nc-plugin.c b/ui/ncurses/nc-plugin.c index ad8210f..f897cc8 100644 --- a/ui/ncurses/nc-plugin.c +++ b/ui/ncurses/nc-plugin.c @@ -40,6 +40,8 @@ extern const struct help_text plugin_help_text; +static void plugin_run_command(void *arg); + struct plugin_screen { struct nc_scr scr; struct cui *cui; @@ -48,6 +50,7 @@ struct plugin_screen { bool exit; bool show_help; + bool show_auth_run; bool need_redraw; void (*on_exit)(struct cui *); @@ -160,7 +163,7 @@ static void plugin_screen_process_key(struct nc_scr *scr, int key) cui_show_help(screen->cui, _("Petitboot Plugin"), &plugin_help_text); - } else if (handled) { + } else if (handled && (screen->cui->current == scr)) { pad_refresh(screen); } } @@ -178,6 +181,12 @@ static int plugin_screen_post(struct nc_scr *scr) } wrefresh(screen->scr.main_ncw); pad_refresh(screen); + + if (screen->show_auth_run) { + screen->show_auth_run = false; + plugin_run_command(screen); + } + return 0; } @@ -232,28 +241,21 @@ static void plugin_run_command(void *arg) talloc_free(cmd); } -/* Call pb-plugin to install a plugin specified by plugin_file */ -int plugin_install_plugin(struct pmenu_item *item) +static void plugin_run_command_check(void *arg) { - struct cui *cui = cui_from_item(item); - struct cui_opt_data *cod = cod_from_item(item); - int rc; - - assert(cui->current == &cui->plugin_menu->scr); - - nc_scr_status_printf(cui->current, _("Installing plugin %s"), - cod->pd->plugin_file); - - rc = cui_send_plugin_install(cui, cod->pd->plugin_file); + struct plugin_screen *screen = arg; - if (rc) { - pb_log("cui_send_plugin_install failed!\n"); - nc_scr_status_printf(cui->current, - _("Failed to send install request")); - } else - pb_debug("cui_send_plugin_install sent!\n"); + if (discover_client_authenticated(screen->cui->client)) { + plugin_run_command(screen); + return; + } - return rc; + /* + * Don't supply a callback as we want to handle running the command + * from the plugin screen. + */ + screen->show_auth_run = true; + cui_show_auth(screen->cui, screen->scr.main_ncw, false, NULL); } static void plugin_screen_setup_widgets(struct plugin_screen *screen) @@ -291,7 +293,7 @@ static void plugin_screen_setup_widgets(struct plugin_screen *screen) } screen->widgets.run_b = widget_new_button(set, 0, 0, 30, - _("Run selected command"), plugin_run_command, screen); + _("Run selected command"), plugin_run_command_check, screen); } static int layout_pair(struct plugin_screen *screen, int y, |