Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mRemoteNG/PuTTYNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2021-12-28 20:52:00 +0300
committerSimon Tatham <anakin@pobox.com>2021-12-28 21:08:31 +0300
commita2ff884512be0cb0ef62aceee5428ba42ca64d9b (patch)
tree2bb40dcbec19fd24524593bfca5fb3b126a4c2bd /otherbackends
parenta82ab70b0bf418a7c18d07e0090bbf194f795cbe (diff)
Richer data type for interactive prompt results.
All the seat functions that request an interactive prompt of some kind to the user - both the main seat_get_userpass_input and the various confirmation dialogs for things like host keys - were using a simple int return value, with the general semantics of 0 = "fail", 1 = "proceed" (and in the case of seat_get_userpass_input, answers to the prompts were provided), and -1 = "request in progress, wait for a callback". In this commit I change all those functions' return types to a new struct called SeatPromptResult, whose primary field is an enum replacing those simple integer values. The main purpose is that the enum has not three but _four_ values: the "fail" result has been split into 'user abort' and 'software abort'. The distinction is that a user abort occurs as a result of an interactive UI action, such as the user clicking 'cancel' in a dialog box or hitting ^D or ^C at a terminal password prompt - and therefore, there's no need to display an error message telling the user that the interactive operation has failed, because the user already knows, because they _did_ it. 'Software abort' is from any other cause, where PuTTY is the first to know there was a problem, and has to tell the user. We already had this 'user abort' vs 'software abort' distinction in other parts of the code - the SSH backend has separate termination functions which protocol layers can call. But we assumed that any failure from an interactive prompt request fell into the 'user abort' category, which is not true. A couple of examples: if you configure a host key fingerprint in your saved session via the SSH > Host keys pane, and the server presents a host key that doesn't match it, then verify_ssh_host_key would report that the user had aborted the connection, and feel no need to tell the user what had gone wrong! Similarly, if a password provided on the command line was not accepted, then (after I fixed the semantics of that in the previous commit) the same wrong handling would occur. So now, those Seat prompt functions too can communicate whether the user or the software originated a connection abort. And in the latter case, we also provide an error message to present to the user. Result: in those two example cases (and others), error messages should no longer go missing. Implementation note: to avoid the hassle of having the error message in a SeatPromptResult being a dynamically allocated string (and hence, every recipient of one must always check whether it's non-NULL and free it on every exit path, plus being careful about copying the struct around), I've instead arranged that the structure contains a function pointer and a couple of parameters, so that the string form of the message can be constructed on demand. That way, the only users who need to free it are the ones who actually _asked_ for it in the first place, which is a much smaller set. (This is one of the rare occasions that I regret not having C++'s extra features available in this code base - a unique_ptr or shared_ptr to a string would have been just the thing here, and the compiler would have done all the hard work for me of remembering where to insert the frees!)
Diffstat (limited to 'otherbackends')
-rw-r--r--otherbackends/rlogin.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/otherbackends/rlogin.c b/otherbackends/rlogin.c
index 59a833a0..37087257 100644
--- a/otherbackends/rlogin.c
+++ b/otherbackends/rlogin.c
@@ -35,7 +35,7 @@ struct Rlogin {
Interactor interactor;
};
-static void rlogin_startup(Rlogin *rlogin, int prompt_result,
+static void rlogin_startup(Rlogin *rlogin, SeatPromptResult spr,
const char *ruser);
static void rlogin_try_username_prompt(void *ctx);
@@ -65,7 +65,7 @@ static void rlogin_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
*/
/* Next terminal output will come from server */
seat_set_trust_status(rlogin->seat, false);
- rlogin_startup(rlogin, 1, ruser);
+ rlogin_startup(rlogin, SPR_OK, ruser);
sfree(ruser);
} else {
/*
@@ -160,17 +160,25 @@ static void rlogin_sent(Plug *plug, size_t bufsize)
seat_sent(rlogin->seat, rlogin->bufsize);
}
-static void rlogin_startup(Rlogin *rlogin, int prompt_result,
+static void rlogin_startup(Rlogin *rlogin, SeatPromptResult spr,
const char *ruser)
{
char z = 0;
char *p;
- if (prompt_result == 0) {
+ if (spr.kind == SPRK_USER_ABORT) {
/* User aborted at the username prompt. */
sk_close(rlogin->s);
rlogin->s = NULL;
seat_notify_remote_exit(rlogin->seat);
+ } else if (spr.kind == SPRK_SW_ABORT) {
+ /* Something else went wrong at the username prompt, so we
+ * have to show some kind of error. */
+ sk_close(rlogin->s);
+ rlogin->s = NULL;
+ char *err = spr_get_error_message(spr);
+ seat_connection_fatal(rlogin->seat, "%s", err);
+ sfree(err);
} else {
sk_write(rlogin->s, &z, 1);
p = conf_get_str(rlogin->conf, CONF_localusername);
@@ -332,9 +340,9 @@ static void rlogin_try_username_prompt(void *ctx)
{
Rlogin *rlogin = (Rlogin *)ctx;
- int ret = seat_get_userpass_input(
+ SeatPromptResult spr = seat_get_userpass_input(
interactor_announce(&rlogin->interactor), rlogin->prompt);
- if (ret < 0)
+ if (spr.kind == SPRK_INCOMPLETE)
return;
/* Next terminal output will come from server */
@@ -345,7 +353,7 @@ static void rlogin_try_username_prompt(void *ctx)
* rlogin_startup will signal to rlogin_sendok by nulling out
* rlogin->prompt. */
rlogin_startup(
- rlogin, ret, prompt_get_result_ref(rlogin->prompt->prompts[0]));
+ rlogin, spr, prompt_get_result_ref(rlogin->prompt->prompts[0]));
}
/*