]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Distinguish ERROR_ACCESS return value from create_wintun()
authorDaniel Lenski <dlenski@gmail.com>
Wed, 31 Mar 2021 01:35:45 +0000 (18:35 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Fri, 10 Sep 2021 18:27:34 +0000 (11:27 -0700)
The error 'Is the driver installed?' is misleading in this case; the actual
problem is likely that the user isn't running as SYSTEM/Administrator.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
tun-win32.c
wintun.c

index b265df8d8748c2fd1624f31826e9e75a050523eb..0258bad9fc12bdc3b1384a1cd3fb838695397a8e 100644 (file)
@@ -379,13 +379,18 @@ intptr_t os_setup_tun(struct openconnect_info *vpninfo)
                }
 
                /* Try creating a Wintun instead of TAP */
-               if (!create_wintun(vpninfo)) {
+               int retw = create_wintun(vpninfo);
+               if (!retw) {
                        ret = search_taps(vpninfo, open_tun);
 
                        if (ret == OPEN_TUN_SOFTFAIL)
                                ret = OPEN_TUN_HARDFAIL;
                        if (ret == OPEN_TUN_HARDFAIL)
                                os_shutdown_wintun(vpninfo);
+               } else if (retw == -EPERM) {
+                       ret = OPEN_TUN_HARDFAIL;
+                       vpn_progress(vpninfo, PRG_ERR,
+                                    _("Access denied creating Wintun adapter. Are you running with Administrator privileges?\n"));
                }
        }
 
index 426481020451948e9de99159f1b9bdd0567621d1..f575e594e1bcf9acea8a9139866d1978093d8860 100644 (file)
--- a/wintun.c
+++ b/wintun.c
@@ -102,19 +102,21 @@ static int init_wintun(struct openconnect_info *vpninfo)
 
 int create_wintun(struct openconnect_info *vpninfo)
 {
-       if (init_wintun(vpninfo))
-               return -1;
+       int ret = init_wintun(vpninfo);
+       if (ret < 0)
+               return ret;
 
        vpninfo->wintun_adapter = WintunCreateAdapter(WINTUN_POOL_NAME,
                                                      vpninfo->ifname_w, NULL, NULL);
        if (vpninfo->wintun_adapter)
                return 0;
 
-       char *errstr = openconnect__win32_strerror(GetLastError());
+       ret = GetLastError();
+       char *errstr = openconnect__win32_strerror(ret);
        vpn_progress(vpninfo, PRG_ERR, "Could not create Wintun adapter '%S': %s\n",
                     vpninfo->ifname_w, errstr);
        free(errstr);
-       return -EIO;
+       return (ret == ERROR_ACCESS_DENIED ? -EPERM : -EIO);
 }
 
 intptr_t open_wintun(struct openconnect_info *vpninfo, char *guid, wchar_t *wname)