Skip to contentSkip to conversation

better --auto-proxy support for Windows

PATCH In review Heiko Hund 3 participants 12 messages Aug 17, 2011 – Sep 13, 2011 Kbuild

lore
Share & tools
lore

Heiko Hund

author
#0 lore raw

cover better --auto-proxy support for Windows

Hi,

the auto-proxy support for Windows was rather sub-optimal. Since Internet Explorer 5 proxy settings were configured with the network or VPN connection, but OpenVPN always queried the settings for the LAN connection. Truely automatic proxy configuration via WPAD and PAC script was not used, either.

This patch series tries to change that. Auto proxy detetction is done with WinHTTP which has support for WPAD, PAC and per connection proxy settings.

Another thing that is changed is the time at which the auto proxy config takes place in OpenVPN. Instead of doing it once during start-up, potentially changed settings are now fetched once every connect.

Heiko Hund (3):
add MinGW WinHTTP compatibility layer
do automatic proxy detection on Windows right
query auto-proxy information when connecting

 configure.ac |   30 ++++++++++
 init.c       |   23 ++++++-
 openvpn.8    |    9 ++-
 options.c    |   15 ++---
 options.h    |    2 +-
 proxy.c      |  173 +++++++++++++++++++++++++++++++++-------------------------
 proxy.h      |    4 +-
 win32.c      |  108 ++++++++++++++++++++++++++++++++++++
 win32.h      |   61 ++++++++++++++++++++
 9 files changed, 330 insertions(+), 95 deletions(-)

Regards
Heiko

Signature · 1 line
1.7.5.4
author
#1 lore raw

PATCH 1/3 add MinGW WinHTTP compatibility layer

MinGW is missing support for winhttp.dll which will be used for automatic proxy server detection in Windows. Until it becomes available the workaround performed is to provide wrapper functions and dynamically map the missing library into the address space, get the function pointer for the actual API and call it with the arguments provided.

To keep things managable and short in the source code two preprocessor macros are defined that do most of the work.

---
 configure.ac |   30 ++++++++++++++++
 win32.c      |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 win32.h      |   61 ++++++++++++++++++++++++++++++++
 3 files changed, 199 insertions(+), 0 deletions(-)
configure.ac +30 -0
index a3789d9..42d46cb 100644
@@ -665,6 +665,36 @@ if test "${WIN32}" = "yes"; then
 fi
 
 dnl
+dnl Check if MinGW knows about WinHTTP API
+dnl
+if test "${WIN32}" = "yes"; then
+   AC_MSG_CHECKING([if MinGW knows about WinHTTP])
+   AC_TRY_LINK([
+       #include <windows.h>
+       #include <winhttp.h>
+     ], [
+       LPWSTR *url;
+       HINTERNET session;
+       WINHTTP_PROXY_INFO proxy_info;
+       WINHTTP_AUTOPROXY_OPTIONS proxy_options;
+       WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_proxy_info;
+
+       WinHttpGetDefaultProxyConfiguration (&proxy_info);
+       WinHttpGetIEProxyConfigForCurrentUser (&ie_proxy_info);
+       WinHttpDetectAutoProxyConfigUrl (WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A, url);
+       session = WinHttpOpen (NULL, WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
+       WinHttpGetProxyForUrl (session, L"http://openvpn.net", &proxy_options, &proxy_info);
+       WinHttpCloseHandle (session);
+     ], [
+       AC_MSG_RESULT([yes])
+     ], [
+       AC_MSG_RESULT([no.])
+       AC_MSG_NOTICE([Enabling WinHTTP compatibility layer.])
+       AC_DEFINE(USE_WINHTTP_COMPAT, 1, [Use the WinHTTP compatibility layer])
+     ])
+fi
+
+dnl
 dnl check for LZO library
 dnl
 
win32.c +108 -0

112 lines not on this page · raw message

win32.h +61 -0

66 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#2 lore raw

Re: [Openvpn-devel] [PATCH 1/3] add MinGW WinHTTP compatibility layer

These macros are soooooooo ugly!
why not do this simply like other examples in OpenVPN code, if I recall correctly in CryptoAPI module.

Quoted 259 lines · Heiko Hund

MinGW is missing support for winhttp.dll which will be used for automatic proxy server detection in Windows. Until it becomes available the workaround performed is to provide wrapper functions and dynamically map the missing library into the address space, get the function pointer for the actual API and call it with the arguments provided.

To keep things managable and short in the source code two preprocessor macros are defined that do most of the work.

---
 configure.ac |   30 ++++++++++++++++
 win32.c      |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ win32.h      |   61 ++++++++++++++++++++++++++++++++

 3 files changed, 199 insertions(+), 0 deletions(-)
configure.ac +0 -0
index a3789d9..42d46cb 100644
@@ -665,6 +665,36 @@ if test "${WIN32}" = "yes"; then

 fi

 dnl

configure.ac +30 -0
+dnl Check if MinGW knows about WinHTTP API
+dnl
+if test "${WIN32}" = "yes"; then
+   AC_MSG_CHECKING([if MinGW knows about WinHTTP])
+   AC_TRY_LINK([
+       #include <windows.h>
+       #include <winhttp.h>
+     ], [
+       LPWSTR *url;
+       HINTERNET session;
+       WINHTTP_PROXY_INFO proxy_info;
+       WINHTTP_AUTOPROXY_OPTIONS proxy_options;
+       WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_proxy_info;
+
+       WinHttpGetDefaultProxyConfiguration (&proxy_info);
+       WinHttpGetIEProxyConfigForCurrentUser (&ie_proxy_info);
+       WinHttpDetectAutoProxyConfigUrl (WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A, url);
+       session = WinHttpOpen (NULL, WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
+       WinHttpGetProxyForUrl (session, L"http://openvpn.net", &proxy_options, &proxy_info);
+       WinHttpCloseHandle (session);
+     ], [
+       AC_MSG_RESULT([yes])
+     ], [
+       AC_MSG_RESULT([no.])
+       AC_MSG_NOTICE([Enabling WinHTTP compatibility layer.])
+       AC_DEFINE(USE_WINHTTP_COMPAT, 1, [Use the WinHTTP compatibility layer])
+     ])
+fi
+
+dnl

 dnl check for LZO library
 dnl

win32.c +108 -0
index cf6cc2d..15743a8 100644
@@ -1128,4 +1128,112 @@ win_get_tempdir()
   }
   return tmpdir;
  }
+
+
+#ifdef USE_WINHTTP_COMPAT
+
+/*
+ * MinGW is missing support for winhttp.dll which is used for automatic
+ * proxy server detection. Until it becomes available the workaround is
+ * to dynamically map the library into the address space and get the
+ * function pointers for the APIs that are used. The two macros below
+ * do just that.
+ *
+ * PROVIDE_WIN32_LIBRARY provides means to access API functions.
+ *     Arguments: LIB - name of the DLL to load
+ *
+ * DEFINE_WIN32_WRAPPER defines a wrapper function around the
+ * original API provoded by the library. The original API can
+ * be accessed within the wrapper as <LIB>_<FUNC> (see Arguments).
+ *     Arguments: LIB   name of the DLL the function is exported in
+ *                ERR   value to return in case something goes wrong
+ *                RET   API function's return value type
+ *                FUNC  exported name of the API function
+ *                ARGS  declaration of the API function arguments
+ *                BODY  the wrapper function's body
+ */
+
+#define PROVIDE_WIN32_LIBRARY(LIB)                                    \
+  static HMODULE get_ ## LIB ## _library ()                           \
+  {                                                                   \
+    static HMODULE lib = NULL;                                        \
+                                                                      \
+    if (lib == NULL)                                                  \
+      {                                                               \
+       char name[MAX_PATH];                                          \
+       UINT len = GetSystemDirectory (name, sizeof (name));          \
+       if (len == 0)                                                 \
+         return NULL;                                                \
+                                                                      \
+       strncpy (name + len, "\\" #LIB ".dll", sizeof (name) - len);  \
+       name[sizeof (name) - 1] = '\0';                               \
+                                                                      \
+       lib = LoadLibrary (name);                                     \
+      }                                                               \
+                                                                      \
+    return lib;                                                       \
+  }
+
+#define DEFINE_WIN32_WRAPPER(LIB, ERR, RET, FUNC, ARGS, BODY)  \
+  RET FUNC ARGS                                                \
+  {                                                            \
+    typedef RET (WINAPI *(FUNC ## _fn)) ARGS;                  \
+    static FUNC ## _fn  LIB ## _ ## FUNC = NULL;               \
+                                                               \
+    if ((LIB ## _ ## FUNC) == NULL)                            \
+      {                                                        \
+       union {                                                \
+         FUNC ## _fn *type;                                   \
+         FARPROC *ptr;                                        \
+       } u = { .type = &(LIB ## _ ## FUNC) };                 \
+                                                               \
+       HMODULE lib = get_ ## LIB ## _library ();              \
+       if (lib == NULL)                                       \
+         return (ERR);                                        \
+                                                               \
+       *(u.ptr) = GetProcAddress (lib, (#FUNC));              \
+       if ((LIB ## _ ## FUNC) == NULL)                        \
+         return (ERR);                                        \
+      }                                                        \
+                                                               \
+    BODY                                                       \
+  }
+
+
+PROVIDE_WIN32_LIBRARY (winhttp)
+
+DEFINE_WIN32_WRAPPER (winhttp, NULL, HINTERNET,
+WinHttpOpen, (LPCWSTR user_agent, DWORD access_type, LPCWSTR proxy, LPCWSTR bypass, DWORD flags),
+  return winhttp_WinHttpOpen (user_agent, access_type, proxy, bypass, flags);
+)
+
+DEFINE_WIN32_WRAPPER (winhttp, FALSE, BOOL,
+WinHttpCloseHandle, (HINTERNET session),
+  return winhttp_WinHttpCloseHandle (session);
+)
+
+DEFINE_WIN32_WRAPPER (winhttp, FALSE, BOOL,
+WinHttpGetDefaultProxyConfiguration, (WINHTTP_PROXY_INFO *proxy_info),
+  return winhttp_WinHttpGetDefaultProxyConfiguration (proxy_info);
+)
+
+DEFINE_WIN32_WRAPPER (winhttp, FALSE, BOOL,
+WinHttpGetIEProxyConfigForCurrentUser, (WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *proxy_config),
+  return winhttp_WinHttpGetIEProxyConfigForCurrentUser(proxy_config);
+)
+
+DEFINE_WIN32_WRAPPER (winhttp, FALSE, BOOL,
+WinHttpDetectAutoProxyConfigUrl, (DWORD flags, LPWSTR *url),
+  return winhttp_WinHttpDetectAutoProxyConfigUrl (flags, url);
+)
+
+DEFINE_WIN32_WRAPPER (winhttp, FALSE, BOOL,
+WinHttpGetProxyForUrl, (HINTERNET session, LPCWSTR url,
+                       WINHTTP_AUTOPROXY_OPTIONS *options,
+                       WINHTTP_PROXY_INFO *proxy_info),
+  return winhttp_WinHttpGetProxyForUrl (session, url, options, proxy_info);
+)
+
+#endif /* USE_WINHTTP_COMPAT */
+
  #endif
win32.h +61 -1
index 87d8ecc..2ff4b8c 100644
@@ -288,5 +288,66 @@ int inet_pton(int af, const char *src, void *st);
  /* Find temporary directory */
  const char *win_get_tempdir();
 
+/*
+ * If MinGW does not know about the WinHTTP C API functions and
+ * constants that are used for automatic proxy server detection
+ * they are declared here. For detailed information see:
+ * http://msdn.microsoft.com/en-us/library/aa384252%28v=VS.85%29.aspx
+ */
+#ifdef USE_WINHTTP_COMPAT
+
+#include <windows.h>
+#include <wininet.h>
+
+/* WINHTTP_PROXY_INFO dwAccessType constants */
+/* and WinHttpOpen() access_type             */
+#define WINHTTP_ACCESS_TYPE_NO_PROXY     1
+#define WINHTTP_ACCESS_TYPE_NAMED_PROXY  3
+
+/* WinHttpDetectAutoProxyConfigUrl() flags */
+#define WINHTTP_AUTO_DETECT_TYPE_DHCP   1
+#define WINHTTP_AUTO_DETECT_TYPE_DNS_A  2
+
+/* WINHTTP_AUTOPROXY_OPTIONS dwFlags */
+#define WINHTTP_AUTOPROXY_CONFIG_URL   2
+
+/* WinHttpOpen() proxy and bypass values */
+#define WINHTTP_NO_PROXY_NAME    0
+#define WINHTTP_NO_PROXY_BYPASS  0
+
+typedef struct {
+  DWORD  dwAccessType;
+  LPWSTR lpszProxy;
+  LPWSTR lpszProxyBypass;
+} WINHTTP_PROXY_INFO;
+
+typedef struct {
+  BOOL   fAutoDetect;
+  LPWSTR lpszAutoConfigUrl;
+  LPWSTR lpszProxy;
+  LPWSTR lpszProxyBypass;
+} WINHTTP_CURRENT_USER_IE_PROXY_CONFIG;
+
+typedef struct {
+  DWORD   dwFlags;
+  DWORD   dwAutoDetectFlags;
+  LPCWSTR lpszAutoConfigUrl;
+  LPVOID  lpvReserved;
+  DWORD   dwReserved;
+  BOOL    fAutoLogonIfChallenged;
+} WINHTTP_AUTOPROXY_OPTIONS;
+
+HINTERNET WinHttpOpen (LPCWSTR user_agent, DWORD access_type,
+                      LPCWSTR proxy, LPCWSTR bypass, DWORD flags);
+BOOL WinHttpCloseHandle (HINTERNET session);
+BOOL WinHttpGetDefaultProxyConfiguration (WINHTTP_PROXY_INFO *proxy_info);
+BOOL WinHttpGetIEProxyConfigForCurrentUser (WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *proxy_config);
+BOOL WinHttpDetectAutoProxyConfigUrl (DWORD flags, LPWSTR *url);
+BOOL WinHttpGetProxyForUrl (HINTERNET session, LPCWSTR url,
+                           WINHTTP_AUTOPROXY_OPTIONS *options,
+                           WINHTTP_PROXY_INFO *proxy_info);
+
+#endif /* USE_WINHTTP_COMPAT */
+
  #endif
  #endif
--

1.7.5.4

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, user administration capabilities and model configuration. Take the hassle out of deploying and managing Subversion and the tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#3 lore raw

Re: [Openvpn-devel] [PATCH 1/3] add MinGW WinHTTP compatibility layer

Quoted 1 line · Alon Bar-Lev

These macros are soooooooo ugly!

I tend to agree; had to read the code closely. But this hack was cool:

union {
FUNC ## _fn *type;
FARPROC *ptr;
} u = { .type = &(LIB ## _ ## FUNC) };
...
*(u.ptr) = GetProcAddress (lib, (#FUNC));

Where did you get that Heiko?

--gv

author
#4 lore raw

Re: [Openvpn-devel] [PATCH 1/3] add MinGW WinHTTP compatibility layer

Quoted 4 lines · On Wednesday 17 August 2011 16:28:42 Gisle Vanem wrote:
Quoted 1 line · Alon Bar-Lev

These macros are soooooooo ugly!

I tend to agree; had to read the code closely.

I tend to disagree. =)

Using macros here makes the code more readable. And managable. Imaging if there'll be another 20 functions to wrap. The result without macros would be a plain mess. I agree however that this whole construct is weird, but I guess that's what you get when you used unsupported APIs.

The way the library is loaded in cryptoapi.c opens a dll hijacking security hole, btw. See http://www.microsoft.com/technet/security/advisory/2269637.mspx
and now imagine this being done in many different places many different ways. I know some people are generally allergic to macros, but reconsider for this situation please.

Besides that if the hack in cryptoapi.c would have been done right it would not pose a threat anymore as MinGW knows CryptAcquireCertificatePrivateKey by now. I'll post a patch that removes that hunk later.

Quoted 10 lines

But this hack was cool:

union {
FUNC ## _fn *type;
FARPROC *ptr;
} u = { .type = &(LIB ## _ ## FUNC) };
...
*(u.ptr) = GetProcAddress (lib, (#FUNC));

Where did you get that Heiko?

author
#5 lore raw

PATCH 1/1 add MinGW WinHTTP compatibility import library

In reply to Heiko Hund

MinGW is missing support for winhttp.dll which will be used for automatic proxy server detection in Windows. Until it becomes available the workaround performed is to define the used constants and function prototypes in openvpn and build a WINHTTP.dll import library in the build process.

---
 Makefile.am   |   15 +++++++++++++
 configure.ac  |   53 ++++++++++++++++++++++++++++++++++++++++++++++
 win32.c       |    2 +
 win32.h       |   65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 winhttp32.def |    8 +++++++
 winhttp64.def |    8 +++++++
 6 files changed, 151 insertions(+), 0 deletions(-)
 create mode 100644 winhttp32.def
 create mode 100644 winhttp64.def
Makefile.am +15 -0
index 266a5af..b1c0a1b 100644
@@ -74,6 +74,8 @@ dist_noinst_DATA = \
 	openvpn.spec \
 	COPYRIGHT.GPL \
 	PORTS \
+	winhttp32.def \
+	winhttp64.def \
 	INSTALL-win32.txt \
 	service-win32/msvc.mak
 
@@ -163,3 +165,16 @@ openvpn.8.html: $(srcdir)/openvpn.8
 else
 dist_man_MANS = openvpn.8
 endif
+
+if BUILD_WINHTTP_IMPLIB
+openvpn_LDADD = libwinhttp.a
+
+if WIN64
+libwinhttp.a: winhttp64.def
+	$(DLLTOOL) -k -d winhttp64.def -l libwinhttp.a
+else
+libwinhttp.a: winhttp32.def
+	$(DLLTOOL) -k -d winhttp32.def -l libwinhttp.a
+endif
+
+endif
configure.ac +53 -0

71 lines not on this page · raw message

win32.c +2 -0
index cf6cc2d..9f150e9 100644
@@ -1128,4 +1128,6 @@ win_get_tempdir()
   }
   return tmpdir;
 }
+
+
 #endif
win32.h +65 -0

70 lines not on this page · raw message

winhttp32.def new file +8 -0
new file mode 100644
index 0000000..4be9274
@@ -0,0 +1,8 @@
+LIBRARY "WINHTTP.dll"
+EXPORTS
[email protected]...
[email protected]...
[email protected]...
[email protected]...
[email protected]...
[email protected]...
winhttp64.def new file +8 -0
new file mode 100644
index 0000000..dd8cc9b
@@ -0,0 +1,8 @@
+LIBRARY "WINHTTP.dll"
+EXPORTS
+WinHttpCloseHandle
+WinHttpDetectAutoProxyConfigUrl
+WinHttpGetDefaultProxyConfiguration
+WinHttpGetIEProxyConfigForCurrentUser
+WinHttpGetProxyForUrl
+WinHttpOpen
Signature · 1 line
1.7.5.4
author
#6 lore raw

PATCH 2/3 do automatic proxy detection on Windows right

In reply to Heiko Hund

Automatic proxy detection is now done using WinHTTP and its built in support for WPAD and PAC. This also means that settings for the currently active network connection are queried, instead of using the default one all the time.

If WPAD or a PAC script are not configured or fail, the static Internet Options proxy settings from the Control Panel are taken into account. If those are unavailable as well, the default proxy configuration, set with proxycfg.exe, is used.

Closes ticket #24.

---
 openvpn.8 |    9 ++--
 options.c |    9 ++--
 proxy.c   |  173 ++++++++++++++++++++++++++++++++++--------------------------
 proxy.h   |    4 +-
 4 files changed, 110 insertions(+), 85 deletions(-)
openvpn.8 +5 -4
index 7118737..3855e86 100644
@@ -490,13 +490,14 @@ If the HTTP proxy server requires a password, it will be queried from
 stdin or the management interface.  If the underlying OS doesn't support an API for
 returning proxy settings, a direct connection will be attempted.
 Currently, only Windows clients support this option via the
-InternetQueryOption API.
+WinHTTP API.
 This option exists in OpenVPN 2.1 or higher.
 .\"*********************************************************
 .TP
-.B \-\-show-proxy-settings
-Show sensed HTTP or SOCKS proxy settings. Currently, only Windows clients
-support this option.
+.B \-\-show-proxy-settings [url]
+Show sensed HTTP or SOCKS proxy settings. The optional URL parameter is used
+with the PAC script, if there is one detected or configured. Currently, only
+Windows clients support this option.
 .\"*********************************************************
 .TP
 .B \-\-http-proxy server port [authfile|'auto'|'auto-nct'] [auth-method]
options.c +5 -4
index 77e7c7f..62c2ac8 100644
@@ -118,7 +118,7 @@ static const char usage_message[] =
   "--connect-retry-max n : Maximum connection attempt retries, default infinite.\n"
 #ifdef GENERAL_PROXY_SUPPORT
   "--auto-proxy    : Try to sense proxy settings (or lack thereof) automatically.\n"
-  "--show-proxy-settings : Show sensed proxy settings.\n"
+  "--show-proxy-settings [url] : Show sensed proxy settings for url.\n"
 #endif
 #ifdef ENABLE_HTTP_PROXY
   "--http-proxy s p [up] [auth] : Connect to remote host\n"
@@ -4677,17 +4677,18 @@ add_option (struct options *options,
       char *error = NULL;
 
       VERIFY_PERMISSION (OPT_P_GENERAL);
-      options->auto_proxy_info = get_proxy_settings (&error, &options->gc);
+      options->auto_proxy_info = get_proxy_settings ("https://openvpn.net", &error, &options->gc);
       if (error)
 	msg (M_WARN, "PROXY: %s", error);
     }
   else if (streq (p[0], "show-proxy-settings"))
     {
       struct auto_proxy_info *pi;
+      const char *url = p[1] ? p[1] : "https://openvpn.net";
       char *error = NULL;
 
       VERIFY_PERMISSION (OPT_P_GENERAL);
-      pi = get_proxy_settings (&error, &options->gc);
+      pi = get_proxy_settings (url, &error, &options->gc);
       if (pi)
 	{
 	  msg (M_INFO|M_NOPREFIX, "HTTP Server: %s", np(pi->http.server));
@@ -4698,7 +4699,7 @@ add_option (struct options *options,
       if (error)
 	msg (msglevel, "Proxy error: %s", error);
 #ifdef WIN32
-      show_win_proxy_settings (M_INFO|M_NOPREFIX);
+      show_win_proxy_settings (url, M_INFO|M_NOPREFIX);
 #endif
       openvpn_exit (OPENVPN_EXIT_STATUS_GOOD); /* exit point */
     }
proxy.c +98 -75

228 lines not on this page · raw message

proxy.h +2 -2
index d89aa4a..daa4907 100644
@@ -44,10 +44,10 @@ struct auto_proxy_info {
   struct auto_proxy_info_entry socks;
 };
 
-struct auto_proxy_info *get_proxy_settings (char **err, struct gc_arena *gc);
+struct auto_proxy_info *get_proxy_settings (const char *url, char **err, struct gc_arena *gc);
 
 #ifdef WIN32
-void show_win_proxy_settings (const int msglevel);
+void show_win_proxy_settings (const char *url, const int msglevel);
 #endif /* WIN32 */
 
 #endif /* GENERAL_PROXY_SUPPORT */
Signature · 1 line
1.7.5.4
author
#7 lore raw

PATCH 3/3 query auto-proxy information when connecting

In reply to Heiko Hund

Delaying automatic proxy detection from the time options are parsed to connection initialization makes sense as proxy information may have changed since the tunnel was established. Especially if the network connection or PAC script changed since then. Now, if openvpn receives an SIGUSR1 it requeries the settings and uses them.

---
 init.c    |   23 +++++++++++++++++++----
 options.c |    8 ++------
 options.h |    2 +-
 3 files changed, 22 insertions(+), 11 deletions(-)
init.c +19 -4
index 4a16fba..8219a11 100644
@@ -388,15 +388,30 @@ init_proxy_dowork (struct context *c)
 #else
   const bool did_http = false;
 #endif
+  struct auto_proxy_info *auto_proxy_info = NULL;
 
   uninit_proxy_dowork (c);
 
+  if (c->options.auto_proxy)
+    {
+      char *error;
+      char url[128];
+
+      openvpn_snprintf (url, sizeof (url), "%s://%s:%d/",
+			(proto_is_udp (c->options.ce.proto) ? "socks" : "https"),
+			c->options.ce.remote, c->options.ce.remote_port);
+
+      auto_proxy_info = get_proxy_settings (url, &error, &c->c2.gc);
+      if (error)
+	msg (M_WARN, "PROXY: %s", error);
+    }
+
 #ifdef ENABLE_HTTP_PROXY
-  if (c->options.ce.http_proxy_options || c->options.auto_proxy_info)
+  if (c->options.ce.http_proxy_options || auto_proxy_info)
     {
       /* Possible HTTP proxy user/pass input */
       c->c1.http_proxy = http_proxy_new (c->options.ce.http_proxy_options,
-					 c->options.auto_proxy_info);
+					 auto_proxy_info);
       if (c->c1.http_proxy)
 	{
 	  did_http = true;
@@ -406,13 +421,13 @@ init_proxy_dowork (struct context *c)
 #endif
 
 #ifdef ENABLE_SOCKS
-  if (!did_http && (c->options.ce.socks_proxy_server || c->options.auto_proxy_info))
+  if (!did_http && (c->options.ce.socks_proxy_server || auto_proxy_info))
     {
       c->c1.socks_proxy = socks_proxy_new (c->options.ce.socks_proxy_server,
 					   c->options.ce.socks_proxy_port,
 					   c->options.ce.socks_proxy_authfile,
 					   c->options.ce.socks_proxy_retry,
-					   c->options.auto_proxy_info);
+					   auto_proxy_info);
       if (c->c1.socks_proxy)
 	{
 	  c->c1.socks_proxy_owned = true;
options.c +2 -6
index 62c2ac8..c6243cd 100644
@@ -2025,7 +2025,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
     msg (M_USAGE, "--remote MUST be used in TCP Client mode");
 
 #ifdef ENABLE_HTTP_PROXY
-  if ((ce->http_proxy_options || options->auto_proxy_info) && ce->proto != PROTO_TCPv4_CLIENT)
+  if ((ce->http_proxy_options || options->auto_proxy) && ce->proto != PROTO_TCPv4_CLIENT)
     msg (M_USAGE, "--http-proxy or --auto-proxy MUST be used in TCP Client mode (i.e. --proto tcp-client)");
 #endif
 
@@ -4674,12 +4674,8 @@ add_option (struct options *options,
 #ifdef GENERAL_PROXY_SUPPORT
   else if (streq (p[0], "auto-proxy"))
     {
-      char *error = NULL;
-
       VERIFY_PERMISSION (OPT_P_GENERAL);
-      options->auto_proxy_info = get_proxy_settings ("https://openvpn.net", &error, &options->gc);
-      if (error)
-	msg (M_WARN, "PROXY: %s", error);
+      options->auto_proxy = true;
     }
   else if (streq (p[0], "show-proxy-settings"))
     {
options.h +1 -1
index 8a51502..47b7ddb 100644
@@ -193,7 +193,7 @@ struct options
 #endif
 
 #ifdef GENERAL_PROXY_SUPPORT
-  struct auto_proxy_info *auto_proxy_info;
+  bool auto_proxy;
 #endif
 
 #if HTTP_PROXY_FALLBACK
Signature · 1 line
1.7.5.4
#8 lore raw
In reply to Heiko Hund

Won't it make it harder to configure openvpn as service?

Quoted 46 lines · Heiko Hund

Hi,

the auto-proxy support for Windows was rather sub-optimal. Since Internet Explorer 5 proxy settings were configured with the network or VPN connection, but OpenVPN always queried the settings for the LAN connection. Truely automatic proxy configuration via WPAD and PAC script was not used, either.

This patch series tries to change that. Auto proxy detetction is done with WinHTTP which has support for WPAD, PAC and per connection proxy settings.

Another thing that is changed is the time at which the auto proxy config takes place in OpenVPN. Instead of doing it once during start-up, potentially changed settings are now fetched once every connect.

Heiko Hund (3):
 add MinGW WinHTTP compatibility layer
 do automatic proxy detection on Windows right
 query auto-proxy information when connecting

 configure.ac |   30 ++++++++++
 init.c       |   23 ++++++-

 openvpn.8    |    9 ++-
 options.c    |   15 ++---
 options.h    |    2 +-
 proxy.c      |  173 +++++++++++++++++++++++++++++++++-------------------------
 proxy.h      |    4 +-
 win32.c      |  108 ++++++++++++++++++++++++++++++++++++
 win32.h      |   61 ++++++++++++++++++++
 9 files changed, 330 insertions(+), 95 deletions(-)

Regards
Heiko
--
1.7.5.4

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, user administration capabilities and model configuration. Take the hassle out of deploying and managing Subversion and the tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

author
#9 lore raw
Quoted 1 line · On Wednesday 17 August 2011 15:59:10 Alon Bar-Lev wrote:

Won't it make it harder to configure openvpn as service?

I don't see how. Please elaborate.

Heiko

Signature · 8 lines
Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200
Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe
 
Represented by the General Partner Astaro Verwaltungs GmbH
Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany 
Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen,
Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen
#10 lore raw

How do you configure Internet Explorer proxy detection for local system account? Or... alternatively you need to create a user for openvpn service, login, execute IE, set whatever.
Quite difficult for unattended setup.
Well, maybe find places in registry where IE stores the settings...

Quoted 16 lines · Heiko Hund
Quoted 1 line · On Wednesday 17 August 2011 15:59:10 Alon Bar-Lev wrote:

Won't it make it harder to configure openvpn as service?

I don't see how. Please elaborate.

Heiko
--
Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200 Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe

Represented by the General Partner Astaro Verwaltungs GmbH Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen, Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen

author
#11 lore raw
Quoted 5 lines · On Wednesday 17 August 2011 16:07:42 Alon Bar-Lev wrote:

How do you configure Internet Explorer proxy detection for local system account? Or... alternatively you need to create a user for openvpn service, login, execute IE, set whatever.
Quite difficult for unattended setup.
Well, maybe find places in registry where IE stores the settings...

I don't think that's a problem. If no IE proxy configuration can be fetched, the default config set with proxycfg will be used. And besides that there's still the option to manually configure proxy settings in openvpn directly for such setups.

Heiko

Signature · 8 lines
Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200
Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe
 
Represented by the General Partner Astaro Verwaltungs GmbH
Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany 
Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen,
Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen