From b7c6e2717848dae9953ebd0f800ce5dc91856bdd Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Mon, 2 Jul 2018 20:16:33 -0400 Subject: [PATCH] Explicitly persist password-save preferences in registry Currently user preference to save password is implicitly set to true if a saved password is found in the registry. This makes it difficult to toggle the save password flag from a dialog if no previously saved password exists. Instead explicitly save the preference. This change helps implementation of the config-specific preferences dialog (next commit). No user-visible changes. Signed-off-by: Selva Nair --- openvpn.c | 8 ++++++++ openvpn_config.c | 21 +++++++++++++++++++++ openvpn_config.h | 7 +++++++ 3 files changed, 36 insertions(+) diff --git a/openvpn.c b/openvpn.c index df01879..ede39de 100644 --- a/openvpn.c +++ b/openvpn.c @@ -555,6 +555,10 @@ UserAuthDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) ManagementCommandFromInputBase64(param->c, "password \"Auth\" \"SCRV1:%s:%s\"", hwndDlg, ID_EDT_AUTH_PASS, ID_EDT_AUTH_CHALLENGE); else ManagementCommandFromInput(param->c, "password \"Auth\" \"%s\"", hwndDlg, ID_EDT_AUTH_PASS); + + /* persist flags as save password option might have changed */ + PersistConfigFlags(param->c); + EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; @@ -795,6 +799,10 @@ PrivKeyPassDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) SecureZeroMemory(passphrase, sizeof(passphrase)); } ManagementCommandFromInput(c, "password \"Private Key\" \"%s\"", hwndDlg, ID_EDT_PASSPHRASE); + + /* persist flags as save password option might have changed */ + PersistConfigFlags(c); + EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; diff --git a/openvpn_config.c b/openvpn_config.c index d6e52c1..350ee6a 100644 --- a/openvpn_config.c +++ b/openvpn_config.c @@ -34,6 +34,7 @@ #include "save_pass.h" #include "misc.h" #include "passphrase.h" +#include "openvpn_config.h" typedef enum { @@ -106,6 +107,9 @@ AddConfigFileToList(int config, const TCHAR *filename, const TCHAR *config_dir) c->manage.skaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); c->manage.skaddr.sin_port = htons(25340 + config); + /* Load persisted flags from registry */ + c->flags = (int)RecallConfigFlags(c); + #ifndef DISABLE_CHANGE_PASSWORD if (CheckKeyFileWriteAccess (c)) c->flags |= FLAG_ALLOW_CHANGE_PASSPHRASE; @@ -390,3 +394,20 @@ BuildFileList() issue_warnings = false; } + +/* Save config flags in registry */ +void +PersistConfigFlags(const connection_t *c) +{ + SetConfigRegistryValueNumeric(c->config_name, L"flags", (DWORD) c->flags); +} + +/* Recall config flags from registry */ +DWORD +RecallConfigFlags(const connection_t *c) +{ + DWORD flags; + if (!GetConfigRegistryValueNumeric(c->config_name, L"flags", &flags)) + flags = 0; + return flags; +} diff --git a/openvpn_config.h b/openvpn_config.h index 6c83664..320c92d 100644 --- a/openvpn_config.h +++ b/openvpn_config.h @@ -23,8 +23,15 @@ #define OPENVPN_CONFIG_H #include "main.h" +#include "registry.h" void BuildFileList(); bool ConfigFileOptionExist(int, const char *); +/* save config preference flags in registry */ +void PersistConfigFlags(const connection_t *c); + +/* recall config preference flags from registry */ +DWORD RecallConfigFlags(const connection_t *c); + #endif