From 918c9ddfc542f7cbdb0b01896ca4c2dd13e987a5 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 20 Oct 2000 09:41:13 +0000 Subject: [PATCH] Save Key now prompts before overwriting an existing file [originally from svn r719] --- puttygen.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/puttygen.c b/puttygen.c index 6a721216..aea9ffee 100644 --- a/puttygen.c +++ b/puttygen.c @@ -22,7 +22,6 @@ /* * TODO: - * - prompt before overwriting an existing file * - check the return value from saversakey() * - test the generated keys for actual working-RSA-key-hood * - variable key size @@ -509,7 +508,18 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, } if (prompt_keyfile(hwnd, "Save private key as:", filename, 1)) { - /* FIXME: prompt before overwriting */ + FILE *fp = fopen(filename, "r"); + if (fp) { + int ret; + char buffer[FILENAME_MAX+80]; + fclose(fp); + sprintf(buffer, "Overwrite existing file\n%.*s?", + FILENAME_MAX, filename); + ret = MessageBox(hwnd, buffer, "PuTTYgen Warning", + MB_YESNO | MB_ICONWARNING); + if (ret != IDYES) + break; + } saversakey(filename, &state->key, &state->aux, *passphrase ? passphrase : NULL); /* FIXME: check return value */