Wireless Daemon for Linux
 help / color / mirror / Atom feed
* [PATCH 1/4] client: Modify error handler to return error msg
@ 2019-10-24 19:53 Tim Kourt
  2019-10-24 19:53 ` [PATCH 2/4] client: Respond to invalid agent requests Tim Kourt
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tim Kourt @ 2019-10-24 19:53 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2657 bytes --]

This allows to send error back to iwd, instead of returning NULL
and waiting for iwd to timeout on agent request.
---
 client/agent.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/client/agent.c b/client/agent.c
index 5ed6538f..c8da72dc 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -50,7 +50,16 @@ static struct pending_op {
 	struct l_queue *saved_input;
 } pending_op;
 
-static struct l_dbus_message *agent_error(const char *text)
+static struct l_dbus_message *agent_error_reply(struct l_dbus_message *message,
+							const char *text)
+{
+	return l_dbus_message_new_error(message,
+					IWD_AGENT_INTERFACE ".Error.Failed",
+					"Error: %s", text);
+}
+
+static struct l_dbus_message *agent_error(struct l_dbus_message *message,
+							const char *text)
 {
 	display_error(text);
 
@@ -60,7 +69,7 @@ static struct l_dbus_message *agent_error(const char *text)
 		l_main_quit();
 	}
 
-	return NULL;
+	return agent_error_reply(message, text);
 }
 
 static struct l_dbus_message *release_method_call(struct l_dbus *dbus,
@@ -108,7 +117,7 @@ static struct l_dbus_message *request_passphrase_method_call(
 		return reply;
 
 	if (command_option_get(COMMAND_OPTION_DONTASK, NULL))
-		return agent_error("No passphrase is provided as "
+		return agent_error(message, "No passphrase is provided as "
 					"'--"COMMAND_OPTION_PASSPHRASE"' "
 						"command-line option.\n");
 
@@ -149,7 +158,7 @@ static struct l_dbus_message *request_private_key_passphrase_method_call(
 		return reply;
 
 	if (command_option_get(COMMAND_OPTION_DONTASK, NULL))
-		return agent_error("No passphrase is provided as "
+		return agent_error(message, "No passphrase is provided as "
 					"'--"COMMAND_OPTION_PASSPHRASE"' "
 						"command-line option.\n");
 
@@ -211,7 +220,8 @@ static struct l_dbus_message *request_username_and_password_method_call(
 		return reply;
 
 	if (command_option_get(COMMAND_OPTION_DONTASK, NULL))
-		return agent_error("No username or password is provided as "
+		return agent_error(message, "No username or password is "
+					"provided as "
 					"'--"COMMAND_OPTION_USERNAME"' or "
 					"'--"COMMAND_OPTION_PASSWORD"' "
 						"command-line option.\n");
@@ -271,7 +281,7 @@ static struct l_dbus_message *request_user_password_method_call(
 		return reply;
 
 	if (command_option_get(COMMAND_OPTION_DONTASK, NULL))
-		return agent_error("No password is provided as "
+		return agent_error(message, "No password is provided as "
 					"'--"COMMAND_OPTION_PASSWORD"' "
 					"command-line option.\n");
 
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] client: Respond to invalid agent requests
  2019-10-24 19:53 [PATCH 1/4] client: Modify error handler to return error msg Tim Kourt
@ 2019-10-24 19:53 ` Tim Kourt
  2019-10-24 19:53 ` [PATCH 3/4] client: Don't check for errors on " Tim Kourt
  2019-10-24 19:53 ` [PATCH 4/4] client: Fail on requests with invalid arguments Tim Kourt
  2 siblings, 0 replies; 5+ messages in thread
From: Tim Kourt @ 2019-10-24 19:53 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2421 bytes --]

This allows to send an error back to iwd, instead of returning NULL
and waiting for iwd to timeout on agent request.
---
 client/agent.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/client/agent.c b/client/agent.c
index c8da72dc..4d23e05e 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -123,11 +123,11 @@ static struct l_dbus_message *request_passphrase_method_call(
 
 	l_dbus_message_get_arguments(message, "o", &path);
 	if (!path)
-		return NULL;
+		return agent_error_reply(message, "Invalid argument");
 
 	proxy = proxy_interface_find(IWD_NETWORK_INTERFACE, path);
 	if (!proxy)
-		return NULL;
+		return agent_error_reply(message, "Invalid network object");
 
 	display("Type the network passphrase for %s.\n",
 				proxy_interface_get_identity_str(proxy));
@@ -164,11 +164,11 @@ static struct l_dbus_message *request_private_key_passphrase_method_call(
 
 	l_dbus_message_get_arguments(message, "o", &path);
 	if (!path)
-		return NULL;
+		return agent_error_reply(message, "Invalid argument");
 
 	proxy = proxy_interface_find(IWD_NETWORK_INTERFACE, path);
 	if (!proxy)
-		return NULL;
+		return agent_error_reply(message, "Invalid network object");
 
 	display("Type the passphrase for the network encrypted private key for "
 			"%s.\n", proxy_interface_get_identity_str(proxy));
@@ -228,11 +228,11 @@ static struct l_dbus_message *request_username_and_password_method_call(
 
 	l_dbus_message_get_arguments(message, "o", &path);
 	if (!path)
-		return NULL;
+		return agent_error_reply(message, "Invalid argument");
 
 	proxy = proxy_interface_find(IWD_NETWORK_INTERFACE, path);
 	if (!proxy)
-		return NULL;
+		return agent_error_reply(message, "Invalid network object");
 
 	display("Type the network credentials for %s.\n",
 				proxy_interface_get_identity_str(proxy));
@@ -287,11 +287,11 @@ static struct l_dbus_message *request_user_password_method_call(
 
 	l_dbus_message_get_arguments(message, "os", &path, &username);
 	if (!path || !username)
-		return NULL;
+		return agent_error_reply(message, "Invalid argument");
 
 	proxy = proxy_interface_find(IWD_NETWORK_INTERFACE, path);
 	if (!proxy)
-		return NULL;
+		return agent_error_reply(message, "Invalid network object");
 
 	display("Type the network password for %s.\n",
 				proxy_interface_get_identity_str(proxy));
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] client: Don't check for errors on agent requests
  2019-10-24 19:53 [PATCH 1/4] client: Modify error handler to return error msg Tim Kourt
  2019-10-24 19:53 ` [PATCH 2/4] client: Respond to invalid agent requests Tim Kourt
@ 2019-10-24 19:53 ` Tim Kourt
  2019-10-24 20:18   ` Denis Kenzior
  2019-10-24 19:53 ` [PATCH 4/4] client: Fail on requests with invalid arguments Tim Kourt
  2 siblings, 1 reply; 5+ messages in thread
From: Tim Kourt @ 2019-10-24 19:53 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1512 bytes --]

This assumes that iwd will never send the errors as agent requests,
therefore, eliminate the unnecessary checks.
---
 client/agent.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/client/agent.c b/client/agent.c
index 4d23e05e..52cb85cf 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -109,9 +109,6 @@ static struct l_dbus_message *request_passphrase_method_call(
 	struct l_dbus_message *reply;
 	const char *path;
 
-	if (dbus_message_has_error(message))
-		return NULL;
-
 	reply = request_passphrase_command_option(message);
 	if (reply)
 		return reply;
@@ -150,9 +147,6 @@ static struct l_dbus_message *request_private_key_passphrase_method_call(
 	struct l_dbus_message *reply;
 	const char *path;
 
-	if (dbus_message_has_error(message))
-		return NULL;
-
 	reply = request_passphrase_command_option(message);
 	if (reply)
 		return reply;
@@ -212,9 +206,6 @@ static struct l_dbus_message *request_username_and_password_method_call(
 	struct l_dbus_message *reply;
 	const char *path;
 
-	if (dbus_message_has_error(message))
-		return NULL;
-
 	reply = request_username_and_password_command_option(message);
 	if (reply)
 		return reply;
@@ -273,9 +264,6 @@ static struct l_dbus_message *request_user_password_method_call(
 	const char *username;
 	char *username_prompt;
 
-	if (dbus_message_has_error(message))
-		return NULL;
-
 	reply = request_user_password_command_option(message);
 	if (reply)
 		return reply;
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] client: Fail on requests with invalid arguments
  2019-10-24 19:53 [PATCH 1/4] client: Modify error handler to return error msg Tim Kourt
  2019-10-24 19:53 ` [PATCH 2/4] client: Respond to invalid agent requests Tim Kourt
  2019-10-24 19:53 ` [PATCH 3/4] client: Don't check for errors on " Tim Kourt
@ 2019-10-24 19:53 ` Tim Kourt
  2 siblings, 0 replies; 5+ messages in thread
From: Tim Kourt @ 2019-10-24 19:53 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1948 bytes --]

---
 client/agent.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/client/agent.c b/client/agent.c
index 52cb85cf..0bda42ea 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -118,7 +118,9 @@ static struct l_dbus_message *request_passphrase_method_call(
 					"'--"COMMAND_OPTION_PASSPHRASE"' "
 						"command-line option.\n");
 
-	l_dbus_message_get_arguments(message, "o", &path);
+	if (!l_dbus_message_get_arguments(message, "o", &path))
+		return agent_error_reply(message, "Invalid argument");
+
 	if (!path)
 		return agent_error_reply(message, "Invalid argument");
 
@@ -156,7 +158,9 @@ static struct l_dbus_message *request_private_key_passphrase_method_call(
 					"'--"COMMAND_OPTION_PASSPHRASE"' "
 						"command-line option.\n");
 
-	l_dbus_message_get_arguments(message, "o", &path);
+	if (!l_dbus_message_get_arguments(message, "o", &path))
+		return agent_error_reply(message, "Invalid argument");
+
 	if (!path)
 		return agent_error_reply(message, "Invalid argument");
 
@@ -217,7 +221,9 @@ static struct l_dbus_message *request_username_and_password_method_call(
 					"'--"COMMAND_OPTION_PASSWORD"' "
 						"command-line option.\n");
 
-	l_dbus_message_get_arguments(message, "o", &path);
+	if (!l_dbus_message_get_arguments(message, "o", &path))
+		return agent_error_reply(message, "Invalid argument");
+
 	if (!path)
 		return agent_error_reply(message, "Invalid argument");
 
@@ -273,7 +279,9 @@ static struct l_dbus_message *request_user_password_method_call(
 					"'--"COMMAND_OPTION_PASSWORD"' "
 					"command-line option.\n");
 
-	l_dbus_message_get_arguments(message, "os", &path, &username);
+	if (!l_dbus_message_get_arguments(message, "os", &path, &username))
+		return agent_error_reply(message, "Invalid arguments");
+
 	if (!path || !username)
 		return agent_error_reply(message, "Invalid argument");
 
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/4] client: Don't check for errors on agent requests
  2019-10-24 19:53 ` [PATCH 3/4] client: Don't check for errors on " Tim Kourt
@ 2019-10-24 20:18   ` Denis Kenzior
  0 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2019-10-24 20:18 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 295 bytes --]

Hi Tim,

On 10/24/19 2:53 PM, Tim Kourt wrote:
> This assumes that iwd will never send the errors as agent requests,
> therefore, eliminate the unnecessary checks.
> ---
>   client/agent.c | 12 ------------
>   1 file changed, 12 deletions(-)
> 

Applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-24 20:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-24 19:53 [PATCH 1/4] client: Modify error handler to return error msg Tim Kourt
2019-10-24 19:53 ` [PATCH 2/4] client: Respond to invalid agent requests Tim Kourt
2019-10-24 19:53 ` [PATCH 3/4] client: Don't check for errors on " Tim Kourt
2019-10-24 20:18   ` Denis Kenzior
2019-10-24 19:53 ` [PATCH 4/4] client: Fail on requests with invalid arguments Tim Kourt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox