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

Stop winutils.c from depending on the global HWND.

The GUI version of pgp_fingerprints() is now a differently named
function that takes a parent HWND as a parameter, and so does my
help-enabled wrapper around MessageBox.
This commit is contained in:
Simon Tatham 2020-02-02 10:00:42 +00:00
parent ad0c7c99f8
commit 46f60bb547
6 changed files with 34 additions and 27 deletions

View File

@ -872,7 +872,7 @@ int win_seat_verify_ssh_host_key(
char *text = dupprintf(wrongmsg, appname, keytype, fingerprint, char *text = dupprintf(wrongmsg, appname, keytype, fingerprint,
appname); appname);
char *caption = dupprintf(mbtitle, appname); char *caption = dupprintf(mbtitle, appname);
mbret = message_box(text, caption, mbret = message_box(hwnd, text, caption,
MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON3, MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON3,
HELPCTXID(errors_hostkey_changed)); HELPCTXID(errors_hostkey_changed));
assert(mbret==IDYES || mbret==IDNO || mbret==IDCANCEL); assert(mbret==IDYES || mbret==IDNO || mbret==IDCANCEL);
@ -887,7 +887,7 @@ int win_seat_verify_ssh_host_key(
int mbret; int mbret;
char *text = dupprintf(absentmsg, keytype, fingerprint, appname); char *text = dupprintf(absentmsg, keytype, fingerprint, appname);
char *caption = dupprintf(mbtitle, appname); char *caption = dupprintf(mbtitle, appname);
mbret = message_box(text, caption, mbret = message_box(hwnd, text, caption,
MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON3, MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON3,
HELPCTXID(errors_hostkey_absent)); HELPCTXID(errors_hostkey_absent));
assert(mbret==IDYES || mbret==IDNO || mbret==IDCANCEL); assert(mbret==IDYES || mbret==IDNO || mbret==IDCANCEL);

View File

@ -648,7 +648,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
"Are you really sure you want to continue?", "Are you really sure you want to continue?",
appname); appname);
s2 = dupprintf("%s Warning", appname); s2 = dupprintf("%s Warning", appname);
if (message_box(s1, s2, if (message_box(NULL, s1, s2,
MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2, MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2,
HELPCTXID(option_cleanup)) == IDYES) { HELPCTXID(option_cleanup)) == IDYES) {
cleanup_all(); cleanup_all();
@ -657,7 +657,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
sfree(s2); sfree(s2);
exit(0); exit(0);
} else if (!strcmp(p, "-pgpfp")) { } else if (!strcmp(p, "-pgpfp")) {
pgp_fingerprints(); pgp_fingerprints_msgbox(NULL);
exit(1); exit(1);
} else if (*p != '-') { } else if (*p != '-') {
cmdline_error("unexpected argument \"%s\"", p); cmdline_error("unexpected argument \"%s\"", p);

View File

@ -657,7 +657,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
!import_possible(type)) { !import_possible(type)) {
char *msg = dupprintf("Couldn't load private key (%s)", char *msg = dupprintf("Couldn't load private key (%s)",
key_type_to_str(type)); key_type_to_str(type));
message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR, message_box(hwnd, msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey)); HELPCTXID(errors_cantloadkey));
sfree(msg); sfree(msg);
return; return;
@ -720,7 +720,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
sfree(comment); sfree(comment);
if (ret == 0) { if (ret == 0) {
char *msg = dupprintf("Couldn't load private key (%s)", errmsg); char *msg = dupprintf("Couldn't load private key (%s)", errmsg);
message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR, message_box(hwnd, msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey)); HELPCTXID(errors_cantloadkey));
sfree(msg); sfree(msg);
} else if (ret == 1) { } else if (ret == 1) {
@ -1572,7 +1572,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-pgpfp")) { if (!strcmp(argv[i], "-pgpfp")) {
pgp_fingerprints(); pgp_fingerprints_msgbox(NULL);
return 1; return 1;
} else if (!strcmp(argv[i], "-restrict-acl") || } else if (!strcmp(argv[i], "-restrict-acl") ||
!strcmp(argv[i], "-restrict_acl") || !strcmp(argv[i], "-restrict_acl") ||

View File

@ -415,7 +415,7 @@ static void win_add_keyfile(Filename *filename)
} }
error: error:
message_box(err, APPNAME, MB_OK | MB_ICONERROR, message_box(hwnd, err, APPNAME, MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey)); HELPCTXID(errors_cantloadkey));
done: done:
if (passphrase) { if (passphrase) {
@ -1271,7 +1271,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
split_into_argv(cmdline, &argc, &argv, &argstart); split_into_argv(cmdline, &argc, &argv, &argstart);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-pgpfp")) { if (!strcmp(argv[i], "-pgpfp")) {
pgp_fingerprints(); pgp_fingerprints_msgbox(NULL);
return 1; return 1;
} else if (!strcmp(argv[i], "-restrict-acl") || } else if (!strcmp(argv[i], "-restrict-acl") ||
!strcmp(argv[i], "-restrict_acl") || !strcmp(argv[i], "-restrict_acl") ||

View File

@ -399,7 +399,9 @@ typedef struct filereq_tag filereq; /* cwd for file requester */
bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save); bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save);
filereq *filereq_new(void); filereq *filereq_new(void);
void filereq_free(filereq *state); void filereq_free(filereq *state);
int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid); void pgp_fingerprints_msgbox(HWND owner);
int message_box(HWND owner, LPCTSTR text, LPCTSTR caption,
DWORD style, DWORD helpctxid);
char *GetDlgItemText_alloc(HWND hwnd, int id); char *GetDlgItemText_alloc(HWND hwnd, int id);
void split_into_argv(char *, int *, char ***, char ***); void split_into_argv(char *, int *, char ***, char ***);

View File

@ -91,6 +91,8 @@ void filereq_free(filereq *state)
* Message box with optional context help. * Message box with optional context help.
*/ */
static HWND message_box_owner;
/* Callback function to launch context help. */ /* Callback function to launch context help. */
static VOID CALLBACK message_box_help_callback(LPHELPINFO lpHelpInfo) static VOID CALLBACK message_box_help_callback(LPHELPINFO lpHelpInfo)
{ {
@ -107,10 +109,11 @@ static VOID CALLBACK message_box_help_callback(LPHELPINFO lpHelpInfo)
CHECK_CTX(pgp_fingerprints); CHECK_CTX(pgp_fingerprints);
#undef CHECK_CTX #undef CHECK_CTX
if (context) if (context)
launch_help(hwnd, context); launch_help(message_box_owner, context);
} }
int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid) int message_box(HWND owner, LPCTSTR text, LPCTSTR caption,
DWORD style, DWORD helpctxid)
{ {
MSGBOXPARAMS mbox; MSGBOXPARAMS mbox;
@ -121,7 +124,7 @@ int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid)
mbox.cbSize = sizeof(mbox); mbox.cbSize = sizeof(mbox);
/* Assumes the globals `hinst' and `hwnd' have sensible values. */ /* Assumes the globals `hinst' and `hwnd' have sensible values. */
mbox.hInstance = hinst; mbox.hInstance = hinst;
mbox.hwndOwner = hwnd; mbox.hwndOwner = message_box_owner = owner;
mbox.lpfnMsgBoxCallback = &message_box_help_callback; mbox.lpfnMsgBoxCallback = &message_box_help_callback;
mbox.dwLanguageId = LANG_NEUTRAL; mbox.dwLanguageId = LANG_NEUTRAL;
mbox.lpszText = text; mbox.lpszText = text;
@ -135,21 +138,23 @@ int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid)
/* /*
* Display the fingerprints of the PGP Master Keys to the user. * Display the fingerprints of the PGP Master Keys to the user.
*/ */
void pgp_fingerprints(void) void pgp_fingerprints_msgbox(HWND owner)
{ {
message_box("These are the fingerprints of the PuTTY PGP Master Keys. They can\n" message_box(
"be used to establish a trust path from this executable to another\n" owner,
"one. See the manual for more information.\n" "These are the fingerprints of the PuTTY PGP Master Keys. They can\n"
"(Note: these fingerprints have nothing to do with SSH!)\n" "be used to establish a trust path from this executable to another\n"
"\n" "one. See the manual for more information.\n"
"PuTTY Master Key as of " PGP_MASTER_KEY_YEAR "(Note: these fingerprints have nothing to do with SSH!)\n"
" (" PGP_MASTER_KEY_DETAILS "):\n" "\n"
" " PGP_MASTER_KEY_FP "\n\n" "PuTTY Master Key as of " PGP_MASTER_KEY_YEAR
"Previous Master Key (" PGP_PREV_MASTER_KEY_YEAR " (" PGP_MASTER_KEY_DETAILS "):\n"
", " PGP_PREV_MASTER_KEY_DETAILS "):\n" " " PGP_MASTER_KEY_FP "\n\n"
" " PGP_PREV_MASTER_KEY_FP, "Previous Master Key (" PGP_PREV_MASTER_KEY_YEAR
"PGP fingerprints", MB_ICONINFORMATION | MB_OK, ", " PGP_PREV_MASTER_KEY_DETAILS "):\n"
HELPCTXID(pgp_fingerprints)); " " PGP_PREV_MASTER_KEY_FP,
"PGP fingerprints", MB_ICONINFORMATION | MB_OK,
HELPCTXID(pgp_fingerprints));
} }
/* /*