mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-04-19 03:58:05 -05:00
Convenience wrappers on plug_closing().
Having a single plug_closing() function covering various kinds of closure is reasonably convenient from the point of view of Plug implementations, but it's annoying for callers, who all have to fill in pointless NULL and 0 parameters in the cases where they're not used. Added some inline helper functions in network.h alongside the main plug_closing() dispatch wrappers, so that each kind of connection closure can present a separate API for the Socket side of the interface, without complicating the vtable for the Plug side. Also, added OS-specific extra helpers in the Unix and Windows directories, which centralise the job of taking an OS error code (of whatever kind) and translating it into its error message. In passing, this removes the horrible ad-hoc made-up error codes in proxy.h, which is OK, because nothing checked for them anyway, and also I'm about to do an API change to plug_closing proper that removes the need for them.
This commit is contained in:
parent
5fdce31eca
commit
364e1aa3f3
@ -224,6 +224,10 @@ static inline void plug_log(
|
|||||||
{ p->vt->log(p, type, addr, port, msg, code); }
|
{ p->vt->log(p, type, addr, port, msg, code); }
|
||||||
static inline void plug_closing(Plug *p, const char *msg, int code)
|
static inline void plug_closing(Plug *p, const char *msg, int code)
|
||||||
{ p->vt->closing(p, msg, code); }
|
{ p->vt->closing(p, msg, code); }
|
||||||
|
static inline void plug_closing_normal(Plug *p)
|
||||||
|
{ p->vt->closing(p, NULL, 0); }
|
||||||
|
static inline void plug_closing_error(Plug *p, const char *msg)
|
||||||
|
{ p->vt->closing(p, msg, 0); }
|
||||||
static inline void plug_receive(Plug *p, int urg, const char *data, size_t len)
|
static inline void plug_receive(Plug *p, int urg, const char *data, size_t len)
|
||||||
{ p->vt->receive(p, urg, data, len); }
|
{ p->vt->receive(p, urg, data, len); }
|
||||||
static inline void plug_sent (Plug *p, size_t bufsize)
|
static inline void plug_sent (Plug *p, size_t bufsize)
|
||||||
|
@ -65,15 +65,13 @@ int proxy_socks5_handlechap (ProxySocket *p)
|
|||||||
* number of attributes
|
* number of attributes
|
||||||
*/
|
*/
|
||||||
if (data[0] != 0x01) {
|
if (data[0] != 0x01) {
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS proxy wants"
|
plug_closing_error(p->plug, "Proxy error: SOCKS proxy wants "
|
||||||
" a different CHAP version",
|
"a different CHAP version");
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (data[1] == 0x00) {
|
if (data[1] == 0x00) {
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS proxy won't"
|
plug_closing_error(p->plug, "Proxy error: SOCKS proxy won't "
|
||||||
" negotiate CHAP with us",
|
"negotiate CHAP with us");
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
p->chap_num_attributes = data[1];
|
p->chap_num_attributes = data[1];
|
||||||
@ -103,9 +101,8 @@ int proxy_socks5_handlechap (ProxySocket *p)
|
|||||||
if (data[0] == 0x00)
|
if (data[0] == 0x00)
|
||||||
p->state = 2;
|
p->state = 2;
|
||||||
else {
|
else {
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS proxy"
|
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
|
||||||
" refused CHAP authentication",
|
"refused CHAP authentication");
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -122,10 +119,9 @@ int proxy_socks5_handlechap (ProxySocket *p)
|
|||||||
case 0x11:
|
case 0x11:
|
||||||
/* Chose a protocol */
|
/* Chose a protocol */
|
||||||
if (data[0] != 0x85) {
|
if (data[0] != 0x85) {
|
||||||
plug_closing(p->plug, "Proxy error: Server chose "
|
plug_closing_error(p->plug, "Proxy error: Server chose "
|
||||||
"CHAP of other than HMAC-MD5 but we "
|
"CHAP of other than HMAC-MD5 but we "
|
||||||
"didn't offer it!",
|
"didn't offer it!");
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -172,8 +168,7 @@ int proxy_socks5_selectchap(ProxySocket *p)
|
|||||||
|
|
||||||
p->state = 8;
|
p->state = 8;
|
||||||
} else
|
} else
|
||||||
plug_closing(p->plug, "Proxy error: Server chose "
|
plug_closing_error(p->plug, "Proxy error: Server chose "
|
||||||
"CHAP authentication but we didn't offer it!",
|
"CHAP authentication but we didn't offer it!");
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,14 @@ void proxy_socks5_offerencryptedauth(BinarySink *bs)
|
|||||||
|
|
||||||
int proxy_socks5_handlechap(ProxySocket *p)
|
int proxy_socks5_handlechap(ProxySocket *p)
|
||||||
{
|
{
|
||||||
|
plug_closing_error(p->plug, "Proxy error: Trying to handle a "
|
||||||
plug_closing(p->plug, "Proxy error: Trying to handle a SOCKS5 CHAP request"
|
"SOCKS5 CHAP request in telnet-only build");
|
||||||
" in telnet-only build",
|
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int proxy_socks5_selectchap(ProxySocket *p)
|
int proxy_socks5_selectchap(ProxySocket *p)
|
||||||
{
|
{
|
||||||
plug_closing(p->plug, "Proxy error: Trying to handle a SOCKS5 CHAP request"
|
plug_closing_error(p->plug, "Proxy error: Trying to handle a "
|
||||||
" in telnet-only build",
|
"SOCKS5 CHAP request in telnet-only build");
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -671,8 +671,8 @@ int proxy_http_negotiate (ProxySocket *p, int change)
|
|||||||
/* We can't rely on whether the %n incremented the sscanf return */
|
/* We can't rely on whether the %n incremented the sscanf return */
|
||||||
if (sscanf((char *)data, "HTTP/%i.%i %n",
|
if (sscanf((char *)data, "HTTP/%i.%i %n",
|
||||||
&maj_ver, &min_ver, &status) < 2 || status == -1) {
|
&maj_ver, &min_ver, &status) < 2 || status == -1) {
|
||||||
plug_closing(p->plug, "Proxy error: HTTP response was absent",
|
plug_closing_error(p->plug, "Proxy error: "
|
||||||
PROXY_ERROR_GENERAL);
|
"HTTP response was absent");
|
||||||
sfree(data);
|
sfree(data);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -687,7 +687,7 @@ int proxy_http_negotiate (ProxySocket *p, int change)
|
|||||||
(data[eol-1] == '\r' || data[eol-1] == '\n'))
|
(data[eol-1] == '\r' || data[eol-1] == '\n'))
|
||||||
data[--eol] = '\0';
|
data[--eol] = '\0';
|
||||||
buf = dupprintf("Proxy error: %s", data+status);
|
buf = dupprintf("Proxy error: %s", data+status);
|
||||||
plug_closing(p->plug, buf, PROXY_ERROR_GENERAL);
|
plug_closing_error(p->plug, buf);
|
||||||
sfree(buf);
|
sfree(buf);
|
||||||
sfree(data);
|
sfree(data);
|
||||||
return 1;
|
return 1;
|
||||||
@ -737,8 +737,7 @@ int proxy_http_negotiate (ProxySocket *p, int change)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plug_closing(p->plug, "Proxy error: unexpected proxy error",
|
plug_closing_error(p->plug, "Proxy error: unexpected proxy error");
|
||||||
PROXY_ERROR_UNEXPECTED);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -854,9 +853,9 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
|
|||||||
bufchain_fetch(&p->pending_input_data, data, 8);
|
bufchain_fetch(&p->pending_input_data, data, 8);
|
||||||
|
|
||||||
if (data[0] != 0) {
|
if (data[0] != 0) {
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS proxy responded with "
|
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
|
||||||
"unexpected reply code version",
|
"responded with unexpected "
|
||||||
PROXY_ERROR_GENERAL);
|
"reply code version");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -864,17 +863,17 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
|
|||||||
|
|
||||||
switch (data[1]) {
|
switch (data[1]) {
|
||||||
case 92:
|
case 92:
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS server wanted IDENTD on client",
|
plug_closing_error(p->plug, "Proxy error: SOCKS server "
|
||||||
PROXY_ERROR_GENERAL);
|
"wanted IDENTD on client");
|
||||||
break;
|
break;
|
||||||
case 93:
|
case 93:
|
||||||
plug_closing(p->plug, "Proxy error: Username and IDENTD on client don't agree",
|
plug_closing_error(p->plug, "Proxy error: Username and "
|
||||||
PROXY_ERROR_GENERAL);
|
"IDENTD on client don't agree");
|
||||||
break;
|
break;
|
||||||
case 91:
|
case 91:
|
||||||
default:
|
default:
|
||||||
plug_closing(p->plug, "Proxy error: Error while communicating with proxy",
|
plug_closing_error(p->plug, "Proxy error: Error while "
|
||||||
PROXY_ERROR_GENERAL);
|
"communicating with proxy");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -890,8 +889,7 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plug_closing(p->plug, "Proxy error: unexpected proxy error",
|
plug_closing_error(p->plug, "Proxy error: unexpected proxy error");
|
||||||
PROXY_ERROR_UNEXPECTED);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -996,8 +994,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
|||||||
bufchain_fetch(&p->pending_input_data, data, 2);
|
bufchain_fetch(&p->pending_input_data, data, 2);
|
||||||
|
|
||||||
if (data[0] != 5) {
|
if (data[0] != 5) {
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS proxy returned unexpected version",
|
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
|
||||||
PROXY_ERROR_GENERAL);
|
"returned unexpected version");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1006,8 +1004,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
|||||||
else if (data[1] == 0x02) p->state = 5; /* username/password authentication */
|
else if (data[1] == 0x02) p->state = 5; /* username/password authentication */
|
||||||
else if (data[1] == 0x03) p->state = 6; /* CHAP authentication */
|
else if (data[1] == 0x03) p->state = 6; /* CHAP authentication */
|
||||||
else {
|
else {
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS proxy did not accept our authentication",
|
plug_closing_error(p->plug, "Proxy error: SOCKS proxy did not "
|
||||||
PROXY_ERROR_GENERAL);
|
"accept our authentication");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
bufchain_consume(&p->pending_input_data, 2);
|
bufchain_consume(&p->pending_input_data, 2);
|
||||||
@ -1030,17 +1028,15 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
|||||||
bufchain_fetch(&p->pending_input_data, data, 2);
|
bufchain_fetch(&p->pending_input_data, data, 2);
|
||||||
|
|
||||||
if (data[0] != 1) {
|
if (data[0] != 1) {
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS password "
|
plug_closing_error(p->plug, "Proxy error: SOCKS password "
|
||||||
"subnegotiation contained wrong version number",
|
"subnegotiation contained wrong version "
|
||||||
PROXY_ERROR_GENERAL);
|
"number");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data[1] != 0) {
|
if (data[1] != 0) {
|
||||||
|
plug_closing_error(p->plug, "Proxy error: SOCKS proxy refused "
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS proxy refused"
|
"password authentication");
|
||||||
" password authentication",
|
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1142,8 +1138,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
|||||||
bufchain_fetch(&p->pending_input_data, data, 5);
|
bufchain_fetch(&p->pending_input_data, data, 5);
|
||||||
|
|
||||||
if (data[0] != 5) {
|
if (data[0] != 5) {
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS proxy returned wrong version number",
|
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
|
||||||
PROXY_ERROR_GENERAL);
|
"returned wrong version number");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1166,7 +1162,7 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
|||||||
data[1]);
|
data[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
plug_closing(p->plug, buf, PROXY_ERROR_GENERAL);
|
plug_closing_error(p->plug, buf);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1180,9 +1176,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
|||||||
case 4: len += 16; break;/* IPv6 address */
|
case 4: len += 16; break;/* IPv6 address */
|
||||||
case 3: len += 1+(unsigned char)data[4]; break; /* domain name */
|
case 3: len += 1+(unsigned char)data[4]; break; /* domain name */
|
||||||
default:
|
default:
|
||||||
plug_closing(p->plug, "Proxy error: SOCKS proxy returned "
|
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
|
||||||
"unrecognised address format",
|
"returned unrecognised address format");
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (bufchain_size(&p->pending_input_data) < len)
|
if (bufchain_size(&p->pending_input_data) < len)
|
||||||
@ -1196,8 +1191,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
|||||||
|
|
||||||
if (p->state == 4) {
|
if (p->state == 4) {
|
||||||
/* TODO: Handle GSSAPI authentication */
|
/* TODO: Handle GSSAPI authentication */
|
||||||
plug_closing(p->plug, "Proxy error: We don't support GSSAPI authentication",
|
plug_closing_error(p->plug, "Proxy error: We don't support "
|
||||||
PROXY_ERROR_GENERAL);
|
"GSSAPI authentication");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1223,10 +1218,9 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
|||||||
strbuf_free(auth);
|
strbuf_free(auth);
|
||||||
p->state = 7;
|
p->state = 7;
|
||||||
} else
|
} else
|
||||||
plug_closing(p->plug, "Proxy error: Server chose "
|
plug_closing_error(p->plug, "Proxy error: Server chose "
|
||||||
"username/password authentication but we "
|
"username/password authentication "
|
||||||
"didn't offer it!",
|
"but we didn't offer it!");
|
||||||
PROXY_ERROR_GENERAL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1238,8 +1232,7 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
plug_closing(p->plug, "Proxy error: Unexpected proxy error",
|
plug_closing_error(p->plug, "Proxy error: Unexpected proxy error");
|
||||||
PROXY_ERROR_UNEXPECTED);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1509,7 +1502,6 @@ int proxy_telnet_negotiate (ProxySocket *p, int change)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
plug_closing(p->plug, "Proxy error: Unexpected proxy error",
|
plug_closing_error(p->plug, "Proxy error: Unexpected proxy error");
|
||||||
PROXY_ERROR_UNEXPECTED);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,6 @@
|
|||||||
#ifndef PUTTY_PROXY_H
|
#ifndef PUTTY_PROXY_H
|
||||||
#define PUTTY_PROXY_H
|
#define PUTTY_PROXY_H
|
||||||
|
|
||||||
#define PROXY_ERROR_GENERAL 8000
|
|
||||||
#define PROXY_ERROR_UNEXPECTED 8001
|
|
||||||
|
|
||||||
typedef struct ProxySocket ProxySocket;
|
typedef struct ProxySocket ProxySocket;
|
||||||
|
|
||||||
struct ProxySocket {
|
struct ProxySocket {
|
||||||
|
@ -234,7 +234,7 @@ static void try_send_ssh_to_socket(void *ctx)
|
|||||||
if (sp->rcvd_eof_ssh_to_socket &&
|
if (sp->rcvd_eof_ssh_to_socket &&
|
||||||
!sp->sent_eof_ssh_to_socket) {
|
!sp->sent_eof_ssh_to_socket) {
|
||||||
sp->sent_eof_ssh_to_socket = true;
|
sp->sent_eof_ssh_to_socket = true;
|
||||||
plug_closing(sp->plug, sp->errmsg, 0);
|
plug_closing_normal(sp->plug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +316,10 @@ static void sshproxy_send_close(SshProxy *sp)
|
|||||||
plug_log(sp->plug, PLUGLOG_CONNECT_FAILED, sp->addr, sp->port,
|
plug_log(sp->plug, PLUGLOG_CONNECT_FAILED, sp->addr, sp->port,
|
||||||
sp->errmsg, 0);
|
sp->errmsg, 0);
|
||||||
|
|
||||||
plug_closing(sp->plug, sp->errmsg, 0);
|
if (sp->errmsg)
|
||||||
|
plug_closing_error(sp->plug, sp->errmsg);
|
||||||
|
else
|
||||||
|
plug_closing_normal(sp->plug);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sshproxy_notify_remote_disconnect_callback(void *vctx)
|
static void sshproxy_notify_remote_disconnect_callback(void *vctx)
|
||||||
|
@ -158,7 +158,7 @@ static void fdsocket_error_callback(void *vs)
|
|||||||
/*
|
/*
|
||||||
* An error has occurred on this socket. Pass it to the plug.
|
* An error has occurred on this socket. Pass it to the plug.
|
||||||
*/
|
*/
|
||||||
plug_closing(fds->plug, strerror(fds->pending_error), fds->pending_error);
|
plug_closing_errno(fds->plug, fds->pending_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fdsocket_try_send(FdSocket *fds)
|
static int fdsocket_try_send(FdSocket *fds)
|
||||||
@ -270,9 +270,9 @@ static void fdsocket_select_result_input(int fd, int event)
|
|||||||
fds->infd = -1;
|
fds->infd = -1;
|
||||||
|
|
||||||
if (retd < 0) {
|
if (retd < 0) {
|
||||||
plug_closing(fds->plug, strerror(errno), errno);
|
plug_closing_errno(fds->plug, errno);
|
||||||
} else {
|
} else {
|
||||||
plug_closing(fds->plug, NULL, 0);
|
plug_closing_normal(fds->plug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1084,6 +1084,11 @@ void *sk_getxdmdata(Socket *sock, int *lenp)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void plug_closing_errno(Plug *plug, int error)
|
||||||
|
{
|
||||||
|
plug_closing(plug, strerror(error), error);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deal with socket errors detected in try_send().
|
* Deal with socket errors detected in try_send().
|
||||||
*/
|
*/
|
||||||
@ -1101,7 +1106,7 @@ static void socket_error_callback(void *vs)
|
|||||||
/*
|
/*
|
||||||
* An error has occurred on this socket. Pass it to the plug.
|
* An error has occurred on this socket. Pass it to the plug.
|
||||||
*/
|
*/
|
||||||
plug_closing(s->plug, strerror(s->pending_error), s->pending_error);
|
plug_closing_errno(s->plug, s->pending_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1295,10 +1300,10 @@ static void net_select_result(int fd, int event)
|
|||||||
*/
|
*/
|
||||||
ret = recv(s->s, buf, sizeof(buf), MSG_OOB);
|
ret = recv(s->s, buf, sizeof(buf), MSG_OOB);
|
||||||
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
|
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
|
||||||
if (ret <= 0) {
|
if (ret == 0) {
|
||||||
plug_closing(s->plug,
|
plug_closing_error(s->plug, "Internal networking trouble");
|
||||||
ret == 0 ? "Internal networking trouble" :
|
} else if (ret < 0) {
|
||||||
strerror(errno), errno);
|
plug_closing_errno(s->plug, errno);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Receiving actual data on a socket means we can
|
* Receiving actual data on a socket means we can
|
||||||
@ -1384,11 +1389,11 @@ static void net_select_result(int fd, int event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
plug_closing(s->plug, strerror(errno), errno);
|
plug_closing_errno(s->plug, errno);
|
||||||
} else if (0 == ret) {
|
} else if (0 == ret) {
|
||||||
s->incomingeof = true; /* stop trying to read now */
|
s->incomingeof = true; /* stop trying to read now */
|
||||||
uxsel_tell(s);
|
uxsel_tell(s);
|
||||||
plug_closing(s->plug, NULL, 0);
|
plug_closing_normal(s->plug);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Receiving actual data on a socket means we can
|
* Receiving actual data on a socket means we can
|
||||||
@ -1438,7 +1443,7 @@ static void net_select_result(int fd, int event)
|
|||||||
err = try_connect(s);
|
err = try_connect(s);
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
plug_closing(s->plug, strerror(err), err);
|
plug_closing_errno(s->plug, err);
|
||||||
return; /* socket is now presumably defunct */
|
return; /* socket is now presumably defunct */
|
||||||
}
|
}
|
||||||
if (!s->connected)
|
if (!s->connected)
|
||||||
|
@ -458,4 +458,7 @@ bool cliloop_no_pw_setup(void *ctx, pollwrapper *pw);
|
|||||||
void cliloop_no_pw_check(void *ctx, pollwrapper *pw);
|
void cliloop_no_pw_check(void *ctx, pollwrapper *pw);
|
||||||
bool cliloop_always_continue(void *ctx, bool, bool);
|
bool cliloop_always_continue(void *ctx, bool, bool);
|
||||||
|
|
||||||
|
/* network.c: network error reporting helper taking an OS error code */
|
||||||
|
void plug_closing_errno(Plug *plug, int error);
|
||||||
|
|
||||||
#endif /* PUTTY_UNIX_PLATFORM_H */
|
#endif /* PUTTY_UNIX_PLATFORM_H */
|
||||||
|
@ -53,10 +53,10 @@ static size_t handle_gotdata(
|
|||||||
HandleSocket *hs = (HandleSocket *)handle_get_privdata(h);
|
HandleSocket *hs = (HandleSocket *)handle_get_privdata(h);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
plug_closing(hs->plug, "Read error from handle", 0);
|
plug_closing_error(hs->plug, "Read error from handle");
|
||||||
return 0;
|
return 0;
|
||||||
} else if (len == 0) {
|
} else if (len == 0) {
|
||||||
plug_closing(hs->plug, NULL, 0);
|
plug_closing_normal(hs->plug);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
assert(hs->frozen != FROZEN && hs->frozen != THAWING);
|
assert(hs->frozen != FROZEN && hs->frozen != THAWING);
|
||||||
@ -107,7 +107,7 @@ static void handle_sentdata(struct handle *h, size_t new_backlog, int err,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
plug_closing(hs->plug, win_strerror(err), err);
|
plug_closing_system_error(hs->plug, err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1335,6 +1335,16 @@ static void sk_net_close(Socket *sock)
|
|||||||
sfree(s);
|
sfree(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void plug_closing_system_error(Plug *plug, DWORD error)
|
||||||
|
{
|
||||||
|
plug_closing(plug, win_strerror(error), error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void plug_closing_winsock_error(Plug *plug, DWORD error)
|
||||||
|
{
|
||||||
|
plug_closing(plug, winsock_error_string(error), error);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deal with socket errors detected in try_send().
|
* Deal with socket errors detected in try_send().
|
||||||
*/
|
*/
|
||||||
@ -1352,8 +1362,7 @@ static void socket_error_callback(void *vs)
|
|||||||
/*
|
/*
|
||||||
* An error has occurred on this socket. Pass it to the plug.
|
* An error has occurred on this socket. Pass it to the plug.
|
||||||
*/
|
*/
|
||||||
plug_closing(s->plug, winsock_error_string(s->pending_error),
|
plug_closing_winsock_error(s->plug, s->pending_error);
|
||||||
s->pending_error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1528,7 +1537,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
plug_closing(s->plug, winsock_error_string(err), err);
|
plug_closing_winsock_error(s->plug, err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1590,9 +1599,9 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
plug_closing(s->plug, winsock_error_string(err), err);
|
plug_closing_winsock_error(s->plug, err);
|
||||||
} else if (0 == ret) {
|
} else if (0 == ret) {
|
||||||
plug_closing(s->plug, NULL, 0);
|
plug_closing_normal(s->plug);
|
||||||
} else {
|
} else {
|
||||||
plug_receive(s->plug, atmark ? 0 : 1, buf, ret);
|
plug_receive(s->plug, atmark ? 0 : 1, buf, ret);
|
||||||
}
|
}
|
||||||
@ -1608,7 +1617,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
|||||||
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
|
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
int err = p_WSAGetLastError();
|
int err = p_WSAGetLastError();
|
||||||
plug_closing(s->plug, winsock_error_string(err), err);
|
plug_closing_winsock_error(s->plug, err);
|
||||||
} else {
|
} else {
|
||||||
plug_receive(s->plug, 2, buf, ret);
|
plug_receive(s->plug, 2, buf, ret);
|
||||||
}
|
}
|
||||||
@ -1631,12 +1640,12 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
|||||||
err = p_WSAGetLastError();
|
err = p_WSAGetLastError();
|
||||||
if (err == WSAEWOULDBLOCK)
|
if (err == WSAEWOULDBLOCK)
|
||||||
break;
|
break;
|
||||||
plug_closing(s->plug, winsock_error_string(err), err);
|
plug_closing_winsock_error(s->plug, err);
|
||||||
} else {
|
} else {
|
||||||
if (ret)
|
if (ret)
|
||||||
plug_receive(s->plug, 0, buf, ret);
|
plug_receive(s->plug, 0, buf, ret);
|
||||||
else
|
else
|
||||||
plug_closing(s->plug, NULL, 0);
|
plug_closing_normal(s->plug);
|
||||||
}
|
}
|
||||||
} while (ret > 0);
|
} while (ret > 0);
|
||||||
return;
|
return;
|
||||||
|
@ -730,4 +730,8 @@ char *handle_restrict_acl_cmdline_prefix(char *cmdline);
|
|||||||
bool handle_special_sessionname_cmdline(char *cmdline, Conf *conf);
|
bool handle_special_sessionname_cmdline(char *cmdline, Conf *conf);
|
||||||
bool handle_special_filemapping_cmdline(char *cmdline, Conf *conf);
|
bool handle_special_filemapping_cmdline(char *cmdline, Conf *conf);
|
||||||
|
|
||||||
|
/* network.c: network error reporting helpers taking OS error code */
|
||||||
|
void plug_closing_system_error(Plug *plug, DWORD error);
|
||||||
|
void plug_closing_winsock_error(Plug *plug, DWORD error);
|
||||||
|
|
||||||
#endif /* PUTTY_WINDOWS_PLATFORM_H */
|
#endif /* PUTTY_WINDOWS_PLATFORM_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user