X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=windows%2Fwindow.c;h=004eb4f827eeccaf6ebc3bf1da8bb5f499c94318;hb=23fbc4f56b04ca5d387c16720caa05ddf2d63e2f;hp=290e6a31cf513da6803b294c61b8e58f09e69d89;hpb=2a73676490570520e6dbb3bc856b0710a645c2bd;p=PuTTY.git diff --git a/windows/window.c b/windows/window.c index 290e6a31..004eb4f8 100644 --- a/windows/window.c +++ b/windows/window.c @@ -10,6 +10,10 @@ #include #include +#ifdef __WINE__ +#define NO_MULTIMON /* winelib doesn't have this */ +#endif + #ifndef NO_MULTIMON #define COMPILE_MULTIMON_STUBS #endif @@ -347,6 +351,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) HRESULT hr; int guess_width, guess_height; + dll_hijacking_protection(); + hinst = inst; hwnd = NULL; flags = FLAG_VERBOSE | FLAG_INTERACTIVE; @@ -355,6 +361,11 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) InitCommonControls(); + /* Set Explicit App User Model Id so that jump lists don't cause + PuTTY to hang on to removable media. */ + + set_explicit_app_user_model_id(); + /* Ensure a Maximize setting in Explorer doesn't maximise the * config box. */ defuse_showwindow(); @@ -396,21 +407,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) return 1; } - /* - * Protect our process - */ - { -#if !defined UNPROTECT && !defined NO_SECURITY - char *error = NULL; - if (! setprocessacl(error)) { - char *message = dupprintf("Could not restrict process ACL: %s", - error); - logevent(NULL, message); - sfree(message); - sfree(error); - } -#endif - } /* * Process the command line. */ @@ -440,11 +436,20 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) * Process a couple of command-line options which are more * easily dealt with before the line is broken up into words. * These are the old-fashioned but convenient @sessionname and - * the internal-use-only &sharedmemoryhandle, neither of which - * are combined with anything else. + * the internal-use-only &sharedmemoryhandle, plus the &R + * prefix for -restrict-acl, all of which are used by PuTTYs + * auto-launching each other via System-menu options. */ while (*p && isspace(*p)) p++; + if (*p == '&' && p[1] == 'R' && + (!p[2] || p[2] == '@' || p[2] == '&')) { + /* &R restrict-acl prefix */ + restrict_process_acl(); + restricted_acl = TRUE; + p += 2; + } + if (*p == '@') { /* * An initial @ means that the whole of the rest of the @@ -482,7 +487,11 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) cleanup_exit(0); } allow_launch = TRUE; - } else { + } else if (!*p) { + /* Do-nothing case for an empty command line - or rather, + * for a command line that's empty _after_ we strip off + * the &R prefix. */ + } else { /* * Otherwise, break up the command line and deal with * it sensibly. @@ -504,39 +513,22 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) i++; /* skip next argument */ } else if (ret == 1) { continue; /* nothing further needs doing */ - } else if (!strcmp(p, "-cleanup") || - !strcmp(p, "-cleanup-during-uninstall")) { + } else if (!strcmp(p, "-cleanup")) { /* * `putty -cleanup'. Remove all registry * entries associated with PuTTY, and also find * and delete the random seed file. */ char *s1, *s2; - /* Are we being invoked from an uninstaller? */ - if (!strcmp(p, "-cleanup-during-uninstall")) { - s1 = dupprintf("Remove saved sessions and random seed file?\n" - "\n" - "If you hit Yes, ALL Registry entries associated\n" - "with %s will be removed, as well as the\n" - "random seed file. THIS PROCESS WILL\n" - "DESTROY YOUR SAVED SESSIONS.\n" - "(This only affects the currently logged-in user.)\n" - "\n" - "If you hit No, uninstallation will proceed, but\n" - "saved sessions etc will be left on the machine.", - appname); - s2 = dupprintf("%s Uninstallation", appname); - } else { - s1 = dupprintf("This procedure will remove ALL Registry entries\n" - "associated with %s, and will also remove\n" - "the random seed file. (This only affects the\n" - "currently logged-in user.)\n" - "\n" - "THIS PROCESS WILL DESTROY YOUR SAVED SESSIONS.\n" - "Are you really sure you want to continue?", - appname); - s2 = dupprintf("%s Warning", appname); - } + s1 = dupprintf("This procedure will remove ALL Registry entries\n" + "associated with %s, and will also remove\n" + "the random seed file. (This only affects the\n" + "currently logged-in user.)\n" + "\n" + "THIS PROCESS WILL DESTROY YOUR SAVED SESSIONS.\n" + "Are you really sure you want to continue?", + appname); + s2 = dupprintf("%s Warning", appname); if (message_box(s1, s2, MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2, HELPCTXID(option_cleanup)) == IDYES) { @@ -852,6 +844,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) } } + if (restricted_acl) { + logevent(NULL, "Running with restricted process ACL"); + } + start_backend(); /* @@ -1538,7 +1534,8 @@ static void init_fonts(int pick_width, int pick_height) if (cset == OEM_CHARSET) ucsdata.font_codepage = GetOEMCP(); else - if (TranslateCharsetInfo ((DWORD *) cset, &info, TCI_SRCCHARSET)) + if (TranslateCharsetInfo ((DWORD *)(ULONG_PTR)cset, + &info, TCI_SRCCHARSET)) ucsdata.font_codepage = info.ciACP; else ucsdata.font_codepage = -1; @@ -2156,13 +2153,18 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, case IDM_SAVEDSESS: { char b[2048]; - char c[30], *cl; - int freecl = FALSE; + char *cl; + const char *argprefix; BOOL inherit_handles; STARTUPINFO si; PROCESS_INFORMATION pi; HANDLE filemap = NULL; + if (restricted_acl) + argprefix = "&R"; + else + argprefix = ""; + if (wParam == IDM_DUPSESS) { /* * Allocate a file-mapping memory chunk for the @@ -2189,20 +2191,21 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, } } inherit_handles = TRUE; - sprintf(c, "putty &%p:%u", filemap, (unsigned)size); - cl = c; + cl = dupprintf("putty %s&%p:%u", argprefix, + filemap, (unsigned)size); } else if (wParam == IDM_SAVEDSESS) { unsigned int sessno = ((lParam - IDM_SAVED_MIN) / MENU_SAVED_STEP) + 1; if (sessno < (unsigned)sesslist.nsessions) { const char *session = sesslist.sessions[sessno]; - cl = dupprintf("putty @%s", session); + cl = dupprintf("putty %s@%s", argprefix, session); inherit_handles = FALSE; - freecl = TRUE; } else break; } else /* IDM_NEWSESS */ { - cl = NULL; + cl = dupprintf("putty%s%s", + *argprefix ? " " : "", + argprefix); inherit_handles = FALSE; } @@ -2221,8 +2224,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, if (filemap) CloseHandle(filemap); - if (freecl) - sfree(cl); + sfree(cl); } break; case IDM_RESTART: @@ -3139,7 +3141,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, */ term_seen_key_event(term); if (ldisc) - ldisc_send(ldisc, buf, len, 1); + ldisc_send(ldisc, (char *)buf, len, 1); show_mouseptr(0); } } @@ -3207,7 +3209,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, case WM_IME_CHAR: if (wParam & 0xFF00) { - unsigned char buf[2]; + char buf[2]; buf[1] = wParam; buf[0] = wParam >> 8; @@ -4247,7 +4249,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, *p++ = "hH\010\010"[shift_state & 3]; return p - output; case VK_NUMPAD5: - *p++ = shift_state ? '.' : '.'; + *p++ = '.'; return p - output; case VK_NUMPAD6: *p++ = "lL\014\014"[shift_state & 3]; @@ -4612,7 +4614,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, break; } if (xkey) { - p += format_arrow_key(p, term, xkey, shift_state); + p += format_arrow_key((char *)p, term, xkey, shift_state); return p - output; } }