Esempio n. 1
0
bool set_explicit_app_user_model_id(void)
{
  DECL_WINDOWS_FUNCTION(static, HRESULT, SetCurrentProcessExplicitAppUserModelID,
                        (PCWSTR));

  static HMODULE shell32_module = 0;

    if (!shell32_module)
    {
        shell32_module = load_system32_dll("Shell32.dll");
        /*
         * We can't typecheck this function here, because it's defined
         * in <shobjidl.h>, which we're not including due to clashes
         * with all the manual-COM machinery above.
         */
        GET_WINDOWS_FUNCTION_NO_TYPECHECK(
            shell32_module, SetCurrentProcessExplicitAppUserModelID);
    }

    if (p_SetCurrentProcessExplicitAppUserModelID)
    {
        if (p_SetCurrentProcessExplicitAppUserModelID(L"SimonTatham.PuTTY") == S_OK)
        {
	  return true;
        }
        return false;
    }
    /* Function doesn't exist, which is ok for Pre-7 systems */

    return true;

}
Esempio n. 2
0
static char *sk_handle_peer_info(Socket s)
{
    Handle_Socket ps = (Handle_Socket) s;
    ULONG pid;
    static HMODULE kernel32_module;
    DECL_WINDOWS_FUNCTION(static, BOOL, GetNamedPipeClientProcessId,
                          (HANDLE, PULONG));

    if (!kernel32_module) {
        kernel32_module = load_system32_dll("kernel32.dll");
#if (defined _MSC_VER && _MSC_VER < 1900) || defined __MINGW32__ || defined COVERITY
        /* For older Visual Studio, and MinGW too (at least as of
         * Ubuntu 16.04), this function isn't available in the header
         * files to type-check. Ditto the toolchain I use for
         * Coveritying the Windows code. */
        GET_WINDOWS_FUNCTION_NO_TYPECHECK(
            kernel32_module, GetNamedPipeClientProcessId);
#else
        GET_WINDOWS_FUNCTION(
            kernel32_module, GetNamedPipeClientProcessId);
#endif
    }

    /*
     * Of course, not all handles managed by this module will be
     * server ends of named pipes, but if they are, then it's useful
     * to log what we can find out about the client end.
     */
    if (p_GetNamedPipeClientProcessId &&
        p_GetNamedPipeClientProcessId(ps->send_H, &pid))
        return dupprintf("process id %lu", (unsigned long)pid);

    return NULL;
}
Esempio n. 3
0
bool got_crypt(void)
{
    static bool attempted = false;
    static bool successful;
    static HMODULE crypt;

    if (!attempted) {
        attempted = true;
        crypt = load_system32_dll("crypt32.dll");
        successful = crypt &&
#ifdef COVERITY
            /* The build toolchain I use with Coverity doesn't know
             * about this function, so can't type-check it */
            GET_WINDOWS_FUNCTION_NO_TYPECHECK(crypt, CryptProtectMemory)
#else
            GET_WINDOWS_FUNCTION(crypt, CryptProtectMemory)
#endif
            ;
    }
    return successful;
}
Esempio n. 4
0
void sk_init(void)
{
#ifndef NO_IPV6
    winsock2_module =
#endif
        winsock_module = load_system32_dll("ws2_32.dll");
    if (!winsock_module) {
	winsock_module = load_system32_dll("wsock32.dll");
    }
    if (!winsock_module)
	modalfatalbox("Unable to load any WinSock library");

#ifndef NO_IPV6
    /* Check if we have getaddrinfo in Winsock */
    if (GetProcAddress(winsock_module, "getaddrinfo") != NULL) {
	GET_WINDOWS_FUNCTION(winsock_module, getaddrinfo);
	GET_WINDOWS_FUNCTION(winsock_module, freeaddrinfo);
	GET_WINDOWS_FUNCTION(winsock_module, getnameinfo);
        /* This function would fail its type-check if we did one,
         * because the VS header file provides an inline definition
         * which is __cdecl instead of WINAPI. */
        GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, gai_strerror);
    } else {
	/* Fall back to wship6.dll for Windows 2000 */
	wship6_module = load_system32_dll("wship6.dll");
	if (wship6_module) {
	    GET_WINDOWS_FUNCTION(wship6_module, getaddrinfo);
	    GET_WINDOWS_FUNCTION(wship6_module, freeaddrinfo);
	    GET_WINDOWS_FUNCTION(wship6_module, getnameinfo);
            /* See comment above about type check */
            GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, gai_strerror);
	} else {
	}
    }
    GET_WINDOWS_FUNCTION(winsock2_module, WSAAddressToStringA);
#endif

    GET_WINDOWS_FUNCTION(winsock_module, WSAAsyncSelect);
    GET_WINDOWS_FUNCTION(winsock_module, WSAEventSelect);
    /* We don't type-check select because at least some MinGW versions
     * of the Windows API headers seem to disagree with the
     * documentation on whether the 'struct timeval *' pointer is
     * const or not. */
    GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, select);
    GET_WINDOWS_FUNCTION(winsock_module, WSAGetLastError);
    GET_WINDOWS_FUNCTION(winsock_module, WSAEnumNetworkEvents);
    GET_WINDOWS_FUNCTION(winsock_module, WSAStartup);
    GET_WINDOWS_FUNCTION(winsock_module, WSACleanup);
    GET_WINDOWS_FUNCTION(winsock_module, closesocket);
#ifndef COVERITY
    GET_WINDOWS_FUNCTION(winsock_module, ntohl);
    GET_WINDOWS_FUNCTION(winsock_module, htonl);
    GET_WINDOWS_FUNCTION(winsock_module, htons);
    GET_WINDOWS_FUNCTION(winsock_module, ntohs);
    GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, gethostname);
#else
    /* The toolchain I use for Windows Coverity builds doesn't know
     * the type signatures of these */
    GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, ntohl);
    GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, htonl);
    GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, htons);
    GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, ntohs);
    GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, gethostname);
#endif
    GET_WINDOWS_FUNCTION(winsock_module, gethostbyname);
    GET_WINDOWS_FUNCTION(winsock_module, getservbyname);
    GET_WINDOWS_FUNCTION(winsock_module, inet_addr);
    GET_WINDOWS_FUNCTION(winsock_module, inet_ntoa);
#if (defined _MSC_VER && _MSC_VER < 1900) || defined __MINGW32__
    /* Older Visual Studio, and MinGW as of Ubuntu 16.04, don't know
     * about this function at all, so can't type-check it */
    GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, inet_ntop);
#else
    GET_WINDOWS_FUNCTION(winsock_module, inet_ntop);
#endif
    GET_WINDOWS_FUNCTION(winsock_module, connect);
    GET_WINDOWS_FUNCTION(winsock_module, bind);
    GET_WINDOWS_FUNCTION(winsock_module, setsockopt);
    GET_WINDOWS_FUNCTION(winsock_module, socket);
    GET_WINDOWS_FUNCTION(winsock_module, listen);
    GET_WINDOWS_FUNCTION(winsock_module, send);
    GET_WINDOWS_FUNCTION(winsock_module, shutdown);
    GET_WINDOWS_FUNCTION(winsock_module, ioctlsocket);
    GET_WINDOWS_FUNCTION(winsock_module, accept);
    GET_WINDOWS_FUNCTION(winsock_module, getpeername);
    GET_WINDOWS_FUNCTION(winsock_module, recv);
    GET_WINDOWS_FUNCTION(winsock_module, WSAIoctl);

    /* Try to get the best WinSock version we can get */
    if (!sk_startup(2,2) &&
	!sk_startup(2,0) &&
	!sk_startup(1,1)) {
	modalfatalbox("Unable to initialise WinSock");
    }

    sktree = newtree234(cmpfortree);
}