Consistently use a single notation to refer to SSH protocol versions, as
[u/mdw/putty] / windows / winpgen.c
index 7772f55..baaf3d9 100644 (file)
@@ -21,8 +21,6 @@
 
 #define DEFAULT_KEYSIZE 1024
 
-static int requested_help;
-
 static char *cmdline_keyfile = NULL;
 
 /*
@@ -198,11 +196,6 @@ static int prompt_keyfile(HWND hwnd, char *dlgtitle,
 {
     OPENFILENAME of;
     memset(&of, 0, sizeof(of));
-#ifdef OPENFILENAME_SIZE_VERSION_400
-    of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
-#else
-    of.lStructSize = sizeof(of);
-#endif
     of.hwndOwner = hwnd;
     if (ppk) {
        of.lpstrFilter = "PuTTY Private Key Files (*.ppk)\0*.ppk\0"
@@ -217,13 +210,9 @@ static int prompt_keyfile(HWND hwnd, char *dlgtitle,
     *filename = '\0';
     of.nMaxFile = FILENAME_MAX;
     of.lpstrFileTitle = NULL;
-    of.lpstrInitialDir = NULL;
     of.lpstrTitle = dlgtitle;
     of.Flags = 0;
-    if (save)
-       return GetSaveFileName(&of);
-    else
-       return GetOpenFileName(&of);
+    return request_file(NULL, &of, FALSE, save);
 }
 
 /*
@@ -436,7 +425,7 @@ void old_keyfile_warning(void)
 {
     static const char mbtitle[] = "PuTTY Key File Warning";
     static const char message[] =
-       "You are loading an SSH 2 private key which has an\n"
+       "You are loading an SSH-2 private key which has an\n"
        "old version of the file format. This means your key\n"
        "file is not fully tamperproof. Future versions of\n"
        "PuTTY may stop supporting this private key format,\n"
@@ -632,6 +621,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
     int needs_pass;
     int type, realtype;
     int ret;
+    const char *errmsg = NULL;
     char *comment;
     struct PassphraseProcStruct pps;
     struct RSAKey newkey1;
@@ -641,11 +631,11 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
     if (type != SSH_KEYTYPE_SSH1 &&
        type != SSH_KEYTYPE_SSH2 &&
        !import_possible(type)) {
-       char msg[256];
-       sprintf(msg, "Couldn't load private key (%s)",
-               key_type_to_str(type));
-       MessageBox(NULL, msg,
-                  "PuTTYgen Error", MB_OK | MB_ICONERROR);
+       char *msg = dupprintf("Couldn't load private key (%s)",
+                             key_type_to_str(type));
+       message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
+                   HELPCTXID(errors_cantloadkey));
+       sfree(msg);
        return;
     }
 
@@ -672,7 +662,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
            dlgret = DialogBoxParam(hinst,
                                    MAKEINTRESOURCE(210),
                                    NULL, PassphraseProc,
-                                   (LPARAM) & pps);
+                                   (LPARAM) &pps);
            if (!dlgret) {
                ret = -2;
                break;
@@ -682,17 +672,17 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
        if (type == SSH_KEYTYPE_SSH1) {
            if (realtype == type)
                ret = loadrsakey(&filename, &newkey1,
-                                passphrase, NULL);
+                                passphrase, &errmsg);
            else
                ret = import_ssh1(&filename, realtype,
-                                 &newkey1, passphrase);
+                                 &newkey1, passphrase, &errmsg);
        } else {
            if (realtype == type)
                newkey2 = ssh2_load_userkey(&filename,
-                                           passphrase, NULL);
+                                           passphrase, &errmsg);
            else
                newkey2 = import_ssh2(&filename, realtype,
-                                     passphrase);
+                                     passphrase, &errmsg);
            if (newkey2 == SSH2_WRONG_PASSPHRASE)
                ret = -1;
            else if (!newkey2)
@@ -704,8 +694,10 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
     if (comment)
        sfree(comment);
     if (ret == 0) {
-       MessageBox(NULL, "Couldn't load private key.",
-                  "PuTTYgen Error", MB_OK | MB_ICONERROR);
+       char *msg = dupprintf("Couldn't load private key (%s)", errmsg);
+       message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
+                   HELPCTXID(errors_cantloadkey));
+       sfree(msg);
     } else if (ret == 1) {
        /*
         * Now update the key controls with all the
@@ -844,9 +836,9 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            menu1 = CreateMenu();
            AppendMenu(menu1, MF_ENABLED, IDC_GENERATE, "&Generate key pair");
            AppendMenu(menu1, MF_SEPARATOR, 0, 0);
-           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH1, "SSH&1 key (RSA)");
-           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH2RSA, "SSH2 &RSA key");
-           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH2DSA, "SSH2 &DSA key");
+           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH1, "SSH-&1 key (RSA)");
+           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH2RSA, "SSH-2 &RSA key");
+           AppendMenu(menu1, MF_ENABLED, IDC_KEYSSH2DSA, "SSH-2 &DSA key");
            AppendMenu(menu, MF_POPUP | MF_ENABLED, (UINT) menu1, "&Key");
            state->keymenu = menu1;
 
@@ -923,9 +915,9 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            endbox(&cp);
            beginbox(&cp, "Parameters", IDC_BOX_PARAMS);
            radioline(&cp, "Type of key to generate:", IDC_TYPESTATIC, 3,
-                     "SSH&1 (RSA)", IDC_KEYSSH1,
-                     "SSH2 &RSA", IDC_KEYSSH2RSA,
-                     "SSH2 &DSA", IDC_KEYSSH2DSA, NULL);
+                     "SSH-&1 (RSA)", IDC_KEYSSH1,
+                     "SSH-2 &RSA", IDC_KEYSSH2RSA,
+                     "SSH-2 &DSA", IDC_KEYSSH2DSA, NULL);
            staticedit(&cp, "Number of &bits in a generated key:",
                       IDC_BITSSTATIC, IDC_BITS, 20);
            endbox(&cp);
@@ -1133,7 +1125,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
                 if (type != realtype &&
                     import_target_type(type) != realtype) {
                     char msg[256];
-                    sprintf(msg, "Cannot export an SSH%d key in an SSH%d"
+                    sprintf(msg, "Cannot export an SSH-%d key in an SSH-%d"
                             " format", (state->ssh2 ? 2 : 1),
                             (state->ssh2 ? 1 : 2));
                    MessageBox(hwnd, msg,
@@ -1340,50 +1332,52 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
       case WM_HELP:
         if (help_path) {
             int id = ((LPHELPINFO)lParam)->iCtrlId;
-            char *cmd = NULL;
+            char *topic = NULL;
             switch (id) {
               case IDC_GENERATING:
               case IDC_PROGRESS:
               case IDC_GENSTATIC:
               case IDC_GENERATE:
-                cmd = "JI(`',`puttygen.generate')"; break;
+                topic = "puttygen.generate"; break;
               case IDC_PKSTATIC:
               case IDC_KEYDISPLAY:
-                cmd = "JI(`',`puttygen.pastekey')"; break;
+                topic = "puttygen.pastekey"; break;
               case IDC_FPSTATIC:
               case IDC_FINGERPRINT:
-                cmd = "JI(`',`puttygen.fingerprint')"; break;
+                topic = "puttygen.fingerprint"; break;
               case IDC_COMMENTSTATIC:
               case IDC_COMMENTEDIT:
-                cmd = "JI(`',`puttygen.comment')"; break;
+                topic = "puttygen.comment"; break;
               case IDC_PASSPHRASE1STATIC:
               case IDC_PASSPHRASE1EDIT:
               case IDC_PASSPHRASE2STATIC:
               case IDC_PASSPHRASE2EDIT:
-                cmd = "JI(`',`puttygen.passphrase')"; break;
+                topic = "puttygen.passphrase"; break;
               case IDC_LOADSTATIC:
               case IDC_LOAD:
-                cmd = "JI(`',`puttygen.load')"; break;
+                topic = "puttygen.load"; break;
               case IDC_SAVESTATIC:
               case IDC_SAVE:
-                cmd = "JI(`',`puttygen.savepriv')"; break;
+                topic = "puttygen.savepriv"; break;
               case IDC_SAVEPUB:
-                cmd = "JI(`',`puttygen.savepub')"; break;
+                topic = "puttygen.savepub"; break;
               case IDC_TYPESTATIC:
               case IDC_KEYSSH1:
               case IDC_KEYSSH2RSA:
               case IDC_KEYSSH2DSA:
-                cmd = "JI(`',`puttygen.keytype')"; break;
+                topic = "puttygen.keytype"; break;
               case IDC_BITSSTATIC:
               case IDC_BITS:
-                cmd = "JI(`',`puttygen.bits')"; break;
+                topic = "puttygen.bits"; break;
               case IDC_IMPORT:
               case IDC_EXPORT_OPENSSH:
               case IDC_EXPORT_SSHCOM:
-                cmd = "JI(`',`puttygen.conversions')"; break;
+                topic = "puttygen.conversions"; break;
             }
-            if (cmd) {
+            if (topic) {
+               char *cmd = dupprintf("JI(`',`%s')", topic);
                 WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
+               sfree(cmd);
                 requested_help = TRUE;
             } else {
                 MessageBeep(0);
@@ -1422,6 +1416,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
     InitCommonControls();
     hinst = inst;
+    hwnd = NULL;
 
     /*
      * See if we can find our Help file.
@@ -1435,7 +1430,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
         if (p && p >= r) r = p+1;
         q = strrchr(b, ':');
         if (q && q >= r) r = q+1;
-        strcpy(r, "putty.hlp");
+        strcpy(r, PUTTY_HELP_FILE);
         if ( (fp = fopen(b, "r")) != NULL) {
             help_path = dupstr(b);
             fclose(fp);