Add ability for ssh2_userkey_loadpub() to return the key comment.
[u/mdw/putty] / ssh.c
diff --git a/ssh.c b/ssh.c
index c55d217..b30d026 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -134,7 +134,7 @@ static const char *const ssh2_disconnect_reasons[] = {
     "protocol error",
     "key exchange failed",
     "host authentication failed",
-    "mac error",
+    "MAC error",
     "compression error",
     "service not available",
     "protocol version not supported",
@@ -1587,7 +1587,7 @@ static void ssh_pkt_ensure(struct Packet *pkt, int length)
 {
     if (pkt->maxlen < length) {
        unsigned char *body = pkt->body;
-       int offset = body ? pkt->data - body : 0;
+       int offset = body ? body - pkt->data : 0;
        pkt->maxlen = length + 256;
        pkt->data = sresize(pkt->data, pkt->maxlen + APIEXTRA, unsigned char);
        if (body) pkt->body = pkt->data + offset;
@@ -1697,10 +1697,10 @@ static struct Packet *ssh1_pkt_init(int pkt_type)
 static struct Packet *ssh2_pkt_init(int pkt_type)
 {
     struct Packet *pkt = ssh_new_packet();
-    pkt->length = 5;
+    pkt->length = 5; /* space for packet length + padding length */
     pkt->forcepad = 0;
     ssh_pkt_addbyte(pkt, (unsigned char) pkt_type);
-    pkt->body = pkt->data + pkt->length;
+    pkt->body = pkt->data + pkt->length; /* after packet type */
     return pkt;
 }
 
@@ -6640,7 +6640,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen,
            if (keytype == SSH_KEYTYPE_SSH2) {
                s->publickey_blob =
                    ssh2_userkey_loadpub(&ssh->cfg.keyfile, NULL,
-                                        &s->publickey_bloblen, NULL);
+                                        &s->publickey_bloblen, NULL, NULL);
            } else {
                char *msgbuf;
                logeventf(ssh, "Unable to use this key file (%s)",
@@ -6982,7 +6982,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen,
                    (unsigned char *)ssh2_userkey_loadpub(&ssh->cfg.keyfile,
                                                          &algorithm,
                                                          &pub_blob_len,
-                                                         NULL);
+                                                         NULL, NULL);
                if (pub_blob) {
                    s->pktout = ssh2_pkt_init(SSH2_MSG_USERAUTH_REQUEST);
                    ssh2_pkt_addstring(s->pktout, s->username);