]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
Add display_prompt function
authorMateusz Piórkowski <mati7337@protonmail.ch>
Fri, 4 Mar 2022 18:15:23 +0000 (19:15 +0100)
committerMateusz Piórkowski <mati7337@protonmail.ch>
Fri, 25 Mar 2022 18:48:26 +0000 (19:48 +0100)
Add display_prompt function which will be called for both passwords
and questions. This will make it possible to get a plaintext password
string.
SetDisplayPromptFunction will make it possible to set this callback
from a theme script.

Closes #150

src/libply-splash-core/ply-boot-splash-plugin.h
src/libply-splash-core/ply-boot-splash.c
src/libply-splash-core/ply-boot-splash.h
src/main.c
src/plugins/splash/script/plugin.c
src/plugins/splash/script/script-lib-plymouth.c
src/plugins/splash/script/script-lib-plymouth.h

index c80770c4152e8c20d91f74bc34bc10113842dc3b..69f34e15a33c8a07c41162e275bbd057e35729da 100644 (file)
@@ -95,6 +95,10 @@ typedef struct
                                  const char               *entry_text);
         void (*become_idle)(ply_boot_splash_plugin_t *plugin,
                             ply_trigger_t            *idle_trigger);
+        void (*display_prompt)(ply_boot_splash_plugin_t *plugin,
+                               const char               *prompt,
+                               const char               *entry_text,
+                               bool                      is_secret);
 } ply_boot_splash_plugin_interface_t;
 
 #endif /* PLY_BOOT_SPLASH_PLUGIN_H */
index 9549ecccb4080660048373e2ad76d392b4cc0648..d5cbf1faf454fa7ee9589af1e20aacba848cf3e8 100644 (file)
@@ -640,6 +640,18 @@ void ply_boot_splash_display_question (ply_boot_splash_t *splash,
                 splash->plugin_interface->display_question (splash->plugin, prompt, entry_text);
 }
 
+void ply_boot_splash_display_prompt (ply_boot_splash_t *splash,
+                                     const char        *prompt,
+                                     const char        *entry_text,
+                                     bool               is_secret)
+{
+        assert (splash != NULL);
+        assert (splash->plugin_interface != NULL);
+        assert (splash->plugin != NULL);
+        if (splash->plugin_interface->display_prompt != NULL)
+                splash->plugin_interface->display_prompt (splash->plugin, prompt, entry_text, is_secret);
+}
+
 
 
 void
index 0bdbe9635c32c5e66db54bf219cc1bd5e5b8848d..1bb0c6ba0110c68ba81ca034eaaf1e35340de079 100644 (file)
@@ -82,6 +82,10 @@ void ply_boot_splash_display_password (ply_boot_splash_t *splash,
 void ply_boot_splash_display_question (ply_boot_splash_t *splash,
                                        const char        *prompt,
                                        const char        *entry_text);
+void ply_boot_splash_display_prompt (ply_boot_splash_t *splash,
+                                     const char        *prompt,
+                                     const char        *entry_text,
+                                     bool               is_secret);
 void ply_boot_splash_attach_to_event_loop (ply_boot_splash_t *splash,
                                            ply_event_loop_t  *loop);
 void ply_boot_splash_attach_progress (ply_boot_splash_t *splash,
index bedab7d39cdf2ced992107fb48f4a2b83ca53287..255a86a8b22af5c7481aa85890970ae52acde277 100644 (file)
@@ -1462,10 +1462,18 @@ update_display (state_t *state)
                         ply_boot_splash_display_password (state->boot_splash,
                                                           entry_trigger->prompt,
                                                           bullets);
+                        ply_boot_splash_display_prompt (state->boot_splash,
+                                                        entry_trigger->prompt,
+                                                        ply_buffer_get_bytes (state->entry_buffer),
+                                                        true);
                 } else if (entry_trigger->type == PLY_ENTRY_TRIGGER_TYPE_QUESTION) {
                         ply_boot_splash_display_question (state->boot_splash,
                                                           entry_trigger->prompt,
                                                           ply_buffer_get_bytes (state->entry_buffer));
+                        ply_boot_splash_display_prompt (state->boot_splash,
+                                                        entry_trigger->prompt,
+                                                        ply_buffer_get_bytes (state->entry_buffer),
+                                                        false);
                 } else {
                         ply_trace ("unkown entry type");
                 }
index 492f4937dfb1b7b61da2e361f6d19fabe3385034..a55b9c2008d99fe9d5f7418827d1d2353ac285a9 100644 (file)
@@ -509,6 +509,21 @@ display_question (ply_boot_splash_plugin_t *plugin,
         unpause_displays (plugin);
 }
 
+static void
+display_prompt (ply_boot_splash_plugin_t *plugin,
+                const char               *prompt,
+                const char               *entry_text,
+                bool                      is_secret)
+{
+        pause_displays (plugin);
+        script_lib_plymouth_on_display_prompt (plugin->script_state,
+                                               plugin->script_plymouth_lib,
+                                               prompt,
+                                               entry_text,
+                                               is_secret);
+        unpause_displays (plugin);
+}
+
 static void
 display_message (ply_boot_splash_plugin_t *plugin,
                  const char               *message)
@@ -552,6 +567,7 @@ ply_boot_splash_plugin_get_interface (void)
                 .display_normal       = display_normal,
                 .display_password     = display_password,
                 .display_question     = display_question,
+                .display_prompt       = display_prompt,
                 .display_message      = display_message,
                 .hide_message         = hide_message,
         };
index 97ac10eddc25bc4b00c23e9f6ca28c7648c452a2..6bef52a888c869ffccfafdd2ca0cab8d748804b2 100644 (file)
@@ -104,6 +104,7 @@ script_lib_plymouth_data_t *script_lib_plymouth_setup (script_state_t        *st
         data->script_display_normal_func = script_obj_new_null ();
         data->script_display_password_func = script_obj_new_null ();
         data->script_display_question_func = script_obj_new_null ();
+        data->script_display_prompt_func = script_obj_new_null ();
         data->script_display_message_func = script_obj_new_null ();
         data->script_hide_message_func = script_obj_new_null ();
         data->script_quit_func = script_obj_new_null ();
@@ -166,6 +167,12 @@ script_lib_plymouth_data_t *script_lib_plymouth_setup (script_state_t        *st
                                     &data->script_display_question_func,
                                     "function",
                                     NULL);
+        script_add_native_function (plymouth_hash,
+                                    "SetDisplayPromptFunction",
+                                    plymouth_set_function,
+                                    &data->script_display_prompt_func,
+                                    "function",
+                                    NULL);
         script_add_native_function (plymouth_hash,
                                     "SetDisplayMessageFunction",
                                     plymouth_set_function,
@@ -215,6 +222,7 @@ void script_lib_plymouth_destroy (script_lib_plymouth_data_t *data)
         script_obj_unref (data->script_display_normal_func);
         script_obj_unref (data->script_display_password_func);
         script_obj_unref (data->script_display_question_func);
+        script_obj_unref (data->script_display_prompt_func);
         script_obj_unref (data->script_display_message_func);
         script_obj_unref (data->script_hide_message_func);
         script_obj_unref (data->script_quit_func);
@@ -342,6 +350,29 @@ void script_lib_plymouth_on_display_question (script_state_t             *state,
         script_obj_unref (ret.object);
 }
 
+void script_lib_plymouth_on_display_prompt (script_state_t             *state,
+                                            script_lib_plymouth_data_t *data,
+                                            const char                 *prompt,
+                                            const char                 *entry_text,
+                                            bool                        is_secret)
+{
+        script_obj_t *prompt_obj = script_obj_new_string (prompt);
+        script_obj_t *entry_text_obj = script_obj_new_string (entry_text);
+        script_obj_t *is_secret_obj = script_obj_new_number (is_secret);
+        script_return_t ret = script_execute_object (state,
+                                                     data->script_display_prompt_func,
+                                                     NULL,
+                                                     prompt_obj,
+                                                     entry_text_obj,
+                                                     is_secret_obj,
+                                                     NULL);
+
+        script_obj_unref (prompt_obj);
+        script_obj_unref (entry_text_obj);
+        script_obj_unref (is_secret_obj);
+        script_obj_unref (ret.object);
+}
+
 void script_lib_plymouth_on_display_message (script_state_t             *state,
                                              script_lib_plymouth_data_t *data,
                                              const char                 *message)
index 0d3fe66bd3378507dfabe02221cf4f92e7fa258f..5a7f38a8ced75d57d07f2af2b8a6773a275cf9b6 100644 (file)
@@ -36,6 +36,7 @@ typedef struct
         script_obj_t          *script_display_normal_func;
         script_obj_t          *script_display_password_func;
         script_obj_t          *script_display_question_func;
+        script_obj_t          *script_display_prompt_func;
         script_obj_t          *script_display_message_func;
         script_obj_t          *script_hide_message_func;
         script_obj_t          *script_quit_func;
@@ -73,6 +74,11 @@ void script_lib_plymouth_on_display_question (script_state_t             *state,
                                               script_lib_plymouth_data_t *data,
                                               const char                 *prompt,
                                               const char                 *entry_text);
+void script_lib_plymouth_on_display_prompt (script_state_t             *state,
+                                            script_lib_plymouth_data_t *data,
+                                            const char                 *prompt,
+                                            const char                 *entry_text,
+                                            bool                        is_secret);
 void script_lib_plymouth_on_display_message (script_state_t             *state,
                                              script_lib_plymouth_data_t *data,
                                              const char                 *new_message);