From 3c81b7a4f2a918549b5fca8d690fa19713b10f90 Mon Sep 17 00:00:00 2001 From: Heiko Hund Date: Fri, 20 Jul 2012 11:55:10 +0200 Subject: [PATCH] support SOCKS 5 proxy auth notifications from mgmt --- openvpn.c | 6 +++++- options.h | 38 +++++++++++++++++++------------------- proxy.c | 22 +++++++++++++++++++--- proxy.h | 2 +- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/openvpn.c b/openvpn.c index 959f46d..8f65681 100644 --- a/openvpn.c +++ b/openvpn.c @@ -306,7 +306,11 @@ OnPassword(connection_t *c, char *msg) } else if (strstr(msg, "'HTTP Proxy'")) { - LocalizedDialogBoxParam(ID_DLG_PROXY_AUTH, ProxyAuthDialogFunc, (LPARAM) c); + QueryProxyAuth(c, http); + } + else if (strstr(msg, "'SOCKS Proxy'")) + { + QueryProxyAuth(c, socks); } } diff --git a/options.h b/options.h index 27781bd..280dc89 100644 --- a/options.h +++ b/options.h @@ -41,6 +41,24 @@ typedef struct connection connection_t; #define MAX_CONFIG_SUBDIRS 50 /* Max number of subdirs to scan for configs */ +typedef enum { + service_noaccess = -1, + service_disconnected = 0, + service_connecting = 1, + service_connected = 2 +} service_state_t; + +typedef enum { + config, + windows, + manual +} proxy_source_t; + +typedef enum { + http, + socks +} proxy_t; + /* connection states */ typedef enum { disconnected, @@ -63,6 +81,7 @@ struct connection { conn_state_t state; /* State the connection currently is in */ int failed_psw_attempts; /* # of failed attempts entering password(s) */ time_t connected_since; /* Time when the connection was established */ + proxy_t proxy_type; /* Set during querying proxy credentials */ struct { SOCKET sk; @@ -77,25 +96,6 @@ struct connection { HWND hwndStatus; }; - -typedef enum { - service_noaccess = -1, - service_disconnected = 0, - service_connecting = 1, - service_connected = 2 -} service_state_t; - -typedef enum { - config, - windows, - manual -} proxy_source_t; - -typedef enum { - http, - socks -} proxy_t; - /* All options used within OpenVPN GUI */ typedef struct { /* Array of configs to autostart */ diff --git a/proxy.c b/proxy.c index 8590f1e..957575f 100644 --- a/proxy.c +++ b/proxy.c @@ -324,10 +324,12 @@ GetProxyRegistrySettings() } -INT_PTR CALLBACK +static INT_PTR CALLBACK ProxyAuthDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + LPCSTR proxy_type; connection_t *c; + char fmt[32]; switch (msg) { @@ -342,8 +344,14 @@ ProxyAuthDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { case IDOK: c = (connection_t *) GetProp(hwndDlg, cfgProp); - ManagementCommandFromInput(c, "username \"HTTP Proxy\" \"%s\"", hwndDlg, ID_EDT_PROXY_USER); - ManagementCommandFromInput(c, "password \"HTTP Proxy\" \"%s\"", hwndDlg, ID_EDT_PROXY_PASS); + proxy_type = (c->proxy_type == http ? "HTTP" : "SOCKS"); + + snprintf(fmt, sizeof(fmt), "username \"%s Proxy\" \"%%s\"", proxy_type); + ManagementCommandFromInput(c, fmt, hwndDlg, ID_EDT_PROXY_USER); + + snprintf(fmt, sizeof(fmt), "password \"%s Proxy\" \"%%s\"", proxy_type); + ManagementCommandFromInput(c, fmt, hwndDlg, ID_EDT_PROXY_PASS); + EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; } @@ -361,6 +369,14 @@ ProxyAuthDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) } +void +QueryProxyAuth(connection_t *c, proxy_t type) +{ + c->proxy_type = type; + LocalizedDialogBoxParam(ID_DLG_PROXY_AUTH, ProxyAuthDialogFunc, (LPARAM) c); +} + + typedef enum { HTTPS_URL, SOCKS_URL } url_scheme; static LPCWSTR UrlSchemeStr(const url_scheme scheme) diff --git a/proxy.h b/proxy.h index 338ca6e..31f9861 100644 --- a/proxy.h +++ b/proxy.h @@ -23,7 +23,7 @@ #define PROXY_H INT_PTR CALLBACK ProxySettingsDialogFunc(HWND, UINT, WPARAM, LPARAM); -INT_PTR CALLBACK ProxyAuthDialogFunc(HWND, UINT, WPARAM, LPARAM); +void QueryProxyAuth(connection_t *, proxy_t); void OnProxy(connection_t *, char *);