]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - windows/winpgnt.c
Merge shorter option name from 'pre-0.64'.
[PuTTY.git] / windows / winpgnt.c
index e220d6bb093fa64b8a3a92f44910a18da476594b..828747dac62a83bdb391f616d53c934bc510f730 100644 (file)
@@ -14,6 +14,7 @@
 #include "ssh.h"
 #include "misc.h"
 #include "tree234.h"
+#include "winsecur.h"
 
 #include <shellapi.h>
 
@@ -116,12 +117,6 @@ static void unmungestr(char *in, char *out, int outlen)
 static tree234 *rsakeys, *ssh2keys;
 
 static int has_security;
-#ifndef NO_SECURITY
-DECL_WINDOWS_FUNCTION(extern, DWORD, GetSecurityInfo,
-                     (HANDLE, SE_OBJECT_TYPE, SECURITY_INFORMATION,
-                      PSID *, PSID *, PACL *, PACL *,
-                      PSECURITY_DESCRIPTOR *));
-#endif
 
 /*
  * Forward references
@@ -354,22 +349,24 @@ static void keylist_update(void)
        }
        for (i = 0; NULL != (skey = index234(ssh2keys, i)); i++) {
            char *listentry, *p;
-           int fp_len;
+           int pos, fp_len;
            /*
-            * Replace two spaces in the fingerprint with tabs, for
-            * nice alignment in the box.
+            * Replace spaces with tabs in the fingerprint prefix, for
+            * nice alignment in the list box, until we encounter a :
+            * meaning we're into the fingerprint proper.
             */
            p = skey->alg->fingerprint(skey->data);
             listentry = dupprintf("%s\t%s", p, skey->comment);
             fp_len = strlen(listentry);
             sfree(p);
 
-           p = strchr(listentry, ' ');
-           if (p && p < listentry + fp_len)
-               *p = '\t';
-           p = strchr(listentry, ' ');
-           if (p && p < listentry + fp_len)
-               *p = '\t';
+            pos = 0;
+            while (1) {
+                pos += strcspn(listentry + pos, " :");
+                if (listentry[pos] == ':')
+                    break;
+                listentry[pos++] = '\t';
+            }
 
            SendDlgItemMessage(keylist, 100, LB_ADDSTRING, 0,
                               (LPARAM) listentry);
@@ -811,8 +808,10 @@ static void *get_keylist1(int *length)
        retval = agent_query(request, 5, &vresponse, &resplen, NULL, NULL);
        assert(retval == 1);
        response = vresponse;
-       if (resplen < 5 || response[4] != SSH1_AGENT_RSA_IDENTITIES_ANSWER)
+       if (resplen < 5 || response[4] != SSH1_AGENT_RSA_IDENTITIES_ANSWER) {
+            sfree(response);
            return NULL;
+        }
 
        ret = snewn(resplen-5, unsigned char);
        memcpy(ret, response+5, resplen-5);
@@ -846,8 +845,10 @@ static void *get_keylist2(int *length)
        retval = agent_query(request, 5, &vresponse, &resplen, NULL, NULL);
        assert(retval == 1);
        response = vresponse;
-       if (resplen < 5 || response[4] != SSH2_AGENT_IDENTITIES_ANSWER)
+       if (resplen < 5 || response[4] != SSH2_AGENT_IDENTITIES_ANSWER) {
+            sfree(response);
            return NULL;
+        }
 
        ret = snewn(resplen-5, unsigned char);
        memcpy(ret, response+5, resplen-5);
@@ -942,12 +943,17 @@ static void answer_msg(void *msg)
                goto failure;
            p += i;
            i = ssh1_read_bignum(p, msgend - p, &reqkey.modulus);
-           if (i < 0)
+           if (i < 0) {
+                freebn(reqkey.exponent);
                goto failure;
+            }
            p += i;
            i = ssh1_read_bignum(p, msgend - p, &challenge);
-           if (i < 0)
+           if (i < 0) {
+                freebn(reqkey.exponent);
+                freebn(reqkey.modulus);
                goto failure;
+            }
            p += i;
            if (msgend < p+16) {
                freebn(reqkey.exponent);
@@ -1137,6 +1143,12 @@ static void answer_msg(void *msg)
                key->alg = &ssh_rsa;
            else if (alglen == 7 && !memcmp(alg, "ssh-dss", 7))
                key->alg = &ssh_dss;
+            else if (alglen == 19 && memcmp(alg, "ecdsa-sha2-nistp256", 19))
+                key->alg = &ssh_ecdsa_nistp256;
+            else if (alglen == 19 && memcmp(alg, "ecdsa-sha2-nistp384", 19))
+                key->alg = &ssh_ecdsa_nistp384;
+            else if (alglen == 19 && memcmp(alg, "ecdsa-sha2-nistp521", 19))
+                key->alg = &ssh_ecdsa_nistp521;
            else {
                sfree(key);
                goto failure;
@@ -1437,10 +1449,12 @@ static void prompt_add_keyfile(void)
     of.lpstrTitle = "Select Private Key File";
     of.Flags = OFN_ALLOWMULTISELECT | OFN_EXPLORER;
     if (request_file(keypath, &of, TRUE, FALSE)) {
-       if(strlen(filelist) > of.nFileOffset)
+       if(strlen(filelist) > of.nFileOffset) {
            /* Only one filename returned? */
-           add_keyfile(filename_from_str(filelist));
-       else {
+            Filename *fn = filename_from_str(filelist);
+           add_keyfile(fn);
+            filename_free(fn);
+        } else {
            /* we are returned a bunch of strings, end to
             * end. first string is the directory, the
             * rest the filenames. terminated with an
@@ -1450,7 +1464,9 @@ static void prompt_add_keyfile(void)
            char *filewalker = filelist + strlen(dir) + 1;
            while (*filewalker != '\0') {
                char *filename = dupcat(dir, "\\", filewalker, NULL);
-               add_keyfile(filename_from_str(filename));
+                Filename *fn = filename_from_str(filename);
+               add_keyfile(fn);
+                filename_free(fn);
                sfree(filename);
                filewalker += strlen(filewalker) + 1;
            }
@@ -1500,7 +1516,7 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg,
 
        keylist = hwnd;
        {
-           static int tabs[] = { 35, 60, 210 };
+           static int tabs[] = { 35, 75, 250 };
            SendDlgItemMessage(hwnd, 100, LB_SETTABSTOPS,
                               sizeof(tabs) / sizeof(*tabs),
                               (LPARAM) tabs);
@@ -1908,6 +1924,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
 #ifdef DEBUG_IPC
                        debug(("couldn't get user SID\n"));
 #endif
+                        CloseHandle(filemap);
                        return 0;
                     }
 
@@ -1915,6 +1932,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
 #ifdef DEBUG_IPC
                        debug(("couldn't get default SID\n"));
 #endif
+                        CloseHandle(filemap);
+                        sfree(ourself);
                        return 0;
                     }
 
@@ -1926,6 +1945,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                        debug(("couldn't get owner info for filemap: %d\n",
                                rc));
 #endif
+                        CloseHandle(filemap);
+                        sfree(ourself);
+                        sfree(ourself2);
                        return 0;
                    }
 #ifdef DEBUG_IPC
@@ -1944,6 +1966,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                    if (!EqualSid(mapowner, ourself) &&
                         !EqualSid(mapowner, ourself2)) {
                         CloseHandle(filemap);
+                        LocalFree(psd);
+                        sfree(ourself);
+                        sfree(ourself2);
                        return 0;      /* security ID mismatch! */
                     }
 #ifdef DEBUG_IPC
@@ -2017,7 +2042,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 {
     WNDCLASS wndclass;
     MSG msg;
-    HMODULE advapi;
     char *command = NULL;
     int added_keys = 0;
     int argc, i;
@@ -2044,7 +2068,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
        /*
         * Attempt to get the security API we need.
         */
-        if (!init_advapi()) {
+        if (!got_advapi()) {
            MessageBox(NULL,
                       "Unable to access security APIs. Pageant will\n"
                       "not run, in case it causes a security breach.",
@@ -2058,8 +2082,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
                   "Pageant Fatal Error", MB_ICONERROR | MB_OK);
        return 1;
 #endif
-    } else
-       advapi = NULL;
+    }
 
     /*
      * See if we can find our Help file.
@@ -2112,8 +2135,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
     for (i = 0; i < argc; i++) {
        if (!strcmp(argv[i], "-pgpfp")) {
            pgp_fingerprints();
-           if (advapi)
-               FreeLibrary(advapi);
            return 1;
        } else if (!strcmp(argv[i], "-c")) {
            /*
@@ -2127,7 +2148,9 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
                command = "";
            break;
        } else {
-           add_keyfile(filename_from_str(argv[i]));
+            Filename *fn = filename_from_str(argv[i]);
+           add_keyfile(fn);
+            filename_free(fn);
            added_keys = TRUE;
        }
     }
@@ -2161,8 +2184,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
            MessageBox(NULL, "Pageant is already running", "Pageant Error",
                       MB_ICONERROR | MB_OK);
        }
-       if (advapi)
-           FreeLibrary(advapi);
        return 0;
     }
 
@@ -2242,9 +2263,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
     if (keypath) filereq_free(keypath);
 
-    if (advapi)
-       FreeLibrary(advapi);
-
     cleanup_exit(msg.wParam);
     return msg.wParam;                /* just in case optimiser complains */
 }