X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/cb5ca81381886483b4ec2a6ff4560434edde8f80..42856df411d7491a1e40c4d21c985b03a6206e22:/pageant.c diff --git a/pageant.c b/pageant.c index fc5e8791..95eb1da6 100644 --- a/pageant.c +++ b/pageant.c @@ -65,7 +65,7 @@ int agent_exists(void); * pads its data with random bytes. Since we only use rsadecrypt() * and the signing functions, which are deterministic, this should * never be called. - * + * * If it _is_ called, there is a _serious_ problem, because it * won't generate true random numbers. So we must scream, panic, * and exit immediately if that should happen. @@ -74,6 +74,8 @@ int random_byte(void) { MessageBox(hwnd, "Internal Error", APPNAME, MB_OK | MB_ICONERROR); exit(0); + /* this line can't be reached but it placates MSVC's warnings :-) */ + return 0; } /* @@ -611,7 +613,7 @@ static void answer_msg(void *msg) break; case SSH2_AGENTC_SIGN_REQUEST: /* - * Reply with either SSH2_AGENT_RSA_RESPONSE or + * Reply with either SSH2_AGENT_SIGN_RESPONSE or * SSH_AGENT_FAILURE, depending on whether we have that key * or not. */ @@ -648,16 +650,19 @@ static void answer_msg(void *msg) { struct RSAKey *key; char *comment; + int commentlen; key = smalloc(sizeof(struct RSAKey)); - memset(key, 0, sizeof(key)); + memset(key, 0, sizeof(struct RSAKey)); p += makekey(p, key, NULL, 1); p += makeprivate(p, key); - p += ssh1_read_bignum(p, key->iqmp); /* p^-1 mod q */ - p += ssh1_read_bignum(p, key->p); /* p */ - p += ssh1_read_bignum(p, key->q); /* q */ - comment = smalloc(GET_32BIT(p)); + p += ssh1_read_bignum(p, &key->iqmp); /* p^-1 mod q */ + p += ssh1_read_bignum(p, &key->p); /* p */ + p += ssh1_read_bignum(p, &key->q); /* q */ + commentlen = GET_32BIT(p); + comment = smalloc(commentlen+1); if (comment) { - memcpy(comment, p + 4, GET_32BIT(p)); + memcpy(comment, p + 4, commentlen); + comment[commentlen] = '\0'; key->comment = comment; } PUT_32BIT(ret, 1); @@ -691,6 +696,8 @@ static void answer_msg(void *msg) /* Add further algorithm names here. */ if (alglen == 7 && !memcmp(alg, "ssh-rsa", 7)) key->alg = &ssh_rsa; + else if (alglen == 7 && !memcmp(alg, "ssh-dss", 7)) + key->alg = &ssh_dss; else { sfree(key); goto failure; @@ -1068,13 +1075,54 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg, return 0; } +/* Set up a system tray icon */ +static BOOL AddTrayIcon(HWND hwnd) +{ + BOOL res; + NOTIFYICONDATA tnid; + HICON hicon; + +#ifdef NIM_SETVERSION + tnid.uVersion = 0; + res = Shell_NotifyIcon(NIM_SETVERSION, &tnid); +#endif + + tnid.cbSize = sizeof(NOTIFYICONDATA); + tnid.hWnd = hwnd; + tnid.uID = 1; /* unique within this systray use */ + tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; + tnid.uCallbackMessage = WM_SYSTRAY; + tnid.hIcon = hicon = LoadIcon(instance, MAKEINTRESOURCE(201)); + strcpy(tnid.szTip, "Pageant (PuTTY authentication agent)"); + + res = Shell_NotifyIcon(NIM_ADD, &tnid); + + if (hicon) DestroyIcon(hicon); + + return res; +} + static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { int ret; static int menuinprogress; + static UINT msgTaskbarCreated = 0; switch (message) { + case WM_CREATE: + msgTaskbarCreated = RegisterWindowMessage(_T("TaskbarCreated")); + break; + default: + if (message==msgTaskbarCreated) { + /* + * Explorer has been restarted, so the tray icon will + * have been lost. + */ + AddTrayIcon(hwnd); + } + break; + case WM_SYSTRAY: if (lParam == WM_RBUTTONUP) { POINT cursorpos; @@ -1335,37 +1383,15 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) 100, 100, NULL, NULL, inst, NULL); /* Set up a system tray icon */ - { - BOOL res; - NOTIFYICONDATA tnid; - HICON hicon; - -#ifdef NIM_SETVERSION - tnid.uVersion = 0; - res = Shell_NotifyIcon(NIM_SETVERSION, &tnid); -#endif - - tnid.cbSize = sizeof(NOTIFYICONDATA); - tnid.hWnd = hwnd; - tnid.uID = 1; /* unique within this systray use */ - tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; - tnid.uCallbackMessage = WM_SYSTRAY; - tnid.hIcon = hicon = LoadIcon(instance, MAKEINTRESOURCE(201)); - strcpy(tnid.szTip, "Pageant (PuTTY authentication agent)"); - - res = Shell_NotifyIcon(NIM_ADD, &tnid); - - if (hicon) - DestroyIcon(hicon); - - 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_ENABLED, IDM_ABOUT, "&About"); - AppendMenu(systray_menu, MF_ENABLED, IDM_CLOSE, "E&xit"); - } + AddTrayIcon(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_ENABLED, IDM_ABOUT, "&About"); + AppendMenu(systray_menu, MF_ENABLED, IDM_CLOSE, "E&xit"); ShowWindow(hwnd, SW_HIDE);