[vlc-devel] [PATCH 02/13] dialog: add b_store_secure to vlc_dialog_wait_login

Thomas Guillem thomas at gllm.fr
Wed Feb 24 14:25:11 CET 2016


In order to signal the login dialog if the keystore is secure.
---
 include/vlc_dialog.h                 | 14 ++++++++------
 lib/dialog.c                         |  2 +-
 modules/gui/macosx/coredialogs.m     |  8 +++++---
 modules/gui/qt4/dialogs/external.cpp | 11 ++++++-----
 modules/gui/qt4/dialogs/external.hpp |  6 +++---
 src/interface/dialog.c               | 17 ++++++++++-------
 src/misc/keystore.c                  |  4 +++-
 test/src/interface/dialog.c          |  6 +++---
 8 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/include/vlc_dialog.h b/include/vlc_dialog.h
index 038e300..6bb21c8 100644
--- a/include/vlc_dialog.h
+++ b/include/vlc_dialog.h
@@ -96,6 +96,7 @@ vlc_dialog_display_error_va(vlc_object_t *p_obj, const char *psz_title,
  * @param ppsz_password a pointer to the password provided by the user, it must
  * be freed with free() on success
  * @param p_store a pointer to the store answer provided by the user (optional)
+ * @param b_store_secure true if the keystore is secure
  * @param psz_default_username default user name proposed
  * @param psz_title title of the login dialog
  * @param psz_fmt format string for the login message
@@ -104,12 +105,12 @@ vlc_dialog_display_error_va(vlc_object_t *p_obj, const char *psz_title,
  */
 VLC_API int
 vlc_dialog_wait_login(vlc_object_t *p_obj, char **ppsz_username,
-                      char **ppsz_password, bool *p_store,
+                      char **ppsz_password, bool *p_store, bool b_store_secure,
                       const char *psz_default_username,
                       const char *psz_title, const char *psz_fmt, ...)
-                      VLC_FORMAT(7,8);
-#define vlc_dialog_wait_login(a, b, c, d, e, f, g, ...) \
-    vlc_dialog_wait_login(VLC_OBJECT(a), b, c, d, e, f, g, ##__VA_ARGS__)
+                      VLC_FORMAT(8,9);
+#define vlc_dialog_wait_login(a, b, c, d, e, f, g, h, ...) \
+    vlc_dialog_wait_login(VLC_OBJECT(a), b, c, d, e, f, g, h, ##__VA_ARGS__)
 
 /**
  * Requests an user name and a password
@@ -119,7 +120,7 @@ vlc_dialog_wait_login(vlc_object_t *p_obj, char **ppsz_username,
  */
 VLC_API int
 vlc_dialog_wait_login_va(vlc_object_t *p_obj, char **ppsz_username,
-                         char **ppsz_password, bool *p_store,
+                         char **ppsz_password, bool *p_store, bool b_store_secure,
                          const char *psz_default_username,
                          const char *psz_title, const char *psz_fmt, va_list ap);
 
@@ -299,12 +300,13 @@ typedef struct vlc_dialog_cbs
      * @param psz_default_username user name that should be set on the user form
      * @param b_ask_store if true, ask the user if he wants to save the
      * credentials
+     @ @param b_store_secure if true, the store is secure
      * @param p_data opaque pointer for the callback
      */
     void (*pf_display_login)(vlc_dialog_id *p_id, const char *psz_title,
                              const char *psz_text,
                              const char *psz_default_username,
-                             bool b_ask_store, void *p_data);
+                             bool b_ask_store, bool b_store_secure, void *p_data);
 
     /**
      * Called when a question dialog needs to be displayed
diff --git a/lib/dialog.c b/lib/dialog.c
index d5d986a..1eeffc4 100644
--- a/lib/dialog.c
+++ b/lib/dialog.c
@@ -56,7 +56,7 @@ display_error_cb(const char *psz_title, const char *psz_text, void *p_data)
 static void
 display_login_cb(vlc_dialog_id *p_id, const char *psz_title,
                  const char *psz_text, const char *psz_default_username,
-                 bool b_ask_store, void *p_data)
+                 bool b_ask_store, bool b_store_secure, void *p_data)
 {
     libvlc_instance_t *p_instance = p_data;
 
diff --git a/modules/gui/macosx/coredialogs.m b/modules/gui/macosx/coredialogs.m
index a782088..3fa8ac4 100644
--- a/modules/gui/macosx/coredialogs.m
+++ b/modules/gui/macosx/coredialogs.m
@@ -61,7 +61,7 @@ static void displayLoginCallback(vlc_dialog_id *p_id,
                                  const char *psz_title,
                                  const char *psz_text,
                                  const char *psz_default_username,
-                                 bool b_ask_store,
+                                 bool b_ask_store, bool b_store_secure,
                                  void *p_data)
 {
     @autoreleasepool {
@@ -71,7 +71,8 @@ static void displayLoginCallback(vlc_dialog_id *p_id,
                                                       toNSStr(psz_title),
                                                       toNSStr(psz_text),
                                                       toNSStr(psz_default_username),
-                                                      @(b_ask_store)]
+                                                      @(b_ask_store),
+                                                      @(b_store_secure)]
                                       waitUntilDone:NO];
     }
 }
@@ -212,7 +213,8 @@ static void updateProgressCallback(vlc_dialog_id *p_id,
     [authenticationLoginTextField setStringValue:dialogData[3]];
     [authenticationPasswordTextField setStringValue:@""];
 
-    authenticationStorePasswordCheckbox.hidden = ![dialogData[4] boolValue];
+    authenticationStorePasswordCheckbox.hidden = ![dialogData[4] boolValue] ||
+                                                 ![dialogData[5] boolValue];
     authenticationStorePasswordCheckbox.state = NSOffState;
 
     [authenticationWindow center];
diff --git a/modules/gui/qt4/dialogs/external.cpp b/modules/gui/qt4/dialogs/external.cpp
index a56d6b9..fb56083 100644
--- a/modules/gui/qt4/dialogs/external.cpp
+++ b/modules/gui/qt4/dialogs/external.cpp
@@ -53,7 +53,7 @@ DialogHandler::DialogHandler (intf_thread_t *p_intf, QObject *_parent)
             this, displayError(const QString &, const QString &));
 
     CONNECT(this, loginDisplayed(vlc_dialog_id *, const QString &,
-                                 const QString &, const QString &, bool),
+                                 const QString &, const QString &, bool, bool),
             this, displayLogin(vlc_dialog_id *, const QString &, const QString &,
                                const QString &, bool));
 
@@ -96,7 +96,7 @@ void
 DialogHandler::displayLoginCb(vlc_dialog_id *p_id, const char *psz_title,
                               const char *psz_text,
                               const char *psz_default_username,
-                              bool b_ask_store, void *p_data)
+                              bool b_ask_store, bool b_store_secure, void *p_data)
 {
     DialogHandler *self =  static_cast<DialogHandler *>(p_data);
     const QString title = qfu(psz_title);
@@ -106,7 +106,7 @@ DialogHandler::displayLoginCb(vlc_dialog_id *p_id, const char *psz_title,
         psz_default_username != NULL ? qfu(psz_default_username) : QString();
 
     emit self->loginDisplayed(p_id, title, text, defaultUsername,
-                              b_ask_store);
+                              b_ask_store, b_store_secure);
 }
 
 void
@@ -185,7 +185,7 @@ void DialogHandler::displayError(const QString &title, const QString &text)
 void DialogHandler::displayLogin(vlc_dialog_id *p_id, const QString &title,
                                  const QString &text,
                                  const QString &defaultUsername,
-                                 bool b_ask_store)
+                                 bool b_ask_store, bool b_store_secure)
 {
     QDialog *dialog = new QDialog();
     QLayout *layout = new QVBoxLayout (dialog);
@@ -212,7 +212,8 @@ void DialogHandler::displayLogin(vlc_dialog_id *p_id, const QString &title,
     grid->addWidget (passLine, 2, 1);
 
     QCheckBox *checkbox = NULL;
-    if (b_ask_store)
+    /* Don't try to store passwords on non secure keystores */
+    if (b_ask_store && b_store_secure)
     {
         checkbox = new QCheckBox;
         checkbox->setChecked (getSettings()->value ("store_password", true).toBool ());
diff --git a/modules/gui/qt4/dialogs/external.hpp b/modules/gui/qt4/dialogs/external.hpp
index 2808819..61ff9db 100644
--- a/modules/gui/qt4/dialogs/external.hpp
+++ b/modules/gui/qt4/dialogs/external.hpp
@@ -49,7 +49,7 @@ signals:
     void errorDisplayed(const QString &title, const QString &text);
     void loginDisplayed(vlc_dialog_id *p_id, const QString &title,
                         const QString &text, const QString &defaultUsername,
-                        bool b_ask_store);
+                        bool b_ask_store, bool b_store_secure);
     void questionDisplayed(vlc_dialog_id *p_id, const QString &title,
                            const QString &text, int i_type,
                            const QString &cancel, const QString &action1,
@@ -64,7 +64,7 @@ private slots:
     void displayError(const QString &title, const QString &text);
     void displayLogin(vlc_dialog_id *p_id, const QString &title,
                       const QString &text, const QString &defaultUsername,
-                      bool b_ask_store);
+                      bool b_ask_store, bool b_store_secure);
     void displayQuestion(vlc_dialog_id *p_id, const QString &title,
                          const QString &text, int i_type,
                          const QString &cancel, const QString &action1,
@@ -80,7 +80,7 @@ private:
 
     static void displayErrorCb(const char *, const char *, void *);
     static void displayLoginCb(vlc_dialog_id *, const char *, const char *,
-                               const char *, bool, void *);
+                               const char *, bool, bool, void *);
     static void displayQuestionCb(vlc_dialog_id *, const char *, const char *,
                                   vlc_dialog_question_type, const char *, 
                                   const char *, const char *, void *);
diff --git a/src/interface/dialog.c b/src/interface/dialog.c
index 9968469..6ee60e9 100644
--- a/src/interface/dialog.c
+++ b/src/interface/dialog.c
@@ -394,7 +394,8 @@ vlc_dialog_display_error(vlc_object_t *p_obj, const char *psz_title,
 static int
 dialog_display_login_va(vlc_dialog_provider *p_provider, vlc_dialog_id **pp_id,
                         const char *psz_default_username, bool b_ask_store,
-                        const char *psz_title, const char *psz_fmt, va_list ap)
+                        bool b_store_secure, const char *psz_title,
+                        const char *psz_fmt, va_list ap)
 {
     vlc_mutex_lock(&p_provider->lock);
     if (p_provider->cbs.pf_display_login == NULL
@@ -420,7 +421,7 @@ dialog_display_login_va(vlc_dialog_provider *p_provider, vlc_dialog_id **pp_id,
     }
     p_provider->cbs.pf_display_login(p_id, psz_title, psz_text,
                                      psz_default_username, b_ask_store,
-                                     p_provider->p_cbs_data);
+                                     b_store_secure, p_provider->p_cbs_data);
     free(psz_text);
     vlc_mutex_unlock(&p_provider->lock);
     *pp_id = p_id;
@@ -430,7 +431,7 @@ dialog_display_login_va(vlc_dialog_provider *p_provider, vlc_dialog_id **pp_id,
 
 int
 vlc_dialog_wait_login_va(vlc_object_t *p_obj,  char **ppsz_username,
-                         char **ppsz_password, bool *p_store,
+                         char **ppsz_password, bool *p_store, bool b_store_secure,
                          const char *psz_default_username,
                          const char *psz_title, const char *psz_fmt, va_list ap)
 {
@@ -443,7 +444,8 @@ vlc_dialog_wait_login_va(vlc_object_t *p_obj,  char **ppsz_username,
 
     vlc_dialog_id *p_id;
     int i_ret = dialog_display_login_va(p_provider, &p_id, psz_default_username,
-                                        p_store != NULL, psz_title, psz_fmt, ap);
+                                        p_store != NULL, b_store_secure,
+                                        psz_title, psz_fmt, ap);
     if (i_ret < 0 || p_id == NULL)
         return i_ret;
 
@@ -463,7 +465,7 @@ vlc_dialog_wait_login_va(vlc_object_t *p_obj,  char **ppsz_username,
 #undef vlc_dialog_wait_login
 int
 vlc_dialog_wait_login(vlc_object_t *p_obj,  char **ppsz_username,
-                      char **ppsz_password, bool *p_store,
+                      char **ppsz_password, bool *p_store, bool b_store_secure,
                       const char *psz_default_username, const char *psz_title,
                       const char *psz_fmt, ...)
 {
@@ -471,8 +473,9 @@ vlc_dialog_wait_login(vlc_object_t *p_obj,  char **ppsz_username,
     va_list ap;
     va_start(ap, psz_fmt);
     int i_ret = vlc_dialog_wait_login_va(p_obj, ppsz_username, ppsz_password,
-                                         p_store,psz_default_username,
-                                         psz_title, psz_fmt, ap);
+                                         p_store, b_store_secure,
+                                         psz_default_username, psz_title,
+                                         psz_fmt, ap);
     va_end(ap);
     return i_ret;
 }
diff --git a/src/misc/keystore.c b/src/misc/keystore.c
index e0f9bba..3a0eafb 100644
--- a/src/misc/keystore.c
+++ b/src/misc/keystore.c
@@ -400,10 +400,12 @@ vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
             va_start(ap, psz_dialog_fmt);
             bool *p_store = p_credential->p_keystore != NULL ?
                             &p_credential->b_store : NULL;
+            bool b_secure = p_credential->p_keystore != NULL ?
+                            p_credential->p_keystore->b_secure : false;
             int i_ret =
                 vlc_dialog_wait_login_va(p_parent,
                                          &psz_dialog_username,
-                                         &psz_dialog_password, p_store,
+                                         &psz_dialog_password, p_store, b_secure,
                                          p_credential->psz_username,
                                          psz_dialog_title, psz_dialog_fmt, ap);
             va_end(ap);
diff --git a/test/src/interface/dialog.c b/test/src/interface/dialog.c
index 12a77a5..7923b0b 100644
--- a/test/src/interface/dialog.c
+++ b/test/src/interface/dialog.c
@@ -63,7 +63,7 @@ display_error_cb(const char *psz_title, const char *psz_text, void *p_data)
 static void
 display_login_cb(vlc_dialog_id *p_id, const char *psz_title,
                  const char *psz_text, const char *psz_default_username,
-                 bool b_ask_store, void *p_data)
+                 bool b_ask_store, bool b_store_secure, void *p_data)
 {
     struct cb_answer *p_ans = p_data;
     printf("login dialog: title: '%s', text: '%s', "
@@ -147,14 +147,14 @@ test_dialogs(vlc_object_t *p_obj, struct cb_answer *p_ans,
     bool b_store;
     set_answer(p_ans, false, "Click OK", 0);
     i_ret = vlc_dialog_wait_login(p_obj, &psz_user, &psz_passwd,
-                                  &b_store, "Click OK", TITLE, "Click OK");
+                                  &b_store, false, "Click OK", TITLE, "Click OK");
     assert(i_ret == 1 && strcmp(psz_user, "Click OK") == 0);
     free(psz_user);
     free(psz_passwd);
 
     set_answer(p_ans, true, NULL, 0);
     i_ret = vlc_dialog_wait_login(p_obj, &psz_user, &psz_passwd,
-                                  &b_store, "Click Cancel", TITLE, "Click Cancel");
+                                  &b_store, false, "Click Cancel", TITLE, "Click Cancel");
     assert(i_ret == 0);
 
     set_answer(p_ans, false, NULL, 0);
-- 
2.7.0



More information about the vlc-devel mailing list