]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
tun.c: enable using wintun driver under SYSTEM
authorLev Stipakov <lev@openvpn.net>
Wed, 19 Aug 2020 07:07:46 +0000 (10:07 +0300)
committerGert Doering <gert@greenie.muc.de>
Sun, 23 Aug 2020 12:31:39 +0000 (14:31 +0200)
Commit 6d19775a468 has removed SYSTEM elevation hack,
but introduced regression - inability to use wintun without
interactive service.

Proceed with ring buffers registration even if iservice is unavailable
and display relevant error message.

Trac: #1318

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20200819070746.197-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20780.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/tun.c

index 30454454780c3d78ebfe9b73e3c6e8de4bef918b..62557364fb4d8f9891198f1c7c7ebea7ce73d360 100644 (file)
@@ -6158,12 +6158,32 @@ wintun_register_ring_buffer(struct tuntap *tt, const char *device_guid)
     }
     else
     {
-        msg(M_FATAL, "ERROR:  Wintun requires SYSTEM privileges and therefore "
-                     "should be used with interactive service. If you want to "
-                     "use openvpn from command line, you need to do SYSTEM "
-                     "elevation yourself (for example with psexec).");
-    }
+        if (!register_ring_buffers(tt->hand,
+                                   tt->wintun_send_ring,
+                                   tt->wintun_receive_ring,
+                                   tt->rw_handle.read,
+                                   tt->rw_handle.write))
+        {
+            switch (GetLastError())
+            {
+                case ERROR_ACCESS_DENIED:
+                    msg(M_FATAL, "ERROR:  Wintun requires SYSTEM privileges and therefore "
+                                 "should be used with interactive service. If you want to "
+                                 "use openvpn from command line, you need to do SYSTEM "
+                                 "elevation yourself (for example with psexec).");
+                    break;
+
+                case ERROR_ALREADY_INITIALIZED:
+                    msg(M_NONFATAL, "Adapter %s is already in use", device_guid);
+                    break;
 
+                default:
+                    msg(M_NONFATAL | M_ERRNO, "Failed to register ring buffers");
+            }
+            ret = false;
+        }
+
+    }
     return ret;
 }