[Openvpn-devel,v3] show the right string for key-direction

Message ID 1517392380-21597-1-git-send-email-arne@rfc2549.org
State Accepted
Headers show
Series [Openvpn-devel,v3] show the right string for key-direction | expand

Commit Message

Arne Schwabe Jan. 30, 2018, 10:53 p.m. UTC
V2: print also a nice string if direction is not set
V3: really include V2 changes
---
 src/openvpn/crypto.c  | 11 +++++++++--
 src/openvpn/crypto.h  |  2 +-
 src/openvpn/options.c |  4 ++--
 3 files changed, 12 insertions(+), 5 deletions(-)

Comments

Steffan Karger Feb. 8, 2018, 8:46 a.m. UTC | #1
Hi,

On 31-01-18 10:53, Arne Schwabe wrote:
> V2: print also a nice string if direction is not set
> V3: really include V2 changes
> ---
>  src/openvpn/crypto.c  | 11 +++++++++--
>  src/openvpn/crypto.h  |  2 +-
>  src/openvpn/options.c |  4 ++--
>  3 files changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
> index 3096f3b0..b3021d4f 100644
> --- a/src/openvpn/crypto.c
> +++ b/src/openvpn/crypto.c
> @@ -1545,11 +1545,18 @@ ascii2keydirection(int msglevel, const char *str)
>  }
>  
>  const char *
> -keydirection2ascii(int kd, bool remote)
> +keydirection2ascii(int kd, bool remote, bool humanreadable)
>  {
>      if (kd == KEY_DIRECTION_BIDIRECTIONAL)
>      {
> -        return NULL;
> +        if (humanreadable)
> +        {
> +            return "not set";
> +        }
> +        else
> +        {
> +            return NULL;
> +        }
>      }
>      else if (kd == KEY_DIRECTION_NORMAL)
>      {
> diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
> index 8e8ee8f5..e1e318eb 100644
> --- a/src/openvpn/crypto.h
> +++ b/src/openvpn/crypto.h
> @@ -470,7 +470,7 @@ void must_have_n_keys(const char *filename, const char *option, const struct key
>  
>  int ascii2keydirection(int msglevel, const char *str);
>  
> -const char *keydirection2ascii(int kd, bool remote);
> +const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
>  
>  /* print keys */
>  void key2_print(const struct key2 *k,
> diff --git a/src/openvpn/options.c b/src/openvpn/options.c
> index 66e1f9d1..9f5cd6ed 100644
> --- a/src/openvpn/options.c
> +++ b/src/openvpn/options.c
> @@ -1706,7 +1706,7 @@ show_settings(const struct options *o)
>  #endif
>  
>      SHOW_STR(shared_secret_file);
> -    SHOW_INT(key_direction);
> +    SHOW_PARM(key_direction, keydirection2ascii(o->key_direction, false, true), "%s");
>      SHOW_STR(ciphername);
>      SHOW_BOOL(ncp_enabled);
>      SHOW_STR(ncp_ciphers);
> @@ -3583,7 +3583,7 @@ options_string(const struct options *o,
>       * Key direction
>       */
>      {
> -        const char *kd = keydirection2ascii(o->key_direction, remote);
> +        const char *kd = keydirection2ascii(o->key_direction, remote, false);
>          if (kd)
>          {
>              buf_printf(&out, ",keydir %s", kd);
> 

'The right' here means 'what was in the config' instead of 'what we use
internally'.  But I agree that's better UX, so:

Acked-by: Steffan Karger <steffan@karger.me>
Tested-by: Steffan Karger <steffan@karger.me>

-Steffan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Gert Doering Feb. 19, 2018, 11:03 p.m. UTC | #2
Your patch has been applied to the master and release/2.4 branch.

commit 7f7f00da88eeea847da57f4f34c66c1f4a935a73 (master)
commit 6725074ba0af914f85e6dbbef5eff08c2539c5b8 (release/2.4)
Author: Arne Schwabe
Date:   Wed Jan 31 10:53:00 2018 +0100

     show the right string for key-direction

     Acked-by: Steffan Karger <steffan.karger@fox-it.com>
     Message-Id: <1517392380-21597-1-git-send-email-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg16415.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

Patch

diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 3096f3b0..b3021d4f 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -1545,11 +1545,18 @@  ascii2keydirection(int msglevel, const char *str)
 }
 
 const char *
-keydirection2ascii(int kd, bool remote)
+keydirection2ascii(int kd, bool remote, bool humanreadable)
 {
     if (kd == KEY_DIRECTION_BIDIRECTIONAL)
     {
-        return NULL;
+        if (humanreadable)
+        {
+            return "not set";
+        }
+        else
+        {
+            return NULL;
+        }
     }
     else if (kd == KEY_DIRECTION_NORMAL)
     {
diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index 8e8ee8f5..e1e318eb 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/crypto.h
@@ -470,7 +470,7 @@  void must_have_n_keys(const char *filename, const char *option, const struct key
 
 int ascii2keydirection(int msglevel, const char *str);
 
-const char *keydirection2ascii(int kd, bool remote);
+const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
 
 /* print keys */
 void key2_print(const struct key2 *k,
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 66e1f9d1..9f5cd6ed 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -1706,7 +1706,7 @@  show_settings(const struct options *o)
 #endif
 
     SHOW_STR(shared_secret_file);
-    SHOW_INT(key_direction);
+    SHOW_PARM(key_direction, keydirection2ascii(o->key_direction, false, true), "%s");
     SHOW_STR(ciphername);
     SHOW_BOOL(ncp_enabled);
     SHOW_STR(ncp_ciphers);
@@ -3583,7 +3583,7 @@  options_string(const struct options *o,
      * Key direction
      */
     {
-        const char *kd = keydirection2ascii(o->key_direction, remote);
+        const char *kd = keydirection2ascii(o->key_direction, remote, false);
         if (kd)
         {
             buf_printf(&out, ",keydir %s", kd);