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 <selva.nair@gmail.com>
pull/271/head
Selva Nair 2018-07-02 20:16:33 -04:00
parent 0138326805
commit b7c6e27178
3 changed files with 36 additions and 0 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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