1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Move host key dialogs over to using ShinyDialogBox.

They were previously using an ad-hoc system for getting hold of their
context structure, which had to be different between the WM_INITDIALOG
handler and everything else. That's exactly what ShinyDialogBox is
good for preventing, so let's use it, to save effort.
This commit is contained in:
Simon Tatham 2022-07-07 17:23:27 +01:00
parent d155009ded
commit 46332db26e
2 changed files with 20 additions and 25 deletions

View File

@ -853,14 +853,13 @@ struct hostkey_dialog_ctx {
const char *helpctx;
};
static INT_PTR CALLBACK HostKeyMoreInfoProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
static INT_PTR HostKeyMoreInfoProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam, void *vctx)
{
struct hostkey_dialog_ctx *ctx = (struct hostkey_dialog_ctx *)vctx;
switch (msg) {
case WM_INITDIALOG: {
const struct hostkey_dialog_ctx *ctx =
(const struct hostkey_dialog_ctx *)lParam;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (INT_PTR)ctx);
if (ctx->fingerprints[SSH_FPTYPE_SHA256])
SetDlgItemText(hwnd, IDC_HKI_SHA256,
@ -876,26 +875,25 @@ static INT_PTR CALLBACK HostKeyMoreInfoProc(HWND hwnd, UINT msg,
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
EndDialog(hwnd, 0);
ShinyEndDialog(hwnd, 0);
return 0;
}
return 0;
case WM_CLOSE:
EndDialog(hwnd, 0);
ShinyEndDialog(hwnd, 0);
return 0;
}
return 0;
}
static INT_PTR CALLBACK HostKeyDialogProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
static INT_PTR HostKeyDialogProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam, void *vctx)
{
struct hostkey_dialog_ctx *ctx = (struct hostkey_dialog_ctx *)vctx;
switch (msg) {
case WM_INITDIALOG: {
strbuf *sb = strbuf_new();
const struct hostkey_dialog_ctx *ctx =
(const struct hostkey_dialog_ctx *)lParam;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (INT_PTR)ctx);
for (int id = 100;; id++) {
char buf[256];
@ -970,26 +968,21 @@ static INT_PTR CALLBACK HostKeyDialogProc(HWND hwnd, UINT msg,
case IDC_HK_ACCEPT:
case IDC_HK_ONCE:
case IDCANCEL:
EndDialog(hwnd, LOWORD(wParam));
ShinyEndDialog(hwnd, LOWORD(wParam));
return 0;
case IDHELP: {
const struct hostkey_dialog_ctx *ctx =
(const struct hostkey_dialog_ctx *)
GetWindowLongPtr(hwnd, GWLP_USERDATA);
launch_help(hwnd, ctx->helpctx);
return 0;
}
case IDC_HK_MOREINFO: {
const struct hostkey_dialog_ctx *ctx =
(const struct hostkey_dialog_ctx *)
GetWindowLongPtr(hwnd, GWLP_USERDATA);
DialogBoxParam(hinst, MAKEINTRESOURCE(IDD_HK_MOREINFO),
hwnd, HostKeyMoreInfoProc, (LPARAM)ctx);
ShinyDialogBox(hinst, MAKEINTRESOURCE(IDD_HK_MOREINFO),
"PuTTYHostKeyMoreInfo", hwnd,
HostKeyMoreInfoProc, ctx);
}
}
return 0;
case WM_CLOSE:
EndDialog(hwnd, IDCANCEL);
ShinyEndDialog(hwnd, IDCANCEL);
return 0;
}
return 0;
@ -1021,9 +1014,9 @@ SeatPromptResult win_seat_confirm_ssh_host_key(
ctx->host = host;
ctx->port = port;
int dlgid = (mismatch ? IDD_HK_WRONG : IDD_HK_ABSENT);
int mbret = DialogBoxParam(
hinst, MAKEINTRESOURCE(dlgid), wgs->term_hwnd,
HostKeyDialogProc, (LPARAM)ctx);
int mbret = ShinyDialogBox(
hinst, MAKEINTRESOURCE(dlgid), "PuTTYHostKeyDialog",
wgs->term_hwnd, HostKeyDialogProc, ctx);
assert(mbret==IDC_HK_ACCEPT || mbret==IDC_HK_ONCE || mbret==IDCANCEL);
if (mbret == IDC_HK_ACCEPT) {
store_host_key(host, port, keytype, keystr);

View File

@ -61,6 +61,7 @@ IDD_HK_ABSENT DIALOG DISCARDABLE 50, 50, 340, 160
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "PuTTY Security Alert"
FONT 8, "MS Shell Dlg"
CLASS "PuTTYHostKeyDialog"
BEGIN
LTEXT "The host key is not cached for this server:", 100, 40, 20, 300, 8
LTEXT "You have no guarantee that the server is the computer you think it is.", 101, 40, 40, 300, 8
@ -120,6 +121,7 @@ IDD_HK_MOREINFO DIALOG DISCARDABLE 140, 40, 400, 156
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "PuTTY: information about the server's host key"
FONT 8, "MS Shell Dlg"
CLASS "PuTTYHostKeyMoreInfo"
BEGIN
LTEXT "SHA256 fingerprint:", 100, 12, 12, 80, 8
EDITTEXT IDC_HKI_SHA256, 100, 10, 288, 12, ES_READONLY