X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/62ddb51e0424dd4bd1098b024f2427959aefc729..accc77cbbcdd332dceb8c9713d0ce0196eb863da:/ssh.c diff --git a/ssh.c b/ssh.c index 953c69f1..d4d3d06a 100644 --- a/ssh.c +++ b/ssh.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "putty.h" #include "tree234.h" @@ -1863,6 +1864,7 @@ static void ssh2_pkt_defer_noqueue(Ssh ssh, struct Packet *pkt, int noignore) * get encrypted with a known IV. */ struct Packet *ipkt = ssh2_pkt_init(SSH2_MSG_IGNORE); + ssh2_pkt_addstring_start(ipkt); ssh2_pkt_defer_noqueue(ssh, ipkt, TRUE); } len = ssh2_pkt_construct(ssh, pkt); @@ -2701,6 +2703,9 @@ static int ssh_closing(Plug plug, const char *error_msg, int error_code, error_msg = "Server closed network connection"; } + if (ssh->close_expected && ssh->clean_exit && ssh->exitcode < 0) + ssh->exitcode = 0; + if (need_notify) notify_remote_exit(ssh->frontend); @@ -3560,6 +3565,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, /* and try again */ } else { assert(0 && "unexpected return from loadrsakey()"); + got_passphrase = FALSE; /* placate optimisers */ } } @@ -6365,11 +6371,13 @@ static void ssh2_msg_channel_request(Ssh ssh, struct Packet *pktin) is_plausible = FALSE; } } + ssh->exitcode = 128; /* means `unknown signal' */ if (is_plausible) { if (is_int) { /* Old non-standard OpenSSH. */ int signum = ssh_pkt_getuint32(pktin); fmt_sig = dupprintf(" %d", signum); + ssh->exitcode = 128 + signum; } else { /* As per the drafts. */ char *sig; @@ -6381,6 +6389,82 @@ static void ssh2_msg_channel_request(Ssh ssh, struct Packet *pktin) fmt_sig = dupprintf(" \"%.*s\"", siglen, sig); } + + /* + * Really hideous method of translating the + * signal description back into a locally + * meaningful number. + */ + + if (0) + ; +#ifdef SIGABRT + else if (siglen == lenof("ABRT")-1 && + !memcmp(sig, "ABRT", siglen)) + ssh->exitcode = 128 + SIGABRT; +#endif +#ifdef SIGALRM + else if (siglen == lenof("ALRM")-1 && + !memcmp(sig, "ALRM", siglen)) + ssh->exitcode = 128 + SIGALRM; +#endif +#ifdef SIGFPE + else if (siglen == lenof("FPE")-1 && + !memcmp(sig, "FPE", siglen)) + ssh->exitcode = 128 + SIGFPE; +#endif +#ifdef SIGHUP + else if (siglen == lenof("HUP")-1 && + !memcmp(sig, "HUP", siglen)) + ssh->exitcode = 128 + SIGHUP; +#endif +#ifdef SIGILL + else if (siglen == lenof("ILL")-1 && + !memcmp(sig, "ILL", siglen)) + ssh->exitcode = 128 + SIGILL; +#endif +#ifdef SIGINT + else if (siglen == lenof("INT")-1 && + !memcmp(sig, "INT", siglen)) + ssh->exitcode = 128 + SIGINT; +#endif +#ifdef SIGKILL + else if (siglen == lenof("KILL")-1 && + !memcmp(sig, "KILL", siglen)) + ssh->exitcode = 128 + SIGKILL; +#endif +#ifdef SIGPIPE + else if (siglen == lenof("PIPE")-1 && + !memcmp(sig, "PIPE", siglen)) + ssh->exitcode = 128 + SIGPIPE; +#endif +#ifdef SIGQUIT + else if (siglen == lenof("QUIT")-1 && + !memcmp(sig, "QUIT", siglen)) + ssh->exitcode = 128 + SIGQUIT; +#endif +#ifdef SIGSEGV + else if (siglen == lenof("SEGV")-1 && + !memcmp(sig, "SEGV", siglen)) + ssh->exitcode = 128 + SIGSEGV; +#endif +#ifdef SIGTERM + else if (siglen == lenof("TERM")-1 && + !memcmp(sig, "TERM", siglen)) + ssh->exitcode = 128 + SIGTERM; +#endif +#ifdef SIGUSR1 + else if (siglen == lenof("USR1")-1 && + !memcmp(sig, "USR1", siglen)) + ssh->exitcode = 128 + SIGUSR1; +#endif +#ifdef SIGUSR2 + else if (siglen == lenof("USR2")-1 && + !memcmp(sig, "USR2", siglen)) + ssh->exitcode = 128 + SIGUSR2; +#endif + else + ssh->exitcode = 128; } core = ssh2_pkt_getbool(pktin); ssh_pkt_getstring(pktin, &msg, &msglen);