[Openvpn-devel,v2,2/7] tun.c: upgrade get_device_guid() to return the Windows driver type

Message ID 20191220161117.1434-2-simon@rozman.si
State Accepted
Headers show
Series [Openvpn-devel,v2,1/7] tun.c: make Windows device lookup functions more general | expand

Commit Message

Simon Rozman Dec. 20, 2019, 5:11 a.m. UTC
Signed-off-by: Simon Rozman <simon@rozman.si>
---
 src/openvpn/tun.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Comments

Lev Stipakov Dec. 20, 2019, 7:23 a.m. UTC | #1
Compared with v1, difference is updated function comment.

Compiled with MSVC.

Acked-by: Lev Stipakov <lstipakov@gmail.com>

pe 20. jouluk. 2019 klo 18.14 Simon Rozman (simon@rozman.si) kirjoitti:

> Signed-off-by: Simon Rozman <simon@rozman.si>
> ---
>  src/openvpn/tun.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
> index 0d6f40fe..f90f201d 100644
> --- a/src/openvpn/tun.c
> +++ b/src/openvpn/tun.c
> @@ -4104,12 +4104,13 @@ get_unspecified_device_guid(const int
> device_number,
>
>  /*
>   * Lookup a --dev-node adapter name in the registry
> - * returning the GUID and optional actual_name.
> + * returning the GUID and optional actual_name and device type
>   */
>  static const char *
>  get_device_guid(const char *name,
>                  char *actual_name,
>                  int actual_name_size,
> +                bool *wintun,
>                  const struct tap_reg *tap_reg,
>                  const struct panel_reg *panel_reg,
>                  struct gc_arena *gc)
> @@ -4145,6 +4146,10 @@ get_device_guid(const char *name,
>          {
>              buf_printf(&actual, "%s", name);
>          }
> +        if (wintun)
> +        {
> +            *wintun = tr->wintun;
> +        }
>          return BSTR(&ret);
>      }
>
> @@ -4154,6 +4159,10 @@ get_device_guid(const char *name,
>          if (tr)
>          {
>              buf_printf(&actual, "%s", name);
> +            if (wintun)
> +            {
> +                *wintun = tr->wintun;
> +            }
>              buf_printf(&ret, "%s", tr->guid);
>              return BSTR(&ret);
>          }
> @@ -4838,7 +4847,7 @@ tap_allow_nonadmin_access(const char *dev_node)
>      if (dev_node)
>      {
>          /* Get the device GUID for the device specified with --dev-node.
> */
> -        device_guid = get_device_guid(dev_node, actual_buffer,
> sizeof(actual_buffer), tap_reg, panel_reg, &gc);
> +        device_guid = get_device_guid(dev_node, actual_buffer,
> sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
>
>          if (!device_guid)
>          {
> @@ -5412,7 +5421,7 @@ netsh_get_id(const char *dev_node, struct gc_arena
> *gc)
>
>      if (dev_node)
>      {
> -        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual),
> tap_reg, panel_reg, gc);
> +        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual),
> NULL, tap_reg, panel_reg, gc);
>      }
>      else
>      {
> @@ -6132,7 +6141,7 @@ tun_open_device(struct tuntap *tt, const char
> *dev_node, const char **device_gui
>      if (dev_node)
>      {
>          /* Get the device GUID for the device specified with --dev-node.
> */
> -        *device_guid = get_device_guid(dev_node, actual_buffer,
> sizeof(actual_buffer), tap_reg, panel_reg, &gc);
> +        *device_guid = get_device_guid(dev_node, actual_buffer,
> sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
>
>          if (!*device_guid)
>          {
> --
> 2.24.1.windows.2
>
>
>
> _______________________________________________
> Openvpn-devel mailing list
> Openvpn-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openvpn-devel
>
Gert Doering Dec. 22, 2019, 8 a.m. UTC | #2
Your patch has been applied to the master branch.

Compile tested on Ubuntu 1604 and stared at code.

As a side note: the granularity of this one is a bit too fine-grained 
for my taste - it changes the function, but none of the callers make
use of it, so it's somewhat of a no-op and hard to test.

commit 9db385f2d179bbc578112e7526b51d424a62aac5
Author: Simon Rozman
Date:   Fri Dec 20 17:11:12 2019 +0100

     tun.c: upgrade get_device_guid() to return the Windows driver type

     Signed-off-by: Simon Rozman <simon@rozman.si>
     Acked-by: Lev Stipakov <lstipakov@gmail.com>
     Message-Id: <20191220161117.1434-2-simon@rozman.si>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19277.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 0d6f40fe..f90f201d 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -4104,12 +4104,13 @@  get_unspecified_device_guid(const int device_number,
 
 /*
  * Lookup a --dev-node adapter name in the registry
- * returning the GUID and optional actual_name.
+ * returning the GUID and optional actual_name and device type
  */
 static const char *
 get_device_guid(const char *name,
                 char *actual_name,
                 int actual_name_size,
+                bool *wintun,
                 const struct tap_reg *tap_reg,
                 const struct panel_reg *panel_reg,
                 struct gc_arena *gc)
@@ -4145,6 +4146,10 @@  get_device_guid(const char *name,
         {
             buf_printf(&actual, "%s", name);
         }
+        if (wintun)
+        {
+            *wintun = tr->wintun;
+        }
         return BSTR(&ret);
     }
 
@@ -4154,6 +4159,10 @@  get_device_guid(const char *name,
         if (tr)
         {
             buf_printf(&actual, "%s", name);
+            if (wintun)
+            {
+                *wintun = tr->wintun;
+            }
             buf_printf(&ret, "%s", tr->guid);
             return BSTR(&ret);
         }
@@ -4838,7 +4847,7 @@  tap_allow_nonadmin_access(const char *dev_node)
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node. */
-        device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
 
         if (!device_guid)
         {
@@ -5412,7 +5421,7 @@  netsh_get_id(const char *dev_node, struct gc_arena *gc)
 
     if (dev_node)
     {
-        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual), tap_reg, panel_reg, gc);
+        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual), NULL, tap_reg, panel_reg, gc);
     }
     else
     {
@@ -6132,7 +6141,7 @@  tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node. */
-        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
 
         if (!*device_guid)
         {