diff options
author | j.novak@netsystem.cz <j.novak@netsystem.cz> | 2021-12-30 16:03:15 +0000 |
---|---|---|
committer | Wireshark GitLab Utility <6629907-ws-gitlab-utility@users.noreply.gitlab.com> | 2021-12-30 16:03:15 +0000 |
commit | 6c9cb8f3faf33bdbbf848397e14257eb35accfc2 (patch) | |
tree | 82e47254caa821c01fab4b547bbf16541ba91e96 /ui | |
parent | 6d0bd4e8e1496d88f016d02502ee94026d01d241 (diff) |
Prefs/Extcap: Added support for password which is never stored on the disk
Diffstat (limited to 'ui')
-rw-r--r-- | ui/preference_utils.c | 15 | ||||
-rw-r--r-- | ui/qt/extcap_argument.cpp | 2 | ||||
-rw-r--r-- | ui/qt/manager/wireshark_preference.cpp | 14 | ||||
-rw-r--r-- | ui/qt/models/pref_models.cpp | 14 | ||||
-rw-r--r-- | ui/qt/models/pref_models.h | 1 | ||||
-rw-r--r-- | ui/qt/module_preferences_scroll_area.cpp | 17 | ||||
-rw-r--r-- | ui/qt/preference_editor_frame.cpp | 4 | ||||
-rw-r--r-- | ui/qt/protocol_preferences_menu.cpp | 1 |
8 files changed, 60 insertions, 8 deletions
diff --git a/ui/preference_utils.c b/ui/preference_utils.c index 950a4d5571..a9731a8130 100644 --- a/ui/preference_utils.c +++ b/ui/preference_utils.c @@ -85,11 +85,11 @@ prefs_store_ext_helper(const char * module_name, const char *pref_name, const ch pref_t * pref = NULL; unsigned int pref_changed = 0; - if ( ! prefs_is_registered_protocol(module_name)) + if ( !prefs_is_registered_protocol(module_name)) return 0; module = prefs_find_module(module_name); - if ( ! module ) + if ( !module ) return 0; pref = prefs_find_preference(module, pref_name); @@ -100,8 +100,13 @@ prefs_store_ext_helper(const char * module_name, const char *pref_name, const ch if (prefs_get_type(pref) == PREF_STRING ) { pref_changed |= prefs_set_string_value(pref, pref_value, pref_stashed); - if ( ! pref_changed || prefs_get_string_value(pref, pref_stashed) != 0 ) + if ( !pref_changed || prefs_get_string_value(pref, pref_stashed) != 0 ) pref_changed |= prefs_set_string_value(pref, pref_value, pref_current); + } else if (prefs_get_type(pref) == PREF_PASSWORD ) + { + pref_changed |= prefs_set_password_value(pref, pref_value, pref_stashed); + if ( !pref_changed || prefs_get_password_value(pref, pref_stashed) != 0 ) + pref_changed |= prefs_set_password_value(pref, pref_value, pref_current); } return pref_changed; @@ -128,11 +133,11 @@ prefs_store_ext_multiple(const char * module, GHashTable * pref_values) gboolean pref_changed = FALSE; GList * keys = NULL; - if ( ! prefs_is_registered_protocol(module)) + if ( !prefs_is_registered_protocol(module)) return pref_changed; keys = g_hash_table_get_keys(pref_values); - if ( ! keys ) + if ( !keys ) return pref_changed; for ( GList * key = keys; key != NULL; key = g_list_next(key) ) diff --git a/ui/qt/extcap_argument.cpp b/ui/qt/extcap_argument.cpp index f927307c39..aaf0059ec1 100644 --- a/ui/qt/extcap_argument.cpp +++ b/ui/qt/extcap_argument.cpp @@ -442,7 +442,7 @@ QWidget * ExtArgText::createEditor(QWidget * parent) textBox->setPlaceholderText(QString().fromUtf8(_argument->placeholder)); if (_argument->arg_type == EXTCAP_ARG_PASSWORD) - textBox->setEchoMode(QLineEdit::Password); + textBox->setEchoMode(QLineEdit::PasswordEchoOnEdit); connect(textBox , SIGNAL(textChanged(QString)), SLOT(onStringChanged(QString))); diff --git a/ui/qt/manager/wireshark_preference.cpp b/ui/qt/manager/wireshark_preference.cpp index 761589d6dd..392fe258cb 100644 --- a/ui/qt/manager/wireshark_preference.cpp +++ b/ui/qt/manager/wireshark_preference.cpp @@ -81,6 +81,20 @@ public: REGISTER_PREFERENCE_TYPE(PREF_STRING, StringPreference) REGISTER_PREFERENCE_TYPE(PREF_CUSTOM, StringPreference) +class PasswordPreference : public StringPreference +{ +public: + PasswordPreference(QObject * parent = Q_NULLPTR) : StringPreference(parent) {} + virtual QWidget * editor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) + { + QLineEdit *le = static_cast<QLineEdit *>(StringPreference::editor(parent, option, index)); + + le->setEchoMode(QLineEdit::PasswordEchoOnEdit); + return le; + } +}; +REGISTER_PREFERENCE_TYPE(PREF_PASSWORD, PasswordPreference) + class UIntPreference : public StringPreference { public: diff --git a/ui/qt/models/pref_models.cpp b/ui/qt/models/pref_models.cpp index c926f82898..5649ca0b1c 100644 --- a/ui/qt/models/pref_models.cpp +++ b/ui/qt/models/pref_models.cpp @@ -20,6 +20,7 @@ #include <QFont> #include <QColor> #include <QRegularExpression> +#include <QApplication> // XXX Should we move this to ui/preference_utils? static GHashTable * pref_ptr_to_pref_ = NULL; @@ -341,7 +342,8 @@ QString PrefsModel::typeToString(int type) AdvancedPrefsModel::AdvancedPrefsModel(QObject * parent) : QSortFilterProxyModel(parent), -filter_() +filter_(), +passwordChar_(QApplication::style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter)) { } @@ -400,7 +402,12 @@ QVariant AdvancedPrefsModel::data(const QModelIndex &dataindex, int role) const if (item->getPref() == NULL) return QVariant(); - return sourceModel()->data(sourceModel()->index(modelIndex.row(), PrefsModel::colValue, modelIndex.parent()), role); + if (PREF_PASSWORD == item->getPrefType()) + { + return QString(sourceModel()->data(sourceModel()->index(modelIndex.row(), PrefsModel::colValue, modelIndex.parent()), role).toString().size(), passwordChar_); + } else { + return sourceModel()->data(sourceModel()->index(modelIndex.row(), PrefsModel::colValue, modelIndex.parent()), role); + } default: break; } @@ -497,6 +504,9 @@ bool AdvancedPrefsModel::setData(const QModelIndex &dataindex, const QVariant &v case PREF_STRING: prefs_set_string_value(item->getPref(), value.toString().toStdString().c_str(), pref_stashed); break; + case PREF_PASSWORD: + prefs_set_password_value(item->getPref(), value.toString().toStdString().c_str(), pref_stashed); + break; case PREF_DECODE_AS_RANGE: case PREF_RANGE: prefs_set_stashed_range_value(item->getPref(), value.toString().toUtf8().constData()); diff --git a/ui/qt/models/pref_models.h b/ui/qt/models/pref_models.h index 920796b974..da3671da54 100644 --- a/ui/qt/models/pref_models.h +++ b/ui/qt/models/pref_models.h @@ -127,6 +127,7 @@ protected: private: QString filter_; + const QChar passwordChar_; }; class ModulePrefsModel : public QSortFilterProxyModel diff --git a/ui/qt/module_preferences_scroll_area.cpp b/ui/qt/module_preferences_scroll_area.cpp index 25333eda58..6501fd04a9 100644 --- a/ui/qt/module_preferences_scroll_area.cpp +++ b/ui/qt/module_preferences_scroll_area.cpp @@ -143,6 +143,22 @@ pref_show(pref_t *pref, gpointer layout_ptr) vb->addLayout(hb); break; } + case PREF_PASSWORD: + { + QHBoxLayout *hb = new QHBoxLayout(); + QLabel *label = new QLabel(prefs_get_title(pref)); + label->setToolTip(tooltip); + hb->addWidget(label); + QLineEdit *string_le = new QLineEdit(); + string_le->setToolTip(tooltip); + string_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref)); + string_le->setMinimumWidth(string_le->fontMetrics().height() * 20); + string_le->setEchoMode(QLineEdit::PasswordEchoOnEdit); + hb->addWidget(string_le); + hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum)); + vb->addLayout(hb); + break; + } case PREF_DECODE_AS_RANGE: case PREF_RANGE: { @@ -256,6 +272,7 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg case PREF_SAVE_FILENAME: case PREF_OPEN_FILENAME: case PREF_DIRNAME: + case PREF_PASSWORD: connect(le, &QLineEdit::textEdited, this, &ModulePreferencesScrollArea::stringLineEditTextEdited); break; case PREF_RANGE: diff --git a/ui/qt/preference_editor_frame.cpp b/ui/qt/preference_editor_frame.cpp index aec2adc47b..c34f97b92d 100644 --- a/ui/qt/preference_editor_frame.cpp +++ b/ui/qt/preference_editor_frame.cpp @@ -98,6 +98,7 @@ void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module browse_button = true; // Fallthrough case PREF_STRING: + case PREF_PASSWORD: connect(ui->preferenceLineEdit, &SyntaxLineEdit::textChanged, this, &PreferenceEditorFrame::stringLineEditTextEdited); show = true; @@ -225,6 +226,9 @@ void PreferenceEditorFrame::on_buttonBox_accepted() case PREF_DIRNAME: apply = prefs_set_string_value(pref_, new_str_.toStdString().c_str(), pref_stashed); break; + case PREF_PASSWORD: + apply = prefs_set_password_value(pref_, new_str_.toStdString().c_str(), pref_stashed); + break; case PREF_RANGE: case PREF_DECODE_AS_RANGE: apply = prefs_set_range_value(pref_, new_range_, pref_stashed); diff --git a/ui/qt/protocol_preferences_menu.cpp b/ui/qt/protocol_preferences_menu.cpp index aa1f89e7da..7a4baddf83 100644 --- a/ui/qt/protocol_preferences_menu.cpp +++ b/ui/qt/protocol_preferences_menu.cpp @@ -237,6 +237,7 @@ void ProtocolPreferencesMenu::addMenuItem(preference *pref) case PREF_RANGE: case PREF_DECODE_AS_UINT: case PREF_DECODE_AS_RANGE: + case PREF_PASSWORD: { EditorPreferenceAction *epa = new EditorPreferenceAction(pref, this); addAction(epa); |