X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/32874aeac8dacbca26663777b39a79efc5d8dc4b..5f2e19fcf977f48387d918948aa3ed66748208b0:/pageant.c diff --git a/pageant.c b/pageant.c index 0605b4b3..fc5e8791 100644 --- a/pageant.c +++ b/pageant.c @@ -168,6 +168,8 @@ static int CALLBACK AboutProc(HWND hwnd, UINT msg, return 0; } +static HWND passphrase_box; + /* * Dialog-box function for the passphrase box. */ @@ -179,6 +181,7 @@ static int CALLBACK PassphraseProc(HWND hwnd, UINT msg, switch (msg) { case WM_INITDIALOG: + passphrase_box = hwnd; /* * Centre the window. */ @@ -294,8 +297,8 @@ static void keylist_update(void) static void add_keyfile(char *filename) { char passphrase[PASSPHRASE_MAXLEN]; - struct RSAKey *rkey; - struct ssh2_userkey *skey; + struct RSAKey *rkey = NULL; + struct ssh2_userkey *skey = NULL; int needs_pass; int ret; int attempts; @@ -324,6 +327,7 @@ static void add_keyfile(char *filename) int dlgret; dlgret = DialogBoxParam(instance, MAKEINTRESOURCE(210), NULL, PassphraseProc, (LPARAM) & pps); + passphrase_box = NULL; if (!dlgret) { if (comment) sfree(comment); @@ -358,6 +362,7 @@ static void add_keyfile(char *filename) if (ver == 1) { if (already_running) { unsigned char *request, *response; + void *vresponse; int reqlen, clen, resplen; clen = strlen(rkey->comment); @@ -391,7 +396,8 @@ static void add_keyfile(char *filename) reqlen += 4 + clen; PUT_32BIT(request, reqlen - 4); - agent_query(request, reqlen, &response, &resplen); + agent_query(request, reqlen, &vresponse, &resplen); + response = vresponse; if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS) MessageBox(NULL, "The already running Pageant " "refused to add the key.", APPNAME, @@ -403,6 +409,7 @@ static void add_keyfile(char *filename) } else { if (already_running) { unsigned char *request, *response; + void *vresponse; int reqlen, alglen, clen, keybloblen, resplen; alglen = strlen(skey->alg->name); clen = strlen(skey->comment); @@ -431,7 +438,8 @@ static void add_keyfile(char *filename) PUT_32BIT(request, reqlen - 4); reqlen += clen + 4; - agent_query(request, reqlen, &response, &resplen); + agent_query(request, reqlen, &vresponse, &resplen); + response = vresponse; if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS) MessageBox(NULL, "The already running Pageant" "refused to add the key.", APPNAME, @@ -938,11 +946,6 @@ static int cmpkeys_ssh2_asymm(void *av, void *bv) return c; } -static void error(char *s) -{ - MessageBox(hwnd, s, APPNAME, MB_OK | MB_ICONERROR); -} - /* * Prompt for a key file to add, and add it. */ @@ -1018,6 +1021,11 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg, case 101: /* add key */ if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == BN_DOUBLECLICKED) { + if (passphrase_box) { + MessageBeep(MB_ICONERROR); + SetForegroundWindow(passphrase_box); + break; + } prompt_add_keyfile(); } return 0; @@ -1092,6 +1100,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, case WM_SYSCOMMAND: switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */ case IDM_CLOSE: + if (passphrase_box) + SendMessage(passphrase_box, WM_CLOSE, 0, 0); SendMessage(hwnd, WM_CLOSE, 0, 0); break; case IDM_VIEWKEYS: @@ -1109,6 +1119,11 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, } break; case IDM_ADDKEY: + if (passphrase_box) { + MessageBeep(MB_ICONERROR); + SetForegroundWindow(passphrase_box); + break; + } prompt_add_keyfile(); break; case IDM_ABOUT: @@ -1135,9 +1150,12 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, COPYDATASTRUCT *cds; char *mapname; void *p; - HANDLE filemap, proc; + HANDLE filemap; +#ifndef NO_SECURITY + HANDLE proc; PSID mapowner, procowner; PSECURITY_DESCRIPTOR psd1 = NULL, psd2 = NULL; +#endif int ret = 0; cds = (COPYDATASTRUCT *) lParam; @@ -1154,8 +1172,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, debug(("filemap is %p\n", filemap)); #endif if (filemap != NULL && filemap != INVALID_HANDLE_VALUE) { - int rc; #ifndef NO_SECURITY + int rc; if (has_security) { if ((proc = OpenProcess(MAXIMUM_ALLOWED, FALSE, GetCurrentProcessId())) == @@ -1234,7 +1252,7 @@ void spawn_cmd(char *cmdline, int show) NULL, NULL, show) <= (HINSTANCE) 32) { TCHAR sMsg[140]; sprintf(sMsg, _T("Failed to run \"%.100s\", Error: %d"), cmdline, - GetLastError()); + (int)GetLastError()); MessageBox(NULL, sMsg, APPNAME, MB_OK | MB_ICONEXCLAMATION); } } @@ -1367,7 +1385,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { char *p; int inquotes = 0; - int ignorearg = 0; p = cmdline; while (*p) { while (*p && isspace(*p))