Add help support to Pageant. (For the primary - non-context - help,
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 11 Dec 2001 18:48:29 +0000 (18:48 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 11 Dec 2001 18:48:29 +0000 (18:48 +0000)
we just invoke the same help file and jump to the Pageant chapter.
It would be nice to be able to bring up the contents box with the
Pageant chapter expanded, but I don't think WinHelp() allows us to
request this.)

git-svn-id: svn://svn.tartarus.org/sgt/putty@1471 cda61777-01e9-0310-a592-d414129be87e

doc/pageant.but
pageant.c
pageant.rc

index c7f552a..cf8db03 100644 (file)
@@ -1,7 +1,9 @@
-\versionid $Id: pageant.but,v 1.5 2001/11/25 17:32:39 simon Exp $
+\versionid $Id: pageant.but,v 1.6 2001/12/11 18:48:29 simon Exp $
 
 \C{pageant} Using Pageant for authentication
 
+\cfg{winhelp-topic}{pageant.general}
+
 Pageant is an SSH authentication agent. It holds your private keys
 in memory, already decoded, so that you can use them often without
 needing to type a passphrase.
@@ -12,7 +14,8 @@ Before you run Pageant, you need to have a private key. See
 \k{pubkey} to find out how to generate and use one.
 
 When you run Pageant, it will put an icon of a computer wearing a
-hat into the System tray. It will then sit and do nothing.
+hat into the System tray. It will then sit and do nothing, until you
+load a private key into it.
 
 If you click the Pageant icon with the right mouse button, you will
 see a menu. Select \q{View Keys} from this menu. The Pageant main
@@ -21,7 +24,8 @@ double-clicking on the Pageant icon.)
 
 The Pageant window contains a list box. This shows the private keys
 Pageant is holding. When you start Pageant, it has no keys, so the
-list box will be empty.
+list box will be empty. After you add one or more keys, they will
+show up in the list box.
 
 To add a key to Pageant, press the \q{Add Key} button. Pageant will
 bring up a file dialog, labelled \q{Select Private Key File}. Find
@@ -42,6 +46,75 @@ When you want to shut down Pageant, click the right button on the
 Pageant icon in the System tray, and select \q{Exit} from the menu.
 Closing the Pageant main window does \e{not} shut down Pageant.
 
+\H{pageant-mainwin} The Pageant main window
+
+The Pageant main window appears when you left-click on the Pageant
+system tray icon, or alternatively right-click and select \q{View
+Keys} from the menu. You can use it to keep track of what keys are
+currently loaded into Pageant, and to add new ones or remove the
+existing keys.
+
+\S{pageant-mainwin-keylist} The key list box
+
+\cfg{winhelp-topic}{pageant.keylist}
+
+The large list box in the Pageant main window lists the private keys
+that are currently loaded into Pageant. The list might look
+something like this:
+
+\c ssh1     1024  22:c3:68:3b:09:41:36:c3:39:83:91:ae:71:b2:0f:04  key1
+\c ssh-rsa  1023  74:63:08:82:95:75:e1:7c:33:31:bb:cb:00:c0:89:8b  key2
+
+For each key, the list box will tell you:
+
+\b The type of the key. Currently, this can be \c{ssh1} (an RSA key
+for use with the SSH v1 protocol), \c{ssh-rsa} (an RSA key for use
+with the SSH v2 protocol), or \c{ssh-dss} (a DSA key for use with
+the SSH v2 protocol).
+
+\b The size (in bits) of the key.
+
+\b The fingerprint for the public key. This should be the same
+fingerprint given by PuTTYgen, and (hopefully) also the same
+fingerprint shown by remote utilities such as \c{ssh-keygen} when
+applied to your \c{authorized_keys} file.
+
+\b The comment attached to the key.
+
+\S{pageant-mainwin-addkey} The \q{Add Key} button
+
+\cfg{winhelp-topic}{pageant.addkey}
+
+To add a key to Pageant by reading it out of a local disk file,
+press the \q{Add Key} button in the Pageant main window, or
+alternatively right-click on the Pageant icon in the system tray and
+select \q{Add Key} from there.
+
+Pageant will bring up a file dialog, labelled \q{Select Private Key
+File}. Find your private key file in this dialog, and press
+\q{Open}. If you want to add more than one key at once, you can
+select multiple files using Shift-click (to select several adjacent
+files) or Ctrl-click (to select non-adjacent files).
+
+Pageant will now load the private key(s). If a key is protected by a
+passphrase, Pageant will ask you to type the passphrase.
+
+(This is not the only way to add a private key to Pageant. You can
+also add one from a remote system by using agent forwarding; see
+\k{pageant-forward} for details.)
+
+\S{pageant-mainwin-remkey} The \q{Remove Key} button
+
+\cfg{winhelp-topic}{pageant.remkey}
+
+If you need to remove a key from Pageant, select that key in the
+list box, and press the \q{Remove Key} button. Pageant will remove
+the key from its memory.
+
+You can apply this to keys you added using the \q{Add Key} button,
+or to keys you added remotely using agent forwarding (see
+\k{pageant-forward}); it makes no difference.
+
 \H{pageant-forward} Using agent forwarding
 
 Agent forwarding is a mechanism that allows applications on your SSH
index 2cfcdd0..20aaaf4 100644 (file)
--- a/pageant.c
+++ b/pageant.c
@@ -12,6 +12,7 @@
 #include <tchar.h>
 
 #include "ssh.h"
+#include "misc.h"
 #include "tree234.h"
 
 #define IDI_MAINICON 200
 #define IDM_CLOSE    0x0010
 #define IDM_VIEWKEYS 0x0020
 #define IDM_ADDKEY   0x0030
-#define IDM_ABOUT    0x0040
+#define IDM_HELP     0x0040
+#define IDM_ABOUT    0x0050
 
 #define APPNAME "Pageant"
 
 extern char ver[];
 
 static HINSTANCE instance;
-static HWND hwnd;
+static HWND main_hwnd;
 static HWND keylist;
 static HWND aboutbox;
 static HMENU systray_menu;
 static int already_running;
+static int requested_help;
+
+static char *help_path;
 
 static tree234 *rsakeys, *ssh2keys;
 
@@ -72,7 +77,7 @@ int agent_exists(void);
  */
 int random_byte(void)
 {
-    MessageBox(hwnd, "Internal Error", APPNAME, MB_OK | MB_ICONERROR);
+    MessageBox(main_hwnd, "Internal Error", APPNAME, MB_OK | MB_ICONERROR);
     exit(0);
     /* this line can't be reached but it placates MSVC's warnings :-) */
     return 0;
@@ -123,7 +128,6 @@ static tree234 *passphrases = NULL;
  */
 static void forget_passphrases(void)
 {
-    int i;
     while (count234(passphrases) > 0) {
        char *pp = index234(passphrases, 0);
        memset(pp, 0, strlen(pp));
@@ -1023,7 +1027,7 @@ static void prompt_add_keyfile(void)
 #else
     of.lStructSize = sizeof(of);
 #endif
-    of.hwndOwner = hwnd;
+    of.hwndOwner = main_hwnd;
     of.lpstrFilter = "All Files\0*\0\0\0";
     of.lpstrCustomFilter = NULL;
     of.nFilterIndex = 1;
@@ -1101,6 +1105,16 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg,
                           rd.right - rd.left, rd.bottom - rd.top, TRUE);
        }
 
+        if (help_path)
+            SetWindowLong(hwnd, GWL_EXSTYLE,
+                          GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
+        else {
+            HWND item = GetDlgItem(hwnd, 103);   /* the Help button */
+            if (item)
+                DestroyWindow(item);
+        }
+        requested_help = FALSE;
+
        keylist = hwnd;
        {
            static int tabs[] = { 35, 60, 210 };
@@ -1189,8 +1203,35 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg,
                keylist_update();
            }
            return 0;
+         case 103:                    /* help */
+            if (HIWORD(wParam) == BN_CLICKED ||
+                HIWORD(wParam) == BN_DOUBLECLICKED) {
+                if (help_path) {
+                    WinHelp(main_hwnd, help_path, HELP_COMMAND,
+                            (DWORD)"JI(`',`pageant.general')");
+                    requested_help = TRUE;
+                }
+            }
+           return 0;
        }
        return 0;
+      case WM_HELP:
+        if (help_path) {
+            int id = ((LPHELPINFO)lParam)->iCtrlId;
+            char *cmd = NULL;
+            switch (id) {
+              case 100: cmd = "JI(`',`pageant.keylist')"; break;
+              case 101: cmd = "JI(`',`pageant.addkey')"; break;
+              case 102: cmd = "JI(`',`pageant.remkey')"; break;
+            }
+            if (cmd) {
+                WinHelp(main_hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
+                requested_help = TRUE;
+            } else {
+                MessageBeep(0);
+            }
+        }
+        break;
       case WM_CLOSE:
        keylist = NULL;
        DestroyWindow(hwnd);
@@ -1312,9 +1353,20 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                             SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
            }
            break;
+         case IDM_HELP:
+            if (help_path) {
+                WinHelp(main_hwnd, help_path, HELP_COMMAND,
+                        (DWORD)"JI(`',`pageant.general')");
+                requested_help = TRUE;
+            }
+           break;
        }
        break;
       case WM_DESTROY:
+        if (requested_help) {
+            WinHelp(main_hwnd, help_path, HELP_QUIT, 0);
+            requested_help = FALSE;
+        }
        PostQuitMessage(0);
        return 0;
       case WM_COPYDATA:
@@ -1477,6 +1529,26 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
     instance = inst;
 
     /*
+     * See if we can find our Help file.
+     */
+    {
+        char b[2048], *p, *q, *r;
+        FILE *fp;
+        GetModuleFileName(NULL, b, sizeof(b) - 1);
+        r = b;
+        p = strrchr(b, '\\');
+        if (p && p >= r) r = p+1;
+        q = strrchr(b, ':');
+        if (q && q >= r) r = q+1;
+        strcpy(r, "putty.hlp");
+        if ( (fp = fopen(b, "r")) != NULL) {
+            help_path = dupstr(b);
+            fclose(fp);
+        } else
+            help_path = NULL;
+    }
+
+    /*
      * Find out if Pageant is already running.
      */
     already_running = FALSE;
@@ -1499,25 +1571,29 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
            RegisterClass(&wndclass);
        }
 
-       hwnd = keylist = NULL;
+       main_hwnd = keylist = NULL;
 
-       hwnd = CreateWindow(APPNAME, APPNAME,
-                           WS_OVERLAPPEDWINDOW | WS_VSCROLL,
-                           CW_USEDEFAULT, CW_USEDEFAULT,
-                           100, 100, NULL, NULL, inst, NULL);
+       main_hwnd = CreateWindow(APPNAME, APPNAME,
+                                 WS_OVERLAPPEDWINDOW | WS_VSCROLL,
+                                 CW_USEDEFAULT, CW_USEDEFAULT,
+                                 100, 100, NULL, NULL, inst, NULL);
 
        /* Set up a system tray icon */
-       AddTrayIcon(hwnd);
+       AddTrayIcon(main_hwnd);
 
         systray_menu = CreatePopupMenu();
         /* accelerators used: vkxa */
         AppendMenu(systray_menu, MF_ENABLED, IDM_VIEWKEYS,
                "&View Keys");
         AppendMenu(systray_menu, MF_ENABLED, IDM_ADDKEY, "Add &Key");
+       AppendMenu(systray_menu, MF_SEPARATOR, 0, 0);
+        if (help_path)
+            AppendMenu(systray_menu, MF_ENABLED, IDM_HELP, "&Help");
         AppendMenu(systray_menu, MF_ENABLED, IDM_ABOUT, "&About");
+       AppendMenu(systray_menu, MF_SEPARATOR, 0, 0);
         AppendMenu(systray_menu, MF_ENABLED, IDM_CLOSE, "E&xit");
 
-       ShowWindow(hwnd, SW_HIDE);
+       ShowWindow(main_hwnd, SW_HIDE);
 
        /*
         * Initialise storage for RSA keys.
@@ -1624,7 +1700,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
        NOTIFYICONDATA tnid;
 
        tnid.cbSize = sizeof(NOTIFYICONDATA);
-       tnid.hWnd = hwnd;
+       tnid.hWnd = main_hwnd;
        tnid.uID = 1;
 
        Shell_NotifyIcon(NIM_DELETE, &tnid);
index 1224a59..217b110 100644 (file)
@@ -27,6 +27,7 @@ BEGIN
         LBS_EXTENDEDSEL | LBS_HASSTRINGS | LBS_USETABSTOPS | WS_VSCROLL | WS_TABSTOP
     PUSHBUTTON "&Add Key", 101, 75, 162, 60, 14
     PUSHBUTTON "&Remove Key", 102, 195, 162, 60, 14
+    PUSHBUTTON "&Help", 103, 10, 182, 50, 14
     DEFPUSHBUTTON "&Close", IDOK, 270, 182, 50, 14
 END