mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 09:58:01 +00:00
Slightly gratuitous logeventf() crusade and purge of fixed-length buffers.
Also a bonus sfree(). [originally from svn r5281]
This commit is contained in:
parent
3311f89129
commit
7ffad81d31
78
ssh.c
78
ssh.c
@ -2247,13 +2247,7 @@ static int do_ssh_init(Ssh ssh, unsigned char c)
|
|||||||
|
|
||||||
s->vstring[s->vslen] = 0;
|
s->vstring[s->vslen] = 0;
|
||||||
s->vstring[strcspn(s->vstring, "\015\012")] = '\0';/* remove EOL chars */
|
s->vstring[strcspn(s->vstring, "\015\012")] = '\0';/* remove EOL chars */
|
||||||
{
|
logeventf(ssh, "Server version: %s", s->vstring);
|
||||||
char *vlog;
|
|
||||||
vlog = snewn(20 + s->vslen, char);
|
|
||||||
sprintf(vlog, "Server version: %s", s->vstring);
|
|
||||||
logevent(vlog);
|
|
||||||
sfree(vlog);
|
|
||||||
}
|
|
||||||
ssh_detect_bugs(ssh, s->vstring);
|
ssh_detect_bugs(ssh, s->vstring);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2433,6 +2427,7 @@ static void ssh_log(Plug plug, int type, SockAddr addr, int port,
|
|||||||
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
||||||
|
|
||||||
logevent(msg);
|
logevent(msg);
|
||||||
|
sfree(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ssh_closing(Plug plug, const char *error_msg, int error_code,
|
static int ssh_closing(Plug plug, const char *error_msg, int error_code,
|
||||||
@ -3047,17 +3042,9 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen,
|
|||||||
s->p = s->response + 5;
|
s->p = s->response + 5;
|
||||||
s->nkeys = GET_32BIT(s->p);
|
s->nkeys = GET_32BIT(s->p);
|
||||||
s->p += 4;
|
s->p += 4;
|
||||||
{
|
logeventf(ssh, "Pageant has %d SSH1 keys", s->nkeys);
|
||||||
char buf[64];
|
|
||||||
sprintf(buf, "Pageant has %d SSH1 keys", s->nkeys);
|
|
||||||
logevent(buf);
|
|
||||||
}
|
|
||||||
for (s->keyi = 0; s->keyi < s->nkeys; s->keyi++) {
|
for (s->keyi = 0; s->keyi < s->nkeys; s->keyi++) {
|
||||||
{
|
logeventf(ssh, "Trying Pageant key #%d", s->keyi);
|
||||||
char buf[64];
|
|
||||||
sprintf(buf, "Trying Pageant key #%d", s->keyi);
|
|
||||||
logevent(buf);
|
|
||||||
}
|
|
||||||
if (s->publickey_blob &&
|
if (s->publickey_blob &&
|
||||||
!memcmp(s->p, s->publickey_blob,
|
!memcmp(s->p, s->publickey_blob,
|
||||||
s->publickey_bloblen)) {
|
s->publickey_bloblen)) {
|
||||||
@ -3266,18 +3253,18 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen,
|
|||||||
if (s->pwpkt_type == SSH1_CMSG_AUTH_RSA) {
|
if (s->pwpkt_type == SSH1_CMSG_AUTH_RSA) {
|
||||||
char *comment = NULL;
|
char *comment = NULL;
|
||||||
int type;
|
int type;
|
||||||
char msgbuf[256];
|
|
||||||
if (flags & FLAG_VERBOSE)
|
if (flags & FLAG_VERBOSE)
|
||||||
c_write_str(ssh, "Trying public key authentication.\r\n");
|
c_write_str(ssh, "Trying public key authentication.\r\n");
|
||||||
logeventf(ssh, "Trying public key \"%s\"",
|
logeventf(ssh, "Trying public key \"%s\"",
|
||||||
filename_to_str(&ssh->cfg.keyfile));
|
filename_to_str(&ssh->cfg.keyfile));
|
||||||
type = key_type(&ssh->cfg.keyfile);
|
type = key_type(&ssh->cfg.keyfile);
|
||||||
if (type != SSH_KEYTYPE_SSH1) {
|
if (type != SSH_KEYTYPE_SSH1) {
|
||||||
sprintf(msgbuf, "Key is of wrong type (%s)",
|
char *msg = dupprintf("Key is of wrong type (%s)",
|
||||||
key_type_to_str(type));
|
key_type_to_str(type));
|
||||||
logevent(msgbuf);
|
logevent(msg);
|
||||||
c_write_str(ssh, msgbuf);
|
c_write_str(ssh, msg);
|
||||||
c_write_str(ssh, "\r\n");
|
c_write_str(ssh, "\r\n");
|
||||||
|
sfree(msg);
|
||||||
s->tried_publickey = 1;
|
s->tried_publickey = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -4145,7 +4132,7 @@ static void ssh1_msg_port_open(Ssh ssh, struct Packet *pktin)
|
|||||||
struct ssh_rportfwd pf, *pfp;
|
struct ssh_rportfwd pf, *pfp;
|
||||||
int remoteid;
|
int remoteid;
|
||||||
int hostsize, port;
|
int hostsize, port;
|
||||||
char *host, buf[1024];
|
char *host;
|
||||||
const char *e;
|
const char *e;
|
||||||
c = snew(struct ssh_channel);
|
c = snew(struct ssh_channel);
|
||||||
c->ssh = ssh;
|
c->ssh = ssh;
|
||||||
@ -4162,21 +4149,17 @@ static void ssh1_msg_port_open(Ssh ssh, struct Packet *pktin)
|
|||||||
pfp = find234(ssh->rportfwds, &pf, NULL);
|
pfp = find234(ssh->rportfwds, &pf, NULL);
|
||||||
|
|
||||||
if (pfp == NULL) {
|
if (pfp == NULL) {
|
||||||
sprintf(buf, "Rejected remote port open request for %s:%d",
|
logeventf(ssh, "Rejected remote port open request for %s:%d",
|
||||||
pf.dhost, port);
|
pf.dhost, port);
|
||||||
logevent(buf);
|
|
||||||
send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
|
send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
|
||||||
PKT_INT, remoteid, PKT_END);
|
PKT_INT, remoteid, PKT_END);
|
||||||
} else {
|
} else {
|
||||||
sprintf(buf, "Received remote port open request for %s:%d",
|
logeventf(ssh, "Received remote port open request for %s:%d",
|
||||||
pf.dhost, port);
|
pf.dhost, port);
|
||||||
logevent(buf);
|
|
||||||
e = pfd_newconnect(&c->u.pfd.s, pf.dhost, port,
|
e = pfd_newconnect(&c->u.pfd.s, pf.dhost, port,
|
||||||
c, &ssh->cfg, pfp->pfrec->addressfamily);
|
c, &ssh->cfg, pfp->pfrec->addressfamily);
|
||||||
if (e != NULL) {
|
if (e != NULL) {
|
||||||
char buf[256];
|
logeventf(ssh, "Port open failed: %s", e);
|
||||||
sprintf(buf, "Port open failed: %s", e);
|
|
||||||
logevent(buf);
|
|
||||||
sfree(c);
|
sfree(c);
|
||||||
send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
|
send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
|
||||||
PKT_INT, remoteid, PKT_END);
|
PKT_INT, remoteid, PKT_END);
|
||||||
@ -4352,11 +4335,8 @@ static void ssh1_msg_channel_data(Ssh ssh, struct Packet *pktin)
|
|||||||
|
|
||||||
static void ssh1_smsg_exit_status(Ssh ssh, struct Packet *pktin)
|
static void ssh1_smsg_exit_status(Ssh ssh, struct Packet *pktin)
|
||||||
{
|
{
|
||||||
char buf[100];
|
|
||||||
ssh->exitcode = ssh_pkt_getuint32(pktin);
|
ssh->exitcode = ssh_pkt_getuint32(pktin);
|
||||||
sprintf(buf, "Server sent command exit status %d",
|
logeventf(ssh, "Server sent command exit status %d", ssh->exitcode);
|
||||||
ssh->exitcode);
|
|
||||||
logevent(buf);
|
|
||||||
send_packet(ssh, SSH1_CMSG_EXIT_CONFIRMATION, PKT_END);
|
send_packet(ssh, SSH1_CMSG_EXIT_CONFIRMATION, PKT_END);
|
||||||
/*
|
/*
|
||||||
* In case `helpful' firewalls or proxies tack
|
* In case `helpful' firewalls or proxies tack
|
||||||
@ -4563,13 +4543,11 @@ static void do_ssh1_connection(Ssh ssh, unsigned char *in, int inlen,
|
|||||||
*/
|
*/
|
||||||
static void ssh1_msg_debug(Ssh ssh, struct Packet *pktin)
|
static void ssh1_msg_debug(Ssh ssh, struct Packet *pktin)
|
||||||
{
|
{
|
||||||
char *buf, *msg;
|
char *msg;
|
||||||
int msglen;
|
int msglen;
|
||||||
|
|
||||||
ssh_pkt_getstring(pktin, &msg, &msglen);
|
ssh_pkt_getstring(pktin, &msg, &msglen);
|
||||||
buf = dupprintf("Remote debug message: %.*s", msglen, msg);
|
logeventf(ssh, "Remote debug message: %.*s", msglen, msg);
|
||||||
logevent(buf);
|
|
||||||
sfree(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ssh1_msg_disconnect(Ssh ssh, struct Packet *pktin)
|
static void ssh1_msg_disconnect(Ssh ssh, struct Packet *pktin)
|
||||||
@ -5737,7 +5715,6 @@ static void ssh2_msg_channel_open_failure(Ssh ssh, struct Packet *pktin)
|
|||||||
unsigned reason_code;
|
unsigned reason_code;
|
||||||
char *reason_string;
|
char *reason_string;
|
||||||
int reason_length;
|
int reason_length;
|
||||||
char *message;
|
|
||||||
struct ssh_channel *c;
|
struct ssh_channel *c;
|
||||||
c = find234(ssh->channels, &i, ssh_channelfind);
|
c = find234(ssh->channels, &i, ssh_channelfind);
|
||||||
if (!c)
|
if (!c)
|
||||||
@ -5749,11 +5726,8 @@ static void ssh2_msg_channel_open_failure(Ssh ssh, struct Packet *pktin)
|
|||||||
if (reason_code >= lenof(reasons))
|
if (reason_code >= lenof(reasons))
|
||||||
reason_code = 0; /* ensure reasons[reason_code] in range */
|
reason_code = 0; /* ensure reasons[reason_code] in range */
|
||||||
ssh_pkt_getstring(pktin, &reason_string, &reason_length);
|
ssh_pkt_getstring(pktin, &reason_string, &reason_length);
|
||||||
message = dupprintf("Forwarded connection refused by"
|
logeventf(ssh, "Forwarded connection refused by server: %s [%.*s]",
|
||||||
" server: %s [%.*s]", reasons[reason_code],
|
reasons[reason_code], reason_length, reason_string);
|
||||||
reason_length, reason_string);
|
|
||||||
logevent(message);
|
|
||||||
sfree(message);
|
|
||||||
|
|
||||||
pfd_close(c->u.pfd.s);
|
pfd_close(c->u.pfd.s);
|
||||||
|
|
||||||
@ -6388,19 +6362,11 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen,
|
|||||||
s->p = s->response + 5;
|
s->p = s->response + 5;
|
||||||
s->nkeys = GET_32BIT(s->p);
|
s->nkeys = GET_32BIT(s->p);
|
||||||
s->p += 4;
|
s->p += 4;
|
||||||
{
|
logeventf(ssh, "Pageant has %d SSH2 keys", s->nkeys);
|
||||||
char buf[64];
|
|
||||||
sprintf(buf, "Pageant has %d SSH2 keys", s->nkeys);
|
|
||||||
logevent(buf);
|
|
||||||
}
|
|
||||||
for (s->keyi = 0; s->keyi < s->nkeys; s->keyi++) {
|
for (s->keyi = 0; s->keyi < s->nkeys; s->keyi++) {
|
||||||
void *vret;
|
void *vret;
|
||||||
|
|
||||||
{
|
logeventf(ssh, "Trying Pageant key #%d", s->keyi);
|
||||||
char buf[64];
|
|
||||||
sprintf(buf, "Trying Pageant key #%d", s->keyi);
|
|
||||||
logevent(buf);
|
|
||||||
}
|
|
||||||
s->pklen = GET_32BIT(s->p);
|
s->pklen = GET_32BIT(s->p);
|
||||||
s->p += 4;
|
s->p += 4;
|
||||||
if (s->publickey_blob &&
|
if (s->publickey_blob &&
|
||||||
@ -7288,7 +7254,7 @@ static void ssh2_msg_disconnect(Ssh ssh, struct Packet *pktin)
|
|||||||
static void ssh2_msg_debug(Ssh ssh, struct Packet *pktin)
|
static void ssh2_msg_debug(Ssh ssh, struct Packet *pktin)
|
||||||
{
|
{
|
||||||
/* log the debug message */
|
/* log the debug message */
|
||||||
char *buf, *msg;
|
char *msg;
|
||||||
int msglen;
|
int msglen;
|
||||||
int always_display;
|
int always_display;
|
||||||
|
|
||||||
@ -7296,9 +7262,7 @@ static void ssh2_msg_debug(Ssh ssh, struct Packet *pktin)
|
|||||||
always_display = ssh2_pkt_getbool(pktin);
|
always_display = ssh2_pkt_getbool(pktin);
|
||||||
ssh_pkt_getstring(pktin, &msg, &msglen);
|
ssh_pkt_getstring(pktin, &msg, &msglen);
|
||||||
|
|
||||||
buf = dupprintf("Remote debug message: %.*s", msglen, msg);
|
logeventf(ssh, "Remote debug message: %.*s", msglen, msg);
|
||||||
logevent(buf);
|
|
||||||
sfree(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ssh2_msg_something_unimplemented(Ssh ssh, struct Packet *pktin)
|
static void ssh2_msg_something_unimplemented(Ssh ssh, struct Packet *pktin)
|
||||||
|
Loading…
Reference in New Issue
Block a user