2018-06-28 16:00:25 +02:00
|
|
|
/*
|
2019-01-09 15:45:48 +01:00
|
|
|
* Copyright 2018 Piotr Caban for CodeWeavers
|
2018-06-28 16:00:25 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
2019-06-06 09:01:46 +02:00
|
|
|
#include <winnls.h>
|
2018-06-28 16:00:25 +02:00
|
|
|
#include <wininet.h>
|
|
|
|
#include <winuser.h>
|
|
|
|
#include <winreg.h>
|
|
|
|
|
|
|
|
#include "inetcpl.h"
|
|
|
|
#include "wine/debug.h"
|
2018-06-28 16:02:45 +02:00
|
|
|
#include "wine/heap.h"
|
2018-06-28 16:00:25 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(inetcpl);
|
|
|
|
|
2020-11-15 23:11:23 +01:00
|
|
|
static const WCHAR internet_settings[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
|
2018-06-28 16:00:25 +02:00
|
|
|
|
|
|
|
static BOOL initdialog_done;
|
|
|
|
|
2018-06-28 16:02:45 +02:00
|
|
|
#define CONNECTION_SETTINGS_VERSION 0x46
|
2018-07-11 17:46:33 +02:00
|
|
|
#define CONNECTION_SETTINGS_MANUAL_PROXY 0x2
|
|
|
|
#define CONNECTION_SETTINGS_PAC_SCRIPT 0x4
|
|
|
|
#define CONNECTION_SETTINGS_WPAD 0x8
|
2018-06-28 16:02:45 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DWORD version;
|
|
|
|
DWORD id;
|
|
|
|
DWORD flags;
|
|
|
|
BYTE data[1];
|
|
|
|
/* DWORD proxy_server_len; */
|
|
|
|
/* UTF8 proxy_server[proxy_server_len]; */
|
|
|
|
/* DWORD bypass_list_len; */
|
|
|
|
/* UTF8 bypass_list[bypass_list_len]; */
|
|
|
|
/* DWORD configuration_script_len; */
|
|
|
|
/* UTF8 configuration_script[configuration_script_len]; */
|
|
|
|
/* DWORD unk[8]; set to 0 */
|
|
|
|
} connection_settings;
|
|
|
|
|
|
|
|
static DWORD create_connection_settings(BOOL manual_proxy, const WCHAR *proxy_server,
|
2018-07-11 17:46:33 +02:00
|
|
|
BOOL use_wpad, BOOL use_pac_script, const WCHAR *pac_url, connection_settings **ret)
|
2018-06-28 16:02:45 +02:00
|
|
|
{
|
|
|
|
DWORD size = FIELD_OFFSET(connection_settings, data), pos;
|
|
|
|
DWORD proxy_server_len;
|
2018-07-11 17:46:33 +02:00
|
|
|
DWORD pac_url_len;
|
2018-06-28 16:02:45 +02:00
|
|
|
|
|
|
|
size += sizeof(DWORD);
|
2021-09-15 12:25:06 +02:00
|
|
|
if(proxy_server)
|
2018-06-28 16:02:45 +02:00
|
|
|
{
|
|
|
|
proxy_server_len = WideCharToMultiByte(CP_UTF8, 0, proxy_server, -1,
|
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
if(!proxy_server_len) return 0;
|
|
|
|
proxy_server_len--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
proxy_server_len = 0;
|
|
|
|
size += proxy_server_len;
|
2018-07-11 17:46:33 +02:00
|
|
|
if(pac_url)
|
|
|
|
{
|
|
|
|
pac_url_len = WideCharToMultiByte(CP_UTF8, 0, pac_url, -1,
|
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
if(!pac_url_len) return 0;
|
|
|
|
pac_url_len--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pac_url_len = 0;
|
2018-06-28 16:02:45 +02:00
|
|
|
size += sizeof(DWORD)*10;
|
|
|
|
|
|
|
|
*ret = heap_alloc_zero(size);
|
|
|
|
if(!*ret) return 0;
|
|
|
|
|
|
|
|
(*ret)->version = CONNECTION_SETTINGS_VERSION;
|
|
|
|
(*ret)->flags = 1;
|
2018-07-11 17:46:33 +02:00
|
|
|
if(manual_proxy) (*ret)->flags |= CONNECTION_SETTINGS_MANUAL_PROXY;
|
|
|
|
if(use_pac_script) (*ret)->flags |= CONNECTION_SETTINGS_PAC_SCRIPT;
|
|
|
|
if(use_wpad) (*ret)->flags |= CONNECTION_SETTINGS_WPAD;
|
2018-06-28 16:02:45 +02:00
|
|
|
((DWORD*)(*ret)->data)[0] = proxy_server_len;
|
|
|
|
pos = sizeof(DWORD);
|
|
|
|
if(proxy_server_len)
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, proxy_server, -1,
|
|
|
|
(char*)(*ret)->data+pos, proxy_server_len, NULL, NULL);
|
|
|
|
pos += proxy_server_len;
|
|
|
|
}
|
2018-07-11 17:46:33 +02:00
|
|
|
pos += sizeof(DWORD); /* skip proxy bypass list */
|
|
|
|
((DWORD*)((*ret)->data+pos))[0] = pac_url_len;
|
|
|
|
pos += sizeof(DWORD);
|
|
|
|
if(pac_url_len)
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, pac_url, -1,
|
|
|
|
(char*)(*ret)->data+pos, pac_url_len, NULL, NULL);
|
|
|
|
pos += pac_url_len;
|
|
|
|
}
|
2018-06-28 16:02:45 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-06-28 16:00:25 +02:00
|
|
|
static void connections_on_initdialog(HWND hwnd)
|
|
|
|
{
|
|
|
|
DWORD type, size, enabled;
|
|
|
|
WCHAR address[INTERNET_MAX_URL_LENGTH], *port;
|
2018-07-11 17:46:33 +02:00
|
|
|
WCHAR pac_url[INTERNET_MAX_URL_LENGTH];
|
|
|
|
HKEY hkey, con;
|
2018-06-28 16:00:25 +02:00
|
|
|
LONG res;
|
|
|
|
|
2018-07-11 17:46:33 +02:00
|
|
|
SendMessageW(GetDlgItem(hwnd, IDC_EDIT_PAC_SCRIPT),
|
|
|
|
EM_LIMITTEXT, INTERNET_MAX_URL_LENGTH, 0);
|
2018-06-28 16:00:25 +02:00
|
|
|
SendMessageW(GetDlgItem(hwnd, IDC_EDIT_PROXY_SERVER),
|
|
|
|
EM_LIMITTEXT, INTERNET_MAX_URL_LENGTH-10, 0);
|
|
|
|
SendMessageW(GetDlgItem(hwnd, IDC_EDIT_PROXY_PORT), EM_LIMITTEXT, 8, 0);
|
|
|
|
|
|
|
|
res = RegOpenKeyW(HKEY_CURRENT_USER, internet_settings, &hkey);
|
|
|
|
if(res)
|
|
|
|
return;
|
|
|
|
|
|
|
|
size = sizeof(enabled);
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegQueryValueExW(hkey, L"ProxyEnable", NULL, &type, (BYTE*)&enabled, &size);
|
2018-06-28 16:00:25 +02:00
|
|
|
if(res || type != REG_DWORD)
|
|
|
|
enabled = 0;
|
|
|
|
size = sizeof(address);
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegQueryValueExW(hkey, L"ProxyServer", NULL, &type, (BYTE*)address, &size);
|
2018-06-28 16:00:25 +02:00
|
|
|
if(res || type != REG_SZ)
|
|
|
|
address[0] = 0;
|
2018-07-11 17:46:33 +02:00
|
|
|
size = sizeof(pac_url);
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegQueryValueExW(hkey, L"AutoConfigURL", NULL, &type, (BYTE*)pac_url, &size);
|
2018-07-11 17:46:33 +02:00
|
|
|
if(res || type != REG_SZ)
|
|
|
|
pac_url[0] = 0;
|
|
|
|
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegOpenKeyW(hkey, L"Connections", &con);
|
2018-06-28 16:00:25 +02:00
|
|
|
RegCloseKey(hkey);
|
2018-07-11 17:46:33 +02:00
|
|
|
if(!res)
|
|
|
|
{
|
|
|
|
connection_settings *settings = NULL;
|
|
|
|
size = 0;
|
|
|
|
|
2020-11-15 23:11:23 +01:00
|
|
|
while((res = RegQueryValueExW(con, L"DefaultConnectionSettings", NULL, &type,
|
2018-07-11 17:46:33 +02:00
|
|
|
(BYTE*)settings, &size)) == ERROR_MORE_DATA || !settings)
|
|
|
|
{
|
|
|
|
connection_settings *new_settings = heap_realloc(settings, size);
|
|
|
|
if(!new_settings)
|
|
|
|
{
|
|
|
|
RegCloseKey(con);
|
|
|
|
heap_free(settings);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
settings = new_settings;
|
|
|
|
}
|
|
|
|
RegCloseKey(con);
|
|
|
|
|
|
|
|
if(!res && type == REG_BINARY)
|
|
|
|
{
|
|
|
|
if(settings->version != CONNECTION_SETTINGS_VERSION)
|
2022-02-11 08:40:29 +01:00
|
|
|
FIXME("unexpected structure version (%lx)\n", settings->version);
|
2018-07-11 17:46:33 +02:00
|
|
|
else if(settings->flags & CONNECTION_SETTINGS_WPAD)
|
|
|
|
CheckDlgButton(hwnd, IDC_USE_WPAD, BST_CHECKED);
|
|
|
|
}
|
|
|
|
heap_free(settings);
|
|
|
|
}
|
2018-06-28 16:00:25 +02:00
|
|
|
|
2022-02-11 08:40:29 +01:00
|
|
|
TRACE("ProxyEnable = %lx\n", enabled);
|
2018-06-28 16:00:25 +02:00
|
|
|
TRACE("ProxyServer = %s\n", wine_dbgstr_w(address));
|
2020-11-15 23:11:22 +01:00
|
|
|
TRACE("AutoConfigURL = %s\n", wine_dbgstr_w(pac_url));
|
2018-06-28 16:00:25 +02:00
|
|
|
|
|
|
|
if(enabled)
|
|
|
|
{
|
|
|
|
CheckDlgButton(hwnd, IDC_USE_PROXY_SERVER, BST_CHECKED);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_EDIT_PROXY_SERVER), TRUE);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_EDIT_PROXY_PORT), TRUE);
|
|
|
|
}
|
|
|
|
|
2019-06-06 09:01:46 +02:00
|
|
|
port = wcschr(address, ':');
|
2018-06-28 16:00:25 +02:00
|
|
|
if(port)
|
|
|
|
{
|
|
|
|
*port = 0;
|
|
|
|
port++;
|
|
|
|
}
|
|
|
|
SetDlgItemTextW(hwnd, IDC_EDIT_PROXY_SERVER, address);
|
|
|
|
if(port)
|
|
|
|
SetDlgItemTextW(hwnd, IDC_EDIT_PROXY_PORT, port);
|
|
|
|
|
2018-07-11 17:46:33 +02:00
|
|
|
if(pac_url[0])
|
|
|
|
{
|
|
|
|
CheckDlgButton(hwnd, IDC_USE_PAC_SCRIPT, BST_CHECKED);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_EDIT_PAC_SCRIPT), TRUE);
|
|
|
|
SetDlgItemTextW(hwnd, IDC_EDIT_PAC_SCRIPT, pac_url);
|
|
|
|
}
|
|
|
|
|
2018-06-28 16:00:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR connections_on_command(HWND hwnd, WPARAM wparam)
|
|
|
|
{
|
|
|
|
BOOL checked;
|
|
|
|
|
|
|
|
switch (wparam)
|
|
|
|
{
|
2018-07-11 17:46:33 +02:00
|
|
|
case IDC_USE_PAC_SCRIPT:
|
|
|
|
checked = IsDlgButtonChecked(hwnd, IDC_USE_PAC_SCRIPT);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_EDIT_PAC_SCRIPT), checked);
|
|
|
|
break;
|
2018-06-28 16:00:25 +02:00
|
|
|
case IDC_USE_PROXY_SERVER:
|
|
|
|
checked = IsDlgButtonChecked(hwnd, IDC_USE_PROXY_SERVER);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_EDIT_PROXY_SERVER), checked);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_EDIT_PROXY_PORT), checked);
|
2018-07-11 17:46:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (wparam)
|
|
|
|
{
|
|
|
|
case IDC_USE_WPAD:
|
|
|
|
case IDC_USE_PAC_SCRIPT:
|
|
|
|
case IDC_USE_PROXY_SERVER:
|
|
|
|
case MAKEWPARAM(IDC_EDIT_PAC_SCRIPT, EN_CHANGE):
|
2018-06-28 16:00:25 +02:00
|
|
|
case MAKEWPARAM(IDC_EDIT_PROXY_SERVER, EN_CHANGE):
|
|
|
|
case MAKEWPARAM(IDC_EDIT_PROXY_PORT, EN_CHANGE):
|
|
|
|
if(initdialog_done)
|
|
|
|
SendMessageW(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR connections_on_notify(HWND hwnd, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
2018-06-28 16:02:45 +02:00
|
|
|
connection_settings *default_connection;
|
2018-07-11 17:46:33 +02:00
|
|
|
WCHAR proxy[INTERNET_MAX_URL_LENGTH];
|
|
|
|
WCHAR pac_script[INTERNET_MAX_URL_LENGTH];
|
2018-06-28 16:00:25 +02:00
|
|
|
PSHNOTIFY *psn = (PSHNOTIFY*)lparam;
|
2018-07-11 17:46:33 +02:00
|
|
|
DWORD proxy_len, port_len, pac_script_len;
|
|
|
|
DWORD use_proxy, use_pac_script, use_wpad, size;
|
2018-06-28 16:00:25 +02:00
|
|
|
LRESULT res;
|
2018-06-28 16:02:45 +02:00
|
|
|
HKEY hkey, con;
|
2018-06-28 16:00:25 +02:00
|
|
|
|
|
|
|
if(psn->hdr.code != PSN_APPLY)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
res = RegOpenKeyW(HKEY_CURRENT_USER, internet_settings, &hkey);
|
|
|
|
if(res)
|
|
|
|
return FALSE;
|
|
|
|
|
2018-07-11 17:46:33 +02:00
|
|
|
use_proxy = IsDlgButtonChecked(hwnd, IDC_USE_PROXY_SERVER);
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegSetValueExW(hkey, L"ProxyEnable", 0, REG_DWORD,
|
2018-07-11 17:46:33 +02:00
|
|
|
(BYTE*)&use_proxy, sizeof(use_proxy));
|
2018-06-28 16:00:25 +02:00
|
|
|
if(res)
|
|
|
|
{
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2022-02-11 08:40:29 +01:00
|
|
|
TRACE("ProxyEnable set to %lx\n", use_proxy);
|
2018-06-28 16:00:25 +02:00
|
|
|
|
2018-07-20 21:45:46 +02:00
|
|
|
proxy_len = GetDlgItemTextW(hwnd, IDC_EDIT_PROXY_SERVER, proxy, ARRAY_SIZE(proxy));
|
2018-07-11 17:46:33 +02:00
|
|
|
if(proxy_len)
|
2018-06-28 16:00:25 +02:00
|
|
|
{
|
2018-07-11 17:46:33 +02:00
|
|
|
proxy[proxy_len++] = ':';
|
2018-07-20 21:45:46 +02:00
|
|
|
port_len = GetDlgItemTextW(hwnd, IDC_EDIT_PROXY_PORT, proxy+proxy_len,
|
|
|
|
ARRAY_SIZE(proxy)-proxy_len);
|
2018-06-28 16:00:25 +02:00
|
|
|
if(!port_len)
|
|
|
|
{
|
2018-07-11 17:46:33 +02:00
|
|
|
proxy[proxy_len++] = '8';
|
|
|
|
proxy[proxy_len++] = '0';
|
|
|
|
proxy[proxy_len] = 0;
|
2018-06-28 16:00:25 +02:00
|
|
|
}
|
|
|
|
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegSetValueExW(hkey, L"ProxyServer", 0, REG_SZ,
|
2018-07-11 17:46:33 +02:00
|
|
|
(BYTE*)proxy, (proxy_len+port_len)*sizeof(WCHAR));
|
2018-06-28 16:00:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegDeleteValueW(hkey, L"ProxyServer");
|
2018-06-28 16:00:25 +02:00
|
|
|
if(res == ERROR_FILE_NOT_FOUND)
|
|
|
|
res = ERROR_SUCCESS;
|
|
|
|
}
|
2018-06-28 16:02:45 +02:00
|
|
|
if(res)
|
|
|
|
{
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-07-11 17:46:33 +02:00
|
|
|
TRACE("ProxtServer set to %s\n", wine_dbgstr_w(proxy));
|
|
|
|
|
|
|
|
use_pac_script = IsDlgButtonChecked(hwnd, IDC_USE_PAC_SCRIPT);
|
|
|
|
pac_script_len = GetDlgItemTextW(hwnd, IDC_EDIT_PAC_SCRIPT,
|
2018-07-20 21:45:46 +02:00
|
|
|
pac_script, ARRAY_SIZE(pac_script));
|
2018-07-11 17:46:33 +02:00
|
|
|
if(!pac_script_len) use_pac_script = FALSE;
|
|
|
|
if(use_pac_script)
|
|
|
|
{
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegSetValueExW(hkey, L"AutoConfigURL", 0, REG_SZ,
|
2018-07-11 17:46:33 +02:00
|
|
|
(BYTE*)pac_script, pac_script_len*sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegDeleteValueW(hkey, L"AutoConfigURL");
|
2018-07-11 17:46:33 +02:00
|
|
|
if(res == ERROR_FILE_NOT_FOUND)
|
|
|
|
res = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
if(res)
|
|
|
|
{
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
TRACE("AutoConfigURL set to %s\n", wine_dbgstr_w(use_pac_script ? pac_script : NULL));
|
|
|
|
|
|
|
|
use_wpad = IsDlgButtonChecked(hwnd, IDC_USE_WPAD);
|
2018-06-28 16:02:45 +02:00
|
|
|
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegCreateKeyExW(hkey, L"Connections", 0, NULL, 0, KEY_WRITE, NULL, &con, NULL);
|
2018-06-28 16:00:25 +02:00
|
|
|
RegCloseKey(hkey);
|
2018-06-28 16:02:45 +02:00
|
|
|
if(res)
|
|
|
|
return FALSE;
|
|
|
|
|
2018-07-11 17:46:33 +02:00
|
|
|
size = create_connection_settings(use_proxy, proxy, use_wpad,
|
|
|
|
use_pac_script, pac_script, &default_connection);
|
2018-06-28 16:02:45 +02:00
|
|
|
if(!size)
|
|
|
|
{
|
|
|
|
RegCloseKey(con);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-11-15 23:11:23 +01:00
|
|
|
res = RegSetValueExW(con, L"DefaultConnectionSettings", 0, REG_BINARY,
|
2018-06-28 16:02:45 +02:00
|
|
|
(BYTE*)default_connection, size);
|
|
|
|
heap_free(default_connection);
|
|
|
|
RegCloseKey(con);
|
2018-06-28 16:00:25 +02:00
|
|
|
return !res;
|
|
|
|
}
|
|
|
|
|
|
|
|
INT_PTR CALLBACK connections_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
connections_on_initdialog(hwnd);
|
|
|
|
initdialog_done = TRUE;
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
return connections_on_command(hwnd, wparam);
|
|
|
|
case WM_NOTIFY:
|
|
|
|
return connections_on_notify(hwnd, wparam, lparam);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|