[Openvpn-devel,v2,3/3] Use a template for "unsupported management commands" error

Message ID 20210825210232.22509-3-selva.nair@gmail.com
State Superseded
Headers show
Series
  • [Openvpn-devel,1/2] Add remote-count and remote-entry query via management
Related show

Commit Message

Selva Nair Aug. 25, 2021, 9:02 p.m.
From: Selva Nair <selva.nair@gmail.com>

The message
"ERROR: The 'foo' commmand is not supported by current daemon mode"
is repeatedly used in manage.c. Move it to a function for uniformity
in messaging.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
---
 src/openvpn/manage.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

Patch

diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 214ea4be..7eff2dba 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -447,6 +447,12 @@  man_signal(struct management *man, const char *name)
     }
 }
 
+static void
+man_command_unsupported(const char *command_name)
+{
+    msg(M_CLIENT, "ERROR: The '%s' command is not supported by the current daemon mode", command_name);
+}
+
 static void
 man_status(struct management *man, const int version, struct status_output *so)
 {
@@ -456,7 +462,7 @@  man_status(struct management *man, const int version, struct status_output *so)
     }
     else
     {
-        msg(M_CLIENT, "ERROR: The 'status' command is not supported by the current daemon mode");
+        man_command_unsupported("status");
     }
 }
 
@@ -572,7 +578,7 @@  man_kill(struct management *man, const char *victim)
     }
     else
     {
-        msg(M_CLIENT, "ERROR: The 'kill' command is not supported by the current daemon mode");
+        man_command_unsupported("kill");
     }
 
     gc_free(&gc);
@@ -777,7 +783,7 @@  man_net(struct management *man)
     }
     else
     {
-        msg(M_CLIENT, "ERROR: The 'net' command is not supported by the current daemon mode");
+        man_command_unsupported("net");
     }
 }
 
@@ -799,7 +805,7 @@  man_send_cc_message(struct management *man, const char *message, const char *par
     }
     else
     {
-        msg(M_CLIENT, "ERROR: This command is not supported by the current daemon mode");
+        man_command_unsupported("cr-repsonse");
     }
 }
 #ifdef ENABLE_PKCS11
@@ -842,7 +848,7 @@  man_remote_entry_count(struct management *man)
     }
     else
     {
-        msg(M_CLIENT, "ERROR: The remote-entry-count command is not supported by the current daemon mode");
+        man_command_unsupported("remote-entry-count");
     }
 }
 
@@ -865,7 +871,7 @@  man_remote_entry_get(struct management *man, unsigned int index)
     }
     else
     {
-        msg(M_CLIENT, "ERROR: The remote-entry command is not supported by the current daemon mode");
+        man_command_unsupported("remote-entry-get");
     }
 
     free(remote);
@@ -956,7 +962,7 @@  in_extra_dispatch(struct management *man)
             }
             else
             {
-                msg(M_CLIENT, "ERROR: The client-auth command is not supported by the current daemon mode");
+                man_command_unsupported("client-auth");
             }
             break;
 
@@ -980,7 +986,7 @@  in_extra_dispatch(struct management *man)
             }
             else
             {
-                msg(M_CLIENT, "ERROR: The client-pf command is not supported by the current daemon mode");
+                man_command_unsupported("client-pf");
             }
             break;
 
@@ -1065,7 +1071,7 @@  man_client_pending_auth(struct management *man, const char *cid_str,
         }
         else
         {
-            msg(M_CLIENT, "ERROR: The client-pending-auth command is not supported by the current daemon mode");
+            man_command_unsupported("client-pending-auth");
         }
     }
 }
@@ -1116,7 +1122,7 @@  man_client_deny(struct management *man, const char *cid_str, const char *kid_str
         }
         else
         {
-            msg(M_CLIENT, "ERROR: The client-deny command is not supported by the current daemon mode");
+            man_command_unsupported("client-deny");
         }
     }
 }
@@ -1141,7 +1147,7 @@  man_client_kill(struct management *man, const char *cid_str, const char *kill_ms
         }
         else
         {
-            msg(M_CLIENT, "ERROR: The client-kill command is not supported by the current daemon mode");
+            man_command_unsupported("client-kill");
         }
     }
 }
@@ -1156,7 +1162,7 @@  man_client_n_clients(struct management *man)
     }
     else
     {
-        msg(M_CLIENT, "ERROR: The nclients command is not supported by the current daemon mode");
+        man_command_unsupported("nclients");
     }
 }
 
@@ -1280,7 +1286,7 @@  man_proxy(struct management *man, const char **p)
     }
     else
     {
-        msg(M_CLIENT, "ERROR: The proxy command is not supported by the current daemon mode");
+        man_command_unsupported("proxy");
     }
 }
 
@@ -1301,7 +1307,7 @@  man_remote(struct management *man, const char **p)
     }
     else
     {
-        msg(M_CLIENT, "ERROR: The remote command is not supported by the current daemon mode");
+        man_command_unsupported("remote");
     }
 }