1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Centralise host key message formatting.

The format _strings_ were previously centralised into the platform-
independent console.c, as const char arrays. Now the actual formatting
operation is centralised as well, by means of console.c providing a
function that takes all the necessary parameters and returns a
formatted piece of text for the console.

Mostly this is so that I can add extra parameters to the message with
some confidence: changing a format string in one file and two fprintf
statements in other files to match seems like the kind of situation
you wish you hadn't got into in the first place :-)
This commit is contained in:
Simon Tatham
2021-09-15 06:00:38 +01:00
parent e5b6aba63a
commit f317f8e67e
4 changed files with 43 additions and 28 deletions

View File

@ -111,7 +111,8 @@ int console_verify_ssh_host_key(
char line[32];
struct termios cf;
const char *common_fmt, *intro, *prompt;
char *common;
const char *intro, *prompt;
/*
* Verify the key.
@ -121,21 +122,23 @@ int console_verify_ssh_host_key(
if (ret == 0) /* success - key matched OK */
return 1;
premsg(&cf);
FingerprintType fptype_default =
ssh2_pick_default_fingerprint(fingerprints);
if (ret == 2) { /* key was different */
common_fmt = hk_wrongmsg_common_fmt;
common = hk_wrongmsg_common(keytype, fingerprints[fptype_default]);
intro = hk_wrongmsg_interactive_intro;
prompt = hk_wrongmsg_interactive_prompt;
} else { /* key was absent */
common_fmt = hk_absentmsg_common_fmt;
common = hk_absentmsg_common(keytype, fingerprints[fptype_default]);
intro = hk_absentmsg_interactive_intro;
prompt = hk_absentmsg_interactive_prompt;
}
FingerprintType fptype_default =
ssh2_pick_default_fingerprint(fingerprints);
premsg(&cf);
fputs(common, stderr);
sfree(common);
fprintf(stderr, common_fmt, keytype, fingerprints[fptype_default]);
if (console_batch_mode) {
fputs(console_abandoned_msg, stderr);
postmsg(&cf);