client: Modify error handler to return error msg
PATCH 1/4 client: Modify error handler to return error msg
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(-)
client/agent.c +16 -6
@@ -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" );
Signature · 1 line
2.13.6
PATCH 2/4 client: Respond to invalid agent requests
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(-)
client/agent.c +8 -8
@@ -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));
Signature · 1 line
2.13.6
PATCH 3/4 client: Don't check for errors on agent requests
In reply to Tim KourtThis 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(-)
client/agent.c +0 -12
@@ -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;
Signature · 1 line
2.13.6
Denis Kenzior
AppliedRe: [PATCH 3/4] client: Don't check for errors on agent requests
Hi Tim,
Quoted 6 lines · Tim Kourt
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
PATCH 4/4 client: Fail on requests with invalid arguments
In reply to Tim Kourt--- client/agent.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
client/agent.c +12 -4
@@ -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" );
Signature · 1 line
2.13.6