Просмотр исходного кода

Merge branch 'thirdparty_dev' into dev

# Conflicts:
#	source/putty/WINDOWS/wingss.c
#	source/putty/WINDOWS/winhandl.c
#	source/putty/WINDOWS/winhsock.c
#	source/putty/WINDOWS/winnet.c
#	source/putty/WINDOWS/winpgntc.c
#	source/putty/WINDOWS/winstore.c

#	source/putty/import.c
#	source/putty/logging.c
#	source/putty/mainchan.c
#	source/putty/proxy.c
#	source/putty/ssh.c
#	source/putty/ssh1connection-client.c
#	source/putty/ssh2connection-client.c
#	source/putty/ssh2userauth.c
#	source/putty/sshmd5.c
#	source/putty/sshpubk.c
#	source/putty/sshrsa.c
#	source/putty/sshsh256.c
#	source/putty/sshsha.c
#	source/putty/storage.h
#	source/putty/utils.c
#	source/putty/x11fwd.c

Source commit: 8e49ad4df32f586004373762d351a630e89d01b0
Martin Prikryl 6 лет назад
Родитель
Сommit
c4b7d2c71d
74 измененных файлов с 5251 добавлено и 5251 удалено
  1. 120 120
      source/putty/conf.c
  2. 125 125
      source/putty/cproxy.c
  3. 1 1
      source/putty/ecc.c
  4. 1 1
      source/putty/errsock.c
  5. 274 274
      source/putty/import.c
  6. 155 155
      source/putty/logging.c
  7. 6 6
      source/putty/mainchan.c
  8. 11 11
      source/putty/memory.c
  9. 9 9
      source/putty/misc.c
  10. 2 2
      source/putty/misc.h
  11. 1 1
      source/putty/mpint.c
  12. 3 3
      source/putty/mpint_i.h
  13. 16 16
      source/putty/network.h
  14. 1 1
      source/putty/nullplug.c
  15. 1 1
      source/putty/pgssapi.h
  16. 30 30
      source/putty/portfwd.c
  17. 430 430
      source/putty/proxy.c
  18. 4 4
      source/putty/proxy.h
  19. 71 71
      source/putty/putty.h
  20. 2 2
      source/putty/puttymem.h
  21. 45 45
      source/putty/ssh.c
  22. 40 40
      source/putty/ssh.h
  23. 1 1
      source/putty/ssh1bpp.c
  24. 5 5
      source/putty/ssh1connection-client.c
  25. 21 21
      source/putty/ssh1connection.c
  26. 1 1
      source/putty/ssh1connection.h
  27. 13 13
      source/putty/ssh1login.c
  28. 12 12
      source/putty/ssh2connection-client.c
  29. 61 61
      source/putty/ssh2connection.c
  30. 1 1
      source/putty/ssh2connection.h
  31. 10 10
      source/putty/ssh2transport.c
  32. 27 27
      source/putty/ssh2userauth.c
  33. 8 8
      source/putty/sshaes.c
  34. 10 10
      source/putty/ssharcf.c
  35. 10 10
      source/putty/sshauxcrypt.c
  36. 94 94
      source/putty/sshblowf.c
  37. 1 1
      source/putty/sshbpp.h
  38. 4 4
      source/putty/sshcr.h
  39. 16 16
      source/putty/sshcrcda.c
  40. 1 1
      source/putty/sshdes.c
  41. 2 2
      source/putty/sshdh.c
  42. 31 31
      source/putty/sshdss.c
  43. 19 19
      source/putty/sshgss.h
  44. 28 28
      source/putty/sshgssc.c
  45. 31 31
      source/putty/sshmd5.c
  46. 1 1
      source/putty/sshppl.h
  47. 292 292
      source/putty/sshpubk.c
  48. 7 7
      source/putty/sshrand.c
  49. 31 31
      source/putty/sshrsa.c
  50. 11 11
      source/putty/sshsh256.c
  51. 87 87
      source/putty/sshsh512.c
  52. 3 3
      source/putty/sshsha.c
  53. 12 12
      source/putty/sshshare.c
  54. 510 510
      source/putty/sshzlib.c
  55. 5 5
      source/putty/storage.h
  56. 654 654
      source/putty/tree234.c
  57. 21 21
      source/putty/tree234.h
  58. 182 182
      source/putty/utils.c
  59. 195 195
      source/putty/wildcard.c
  60. 134 134
      source/putty/windows/wingss.c
  61. 212 212
      source/putty/windows/winhandl.c
  62. 6 6
      source/putty/windows/winhsock.c
  63. 72 72
      source/putty/windows/winmisc.c
  64. 41 41
      source/putty/windows/winmiscs.c
  65. 311 311
      source/putty/windows/winnet.c
  66. 7 7
      source/putty/windows/winnoise.c
  67. 6 6
      source/putty/windows/winpgntc.c
  68. 10 10
      source/putty/windows/winproxy.c
  69. 12 12
      source/putty/windows/winsecur.c
  70. 10 10
      source/putty/windows/winsecur.h
  71. 166 166
      source/putty/windows/winstore.c
  72. 48 48
      source/putty/windows/winstuff.h
  73. 178 178
      source/putty/windows/winucs.c
  74. 272 272
      source/putty/x11fwd.c

+ 120 - 120
source/putty/conf.c

@@ -36,8 +36,8 @@ static int valuetypes[] = { CONFIG_OPTIONS(CONF_VALUETYPE_DEF) };
 struct key {
     int primary;
     union {
-	int i;
-	char *s;
+        int i;
+        char *s;
     } secondary;
 };
 
@@ -46,18 +46,18 @@ struct key {
 struct constkey {
     int primary;
     union {
-	int i;
-	const char *s;
+        int i;
+        const char *s;
     } secondary;
 };
 
 struct value {
     union {
-	bool boolval;
-	int intval;
-	char *stringval;
-	Filename *fileval;
-	FontSpec *fontval;
+        bool boolval;
+        int intval;
+        char *stringval;
+        Filename *fileval;
+        FontSpec *fontval;
     } u;
 };
 
@@ -84,20 +84,20 @@ static int conf_cmp(void *av, void *bv)
     struct key *b = (struct key *)bv;
 
     if (a->primary < b->primary)
-	return -1;
+        return -1;
     else if (a->primary > b->primary)
-	return +1;
+        return +1;
     switch (subkeytypes[a->primary]) {
       case TYPE_INT:
-	if (a->secondary.i < b->secondary.i)
-	    return -1;
-	else if (a->secondary.i > b->secondary.i)
-	    return +1;
-	return 0;
+        if (a->secondary.i < b->secondary.i)
+            return -1;
+        else if (a->secondary.i > b->secondary.i)
+            return +1;
+        return 0;
       case TYPE_STR:
-	return strcmp(a->secondary.s, b->secondary.s);
+        return strcmp(a->secondary.s, b->secondary.s);
       default:
-	return 0;
+        return 0;
     }
 }
 
@@ -107,20 +107,20 @@ static int conf_cmp_constkey(void *av, void *bv)
     struct constkey *b = (struct constkey *)bv;
 
     if (a->primary < b->primary)
-	return -1;
+        return -1;
     else if (a->primary > b->primary)
-	return +1;
+        return +1;
     switch (subkeytypes[a->primary]) {
       case TYPE_INT:
-	if (a->secondary.i < b->secondary.i)
-	    return -1;
-	else if (a->secondary.i > b->secondary.i)
-	    return +1;
-	return 0;
+        if (a->secondary.i < b->secondary.i)
+            return -1;
+        else if (a->secondary.i > b->secondary.i)
+            return +1;
+        return 0;
       case TYPE_STR:
-	return strcmp(a->secondary.s, b->secondary.s);
+        return strcmp(a->secondary.s, b->secondary.s);
       default:
-	return 0;
+        return 0;
     }
 }
 
@@ -132,7 +132,7 @@ static int conf_cmp_constkey(void *av, void *bv)
 static void free_key(struct key *key)
 {
     if (subkeytypes[key->primary] == TYPE_STR)
-	sfree(key->secondary.s);
+        sfree(key->secondary.s);
 }
 
 /*
@@ -144,11 +144,11 @@ static void copy_key(struct key *to, struct key *from)
     to->primary = from->primary;
     switch (subkeytypes[to->primary]) {
       case TYPE_INT:
-	to->secondary.i = from->secondary.i;
-	break;
+        to->secondary.i = from->secondary.i;
+        break;
       case TYPE_STR:
-	to->secondary.s = dupstr(from->secondary.s);
-	break;
+        to->secondary.s = dupstr(from->secondary.s);
+        break;
     }
 }
 
@@ -160,11 +160,11 @@ static void copy_key(struct key *to, struct key *from)
 static void free_value(struct value *val, int type)
 {
     if (type == TYPE_STR)
-	sfree(val->u.stringval);
+        sfree(val->u.stringval);
     else if (type == TYPE_FILENAME)
-	filename_free(val->u.fileval);
+        filename_free(val->u.fileval);
     else if (type == TYPE_FONT)
-	fontspec_free(val->u.fontval);
+        fontspec_free(val->u.fontval);
 }
 
 /*
@@ -175,20 +175,20 @@ static void copy_value(struct value *to, struct value *from, int type)
 {
     switch (type) {
       case TYPE_BOOL:
-	to->u.boolval = from->u.boolval;
-	break;
+        to->u.boolval = from->u.boolval;
+        break;
       case TYPE_INT:
-	to->u.intval = from->u.intval;
-	break;
+        to->u.intval = from->u.intval;
+        break;
       case TYPE_STR:
-	to->u.stringval = dupstr(from->u.stringval);
-	break;
+        to->u.stringval = dupstr(from->u.stringval);
+        break;
       case TYPE_FILENAME:
-	to->u.fileval = filename_copy(from->u.fileval);
-	break;
+        to->u.fileval = filename_copy(from->u.fileval);
+        break;
       case TYPE_FONT:
-	to->u.fontval = fontspec_copy(from->u.fontval);
-	break;
+        to->u.fontval = fontspec_copy(from->u.fontval);
+        break;
     }
 }
 
@@ -216,7 +216,7 @@ static void conf_clear(Conf *conf)
     struct conf_entry *entry;
 
     while ((entry = delpos234(conf->tree, 0)) != NULL)
-	free_entry(entry);
+        free_entry(entry);
 }
 
 void conf_free(Conf *conf)
@@ -230,10 +230,10 @@ static void conf_insert(Conf *conf, struct conf_entry *entry)
 {
     struct conf_entry *oldentry = add234(conf->tree, entry);
     if (oldentry && oldentry != entry) {
-	del234(conf->tree, oldentry);
-	free_entry(oldentry);
-	oldentry = add234(conf->tree, entry);
-	assert(oldentry == entry);
+        del234(conf->tree, oldentry);
+        free_entry(oldentry);
+        oldentry = add234(conf->tree, entry);
+        assert(oldentry == entry);
     }
 }
 
@@ -245,11 +245,11 @@ void conf_copy_into(Conf *newconf, Conf *oldconf)
     conf_clear(newconf);
 
     for (i = 0; (entry = index234(oldconf->tree, i)) != NULL; i++) {
-	entry2 = snew(struct conf_entry);
-	copy_key(&entry2->key, &entry->key);
-	copy_value(&entry2->value, &entry->value,
-		   valuetypes[entry->key.primary]);
-	add234(newconf->tree, entry2);
+        entry2 = snew(struct conf_entry);
+        copy_key(&entry2->key, &entry->key);
+        copy_value(&entry2->value, &entry->value,
+                   valuetypes[entry->key.primary]);
+        add234(newconf->tree, entry2);
     }
 }
 
@@ -336,7 +336,7 @@ char *conf_get_str_str(Conf *conf, int primary, const char *secondary)
 }
 
 char *conf_get_str_strs(Conf *conf, int primary,
-		       char *subkeyin, char **subkeyout)
+                       char *subkeyin, char **subkeyout)
 {
     struct constkey key;
     struct conf_entry *entry;
@@ -345,14 +345,14 @@ char *conf_get_str_strs(Conf *conf, int primary,
     assert(valuetypes[primary] == TYPE_STR);
     key.primary = primary;
     if (subkeyin) {
-	key.secondary.s = subkeyin;
-	entry = findrel234(conf->tree, &key, NULL, REL234_GT);
+        key.secondary.s = subkeyin;
+        entry = findrel234(conf->tree, &key, NULL, REL234_GT);
     } else {
-	key.secondary.s = "";
-	entry = findrel234(conf->tree, &key, conf_cmp_constkey, REL234_GE);
+        key.secondary.s = "";
+        entry = findrel234(conf->tree, &key, conf_cmp_constkey, REL234_GE);
     }
     if (!entry || entry->key.primary != primary)
-	return NULL;
+        return NULL;
     *subkeyout = entry->key.secondary.s;
     return entry->value.u.stringval;
 }
@@ -370,10 +370,10 @@ char *conf_get_str_nthstrkey(Conf *conf, int primary, int n)
     entry = findrelpos234(conf->tree, &key, conf_cmp_constkey,
                           REL234_GE, &index);
     if (!entry || entry->key.primary != primary)
-	return NULL;
+        return NULL;
     entry = index234(conf->tree, index + n);
     if (!entry || entry->key.primary != primary)
-	return NULL;
+        return NULL;
     return entry->key.secondary.s;
 }
 
@@ -450,7 +450,7 @@ void conf_set_str(Conf *conf, int primary, const char *value)
 }
 
 void conf_set_str_str(Conf *conf, int primary, const char *secondary,
-		      const char *value)
+                      const char *value)
 {
     struct conf_entry *entry = snew(struct conf_entry);
 
@@ -473,8 +473,8 @@ void conf_del_str_str(Conf *conf, int primary, const char *secondary)
     key.secondary.s = (char *)secondary;
     entry = find234(conf->tree, &key, NULL);
     if (entry) {
-	del234(conf->tree, entry);
-	free_entry(entry);
+        del234(conf->tree, entry);
+        free_entry(entry);
     }
  }
 
@@ -506,33 +506,33 @@ void conf_serialise(BinarySink *bs, Conf *conf)
     struct conf_entry *entry;
 
     for (i = 0; (entry = index234(conf->tree, i)) != NULL; i++) {
-	put_uint32(bs, entry->key.primary);
+        put_uint32(bs, entry->key.primary);
 
-	switch (subkeytypes[entry->key.primary]) {
-	  case TYPE_INT:
-	    put_uint32(bs, entry->key.secondary.i);
-	    break;
-	  case TYPE_STR:
+        switch (subkeytypes[entry->key.primary]) {
+          case TYPE_INT:
+            put_uint32(bs, entry->key.secondary.i);
+            break;
+          case TYPE_STR:
             put_asciz(bs, entry->key.secondary.s);
-	    break;
-	}
-	switch (valuetypes[entry->key.primary]) {
-	  case TYPE_BOOL:
-	    put_bool(bs, entry->value.u.boolval);
-	    break;
-	  case TYPE_INT:
-	    put_uint32(bs, entry->value.u.intval);
-	    break;
-	  case TYPE_STR:
-	    put_asciz(bs, entry->value.u.stringval);
-	    break;
-	  case TYPE_FILENAME:
+            break;
+        }
+        switch (valuetypes[entry->key.primary]) {
+          case TYPE_BOOL:
+            put_bool(bs, entry->value.u.boolval);
+            break;
+          case TYPE_INT:
+            put_uint32(bs, entry->value.u.intval);
+            break;
+          case TYPE_STR:
+            put_asciz(bs, entry->value.u.stringval);
+            break;
+          case TYPE_FILENAME:
             filename_serialise(bs, entry->value.u.fileval);
-	    break;
-	  case TYPE_FONT:
+            break;
+          case TYPE_FONT:
             fontspec_serialise(bs, entry->value.u.fontval);
-	    break;
-	}
+            break;
+        }
     }
 
     put_uint32(bs, 0xFFFFFFFFU);
@@ -550,44 +550,44 @@ bool conf_deserialise(Conf *conf, BinarySource *src)
             return false;
         if (primary == 0xFFFFFFFFU)
             return true;
-	if (primary >= N_CONFIG_OPTIONS)
-	    return false;
-
-	entry = snew(struct conf_entry);
-	entry->key.primary = primary;
-
-	switch (subkeytypes[entry->key.primary]) {
-	  case TYPE_INT:
-	    entry->key.secondary.i = toint(get_uint32(src));
-	    break;
-	  case TYPE_STR:
-	    entry->key.secondary.s = dupstr(get_asciz(src));
-	    break;
-	}
-
-	switch (valuetypes[entry->key.primary]) {
-	  case TYPE_BOOL:
-	    entry->value.u.boolval = get_bool(src);
-	    break;
-	  case TYPE_INT:
-	    entry->value.u.intval = toint(get_uint32(src));
-	    break;
-	  case TYPE_STR:
-	    entry->value.u.stringval = dupstr(get_asciz(src));
-	    break;
-	  case TYPE_FILENAME:
+        if (primary >= N_CONFIG_OPTIONS)
+            return false;
+
+        entry = snew(struct conf_entry);
+        entry->key.primary = primary;
+
+        switch (subkeytypes[entry->key.primary]) {
+          case TYPE_INT:
+            entry->key.secondary.i = toint(get_uint32(src));
+            break;
+          case TYPE_STR:
+            entry->key.secondary.s = dupstr(get_asciz(src));
+            break;
+        }
+
+        switch (valuetypes[entry->key.primary]) {
+          case TYPE_BOOL:
+            entry->value.u.boolval = get_bool(src);
+            break;
+          case TYPE_INT:
+            entry->value.u.intval = toint(get_uint32(src));
+            break;
+          case TYPE_STR:
+            entry->value.u.stringval = dupstr(get_asciz(src));
+            break;
+          case TYPE_FILENAME:
             entry->value.u.fileval = filename_deserialise(src);
-	    break;
-	  case TYPE_FONT:
+            break;
+          case TYPE_FONT:
             entry->value.u.fontval = fontspec_deserialise(src);
-	    break;
-	}
+            break;
+        }
 
         if (get_err(src)) {
             free_entry(entry);
             return false;
         }
 
-	conf_insert(conf, entry);
+        conf_insert(conf, entry);
     }
 }

+ 125 - 125
source/putty/cproxy.c

@@ -16,7 +16,7 @@
 #include "marshal.h"
 
 static void hmacmd5_chap(const unsigned char *challenge, int challen,
-			 const char *passwd, unsigned char *response)
+                         const char *passwd, unsigned char *response)
 {
     mac_simple(&ssh_hmac_md5, ptrlen_from_asciz(passwd),
                make_ptrlen(challenge, challen), response);
@@ -42,103 +42,103 @@ int proxy_socks5_handlechap (ProxySocket *p)
     unsigned char outbuf[20];
 
     while(p->chap_num_attributes == 0 ||
-	  p->chap_num_attributes_processed < p->chap_num_attributes) {
-	if (p->chap_num_attributes == 0 ||
-	    p->chap_current_attribute == -1) {
-	    /* CHAP normally reads in two bytes, either at the
-	     * beginning or for each attribute/value pair.  But if
-	     * we're waiting for the value's data, we might not want
-	     * to read 2 bytes.
-	     */
- 
-	    if (bufchain_size(&p->pending_input_data) < 2)
-		return 1;	       /* not got anything yet */
-
-	    /* get the response */
-	    bufchain_fetch(&p->pending_input_data, data, 2);
-	    bufchain_consume(&p->pending_input_data, 2);
-	}
-
-	if (p->chap_num_attributes == 0) {
-	    /* If there are no attributes, this is our first msg
-	     * with the server, where we negotiate version and 
-	     * number of attributes
-	     */
-	    if (data[0] != 0x01) {
-		plug_closing(p->plug, "Proxy error: SOCKS proxy wants"
-			     " a different CHAP version",
-			     PROXY_ERROR_GENERAL, 0);
-		return 1;
-	    }
-	    if (data[1] == 0x00) {
-		plug_closing(p->plug, "Proxy error: SOCKS proxy won't"
-			     " negotiate CHAP with us",
-			     PROXY_ERROR_GENERAL, 0);
-		return 1;
-	    }
-	    p->chap_num_attributes = data[1];
-	} else {
-	    if (p->chap_current_attribute == -1) {
-		/* We have to read in each attribute/value pair -
-		 * those we don't understand can be ignored, but
-		 * there are a few we'll need to handle.
-		 */
-		p->chap_current_attribute = data[0];
-		p->chap_current_datalen = data[1];
-	    }
-	    if (bufchain_size(&p->pending_input_data) <
-		p->chap_current_datalen)
-		return 1;	       /* not got everything yet */
-
-	    /* get the response */
-	    bufchain_fetch(&p->pending_input_data, data,
-			   p->chap_current_datalen);
-
-	    bufchain_consume(&p->pending_input_data,
-			     p->chap_current_datalen);
-
-	    switch (p->chap_current_attribute) {
-	      case 0x00:
-		/* Successful authentication */
-		if (data[0] == 0x00)
-		    p->state = 2;
-		else {
-		    plug_closing(p->plug, "Proxy error: SOCKS proxy"
-				 " refused CHAP authentication",
-				 PROXY_ERROR_GENERAL, 0);
-		    return 1;
-		}
-	      break;
-	      case 0x03:
-		outbuf[0] = 0x01; /* Version */
-		outbuf[1] = 0x01; /* One attribute */
-		outbuf[2] = 0x04; /* Response */
-		outbuf[3] = 0x10; /* Length */
-		hmacmd5_chap(data, p->chap_current_datalen,
-			     conf_get_str(p->conf, CONF_proxy_password),
-			     &outbuf[4]);
-		sk_write(p->sub_socket, outbuf, 20);
-	      break;
-	      case 0x11:
-	        /* Chose a protocol */
-		if (data[0] != 0x85) {
-		    plug_closing(p->plug, "Proxy error: Server chose "
-				 "CHAP of other than HMAC-MD5 but we "
-				 "didn't offer it!",
-				 PROXY_ERROR_GENERAL, 0);
-		    return 1;
-		}
-	      break;
-	    }
-	    p->chap_current_attribute = -1;
-	    p->chap_num_attributes_processed++;
-	}
-	if (p->state == 8 &&
-	    p->chap_num_attributes_processed >= p->chap_num_attributes) {
-	    p->chap_num_attributes = 0;
-	    p->chap_num_attributes_processed = 0;
-	    p->chap_current_datalen = 0;
-	}
+          p->chap_num_attributes_processed < p->chap_num_attributes) {
+        if (p->chap_num_attributes == 0 ||
+            p->chap_current_attribute == -1) {
+            /* CHAP normally reads in two bytes, either at the
+             * beginning or for each attribute/value pair.  But if
+             * we're waiting for the value's data, we might not want
+             * to read 2 bytes.
+             */
+
+            if (bufchain_size(&p->pending_input_data) < 2)
+                return 1;              /* not got anything yet */
+
+            /* get the response */
+            bufchain_fetch(&p->pending_input_data, data, 2);
+            bufchain_consume(&p->pending_input_data, 2);
+        }
+
+        if (p->chap_num_attributes == 0) {
+            /* If there are no attributes, this is our first msg
+             * with the server, where we negotiate version and
+             * number of attributes
+             */
+            if (data[0] != 0x01) {
+                plug_closing(p->plug, "Proxy error: SOCKS proxy wants"
+                             " a different CHAP version",
+                             PROXY_ERROR_GENERAL, 0);
+                return 1;
+            }
+            if (data[1] == 0x00) {
+                plug_closing(p->plug, "Proxy error: SOCKS proxy won't"
+                             " negotiate CHAP with us",
+                             PROXY_ERROR_GENERAL, 0);
+                return 1;
+            }
+            p->chap_num_attributes = data[1];
+        } else {
+            if (p->chap_current_attribute == -1) {
+                /* We have to read in each attribute/value pair -
+                 * those we don't understand can be ignored, but
+                 * there are a few we'll need to handle.
+                 */
+                p->chap_current_attribute = data[0];
+                p->chap_current_datalen = data[1];
+            }
+            if (bufchain_size(&p->pending_input_data) <
+                p->chap_current_datalen)
+                return 1;              /* not got everything yet */
+
+            /* get the response */
+            bufchain_fetch(&p->pending_input_data, data,
+                           p->chap_current_datalen);
+
+            bufchain_consume(&p->pending_input_data,
+                             p->chap_current_datalen);
+
+            switch (p->chap_current_attribute) {
+              case 0x00:
+                /* Successful authentication */
+                if (data[0] == 0x00)
+                    p->state = 2;
+                else {
+                    plug_closing(p->plug, "Proxy error: SOCKS proxy"
+                                 " refused CHAP authentication",
+                                 PROXY_ERROR_GENERAL, 0);
+                    return 1;
+                }
+              break;
+              case 0x03:
+                outbuf[0] = 0x01; /* Version */
+                outbuf[1] = 0x01; /* One attribute */
+                outbuf[2] = 0x04; /* Response */
+                outbuf[3] = 0x10; /* Length */
+                hmacmd5_chap(data, p->chap_current_datalen,
+                             conf_get_str(p->conf, CONF_proxy_password),
+                             &outbuf[4]);
+                sk_write(p->sub_socket, outbuf, 20);
+              break;
+              case 0x11:
+                /* Chose a protocol */
+                if (data[0] != 0x85) {
+                    plug_closing(p->plug, "Proxy error: Server chose "
+                                 "CHAP of other than HMAC-MD5 but we "
+                                 "didn't offer it!",
+                                 PROXY_ERROR_GENERAL, 0);
+                    return 1;
+                }
+              break;
+            }
+            p->chap_current_attribute = -1;
+            p->chap_num_attributes_processed++;
+        }
+        if (p->state == 8 &&
+            p->chap_num_attributes_processed >= p->chap_num_attributes) {
+            p->chap_num_attributes = 0;
+            p->chap_num_attributes_processed = 0;
+            p->chap_current_datalen = 0;
+        }
     }
     return 0;
 }
@@ -148,32 +148,32 @@ int proxy_socks5_selectchap(ProxySocket *p)
     char *username = conf_get_str(p->conf, CONF_proxy_username);
     char *password = conf_get_str(p->conf, CONF_proxy_password);
     if (username[0] || password[0]) {
-	char chapbuf[514];
-	int ulen;
-	chapbuf[0] = '\x01'; /* Version */
-	chapbuf[1] = '\x02'; /* Number of attributes sent */
-	chapbuf[2] = '\x11'; /* First attribute - algorithms list */
-	chapbuf[3] = '\x01'; /* Only one CHAP algorithm */
-	chapbuf[4] = '\x85'; /* ...and it's HMAC-MD5, the core one */
-	chapbuf[5] = '\x02'; /* Second attribute - username */
-
-	ulen = strlen(username);
-	if (ulen > 255) ulen = 255;
-	if (ulen < 1) ulen = 1;
-
-	chapbuf[6] = ulen;
-	memcpy(chapbuf+7, username, ulen);
-
-	sk_write(p->sub_socket, chapbuf, ulen + 7);
-	p->chap_num_attributes = 0;
-	p->chap_num_attributes_processed = 0;
-	p->chap_current_attribute = -1;
-	p->chap_current_datalen = 0;
-
-	p->state = 8;
-    } else 
-	plug_closing(p->plug, "Proxy error: Server chose "
-		     "CHAP authentication but we didn't offer it!",
-		 PROXY_ERROR_GENERAL, 0);
+        char chapbuf[514];
+        int ulen;
+        chapbuf[0] = '\x01'; /* Version */
+        chapbuf[1] = '\x02'; /* Number of attributes sent */
+        chapbuf[2] = '\x11'; /* First attribute - algorithms list */
+        chapbuf[3] = '\x01'; /* Only one CHAP algorithm */
+        chapbuf[4] = '\x85'; /* ...and it's HMAC-MD5, the core one */
+        chapbuf[5] = '\x02'; /* Second attribute - username */
+
+        ulen = strlen(username);
+        if (ulen > 255) ulen = 255;
+        if (ulen < 1) ulen = 1;
+
+        chapbuf[6] = ulen;
+        memcpy(chapbuf+7, username, ulen);
+
+        sk_write(p->sub_socket, chapbuf, ulen + 7);
+        p->chap_num_attributes = 0;
+        p->chap_num_attributes_processed = 0;
+        p->chap_current_attribute = -1;
+        p->chap_current_datalen = 0;
+
+        p->state = 8;
+    } else
+        plug_closing(p->plug, "Proxy error: Server chose "
+                     "CHAP authentication but we didn't offer it!",
+                 PROXY_ERROR_GENERAL, 0);
     return 1;
 }

+ 1 - 1
source/putty/ecc.c

@@ -545,7 +545,7 @@ unsigned ecc_weierstrass_point_valid(WeierstrassPoint *P)
     mp_int *z6 = monty_mul(wc->mc, z2, z4);
     mp_int *bz6 = monty_mul(wc->mc, wc->b, z6);
     mp_int *rhs = monty_add(wc->mc, x3_plus_axz4, bz6);
-    
+
     unsigned valid = mp_cmp_eq(lhs, rhs);
 
     mp_free(lhs);

+ 1 - 1
source/putty/errsock.c

@@ -21,7 +21,7 @@ static Plug *sk_error_plug(Socket *s, Plug *p)
     ErrorSocket *es = container_of(s, ErrorSocket, sock);
     Plug *ret = es->plug;
     if (p)
-	es->plug = p;
+        es->plug = p;
     return ret;
 }
 

Разница между файлами не показана из-за своего большого размера
+ 274 - 274
source/putty/import.c


+ 155 - 155
source/putty/logging.c

@@ -19,7 +19,7 @@ struct LogContext {
     Filename *currlogfilename;
     LogPolicy *lp;
     Conf *conf;
-    int logtype;		       /* cached out of conf */
+    int logtype;                       /* cached out of conf */
 };
 
 static Filename *xlatlognam(Filename *s, char *hostname, int port,
@@ -39,19 +39,19 @@ static void logwrite(LogContext *ctx, ptrlen data)
      * those three _after_ processing L_CLOSED.
      */
     if (ctx->state == L_CLOSED)
-	logfopen(ctx);
+        logfopen(ctx);
 
     if (ctx->state == L_OPENING) {
-	bufchain_add(&ctx->queue, data.ptr, data.len);
+        bufchain_add(&ctx->queue, data.ptr, data.len);
     } else if (ctx->state == L_OPEN) {
-	assert(ctx->lgfp);
-	if (fwrite(data.ptr, 1, data.len, ctx->lgfp) < data.len) {
-	    logfclose(ctx);
-	    ctx->state = L_ERROR;
+        assert(ctx->lgfp);
+        if (fwrite(data.ptr, 1, data.len, ctx->lgfp) < data.len) {
+            logfclose(ctx);
+            ctx->state = L_ERROR;
             lp_eventlog(ctx->lp, "Disabled writing session log "
                         "due to error while writing");
-	}
-    }				       /* else L_ERROR, so ignore the write */
+        }
+    }                                  /* else L_ERROR, so ignore the write */
 }
 
 /*
@@ -77,8 +77,8 @@ static void logprintf(LogContext *ctx, const char *fmt, ...)
 void logflush(LogContext *ctx)
 {
     if (ctx->logtype > 0)
-	if (ctx->state == L_OPEN)
-	    fflush(ctx->lgfp);
+        if (ctx->state == L_OPEN)
+            fflush(ctx->lgfp);
 }
 
 static void logfopen_callback(void *vctx, int mode)
@@ -90,36 +90,36 @@ static void logfopen_callback(void *vctx, int mode)
     bool shout = false;
 
     if (mode == 0) {
-	ctx->state = L_ERROR;	       /* disable logging */
+        ctx->state = L_ERROR;          /* disable logging */
     } else {
-	fmode = (mode == 1 ? "ab" : "wb");
-	ctx->lgfp = f_open(ctx->currlogfilename, fmode, false);
-	if (ctx->lgfp) {
-	    ctx->state = L_OPEN;
+        fmode = (mode == 1 ? "ab" : "wb");
+        ctx->lgfp = f_open(ctx->currlogfilename, fmode, false);
+        if (ctx->lgfp) {
+            ctx->state = L_OPEN;
         } else {
-	    ctx->state = L_ERROR;
+            ctx->state = L_ERROR;
             shout = true;
         }
     }
 
     if (ctx->state == L_OPEN && conf_get_bool(ctx->conf, CONF_logheader)) {
-	/* Write header line into log file. */
-	tm = ltime();
-	strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm);
-	logprintf(ctx, "=~=~=~=~=~=~=~=~=~=~=~= PuTTY log %s"
-		  " =~=~=~=~=~=~=~=~=~=~=~=\r\n", buf);
+        /* Write header line into log file. */
+        tm = ltime();
+        strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm);
+        logprintf(ctx, "=~=~=~=~=~=~=~=~=~=~=~= PuTTY log %s"
+                  " =~=~=~=~=~=~=~=~=~=~=~=\r\n", buf);
     }
 
     event = dupprintf(WINSCP_BOM "%s session log (%s mode) to file: %s",
-		      ctx->state == L_ERROR ?
-		      (mode == 0 ? "Disabled writing" : "Error writing") :
-		      (mode == 1 ? "Appending" : "Writing new"),
-		      (ctx->logtype == LGTYP_ASCII ? "ASCII" :
-		       ctx->logtype == LGTYP_DEBUG ? "raw" :
-		       ctx->logtype == LGTYP_PACKETS ? "SSH packets" :
-		       ctx->logtype == LGTYP_SSHRAW ? "SSH raw data" :
-		       "unknown"),
-		      filename_to_str(ctx->currlogfilename));
+                      ctx->state == L_ERROR ?
+                      (mode == 0 ? "Disabled writing" : "Error writing") :
+                      (mode == 1 ? "Appending" : "Writing new"),
+                      (ctx->logtype == LGTYP_ASCII ? "ASCII" :
+                       ctx->logtype == LGTYP_DEBUG ? "raw" :
+                       ctx->logtype == LGTYP_PACKETS ? "SSH packets" :
+                       ctx->logtype == LGTYP_SSHRAW ? "SSH raw data" :
+                       "unknown"),
+                      filename_to_str(ctx->currlogfilename));
     lp_eventlog(ctx->lp, event);
     if (shout) {
         /*
@@ -138,8 +138,8 @@ static void logfopen_callback(void *vctx, int mode)
     assert(ctx->state != L_OPENING);   /* make _sure_ it won't be requeued */
     while (bufchain_size(&ctx->queue)) {
         ptrlen data = bufchain_prefix(&ctx->queue);
-	logwrite(ctx, data);
-	bufchain_consume(&ctx->queue, data.len);
+        logwrite(ctx, data);
+        bufchain_consume(&ctx->queue, data.len);
     }
     logflush(ctx);
 }
@@ -156,42 +156,42 @@ void logfopen(LogContext *ctx)
 
     /* Prevent repeat calls */
     if (ctx->state != L_CLOSED)
-	return;
+        return;
 
     if (!ctx->logtype)
-	return;
+        return;
 
     tm = ltime();
 
     /* substitute special codes in file name */
     if (ctx->currlogfilename)
         filename_free(ctx->currlogfilename);
-    ctx->currlogfilename = 
+    ctx->currlogfilename =
         xlatlognam(conf_get_filename(ctx->conf, CONF_logfilename),
                    conf_get_str(ctx->conf, CONF_host),
                    conf_get_int(ctx->conf, CONF_port), &tm);
 
     if (open_for_write_would_lose_data(ctx->currlogfilename)) {
-	int logxfovr = conf_get_int(ctx->conf, CONF_logxfovr);
-	if (logxfovr != LGXF_ASK) {
-	    mode = ((logxfovr == LGXF_OVR) ? 2 : 1);
-	} else
+        int logxfovr = conf_get_int(ctx->conf, CONF_logxfovr);
+        if (logxfovr != LGXF_ASK) {
+            mode = ((logxfovr == LGXF_OVR) ? 2 : 1);
+        } else
             mode = lp_askappend(ctx->lp, ctx->currlogfilename,
                                 logfopen_callback, ctx);
     } else
-	mode = 2;		       /* create == overwrite */
+        mode = 2;                      /* create == overwrite */
 
     if (mode < 0)
-	ctx->state = L_OPENING;
+        ctx->state = L_OPENING;
     else
-	logfopen_callback(ctx, mode);  /* open the file */
+        logfopen_callback(ctx, mode);  /* open the file */
 }
 
 void logfclose(LogContext *ctx)
 {
     if (ctx->lgfp) {
-	fclose(ctx->lgfp);
-	ctx->lgfp = NULL;
+        fclose(ctx->lgfp);
+        ctx->lgfp = NULL;
     }
     ctx->state = L_CLOSED;
 }
@@ -202,8 +202,8 @@ void logfclose(LogContext *ctx)
 void logtraffic(LogContext *ctx, unsigned char c, int logmode)
 {
     if (ctx->logtype > 0) {
-	if (ctx->logtype == logmode)
-	    logwrite(ctx, make_ptrlen(&c, 1));
+        if (ctx->logtype == logmode)
+            logwrite(ctx, make_ptrlen(&c, 1));
     }
 }
 
@@ -274,9 +274,9 @@ void logeventf(LogContext *ctx, const char *fmt, ...)
  * Set of blanking areas must be in increasing order.
  */
 void log_packet(LogContext *ctx, int direction, int type,
-		const char *texttype, const void *data, size_t len,
-		int n_blanks, const struct logblank_t *blanks,
-		const unsigned long *seq,
+                const char *texttype, const void *data, size_t len,
+                int n_blanks, const struct logblank_t *blanks,
+                const unsigned long *seq,
                 unsigned downstream_id, const char *additional_log_text)
 {
     char dumpdata[128], smalldata[5];
@@ -285,20 +285,20 @@ void log_packet(LogContext *ctx, int direction, int type,
 
     if (!(ctx->logtype == LGTYP_SSHRAW ||
           (ctx->logtype == LGTYP_PACKETS && texttype)))
-	return;
+        return;
 
     /* Packet header. */
     if (texttype) {
         logprintf(ctx, "%s packet ",
                   direction == PKT_INCOMING ? "Incoming" : "Outgoing");
 
-	if (seq)
-	    logprintf(ctx, "#0x%lx, ", *seq);
+        if (seq)
+            logprintf(ctx, "#0x%lx, ", *seq);
 
         logprintf(ctx, "type %d / 0x%02x (%s)", type, type, texttype);
 
         if (downstream_id) {
-	    logprintf(ctx, " on behalf of downstream #%u", downstream_id);
+            logprintf(ctx, " on behalf of downstream #%u", downstream_id);
             if (additional_log_text)
                 logprintf(ctx, " (%s)", additional_log_text);
         }
@@ -315,8 +315,8 @@ void log_packet(LogContext *ctx, int direction, int type,
          */
         char buf[256];
         struct tm tm;
-	tm = ltime();
-	strftime(buf, 24, "%Y-%m-%d %H:%M:%S", &tm);
+        tm = ltime();
+        strftime(buf, 24, "%Y-%m-%d %H:%M:%S", &tm);
         logprintf(ctx, "%s raw data at %s\r\n",
                   direction == PKT_INCOMING ? "Incoming" : "Outgoing",
                   buf);
@@ -327,68 +327,68 @@ void log_packet(LogContext *ctx, int direction, int type,
      * parts as specified.
      */
     while (p < len) {
-	int blktype;
-
-	/* Move to a current entry in the blanking array. */
-	while ((b < n_blanks) &&
-	       (p >= blanks[b].offset + blanks[b].len))
-	    b++;
-	/* Work out what type of blanking to apply to
-	 * this byte. */
-	blktype = PKTLOG_EMIT; /* default */
-	if ((b < n_blanks) &&
-	    (p >= blanks[b].offset) &&
-	    (p < blanks[b].offset + blanks[b].len))
-	    blktype = blanks[b].type;
-
-	/* If we're about to stop omitting, it's time to say how
-	 * much we omitted. */
-	if ((blktype != PKTLOG_OMIT) && omitted) {
-	    logprintf(ctx, "  (%d byte%s omitted)\r\n",
-		      omitted, (omitted==1?"":"s"));
-	    omitted = 0;
-	}
-
-	/* (Re-)initialise dumpdata as necessary
-	 * (start of row, or if we've just stopped omitting) */
-	if (!output_pos && !omitted)
-	    sprintf(dumpdata, "  %08zx%*s\r\n", p-(p%16), 1+3*16+2+16, "");
-
-	/* Deal with the current byte. */
-	if (blktype == PKTLOG_OMIT) {
-	    omitted++;
-	} else {
-	    int c;
-	    if (blktype == PKTLOG_BLANK) {
-		c = 'X';
-		sprintf(smalldata, "XX");
-	    } else {  /* PKTLOG_EMIT */
-		c = ((unsigned char *)data)[p];
-		sprintf(smalldata, "%02x", c);
-	    }
-	    dumpdata[10+2+3*(p%16)] = smalldata[0];
-	    dumpdata[10+2+3*(p%16)+1] = smalldata[1];
-	    dumpdata[10+1+3*16+2+(p%16)] = (c >= 0x20 && c < 0x7F ? c : '.');
-	    output_pos = (p%16) + 1;
-	}
-
-	p++;
-
-	/* Flush row if necessary */
-	if (((p % 16) == 0) || (p == len) || omitted) {
-	    if (output_pos) {
-		strcpy(dumpdata + 10+1+3*16+2+output_pos, "\r\n");
-		logwrite(ctx, ptrlen_from_asciz(dumpdata));
-		output_pos = 0;
-	    }
-	}
+        int blktype;
+
+        /* Move to a current entry in the blanking array. */
+        while ((b < n_blanks) &&
+               (p >= blanks[b].offset + blanks[b].len))
+            b++;
+        /* Work out what type of blanking to apply to
+         * this byte. */
+        blktype = PKTLOG_EMIT; /* default */
+        if ((b < n_blanks) &&
+            (p >= blanks[b].offset) &&
+            (p < blanks[b].offset + blanks[b].len))
+            blktype = blanks[b].type;
+
+        /* If we're about to stop omitting, it's time to say how
+         * much we omitted. */
+        if ((blktype != PKTLOG_OMIT) && omitted) {
+            logprintf(ctx, "  (%d byte%s omitted)\r\n",
+                      omitted, (omitted==1?"":"s"));
+            omitted = 0;
+        }
+
+        /* (Re-)initialise dumpdata as necessary
+         * (start of row, or if we've just stopped omitting) */
+        if (!output_pos && !omitted)
+            sprintf(dumpdata, "  %08zx%*s\r\n", p-(p%16), 1+3*16+2+16, "");
+
+        /* Deal with the current byte. */
+        if (blktype == PKTLOG_OMIT) {
+            omitted++;
+        } else {
+            int c;
+            if (blktype == PKTLOG_BLANK) {
+                c = 'X';
+                sprintf(smalldata, "XX");
+            } else {  /* PKTLOG_EMIT */
+                c = ((unsigned char *)data)[p];
+                sprintf(smalldata, "%02x", c);
+            }
+            dumpdata[10+2+3*(p%16)] = smalldata[0];
+            dumpdata[10+2+3*(p%16)+1] = smalldata[1];
+            dumpdata[10+1+3*16+2+(p%16)] = (c >= 0x20 && c < 0x7F ? c : '.');
+            output_pos = (p%16) + 1;
+        }
+
+        p++;
+
+        /* Flush row if necessary */
+        if (((p % 16) == 0) || (p == len) || omitted) {
+            if (output_pos) {
+                strcpy(dumpdata + 10+1+3*16+2+output_pos, "\r\n");
+                logwrite(ctx, ptrlen_from_asciz(dumpdata));
+                output_pos = 0;
+            }
+        }
 
     }
 
     /* Tidy up */
     if (omitted)
-	logprintf(ctx, "  (%d byte%s omitted)\r\n",
-		  omitted, (omitted==1?"":"s"));
+        logprintf(ctx, "  (%d byte%s omitted)\r\n",
+                  omitted, (omitted==1?"":"s"));
     logflush(ctx);
 }
 
@@ -426,15 +426,15 @@ void log_reconfig(LogContext *ctx, Conf *conf)
     bool reset_logging;
 
     if (!filename_equal(conf_get_filename(ctx->conf, CONF_logfilename),
-			conf_get_filename(conf, CONF_logfilename)) ||
-	conf_get_int(ctx->conf, CONF_logtype) !=
-	conf_get_int(conf, CONF_logtype))
-	reset_logging = true;
+                        conf_get_filename(conf, CONF_logfilename)) ||
+        conf_get_int(ctx->conf, CONF_logtype) !=
+        conf_get_int(conf, CONF_logtype))
+        reset_logging = true;
     else
-	reset_logging = false;
+        reset_logging = false;
 
     if (reset_logging)
-	logfclose(ctx);
+        logfclose(ctx);
 
     conf_free(ctx->conf);
     ctx->conf = conf_copy(conf);
@@ -442,7 +442,7 @@ void log_reconfig(LogContext *ctx, Conf *conf)
     ctx->logtype = conf_get_int(ctx->conf, CONF_logtype);
 
     if (reset_logging)
-	logfopen(ctx);
+        logfopen(ctx);
 }
 
 /*
@@ -465,48 +465,48 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port,
 
     while (*s) {
         bool sanitise = false;
-	/* Let (bufp, len) be the string to append. */
-	bufp = buf;		       /* don't usually override this */
-	if (*s == '&') {
-	    char c;
-	    s++;
-	    size = 0;
-	    if (*s) switch (c = *s++, tolower((unsigned char)c)) {
-	      case 'y':
-		size = strftime(buf, sizeof(buf), "%Y", tm);
-		break;
-	      case 'm':
-		size = strftime(buf, sizeof(buf), "%m", tm);
-		break;
-	      case 'd':
-		size = strftime(buf, sizeof(buf), "%d", tm);
-		break;
-	      case 't':
-		size = strftime(buf, sizeof(buf), "%H%M%S", tm);
-		break;
-	      case 'h':
-		bufp = hostname;
-		size = strlen(bufp);
-		break;
-	      case 'p':
+        /* Let (bufp, len) be the string to append. */
+        bufp = buf;                    /* don't usually override this */
+        if (*s == '&') {
+            char c;
+            s++;
+            size = 0;
+            if (*s) switch (c = *s++, tolower((unsigned char)c)) {
+              case 'y':
+                size = strftime(buf, sizeof(buf), "%Y", tm);
+                break;
+              case 'm':
+                size = strftime(buf, sizeof(buf), "%m", tm);
+                break;
+              case 'd':
+                size = strftime(buf, sizeof(buf), "%d", tm);
+                break;
+              case 't':
+                size = strftime(buf, sizeof(buf), "%H%M%S", tm);
+                break;
+              case 'h':
+                bufp = hostname;
+                size = strlen(bufp);
+                break;
+              case 'p':
                 size = sprintf(buf, "%d", port);
-		break;
-	      default:
-		buf[0] = '&';
-		size = 1;
-		if (c != '&')
-		    buf[size++] = c;
-	    }
+                break;
+              default:
+                buf[0] = '&';
+                size = 1;
+                if (c != '&')
+                    buf[size++] = c;
+            }
             /* Never allow path separators - or any other illegal
              * filename character - to come out of any of these
              * auto-format directives. E.g. 'hostname' can contain
              * colons, if it's an IPv6 address, and colons aren't
              * legal in filenames on Windows. */
             sanitise = true;
-	} else {
-	    buf[0] = *s++;
-	    size = 1;
-	}
+        } else {
+            buf[0] = *s++;
+            size = 1;
+        }
         while (size-- > 0) {
             char c = *bufp++;
             if (sanitise)

+ 6 - 6
source/putty/mainchan.c

@@ -134,15 +134,15 @@ static void mainchan_open_confirmation(Channel *chan)
         sshfwd_hint_channel_is_simple(mc->sc);
 
     if (mc->type == MAINCHAN_SESSION) {
-	/*
-	 * Send the CHANNEL_REQUESTS for the main session channel.
+        /*
+         * Send the CHANNEL_REQUESTS for the main session channel.
          */
         char *key, *val, *cmd;
         struct X11Display *x11disp;
         struct X11FakeAuth *x11auth;
         bool retry_cmd_now = false;
 
-	if (conf_get_bool(mc->conf, CONF_x11_forward)) {
+        if (conf_get_bool(mc->conf, CONF_x11_forward)) {
             char *x11_setup_err;
             if ((x11disp = x11_setup_display(
                      conf_get_str(mc->conf, CONF_x11_display),
@@ -161,12 +161,12 @@ static void mainchan_open_confirmation(Channel *chan)
             }
         }
 
-	if (ssh_agent_forwarding_permitted(mc->cl)) {
+        if (ssh_agent_forwarding_permitted(mc->cl)) {
             sshfwd_request_agent_forwarding(mc->sc, true);
             mc->req_agent = true;
         }
 
-	if (!conf_get_bool(mc->conf, CONF_nopty)) {
+        if (!conf_get_bool(mc->conf, CONF_nopty)) {
             sshfwd_request_pty(
                 mc->sc, true, mc->conf, mc->term_width, mc->term_height);
             mc->req_pty = true;
@@ -327,7 +327,7 @@ static void mainchan_ready(mainchan *mc)
     /* If an EOF arrived before we were ready, handle it now. */
     if (mc->eof_pending) {
         mc->eof_pending = false;
-	mainchan_special_cmd(mc, SS_EOF, 0);
+        mainchan_special_cmd(mc, SS_EOF, 0);
     }
 
     ssh_ldisc_update(mc->ppl->ssh);

+ 11 - 11
source/putty/memory.c

@@ -52,22 +52,22 @@ void *saferealloc(void *ptr, size_t n, size_t size)
     void *p;
 
     if (n > INT_MAX / size) {
-	p = NULL;
+        p = NULL;
     } else {
-	size *= n;
-	if (!ptr) {
+        size *= n;
+        if (!ptr) {
 #ifdef MINEFIELD
-	    p = minefield_c_malloc(size);
+            p = minefield_c_malloc(size);
 #else
-	    p = malloc(size);
+            p = malloc(size);
 #endif
-	} else {
+        } else {
 #ifdef MINEFIELD
-	    p = minefield_c_realloc(ptr, size);
+            p = minefield_c_realloc(ptr, size);
 #else
-	    p = realloc(ptr, size);
+            p = realloc(ptr, size);
 #endif
-	}
+        }
     }
 
     if (!p)
@@ -80,9 +80,9 @@ void safefree(void *ptr)
 {
     if (ptr) {
 #ifdef MINEFIELD
-	minefield_c_free(ptr);
+        minefield_c_free(ptr);
 #else
-	free(ptr);
+        free(ptr);
 #endif
     }
 }

+ 9 - 9
source/putty/misc.c

@@ -85,11 +85,11 @@ void free_prompts(prompts_t *p)
 {
     size_t i;
     for (i=0; i < p->n_prompts; i++) {
-	prompt_t *pr = p->prompts[i];
-	smemclr(pr->result, pr->resultsize); /* burn the evidence */
-	sfree(pr->result);
-	sfree(pr->prompt);
-	sfree(pr);
+        prompt_t *pr = p->prompts[i];
+        smemclr(pr->result, pr->resultsize); /* burn the evidence */
+        sfree(pr->result);
+        sfree(pr->prompt);
+        sfree(pr);
     }
     sfree(p->prompts);
     sfree(p->name);
@@ -104,17 +104,17 @@ void free_prompts(prompts_t *p)
 bool conf_launchable(Conf *conf)
 {
     if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
-	return conf_get_str(conf, CONF_serline)[0] != 0;
+        return conf_get_str(conf, CONF_serline)[0] != 0;
     else
-	return conf_get_str(conf, CONF_host)[0] != 0;
+        return conf_get_str(conf, CONF_host)[0] != 0;
 }
 
 char const *conf_dest(Conf *conf)
 {
     if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
-	return conf_get_str(conf, CONF_serline);
+        return conf_get_str(conf, CONF_serline);
     else
-	return conf_get_str(conf, CONF_host);
+        return conf_get_str(conf, CONF_host);
 }
 
 /*

+ 2 - 2
source/putty/misc.h

@@ -9,8 +9,8 @@
 #include "puttymem.h"
 #include "marshal.h"
 
-#include <stdio.h>		       /* for FILE * */
-#include <stdarg.h>		       /* for va_list */
+#include <stdio.h>                     /* for FILE * */
+#include <stdarg.h>                    /* for va_list */
 #include <stdlib.h>                    /* for abort */
 #include <time.h>                      /* for struct tm */
 #include <limits.h>                    /* for INT_MAX/MIN */

+ 1 - 1
source/putty/mpint.c

@@ -1952,7 +1952,7 @@ void mp_divmod_into(mp_int *n, mp_int *d, mp_int *q_out, mp_int *r_out)
      *
      * So when we multiply n (the input numerator) by our final
      * reciprocal approximation r, but actually r differs from R/d by
-     * up to 2, then it follows that 
+     * up to 2, then it follows that
      *
      *   n/d - nr/R = n/d - [ n (R/d + e) ] / R
      *              = n/d - [ (n/d) R + n e ] / R

+ 3 - 3
source/putty/mpint_i.h

@@ -228,7 +228,7 @@
           (ret) = (BignumInt)ADC_temp;                            \
           (retc) = (BignumCarry)(ADC_temp >> BIGNUM_INT_BITS);    \
       } while (0)
-  
+
   #define BignumMUL(rh, rl, a, b) do                              \
       {                                                           \
           DEFINE_BIGNUMDBLINT;                                    \
@@ -237,7 +237,7 @@
           (rh) = (BignumInt)(MUL_temp >> BIGNUM_INT_BITS);        \
           (rl) = (BignumInt)(MUL_temp);                           \
       } while (0)
-  
+
   #define BignumMULADD(rh, rl, a, b, addend) do                   \
       {                                                           \
           DEFINE_BIGNUMDBLINT;                                    \
@@ -247,7 +247,7 @@
           (rh) = (BignumInt)(MUL_temp >> BIGNUM_INT_BITS);        \
           (rl) = (BignumInt)(MUL_temp);                           \
       } while (0)
-  
+
   #define BignumMULADD2(rh, rl, a, b, addend1, addend2) do        \
       {                                                           \
           DEFINE_BIGNUMDBLINT;                                    \

+ 16 - 16
source/putty/network.h

@@ -3,7 +3,7 @@
  *
  * The way this works is: a back end can choose to open any number
  * of sockets - including zero, which might be necessary in some.
- * It can register a bunch of callbacks (most notably for when 
+ * It can register a bunch of callbacks (most notably for when
  * data is received) for each socket, and it can call the networking
  * abstraction to send data without having to worry about blocking.
  * The stuff behind the abstraction takes care of selects and
@@ -46,18 +46,18 @@ struct Plug {
 
 struct PlugVtable {
     void (*log)(Plug *p, int type, SockAddr *addr, int port,
-		const char *error_msg, int error_code);
+                const char *error_msg, int error_code);
     /*
      * Passes the client progress reports on the process of setting
      * up the connection.
-     * 
-     * 	- type==0 means we are about to try to connect to address
-     * 	  `addr' (error_msg and error_code are ignored)
-     * 	- type==1 means we have failed to connect to address `addr'
-     * 	  (error_msg and error_code are supplied). This is not a
-     * 	  fatal error - we may well have other candidate addresses
-     * 	  to fall back to. When it _is_ fatal, the closing()
-     * 	  function will be called.
+     *
+     *  - type==0 means we are about to try to connect to address
+     *    `addr' (error_msg and error_code are ignored)
+     *  - type==1 means we have failed to connect to address `addr'
+     *    (error_msg and error_code are supplied). This is not a
+     *    fatal error - we may well have other candidate addresses
+     *    to fall back to. When it _is_ fatal, the closing()
+     *    function will be called.
      *  - type==2 means that error_msg contains a line of generic
      *    logging information about setting up the connection. This
      *    will typically be a wodge of standard-error output from a
@@ -73,10 +73,10 @@ struct PlugVtable {
     /*
      *  - urgent==0. `data' points to `len' bytes of perfectly
      *    ordinary data.
-     * 
+     *
      *  - urgent==1. `data' points to `len' bytes of data,
      *    which were read from before an Urgent pointer.
-     * 
+     *
      *  - urgent==2. `data' points to `len' bytes of data,
      *    the first of which was the one at the Urgent mark.
      */
@@ -117,8 +117,8 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
 
 /* socket functions */
 
-void sk_init(void);		       /* called once at program startup */
-void sk_cleanup(void);		       /* called just before program exit */
+void sk_init(void);                    /* called once at program startup */
+void sk_cleanup(void);                 /* called just before program exit */
 
 SockAddr *sk_namelookup(const char *host, char **canonicalname, int address_family);
 SockAddr *sk_nonamelookup(const char *host);
@@ -194,13 +194,13 @@ static inline const char *sk_socket_error(Socket *s)
  * which all READABLE notifications are ignored, so that data is
  * not accepted from the peer until the socket is unfrozen. This
  * exists for two purposes:
- * 
+ *
  *  - Port forwarding: when a local listening port receives a
  *    connection, we do not want to receive data from the new
  *    socket until we have somewhere to send it. Hence, we freeze
  *    the socket until its associated SSH channel is ready; then we
  *    unfreeze it and pending data is delivered.
- * 
+ *
  *  - Socket buffering: if an SSH channel (or the whole connection)
  *    backs up or presents a zero window, we must freeze the
  *    associated local socket in order to avoid unbounded buffer

+ 1 - 1
source/putty/nullplug.c

@@ -13,7 +13,7 @@ static void nullplug_socket_log(Plug *plug, int type, SockAddr *addr, int port,
 }
 
 static void nullplug_closing(Plug *plug, const char *error_msg, int error_code,
-			     bool calling_back)
+                             bool calling_back)
 {
 }
 

+ 1 - 1
source/putty/pgssapi.h

@@ -16,7 +16,7 @@
  */
 #ifdef STATIC_GSSAPI
 #include <gssapi/gssapi.h>
-typedef gss_OID const_gss_OID;	       /* for our prototypes below */
+typedef gss_OID const_gss_OID;         /* for our prototypes below */
 #else /* STATIC_GSSAPI */
 
 /*******************************************************************************

+ 30 - 30
source/putty/portfwd.c

@@ -96,13 +96,13 @@ static void free_portlistener_state(struct PortListener *pl)
 }
 
 static void pfd_log(Plug *plug, int type, SockAddr *addr, int port,
-		    const char *error_msg, int error_code)
+                    const char *error_msg, int error_code)
 {
     /* we have to dump these since we have no interface to logging.c */
 }
 
 static void pfl_log(Plug *plug, int type, SockAddr *addr, int port,
-		    const char *error_msg, int error_code)
+                    const char *error_msg, int error_code)
 {
     /* we have to dump these since we have no interface to logging.c */
 }
@@ -110,7 +110,7 @@ static void pfl_log(Plug *plug, int type, SockAddr *addr, int port,
 static void pfd_close(struct PortForwarding *pf);
 
 static void pfd_closing(Plug *plug, const char *error_msg, int error_code,
-			bool calling_back)
+                        bool calling_back)
 {
     struct PortForwarding *pf =
         container_of(plug, struct PortForwarding, plug);
@@ -143,7 +143,7 @@ static void pfd_closing(Plug *plug, const char *error_msg, int error_code,
 static void pfl_terminate(struct PortListener *pl);
 
 static void pfl_closing(Plug *plug, const char *error_msg, int error_code,
-			bool calling_back)
+                        bool calling_back)
 {
     struct PortListener *pl = (struct PortListener *) plug;
     pfl_terminate(pl);
@@ -399,16 +399,16 @@ static void pfd_receive(Plug *plug, int urgent, const char *data, size_t len)
             }
         }
 
-	/*
-	 * We come here when we're ready to make an actual
-	 * connection.
-	 */
+        /*
+         * We come here when we're ready to make an actual
+         * connection.
+         */
 
-	/*
-	 * Freeze the socket until the SSH server confirms the
-	 * connection.
-	 */
-	sk_set_frozen(pf->s, 1);
+        /*
+         * Freeze the socket until the SSH server confirms the
+         * connection.
+         */
+        sk_set_frozen(pf->s, 1);
 
         pf->c = wrap_lportfwd_open(pf->cl, pf->hostname, pf->port, pf->s,
                                    &pf->chan);
@@ -423,7 +423,7 @@ static void pfd_sent(Plug *plug, size_t bufsize)
         container_of(plug, struct PortForwarding, plug);
 
     if (pf->c)
-	sshfwd_unthrottle(pf->c, bufsize);
+        sshfwd_unthrottle(pf->c, bufsize);
 }
 
 static const PlugVtable PortForwarding_plugvt = {
@@ -526,22 +526,22 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
     chan = portfwd_raw_new(pl->cl, &plug);
     s = constructor(ctx, plug);
     if ((err = sk_socket_error(s)) != NULL) {
-	portfwd_raw_free(chan);
-	return 1;
+        portfwd_raw_free(chan);
+        return 1;
     }
 
     pf = container_of(chan, struct PortForwarding, chan);
 
     if (pl->is_dynamic) {
         pf->s = s;
-	pf->socks_state = SOCKS_INITIAL;
+        pf->socks_state = SOCKS_INITIAL;
         pf->socksbuf = strbuf_new();
         pf->socksbuf_consumed = 0;
-	pf->port = 0;		       /* "hostname" buffer is so far empty */
-	sk_set_frozen(s, 0);	       /* we want to receive SOCKS _now_! */
+        pf->port = 0;                  /* "hostname" buffer is so far empty */
+        sk_set_frozen(s, 0);           /* we want to receive SOCKS _now_! */
     } else {
-	pf->hostname = dupstr(pl->hostname);
-	pf->port = pl->port;	
+        pf->hostname = dupstr(pl->hostname);
+        pf->port = pl->port;
         portfwd_raw_setup(
             chan, s,
             wrap_lportfwd_open(pl->cl, pf->hostname, pf->port, s, &pf->chan));
@@ -580,11 +580,11 @@ static char *pfl_listen(const char *desthost, int destport,
     pl = *pl_ret = new_portlistener_state();
     pl->plug.vt = &PortListener_plugvt;
     if (desthost) {
-	pl->hostname = dupstr(desthost);
-	pl->port = destport;
-	pl->is_dynamic = false;
+        pl->hostname = dupstr(desthost);
+        pl->port = destport;
+        pl->is_dynamic = false;
     } else
-	pl->is_dynamic = true;
+        pl->is_dynamic = true;
     pl->cl = cl;
 
     pl->s = new_listener(srcaddr, port, &pl->plug,
@@ -593,9 +593,9 @@ static char *pfl_listen(const char *desthost, int destport,
     if ((err = sk_socket_error(pl->s)) != NULL) {
         char *err_ret = dupstr(err);
         sk_close(pl->s);
-	free_portlistener_state(pl);
+        free_portlistener_state(pl);
         *pl_ret = NULL;
-	return err_ret;
+        return err_ret;
     }
 
     return NULL;
@@ -609,7 +609,7 @@ static char *pfd_log_close_msg(Channel *chan)
 static void pfd_close(struct PortForwarding *pf)
 {
     if (!pf)
-	return;
+        return;
 
     sk_close(pf->s);
     free_portfwd_state(pf);
@@ -621,7 +621,7 @@ static void pfd_close(struct PortForwarding *pf)
 static void pfl_terminate(struct PortListener *pl)
 {
     if (!pl)
-	return;
+        return;
 
     sk_close(pl->s);
     free_portlistener_state(pl);
@@ -669,7 +669,7 @@ static void pfd_open_confirmation(Channel *chan)
     sk_set_frozen(pf->s, 0);
     sk_write(pf->s, NULL, 0);
     if (pf->socksbuf) {
-	sshfwd_write(pf->c, pf->socksbuf->u + pf->socksbuf_consumed,
+        sshfwd_write(pf->c, pf->socksbuf->u + pf->socksbuf_consumed,
                      pf->socksbuf->len - pf->socksbuf_consumed);
         strbuf_free(pf->socksbuf);
         pf->socksbuf = NULL;

Разница между файлами не показана из-за своего большого размера
+ 430 - 430
source/putty/proxy.c


+ 4 - 4
source/putty/proxy.h

@@ -32,10 +32,10 @@ struct ProxySocket {
 #define PROXY_STATE_ACTIVE  0
 
     int state; /* proxy states greater than 0 are implementation
-		* dependent, but represent various stages/states
-		* of the initialization/setup/negotiation with the
-		* proxy server.
-		*/
+                * dependent, but represent various stages/states
+                * of the initialization/setup/negotiation with the
+                * proxy server.
+                */
     bool freeze; /* should we freeze the underlying socket when
                   * we are done with the proxy negotiation? this
                   * simply caches the value of sk_set_frozen calls.

+ 71 - 71
source/putty/putty.h

@@ -1,7 +1,7 @@
 #ifndef PUTTY_PUTTY_H
 #define PUTTY_PUTTY_H
 
-#include <stddef.h>		       /* for wchar_t */
+#include <stddef.h>                    /* for wchar_t */
 #include <limits.h>                    /* for INT_MAX */
 
 /*
@@ -28,7 +28,7 @@
  * clip some values so that the resulting number of ticks does not overflow an
  * integer value.
  */
-#define MAX_TICK_MINS	(INT_MAX / (60 * TICKSPERSEC))
+#define MAX_TICK_MINS   (INT_MAX / (60 * TICKSPERSEC))
 
 /*
  * Fingerprints of the current and previous PGP master keys, to
@@ -61,10 +61,10 @@
  * ATTR_INVALID is an illegal colour combination.
  */
 
-#define TATTR_ACTCURS 	    0x40000000UL      /* active cursor (block) */
-#define TATTR_PASCURS 	    0x20000000UL      /* passive cursor (box) */
-#define TATTR_RIGHTCURS	    0x10000000UL      /* cursor-on-RHS */
-#define TATTR_COMBINING	    0x80000000UL      /* combining characters */
+#define TATTR_ACTCURS       0x40000000UL      /* active cursor (block) */
+#define TATTR_PASCURS       0x20000000UL      /* passive cursor (box) */
+#define TATTR_RIGHTCURS     0x10000000UL      /* cursor-on-RHS */
+#define TATTR_COMBINING     0x80000000UL      /* combining characters */
 
 #define DATTR_STARTRUN      0x80000000UL   /* start of redraw run */
 
@@ -79,8 +79,8 @@
 #define LATTR_MODE   0x00000003UL
 #define LATTR_WRAPPED 0x00000010UL     /* this line wraps to next */
 #define LATTR_WRAPPED2 0x00000020UL    /* with WRAPPED: CJK wide character
-					  wrapped to next line, so last
-					  single-width cell is empty */
+                                          wrapped to next line, so last
+                                          single-width cell is empty */
 
 #define ATTR_INVALID 0x03FFFFU
 
@@ -98,7 +98,7 @@
 #define DIRECT_CHAR(c) ((c&0xFFFFFC00)==0xD800)
 #define DIRECT_FONT(c) ((c&0xFFFFFE00)==0xF000)
 
-#define UCSERR	     (CSET_LINEDRW|'a')	/* UCS Format error character. */
+#define UCSERR       (CSET_LINEDRW|'a') /* UCS Format error character. */
 /*
  * UCSWIDE is a special value used in the terminal data to signify
  * the character cell containing the right-hand half of a CJK wide
@@ -107,7 +107,7 @@
  * to input it via UTF-8 because our UTF-8 decoder correctly
  * rejects surrogates).
  */
-#define UCSWIDE	     0xDFFF
+#define UCSWIDE      0xDFFF
 
 #define ATTR_NARROW  0x0800000U
 #define ATTR_WIDE    0x0400000U
@@ -148,7 +148,7 @@
 struct sesslist {
     int nsessions;
     const char **sessions;
-    char *buffer;		       /* so memory can be freed later */
+    char *buffer;                      /* so memory can be freed later */
 };
 
 struct unicode_data {
@@ -164,14 +164,14 @@ struct unicode_data {
     unsigned char unitab_ctrl[256];
 };
 
-#define LGXF_OVR  1		       /* existing logfile overwrite */
-#define LGXF_APN  0		       /* existing logfile append */
-#define LGXF_ASK -1		       /* existing logfile ask */
-#define LGTYP_NONE  0		       /* logmode: no logging */
-#define LGTYP_ASCII 1		       /* logmode: pure ascii */
-#define LGTYP_DEBUG 2		       /* logmode: all chars of traffic */
-#define LGTYP_PACKETS 3		       /* logmode: SSH data packets */
-#define LGTYP_SSHRAW 4		       /* logmode: SSH raw data */
+#define LGXF_OVR  1                    /* existing logfile overwrite */
+#define LGXF_APN  0                    /* existing logfile append */
+#define LGXF_ASK -1                    /* existing logfile ask */
+#define LGTYP_NONE  0                  /* logmode: no logging */
+#define LGTYP_ASCII 1                  /* logmode: pure ascii */
+#define LGTYP_DEBUG 2                  /* logmode: all chars of traffic */
+#define LGTYP_PACKETS 3                /* logmode: SSH data packets */
+#define LGTYP_SSHRAW 4                 /* logmode: SSH raw data */
 
 /*
  * Enumeration of 'special commands' that can be sent during a
@@ -228,8 +228,8 @@ typedef enum {
      * backend_get_specials() will use them to specify the structure
      * of the GUI specials menu.
      */
-    SS_SEP,	    /* Separator */
-    SS_SUBMENU,	    /* Start a new submenu with specified name */
+    SS_SEP,         /* Separator */
+    SS_SUBMENU,     /* Start a new submenu with specified name */
     SS_EXITMENU,    /* Exit current submenu, or end of entire specials list */
 } SessionSpecialCode;
 
@@ -259,32 +259,32 @@ typedef enum {
 
 /* Keyboard modifiers -- keys the user is actually holding down */
 
-#define PKM_SHIFT	0x01
-#define PKM_CONTROL	0x02
-#define PKM_META	0x04
-#define PKM_ALT		0x08
+#define PKM_SHIFT       0x01
+#define PKM_CONTROL     0x02
+#define PKM_META        0x04
+#define PKM_ALT         0x08
 
 /* Keyboard flags that aren't really modifiers */
-#define PKF_CAPSLOCK	0x10
-#define PKF_NUMLOCK	0x20
-#define PKF_REPEAT	0x40
+#define PKF_CAPSLOCK    0x10
+#define PKF_NUMLOCK     0x20
+#define PKF_REPEAT      0x40
 
 /* Stand-alone keysyms for function keys */
 
 typedef enum {
-    PK_NULL,		/* No symbol for this key */
+    PK_NULL,            /* No symbol for this key */
     /* Main keypad keys */
     PK_ESCAPE, PK_TAB, PK_BACKSPACE, PK_RETURN, PK_COMPOSE,
     /* Editing keys */
     PK_HOME, PK_INSERT, PK_DELETE, PK_END, PK_PAGEUP, PK_PAGEDOWN,
     /* Cursor keys */
     PK_UP, PK_DOWN, PK_RIGHT, PK_LEFT, PK_REST,
-    /* Numeric keypad */			/* Real one looks like: */
-    PK_PF1, PK_PF2, PK_PF3, PK_PF4,		/* PF1 PF2 PF3 PF4 */
-    PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL,	/*  7   8   9   -  */
-    PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4,	/*  4   5   6   ,  */
-    PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9,	/*  1   2   3  en- */
-    PK_KPBIGPLUS, PK_KPENTER,			/*    0     .  ter */
+    /* Numeric keypad */                        /* Real one looks like: */
+    PK_PF1, PK_PF2, PK_PF3, PK_PF4,             /* PF1 PF2 PF3 PF4 */
+    PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL,       /*  7   8   9   -  */
+    PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4,     /*  4   5   6   ,  */
+    PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9,     /*  1   2   3  en- */
+    PK_KPBIGPLUS, PK_KPENTER,                   /*    0     .  ter */
     /* Top row */
     PK_F1,  PK_F2,  PK_F3,  PK_F4,  PK_F5,
     PK_F6,  PK_F7,  PK_F8,  PK_F9,  PK_F10,
@@ -293,10 +293,10 @@ typedef enum {
     PK_PAUSE
 } Key_Sym;
 
-#define PK_ISEDITING(k)	((k) >= PK_HOME && (k) <= PK_PAGEDOWN)
-#define PK_ISCURSOR(k)	((k) >= PK_UP && (k) <= PK_REST)
-#define PK_ISKEYPAD(k)	((k) >= PK_PF1 && (k) <= PK_KPENTER)
-#define PK_ISFKEY(k)	((k) >= PK_F1 && (k) <= PK_F20)
+#define PK_ISEDITING(k) ((k) >= PK_HOME && (k) <= PK_PAGEDOWN)
+#define PK_ISCURSOR(k)  ((k) >= PK_UP && (k) <= PK_REST)
+#define PK_ISKEYPAD(k)  ((k) >= PK_PF1 && (k) <= PK_KPENTER)
+#define PK_ISFKEY(k)    ((k) >= PK_F1 && (k) <= PK_F20)
 
 enum {
     VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN, VT_UNICODE
@@ -331,14 +331,14 @@ enum {
     /*
      * SSH ciphers (both SSH-1 and SSH-2)
      */
-    CIPHER_WARN,		       /* pseudo 'cipher' */
+    CIPHER_WARN,                       /* pseudo 'cipher' */
     CIPHER_3DES,
     CIPHER_BLOWFISH,
-    CIPHER_AES,			       /* (SSH-2 only) */
+    CIPHER_AES,                        /* (SSH-2 only) */
     CIPHER_DES,
     CIPHER_ARCFOUR,
     CIPHER_CHACHA20,
-    CIPHER_MAX			       /* no. ciphers (inc warn) */
+    CIPHER_MAX                         /* no. ciphers (inc warn) */
 };
 
 enum TriState {
@@ -366,7 +366,7 @@ enum {
     /*
      * Line discipline options which the backend might try to control.
      */
-    LD_EDIT,			       /* local line editing */
+    LD_EDIT,                           /* local line editing */
     LD_ECHO,                           /* local echo */
     LD_N_OPTIONS
 };
@@ -668,16 +668,16 @@ typedef struct {
      */
     bool from_server;
 
-    char *name;		/* Short description, perhaps for dialog box title */
+    char *name;         /* Short description, perhaps for dialog box title */
     bool name_reqd;     /* Display of `name' required or optional? */
-    char *instruction;	/* Long description, maybe with embedded newlines */
+    char *instruction;  /* Long description, maybe with embedded newlines */
     bool instr_reqd;    /* Display of `instruction' required or optional? */
     size_t n_prompts;   /* May be zero (in which case display the foregoing,
                          * if any, and return success) */
     size_t prompts_size; /* allocated storage capacity for prompts[] */
     prompt_t **prompts;
-    void *data;		/* slot for housekeeping data, managed by
-			 * seat_get_userpass_input(); initially NULL */
+    void *data;         /* slot for housekeeping data, managed by
+                         * seat_get_userpass_input(); initially NULL */
 } prompts_t;
 prompts_t *new_prompts(void); // WINSCP (void)
 void add_prompt(prompts_t *p, char *promptstr, bool echo);
@@ -741,11 +741,11 @@ enum { ALL_CLIPBOARDS(CLIP_ID) N_CLIPBOARDS };
  * by seat_set_busy_status. Initial state is assumed to be
  * BUSY_NOT. */
 typedef enum BusyStatus {
-    BUSY_NOT,	    /* Not busy, all user interaction OK */
+    BUSY_NOT,       /* Not busy, all user interaction OK */
     BUSY_WAITING,   /* Waiting for something; local event loops still
-		       running so some local interaction (e.g. menus)
-		       OK, but network stuff is suspended */
-    BUSY_CPU	    /* Locally busy (e.g. crypto); user interaction
+                       running so some local interaction (e.g. menus)
+                       OK, but network stuff is suspended */
+    BUSY_CPU        /* Locally busy (e.g. crypto); user interaction
                      * suspended */
 } BusyStatus;
 
@@ -1501,7 +1501,7 @@ enum config_primary_key { CONFIG_OPTIONS(CONF_ENUM_DEF) N_CONFIG_OPTIONS };
 #define NCFGCOLOURS 22 /* number of colours in CONF_colours above */
 
 /* Functions handling configuration structures. */
-Conf *conf_new(void);		       /* create an empty configuration */
+Conf *conf_new(void);                  /* create an empty configuration */
 void conf_free(Conf *conf);
 Conf *conf_copy(Conf *oldconf);
 void conf_copy_into(Conf *dest, Conf *src);
@@ -1528,7 +1528,7 @@ void conf_set_int(Conf *conf, int key, int value);
 void conf_set_int_int(Conf *conf, int key, int subkey, int value);
 void conf_set_str(Conf *conf, int key, const char *value);
 void conf_set_str_str(Conf *conf, int key,
-		      const char *subkey, const char *val);
+                      const char *subkey, const char *val);
 void conf_del_str_str(Conf *conf, int key, const char *subkey);
 void conf_set_filename(Conf *conf, int key, const Filename *val);
 void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
@@ -1628,9 +1628,9 @@ void term_scroll_to_selection(Terminal *, int);
 void term_pwron(Terminal *, bool);
 void term_clrsb(Terminal *);
 void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
-		int, int, bool, bool, bool);
+                int, int, bool, bool, bool);
 void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
-	      unsigned int);
+              unsigned int);
 void term_lost_clipboard_ownership(Terminal *, int clipboard);
 void term_update(Terminal *);
 void term_invalidate(Terminal *);
@@ -1641,7 +1641,7 @@ void term_copyall(Terminal *, const int *, int);
 void term_reconfig(Terminal *, Conf *);
 void term_request_copy(Terminal *, const int *clipboards, int n_clipboards);
 void term_request_paste(Terminal *, int clipboard);
-void term_seen_key_event(Terminal *); 
+void term_seen_key_event(Terminal *);
 size_t term_data(Terminal *, bool is_stderr, const void *data, size_t len);
 void term_provide_backend(Terminal *term, Backend *backend);
 void term_provide_logctx(Terminal *term, LogContext *logctx);
@@ -1739,9 +1739,9 @@ struct logblank_t {
     int type;
 };
 void log_packet(LogContext *logctx, int direction, int type,
-		const char *texttype, const void *data, size_t len,
-		int n_blanks, const struct logblank_t *blanks,
-		const unsigned long *sequence,
+                const char *texttype, const void *data, size_t len,
+                int n_blanks, const struct logblank_t *blanks,
+                const unsigned long *sequence,
                 unsigned downstream_id, const char *additional_log_text);
 
 /* This is defined by applications that have an obvious logging
@@ -1841,7 +1841,7 @@ void prepare_session(Conf *conf);
  * Exports from sercfg.c.
  */
 void ser_setup_config_box(struct controlbox *b, bool midsession,
-			  int parity_mask, int flow_mask);
+                          int parity_mask, int flow_mask);
 
 /*
  * Exports from version.c.
@@ -1858,10 +1858,10 @@ extern const char commitid[];
 /* void init_ucs(void); -- this is now in platform-specific headers */
 bool is_dbcs_leadbyte(int codepage, char byte);
 int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
-	     wchar_t *wcstr, int wclen);
+             wchar_t *wcstr, int wclen);
 int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
-	     char *mbstr, int mblen, const char *defchr,
-	     struct unicode_data *ucsdata);
+             char *mbstr, int mblen, const char *defchr,
+             struct unicode_data *ucsdata);
 wchar_t xlat_uskbd2cyrllic(int ch);
 int check_compose(int first, int second);
 int decode_codepage(char *cp_name);
@@ -1983,21 +1983,21 @@ void cmdline_error(const char *, ...);
 struct controlbox;
 union control;
 void conf_radiobutton_handler(union control *ctrl, dlgparam *dlg,
-			      void *data, int event);
+                              void *data, int event);
 #define CHECKBOX_INVERT (1<<30)
 void conf_checkbox_handler(union control *ctrl, dlgparam *dlg,
-			   void *data, int event);
+                           void *data, int event);
 void conf_editbox_handler(union control *ctrl, dlgparam *dlg,
-			  void *data, int event);
+                          void *data, int event);
 void conf_filesel_handler(union control *ctrl, dlgparam *dlg,
-			  void *data, int event);
+                          void *data, int event);
 void conf_fontsel_handler(union control *ctrl, dlgparam *dlg,
-			  void *data, int event);
+                          void *data, int event);
 /* Much more special-purpose function needed by sercfg.c */
 void config_protocolbuttons_handler(union control *, dlgparam *, void *, int);
 
 void setup_config_box(struct controlbox *b, bool midsession,
-		      int protocol, int protcfginfo);
+                      int protocol, int protcfginfo);
 
 /*
  * Exports from minibidi.c.
@@ -2017,7 +2017,7 @@ bool is_rtl(int c);
 enum {
     X11_NO_AUTH,
     X11_MIT,                           /* MIT-MAGIC-COOKIE-1 */
-    X11_XDM,			       /* XDM-AUTHORIZATION-1 */
+    X11_XDM,                           /* XDM-AUTHORIZATION-1 */
     X11_NAUTHS
 };
 extern const char *const x11_authnames[];  /* declared in x11fwd.c */
@@ -2046,7 +2046,7 @@ Filename *filename_copy(const Filename *fn);
 void filename_free(Filename *fn);
 void filename_serialise(BinarySink *bs, const Filename *f);
 Filename *filename_deserialise(BinarySource *src);
-char *get_username(void);	       /* return value needs freeing */
+char *get_username(void);              /* return value needs freeing */
 char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */
 char filename_char_sanitise(char c);   /* rewrite special pathname chars */
 bool open_for_write_would_lose_data(const Filename *fn);

+ 2 - 2
source/putty/puttymem.h

@@ -5,8 +5,8 @@
 #ifndef PUTTY_PUTTYMEM_H
 #define PUTTY_PUTTYMEM_H
 
-#include <stddef.h>		       /* for size_t */
-#include <string.h>		       /* for memcpy() */
+#include <stddef.h>                    /* for size_t */
+#include <string.h>                    /* for memcpy() */
 
 #include "defs.h"
 

+ 45 - 45
source/putty/ssh.c

@@ -22,11 +22,11 @@
 #ifndef NO_GSSAPI
 #include "sshgssc.h"
 #include "sshgss.h"
-#define MIN_CTXT_LIFETIME 5	/* Avoid rekey with short lifetime (seconds) */
-#define GSS_KEX_CAPABLE	(1<<0)	/* Can do GSS KEX */
+#define MIN_CTXT_LIFETIME 5     /* Avoid rekey with short lifetime (seconds) */
+#define GSS_KEX_CAPABLE (1<<0)  /* Can do GSS KEX */
 #define GSS_CRED_UPDATED (1<<1) /* Cred updated since previous delegation */
-#define GSS_CTXT_EXPIRES (1<<2)	/* Context expires before next timer */
-#define GSS_CTXT_MAYFAIL (1<<3)	/* Context may expire during handshake */
+#define GSS_CTXT_EXPIRES (1<<2) /* Context expires before next timer */
+#define GSS_CTXT_MAYFAIL (1<<3) /* Context may expire during handshake */
 #endif
 
 struct Ssh {
@@ -240,7 +240,7 @@ static void ssh_got_ssh_version(struct ssh_version_receiver *rcv,
 #endif
 
             connection_layer = ssh2_connection_new(
-                ssh, ssh->connshare, is_simple, ssh->conf, 
+                ssh, ssh->connshare, is_simple, ssh->conf,
                 ssh_verstring_get_remote(old_bpp), &ssh->cl);
             ssh_connect_ppl(ssh, connection_layer);
 
@@ -600,7 +600,7 @@ static void ssh_socket_log(Plug *plug, int type, SockAddr *addr, int port,
 }
 
 static void ssh_closing(Plug *plug, const char *error_msg, int error_code,
-			bool calling_back)
+                        bool calling_back)
 {
     Ssh *ssh = container_of(plug, Ssh, plug);
     if (error_msg) {
@@ -617,8 +617,8 @@ static void ssh_receive(Plug *plug, int urgent, const char *data, size_t len)
 
     /* Log raw data, if we're in that mode. */
     if (ssh->logctx)
-	log_packet(ssh->logctx, PKT_INCOMING, -1, NULL, data, len,
-		   0, NULL, NULL, 0, NULL);
+        log_packet(ssh->logctx, PKT_INCOMING, -1, NULL, data, len,
+                   0, NULL, NULL, 0, NULL);
 
     bufchain_add(&ssh->in_raw, data, len);
     if (!ssh->logically_frozen && ssh->bpp)
@@ -637,7 +637,7 @@ static void ssh_sent(Plug *plug, size_t bufsize)
      * some more data off its bufchain.
      */
     if (bufsize < SSH_MAX_BACKLOG) {
-	ssh_throttle_all(ssh, false, bufsize);
+        ssh_throttle_all(ssh, false, bufsize);
         queue_idempotent_callback(&ssh->ic_out_raw);
     }
 }
@@ -651,31 +651,31 @@ static void ssh_hostport_setup(const char *host, int port, Conf *conf,
         *loghost_ret = loghost;
 
     if (*loghost) {
-	char *tmphost;
+        char *tmphost;
         char *colon;
 
         tmphost = dupstr(loghost);
-	*savedport = 22;	       /* default ssh port */
-
-	/*
-	 * A colon suffix on the hostname string also lets us affect
-	 * savedport. (Unless there are multiple colons, in which case
-	 * we assume this is an unbracketed IPv6 literal.)
-	 */
-	colon = host_strrchr(tmphost, ':');
-	if (colon && colon == host_strchr(tmphost, ':')) {
-	    *colon++ = '\0';
-	    if (*colon)
-		*savedport = atoi(colon);
-	}
+        *savedport = 22;               /* default ssh port */
+
+        /*
+         * A colon suffix on the hostname string also lets us affect
+         * savedport. (Unless there are multiple colons, in which case
+         * we assume this is an unbracketed IPv6 literal.)
+         */
+        colon = host_strrchr(tmphost, ':');
+        if (colon && colon == host_strchr(tmphost, ':')) {
+            *colon++ = '\0';
+            if (*colon)
+                *savedport = atoi(colon);
+        }
 
         *savedhost = host_strduptrim(tmphost);
         sfree(tmphost);
     } else {
-	*savedhost = host_strduptrim(host);
-	if (port < 0)
-	    port = 22;		       /* default ssh port */
-	*savedport = port;
+        *savedhost = host_strduptrim(host);
+        if (port < 0)
+            port = 22;                 /* default ssh port */
+        *savedport = port;
     }
 }
 
@@ -795,11 +795,11 @@ static const char *connect_to_host(
     sshprot = conf_get_int(ssh->conf, CONF_sshprot);
     assert(sshprot == 0 || sshprot == 3);
     if (sshprot == 0)
-	/* SSH-1 only */
-	ssh->version = 1;
+        /* SSH-1 only */
+        ssh->version = 1;
     if (sshprot == 3 || ssh->bare_connection) {
-	/* SSH-2 only */
-	ssh->version = 2;
+        /* SSH-2 only */
+        ssh->version = 2;
     }
 
     /*
@@ -819,8 +819,8 @@ static const char *connect_to_host(
      * loghost, if configured, overrides realhost.
      */
     if (*loghost) {
-	sfree(*realhost);
-	*realhost = dupstr(loghost);
+        sfree(*realhost);
+        *realhost = dupstr(loghost);
     }
 
     return NULL;
@@ -856,7 +856,7 @@ void ssh_throttle_conn(Ssh *ssh, int adjust)
 static void ssh_throttle_all(Ssh *ssh, bool enable, size_t bufsize)
 {
     if (enable == ssh->throttled_all)
-	return;
+        return;
     ssh->throttled_all = enable;
     ssh->overall_bufsize = bufsize;
 
@@ -877,7 +877,7 @@ static void ssh_cache_conf_values(Ssh *ssh)
 static const char *ssh_init(Seat *seat, Backend **backend_handle,
                             LogContext *logctx, Conf *conf,
                             const char *host, int port, char **realhost,
-			    bool nodelay, bool keepalive)
+                            bool nodelay, bool keepalive)
 {
     const char *p;
     Ssh *ssh;
@@ -917,7 +917,7 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle,
          * the random seed won't be re-saved. */
         ssh->need_random_unref = false;
         random_unref();
-	return p;
+        return p;
     }
 
     return NULL;
@@ -939,13 +939,13 @@ static void ssh_free(Backend *be)
 
 #ifndef NO_GSSAPI
     if (ssh->gss_state.srv_name)
-        ssh->gss_state.lib->release_name( 
+        ssh->gss_state.lib->release_name(
             ssh->gss_state.lib, &ssh->gss_state.srv_name);
     if (ssh->gss_state.ctx != NULL)
         ssh->gss_state.lib->release_cred(
             ssh->gss_state.lib, &ssh->gss_state.ctx);
     if (ssh->gss_state.libs)
-	ssh_gss_cleanup(ssh->gss_state.libs);
+        ssh_gss_cleanup(ssh->gss_state.libs);
 #endif
 
     sfree(ssh->deferred_abort_message);
@@ -984,7 +984,7 @@ static size_t ssh_send(Backend *be, const char *buf, size_t len)
     Ssh *ssh = container_of(be, Ssh, backend);
 
     if (ssh == NULL || ssh->s == NULL)
-	return 0;
+        return 0;
 
     bufchain_add(&ssh->user_input, buf, len);
     if (ssh->base_layer)
@@ -1002,7 +1002,7 @@ static size_t ssh_sendbuffer(Backend *be)
     size_t backlog;
 
     if (!ssh || !ssh->s || !ssh->cl)
-	return 0;
+        return 0;
 
     backlog = ssh_stdin_backlog(ssh->cl);
 
@@ -1013,7 +1013,7 @@ static size_t ssh_sendbuffer(Backend *be)
      * size on that to any individual buffer on the stdin channel.
      */
     if (ssh->throttled_all)
-	backlog += ssh->overall_bufsize;
+        backlog += ssh->overall_bufsize;
 
     return backlog;
 }
@@ -1120,7 +1120,7 @@ void ssh_ldisc_update(Ssh *ssh)
     /* Called when the connection layer wants to propagate an update
      * to the line discipline options */
     if (ssh->ldisc)
-	ldisc_echoedit_update(ssh->ldisc);
+        ldisc_echoedit_update(ssh->ldisc);
 }
 
 static bool ssh_ldisc(Backend *be, int option)
@@ -1158,11 +1158,11 @@ static int ssh_cfg_info(Backend *be)
 {
     Ssh *ssh = container_of(be, Ssh, backend);
     if (ssh->version == 0)
-	return 0; /* don't know yet */
+        return 0; /* don't know yet */
     else if (ssh->bare_connection)
-	return -1;
+        return -1;
     else
-	return ssh->version;
+        return ssh->version;
 }
 
 /*

+ 40 - 40
source/putty/ssh.h

@@ -647,7 +647,7 @@ struct ssh_cipheralg {
      * different. */
     int padded_keybytes;
     unsigned int flags;
-#define SSH_CIPHER_IS_CBC	1
+#define SSH_CIPHER_IS_CBC       1
 #define SSH_CIPHER_SEPARATE_LENGTH      2
     const char *text_name;
     /* If set, this takes priority over other MAC. */
@@ -908,7 +908,7 @@ static inline const ssh_compression_alg *ssh_decompressor_alg(
 
 struct ssh2_userkey {
     ssh_key *key;                      /* the key itself */
-    char *comment;		       /* the key comment */
+    char *comment;                     /* the key comment */
 };
 
 /* The maximum length of any hash algorithm. (bytes) */
@@ -994,7 +994,7 @@ bool platform_sha256_hw_available(void);
 bool platform_sha1_hw_available(void);
 
 /*
- * PuTTY version number formatted as an SSH version string. 
+ * PuTTY version number formatted as an SSH version string.
  */
 extern
 #ifndef MPEXT
@@ -1138,7 +1138,7 @@ char *platform_get_x_display(void);
  * calling this function to do the rest of the work.
  */
 void x11_get_auth_from_authfile(struct X11Display *display,
-				const char *authfilename);
+                                const char *authfilename);
 void x11_format_auth_for_authfile(
     BinarySink *bs, SockAddr *addr, int display_no,
     ptrlen authproto, ptrlen authdata);
@@ -1253,7 +1253,7 @@ bool import_possible(int type);
 int import_target_type(int type);
 bool import_encrypted(const Filename *filename, int type, char **comment);
 int import_ssh1(const Filename *filename, int type,
-		RSAKey *key, char *passphrase, const char **errmsg_p);
+                RSAKey *key, char *passphrase, const char **errmsg_p);
 ssh2_userkey *import_ssh2(const Filename *filename, int type,
                           char *passphrase, const char **errmsg_p);
 bool export_ssh1(const Filename *filename, int type,
@@ -1264,9 +1264,9 @@ bool export_ssh2(const Filename *filename, int type,
 void des3_decrypt_pubkey(const void *key, void *blk, int len);
 void des3_encrypt_pubkey(const void *key, void *blk, int len);
 void des3_decrypt_pubkey_ossh(const void *key, const void *iv,
-			      void *blk, int len);
+                              void *blk, int len);
 void des3_encrypt_pubkey_ossh(const void *key, const void *iv,
-			      void *blk, int len);
+                              void *blk, int len);
 void aes256_encrypt_pubkey(const void *key, void *blk, int len);
 void aes256_decrypt_pubkey(const void *key, void *blk, int len);
 
@@ -1289,9 +1289,9 @@ void openssh_bcrypt(const char *passphrase,
 typedef void (*progfn_t) (void *param, int action, int phase, int progress);
 
 int rsa_generate(RSAKey *key, int bits, progfn_t pfn,
-		 void *pfnparam);
+                 void *pfnparam);
 int dsa_generate(struct dss_key *key, int bits, progfn_t pfn,
-		 void *pfnparam);
+                 void *pfnparam);
 int ecdsa_generate(struct ecdsa_key *key, int bits, progfn_t pfn,
                    void *pfnparam);
 int eddsa_generate(struct eddsa_key *key, int bits, progfn_t pfn,
@@ -1364,16 +1364,16 @@ void platform_ssh_share_cleanup(const char *name);
     X(y, SSH1_CMSG_AUTH_CCARD_RESPONSE, 72)             \
     /* end of list */
 
-#define SSH1_AUTH_RHOSTS                          1	/* 0x1 */
-#define SSH1_AUTH_RSA                             2	/* 0x2 */
-#define SSH1_AUTH_PASSWORD                        3	/* 0x3 */
-#define SSH1_AUTH_RHOSTS_RSA                      4	/* 0x4 */
-#define SSH1_AUTH_TIS                             5	/* 0x5 */
-#define SSH1_AUTH_CCARD                           16	/* 0x10 */
+#define SSH1_AUTH_RHOSTS                          1     /* 0x1 */
+#define SSH1_AUTH_RSA                             2     /* 0x2 */
+#define SSH1_AUTH_PASSWORD                        3     /* 0x3 */
+#define SSH1_AUTH_RHOSTS_RSA                      4     /* 0x4 */
+#define SSH1_AUTH_TIS                             5     /* 0x5 */
+#define SSH1_AUTH_CCARD                           16    /* 0x10 */
 
-#define SSH1_PROTOFLAG_SCREEN_NUMBER              1	/* 0x1 */
+#define SSH1_PROTOFLAG_SCREEN_NUMBER              1     /* 0x1 */
 /* Mask for protoflags we will echo back to server if seen */
-#define SSH1_PROTOFLAGS_SUPPORTED                 0	/* 0x1 */
+#define SSH1_PROTOFLAGS_SUPPORTED                 0     /* 0x1 */
 
 /*
  * List macro defining SSH-2 message type codes. Some of these depend
@@ -1459,7 +1459,7 @@ enum {
 #define SSH1_AGENT_RSA_RESPONSE               4
 #define SSH1_AGENTC_ADD_RSA_IDENTITY          7
 #define SSH1_AGENTC_REMOVE_RSA_IDENTITY       8
-#define SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9	/* openssh private? */
+#define SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9 /* openssh private? */
 
 /*
  * Messages common to SSH-1 and OpenSSH's SSH-2.
@@ -1481,28 +1481,28 @@ enum {
 /*
  * Assorted other SSH-related enumerations.
  */
-#define SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1	/* 0x1 */
-#define SSH2_DISCONNECT_PROTOCOL_ERROR            2	/* 0x2 */
-#define SSH2_DISCONNECT_KEY_EXCHANGE_FAILED       3	/* 0x3 */
-#define SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED 4	/* 0x4 */
-#define SSH2_DISCONNECT_MAC_ERROR                 5	/* 0x5 */
-#define SSH2_DISCONNECT_COMPRESSION_ERROR         6	/* 0x6 */
-#define SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE     7	/* 0x7 */
-#define SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8	/* 0x8 */
-#define SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE   9	/* 0x9 */
-#define SSH2_DISCONNECT_CONNECTION_LOST           10	/* 0xa */
-#define SSH2_DISCONNECT_BY_APPLICATION            11	/* 0xb */
-#define SSH2_DISCONNECT_TOO_MANY_CONNECTIONS      12	/* 0xc */
-#define SSH2_DISCONNECT_AUTH_CANCELLED_BY_USER    13	/* 0xd */
-#define SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14	/* 0xe */
-#define SSH2_DISCONNECT_ILLEGAL_USER_NAME         15	/* 0xf */
-
-#define SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED     1	/* 0x1 */
-#define SSH2_OPEN_CONNECT_FAILED                  2	/* 0x2 */
-#define SSH2_OPEN_UNKNOWN_CHANNEL_TYPE            3	/* 0x3 */
-#define SSH2_OPEN_RESOURCE_SHORTAGE               4	/* 0x4 */
-
-#define SSH2_EXTENDED_DATA_STDERR                 1	/* 0x1 */
+#define SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1   /* 0x1 */
+#define SSH2_DISCONNECT_PROTOCOL_ERROR            2     /* 0x2 */
+#define SSH2_DISCONNECT_KEY_EXCHANGE_FAILED       3     /* 0x3 */
+#define SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED 4    /* 0x4 */
+#define SSH2_DISCONNECT_MAC_ERROR                 5     /* 0x5 */
+#define SSH2_DISCONNECT_COMPRESSION_ERROR         6     /* 0x6 */
+#define SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE     7     /* 0x7 */
+#define SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8        /* 0x8 */
+#define SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE   9     /* 0x9 */
+#define SSH2_DISCONNECT_CONNECTION_LOST           10    /* 0xa */
+#define SSH2_DISCONNECT_BY_APPLICATION            11    /* 0xb */
+#define SSH2_DISCONNECT_TOO_MANY_CONNECTIONS      12    /* 0xc */
+#define SSH2_DISCONNECT_AUTH_CANCELLED_BY_USER    13    /* 0xd */
+#define SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14       /* 0xe */
+#define SSH2_DISCONNECT_ILLEGAL_USER_NAME         15    /* 0xf */
+
+#define SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED     1     /* 0x1 */
+#define SSH2_OPEN_CONNECT_FAILED                  2     /* 0x2 */
+#define SSH2_OPEN_UNKNOWN_CHANNEL_TYPE            3     /* 0x3 */
+#define SSH2_OPEN_RESOURCE_SHORTAGE               4     /* 0x4 */
+
+#define SSH2_EXTENDED_DATA_STDERR                 1     /* 0x1 */
 
 enum {
     /* TTY modes with opcodes defined consistently in the SSH specs. */

+ 1 - 1
source/putty/ssh1bpp.c

@@ -286,7 +286,7 @@ static void ssh1_bpp_handle_input(BinaryPacketProtocol *bpp)
 static PktOut *ssh1_bpp_new_pktout(int pkt_type)
 {
     PktOut *pkt = ssh_new_packet();
-    pkt->length = 4 + 8;	    /* space for length + max padding */
+    pkt->length = 4 + 8;            /* space for length + max padding */
     put_byte(pkt, pkt_type);
     pkt->prefix = pkt->length;
     pkt->type = pkt_type;

+ 5 - 5
source/putty/ssh1connection-client.c

@@ -471,17 +471,17 @@ static void ssh1_rportfwd_response(struct ssh1_connection_state *s,
     struct ssh_rportfwd *rpf = (struct ssh_rportfwd *)ctx;
 
     if (success) {
-	ppl_logevent("Remote port forwarding from %s enabled",
+        ppl_logevent("Remote port forwarding from %s enabled",
                      rpf->log_description);
     } else {
-	ppl_logevent("Remote port forwarding from %s refused",
+        ppl_logevent("Remote port forwarding from %s refused",
                      rpf->log_description);
 
 	{ // WINSCP
-	struct ssh_rportfwd *realpf = del234(s->rportfwds, rpf);
-	assert(realpf == rpf);
+        struct ssh_rportfwd *realpf = del234(s->rportfwds, rpf);
+        assert(realpf == rpf);
         portfwdmgr_close(s->portfwdmgr, rpf->pfr);
-	free_rportfwd(rpf);
+        free_rportfwd(rpf);
 	} // WINSCP
     }
 }

+ 21 - 21
source/putty/ssh1connection.c

@@ -22,15 +22,15 @@ static int ssh1_rportfwd_cmp(void *av, void *bv)
     struct ssh_rportfwd *b = (struct ssh_rportfwd *) bv;
     int i;
     if ( (i = strcmp(a->dhost, b->dhost)) != 0)
-	return i < 0 ? -1 : +1;
+        return i < 0 ? -1 : +1;
     if (a->dport > b->dport)
-	return +1;
+        return +1;
     if (a->dport < b->dport)
-	return -1;
+        return -1;
     return 0;
 }
 
-static void ssh1_connection_free(PacketProtocolLayer *); 
+static void ssh1_connection_free(PacketProtocolLayer *);
 static void ssh1_connection_process_queue(PacketProtocolLayer *);
 static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl,
                                         SessionSpecialCode code, int arg);
@@ -137,9 +137,9 @@ static int ssh1_channelcmp(void *av, void *bv)
     const struct ssh1_channel *a = (const struct ssh1_channel *) av;
     const struct ssh1_channel *b = (const struct ssh1_channel *) bv;
     if (a->localid < b->localid)
-	return -1;
+        return -1;
     if (a->localid > b->localid)
-	return +1;
+        return +1;
     return 0;
 }
 
@@ -148,9 +148,9 @@ static int ssh1_channelfind(void *av, void *bv)
     const unsigned *a = (const unsigned *) av;
     const struct ssh1_channel *b = (const struct ssh1_channel *) bv;
     if (*a < b->localid)
-	return -1;
+        return -1;
     if (*a > b->localid)
-	return +1;
+        return +1;
     return 0;
 }
 
@@ -204,7 +204,7 @@ static void ssh1_connection_free(PacketProtocolLayer *ppl)
         chan_free(s->mainchan_chan);
 
     if (s->x11disp)
-	x11_free_display(s->x11disp);
+        x11_free_display(s->x11disp);
     while ((auth = delpos234(s->x11authtree, 0)) != NULL)
         x11_free_fake_auth(auth);
     freetree234(s->x11authtree);
@@ -273,7 +273,7 @@ static bool ssh1_connection_filter_queue(struct ssh1_connection_state *s)
                     localid);
                 return true;
             }
- 
+
             switch (pktin->type) {
               case SSH1_MSG_CHANNEL_OPEN_CONFIRMATION:
                 assert(c->halfopen);
@@ -430,19 +430,19 @@ static void ssh1_connection_process_queue(PacketProtocolLayer *ppl)
 
     while (1) {
 
-	/*
-	 * By this point, most incoming packets are already being
-	 * handled by filter_queue, and we need only pay attention to
-	 * the unusual ones.
-	 */
+        /*
+         * By this point, most incoming packets are already being
+         * handled by filter_queue, and we need only pay attention to
+         * the unusual ones.
+         */
 
-	if ((pktin = ssh1_connection_pop(s)) != NULL) {
+        if ((pktin = ssh1_connection_pop(s)) != NULL) {
             ssh_proto_error(s->ppl.ssh, "Unexpected packet received, "
                             "type %d (%s)", pktin->type,
                             ssh1_pkt_type(pktin->type));
             return;
-	}
-	crReturnV;
+        }
+        crReturnV;
     }
 
     crFinishV;
@@ -465,7 +465,7 @@ static void ssh1_channel_check_close(struct ssh1_channel *c)
     if ((!((CLOSES_SENT_CLOSE | CLOSES_RCVD_CLOSE) & ~c->closes) ||
          chan_want_close(c->chan, (c->closes & CLOSES_SENT_CLOSE),
                          (c->closes & CLOSES_RCVD_CLOSE))) &&
-	!(c->closes & CLOSES_SENT_CLOSECONF)) {
+        !(c->closes & CLOSES_SENT_CLOSECONF)) {
         /*
          * We have both sent and received CLOSE (or the channel type
          * doesn't need us to), which means the channel is in final
@@ -628,8 +628,8 @@ static void ssh1channel_unthrottle(SshChannel *sc, size_t bufsize)
     struct ssh1_connection_state *s = c->connlayer;
 
     if (c->throttling_conn && bufsize <= SSH1_BUFFER_LIMIT) {
-	c->throttling_conn = false;
-	ssh_throttle_conn(s->ppl.ssh, -1);
+        c->throttling_conn = false;
+        ssh_throttle_conn(s->ppl.ssh, -1);
     }
 }
 

+ 1 - 1
source/putty/ssh1connection.h

@@ -10,7 +10,7 @@ struct ssh1_connection_state {
     Conf *conf;
     int local_protoflags, remote_protoflags;
 
-    tree234 *channels;		       /* indexed by local id */
+    tree234 *channels;                 /* indexed by local id */
 
     /* In SSH-1, the main session doesn't take the form of a 'channel'
      * according to the wire protocol. But we want to use the same API

+ 13 - 13
source/putty/ssh1login.c

@@ -63,7 +63,7 @@ struct ssh1_login_state {
     PacketProtocolLayer ppl;
 };
 
-static void ssh1_login_free(PacketProtocolLayer *); 
+static void ssh1_login_free(PacketProtocolLayer *);
 static void ssh1_login_process_queue(PacketProtocolLayer *);
 static void ssh1_login_dialog_callback(void *, int);
 static void ssh1_login_special_cmd(PacketProtocolLayer *ppl,
@@ -292,8 +292,8 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
         bool cipher_chosen = false, warn = false;
         const char *cipher_string = NULL;
         int i;
-	for (i = 0; !cipher_chosen && i < CIPHER_MAX; i++) {
-	    int next_cipher = conf_get_int_int(
+        for (i = 0; !cipher_chosen && i < CIPHER_MAX; i++) {
+            int next_cipher = conf_get_int_int(
                 s->conf, CONF_ssh_cipherlist, i);
             if (next_cipher == CIPHER_WARN) {
                 /* If/when we choose a cipher, warn about it */
@@ -957,29 +957,29 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
              * SSH1_MSG_IGNORE packets. This way a passive
              * listener can't tell which is the password, and
              * hence can't deduce the password length.
-             * 
+             *
              * Anybody with a password length greater than 16
              * bytes is going to have enough entropy in their
              * password that a listener won't find it _that_
              * much help to know how long it is. So what we'll
              * do is:
-             * 
+             *
              *  - if password length < 16, we send 15 packets
              *    containing string lengths 1 through 15
-             * 
+             *
              *  - otherwise, we let N be the nearest multiple
              *    of 8 below the password length, and send 8
              *    packets containing string lengths N through
              *    N+7. This won't obscure the order of
              *    magnitude of the password length, but it will
              *    introduce a bit of extra uncertainty.
-             * 
+             *
              * A few servers can't deal with SSH1_MSG_IGNORE, at
              * least in this context. For these servers, we need
              * an alternative defence. We make use of the fact
              * that the password is interpreted as a C string:
              * so we can append a NUL, then some random data.
-             * 
+             *
              * A few servers can deal with neither SSH1_MSG_IGNORE
              * here _nor_ a padded password string.
              * For these servers we are left with no defences
@@ -1019,7 +1019,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                     }
                 }
                 ppl_logevent("Sending password with camouflage packets");
-            } 
+            }
             else if (!(s->ppl.remote_bugs & BUG_NEEDS_SSH1_PLAIN_PASSWORD)) {
                 /*
                  * The server can't deal with SSH1_MSG_IGNORE
@@ -1076,7 +1076,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
         put_uint32(pkt, 6);         /* gzip compression level */
         pq_push(s->ppl.out_pq, pkt);
         crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL);
-	if (pktin->type == SSH1_SMSG_SUCCESS) {
+        if (pktin->type == SSH1_SMSG_SUCCESS) {
             /*
              * We don't have to actually do anything here: the SSH-1
              * BPP will take care of automatically starting the
@@ -1085,15 +1085,15 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
              * easiest way to avoid race conditions if other packets
              * cross in transit.)
              */
-	} else if (pktin->type == SSH1_SMSG_FAILURE) {
+        } else if (pktin->type == SSH1_SMSG_FAILURE) {
             ppl_logevent("Server refused to enable compression");
-	    ppl_printf("Server refused to compress\r\n");
+            ppl_printf("Server refused to compress\r\n");
         } else {
             ssh_proto_error(s->ppl.ssh, "Received unexpected packet"
                             " in response to compression request, type %d "
                             "(%s)", pktin->type, ssh1_pkt_type(pktin->type));
             return;
-	}
+        }
     }
 
     ssh1_connection_set_protoflags(

+ 12 - 12
source/putty/ssh2connection-client.c

@@ -181,11 +181,11 @@ static int ssh2_rportfwd_cmp(void *av, void *bv)
     struct ssh_rportfwd *b = (struct ssh_rportfwd *) bv;
     int i;
     if ( (i = strcmp(a->shost, b->shost)) != 0)
-	return i < 0 ? -1 : +1;
+        return i < 0 ? -1 : +1;
     if (a->sport > b->sport)
-	return +1;
+        return +1;
     if (a->sport < b->sport)
-	return -1;
+        return -1;
     return 0;
 }
 
@@ -196,17 +196,17 @@ static void ssh2_rportfwd_globreq_response(struct ssh2_connection_state *s,
     struct ssh_rportfwd *rpf = (struct ssh_rportfwd *)ctx;
 
     if (pktin->type == SSH2_MSG_REQUEST_SUCCESS) {
-	ppl_logevent("Remote port forwarding from %s enabled",
+        ppl_logevent("Remote port forwarding from %s enabled",
                      rpf->log_description);
     } else {
-	ppl_logevent("Remote port forwarding from %s refused",
+        ppl_logevent("Remote port forwarding from %s refused",
                      rpf->log_description);
 
 	{ // WINSCP
-	struct ssh_rportfwd *realpf = del234(s->rportfwds, rpf);
-	assert(realpf == rpf);
+        struct ssh_rportfwd *realpf = del234(s->rportfwds, rpf);
+        assert(realpf == rpf);
         portfwdmgr_close(s->portfwdmgr, rpf->pfr);
-	free_rportfwd(rpf);
+        free_rportfwd(rpf);
 	} // WINSCP
     }
 }
@@ -414,8 +414,8 @@ void ssh2channel_request_pty(
     put_stringz(pktout, conf_get_str(conf, CONF_termtype));
     put_uint32(pktout, w);
     put_uint32(pktout, h);
-    put_uint32(pktout, 0);	       /* pixel width */
-    put_uint32(pktout, 0);	       /* pixel height */
+    put_uint32(pktout, 0);             /* pixel width */
+    put_uint32(pktout, 0);             /* pixel height */
     modebuf = strbuf_new();
     write_ttymodes_to_packet(
         BinarySink_UPCAST(modebuf), 2,
@@ -474,8 +474,8 @@ void ssh2channel_send_terminal_size_change(SshChannel *sc, int w, int h)
     PktOut *pktout = ssh2_chanreq_init(c, "window-change", NULL, NULL);
     put_uint32(pktout, w);
     put_uint32(pktout, h);
-    put_uint32(pktout, 0);	       /* pixel width */
-    put_uint32(pktout, 0);	       /* pixel height */
+    put_uint32(pktout, 0);             /* pixel width */
+    put_uint32(pktout, 0);             /* pixel height */
     pq_push(s->ppl.out_pq, pktout);
 }
 

+ 61 - 61
source/putty/ssh2connection.c

@@ -14,7 +14,7 @@
 // WINSCP
 #define queue_toplevel_callback(FN, CTX) queue_toplevel_callback(get_log_callback_set(CTX->cl.logctx), FN, CTX)
 
-static void ssh2_connection_free(PacketProtocolLayer *); 
+static void ssh2_connection_free(PacketProtocolLayer *);
 static void ssh2_connection_process_queue(PacketProtocolLayer *);
 static bool ssh2_connection_get_specials(
     PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
@@ -195,9 +195,9 @@ static int ssh2_channelcmp(void *av, void *bv)
     const struct ssh2_channel *a = (const struct ssh2_channel *) av;
     const struct ssh2_channel *b = (const struct ssh2_channel *) bv;
     if (a->localid < b->localid)
-	return -1;
+        return -1;
     if (a->localid > b->localid)
-	return +1;
+        return +1;
     return 0;
 }
 
@@ -206,9 +206,9 @@ static int ssh2_channelfind(void *av, void *bv)
     const unsigned *a = (const unsigned *) av;
     const struct ssh2_channel *b = (const struct ssh2_channel *) bv;
     if (*a < b->localid)
-	return -1;
+        return -1;
     if (*a > b->localid)
-	return +1;
+        return +1;
     return 0;
 }
 
@@ -414,7 +414,7 @@ static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                 put_uint32(pktout, c->remoteid);
                 put_uint32(pktout, chanopen_result.u.failure.reason_code);
                 put_stringz(pktout, chanopen_result.u.failure.wire_message);
-                put_stringz(pktout, "en");	/* language tag */
+                put_stringz(pktout, "en");      /* language tag */
                 pq_push(s->ppl.out_pq, pktout);
                 ppl_logevent("Rejected channel open: %s",
                              chanopen_result.u.failure.wire_message);
@@ -485,7 +485,7 @@ static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                                 localid);
                 return true;
             }
- 
+
             switch (pktin->type) {
               case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:
                 assert(c->halfopen);
@@ -860,7 +860,7 @@ static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s)
 }
 
 static void ssh2_handle_winadj_response(struct ssh2_channel *c,
-					PktIn *pktin, void *ctx)
+                                        PktIn *pktin, void *ctx)
 {
     unsigned *sizep = ctx;
 
@@ -880,7 +880,7 @@ static void ssh2_handle_winadj_response(struct ssh2_channel *c,
      * complete.
      */
     if (c->throttle_state == UNTHROTTLING)
-	c->throttle_state = UNTHROTTLED;
+        c->throttle_state = UNTHROTTLED;
 }
 
 static void ssh2_set_window(struct ssh2_channel *c, int newwin)
@@ -894,7 +894,7 @@ static void ssh2_set_window(struct ssh2_channel *c, int newwin)
      * CLOSE.
      */
     if (c->closes & (CLOSES_RCVD_EOF | CLOSES_SENT_CLOSE))
-	return;
+        return;
 
     /*
      * If the client-side Channel is in an initial setup phase with a
@@ -911,7 +911,7 @@ static void ssh2_set_window(struct ssh2_channel *c, int newwin)
      * window as well).
      */
     if ((s->ppl.remote_bugs & BUG_SSH2_MAXPKT) && newwin > OUR_V2_MAXPKT)
-	newwin = OUR_V2_MAXPKT;
+        newwin = OUR_V2_MAXPKT;
 
     /*
      * Only send a WINDOW_ADJUST if there's significantly more window
@@ -921,39 +921,39 @@ static void ssh2_set_window(struct ssh2_channel *c, int newwin)
      * "Significant" is arbitrarily defined as half the window size.
      */
     if (newwin / 2 >= c->locwindow) {
-	PktOut *pktout;
-	unsigned *up;
-
-	/*
-	 * In order to keep track of how much window the client
-	 * actually has available, we'd like it to acknowledge each
-	 * WINDOW_ADJUST.  We can't do that directly, so we accompany
-	 * it with a CHANNEL_REQUEST that has to be acknowledged.
-	 *
-	 * This is only necessary if we're opening the window wide.
-	 * If we're not, then throughput is being constrained by
-	 * something other than the maximum window size anyway.
-	 */
-	if (newwin == c->locmaxwin &&
+        PktOut *pktout;
+        unsigned *up;
+
+        /*
+         * In order to keep track of how much window the client
+         * actually has available, we'd like it to acknowledge each
+         * WINDOW_ADJUST.  We can't do that directly, so we accompany
+         * it with a CHANNEL_REQUEST that has to be acknowledged.
+         *
+         * This is only necessary if we're opening the window wide.
+         * If we're not, then throughput is being constrained by
+         * something other than the maximum window size anyway.
+         */
+        if (newwin == c->locmaxwin &&
             !(s->ppl.remote_bugs & BUG_CHOKES_ON_WINADJ)) {
-	    up = snew(unsigned);
-	    *up = newwin - c->locwindow;
-	    pktout = ssh2_chanreq_init(c, "[email protected]",
-				       ssh2_handle_winadj_response, up);
-	    pq_push(s->ppl.out_pq, pktout);
-
-	    if (c->throttle_state != UNTHROTTLED)
-		c->throttle_state = UNTHROTTLING;
-	} else {
-	    /* Pretend the WINDOW_ADJUST was acked immediately. */
-	    c->remlocwin = newwin;
-	    c->throttle_state = THROTTLED;
-	}
-	pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_WINDOW_ADJUST);
-	put_uint32(pktout, c->remoteid);
-	put_uint32(pktout, newwin - c->locwindow);
-	pq_push(s->ppl.out_pq, pktout);
-	c->locwindow = newwin;
+            up = snew(unsigned);
+            *up = newwin - c->locwindow;
+            pktout = ssh2_chanreq_init(c, "[email protected]",
+                                       ssh2_handle_winadj_response, up);
+            pq_push(s->ppl.out_pq, pktout);
+
+            if (c->throttle_state != UNTHROTTLED)
+                c->throttle_state = UNTHROTTLING;
+        } else {
+            /* Pretend the WINDOW_ADJUST was acked immediately. */
+            c->remlocwin = newwin;
+            c->throttle_state = THROTTLED;
+        }
+        pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_WINDOW_ADJUST);
+        put_uint32(pktout, c->remoteid);
+        put_uint32(pktout, newwin - c->locwindow);
+        pq_push(s->ppl.out_pq, pktout);
+        c->locwindow = newwin;
     }
 }
 
@@ -1036,13 +1036,13 @@ static void ssh2_connection_process_queue(PacketProtocolLayer *ppl)
      */
 
     while (1) {
-	if ((pktin = ssh2_connection_pop(s)) != NULL) {
+        if ((pktin = ssh2_connection_pop(s)) != NULL) {
 
-	    /*
-	     * _All_ the connection-layer packets we expect to
-	     * receive are now handled by the dispatch table.
-	     * Anything that reaches here must be bogus.
-	     */
+            /*
+             * _All_ the connection-layer packets we expect to
+             * receive are now handled by the dispatch table.
+             * Anything that reaches here must be bogus.
+             */
 
             ssh_proto_error(s->ppl.ssh, "Received unexpected connection-layer "
                             "packet, type %d (%s)", pktin->type,
@@ -1050,8 +1050,8 @@ static void ssh2_connection_process_queue(PacketProtocolLayer *ppl)
                                           s->ppl.bpp->pls->actx,
                                           pktin->type));
             return;
-	}
-	crReturnV;
+        }
+        crReturnV;
     }
 
     crFinishV;
@@ -1073,22 +1073,22 @@ static void ssh2_channel_check_close(struct ssh2_channel *c)
 
     if (chan_want_close(c->chan, (c->closes & CLOSES_SENT_EOF),
                         (c->closes & CLOSES_RCVD_EOF)) &&
-	!c->chanreq_head &&
-	!(c->closes & CLOSES_SENT_CLOSE)) {
+        !c->chanreq_head &&
+        !(c->closes & CLOSES_SENT_CLOSE)) {
         /*
          * We have both sent and received EOF (or the channel is a
          * zombie), and we have no outstanding channel requests, which
          * means the channel is in final wind-up. But we haven't sent
          * CLOSE, so let's do so now.
          */
-	pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_CLOSE);
-	put_uint32(pktout, c->remoteid);
-	pq_push(s->ppl.out_pq, pktout);
+        pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_CLOSE);
+        put_uint32(pktout, c->remoteid);
+        pq_push(s->ppl.out_pq, pktout);
         c->closes |= CLOSES_SENT_EOF | CLOSES_SENT_CLOSE;
     }
 
     if (!((CLOSES_SENT_CLOSE | CLOSES_RCVD_CLOSE) & ~c->closes)) {
-	assert(c->chanreq_head == NULL);
+        assert(c->chanreq_head == NULL);
         /*
          * We have both sent and received CLOSE, which means we're
          * completely done with the channel.
@@ -1173,7 +1173,7 @@ static void ssh2_try_send_and_unthrottle(struct ssh2_channel *c)
 {
     int bufsize;
     if (c->closes & CLOSES_SENT_EOF)
-	return;                   /* don't send on channels we've EOFed */
+        return;                   /* don't send on channels we've EOFed */
     bufsize = ssh2_try_send(c);
     if (bufsize == 0) {
         c->throttled_by_backlog = false;
@@ -1397,8 +1397,8 @@ static void ssh2channel_unthrottle(SshChannel *sc, size_t bufsize)
         ssh2_set_window(c, buflimit - bufsize);
 
     if (c->throttling_conn && bufsize <= buflimit) {
-	c->throttling_conn = false;
-	ssh_throttle_conn(s->ppl.ssh, -1);
+        c->throttling_conn = false;
+        ssh_throttle_conn(s->ppl.ssh, -1);
     }
 }
 
@@ -1625,7 +1625,7 @@ static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl,
             pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_IGNORE);
             put_stringz(pktout, "");
             pq_push(s->ppl.out_pq, pktout);
-	}
+        }
     } else if (s->mainchan) {
         mainchan_special_cmd(s->mainchan, code, arg);
     }

+ 1 - 1
source/putty/ssh2connection.h

@@ -25,7 +25,7 @@ struct ssh2_connection_state {
 
     Conf *conf;
 
-    tree234 *channels;		       /* indexed by local id */
+    tree234 *channels;                 /* indexed by local id */
     bool all_channels_throttled;
 
     bool X11_fwd_enabled;

+ 10 - 10
source/putty/ssh2transport.c

@@ -1595,7 +1595,7 @@ static void ssh2_transport_timer(void *ctx, unsigned long now)
 
     mins = sanitise_rekey_time(conf_get_int(s->conf, CONF_ssh_rekey_time), 60);
     if (mins == 0)
-	return;
+        return;
 
     /* Rekey if enough time has elapsed */
     ticks = mins * 60 * TICKSPERSEC;
@@ -1900,18 +1900,18 @@ static void ssh2_transport_special_cmd(PacketProtocolLayer *ppl,
         container_of(ppl, struct ssh2_transport_state, ppl);
 
     if (code == SS_REKEY) {
-	if (!s->kex_in_progress) {
+        if (!s->kex_in_progress) {
             s->rekey_reason = "at user request";
             s->rekey_class = RK_NORMAL;
             queue_idempotent_callback(&s->ppl.ic_process_queue);
-	}
+        }
     } else if (code == SS_XCERT) {
-	if (!s->kex_in_progress) {
+        if (!s->kex_in_progress) {
             s->cross_certifying = s->hostkey_alg = ssh2_hostkey_algs[arg].alg;
             s->rekey_reason = "cross-certifying new host key";
             s->rekey_class = RK_NORMAL;
             queue_idempotent_callback(&s->ppl.ic_process_queue);
-	}
+        }
     } else {
         /* Send everything else to the next layer up. This includes
          * SS_PING/SS_NOP, which we _could_ handle here - but it's
@@ -1954,7 +1954,7 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
     old_max_data_size = s->max_data_size;
     ssh2_transport_set_max_data_size(s);
     if (old_max_data_size != s->max_data_size &&
-	s->max_data_size != 0) {
+        s->max_data_size != 0) {
         if (s->max_data_size < old_max_data_size) {
             unsigned long diff = old_max_data_size - s->max_data_size;
 
@@ -1972,19 +1972,19 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
     }
 
     if (conf_get_bool(s->conf, CONF_compression) !=
-	conf_get_bool(conf, CONF_compression)) {
+        conf_get_bool(conf, CONF_compression)) {
         rekey_reason = "compression setting changed";
         rekey_mandatory = true;
     }
 
     for (i = 0; i < CIPHER_MAX; i++)
-	if (conf_get_int_int(s->conf, CONF_ssh_cipherlist, i) !=
-	    conf_get_int_int(conf, CONF_ssh_cipherlist, i)) {
+        if (conf_get_int_int(s->conf, CONF_ssh_cipherlist, i) !=
+            conf_get_int_int(conf, CONF_ssh_cipherlist, i)) {
         rekey_reason = "cipher settings changed";
         rekey_mandatory = true;
     }
     if (conf_get_bool(s->conf, CONF_ssh2_des_cbc) !=
-	conf_get_bool(conf, CONF_ssh2_des_cbc)) {
+        conf_get_bool(conf, CONF_ssh2_des_cbc)) {
         rekey_reason = "cipher settings changed";
         rekey_mandatory = true;
     }

+ 27 - 27
source/putty/ssh2userauth.c

@@ -91,7 +91,7 @@ struct ssh2_userauth_state {
     PacketProtocolLayer ppl;
 };
 
-static void ssh2_userauth_free(PacketProtocolLayer *); 
+static void ssh2_userauth_free(PacketProtocolLayer *);
 static void ssh2_userauth_process_queue(PacketProtocolLayer *);
 static bool ssh2_userauth_get_specials(
     PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
@@ -378,16 +378,16 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
      * beginning to try another username, if this is configured on.
      * (If they specify a username in the config, they are never
      * asked, even if they do give a wrong password.)
-     * 
+     *
      * I think this best serves the needs of
-     * 
+     *
      *  - the people who have no configuration, no keys, and just
      *    want to try repeated (username,password) pairs until they
      *    type both correctly
-     * 
+     *
      *  - people who have keys and configuration but occasionally
      *    need to fall back to passwords
-     * 
+     *
      *  - people with a key held in Pageant, who might not have
      *    logged in to a particular machine before; so they want to
      *    type a username, and then _either_ their key will be
@@ -411,7 +411,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
             s->cur_prompt->to_server = true;
             s->cur_prompt->from_server = false;
             s->cur_prompt->name = dupstr("SSH login name");
-            add_prompt(s->cur_prompt, dupstr("login as: "), true); 
+            add_prompt(s->cur_prompt, dupstr("login as: "), true);
             s->userpass_ret = seat_get_userpass_input(
                 s->ppl.seat, s->cur_prompt, NULL);
             while (1) {
@@ -1221,7 +1221,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 put_stringz(s->pktout, "");     /* lang */
                 put_stringz(s->pktout, "");     /* submethods */
                 pq_push(s->ppl.out_pq, s->pktout);
-                
+
                 ppl_logevent("Attempting keyboard-interactive authentication");
 
                 if (!s->ki_scc_initialised) {
@@ -1532,7 +1532,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 while ((pktin->type == SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ) ||
                        s->change_password) { // WINSCP
 
-                    /* 
+                    /*
                      * We're being asked for a new password
                      * (perhaps not for the first time).
                      * Loop until the server accepts it.
@@ -1540,7 +1540,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
 
                     bool got_new = false; /* not live over crReturn */
                     ptrlen prompt;  /* not live over crReturn */
-                    
+
                     if (!s->change_password) // WINSCP
                     {
                         const char *msg;
@@ -1663,7 +1663,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     s->pktout->minlen = 256;
                     pq_push(s->ppl.out_pq, s->pktout);
                     ppl_logevent("Sent new password");
-                    
+
                     /*
                      * Now see what the server has to say about it.
                      * (If it's CHANGEREQ again, it's not happy with the
@@ -1795,42 +1795,42 @@ static void ssh2_userauth_add_sigblob(
     if ((s->ppl.remote_bugs & BUG_SSH2_RSA_PADDING) &&
         ptrlen_eq_string(get_string(pk), "ssh-rsa") &&
         ptrlen_eq_string(get_string(sig), "ssh-rsa")) {
-	ptrlen mod_mp, sig_mp;
+        ptrlen mod_mp, sig_mp;
         size_t sig_prefix_len;
 
-	/*
-	 * Find the modulus and signature integers.
-	 */
+        /*
+         * Find the modulus and signature integers.
+         */
         get_string(pk);                /* skip over exponent */
         mod_mp = get_string(pk);       /* remember modulus */
         sig_prefix_len = sig->pos;
-	sig_mp = get_string(sig);
+        sig_mp = get_string(sig);
         if (get_err(pk) || get_err(sig))
             goto give_up;
 
         /*
          * Find the byte length of the modulus, not counting leading
-	 * zeroes.
+         * zeroes.
          */
-	while (mod_mp.len > 0 && *(const char *)mod_mp.ptr == 0) {
+        while (mod_mp.len > 0 && *(const char *)mod_mp.ptr == 0) {
             mod_mp.len--;
             mod_mp.ptr = (const char *)mod_mp.ptr + 1;
         }
 
-	/* debug("modulus length is %d\n", len); */
-	/* debug("signature length is %d\n", siglen); */
+        /* debug("modulus length is %d\n", len); */
+        /* debug("signature length is %d\n", siglen); */
 
-	if (mod_mp.len != sig_mp.len) {
+        if (mod_mp.len != sig_mp.len) {
             strbuf *substr = strbuf_new();
-	    put_data(substr, sigblob.ptr, sig_prefix_len);
-	    put_uint32(substr, mod_mp.len);
-	    put_padding(substr, mod_mp.len - sig_mp.len, 0);
-	    put_datapl(substr, sig_mp);
+            put_data(substr, sigblob.ptr, sig_prefix_len);
+            put_uint32(substr, mod_mp.len);
+            put_padding(substr, mod_mp.len - sig_mp.len, 0);
+            put_datapl(substr, sig_mp);
             put_stringsb(pkt, substr);
-	    return;
-	}
+            return;
+        }
 
-	/* Otherwise fall through and do it the easy way. We also come
+        /* Otherwise fall through and do it the easy way. We also come
          * here as a fallback if we discover above that the key blob
          * is misformatted in some way. */
       give_up:;

+ 8 - 8
source/putty/sshaes.c

@@ -869,7 +869,7 @@ struct aes_sliced_key {
          * Prepare a word of round key in the low 4 bits of each
          * integer in slices[].
          */
-	if (i < key_words) {
+        if (i < key_words) {
             memcpy(inblk, key + 4*i, 4);
             TO_BITSLICES(slices, inblk, uint16_t, =, 0);
         } else {
@@ -918,7 +918,7 @@ struct aes_sliced_key {
             prevslices = sk->roundkeys_serial + 8 * (wordindex >> 2);
             for (size_t i = 0; i < 8; i++)
                 slices[i] ^= prevslices[i] >> bitshift;
-	}
+        }
 
         /*
          * Now copy it into sk.
@@ -1349,10 +1349,10 @@ static FUNC_ISA void aes_ni_key_expand(
     unsigned rconpos = 0;
 
     for (size_t i = 0; i < sched_words; i++) {
-	if (i < key_words) {
+        if (i < key_words) {
             sched[i] = GET_32BIT_LSB_FIRST(key + 4 * i);
         } else {
-	    uint32_t temp = sched[i - 1];
+            uint32_t temp = sched[i - 1];
 
             bool rotate_and_round_constant = (i % key_words == 0);
             bool only_sub = (key_words == 8 && i % 8 == 4);
@@ -1371,7 +1371,7 @@ static FUNC_ISA void aes_ni_key_expand(
             }
 
             sched[i] = sched[i - key_words] ^ temp;
-	}
+        }
     }
 
     /*
@@ -1668,10 +1668,10 @@ static FUNC_ISA void aes_neon_key_expand(
     unsigned rconpos = 0;
 
     for (size_t i = 0; i < sched_words; i++) {
-	if (i < key_words) {
+        if (i < key_words) {
             sched[i] = GET_32BIT_LSB_FIRST(key + 4 * i);
         } else {
-	    uint32_t temp = sched[i - 1];
+            uint32_t temp = sched[i - 1];
 
             bool rotate_and_round_constant = (i % key_words == 0);
             bool sub = rotate_and_round_constant ||
@@ -1694,7 +1694,7 @@ static FUNC_ISA void aes_neon_key_expand(
             }
 
             sched[i] = sched[i - key_words] ^ temp;
-	}
+        }
     }
 
     /*

+ 10 - 10
source/putty/ssharcf.c

@@ -22,16 +22,16 @@ static void arcfour_block(void *handle, void *vblk, int len)
     s = ctx->s;
     i = ctx->i; j = ctx->j;
     for (k = 0; (int)k < len; k++) {
-	i  = (i + 1) & 0xff;
-	j  = (j + s[i]) & 0xff;
-	tmp = s[i]; s[i] = s[j]; s[j] = tmp;
-	blk[k] ^= s[(s[i]+s[j]) & 0xff];
+        i  = (i + 1) & 0xff;
+        j  = (j + s[i]) & 0xff;
+        tmp = s[i]; s[i] = s[j]; s[j] = tmp;
+        blk[k] ^= s[(s[i]+s[j]) & 0xff];
     }
     ctx->i = i; ctx->j = j;
 }
 
 static void arcfour_setkey(ArcfourContext *ctx, unsigned char const *key,
-			   unsigned keybytes)
+                           unsigned keybytes)
 {
     unsigned char tmp, k[256], *s;
     unsigned i, j;
@@ -40,13 +40,13 @@ static void arcfour_setkey(ArcfourContext *ctx, unsigned char const *key,
     assert(keybytes <= 256);
     ctx->i = ctx->j = 0;
     for (i = 0; i < 256; i++) {
-	s[i] = i;
-	k[i] = key[i % keybytes];
+        s[i] = i;
+        k[i] = key[i % keybytes];
     }
     j = 0;
     for (i = 0; i < 256; i++) {
-	j = (j + s[i] + k[i]) & 0xff;
-	tmp = s[i]; s[i] = s[j]; s[j] = tmp;
+        j = (j + s[i] + k[i]) & 0xff;
+        tmp = s[i]; s[i] = s[j]; s[j] = tmp;
     }
 }
 
@@ -56,7 +56,7 @@ static void arcfour_setkey(ArcfourContext *ctx, unsigned char const *key,
  * We don't implement Arcfour in SSH-1 because it's utterly insecure in
  * several ways.  See CERT Vulnerability Notes VU#25309, VU#665372,
  * and VU#565052.
- * 
+ *
  * We don't implement the "arcfour" algorithm in SSH-2 because it doesn't
  * stir the cipher state before emitting keystream, and hence is likely
  * to leak data about the key.

+ 10 - 10
source/putty/sshauxcrypt.c

@@ -90,7 +90,7 @@ static ssh_cipher *des3_pubkey_ossh_cipher(const void *vkey, const void *viv)
 }
 
 void des3_decrypt_pubkey_ossh(const void *vkey, const void *viv,
-			      void *vblk, int len)
+                              void *vblk, int len)
 {
     ssh_cipher *c = des3_pubkey_ossh_cipher(vkey, viv);
     ssh_cipher_decrypt(c, vblk, len);
@@ -98,7 +98,7 @@ void des3_decrypt_pubkey_ossh(const void *vkey, const void *viv,
 }
 
 void des3_encrypt_pubkey_ossh(const void *vkey, const void *viv,
-			      void *vblk, int len)
+                              void *vblk, int len)
 {
     ssh_cipher *c = des3_pubkey_ossh_cipher(vkey, viv);
     ssh_cipher_encrypt(c, vblk, len);
@@ -121,14 +121,14 @@ static ssh_cipher *des_xdmauth_cipher(const void *vkeydata)
     nbits = 0;
     j = 0;
     for (i = 0; i < 8; i++) {
-	if (nbits < 7) {
-	    bits = (bits << 8) | keydata[j];
-	    nbits += 8;
-	    j++;
-	}
-	key[i] = (bits >> (nbits - 7)) << 1;
-	bits &= ~(0x7F << (nbits - 7));
-	nbits -= 7;
+        if (nbits < 7) {
+            bits = (bits << 8) | keydata[j];
+            nbits += 8;
+            j++;
+        }
+        key[i] = (bits >> (nbits - 7)) << 1;
+        bits &= ~(0x7F << (nbits - 7));
+        nbits -= 7;
     }
 
     { // WINSCP

+ 94 - 94
source/putty/sshblowf.c

@@ -11,7 +11,7 @@
 
 struct BlowfishContext {
     uint32_t S0[256], S1[256], S2[256], S3[256], P[18];
-    uint32_t iv0, iv1;		       /* for CBC mode */
+    uint32_t iv0, iv1;                 /* for CBC mode */
 };
 
 /*
@@ -234,7 +234,7 @@ static const uint32_t sbox3[] = {
 #define ROUND(n) ( xL ^= P[n], t = xL, xL = F(xL) ^ xR, xR = t )
 
 static void blowfish_encrypt(uint32_t xL, uint32_t xR, uint32_t *output,
-			     BlowfishContext * ctx)
+                             BlowfishContext * ctx)
 {
     uint32_t *S0 = ctx->S0;
     uint32_t *S1 = ctx->S1;
@@ -267,7 +267,7 @@ static void blowfish_encrypt(uint32_t xL, uint32_t xR, uint32_t *output,
 }
 
 static void blowfish_decrypt(uint32_t xL, uint32_t xR, uint32_t *output,
-			     BlowfishContext * ctx)
+                             BlowfishContext * ctx)
 {
     uint32_t *S0 = ctx->S0;
     uint32_t *S1 = ctx->S1;
@@ -310,17 +310,17 @@ static void blowfish_lsb_encrypt_cbc(unsigned char *blk, int len,
     iv1 = ctx->iv1;
 
     while (len > 0) {
-	xL = GET_32BIT_LSB_FIRST(blk);
-	xR = GET_32BIT_LSB_FIRST(blk + 4);
-	iv0 ^= xL;
-	iv1 ^= xR;
-	blowfish_encrypt(iv0, iv1, out, ctx);
-	iv0 = out[0];
-	iv1 = out[1];
-	PUT_32BIT_LSB_FIRST(blk, iv0);
-	PUT_32BIT_LSB_FIRST(blk + 4, iv1);
-	blk += 8;
-	len -= 8;
+        xL = GET_32BIT_LSB_FIRST(blk);
+        xR = GET_32BIT_LSB_FIRST(blk + 4);
+        iv0 ^= xL;
+        iv1 ^= xR;
+        blowfish_encrypt(iv0, iv1, out, ctx);
+        iv0 = out[0];
+        iv1 = out[1];
+        PUT_32BIT_LSB_FIRST(blk, iv0);
+        PUT_32BIT_LSB_FIRST(blk + 4, iv1);
+        blk += 8;
+        len -= 8;
     }
 
     ctx->iv0 = iv0;
@@ -335,18 +335,18 @@ void blowfish_lsb_encrypt_ecb(void *vblk, int len, BlowfishContext * ctx)
     assert((len & 7) == 0);
 
     while (len > 0) {
-	xL = GET_32BIT_LSB_FIRST(blk);
-	xR = GET_32BIT_LSB_FIRST(blk + 4);
-	blowfish_encrypt(xL, xR, out, ctx);
-	PUT_32BIT_LSB_FIRST(blk, out[0]);
-	PUT_32BIT_LSB_FIRST(blk + 4, out[1]);
-	blk += 8;
-	len -= 8;
+        xL = GET_32BIT_LSB_FIRST(blk);
+        xR = GET_32BIT_LSB_FIRST(blk + 4);
+        blowfish_encrypt(xL, xR, out, ctx);
+        PUT_32BIT_LSB_FIRST(blk, out[0]);
+        PUT_32BIT_LSB_FIRST(blk + 4, out[1]);
+        blk += 8;
+        len -= 8;
     }
 }
 
 static void blowfish_lsb_decrypt_cbc(unsigned char *blk, int len,
-				     BlowfishContext * ctx)
+                                     BlowfishContext * ctx)
 {
     uint32_t xL, xR, out[2], iv0, iv1;
 
@@ -356,17 +356,17 @@ static void blowfish_lsb_decrypt_cbc(unsigned char *blk, int len,
     iv1 = ctx->iv1;
 
     while (len > 0) {
-	xL = GET_32BIT_LSB_FIRST(blk);
-	xR = GET_32BIT_LSB_FIRST(blk + 4);
-	blowfish_decrypt(xL, xR, out, ctx);
-	iv0 ^= out[0];
-	iv1 ^= out[1];
-	PUT_32BIT_LSB_FIRST(blk, iv0);
-	PUT_32BIT_LSB_FIRST(blk + 4, iv1);
-	iv0 = xL;
-	iv1 = xR;
-	blk += 8;
-	len -= 8;
+        xL = GET_32BIT_LSB_FIRST(blk);
+        xR = GET_32BIT_LSB_FIRST(blk + 4);
+        blowfish_decrypt(xL, xR, out, ctx);
+        iv0 ^= out[0];
+        iv1 ^= out[1];
+        PUT_32BIT_LSB_FIRST(blk, iv0);
+        PUT_32BIT_LSB_FIRST(blk + 4, iv1);
+        iv0 = xL;
+        iv1 = xR;
+        blk += 8;
+        len -= 8;
     }
 
     ctx->iv0 = iv0;
@@ -374,7 +374,7 @@ static void blowfish_lsb_decrypt_cbc(unsigned char *blk, int len,
 }
 
 static void blowfish_msb_encrypt_cbc(unsigned char *blk, int len,
-				     BlowfishContext * ctx)
+                                     BlowfishContext * ctx)
 {
     uint32_t xL, xR, out[2], iv0, iv1;
 
@@ -384,17 +384,17 @@ static void blowfish_msb_encrypt_cbc(unsigned char *blk, int len,
     iv1 = ctx->iv1;
 
     while (len > 0) {
-	xL = GET_32BIT_MSB_FIRST(blk);
-	xR = GET_32BIT_MSB_FIRST(blk + 4);
-	iv0 ^= xL;
-	iv1 ^= xR;
-	blowfish_encrypt(iv0, iv1, out, ctx);
-	iv0 = out[0];
-	iv1 = out[1];
-	PUT_32BIT_MSB_FIRST(blk, iv0);
-	PUT_32BIT_MSB_FIRST(blk + 4, iv1);
-	blk += 8;
-	len -= 8;
+        xL = GET_32BIT_MSB_FIRST(blk);
+        xR = GET_32BIT_MSB_FIRST(blk + 4);
+        iv0 ^= xL;
+        iv1 ^= xR;
+        blowfish_encrypt(iv0, iv1, out, ctx);
+        iv0 = out[0];
+        iv1 = out[1];
+        PUT_32BIT_MSB_FIRST(blk, iv0);
+        PUT_32BIT_MSB_FIRST(blk + 4, iv1);
+        blk += 8;
+        len -= 8;
     }
 
     ctx->iv0 = iv0;
@@ -402,7 +402,7 @@ static void blowfish_msb_encrypt_cbc(unsigned char *blk, int len,
 }
 
 static void blowfish_msb_decrypt_cbc(unsigned char *blk, int len,
-				     BlowfishContext * ctx)
+                                     BlowfishContext * ctx)
 {
     uint32_t xL, xR, out[2], iv0, iv1;
 
@@ -412,17 +412,17 @@ static void blowfish_msb_decrypt_cbc(unsigned char *blk, int len,
     iv1 = ctx->iv1;
 
     while (len > 0) {
-	xL = GET_32BIT_MSB_FIRST(blk);
-	xR = GET_32BIT_MSB_FIRST(blk + 4);
-	blowfish_decrypt(xL, xR, out, ctx);
-	iv0 ^= out[0];
-	iv1 ^= out[1];
-	PUT_32BIT_MSB_FIRST(blk, iv0);
-	PUT_32BIT_MSB_FIRST(blk + 4, iv1);
-	iv0 = xL;
-	iv1 = xR;
-	blk += 8;
-	len -= 8;
+        xL = GET_32BIT_MSB_FIRST(blk);
+        xR = GET_32BIT_MSB_FIRST(blk + 4);
+        blowfish_decrypt(xL, xR, out, ctx);
+        iv0 ^= out[0];
+        iv1 ^= out[1];
+        PUT_32BIT_MSB_FIRST(blk, iv0);
+        PUT_32BIT_MSB_FIRST(blk + 4, iv1);
+        iv0 = xL;
+        iv1 = xR;
+        blk += 8;
+        len -= 8;
     }
 
     ctx->iv0 = iv0;
@@ -430,7 +430,7 @@ static void blowfish_msb_decrypt_cbc(unsigned char *blk, int len,
 }
 
 static void blowfish_msb_sdctr(unsigned char *blk, int len,
-				     BlowfishContext * ctx)
+                                     BlowfishContext * ctx)
 {
     uint32_t b[2], iv0, iv1, tmp;
 
@@ -440,15 +440,15 @@ static void blowfish_msb_sdctr(unsigned char *blk, int len,
     iv1 = ctx->iv1;
 
     while (len > 0) {
-	blowfish_encrypt(iv0, iv1, b, ctx);
-	tmp = GET_32BIT_MSB_FIRST(blk);
-	PUT_32BIT_MSB_FIRST(blk, tmp ^ b[0]);
-	tmp = GET_32BIT_MSB_FIRST(blk + 4);
-	PUT_32BIT_MSB_FIRST(blk + 4, tmp ^ b[1]);
-	if ((iv1 = (iv1 + 1) & 0xffffffff) == 0)
-	    iv0 = (iv0 + 1) & 0xffffffff;
-	blk += 8;
-	len -= 8;
+        blowfish_encrypt(iv0, iv1, b, ctx);
+        tmp = GET_32BIT_MSB_FIRST(blk);
+        PUT_32BIT_MSB_FIRST(blk, tmp ^ b[0]);
+        tmp = GET_32BIT_MSB_FIRST(blk + 4);
+        PUT_32BIT_MSB_FIRST(blk + 4, tmp ^ b[1]);
+        if ((iv1 = (iv1 + 1) & 0xffffffff) == 0)
+            iv0 = (iv0 + 1) & 0xffffffff;
+        blk += 8;
+        len -= 8;
     }
 
     ctx->iv0 = iv0;
@@ -460,14 +460,14 @@ void blowfish_initkey(BlowfishContext *ctx)
     int i;
 
     for (i = 0; i < 18; i++) {
-	ctx->P[i] = parray[i];
+        ctx->P[i] = parray[i];
     }
 
     for (i = 0; i < 256; i++) {
-	ctx->S0[i] = sbox0[i];
-	ctx->S1[i] = sbox1[i];
-	ctx->S2[i] = sbox2[i];
-	ctx->S3[i] = sbox3[i];
+        ctx->S0[i] = sbox0[i];
+        ctx->S1[i] = sbox1[i];
+        ctx->S2[i] = sbox2[i];
+        ctx->S3[i] = sbox3[i];
     }
 }
 
@@ -495,13 +495,13 @@ void blowfish_expandkey(BlowfishContext * ctx,
     }
 
     for (i = 0; i < 18; i++) {
-	P[i] ^=
-	    ((uint32_t) (unsigned char) (key[(i * 4 + 0) % keybytes])) << 24;
-	P[i] ^=
-	    ((uint32_t) (unsigned char) (key[(i * 4 + 1) % keybytes])) << 16;
-	P[i] ^=
-	    ((uint32_t) (unsigned char) (key[(i * 4 + 2) % keybytes])) << 8;
-	P[i] ^= ((uint32_t) (unsigned char) (key[(i * 4 + 3) % keybytes]));
+        P[i] ^=
+            ((uint32_t) (unsigned char) (key[(i * 4 + 0) % keybytes])) << 24;
+        P[i] ^=
+            ((uint32_t) (unsigned char) (key[(i * 4 + 1) % keybytes])) << 16;
+        P[i] ^=
+            ((uint32_t) (unsigned char) (key[(i * 4 + 2) % keybytes])) << 8;
+        P[i] ^= ((uint32_t) (unsigned char) (key[(i * 4 + 3) % keybytes]));
     }
 
     str[0] = str[1] = 0;
@@ -510,38 +510,38 @@ void blowfish_expandkey(BlowfishContext * ctx,
         for (j = 0; j < 8; j++)
             str[j/4] ^= ((uint32_t)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
 
-	blowfish_encrypt(str[0], str[1], str, ctx);
-	P[i] = str[0];
-	P[i + 1] = str[1];
+        blowfish_encrypt(str[0], str[1], str, ctx);
+        P[i] = str[0];
+        P[i + 1] = str[1];
     }
 
     for (i = 0; i < 256; i += 2) {
         for (j = 0; j < 8; j++)
             str[j/4] ^= ((uint32_t)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
-	blowfish_encrypt(str[0], str[1], str, ctx);
-	S0[i] = str[0];
-	S0[i + 1] = str[1];
+        blowfish_encrypt(str[0], str[1], str, ctx);
+        S0[i] = str[0];
+        S0[i + 1] = str[1];
     }
     for (i = 0; i < 256; i += 2) {
         for (j = 0; j < 8; j++)
             str[j/4] ^= ((uint32_t)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
-	blowfish_encrypt(str[0], str[1], str, ctx);
-	S1[i] = str[0];
-	S1[i + 1] = str[1];
+        blowfish_encrypt(str[0], str[1], str, ctx);
+        S1[i] = str[0];
+        S1[i + 1] = str[1];
     }
     for (i = 0; i < 256; i += 2) {
         for (j = 0; j < 8; j++)
             str[j/4] ^= ((uint32_t)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
-	blowfish_encrypt(str[0], str[1], str, ctx);
-	S2[i] = str[0];
-	S2[i + 1] = str[1];
+        blowfish_encrypt(str[0], str[1], str, ctx);
+        S2[i] = str[0];
+        S2[i + 1] = str[1];
     }
     for (i = 0; i < 256; i += 2) {
         for (j = 0; j < 8; j++)
             str[j/4] ^= ((uint32_t)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
-	blowfish_encrypt(str[0], str[1], str, ctx);
-	S3[i] = str[0];
-	S3[i + 1] = str[1];
+        blowfish_encrypt(str[0], str[1], str, ctx);
+        S3[i] = str[0];
+        S3[i + 1] = str[1];
     }
 }
 

+ 1 - 1
source/putty/sshbpp.h

@@ -6,7 +6,7 @@
 #define PUTTY_SSHBPP_H
 
 struct BinaryPacketProtocolVtable {
-    void (*free)(BinaryPacketProtocol *); 
+    void (*free)(BinaryPacketProtocol *);
     void (*handle_input)(BinaryPacketProtocol *);
     void (*handle_output)(BinaryPacketProtocol *);
     PktOut *(*new_pktout)(int type);

+ 4 - 4
source/putty/sshcr.h

@@ -8,16 +8,16 @@
 /*
  * If these macros look impenetrable to you, you might find it helpful
  * to read
- * 
+ *
  *   https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
- * 
+ *
  * which explains the theory behind these macros.
- * 
+ *
  * In particular, if you are getting `case expression not constant'
  * errors when building with MS Visual Studio, this is because MS's
  * Edit and Continue debugging feature causes their compiler to
  * violate ANSI C. To disable Edit and Continue debugging:
- * 
+ *
  *  - right-click ssh.c in the FileView
  *  - click Settings
  *  - select the C/C++ tab and the General category

+ 16 - 16
source/putty/sshcrcda.c

@@ -1,4 +1,4 @@
-/*	$OpenBSD: deattack.c,v 1.14 2001/06/23 15:12:18 itojun Exp $	*/
+/*      $OpenBSD: deattack.c,v 1.14 2001/06/23 15:12:18 itojun Exp $    */
 
 /*
  * Cryptographic attack detector for ssh - source code
@@ -17,7 +17,7 @@
  *
  * Ariel Futoransky <[email protected]>
  * <http://www.core-sdi.com>
- * 
+ *
  * Modified for use in PuTTY by Simon Tatham
  */
 
@@ -26,23 +26,23 @@
 #include "ssh.h"
 
 /* SSH Constants */
-#define SSH_MAXBLOCKS	(32 * 1024)
-#define SSH_BLOCKSIZE	(8)
+#define SSH_MAXBLOCKS   (32 * 1024)
+#define SSH_BLOCKSIZE   (8)
 
 /* Hashing constants */
-#define HASH_MINSIZE	(8 * 1024)
-#define HASH_ENTRYSIZE	(sizeof(uint16_t))
-#define HASH_FACTOR(x)	((x)*3/2)
-#define HASH_UNUSEDCHAR	(0xff)
-#define HASH_UNUSED	(0xffff)
-#define HASH_IV     	(0xfffe)
+#define HASH_MINSIZE    (8 * 1024)
+#define HASH_ENTRYSIZE  (sizeof(uint16_t))
+#define HASH_FACTOR(x)  ((x)*3/2)
+#define HASH_UNUSEDCHAR (0xff)
+#define HASH_UNUSED     (0xffff)
+#define HASH_IV         (0xfffe)
 
-#define HASH_MINBLOCKS	(7*SSH_BLOCKSIZE)
+#define HASH_MINBLOCKS  (7*SSH_BLOCKSIZE)
 
 /* Hash function (Input keys are cipher results) */
-#define HASH(x)		GET_32BIT_MSB_FIRST(x)
+#define HASH(x)         GET_32BIT_MSB_FIRST(x)
 
-#define CMP(a, b)	(memcmp(a, b, SSH_BLOCKSIZE))
+#define CMP(a, b)       (memcmp(a, b, SSH_BLOCKSIZE))
 
 #ifdef MPEXT
 static
@@ -69,9 +69,9 @@ struct crcda_ctx *crcda_make_context(void)
 void crcda_free_context(struct crcda_ctx *ctx)
 {
     if (ctx) {
-	sfree(ctx->h);
-	ctx->h = NULL;
-	sfree(ctx);
+        sfree(ctx->h);
+        ctx->h = NULL;
+        sfree(ctx);
     }
 }
 

+ 1 - 1
source/putty/sshdes.c

@@ -591,7 +591,7 @@ static inline LR des_round(LR in, const des_keysched *sched, size_t round)
 
 static inline LR des_inner_cipher(LR lr, const des_keysched *sched,
                                   size_t start, size_t step)
-{ 
+{
     lr = des_round(lr, sched, start+0x0*step);
     lr = des_round(lr, sched, start+0x1*step);
     lr = des_round(lr, sched, start+0x2*step);

+ 2 - 2
source/putty/sshdh.c

@@ -194,13 +194,13 @@ void dh_cleanup(dh_ctx *ctx)
 /*
  * DH stage 1: invent a number x between 1 and q, and compute e =
  * g^x mod p. Return e.
- * 
+ *
  * If `nbits' is greater than zero, it is used as an upper limit
  * for the number of bits in x. This is safe provided that (a) you
  * use twice as many bits in x as the number of bits you expect to
  * use in your session key, and (b) the DH group is a safe prime
  * (which SSH demands that it must be).
- * 
+ *
  * P. C. van Oorschot, M. J. Wiener
  * "On Diffie-Hellman Key Agreement with Short Exponents".
  * Advances in Cryptology: Proceedings of Eurocrypt '96

+ 31 - 31
source/putty/sshdss.c

@@ -19,7 +19,7 @@ static ssh_key *dss_new_pub(const ssh_keyalg *self, ptrlen data)
 
     BinarySource_BARE_INIT_PL(src, data);
     if (!ptrlen_eq_string(get_string(src), "ssh-dss"))
-	return NULL;
+        return NULL;
 
     dss = snew(struct dss_key);
     dss->sshk.vt = &ssh_dss;
@@ -75,7 +75,7 @@ static char *dss_cache_str(ssh_key *key)
     strbuf *sb = strbuf_new();
 
     if (!dss->p)
-	return NULL;
+        return NULL;
 
     append_hex_to_strbuf(sb, dss->p);
     append_hex_to_strbuf(sb, dss->q);
@@ -99,7 +99,7 @@ static bool dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
     bool toret;
 
     if (!dss->p)
-	return false;
+        return false;
 
     BinarySource_BARE_INIT_PL(src, sig);
 
@@ -115,7 +115,7 @@ static bool dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
      * else is assumed to be RFC-compliant.
      */
     if (sig.len != 40) {      /* bug not present; read admin fields */
-	ptrlen type = get_string(src);
+        ptrlen type = get_string(src);
         sig = get_string(src);
 
         if (get_err(src) || !ptrlen_eq_string(type, "ssh-dss") ||
@@ -132,7 +132,7 @@ static bool dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
             mp_free(r);
         if (s)
             mp_free(s);
-	return false;
+        return false;
     }
 
     /* Basic sanity checks: 0 < r,s < q */
@@ -248,15 +248,15 @@ static ssh_key *dss_new_priv(const ssh_keyalg *self, ptrlen pub, ptrlen priv)
      */
     hash = get_string(src);
     if (hash.len == 20) {
-	ssh_hash *h = ssh_hash_new(&ssh_sha1);
-	put_mp_ssh2(h, dss->p);
-	put_mp_ssh2(h, dss->q);
-	put_mp_ssh2(h, dss->g);
-	ssh_hash_final(h, digest);
-	if (!smemeq(hash.ptr, digest, 20)) {
-	    dss_freekey(&dss->sshk);
-	    return NULL;
-	}
+        ssh_hash *h = ssh_hash_new(&ssh_sha1);
+        put_mp_ssh2(h, dss->p);
+        put_mp_ssh2(h, dss->q);
+        put_mp_ssh2(h, dss->g);
+        ssh_hash_final(h, digest);
+        if (!smemeq(hash.ptr, digest, 20)) {
+            dss_freekey(&dss->sshk);
+            return NULL;
+        }
     }
 
     /*
@@ -265,8 +265,8 @@ static ssh_key *dss_new_priv(const ssh_keyalg *self, ptrlen pub, ptrlen priv)
     ytest = mp_modpow(dss->g, dss->x, dss->p);
     if (!mp_cmp_eq(ytest, dss->y)) {
         mp_free(ytest);
-	dss_freekey(&dss->sshk);
-	return NULL;
+        dss_freekey(&dss->sshk);
+        return NULL;
     }
     mp_free(ytest);
 
@@ -331,59 +331,59 @@ mp_int *dss_gen_k(const char *id_string, mp_int *modulus,
 {
     /*
      * The basic DSS signing algorithm is:
-     * 
+     *
      *  - invent a random k between 1 and q-1 (exclusive).
      *  - Compute r = (g^k mod p) mod q.
      *  - Compute s = k^-1 * (hash + x*r) mod q.
-     * 
+     *
      * This has the dangerous properties that:
-     * 
+     *
      *  - if an attacker in possession of the public key _and_ the
      *    signature (for example, the host you just authenticated
      *    to) can guess your k, he can reverse the computation of s
      *    and work out x = r^-1 * (s*k - hash) mod q. That is, he
      *    can deduce the private half of your key, and masquerade
      *    as you for as long as the key is still valid.
-     * 
+     *
      *  - since r is a function purely of k and the public key, if
      *    the attacker only has a _range of possibilities_ for k
      *    it's easy for him to work through them all and check each
      *    one against r; he'll never be unsure of whether he's got
      *    the right one.
-     * 
+     *
      *  - if you ever sign two different hashes with the same k, it
      *    will be immediately obvious because the two signatures
      *    will have the same r, and moreover an attacker in
      *    possession of both signatures (and the public key of
      *    course) can compute k = (hash1-hash2) * (s1-s2)^-1 mod q,
      *    and from there deduce x as before.
-     * 
+     *
      *  - the Bleichenbacher attack on DSA makes use of methods of
      *    generating k which are significantly non-uniformly
      *    distributed; in particular, generating a 160-bit random
      *    number and reducing it mod q is right out.
-     * 
+     *
      * For this reason we must be pretty careful about how we
      * generate our k. Since this code runs on Windows, with no
      * particularly good system entropy sources, we can't trust our
      * RNG itself to produce properly unpredictable data. Hence, we
      * use a totally different scheme instead.
-     * 
+     *
      * What we do is to take a SHA-512 (_big_) hash of the private
      * key x, and then feed this into another SHA-512 hash that
      * also includes the message hash being signed. That is:
-     * 
+     *
      *   proto_k = SHA512 ( SHA512(x) || SHA160(message) )
-     * 
+     *
      * This number is 512 bits long, so reducing it mod q won't be
      * noticeably non-uniform. So
-     * 
+     *
      *   k = proto_k mod q
-     * 
+     *
      * This has the interesting property that it's _deterministic_:
      * signing the same hash twice with the same key yields the
      * same signature.
-     * 
+     *
      * Despite this determinism, it's still not predictable to an
      * attacker, because in order to repeat the SHA-512
      * construction that created it, the attacker would have to
@@ -394,7 +394,7 @@ mp_int *dss_gen_k(const char *id_string, mp_int *modulus,
      * Reuse of k is left to chance; all it does is prevent
      * _excessively high_ chances of reuse of k due to entropy
      * problems.)
-     * 
+     *
      * Thanks to Colin Plumb for the general idea of using x to
      * ensure k is hard to guess, and to the Cambridge University
      * Computer Security Group for helping to argue out all the
@@ -475,7 +475,7 @@ static void dss_sign(ssh_key *key, ptrlen data, unsigned flags, BinarySink *bs)
     put_stringz(bs, "ssh-dss");
     put_uint32(bs, 40);
     for (i = 0; i < 20; i++)
-	put_byte(bs, mp_get_byte(r, 19 - i));
+        put_byte(bs, mp_get_byte(r, 19 - i));
     for (i = 0; i < 20; i++)
         put_byte(bs, mp_get_byte(s, 19 - i));
     mp_free(r);

+ 19 - 19
source/putty/sshgss.h

@@ -20,9 +20,9 @@ typedef enum Ssh_gss_stat {
 
 #define SSH_GSS_S_COMPLETE SSH_GSS_OK
 
-#define SSH_GSS_CLEAR_BUF(buf) do {		\
-    (*buf).length = 0;				\
-    (*buf).value = NULL;				\
+#define SSH_GSS_CLEAR_BUF(buf) do {             \
+    (*buf).length = 0;                          \
+    (*buf).value = NULL;                                \
 } while (0)
 
 typedef gss_buffer_desc Ssh_gss_buf;
@@ -30,7 +30,7 @@ typedef gss_name_t Ssh_gss_name;
 
 #define GSS_NO_EXPIRATION ((time_t)-1)
 
-#define GSS_DEF_REKEY_MINS 2	/* Default minutes between GSS cache checks */
+#define GSS_DEF_REKEY_MINS 2    /* Default minutes between GSS cache checks */
 
 /* Functions, provided by either wingss.c or sshgssc.c */
 
@@ -61,7 +61,7 @@ void ssh_gss_cleanup(struct ssh_gss_liblist *list);
  * use. buf->data is not dynamically allocated.
  */
 typedef Ssh_gss_stat (*t_ssh_gss_indicate_mech)(struct ssh_gss_library *lib,
-						Ssh_gss_buf *buf);
+                                                Ssh_gss_buf *buf);
 
 /*
  * Converts a name such as a hostname into a GSSAPI internal form,
@@ -69,14 +69,14 @@ typedef Ssh_gss_stat (*t_ssh_gss_indicate_mech)(struct ssh_gss_library *lib,
  * ssh_gss_release_name().
  */
 typedef Ssh_gss_stat (*t_ssh_gss_import_name)(struct ssh_gss_library *lib,
-					      char *in, Ssh_gss_name *out);
+                                              char *in, Ssh_gss_name *out);
 
 /*
  * Frees the contents of an Ssh_gss_name structure filled in by
  * ssh_gss_import_name().
  */
 typedef Ssh_gss_stat (*t_ssh_gss_release_name)(struct ssh_gss_library *lib,
-					       Ssh_gss_name *name);
+                                               Ssh_gss_name *name);
 
 /*
  * The main GSSAPI security context setup function. The "out"
@@ -96,7 +96,7 @@ typedef Ssh_gss_stat (*t_ssh_gss_init_sec_context)
  * way.
  */
 typedef Ssh_gss_stat (*t_ssh_gss_free_tok)(struct ssh_gss_library *lib,
-					   Ssh_gss_buf *);
+                                           Ssh_gss_buf *);
 
 /*
  * Acquires the credentials to perform authentication in the first
@@ -111,14 +111,14 @@ typedef Ssh_gss_stat (*t_ssh_gss_acquire_cred)(struct ssh_gss_library *lib,
  * ssh_gss_acquire_cred().
  */
 typedef Ssh_gss_stat (*t_ssh_gss_release_cred)(struct ssh_gss_library *lib,
-					       Ssh_gss_ctx *);
+                                               Ssh_gss_ctx *);
 
 /*
  * Gets a MIC for some input data. "out" needs to be freed by
  * ssh_gss_free_mic().
  */
 typedef Ssh_gss_stat (*t_ssh_gss_get_mic)(struct ssh_gss_library *lib,
-					  Ssh_gss_ctx ctx, Ssh_gss_buf *in,
+                                          Ssh_gss_ctx ctx, Ssh_gss_buf *in,
                                           Ssh_gss_buf *out);
 
 /*
@@ -137,17 +137,17 @@ typedef Ssh_gss_stat (*t_ssh_gss_verify_mic)(struct ssh_gss_library *lib,
  * way.
  */
 typedef Ssh_gss_stat (*t_ssh_gss_free_mic)(struct ssh_gss_library *lib,
-					   Ssh_gss_buf *);
+                                           Ssh_gss_buf *);
 
 /*
  * Return an error message after authentication failed. The
  * message string is returned in "buf", with buf->len giving the
  * number of characters of printable message text and buf->data
  * containing one more character which is a trailing NUL.
- * buf->data should be manually freed by the caller. 
+ * buf->data should be manually freed by the caller.
  */
 typedef Ssh_gss_stat (*t_ssh_gss_display_status)(struct ssh_gss_library *lib,
-						 Ssh_gss_ctx, Ssh_gss_buf *buf);
+                                                 Ssh_gss_ctx, Ssh_gss_buf *buf);
 
 struct ssh_gss_library {
     /*
@@ -185,12 +185,12 @@ struct ssh_gss_library {
      * Additional data for the wrapper layers.
      */
     union {
-	struct gssapi_functions gssapi;
-	/*
-	 * The SSPI wrappers don't need to store their Windows API
-	 * function pointers in this structure, because there can't
-	 * be more than one set of them available.
-	 */
+        struct gssapi_functions gssapi;
+        /*
+         * The SSPI wrappers don't need to store their Windows API
+         * function pointers in this structure, because there can't
+         * be more than one set of them available.
+         */
     } u;
 
     /*

+ 28 - 28
source/putty/sshgssc.c

@@ -8,7 +8,7 @@
 #ifndef NO_GSSAPI
 
 static Ssh_gss_stat ssh_gssapi_indicate_mech(struct ssh_gss_library *lib,
-					     Ssh_gss_buf *mech)
+                                             Ssh_gss_buf *mech)
 {
     /* Copy constant into mech */
     mech->length  = GSS_MECH_KRB5->length;
@@ -17,8 +17,8 @@ static Ssh_gss_stat ssh_gssapi_indicate_mech(struct ssh_gss_library *lib,
 }
 
 static Ssh_gss_stat ssh_gssapi_import_name(struct ssh_gss_library *lib,
-					   char *host,
-					   Ssh_gss_name *srv_name)
+                                           char *host,
+                                           Ssh_gss_name *srv_name)
 {
     struct gssapi_functions *gss = &lib->u.gssapi;
     OM_uint32 min_stat,maj_stat;
@@ -31,7 +31,7 @@ static Ssh_gss_stat ssh_gssapi_import_name(struct ssh_gss_library *lib,
     host_buf.length = strlen(pStr);
 
     maj_stat = gss->import_name(&min_stat, &host_buf,
-				GSS_C_NT_HOSTBASED_SERVICE, srv_name);
+                                GSS_C_NT_HOSTBASED_SERVICE, srv_name);
     /* Release buffer */
     sfree(pStr);
     if (maj_stat == GSS_S_COMPLETE) return SSH_GSS_OK;
@@ -110,10 +110,10 @@ static Ssh_gss_stat ssh_gssapi_acquire_cred(struct ssh_gss_library *lib,
 }
 
 static Ssh_gss_stat ssh_gssapi_init_sec_context(struct ssh_gss_library *lib,
-						Ssh_gss_ctx *ctx,
-						Ssh_gss_name srv_name,
-						int to_deleg,
-						Ssh_gss_buf *recv_tok,
+                                                Ssh_gss_ctx *ctx,
+                                                Ssh_gss_name srv_name,
+                                                int to_deleg,
+                                                Ssh_gss_buf *recv_tok,
                                                 Ssh_gss_buf *send_tok,
                                                 time_t *expiry,
                                                 unsigned long *lifetime)
@@ -125,18 +125,18 @@ static Ssh_gss_stat ssh_gssapi_init_sec_context(struct ssh_gss_library *lib,
 
     if (to_deleg) to_deleg = GSS_C_DELEG_FLAG;
     gssctx->maj_stat = gss->init_sec_context(&gssctx->min_stat,
-					     GSS_C_NO_CREDENTIAL,
-					     &gssctx->ctx,
-					     srv_name,
-					     (gss_OID) GSS_MECH_KRB5,
-					     GSS_C_MUTUAL_FLAG |
-					     GSS_C_INTEG_FLAG | to_deleg,
-					     0,
-					     GSS_C_NO_CHANNEL_BINDINGS,
-					     recv_tok,
-					     NULL,   /* ignore mech type */
-					     send_tok,
-					     &ret_flags,
+                                             GSS_C_NO_CREDENTIAL,
+                                             &gssctx->ctx,
+                                             srv_name,
+                                             (gss_OID) GSS_MECH_KRB5,
+                                             GSS_C_MUTUAL_FLAG |
+                                             GSS_C_INTEG_FLAG | to_deleg,
+                                             0,
+                                             GSS_C_NO_CHANNEL_BINDINGS,
+                                             recv_tok,
+                                             NULL,   /* ignore mech type */
+                                             send_tok,
+                                             &ret_flags,
                                              &lifetime_rec);
 
     if (lifetime) {
@@ -158,8 +158,8 @@ static Ssh_gss_stat ssh_gssapi_init_sec_context(struct ssh_gss_library *lib,
 }
 
 static Ssh_gss_stat ssh_gssapi_display_status(struct ssh_gss_library *lib,
-					      Ssh_gss_ctx ctx,
-					      Ssh_gss_buf *buf)
+                                              Ssh_gss_ctx ctx,
+                                              Ssh_gss_buf *buf)
 {
     struct gssapi_functions *gss = &lib->u.gssapi;
     gssapi_ssh_gss_ctx *gssctx = (gssapi_ssh_gss_ctx *) ctx;
@@ -202,7 +202,7 @@ static Ssh_gss_stat ssh_gssapi_display_status(struct ssh_gss_library *lib,
 }
 
 static Ssh_gss_stat ssh_gssapi_free_tok(struct ssh_gss_library *lib,
-					Ssh_gss_buf *send_tok)
+                                        Ssh_gss_buf *send_tok)
 {
     struct gssapi_functions *gss = &lib->u.gssapi;
     OM_uint32 min_stat,maj_stat;
@@ -213,7 +213,7 @@ static Ssh_gss_stat ssh_gssapi_free_tok(struct ssh_gss_library *lib,
 }
 
 static Ssh_gss_stat ssh_gssapi_release_cred(struct ssh_gss_library *lib,
-					    Ssh_gss_ctx *ctx)
+                                            Ssh_gss_ctx *ctx)
 {
     struct gssapi_functions *gss = &lib->u.gssapi;
     gssapi_ssh_gss_ctx *gssctx = (gssapi_ssh_gss_ctx *) *ctx;
@@ -232,7 +232,7 @@ static Ssh_gss_stat ssh_gssapi_release_cred(struct ssh_gss_library *lib,
 
 
 static Ssh_gss_stat ssh_gssapi_release_name(struct ssh_gss_library *lib,
-					    Ssh_gss_name *srv_name)
+                                            Ssh_gss_name *srv_name)
 {
     struct gssapi_functions *gss = &lib->u.gssapi;
     OM_uint32 min_stat,maj_stat;
@@ -243,8 +243,8 @@ static Ssh_gss_stat ssh_gssapi_release_name(struct ssh_gss_library *lib,
 }
 
 static Ssh_gss_stat ssh_gssapi_get_mic(struct ssh_gss_library *lib,
-				       Ssh_gss_ctx ctx, Ssh_gss_buf *buf,
-				       Ssh_gss_buf *hash)
+                                       Ssh_gss_ctx ctx, Ssh_gss_buf *buf,
+                                       Ssh_gss_buf *hash)
 {
     struct gssapi_functions *gss = &lib->u.gssapi;
     gssapi_ssh_gss_ctx *gssctx = (gssapi_ssh_gss_ctx *) ctx;
@@ -263,7 +263,7 @@ static Ssh_gss_stat ssh_gssapi_verify_mic(struct ssh_gss_library *lib,
 }
 
 static Ssh_gss_stat ssh_gssapi_free_mic(struct ssh_gss_library *lib,
-					Ssh_gss_buf *hash)
+                                        Ssh_gss_buf *hash)
 {
     /* On Unix this is the same freeing process as ssh_gssapi_free_tok. */
     return ssh_gssapi_free_tok(lib, hash);

+ 31 - 31
source/putty/sshmd5.c

@@ -154,35 +154,35 @@ static void MD5_BinarySink_write(BinarySink *bs, const void *data, size_t len)
     s->len += lenw;
 
     if (s->blkused + len < BLKSIZE) {
-	/*
-	 * Trivial case: just add to the block.
-	 */
-	memcpy(s->block + s->blkused, q, len);
-	s->blkused += len;
+        /*
+         * Trivial case: just add to the block.
+         */
+        memcpy(s->block + s->blkused, q, len);
+        s->blkused += len;
     } else {
-	/*
-	 * We must complete and process at least one block.
-	 */
-	while (s->blkused + len >= BLKSIZE) {
-	    memcpy(s->block + s->blkused, q, BLKSIZE - s->blkused);
-	    q += BLKSIZE - s->blkused;
-	    len -= BLKSIZE - s->blkused;
-	    /* Now process the block. Gather bytes little-endian into words */
-	    for (i = 0; i < 16; i++) {
-		wordblock[i] =
-		    (((uint32_t) s->block[i * 4 + 3]) << 24) |
-		    (((uint32_t) s->block[i * 4 + 2]) << 16) |
-		    (((uint32_t) s->block[i * 4 + 1]) << 8) |
-		    (((uint32_t) s->block[i * 4 + 0]) << 0);
-	    }
-	    MD5_Block(&s->core, wordblock);
-	    s->blkused = 0;
-	}
+        /*
+         * We must complete and process at least one block.
+         */
+        while (s->blkused + len >= BLKSIZE) {
+            memcpy(s->block + s->blkused, q, BLKSIZE - s->blkused);
+            q += BLKSIZE - s->blkused;
+            len -= BLKSIZE - s->blkused;
+            /* Now process the block. Gather bytes little-endian into words */
+            for (i = 0; i < 16; i++) {
+                wordblock[i] =
+                    (((uint32_t) s->block[i * 4 + 3]) << 24) |
+                    (((uint32_t) s->block[i * 4 + 2]) << 16) |
+                    (((uint32_t) s->block[i * 4 + 1]) << 8) |
+                    (((uint32_t) s->block[i * 4 + 0]) << 0);
+            }
+            MD5_Block(&s->core, wordblock);
+            s->blkused = 0;
+        }
 #ifdef MPEXT
 	if (len > 0)
 #endif
-	memcpy(s->block, q, len);
-	s->blkused = len;
+        memcpy(s->block, q, len);
+        s->blkused = len;
     }
 }
 
@@ -194,9 +194,9 @@ void MD5Final(unsigned char output[16], struct MD5Context *s)
     uint64_t len;
 
     if (s->blkused >= 56)
-	pad = 56 + 64 - s->blkused;
+        pad = 56 + 64 - s->blkused;
     else
-	pad = 56 - s->blkused;
+        pad = 56 - s->blkused;
 
     len = (s->len << 3);
 
@@ -209,10 +209,10 @@ void MD5Final(unsigned char output[16], struct MD5Context *s)
     put_data(s, c, 8);
 
     for (i = 0; i < 4; i++) {
-	output[4 * i + 3] = (s->core.h[i] >> 24) & 0xFF;
-	output[4 * i + 2] = (s->core.h[i] >> 16) & 0xFF;
-	output[4 * i + 1] = (s->core.h[i] >> 8) & 0xFF;
-	output[4 * i + 0] = (s->core.h[i] >> 0) & 0xFF;
+        output[4 * i + 3] = (s->core.h[i] >> 24) & 0xFF;
+        output[4 * i + 2] = (s->core.h[i] >> 16) & 0xFF;
+        output[4 * i + 1] = (s->core.h[i] >> 8) & 0xFF;
+        output[4 * i + 0] = (s->core.h[i] >> 0) & 0xFF;
     }
 }
 

+ 1 - 1
source/putty/sshppl.h

@@ -10,7 +10,7 @@
 typedef void (*packet_handler_fn_t)(PacketProtocolLayer *ppl, PktIn *pktin);
 
 struct PacketProtocolLayerVtable {
-    void (*free)(PacketProtocolLayer *); 
+    void (*free)(PacketProtocolLayer *);
     void (*process_queue)(PacketProtocolLayer *ppl);
     bool (*get_specials)(
         PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);

Разница между файлами не показана из-за своего большого размера
+ 292 - 292
source/putty/sshpubk.c


+ 7 - 7
source/putty/sshrand.c

@@ -39,7 +39,7 @@ void random_add_noise(NoiseSourceId source, const void *noise, int length)
 {
     WINSCP_PUTTY_SECTION_ENTER;
     if (!random_active)
-	return;
+        return;
 
     prng_add_entropy(global_prng, source, make_ptrlen(noise, length));
     WINSCP_PUTTY_SECTION_LEAVE;
@@ -50,9 +50,9 @@ static void random_timer(void *ctx, unsigned long now)
     unreachable_internal(); // WINSCP
     WINSCP_PUTTY_SECTION_ENTER;
     if (random_active > 0 && now == next_noise_collection) {
-	noise_regular();
-	next_noise_collection =
-	    schedule_timer(NOISE_REGULAR_INTERVAL, random_timer,
+        noise_regular();
+        next_noise_collection =
+            schedule_timer(NOISE_REGULAR_INTERVAL, random_timer,
                            &random_timer_ctx);
     }
     WINSCP_PUTTY_SECTION_LEAVE;
@@ -92,9 +92,9 @@ void random_save_seed(void)
     void *data;
 
     if (random_active) {
-	random_get_savedata(&data, &len);
-	write_random_seed(data, len);
-	sfree(data);
+        random_get_savedata(&data, &len);
+        write_random_seed(data, len);
+        sfree(data);
     }
 }
 

+ 31 - 31
source/putty/sshrsa.c

@@ -50,7 +50,7 @@ bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key)
     unsigned char *p;
 
     if (key->bytes < length + 4)
-	return false;                  /* RSA key too short! */
+        return false;                  /* RSA key too short! */
 
     memmove(data + key->bytes - length, data, length);
     data[0] = 0;
@@ -98,7 +98,7 @@ bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key)
 
     p = data;
     for (i = key->bytes; i--;) {
-	*p++ = mp_get_byte(b2, i);
+        *p++ = mp_get_byte(b2, i);
     }
 
     mp_free(b1);
@@ -296,7 +296,7 @@ char *rsa_ssh1_fingerprint(RSAKey *key)
     out = strbuf_new();
     strbuf_catf(out, "%d ", mp_get_nbits(key->modulus));
     for (i = 0; i < 16; i++)
-	strbuf_catf(out, "%s%02x", i ? ":" : "", digest[i]);
+        strbuf_catf(out, "%s%02x", i ? ":" : "", digest[i]);
     if (key->comment)
         strbuf_catf(out, " %s", key->comment);
     return strbuf_to_str(out);
@@ -388,7 +388,7 @@ int rsa_ssh1_public_blob_len(ptrlen data)
     mp_free(get_mp_ssh1(src));
 
     if (get_err(src))
-	return -1;
+        return -1;
 
     /* Return the number of bytes consumed. */
     return src->pos;
@@ -397,19 +397,19 @@ int rsa_ssh1_public_blob_len(ptrlen data)
 void freersapriv(RSAKey *key)
 {
     if (key->private_exponent) {
-	mp_free(key->private_exponent);
+        mp_free(key->private_exponent);
         key->private_exponent = NULL;
     }
     if (key->p) {
-	mp_free(key->p);
+        mp_free(key->p);
         key->p = NULL;
     }
     if (key->q) {
-	mp_free(key->q);
+        mp_free(key->q);
         key->q = NULL;
     }
     if (key->iqmp) {
-	mp_free(key->iqmp);
+        mp_free(key->iqmp);
         key->iqmp = NULL;
     }
 }
@@ -418,21 +418,21 @@ void freersakey(RSAKey *key)
 {
     freersapriv(key);
     if (key->modulus) {
-	mp_free(key->modulus);
+        mp_free(key->modulus);
         key->modulus = NULL;
     }
     if (key->exponent) {
-	mp_free(key->exponent);
+        mp_free(key->exponent);
         key->exponent = NULL;
     }
     if (key->comment) {
-	sfree(key->comment);
+        sfree(key->comment);
         key->comment = NULL;
     }
 }
 
 /* ----------------------------------------------------------------------
- * Implementation of the ssh-rsa signing key type. 
+ * Implementation of the ssh-rsa signing key type.
  */
 
 static void rsa2_freekey(ssh_key *key);   /* forward reference */
@@ -444,7 +444,7 @@ static ssh_key *rsa2_new_pub(const ssh_keyalg *self, ptrlen data)
 
     BinarySource_BARE_INIT_PL(src, data);
     if (!ptrlen_eq_string(get_string(src), "ssh-rsa"))
-	return NULL;
+        return NULL;
 
     rsa = snew(RSAKey);
     rsa->sshk.vt = &ssh_rsa;
@@ -455,8 +455,8 @@ static ssh_key *rsa2_new_pub(const ssh_keyalg *self, ptrlen data)
     rsa->comment = NULL;
 
     if (get_err(src)) {
-	rsa2_freekey(&rsa->sshk);
-	return NULL;
+        rsa2_freekey(&rsa->sshk);
+        return NULL;
     }
 
     return &rsa->sshk;
@@ -513,8 +513,8 @@ static ssh_key *rsa2_new_priv(const ssh_keyalg *self,
     rsa->iqmp = get_mp_ssh2(src);
 
     if (get_err(src) || !rsa_verify(rsa)) {
-	rsa2_freekey(&rsa->sshk);
-	return NULL;
+        rsa2_freekey(&rsa->sshk);
+        return NULL;
     }
 
     return &rsa->sshk;
@@ -537,8 +537,8 @@ static ssh_key *rsa2_new_priv_openssh(const ssh_keyalg *self,
     rsa->q = get_mp_ssh2(src);
 
     if (get_err(src) || !rsa_verify(rsa)) {
-	rsa2_freekey(&rsa->sshk);
-	return NULL;
+        rsa2_freekey(&rsa->sshk);
+        return NULL;
     }
 
     return &rsa->sshk;
@@ -724,7 +724,7 @@ static bool rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
      */
     in_pl = get_string(src);
     if (get_err(src) || !ptrlen_eq_string(type, "ssh-rsa"))
-	return false;
+        return false;
 
     in = mp_from_bytes_be(in_pl);
     out = mp_modpow(in, rsa->exponent, rsa->modulus);
@@ -774,7 +774,7 @@ static void rsa2_sign(ssh_key *key, ptrlen data,
     { // WINSCP
     size_t i; // WINSCP
     for (i = 0; i < nbytes; i++)
-	put_byte(bs, mp_get_byte(out, nbytes - 1 - i));
+        put_byte(bs, mp_get_byte(out, nbytes - 1 - i));
     } // WINSCP
 
     mp_free(out);
@@ -836,7 +836,7 @@ int ssh_rsakex_klen(RSAKey *rsa)
 }
 
 static void oaep_mask(const ssh_hashalg *h, void *seed, int seedlen,
-		      void *vdata, int datalen)
+                      void *vdata, int datalen)
 {
     unsigned char *data = (unsigned char *)vdata;
     unsigned count = 0;
@@ -846,7 +846,7 @@ static void oaep_mask(const ssh_hashalg *h, void *seed, int seedlen,
         ssh_hash *s;
         unsigned char hash[MAX_HASH_LEN];
 
-	assert(h->hlen <= MAX_HASH_LEN);
+        assert(h->hlen <= MAX_HASH_LEN);
         s = ssh_hash_new(h);
         put_data(s, seed, seedlen);
         put_uint32(s, count);
@@ -870,26 +870,26 @@ strbuf *ssh_rsakex_encrypt(RSAKey *rsa, const ssh_hashalg *h, ptrlen in)
 
     /*
      * Here we encrypt using RSAES-OAEP. Essentially this means:
-     * 
+     *
      *  - we have a SHA-based `mask generation function' which
      *    creates a pseudo-random stream of mask data
      *    deterministically from an input chunk of data.
-     * 
+     *
      *  - we have a random chunk of data called a seed.
-     * 
+     *
      *  - we use the seed to generate a mask which we XOR with our
      *    plaintext.
-     * 
+     *
      *  - then we use _the masked plaintext_ to generate a mask
      *    which we XOR with the seed.
-     * 
+     *
      *  - then we concatenate the masked seed and the masked
      *    plaintext, and RSA-encrypt that lot.
-     * 
+     *
      * The result is that the data input to the encryption function
      * is random-looking and (hopefully) contains no exploitable
      * structure such as PKCS1-v1_5 does.
-     * 
+     *
      * For a precise specification, see RFC 3447, section 7.1.1.
      * Some of the variable names below are derived from that, so
      * it'd probably help to read it anyway.
@@ -945,7 +945,7 @@ strbuf *ssh_rsakex_encrypt(RSAKey *rsa, const ssh_hashalg *h, ptrlen in)
     b2 = mp_modpow(b1, rsa->exponent, rsa->modulus);
     p = (char *)out;
     for (i = outlen; i--;) {
-	*p++ = mp_get_byte(b2, i);
+        *p++ = mp_get_byte(b2, i);
     }
     mp_free(b1);
     mp_free(b2);

+ 11 - 11
source/putty/sshsh256.c

@@ -1,6 +1,6 @@
 /*
  * SHA-256 algorithm as described at
- * 
+ *
  *   http://csrc.nist.gov/cryptval/shs.html
  */
 
@@ -256,20 +256,20 @@ static inline void sha256_sw_round(
         w[t] = GET_32BIT_MSB_FIRST(block + 4*t);
 
     for (size_t t = 16; t < SHA256_ROUNDS; t++)
-	w[t] = sigma_1(w[t-2]) + w[t-7] + sigma_0(w[t-15]) + w[t-16];
+        w[t] = sigma_1(w[t-2]) + w[t-7] + sigma_0(w[t-15]) + w[t-16];
 
     a = core[0]; b = core[1]; c = core[2]; d = core[3];
     e = core[4]; f = core[5]; g = core[6]; h = core[7];
 
     for (size_t t = 0; t < SHA256_ROUNDS; t += 8) {
-	sha256_sw_round(t+0, w, &a,&b,&c,&d,&e,&f,&g,&h);
-	sha256_sw_round(t+1, w, &h,&a,&b,&c,&d,&e,&f,&g);
-	sha256_sw_round(t+2, w, &g,&h,&a,&b,&c,&d,&e,&f);
-	sha256_sw_round(t+3, w, &f,&g,&h,&a,&b,&c,&d,&e);
-	sha256_sw_round(t+4, w, &e,&f,&g,&h,&a,&b,&c,&d);
-	sha256_sw_round(t+5, w, &d,&e,&f,&g,&h,&a,&b,&c);
-	sha256_sw_round(t+6, w, &c,&d,&e,&f,&g,&h,&a,&b);
-	sha256_sw_round(t+7, w, &b,&c,&d,&e,&f,&g,&h,&a);
+        sha256_sw_round(t+0, w, &a,&b,&c,&d,&e,&f,&g,&h);
+        sha256_sw_round(t+1, w, &h,&a,&b,&c,&d,&e,&f,&g);
+        sha256_sw_round(t+2, w, &g,&h,&a,&b,&c,&d,&e,&f);
+        sha256_sw_round(t+3, w, &f,&g,&h,&a,&b,&c,&d,&e);
+        sha256_sw_round(t+4, w, &e,&f,&g,&h,&a,&b,&c,&d);
+        sha256_sw_round(t+5, w, &d,&e,&f,&g,&h,&a,&b,&c);
+        sha256_sw_round(t+6, w, &c,&d,&e,&f,&g,&h,&a,&b);
+        sha256_sw_round(t+7, w, &b,&c,&d,&e,&f,&g,&h,&a);
     }
 
     core[0] += a; core[1] += b; core[2] += c; core[3] += d;
@@ -400,7 +400,7 @@ const ssh_hashalg ssh_sha256_sw = {
 /*WINSCP static*/ bool sha256_hw_available(void)
 {
     unsigned int CPUInfo[4];
-    GET_CPU_ID_0(CPUInfo);  
+    GET_CPU_ID_0(CPUInfo);
     if (CPUInfo[0] < 7)
         return false;
 

+ 87 - 87
source/putty/sshsh512.c

@@ -1,6 +1,6 @@
 /*
  * SHA-512 algorithm as described at
- * 
+ *
  *   http://csrc.nist.gov/cryptval/shs.html
  *
  * Modifications made for SHA-384 also
@@ -42,30 +42,30 @@ typedef struct {
 
 #define Ch(r,t,x,y,z) ( not(t,x), and(r,t,z), and(t,x,y), xor(r,r,t) )
 #define Maj(r,t,x,y,z) ( and(r,x,y), and(t,x,z), xor(r,r,t), \
-			 and(t,y,z), xor(r,r,t) )
+                         and(t,y,z), xor(r,r,t) )
 #define bigsigma0(r,t,x) ( rorL(r,x,28), rorB(t,x,34), xor(r,r,t), \
-			   rorB(t,x,39), xor(r,r,t) )
+                           rorB(t,x,39), xor(r,r,t) )
 #define bigsigma1(r,t,x) ( rorL(r,x,14), rorL(t,x,18), xor(r,r,t), \
-			   rorB(t,x,41), xor(r,r,t) )
+                           rorB(t,x,41), xor(r,r,t) )
 #define smallsigma0(r,t,x) ( rorL(r,x,1), rorL(t,x,8), xor(r,r,t), \
-			     shrL(t,x,7), xor(r,r,t) )
+                             shrL(t,x,7), xor(r,r,t) )
 #define smallsigma1(r,t,x) ( rorL(r,x,19), rorB(t,x,61), xor(r,r,t), \
-			     shrL(t,x,6), xor(r,r,t) )
+                             shrL(t,x,6), xor(r,r,t) )
 
 static void SHA512_Core_Init(SHA512_State *s) {
     static const uint64_t iv[] = {
-	INIT(0x6a09e667, 0xf3bcc908),
-	INIT(0xbb67ae85, 0x84caa73b),
-	INIT(0x3c6ef372, 0xfe94f82b),
-	INIT(0xa54ff53a, 0x5f1d36f1),
-	INIT(0x510e527f, 0xade682d1),
-	INIT(0x9b05688c, 0x2b3e6c1f),
-	INIT(0x1f83d9ab, 0xfb41bd6b),
-	INIT(0x5be0cd19, 0x137e2179),
+        INIT(0x6a09e667, 0xf3bcc908),
+        INIT(0xbb67ae85, 0x84caa73b),
+        INIT(0x3c6ef372, 0xfe94f82b),
+        INIT(0xa54ff53a, 0x5f1d36f1),
+        INIT(0x510e527f, 0xade682d1),
+        INIT(0x9b05688c, 0x2b3e6c1f),
+        INIT(0x1f83d9ab, 0xfb41bd6b),
+        INIT(0x5be0cd19, 0x137e2179),
     };
     int i;
     for (i = 0; i < 8; i++)
-	s->h[i] = iv[i];
+        s->h[i] = iv[i];
 }
 
 static void SHA384_Core_Init(SHA512_State *s) {
@@ -88,46 +88,46 @@ static void SHA512_Block(SHA512_State *s, uint64_t *block) {
     uint64_t w[80];
     uint64_t a,b,c,d,e,f,g,h;
     static const uint64_t k[] = {
-	INIT(0x428a2f98, 0xd728ae22), INIT(0x71374491, 0x23ef65cd),
-	INIT(0xb5c0fbcf, 0xec4d3b2f), INIT(0xe9b5dba5, 0x8189dbbc),
-	INIT(0x3956c25b, 0xf348b538), INIT(0x59f111f1, 0xb605d019),
-	INIT(0x923f82a4, 0xaf194f9b), INIT(0xab1c5ed5, 0xda6d8118),
-	INIT(0xd807aa98, 0xa3030242), INIT(0x12835b01, 0x45706fbe),
-	INIT(0x243185be, 0x4ee4b28c), INIT(0x550c7dc3, 0xd5ffb4e2),
-	INIT(0x72be5d74, 0xf27b896f), INIT(0x80deb1fe, 0x3b1696b1),
-	INIT(0x9bdc06a7, 0x25c71235), INIT(0xc19bf174, 0xcf692694),
-	INIT(0xe49b69c1, 0x9ef14ad2), INIT(0xefbe4786, 0x384f25e3),
-	INIT(0x0fc19dc6, 0x8b8cd5b5), INIT(0x240ca1cc, 0x77ac9c65),
-	INIT(0x2de92c6f, 0x592b0275), INIT(0x4a7484aa, 0x6ea6e483),
-	INIT(0x5cb0a9dc, 0xbd41fbd4), INIT(0x76f988da, 0x831153b5),
-	INIT(0x983e5152, 0xee66dfab), INIT(0xa831c66d, 0x2db43210),
-	INIT(0xb00327c8, 0x98fb213f), INIT(0xbf597fc7, 0xbeef0ee4),
-	INIT(0xc6e00bf3, 0x3da88fc2), INIT(0xd5a79147, 0x930aa725),
-	INIT(0x06ca6351, 0xe003826f), INIT(0x14292967, 0x0a0e6e70),
-	INIT(0x27b70a85, 0x46d22ffc), INIT(0x2e1b2138, 0x5c26c926),
-	INIT(0x4d2c6dfc, 0x5ac42aed), INIT(0x53380d13, 0x9d95b3df),
-	INIT(0x650a7354, 0x8baf63de), INIT(0x766a0abb, 0x3c77b2a8),
-	INIT(0x81c2c92e, 0x47edaee6), INIT(0x92722c85, 0x1482353b),
-	INIT(0xa2bfe8a1, 0x4cf10364), INIT(0xa81a664b, 0xbc423001),
-	INIT(0xc24b8b70, 0xd0f89791), INIT(0xc76c51a3, 0x0654be30),
-	INIT(0xd192e819, 0xd6ef5218), INIT(0xd6990624, 0x5565a910),
-	INIT(0xf40e3585, 0x5771202a), INIT(0x106aa070, 0x32bbd1b8),
-	INIT(0x19a4c116, 0xb8d2d0c8), INIT(0x1e376c08, 0x5141ab53),
-	INIT(0x2748774c, 0xdf8eeb99), INIT(0x34b0bcb5, 0xe19b48a8),
-	INIT(0x391c0cb3, 0xc5c95a63), INIT(0x4ed8aa4a, 0xe3418acb),
-	INIT(0x5b9cca4f, 0x7763e373), INIT(0x682e6ff3, 0xd6b2b8a3),
-	INIT(0x748f82ee, 0x5defb2fc), INIT(0x78a5636f, 0x43172f60),
-	INIT(0x84c87814, 0xa1f0ab72), INIT(0x8cc70208, 0x1a6439ec),
-	INIT(0x90befffa, 0x23631e28), INIT(0xa4506ceb, 0xde82bde9),
-	INIT(0xbef9a3f7, 0xb2c67915), INIT(0xc67178f2, 0xe372532b),
-	INIT(0xca273ece, 0xea26619c), INIT(0xd186b8c7, 0x21c0c207),
-	INIT(0xeada7dd6, 0xcde0eb1e), INIT(0xf57d4f7f, 0xee6ed178),
-	INIT(0x06f067aa, 0x72176fba), INIT(0x0a637dc5, 0xa2c898a6),
-	INIT(0x113f9804, 0xbef90dae), INIT(0x1b710b35, 0x131c471b),
-	INIT(0x28db77f5, 0x23047d84), INIT(0x32caab7b, 0x40c72493),
-	INIT(0x3c9ebe0a, 0x15c9bebc), INIT(0x431d67c4, 0x9c100d4c),
-	INIT(0x4cc5d4be, 0xcb3e42b6), INIT(0x597f299c, 0xfc657e2a),
-	INIT(0x5fcb6fab, 0x3ad6faec), INIT(0x6c44198c, 0x4a475817),
+        INIT(0x428a2f98, 0xd728ae22), INIT(0x71374491, 0x23ef65cd),
+        INIT(0xb5c0fbcf, 0xec4d3b2f), INIT(0xe9b5dba5, 0x8189dbbc),
+        INIT(0x3956c25b, 0xf348b538), INIT(0x59f111f1, 0xb605d019),
+        INIT(0x923f82a4, 0xaf194f9b), INIT(0xab1c5ed5, 0xda6d8118),
+        INIT(0xd807aa98, 0xa3030242), INIT(0x12835b01, 0x45706fbe),
+        INIT(0x243185be, 0x4ee4b28c), INIT(0x550c7dc3, 0xd5ffb4e2),
+        INIT(0x72be5d74, 0xf27b896f), INIT(0x80deb1fe, 0x3b1696b1),
+        INIT(0x9bdc06a7, 0x25c71235), INIT(0xc19bf174, 0xcf692694),
+        INIT(0xe49b69c1, 0x9ef14ad2), INIT(0xefbe4786, 0x384f25e3),
+        INIT(0x0fc19dc6, 0x8b8cd5b5), INIT(0x240ca1cc, 0x77ac9c65),
+        INIT(0x2de92c6f, 0x592b0275), INIT(0x4a7484aa, 0x6ea6e483),
+        INIT(0x5cb0a9dc, 0xbd41fbd4), INIT(0x76f988da, 0x831153b5),
+        INIT(0x983e5152, 0xee66dfab), INIT(0xa831c66d, 0x2db43210),
+        INIT(0xb00327c8, 0x98fb213f), INIT(0xbf597fc7, 0xbeef0ee4),
+        INIT(0xc6e00bf3, 0x3da88fc2), INIT(0xd5a79147, 0x930aa725),
+        INIT(0x06ca6351, 0xe003826f), INIT(0x14292967, 0x0a0e6e70),
+        INIT(0x27b70a85, 0x46d22ffc), INIT(0x2e1b2138, 0x5c26c926),
+        INIT(0x4d2c6dfc, 0x5ac42aed), INIT(0x53380d13, 0x9d95b3df),
+        INIT(0x650a7354, 0x8baf63de), INIT(0x766a0abb, 0x3c77b2a8),
+        INIT(0x81c2c92e, 0x47edaee6), INIT(0x92722c85, 0x1482353b),
+        INIT(0xa2bfe8a1, 0x4cf10364), INIT(0xa81a664b, 0xbc423001),
+        INIT(0xc24b8b70, 0xd0f89791), INIT(0xc76c51a3, 0x0654be30),
+        INIT(0xd192e819, 0xd6ef5218), INIT(0xd6990624, 0x5565a910),
+        INIT(0xf40e3585, 0x5771202a), INIT(0x106aa070, 0x32bbd1b8),
+        INIT(0x19a4c116, 0xb8d2d0c8), INIT(0x1e376c08, 0x5141ab53),
+        INIT(0x2748774c, 0xdf8eeb99), INIT(0x34b0bcb5, 0xe19b48a8),
+        INIT(0x391c0cb3, 0xc5c95a63), INIT(0x4ed8aa4a, 0xe3418acb),
+        INIT(0x5b9cca4f, 0x7763e373), INIT(0x682e6ff3, 0xd6b2b8a3),
+        INIT(0x748f82ee, 0x5defb2fc), INIT(0x78a5636f, 0x43172f60),
+        INIT(0x84c87814, 0xa1f0ab72), INIT(0x8cc70208, 0x1a6439ec),
+        INIT(0x90befffa, 0x23631e28), INIT(0xa4506ceb, 0xde82bde9),
+        INIT(0xbef9a3f7, 0xb2c67915), INIT(0xc67178f2, 0xe372532b),
+        INIT(0xca273ece, 0xea26619c), INIT(0xd186b8c7, 0x21c0c207),
+        INIT(0xeada7dd6, 0xcde0eb1e), INIT(0xf57d4f7f, 0xee6ed178),
+        INIT(0x06f067aa, 0x72176fba), INIT(0x0a637dc5, 0xa2c898a6),
+        INIT(0x113f9804, 0xbef90dae), INIT(0x1b710b35, 0x131c471b),
+        INIT(0x28db77f5, 0x23047d84), INIT(0x32caab7b, 0x40c72493),
+        INIT(0x3c9ebe0a, 0x15c9bebc), INIT(0x431d67c4, 0x9c100d4c),
+        INIT(0x4cc5d4be, 0xcb3e42b6), INIT(0x597f299c, 0xfc657e2a),
+        INIT(0x5fcb6fab, 0x3ad6faec), INIT(0x6c44198c, 0x4a475817),
     };
 
     int t;
@@ -136,12 +136,12 @@ static void SHA512_Block(SHA512_State *s, uint64_t *block) {
         w[t] = block[t];
 
     for (t = 16; t < 80; t++) {
-	uint64_t p, q, r, tmp;
-	smallsigma1(p, tmp, w[t-2]);
-	smallsigma0(q, tmp, w[t-15]);
-	add(r, p, q);
-	add(p, r, w[t-7]);
-	add(w[t], p, w[t-16]);
+        uint64_t p, q, r, tmp;
+        smallsigma1(p, tmp, w[t-2]);
+        smallsigma0(q, tmp, w[t-15]);
+        add(r, p, q);
+        add(p, r, w[t-7]);
+        add(w[t], p, w[t-16]);
     }
 
     a = s->h[0]; b = s->h[1]; c = s->h[2]; d = s->h[3];
@@ -151,36 +151,36 @@ static void SHA512_Block(SHA512_State *s, uint64_t *block) {
         uint64_t tmp, p, q, r;
 
 #define ROUND(j,a,b,c,d,e,f,g,h) \
-	bigsigma1(p, tmp, e); \
-	Ch(q, tmp, e, f, g); \
-	add(r, p, q); \
-	add(p, r, k[j]) ; \
-	add(q, p, w[j]); \
-	add(r, q, h); \
-	bigsigma0(p, tmp, a); \
-	Maj(tmp, q, a, b, c); \
-	add(q, tmp, p); \
-	add(p, r, d); \
-	d = p; \
-	add(h, q, r);
-
-	ROUND(t+0, a,b,c,d,e,f,g,h);
-	ROUND(t+1, h,a,b,c,d,e,f,g);
-	ROUND(t+2, g,h,a,b,c,d,e,f);
-	ROUND(t+3, f,g,h,a,b,c,d,e);
-	ROUND(t+4, e,f,g,h,a,b,c,d);
-	ROUND(t+5, d,e,f,g,h,a,b,c);
-	ROUND(t+6, c,d,e,f,g,h,a,b);
-	ROUND(t+7, b,c,d,e,f,g,h,a);
+        bigsigma1(p, tmp, e); \
+        Ch(q, tmp, e, f, g); \
+        add(r, p, q); \
+        add(p, r, k[j]) ; \
+        add(q, p, w[j]); \
+        add(r, q, h); \
+        bigsigma0(p, tmp, a); \
+        Maj(tmp, q, a, b, c); \
+        add(q, tmp, p); \
+        add(p, r, d); \
+        d = p; \
+        add(h, q, r);
+
+        ROUND(t+0, a,b,c,d,e,f,g,h);
+        ROUND(t+1, h,a,b,c,d,e,f,g);
+        ROUND(t+2, g,h,a,b,c,d,e,f);
+        ROUND(t+3, f,g,h,a,b,c,d,e);
+        ROUND(t+4, e,f,g,h,a,b,c,d);
+        ROUND(t+5, d,e,f,g,h,a,b,c);
+        ROUND(t+6, c,d,e,f,g,h,a,b);
+        ROUND(t+7, b,c,d,e,f,g,h,a);
     }
 
     {
-	uint64_t tmp;
+        uint64_t tmp;
 #define UPDATE(state, local) ( tmp = state, add(state, tmp, local) )
-	UPDATE(s->h[0], a); UPDATE(s->h[1], b);
-	UPDATE(s->h[2], c); UPDATE(s->h[3], d);
-	UPDATE(s->h[4], e); UPDATE(s->h[5], f);
-	UPDATE(s->h[6], g); UPDATE(s->h[7], h);
+        UPDATE(s->h[0], a); UPDATE(s->h[1], b);
+        UPDATE(s->h[2], c); UPDATE(s->h[3], d);
+        UPDATE(s->h[4], e); UPDATE(s->h[5], f);
+        UPDATE(s->h[6], g); UPDATE(s->h[7], h);
     }
 }
 

+ 3 - 3
source/putty/sshsha.c

@@ -1,6 +1,6 @@
 /*
  * SHA-1 algorithm as described at
- * 
+ *
  *   http://csrc.nist.gov/cryptval/shs.html
  */
 
@@ -210,7 +210,7 @@ static void sha1_sw_block(uint32_t *core, const uint8_t *block)
         w[t] = GET_32BIT_MSB_FIRST(block + 4*t);
 
     for (t = 16; t < SHA1_ROUNDS; t++) // WINSCP
-	w[t] = rol(w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16], 1);
+        w[t] = rol(w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16], 1);
 
     a = core[0]; b = core[1]; c = core[2]; d = core[3];
     e = core[4];
@@ -364,7 +364,7 @@ const ssh_hashalg ssh_sha1_sw = {
 static bool sha1_hw_available(void)
 {
     unsigned int CPUInfo[4];
-    GET_CPU_ID_0(CPUInfo);  
+    GET_CPU_ID_0(CPUInfo);
     if (CPUInfo[0] < 7)
         return false;
 

+ 12 - 12
source/putty/sshshare.c

@@ -344,12 +344,12 @@ static unsigned share_find_unused_id
     low = low_orig;
     high = high_orig = count234(sharestate->connections);
     while (high - low > 1) {
-	mid = (high + low) / 2;
-	cs = index234(sharestate->connections, mid);
-	if (cs->id == first + (mid - low_orig))
-	    low = mid;		       /* this one is still in the sequence */
-	else
-	    high = mid;		       /* this one is past the end */
+        mid = (high + low) / 2;
+        cs = index234(sharestate->connections, mid);
+        if (cs->id == first + (mid - low_orig))
+            low = mid;                 /* this one is still in the sequence */
+        else
+            high = mid;                /* this one is past the end */
     }
 
     /*
@@ -368,7 +368,7 @@ static unsigned share_find_unused_id
     {
         struct ssh_sharing_connstate dummy;
         dummy.id = ret;
-	assert(NULL == find234(sharestate->connections, &dummy, NULL));
+        assert(NULL == find234(sharestate->connections, &dummy, NULL));
     }
     return ret;
 }
@@ -581,7 +581,7 @@ static struct share_channel *share_add_channel
     if (chan->state != UNACKNOWLEDGED) {
         if (add234(cs->channels_by_server, chan) != chan) {
             del234(cs->channels_by_us, chan);
-            sfree(chan);            
+            sfree(chan);
             return NULL;
         }
     }
@@ -938,7 +938,7 @@ static void share_disconnect(struct ssh_sharing_connstate *cs,
 }
 
 static void share_closing(Plug *plug, const char *error_msg, int error_code,
-			  bool calling_back)
+                          bool calling_back)
 {
     struct ssh_sharing_connstate *cs = container_of(
         plug, struct ssh_sharing_connstate, plug);
@@ -1523,7 +1523,7 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs,
             err = dupprintf("CHANNEL_OPEN_CONFIRMATION packet cited unknown channel %u", (unsigned)server_id);
             goto confused;
         }
-            
+
         PUT_32BIT_MSB_FIRST(pkt + id_pos, new_id);
 
         chan = share_add_channel(cs, old_id, new_id, server_id, OPEN, maxpkt);
@@ -1846,7 +1846,7 @@ static void share_sent(Plug *plug, size_t bufsize)
 }
 
 static void share_listen_closing(Plug *plug, const char *error_msg,
-				 int error_code, bool calling_back)
+                                 int error_code, bool calling_back)
 {
     ssh_sharing_state *sharestate =
         container_of(plug, ssh_sharing_state, plug);
@@ -1937,7 +1937,7 @@ static int share_listen_accepting(Plug *plug,
     cs->sock = constructor(ctx, &cs->plug);
     if ((err = sk_socket_error(cs->sock)) != NULL) {
         sfree(cs);
-	return err != NULL;
+        return err != NULL;
     }
 
     sk_set_frozen(cs->sock, 0);

+ 510 - 510
source/putty/sshzlib.c

@@ -1,18 +1,18 @@
 /*
  * Zlib (RFC1950 / RFC1951) compression for PuTTY.
- * 
+ *
  * There will no doubt be criticism of my decision to reimplement
  * Zlib compression from scratch instead of using the existing zlib
  * code. People will cry `reinventing the wheel'; they'll claim
  * that the `fundamental basis of OSS' is code reuse; they'll want
  * to see a really good reason for me having chosen not to use the
  * existing code.
- * 
+ *
  * Well, here are my reasons. Firstly, I don't want to link the
  * whole of zlib into the PuTTY binary; PuTTY is justifiably proud
  * of its small size and I think zlib contains a lot of unnecessary
  * baggage for the kind of compression that SSH requires.
- * 
+ *
  * Secondly, I also don't like the alternative of using zlib.dll.
  * Another thing PuTTY is justifiably proud of is its ease of
  * installation, and the last thing I want to do is to start
@@ -20,7 +20,7 @@
  * zlib.dll kicking around, one with C calling conventions on the
  * exported functions and another with WINAPI conventions, and
  * there would be a significant danger of getting the wrong one.
- * 
+ *
  * Thirdly, there seems to be a difference of opinion on the IETF
  * secsh mailing list about the correct way to round off a
  * compressed packet and start the next. In particular, there's
@@ -28,7 +28,7 @@
  * capable of supporting (see below for an explanation). Given that
  * sort of uncertainty, I thought it might be better to have code
  * that will support even the zlib-incompatible worst case.
- * 
+ *
  * Fourthly, it's a _second implementation_. Second implementations
  * are fundamentally a Good Thing in standardisation efforts. The
  * difference of opinion mentioned above has arisen _precisely_
@@ -71,15 +71,15 @@ static int lz77_init(struct LZ77Context *ctx);
  * instead call literal() for everything.
  */
 static void lz77_compress(struct LZ77Context *ctx,
-			  const unsigned char *data, int len);
+                          const unsigned char *data, int len);
 
 /*
  * Modifiable parameters.
  */
-#define WINSIZE 32768		       /* window size. Must be power of 2! */
-#define HASHMAX 2039		       /* one more than max hash value */
-#define MAXMATCH 32		       /* how many matches we track */
-#define HASHCHARS 3		       /* how many chars make a hash */
+#define WINSIZE 32768                  /* window size. Must be power of 2! */
+#define HASHMAX 2039                   /* one more than max hash value */
+#define MAXMATCH 32                    /* how many matches we track */
+#define HASHCHARS 3                    /* how many chars make a hash */
 
 /*
  * This compressor takes a less slapdash approach than the
@@ -90,14 +90,14 @@ static void lz77_compress(struct LZ77Context *ctx,
  * byte), we can carefully remove the hash chain entry.
  */
 
-#define INVALID -1		       /* invalid hash _and_ invalid offset */
+#define INVALID -1                     /* invalid hash _and_ invalid offset */
 struct WindowEntry {
-    short next, prev;		       /* array indices within the window */
+    short next, prev;                  /* array indices within the window */
     short hashval;
 };
 
 struct HashEntry {
-    short first;		       /* window index of first in chain */
+    short first;                       /* window index of first in chain */
 };
 
 struct Match {
@@ -125,14 +125,14 @@ static int lz77_init(struct LZ77Context *ctx)
 
     st = snew(struct LZ77InternalContext);
     if (!st)
-	return 0;
+        return 0;
 
     ctx->ictx = st;
 
     for (i = 0; i < WINSIZE; i++)
-	st->win[i].next = st->win[i].prev = st->win[i].hashval = INVALID;
+        st->win[i].next = st->win[i].prev = st->win[i].hashval = INVALID;
     for (i = 0; i < HASHMAX; i++)
-	st->hashtab[i].first = INVALID;
+        st->hashtab[i].first = INVALID;
     st->winpos = 0;
 
     st->npending = 0;
@@ -141,7 +141,7 @@ static int lz77_init(struct LZ77Context *ctx)
 }
 
 static void lz77_advance(struct LZ77InternalContext *st,
-			 unsigned char c, int hash)
+                         unsigned char c, int hash)
 {
     int off;
 
@@ -150,9 +150,9 @@ static void lz77_advance(struct LZ77InternalContext *st,
      * or empty the chain if it's the only thing on the chain.
      */
     if (st->win[st->winpos].prev != INVALID) {
-	st->win[st->win[st->winpos].prev].next = INVALID;
+        st->win[st->win[st->winpos].prev].next = INVALID;
     } else if (st->win[st->winpos].hashval != INVALID) {
-	st->hashtab[st->win[st->winpos].hashval].first = INVALID;
+        st->hashtab[st->win[st->winpos].hashval].first = INVALID;
     }
 
     /*
@@ -164,7 +164,7 @@ static void lz77_advance(struct LZ77InternalContext *st,
     off = st->win[st->winpos].next = st->hashtab[hash].first;
     st->hashtab[hash].first = st->winpos;
     if (off != INVALID)
-	st->win[off].prev = st->winpos;
+        st->win[off].prev = st->winpos;
     st->data[st->winpos] = c;
 
     /*
@@ -176,7 +176,7 @@ static void lz77_advance(struct LZ77InternalContext *st,
 #define CHARAT(k) ( (k)<0 ? st->data[(st->winpos+k)&(WINSIZE-1)] : data[k] )
 
 static void lz77_compress(struct LZ77Context *ctx,
-			  const unsigned char *data, int len)
+                          const unsigned char *data, int len)
 {
     struct LZ77InternalContext *st = ctx->ictx;
     int i, distance, off, nmatch, matchlen, advance;
@@ -195,18 +195,18 @@ static void lz77_compress(struct LZ77Context *ctx,
      * HASHCHARS in size.
      */
     for (i = 0; i < st->npending; i++) {
-	unsigned char foo[HASHCHARS];
-	int j;
-	if (len + st->npending - i < HASHCHARS) {
-	    /* Update the pending array. */
-	    for (j = i; j < st->npending; j++)
-		st->pending[j - i] = st->pending[j];
-	    break;
-	}
-	for (j = 0; j < HASHCHARS; j++)
-	    foo[j] = (i + j < st->npending ? st->pending[i + j] :
-		      data[i + j - st->npending]);
-	lz77_advance(st, foo[0], lz77_hash(foo));
+        unsigned char foo[HASHCHARS];
+        int j;
+        if (len + st->npending - i < HASHCHARS) {
+            /* Update the pending array. */
+            for (j = i; j < st->npending; j++)
+                st->pending[j - i] = st->pending[j];
+            break;
+        }
+        for (j = 0; j < HASHCHARS; j++)
+            foo[j] = (i + j < st->npending ? st->pending[i + j] :
+                      data[i + j - st->npending]);
+        lz77_advance(st, foo[0], lz77_hash(foo));
     }
     st->npending -= i;
 
@@ -215,115 +215,115 @@ static void lz77_compress(struct LZ77Context *ctx,
     deferchr = '\0';
     while (len > 0) {
 
-	if (len >= HASHCHARS) {
-	    /*
-	     * Hash the next few characters.
-	     */
-	    int hash = lz77_hash(data);
-
-	    /*
-	     * Look the hash up in the corresponding hash chain and see
-	     * what we can find.
-	     */
-	    nmatch = 0;
-	    for (off = st->hashtab[hash].first;
-		 off != INVALID; off = st->win[off].next) {
-		/* distance = 1       if off == st->winpos-1 */
-		/* distance = WINSIZE if off == st->winpos   */
-		distance =
-		    WINSIZE - (off + WINSIZE - st->winpos) % WINSIZE;
-		for (i = 0; i < HASHCHARS; i++)
-		    if (CHARAT(i) != CHARAT(i - distance))
-			break;
-		if (i == HASHCHARS) {
-		    matches[nmatch].distance = distance;
-		    matches[nmatch].len = 3;
-		    if (++nmatch >= MAXMATCH)
-			break;
-		}
-	    }
-	} else {
-	    nmatch = 0;
-	}
-
-	if (nmatch > 0) {
-	    /*
-	     * We've now filled up matches[] with nmatch potential
-	     * matches. Follow them down to find the longest. (We
-	     * assume here that it's always worth favouring a
-	     * longer match over a shorter one.)
-	     */
-	    matchlen = HASHCHARS;
-	    while (matchlen < len) {
-		int j;
-		for (i = j = 0; i < nmatch; i++) {
-		    if (CHARAT(matchlen) ==
-			CHARAT(matchlen - matches[i].distance)) {
-			matches[j++] = matches[i];
-		    }
-		}
-		if (j == 0)
-		    break;
-		matchlen++;
-		nmatch = j;
-	    }
-
-	    /*
-	     * We've now got all the longest matches. We favour the
-	     * shorter distances, which means we go with matches[0].
-	     * So see if we want to defer it or throw it away.
-	     */
-	    matches[0].len = matchlen;
-	    if (defermatch.len > 0) {
-		if (matches[0].len > defermatch.len + 1) {
-		    /* We have a better match. Emit the deferred char,
-		     * and defer this match. */
-		    ctx->literal(ctx, (unsigned char) deferchr);
-		    defermatch = matches[0];
-		    deferchr = data[0];
-		    advance = 1;
-		} else {
-		    /* We don't have a better match. Do the deferred one. */
-		    ctx->match(ctx, defermatch.distance, defermatch.len);
-		    advance = defermatch.len - 1;
-		    defermatch.len = 0;
-		}
-	    } else {
-		/* There was no deferred match. Defer this one. */
-		defermatch = matches[0];
-		deferchr = data[0];
-		advance = 1;
-	    }
-	} else {
-	    /*
-	     * We found no matches. Emit the deferred match, if
-	     * any; otherwise emit a literal.
-	     */
-	    if (defermatch.len > 0) {
-		ctx->match(ctx, defermatch.distance, defermatch.len);
-		advance = defermatch.len - 1;
-		defermatch.len = 0;
-	    } else {
-		ctx->literal(ctx, data[0]);
-		advance = 1;
-	    }
-	}
-
-	/*
-	 * Now advance the position by `advance' characters,
-	 * keeping the window and hash chains consistent.
-	 */
-	while (advance > 0) {
-	    if (len >= HASHCHARS) {
-		lz77_advance(st, *data, lz77_hash(data));
-	    } else {
+        if (len >= HASHCHARS) {
+            /*
+             * Hash the next few characters.
+             */
+            int hash = lz77_hash(data);
+
+            /*
+             * Look the hash up in the corresponding hash chain and see
+             * what we can find.
+             */
+            nmatch = 0;
+            for (off = st->hashtab[hash].first;
+                 off != INVALID; off = st->win[off].next) {
+                /* distance = 1       if off == st->winpos-1 */
+                /* distance = WINSIZE if off == st->winpos   */
+                distance =
+                    WINSIZE - (off + WINSIZE - st->winpos) % WINSIZE;
+                for (i = 0; i < HASHCHARS; i++)
+                    if (CHARAT(i) != CHARAT(i - distance))
+                        break;
+                if (i == HASHCHARS) {
+                    matches[nmatch].distance = distance;
+                    matches[nmatch].len = 3;
+                    if (++nmatch >= MAXMATCH)
+                        break;
+                }
+            }
+        } else {
+            nmatch = 0;
+        }
+
+        if (nmatch > 0) {
+            /*
+             * We've now filled up matches[] with nmatch potential
+             * matches. Follow them down to find the longest. (We
+             * assume here that it's always worth favouring a
+             * longer match over a shorter one.)
+             */
+            matchlen = HASHCHARS;
+            while (matchlen < len) {
+                int j;
+                for (i = j = 0; i < nmatch; i++) {
+                    if (CHARAT(matchlen) ==
+                        CHARAT(matchlen - matches[i].distance)) {
+                        matches[j++] = matches[i];
+                    }
+                }
+                if (j == 0)
+                    break;
+                matchlen++;
+                nmatch = j;
+            }
+
+            /*
+             * We've now got all the longest matches. We favour the
+             * shorter distances, which means we go with matches[0].
+             * So see if we want to defer it or throw it away.
+             */
+            matches[0].len = matchlen;
+            if (defermatch.len > 0) {
+                if (matches[0].len > defermatch.len + 1) {
+                    /* We have a better match. Emit the deferred char,
+                     * and defer this match. */
+                    ctx->literal(ctx, (unsigned char) deferchr);
+                    defermatch = matches[0];
+                    deferchr = data[0];
+                    advance = 1;
+                } else {
+                    /* We don't have a better match. Do the deferred one. */
+                    ctx->match(ctx, defermatch.distance, defermatch.len);
+                    advance = defermatch.len - 1;
+                    defermatch.len = 0;
+                }
+            } else {
+                /* There was no deferred match. Defer this one. */
+                defermatch = matches[0];
+                deferchr = data[0];
+                advance = 1;
+            }
+        } else {
+            /*
+             * We found no matches. Emit the deferred match, if
+             * any; otherwise emit a literal.
+             */
+            if (defermatch.len > 0) {
+                ctx->match(ctx, defermatch.distance, defermatch.len);
+                advance = defermatch.len - 1;
+                defermatch.len = 0;
+            } else {
+                ctx->literal(ctx, data[0]);
+                advance = 1;
+            }
+        }
+
+        /*
+         * Now advance the position by `advance' characters,
+         * keeping the window and hash chains consistent.
+         */
+        while (advance > 0) {
+            if (len >= HASHCHARS) {
+                lz77_advance(st, *data, lz77_hash(data));
+            } else {
                 assert(st->npending < HASHCHARS);
-		st->pending[st->npending++] = *data;
-	    }
-	    data++;
-	    len--;
-	    advance--;
-	}
+                st->pending[st->npending++] = *data;
+            }
+            data++;
+            len--;
+            advance--;
+        }
     }
 }
 
@@ -334,7 +334,7 @@ static void lz77_compress(struct LZ77Context *ctx,
  * compressing a large file under no significant time constraint,
  * but when you're compressing little bits in real time, things get
  * hairier.
- * 
+ *
  * I suppose it's possible that I could compute Huffman trees based
  * on the frequencies in the _previous_ block, as a sort of
  * heuristic, but I'm not confident that the gain would balance out
@@ -355,8 +355,8 @@ static void outbits(struct Outbuf *out, unsigned long bits, int nbits)
     out->noutbits += nbits;
     while (out->noutbits >= 8) {
         put_byte(out->outbuf, out->outbits & 0xFF);
-	out->outbits >>= 8;
-	out->noutbits -= 8;
+        out->outbits >>= 8;
+        out->noutbits -= 8;
     }
 }
 
@@ -470,11 +470,11 @@ static void zlib_literal(struct LZ77Context *ectx, unsigned char c)
     struct Outbuf *out = (struct Outbuf *) ectx->userdata;
 
     if (c <= 143) {
-	/* 0 through 143 are 8 bits long starting at 00110000. */
-	outbits(out, mirrorbytes[0x30 + c], 8);
+        /* 0 through 143 are 8 bits long starting at 00110000. */
+        outbits(out, mirrorbytes[0x30 + c], 8);
     } else {
-	/* 144 through 255 are 9 bits long starting at 110010000. */
-	outbits(out, 1 + 2 * mirrorbytes[0x90 - 144 + c], 9);
+        /* 144 through 255 are 9 bits long starting at 110010000. */
+        outbits(out, 1 + 2 * mirrorbytes[0x90 - 144 + c], 9);
     }
 }
 
@@ -485,86 +485,86 @@ static void zlib_match(struct LZ77Context *ectx, int distance, int len)
     struct Outbuf *out = (struct Outbuf *) ectx->userdata;
 
     while (len > 0) {
-	int thislen;
-
-	/*
-	 * We can transmit matches of lengths 3 through 258
-	 * inclusive. So if len exceeds 258, we must transmit in
-	 * several steps, with 258 or less in each step.
-	 * 
-	 * Specifically: if len >= 261, we can transmit 258 and be
-	 * sure of having at least 3 left for the next step. And if
-	 * len <= 258, we can just transmit len. But if len == 259
-	 * or 260, we must transmit len-3.
-	 */
-	thislen = (len > 260 ? 258 : len <= 258 ? len : len - 3);
-	len -= thislen;
-
-	/*
-	 * Binary-search to find which length code we're
-	 * transmitting.
-	 */
-	i = -1;
-	j = lenof(lencodes);
-	while (1) {
-	    assert(j - i >= 2);
-	    k = (j + i) / 2;
-	    if (thislen < lencodes[k].min)
-		j = k;
-	    else if (thislen > lencodes[k].max)
-		i = k;
-	    else {
-		l = &lencodes[k];
-		break;		       /* found it! */
-	    }
-	}
-
-	/*
-	 * Transmit the length code. 256-279 are seven bits
-	 * starting at 0000000; 280-287 are eight bits starting at
-	 * 11000000.
-	 */
-	if (l->code <= 279) {
-	    outbits(out, mirrorbytes[(l->code - 256) * 2], 7);
-	} else {
-	    outbits(out, mirrorbytes[0xc0 - 280 + l->code], 8);
-	}
-
-	/*
-	 * Transmit the extra bits.
-	 */
-	if (l->extrabits)
-	    outbits(out, thislen - l->min, l->extrabits);
-
-	/*
-	 * Binary-search to find which distance code we're
-	 * transmitting.
-	 */
-	i = -1;
-	j = lenof(distcodes);
-	while (1) {
-	    assert(j - i >= 2);
-	    k = (j + i) / 2;
-	    if (distance < distcodes[k].min)
-		j = k;
-	    else if (distance > distcodes[k].max)
-		i = k;
-	    else {
-		d = &distcodes[k];
-		break;		       /* found it! */
-	    }
-	}
-
-	/*
-	 * Transmit the distance code. Five bits starting at 00000.
-	 */
-	outbits(out, mirrorbytes[d->code * 8], 5);
-
-	/*
-	 * Transmit the extra bits.
-	 */
-	if (d->extrabits)
-	    outbits(out, distance - d->min, d->extrabits);
+        int thislen;
+
+        /*
+         * We can transmit matches of lengths 3 through 258
+         * inclusive. So if len exceeds 258, we must transmit in
+         * several steps, with 258 or less in each step.
+         *
+         * Specifically: if len >= 261, we can transmit 258 and be
+         * sure of having at least 3 left for the next step. And if
+         * len <= 258, we can just transmit len. But if len == 259
+         * or 260, we must transmit len-3.
+         */
+        thislen = (len > 260 ? 258 : len <= 258 ? len : len - 3);
+        len -= thislen;
+
+        /*
+         * Binary-search to find which length code we're
+         * transmitting.
+         */
+        i = -1;
+        j = lenof(lencodes);
+        while (1) {
+            assert(j - i >= 2);
+            k = (j + i) / 2;
+            if (thislen < lencodes[k].min)
+                j = k;
+            else if (thislen > lencodes[k].max)
+                i = k;
+            else {
+                l = &lencodes[k];
+                break;                 /* found it! */
+            }
+        }
+
+        /*
+         * Transmit the length code. 256-279 are seven bits
+         * starting at 0000000; 280-287 are eight bits starting at
+         * 11000000.
+         */
+        if (l->code <= 279) {
+            outbits(out, mirrorbytes[(l->code - 256) * 2], 7);
+        } else {
+            outbits(out, mirrorbytes[0xc0 - 280 + l->code], 8);
+        }
+
+        /*
+         * Transmit the extra bits.
+         */
+        if (l->extrabits)
+            outbits(out, thislen - l->min, l->extrabits);
+
+        /*
+         * Binary-search to find which distance code we're
+         * transmitting.
+         */
+        i = -1;
+        j = lenof(distcodes);
+        while (1) {
+            assert(j - i >= 2);
+            k = (j + i) / 2;
+            if (distance < distcodes[k].min)
+                j = k;
+            else if (distance > distcodes[k].max)
+                i = k;
+            else {
+                d = &distcodes[k];
+                break;                 /* found it! */
+            }
+        }
+
+        /*
+         * Transmit the distance code. Five bits starting at 00000.
+         */
+        outbits(out, mirrorbytes[d->code * 8], 5);
+
+        /*
+         * Transmit the extra bits.
+         */
+        if (d->extrabits)
+            outbits(out, distance - d->min, d->extrabits);
     }
 }
 
@@ -623,12 +623,12 @@ void zlib_compress_block(ssh_compressor *sc,
      * algorithm.)
      */
     if (out->firstblock) {
-	outbits(out, 0x9C78, 16);
-	out->firstblock = false;
+        outbits(out, 0x9C78, 16);
+        out->firstblock = false;
 
-	in_block = false;
+        in_block = false;
     } else
-	in_block = true;
+        in_block = true;
 
     if (!in_block) {
         /*
@@ -668,9 +668,9 @@ void zlib_compress_block(ssh_compressor *sc,
      *
      * For the moment, we will use Zlib partial flush.
      */
-    outbits(out, 0, 7);	       /* close block */
+    outbits(out, 0, 7);        /* close block */
     outbits(out, 2, 3 + 7);    /* empty static block */
-    outbits(out, 2, 3);	       /* open new block */
+    outbits(out, 2, 3);        /* open new block */
 
     /*
      * If we've been asked to pad out the compressed data until it's
@@ -678,8 +678,8 @@ void zlib_compress_block(ssh_compressor *sc,
      * blocks.
      */
     while (out->outbuf->len < minlen) {
-        outbits(out, 0, 7);	       /* close block */
-        outbits(out, 2, 3);	       /* open new static block */
+        outbits(out, 0, 7);            /* close block */
+        outbits(out, 2, 3);            /* open new static block */
     }
 
     *outlen = out->outbuf->len;
@@ -710,7 +710,7 @@ struct zlib_tableentry {
 };
 
 struct zlib_table {
-    int mask;			       /* mask applied to input bit stream */
+    int mask;                          /* mask applied to input bit stream */
     struct zlib_tableentry *table;
 };
 
@@ -723,8 +723,8 @@ struct zlib_table {
  * recurse to build subtables.
  */
 static struct zlib_table *zlib_mkonetab(int *codes, unsigned char *lengths,
-					int nsyms,
-					int pfx, int pfxbits, int bits)
+                                        int nsyms,
+                                        int pfx, int pfxbits, int bits)
 {
     struct zlib_table *tab = snew(struct zlib_table);
     int pfxmask = (1 << pfxbits) - 1;
@@ -734,34 +734,34 @@ static struct zlib_table *zlib_mkonetab(int *codes, unsigned char *lengths,
     tab->mask = (1 << bits) - 1;
 
     for (code = 0; code <= tab->mask; code++) {
-	tab->table[code].code = -1;
-	tab->table[code].nbits = 0;
-	tab->table[code].nexttable = NULL;
+        tab->table[code].code = -1;
+        tab->table[code].nbits = 0;
+        tab->table[code].nexttable = NULL;
     }
 
     for (i = 0; i < nsyms; i++) {
-	if (lengths[i] <= pfxbits || (codes[i] & pfxmask) != pfx)
-	    continue;
-	code = (codes[i] >> pfxbits) & tab->mask;
-	for (j = code; j <= tab->mask; j += 1 << (lengths[i] - pfxbits)) {
-	    tab->table[j].code = i;
-	    nbits = lengths[i] - pfxbits;
-	    if (tab->table[j].nbits < nbits)
-		tab->table[j].nbits = nbits;
-	}
+        if (lengths[i] <= pfxbits || (codes[i] & pfxmask) != pfx)
+            continue;
+        code = (codes[i] >> pfxbits) & tab->mask;
+        for (j = code; j <= tab->mask; j += 1 << (lengths[i] - pfxbits)) {
+            tab->table[j].code = i;
+            nbits = lengths[i] - pfxbits;
+            if (tab->table[j].nbits < nbits)
+                tab->table[j].nbits = nbits;
+        }
     }
     for (code = 0; code <= tab->mask; code++) {
-	if (tab->table[code].nbits <= bits)
-	    continue;
-	/* Generate a subtable. */
-	tab->table[code].code = -1;
-	nbits = tab->table[code].nbits - bits;
-	if (nbits > 7)
-	    nbits = 7;
-	tab->table[code].nbits = bits;
-	tab->table[code].nexttable = zlib_mkonetab(codes, lengths, nsyms,
-						   pfx | (code << pfxbits),
-						   pfxbits + bits, nbits);
+        if (tab->table[code].nbits <= bits)
+            continue;
+        /* Generate a subtable. */
+        tab->table[code].code = -1;
+        nbits = tab->table[code].nbits - bits;
+        if (nbits > 7)
+            nbits = 7;
+        tab->table[code].nbits = bits;
+        tab->table[code].nexttable = zlib_mkonetab(codes, lengths, nsyms,
+                                                   pfx | (code << pfxbits),
+                                                   pfxbits + bits, nbits);
     }
 
     return tab;
@@ -771,7 +771,7 @@ static struct zlib_table *zlib_mkonetab(int *codes, unsigned char *lengths,
  * Build a decode table, given a set of Huffman tree lengths.
  */
 static struct zlib_table *zlib_mktable(unsigned char *lengths,
-				       int nlengths)
+                                       int nlengths)
 {
     int count[MAXCODELEN], startcode[MAXCODELEN], codes[MAXSYMS];
     int code, maxlen;
@@ -780,27 +780,27 @@ static struct zlib_table *zlib_mktable(unsigned char *lengths,
     /* Count the codes of each length. */
     maxlen = 0;
     for (i = 1; i < MAXCODELEN; i++)
-	count[i] = 0;
+        count[i] = 0;
     for (i = 0; i < nlengths; i++) {
-	count[lengths[i]]++;
-	if (maxlen < lengths[i])
-	    maxlen = lengths[i];
+        count[lengths[i]]++;
+        if (maxlen < lengths[i])
+            maxlen = lengths[i];
     }
     /* Determine the starting code for each length block. */
     code = 0;
     for (i = 1; i < MAXCODELEN; i++) {
-	startcode[i] = code;
-	code += count[i];
-	code <<= 1;
+        startcode[i] = code;
+        code += count[i];
+        code <<= 1;
     }
     /* Determine the code for each symbol. Mirrored, of course. */
     for (i = 0; i < nlengths; i++) {
-	code = startcode[lengths[i]]++;
-	codes[i] = 0;
-	for (j = 0; j < lengths[i]; j++) {
-	    codes[i] = (codes[i] << 1) | (code & 1);
-	    code >>= 1;
-	}
+        code = startcode[lengths[i]]++;
+        codes[i] = 0;
+        for (j = 0; j < lengths[i]; j++) {
+            codes[i] = (codes[i] << 1) | (code & 1);
+            code >>= 1;
+        }
     }
 
     /*
@@ -808,7 +808,7 @@ static struct zlib_table *zlib_mktable(unsigned char *lengths,
      * table.
      */
     return zlib_mkonetab(codes, lengths, nlengths, 0, 0,
-			 maxlen < 9 ? maxlen : 9);
+                         maxlen < 9 ? maxlen : 9);
 }
 
 static int zlib_freetable(struct zlib_table **ztab)
@@ -817,16 +817,16 @@ static int zlib_freetable(struct zlib_table **ztab)
     int code;
 
     if (ztab == NULL)
-	return -1;
+        return -1;
 
     if (*ztab == NULL)
-	return 0;
+        return 0;
 
     tab = *ztab;
 
     for (code = 0; code <= tab->mask; code++)
-	if (tab->table[code].nexttable != NULL)
-	    zlib_freetable(&tab->table[code].nexttable);
+        if (tab->table[code].nexttable != NULL)
+            zlib_freetable(&tab->table[code].nexttable);
 
     sfree(tab->table);
     tab->table = NULL;
@@ -841,13 +841,13 @@ struct zlib_decompress_ctx {
     struct zlib_table *staticlentable, *staticdisttable;
     struct zlib_table *currlentable, *currdisttable, *lenlentable;
     enum {
-	START, OUTSIDEBLK,
-	TREES_HDR, TREES_LENLEN, TREES_LEN, TREES_LENREP,
-	INBLK, GOTLENSYM, GOTLEN, GOTDISTSYM,
-	UNCOMP_LEN, UNCOMP_NLEN, UNCOMP_DATA
+        START, OUTSIDEBLK,
+        TREES_HDR, TREES_LENLEN, TREES_LEN, TREES_LENREP,
+        INBLK, GOTLENSYM, GOTLEN, GOTDISTSYM,
+        UNCOMP_LEN, UNCOMP_NLEN, UNCOMP_DATA
     } state;
     int sym, hlit, hdist, hclen, lenptr, lenextrabits, lenaddon, len,
-	lenrep;
+        lenrep;
     int uncomplen;
     unsigned char lenlen[19];
 
@@ -916,7 +916,7 @@ ssh_decompressor *zlib_decompress_init(void)
     dctx->staticlentable = zlib_mktable(lengths, 288);
     memset(lengths, 5, 32);
     dctx->staticdisttable = zlib_mktable(lengths, 32);
-    dctx->state = START;		       /* even before header */
+    dctx->state = START;                       /* even before header */
     dctx->currlentable = dctx->currdisttable = dctx->lenlentable = NULL;
     dctx->bits = 0;
     dctx->nbits = 0;
@@ -933,11 +933,11 @@ void zlib_decompress_cleanup(ssh_decompressor *dc)
         container_of(dc, struct zlib_decompress_ctx, dc);
 
     if (dctx->currlentable && dctx->currlentable != dctx->staticlentable)
-	zlib_freetable(&dctx->currlentable);
+        zlib_freetable(&dctx->currlentable);
     if (dctx->currdisttable && dctx->currdisttable != dctx->staticdisttable)
-	zlib_freetable(&dctx->currdisttable);
+        zlib_freetable(&dctx->currdisttable);
     if (dctx->lenlentable)
-	zlib_freetable(&dctx->lenlentable);
+        zlib_freetable(&dctx->lenlentable);
     zlib_freetable(&dctx->staticlentable);
     zlib_freetable(&dctx->staticdisttable);
     if (dctx->outblk)
@@ -946,34 +946,34 @@ void zlib_decompress_cleanup(ssh_decompressor *dc)
 }
 
 static int zlib_huflookup(unsigned long *bitsp, int *nbitsp,
-		   struct zlib_table *tab)
+                   struct zlib_table *tab)
 {
     unsigned long bits = *bitsp;
     int nbits = *nbitsp;
     while (1) {
-	struct zlib_tableentry *ent;
-	ent = &tab->table[bits & tab->mask];
-	if (ent->nbits > nbits)
-	    return -1;		       /* not enough data */
-	bits >>= ent->nbits;
-	nbits -= ent->nbits;
-	if (ent->code == -1)
-	    tab = ent->nexttable;
-	else {
-	    *bitsp = bits;
-	    *nbitsp = nbits;
-	    return ent->code;
-	}
-
-	if (!tab) {
-	    /*
-	     * There was a missing entry in the table, presumably
-	     * due to an invalid Huffman table description, and the
-	     * subsequent data has attempted to use the missing
-	     * entry. Return a decoding failure.
-	     */
-	    return -2;
-	}
+        struct zlib_tableentry *ent;
+        ent = &tab->table[bits & tab->mask];
+        if (ent->nbits > nbits)
+            return -1;                 /* not enough data */
+        bits >>= ent->nbits;
+        nbits -= ent->nbits;
+        if (ent->code == -1)
+            tab = ent->nexttable;
+        else {
+            *bitsp = bits;
+            *nbitsp = nbits;
+            return ent->code;
+        }
+
+        if (!tab) {
+            /*
+             * There was a missing entry in the table, presumably
+             * due to an invalid Huffman table description, and the
+             * subsequent data has attempted to use the missing
+             * entry. Return a decoding failure.
+             */
+            return -2;
+        }
     }
 }
 
@@ -995,23 +995,23 @@ bool zlib_decompress_block(ssh_decompressor *dc,
     const coderecord *rec;
     int code, blktype, rep, dist, nlen, header;
     static const unsigned char lenlenmap[] = {
-	16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+        16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
     };
 
     assert(!dctx->outblk);
     dctx->outblk = strbuf_new_nm();
 
     while (len > 0 || dctx->nbits > 0) {
-	while (dctx->nbits < 24 && len > 0) {
-	    dctx->bits |= (*block++) << dctx->nbits;
-	    dctx->nbits += 8;
-	    len--;
-	}
-	switch (dctx->state) {
-	  case START:
-	    /* Expect 16-bit zlib header. */
-	    if (dctx->nbits < 16)
-		goto finished;	       /* done all we can */
+        while (dctx->nbits < 24 && len > 0) {
+            dctx->bits |= (*block++) << dctx->nbits;
+            dctx->nbits += 8;
+            len--;
+        }
+        switch (dctx->state) {
+          case START:
+            /* Expect 16-bit zlib header. */
+            if (dctx->nbits < 16)
+                goto finished;         /* done all we can */
 
             /*
              * The header is stored as a big-endian 16-bit integer,
@@ -1038,194 +1038,194 @@ bool zlib_decompress_block(ssh_decompressor *dc,
                 (header % 31) != 0)
                 goto decode_error;
 
-	    dctx->state = OUTSIDEBLK;
-	    break;
-	  case OUTSIDEBLK:
-	    /* Expect 3-bit block header. */
-	    if (dctx->nbits < 3)
-		goto finished;	       /* done all we can */
-	    EATBITS(1);
-	    blktype = dctx->bits & 3;
-	    EATBITS(2);
-	    if (blktype == 0) {
-		int to_eat = dctx->nbits & 7;
-		dctx->state = UNCOMP_LEN;
-		EATBITS(to_eat);       /* align to byte boundary */
-	    } else if (blktype == 1) {
-		dctx->currlentable = dctx->staticlentable;
-		dctx->currdisttable = dctx->staticdisttable;
-		dctx->state = INBLK;
-	    } else if (blktype == 2) {
-		dctx->state = TREES_HDR;
-	    }
-	    break;
-	  case TREES_HDR:
-	    /*
-	     * Dynamic block header. Five bits of HLIT, five of
-	     * HDIST, four of HCLEN.
-	     */
-	    if (dctx->nbits < 5 + 5 + 4)
-		goto finished;	       /* done all we can */
-	    dctx->hlit = 257 + (dctx->bits & 31);
-	    EATBITS(5);
-	    dctx->hdist = 1 + (dctx->bits & 31);
-	    EATBITS(5);
-	    dctx->hclen = 4 + (dctx->bits & 15);
-	    EATBITS(4);
-	    dctx->lenptr = 0;
-	    dctx->state = TREES_LENLEN;
-	    memset(dctx->lenlen, 0, sizeof(dctx->lenlen));
-	    break;
-	  case TREES_LENLEN:
-	    if (dctx->nbits < 3)
-		goto finished;
-	    while (dctx->lenptr < dctx->hclen && dctx->nbits >= 3) {
-		dctx->lenlen[lenlenmap[dctx->lenptr++]] =
-		    (unsigned char) (dctx->bits & 7);
-		EATBITS(3);
-	    }
-	    if (dctx->lenptr == dctx->hclen) {
-		dctx->lenlentable = zlib_mktable(dctx->lenlen, 19);
-		dctx->state = TREES_LEN;
-		dctx->lenptr = 0;
-	    }
-	    break;
-	  case TREES_LEN:
-	    if (dctx->lenptr >= dctx->hlit + dctx->hdist) {
-		dctx->currlentable = zlib_mktable(dctx->lengths, dctx->hlit);
-		dctx->currdisttable = zlib_mktable(dctx->lengths + dctx->hlit,
-						  dctx->hdist);
-		zlib_freetable(&dctx->lenlentable);
-		dctx->lenlentable = NULL;
-		dctx->state = INBLK;
-		break;
-	    }
-	    code =
-		zlib_huflookup(&dctx->bits, &dctx->nbits, dctx->lenlentable);
-	    if (code == -1)
-		goto finished;
-	    if (code == -2)
-		goto decode_error;
-	    if (code < 16)
-		dctx->lengths[dctx->lenptr++] = code;
-	    else {
-		dctx->lenextrabits = (code == 16 ? 2 : code == 17 ? 3 : 7);
-		dctx->lenaddon = (code == 18 ? 11 : 3);
-		dctx->lenrep = (code == 16 && dctx->lenptr > 0 ?
-			       dctx->lengths[dctx->lenptr - 1] : 0);
-		dctx->state = TREES_LENREP;
-	    }
-	    break;
-	  case TREES_LENREP:
-	    if (dctx->nbits < dctx->lenextrabits)
-		goto finished;
-	    rep =
-		dctx->lenaddon +
-		(dctx->bits & ((1 << dctx->lenextrabits) - 1));
-	    EATBITS(dctx->lenextrabits);
-	    while (rep > 0 && dctx->lenptr < dctx->hlit + dctx->hdist) {
-		dctx->lengths[dctx->lenptr] = dctx->lenrep;
-		dctx->lenptr++;
-		rep--;
-	    }
-	    dctx->state = TREES_LEN;
-	    break;
-	  case INBLK:
-	    code =
-		zlib_huflookup(&dctx->bits, &dctx->nbits, dctx->currlentable);
-	    if (code == -1)
-		goto finished;
-	    if (code == -2)
-		goto decode_error;
-	    if (code < 256)
-		zlib_emit_char(dctx, code);
-	    else if (code == 256) {
-		dctx->state = OUTSIDEBLK;
-		if (dctx->currlentable != dctx->staticlentable) {
-		    zlib_freetable(&dctx->currlentable);
-		    dctx->currlentable = NULL;
-		}
-		if (dctx->currdisttable != dctx->staticdisttable) {
-		    zlib_freetable(&dctx->currdisttable);
-		    dctx->currdisttable = NULL;
-		}
-	    } else if (code < 286) {
-		dctx->state = GOTLENSYM;
-		dctx->sym = code;
-	    } else {
+            dctx->state = OUTSIDEBLK;
+            break;
+          case OUTSIDEBLK:
+            /* Expect 3-bit block header. */
+            if (dctx->nbits < 3)
+                goto finished;         /* done all we can */
+            EATBITS(1);
+            blktype = dctx->bits & 3;
+            EATBITS(2);
+            if (blktype == 0) {
+                int to_eat = dctx->nbits & 7;
+                dctx->state = UNCOMP_LEN;
+                EATBITS(to_eat);       /* align to byte boundary */
+            } else if (blktype == 1) {
+                dctx->currlentable = dctx->staticlentable;
+                dctx->currdisttable = dctx->staticdisttable;
+                dctx->state = INBLK;
+            } else if (blktype == 2) {
+                dctx->state = TREES_HDR;
+            }
+            break;
+          case TREES_HDR:
+            /*
+             * Dynamic block header. Five bits of HLIT, five of
+             * HDIST, four of HCLEN.
+             */
+            if (dctx->nbits < 5 + 5 + 4)
+                goto finished;         /* done all we can */
+            dctx->hlit = 257 + (dctx->bits & 31);
+            EATBITS(5);
+            dctx->hdist = 1 + (dctx->bits & 31);
+            EATBITS(5);
+            dctx->hclen = 4 + (dctx->bits & 15);
+            EATBITS(4);
+            dctx->lenptr = 0;
+            dctx->state = TREES_LENLEN;
+            memset(dctx->lenlen, 0, sizeof(dctx->lenlen));
+            break;
+          case TREES_LENLEN:
+            if (dctx->nbits < 3)
+                goto finished;
+            while (dctx->lenptr < dctx->hclen && dctx->nbits >= 3) {
+                dctx->lenlen[lenlenmap[dctx->lenptr++]] =
+                    (unsigned char) (dctx->bits & 7);
+                EATBITS(3);
+            }
+            if (dctx->lenptr == dctx->hclen) {
+                dctx->lenlentable = zlib_mktable(dctx->lenlen, 19);
+                dctx->state = TREES_LEN;
+                dctx->lenptr = 0;
+            }
+            break;
+          case TREES_LEN:
+            if (dctx->lenptr >= dctx->hlit + dctx->hdist) {
+                dctx->currlentable = zlib_mktable(dctx->lengths, dctx->hlit);
+                dctx->currdisttable = zlib_mktable(dctx->lengths + dctx->hlit,
+                                                  dctx->hdist);
+                zlib_freetable(&dctx->lenlentable);
+                dctx->lenlentable = NULL;
+                dctx->state = INBLK;
+                break;
+            }
+            code =
+                zlib_huflookup(&dctx->bits, &dctx->nbits, dctx->lenlentable);
+            if (code == -1)
+                goto finished;
+            if (code == -2)
+                goto decode_error;
+            if (code < 16)
+                dctx->lengths[dctx->lenptr++] = code;
+            else {
+                dctx->lenextrabits = (code == 16 ? 2 : code == 17 ? 3 : 7);
+                dctx->lenaddon = (code == 18 ? 11 : 3);
+                dctx->lenrep = (code == 16 && dctx->lenptr > 0 ?
+                               dctx->lengths[dctx->lenptr - 1] : 0);
+                dctx->state = TREES_LENREP;
+            }
+            break;
+          case TREES_LENREP:
+            if (dctx->nbits < dctx->lenextrabits)
+                goto finished;
+            rep =
+                dctx->lenaddon +
+                (dctx->bits & ((1 << dctx->lenextrabits) - 1));
+            EATBITS(dctx->lenextrabits);
+            while (rep > 0 && dctx->lenptr < dctx->hlit + dctx->hdist) {
+                dctx->lengths[dctx->lenptr] = dctx->lenrep;
+                dctx->lenptr++;
+                rep--;
+            }
+            dctx->state = TREES_LEN;
+            break;
+          case INBLK:
+            code =
+                zlib_huflookup(&dctx->bits, &dctx->nbits, dctx->currlentable);
+            if (code == -1)
+                goto finished;
+            if (code == -2)
+                goto decode_error;
+            if (code < 256)
+                zlib_emit_char(dctx, code);
+            else if (code == 256) {
+                dctx->state = OUTSIDEBLK;
+                if (dctx->currlentable != dctx->staticlentable) {
+                    zlib_freetable(&dctx->currlentable);
+                    dctx->currlentable = NULL;
+                }
+                if (dctx->currdisttable != dctx->staticdisttable) {
+                    zlib_freetable(&dctx->currdisttable);
+                    dctx->currdisttable = NULL;
+                }
+            } else if (code < 286) {
+                dctx->state = GOTLENSYM;
+                dctx->sym = code;
+            } else {
                 /* literal/length symbols 286 and 287 are invalid */
                 goto decode_error;
             }
-	    break;
-	  case GOTLENSYM:
-	    rec = &lencodes[dctx->sym - 257];
-	    if (dctx->nbits < rec->extrabits)
-		goto finished;
-	    dctx->len =
-		rec->min + (dctx->bits & ((1 << rec->extrabits) - 1));
-	    EATBITS(rec->extrabits);
-	    dctx->state = GOTLEN;
-	    break;
-	  case GOTLEN:
-	    code =
-		zlib_huflookup(&dctx->bits, &dctx->nbits,
-			       dctx->currdisttable);
-	    if (code == -1)
-		goto finished;
-	    if (code == -2)
-		goto decode_error;
-	    if (code >= 30)            /* dist symbols 30 and 31 are invalid */
-		goto decode_error;
-	    dctx->state = GOTDISTSYM;
-	    dctx->sym = code;
-	    break;
-	  case GOTDISTSYM:
-	    rec = &distcodes[dctx->sym];
-	    if (dctx->nbits < rec->extrabits)
-		goto finished;
-	    dist = rec->min + (dctx->bits & ((1 << rec->extrabits) - 1));
-	    EATBITS(rec->extrabits);
-	    dctx->state = INBLK;
-	    while (dctx->len--)
-		zlib_emit_char(dctx, dctx->window[(dctx->winpos - dist) &
-						  (WINSIZE - 1)]);
-	    break;
-	  case UNCOMP_LEN:
-	    /*
-	     * Uncompressed block. We expect to see a 16-bit LEN.
-	     */
-	    if (dctx->nbits < 16)
-		goto finished;
-	    dctx->uncomplen = dctx->bits & 0xFFFF;
-	    EATBITS(16);
-	    dctx->state = UNCOMP_NLEN;
-	    break;
-	  case UNCOMP_NLEN:
-	    /*
-	     * Uncompressed block. We expect to see a 16-bit NLEN,
-	     * which should be the one's complement of the previous
-	     * LEN.
-	     */
-	    if (dctx->nbits < 16)
-		goto finished;
-	    nlen = dctx->bits & 0xFFFF;
-	    EATBITS(16);
-	    if (dctx->uncomplen != (nlen ^ 0xFFFF))
-		goto decode_error;
-	    if (dctx->uncomplen == 0)
-		dctx->state = OUTSIDEBLK;	/* block is empty */
-	    else
-		dctx->state = UNCOMP_DATA;
-	    break;
-	  case UNCOMP_DATA:
-	    if (dctx->nbits < 8)
-		goto finished;
-	    zlib_emit_char(dctx, dctx->bits & 0xFF);
-	    EATBITS(8);
-	    if (--dctx->uncomplen == 0)
-		dctx->state = OUTSIDEBLK;	/* end of uncompressed block */
-	    break;
-	}
+            break;
+          case GOTLENSYM:
+            rec = &lencodes[dctx->sym - 257];
+            if (dctx->nbits < rec->extrabits)
+                goto finished;
+            dctx->len =
+                rec->min + (dctx->bits & ((1 << rec->extrabits) - 1));
+            EATBITS(rec->extrabits);
+            dctx->state = GOTLEN;
+            break;
+          case GOTLEN:
+            code =
+                zlib_huflookup(&dctx->bits, &dctx->nbits,
+                               dctx->currdisttable);
+            if (code == -1)
+                goto finished;
+            if (code == -2)
+                goto decode_error;
+            if (code >= 30)            /* dist symbols 30 and 31 are invalid */
+                goto decode_error;
+            dctx->state = GOTDISTSYM;
+            dctx->sym = code;
+            break;
+          case GOTDISTSYM:
+            rec = &distcodes[dctx->sym];
+            if (dctx->nbits < rec->extrabits)
+                goto finished;
+            dist = rec->min + (dctx->bits & ((1 << rec->extrabits) - 1));
+            EATBITS(rec->extrabits);
+            dctx->state = INBLK;
+            while (dctx->len--)
+                zlib_emit_char(dctx, dctx->window[(dctx->winpos - dist) &
+                                                  (WINSIZE - 1)]);
+            break;
+          case UNCOMP_LEN:
+            /*
+             * Uncompressed block. We expect to see a 16-bit LEN.
+             */
+            if (dctx->nbits < 16)
+                goto finished;
+            dctx->uncomplen = dctx->bits & 0xFFFF;
+            EATBITS(16);
+            dctx->state = UNCOMP_NLEN;
+            break;
+          case UNCOMP_NLEN:
+            /*
+             * Uncompressed block. We expect to see a 16-bit NLEN,
+             * which should be the one's complement of the previous
+             * LEN.
+             */
+            if (dctx->nbits < 16)
+                goto finished;
+            nlen = dctx->bits & 0xFFFF;
+            EATBITS(16);
+            if (dctx->uncomplen != (nlen ^ 0xFFFF))
+                goto decode_error;
+            if (dctx->uncomplen == 0)
+                dctx->state = OUTSIDEBLK;       /* block is empty */
+            else
+                dctx->state = UNCOMP_DATA;
+            break;
+          case UNCOMP_DATA:
+            if (dctx->nbits < 8)
+                goto finished;
+            zlib_emit_char(dctx, dctx->bits & 0xFF);
+            EATBITS(8);
+            if (--dctx->uncomplen == 0)
+                dctx->state = OUTSIDEBLK;       /* end of uncompressed block */
+            break;
+        }
     }
 
   finished:

+ 5 - 5
source/putty/storage.h

@@ -25,7 +25,7 @@
  * A given key will be written at most once while saving a session.
  * Keys may be up to 255 characters long.  String values have no length
  * limit.
- * 
+ *
  * Any returned error message must be freed after use.
  */
 settings_w *open_settings_w(const char *sessionname, char **errmsg);
@@ -42,12 +42,12 @@ void close_settings_w(settings_w *handle);
  * open_setting_r() to get a `void *' handle, then pass that to a
  * number of calls to read_setting_s() and read_setting_i(), and
  * then close it using close_settings_r().
- * 
+ *
  * read_setting_s() returns a dynamically allocated string which the
  * caller must free. read_setting_filename() and
  * read_setting_fontspec() likewise return dynamically allocated
  * structures.
- * 
+ *
  * If a particular string setting is not present in the session,
  * read_setting_s() can return NULL, in which case the caller
  * should invent a sensible default. If an integer setting is not
@@ -86,7 +86,7 @@ int retrieve_host_key(const char *hostname, int port,
  * or 2 (entry exists in database and is different).
  */
 int verify_host_key(const char *hostname, int port,
-		    const char *keytype, const char *key);
+                    const char *keytype, const char *key);
 #endif
 
 /*
@@ -94,7 +94,7 @@ int verify_host_key(const char *hostname, int port,
  * entry that might have been there.
  */
 void store_host_key(const char *hostname, int port,
-		    const char *keytype, const char *key);
+                    const char *keytype, const char *key);
 
 /* ----------------------------------------------------------------------
  * Functions to access PuTTY's random number seed file.

Разница между файлами не показана из-за своего большого размера
+ 654 - 654
source/putty/tree234.c


+ 21 - 21
source/putty/tree234.h

@@ -1,8 +1,8 @@
 /*
  * tree234.h: header defining functions in tree234.c.
- * 
+ *
  * This file is copyright 1999-2001 Simon Tatham.
- * 
+ *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
  * files (the "Software"), to deal in the Software without
@@ -11,10 +11,10 @@
  * sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following
  * conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -57,7 +57,7 @@ void *add234(tree234 * t, void *e);
  * Add an element e to an unsorted 2-3-4 tree t. Returns e on
  * success, NULL on failure. (Failure should only occur if the
  * index is out of range or the tree is sorted.)
- * 
+ *
  * Index range can be from 0 to the tree's current element count,
  * inclusive.
  */
@@ -66,14 +66,14 @@ void *addpos234(tree234 * t, void *e, int index);
 /*
  * Look up the element at a given numeric index in a 2-3-4 tree.
  * Returns NULL if the index is out of range.
- * 
+ *
  * One obvious use for this function is in iterating over the whole
  * of a tree (sorted or unsorted):
- * 
+ *
  *   for (i = 0; (p = index234(tree, i)) != NULL; i++) consume(p);
- * 
+ *
  * or
- * 
+ *
  *   int maxcount = count234(tree);
  *   for (i = 0; i < maxcount; i++) {
  *       p = index234(tree, i);
@@ -89,36 +89,36 @@ void *index234(tree234 * t, int index);
  * can be an asymmetric function if desired. cmp can also be passed
  * as NULL, in which case the compare function from the tree proper
  * will be used.
- * 
+ *
  * Three of these functions are special cases of findrelpos234. The
  * non-`pos' variants lack the `index' parameter: if the parameter
  * is present and non-NULL, it must point to an integer variable
  * which will be filled with the numeric index of the returned
  * element.
- * 
+ *
  * The non-`rel' variants lack the `relation' parameter. This
  * parameter allows you to specify what relation the element you
  * provide has to the element you're looking for. This parameter
  * can be:
- * 
+ *
  *   REL234_EQ     - find only an element that compares equal to e
  *   REL234_LT     - find the greatest element that compares < e
  *   REL234_LE     - find the greatest element that compares <= e
  *   REL234_GT     - find the smallest element that compares > e
  *   REL234_GE     - find the smallest element that compares >= e
- * 
+ *
  * Non-`rel' variants assume REL234_EQ.
- * 
+ *
  * If `rel' is REL234_GT or REL234_LT, the `e' parameter may be
  * NULL. In this case, REL234_GT will return the smallest element
  * in the tree, and REL234_LT will return the greatest. This gives
  * an alternative means of iterating over a sorted tree, instead of
  * using index234:
- * 
+ *
  *   // to loop forwards
  *   for (p = NULL; (p = findrel234(tree, p, NULL, REL234_GT)) != NULL ;)
  *       consume(p);
- * 
+ *
  *   // to loop backwards
  *   for (p = NULL; (p = findrel234(tree, p, NULL, REL234_LT)) != NULL ;)
  *       consume(p);
@@ -130,7 +130,7 @@ void *find234(tree234 * t, void *e, cmpfn234 cmp);
 void *findrel234(tree234 * t, void *e, cmpfn234 cmp, int relation);
 void *findpos234(tree234 * t, void *e, cmpfn234 cmp, int *index);
 void *findrelpos234(tree234 * t, void *e, cmpfn234 cmp, int relation,
-		    int *index);
+                    int *index);
 
 /*
  * A more general search type still. Use search234_start() to
@@ -170,15 +170,15 @@ void search234_step(search234_state *state, int direction);
 /*
  * Delete an element e in a 2-3-4 tree. Does not free the element,
  * merely removes all links to it from the tree nodes.
- * 
+ *
  * delpos234 deletes the element at a particular tree index: it
  * works on both sorted and unsorted trees.
- * 
+ *
  * del234 deletes the element passed to it, so it only works on
  * sorted trees. (It's equivalent to using findpos234 to determine
  * the index of an element, and then passing that index to
  * delpos234.)
- * 
+ *
  * Both functions return a pointer to the element they delete, for
  * the user to free or pass on elsewhere or whatever. If the index
  * is out of range (delpos234) or the element is already not in the
@@ -192,4 +192,4 @@ void *delpos234(tree234 * t, int index);
  */
 int count234(tree234 * t);
 
-#endif				/* TREE234_H */
+#endif                          /* TREE234_H */

+ 182 - 182
source/putty/utils.c

@@ -32,21 +32,21 @@ unsigned long parse_blocksize(const char *bs)
     char *suf;
     unsigned long r = strtoul(bs, &suf, 10);
     if (*suf != '\0') {
-	while (*suf && isspace((unsigned char)*suf)) suf++;
-	switch (*suf) {
-	  case 'k': case 'K':
-	    r *= 1024ul;
-	    break;
-	  case 'm': case 'M':
-	    r *= 1024ul * 1024ul;
-	    break;
-	  case 'g': case 'G':
-	    r *= 1024ul * 1024ul * 1024ul;
-	    break;
-	  case '\0':
-	  default:
-	    break;
-	}
+        while (*suf && isspace((unsigned char)*suf)) suf++;
+        switch (*suf) {
+          case 'k': case 'K':
+            r *= 1024ul;
+            break;
+          case 'm': case 'M':
+            r *= 1024ul * 1024ul;
+            break;
+          case 'g': case 'G':
+            r *= 1024ul * 1024ul * 1024ul;
+            break;
+          case '\0':
+          default:
+            break;
+        }
     }
     return r;
 }
@@ -58,39 +58,39 @@ unsigned long parse_blocksize(const char *bs)
  * The precise current parsing is an oddity inherited from the terminal
  * answerback-string parsing code. All sequences start with ^; all except
  * ^<123> are two characters. The ones that are worth keeping are probably:
- *   ^?		    127
- *   ^@A-Z[\]^_	    0-31
- *   a-z	    1-26
- *   <num>	    specified by number (decimal, 0octal, 0xHEX)
- *   ~		    ^ escape
+ *   ^?             127
+ *   ^@A-Z[\]^_     0-31
+ *   a-z            1-26
+ *   <num>          specified by number (decimal, 0octal, 0xHEX)
+ *   ~              ^ escape
  */
 char ctrlparse(char *s, char **next)
 {
     char c = 0;
     if (*s != '^') {
-	*next = NULL;
+        *next = NULL;
     } else {
-	s++;
-	if (*s == '\0') {
-	    *next = NULL;
-	} else if (*s == '<') {
-	    s++;
-	    c = (char)strtol(s, next, 0);
-	    if ((*next == s) || (**next != '>')) {
-		c = 0;
-		*next = NULL;
-	    } else
-		(*next)++;
-	} else if (*s >= 'a' && *s <= 'z') {
-	    c = (*s - ('a' - 1));
-	    *next = s+1;
-	} else if ((*s >= '@' && *s <= '_') || *s == '?' || (*s & 0x80)) {
-	    c = ('@' ^ *s);
-	    *next = s+1;
-	} else if (*s == '~') {
-	    c = '^';
-	    *next = s+1;
-	}
+        s++;
+        if (*s == '\0') {
+            *next = NULL;
+        } else if (*s == '<') {
+            s++;
+            c = (char)strtol(s, next, 0);
+            if ((*next == s) || (**next != '>')) {
+                c = 0;
+                *next = NULL;
+            } else
+                (*next)++;
+        } else if (*s >= 'a' && *s <= 'z') {
+            c = (*s - ('a' - 1));
+            *next = s+1;
+        } else if ((*s >= '@' && *s <= '_') || *s == '?' || (*s & 0x80)) {
+            c = ('@' ^ *s);
+            *next = s+1;
+        } else if (*s == '~') {
+            c = '^';
+            *next = s+1;
+        }
     }
     return c;
 }
@@ -258,10 +258,10 @@ char *dupcat(const char *s1, ...)
     len = strlen(s1);
     va_start(ap, s1);
     while (1) {
-	sn = va_arg(ap, char *);
-	if (!sn)
-	    break;
-	len += strlen(sn);
+        sn = va_arg(ap, char *);
+        if (!sn)
+            break;
+        len += strlen(sn);
     }
     va_end(ap);
 
@@ -271,11 +271,11 @@ char *dupcat(const char *s1, ...)
 
     va_start(ap, s1);
     while (1) {
-	sn = va_arg(ap, char *);
-	if (!sn)
-	    break;
-	strcpy(q, sn);
-	q += strlen(q);
+        sn = va_arg(ap, char *);
+        if (!sn)
+            break;
+        strcpy(q, sn);
+        q += strlen(q);
     }
     va_end(ap);
 
@@ -317,21 +317,21 @@ int string_length_for_printf(size_t s)
 
 /*
  * Do an sprintf(), but into a custom-allocated buffer.
- * 
+ *
  * Currently I'm doing this via vsnprintf. This has worked so far,
  * but it's not good, because vsnprintf is not available on all
  * platforms. There's an ifdef to use `_vsnprintf', which seems
  * to be the local name for it on Windows. Other platforms may
  * lack it completely, in which case it'll be time to rewrite
  * this function in a totally different way.
- * 
+ *
  * The only `properly' portable solution I can think of is to
  * implement my own format string scanner, which figures out an
  * upper bound for the length of each formatting directive,
  * allocates the buffer as it goes along, and calls sprintf() to
  * actually process each directive. If I ever need to actually do
  * this, some caveats:
- * 
+ *
  *  - It's very hard to find a reliable upper bound for
  *    floating-point values. %f, in particular, when supplied with
  *    a number near to the upper or lower limit of representable
@@ -340,10 +340,10 @@ int string_length_for_printf(size_t s)
  *    constants in <float.h>, or even to predict it dynamically by
  *    looking at the exponent of the specific float provided, but
  *    it won't be fun.
- * 
+ *
  *  - Don't forget to _check_, after calling sprintf, that it's
  *    used at most the amount of space we had available.
- * 
+ *
  *  - Fault any formatting directive we don't fully understand. The
  *    aim here is to _guarantee_ that we never overflow the buffer,
  *    because this is a security-critical function. If we see a
@@ -357,8 +357,8 @@ static char *dupvprintf_inner(char *buf, size_t oldlen, size_t *sizeptr,
     sgrowarrayn_nm(buf, size, oldlen, 512);
 
     while (1) {
-	va_list aq;
-	va_copy(aq, ap);
+        va_list aq;
+        va_copy(aq, ap);
 	{ // WINSCP
 #if defined _DEBUG && defined IDE
 // CodeGuard hangs in v*printf functions. But while it's possible to disable CodeGuard in vsprintf, it's not possible for vsnprintf.
@@ -368,24 +368,24 @@ static char *dupvprintf_inner(char *buf, size_t oldlen, size_t *sizeptr,
 // Disable=yes
 	int len = vsprintf(buf + oldlen, fmt, aq);
 #else
-	int len = vsnprintf(buf + oldlen, size - oldlen, fmt, aq);
+        int len = vsnprintf(buf + oldlen, size - oldlen, fmt, aq);
 #endif
-	va_end(aq);
+        va_end(aq);
 
-	if (len >= 0 && len < size) {
-	    /* This is the C99-specified criterion for snprintf to have
-	     * been completely successful. */
+        if (len >= 0 && len < size) {
+            /* This is the C99-specified criterion for snprintf to have
+             * been completely successful. */
             *sizeptr = size;
-	    return buf;
-	} else if (len > 0) {
-	    /* This is the C99 error condition: the returned length is
-	     * the required buffer size not counting the NUL. */
-	    sgrowarrayn_nm(buf, size, oldlen + 1, len);
-	} else {
-	    /* This is the pre-C99 glibc error condition: <0 means the
-	     * buffer wasn't big enough, so we enlarge it a bit and hope. */
-	    sgrowarray_nm(buf, size, size);
-	}
+            return buf;
+        } else if (len > 0) {
+            /* This is the C99 error condition: the returned length is
+             * the required buffer size not counting the NUL. */
+            sgrowarrayn_nm(buf, size, oldlen + 1, len);
+        } else {
+            /* This is the pre-C99 glibc error condition: <0 means the
+             * buffer wasn't big enough, so we enlarge it a bit and hope. */
+            sgrowarray_nm(buf, size, size);
+        }
 	} // WINSCP
     }
 }
@@ -502,14 +502,14 @@ char *fgetline(FILE *fp)
     char *ret = snewn(512, char);
     size_t size = 512, len = 0;
     while (fgets(ret + len, size - len, fp)) {
-	len += strlen(ret + len);
-	if (len > 0 && ret[len-1] == '\n')
-	    break;		       /* got a newline, we're done */
+        len += strlen(ret + len);
+        if (len > 0 && ret[len-1] == '\n')
+            break;                     /* got a newline, we're done */
         sgrowarrayn_nm(ret, size, len, 512);
     }
-    if (len == 0) {		       /* first fgets returned NULL */
-	sfree(ret);
-	return NULL;
+    if (len == 0) {                    /* first fgets returned NULL */
+        sfree(ret);
+        return NULL;
     }
     ret[len] = '\0';
     return ret;
@@ -554,25 +554,25 @@ char *chomp(char *str)
 void base64_encode_atom(const unsigned char *data, int n, char *out)
 {
     static const char base64_chars[] =
-	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
     unsigned word;
 
     word = data[0] << 16;
     if (n > 1)
-	word |= data[1] << 8;
+        word |= data[1] << 8;
     if (n > 2)
-	word |= data[2];
+        word |= data[2];
     out[0] = base64_chars[(word >> 18) & 0x3F];
     out[1] = base64_chars[(word >> 12) & 0x3F];
     if (n > 1)
-	out[2] = base64_chars[(word >> 6) & 0x3F];
+        out[2] = base64_chars[(word >> 6) & 0x3F];
     else
-	out[2] = '=';
+        out[2] = '=';
     if (n > 2)
-	out[3] = base64_chars[word & 0x3F];
+        out[3] = base64_chars[word & 0x3F];
     else
-	out[3] = '=';
+        out[3] = '=';
 }
 
 int base64_decode_atom(const char *atom, unsigned char *out)
@@ -583,50 +583,50 @@ int base64_decode_atom(const char *atom, unsigned char *out)
     char c;
 
     for (i = 0; i < 4; i++) {
-	c = atom[i];
-	if (c >= 'A' && c <= 'Z')
-	    v = c - 'A';
-	else if (c >= 'a' && c <= 'z')
-	    v = c - 'a' + 26;
-	else if (c >= '0' && c <= '9')
-	    v = c - '0' + 52;
-	else if (c == '+')
-	    v = 62;
-	else if (c == '/')
-	    v = 63;
-	else if (c == '=')
-	    v = -1;
-	else
-	    return 0;		       /* invalid atom */
-	vals[i] = v;
+        c = atom[i];
+        if (c >= 'A' && c <= 'Z')
+            v = c - 'A';
+        else if (c >= 'a' && c <= 'z')
+            v = c - 'a' + 26;
+        else if (c >= '0' && c <= '9')
+            v = c - '0' + 52;
+        else if (c == '+')
+            v = 62;
+        else if (c == '/')
+            v = 63;
+        else if (c == '=')
+            v = -1;
+        else
+            return 0;                  /* invalid atom */
+        vals[i] = v;
     }
 
     if (vals[0] == -1 || vals[1] == -1)
-	return 0;
+        return 0;
     if (vals[2] == -1 && vals[3] != -1)
-	return 0;
+        return 0;
 
     if (vals[3] != -1)
-	len = 3;
+        len = 3;
     else if (vals[2] != -1)
-	len = 2;
+        len = 2;
     else
-	len = 1;
+        len = 1;
 
     word = ((vals[0] << 18) |
-	    (vals[1] << 12) | ((vals[2] & 0x3F) << 6) | (vals[3] & 0x3F));
+            (vals[1] << 12) | ((vals[2] & 0x3F) << 6) | (vals[3] & 0x3F));
     out[0] = (word >> 16) & 0xFF;
     if (len > 1)
-	out[1] = (word >> 8) & 0xFF;
+        out[1] = (word >> 8) & 0xFF;
     if (len > 2)
-	out[2] = word & 0xFF;
+        out[2] = word & 0xFF;
     return len;
 }
 
 /* ----------------------------------------------------------------------
  * Generic routines to deal with send buffers: a linked list of
  * smallish blocks, with the operations
- * 
+ *
  *  - add an arbitrary amount of data to the end of the list
  *  - remove the first N bytes from the list
  *  - return a (pointer,length) pair giving some initial data in
@@ -663,10 +663,10 @@ void bufchain_clear(bufchain *ch)
 {
     struct bufchain_granule *b;
     while (ch->head) {
-	b = ch->head;
-	ch->head = ch->head->next;
+        b = ch->head;
+        ch->head = ch->head->next;
         smemclr(b, sizeof(*b));
-	sfree(b);
+        sfree(b);
     }
     ch->tail = NULL;
     ch->buffersize = 0;
@@ -694,28 +694,28 @@ void bufchain_add(bufchain *ch, const void *data, size_t len)
     ch->buffersize += len;
 
     while (len > 0) {
-	if (ch->tail && ch->tail->bufend < ch->tail->bufmax) {
-	    size_t copylen = min(len, ch->tail->bufmax - ch->tail->bufend);
-	    memcpy(ch->tail->bufend, buf, copylen);
-	    buf += copylen;
-	    len -= copylen;
-	    ch->tail->bufend += copylen;
-	}
-	if (len > 0) {
-	    size_t grainlen =
-		max(sizeof(struct bufchain_granule) + len, BUFFER_MIN_GRANULE);
-	    struct bufchain_granule *newbuf;
-	    newbuf = smalloc(grainlen);
-	    newbuf->bufpos = newbuf->bufend =
-		(char *)newbuf + sizeof(struct bufchain_granule);
-	    newbuf->bufmax = (char *)newbuf + grainlen;
-	    newbuf->next = NULL;
-	    if (ch->tail)
-		ch->tail->next = newbuf;
-	    else
-		ch->head = newbuf;
-	    ch->tail = newbuf;
-	}
+        if (ch->tail && ch->tail->bufend < ch->tail->bufmax) {
+            size_t copylen = min(len, ch->tail->bufmax - ch->tail->bufend);
+            memcpy(ch->tail->bufend, buf, copylen);
+            buf += copylen;
+            len -= copylen;
+            ch->tail->bufend += copylen;
+        }
+        if (len > 0) {
+            size_t grainlen =
+                max(sizeof(struct bufchain_granule) + len, BUFFER_MIN_GRANULE);
+            struct bufchain_granule *newbuf;
+            newbuf = smalloc(grainlen);
+            newbuf->bufpos = newbuf->bufend =
+                (char *)newbuf + sizeof(struct bufchain_granule);
+            newbuf->bufmax = (char *)newbuf + grainlen;
+            newbuf->next = NULL;
+            if (ch->tail)
+                ch->tail->next = newbuf;
+            else
+                ch->head = newbuf;
+            ch->tail = newbuf;
+        }
     }
 
     if (ch->ic)
@@ -728,20 +728,20 @@ void bufchain_consume(bufchain *ch, size_t len)
 
     assert(ch->buffersize >= len);
     while (len > 0) {
-	int remlen = len;
-	assert(ch->head != NULL);
-	if (remlen >= ch->head->bufend - ch->head->bufpos) {
-	    remlen = ch->head->bufend - ch->head->bufpos;
-	    tmp = ch->head;
-	    ch->head = tmp->next;
-	    if (!ch->head)
-		ch->tail = NULL;
+        int remlen = len;
+        assert(ch->head != NULL);
+        if (remlen >= ch->head->bufend - ch->head->bufpos) {
+            remlen = ch->head->bufend - ch->head->bufpos;
+            tmp = ch->head;
+            ch->head = tmp->next;
+            if (!ch->head)
+                ch->tail = NULL;
             smemclr(tmp, sizeof(*tmp));
-	    sfree(tmp);
-	} else
-	    ch->head->bufpos += remlen;
-	ch->buffersize -= remlen;
-	len -= remlen;
+            sfree(tmp);
+        } else
+            ch->head->bufpos += remlen;
+        ch->buffersize -= remlen;
+        len -= remlen;
     }
 }
 
@@ -759,16 +759,16 @@ void bufchain_fetch(bufchain *ch, void *data, size_t len)
 
     assert(ch->buffersize >= len);
     while (len > 0) {
-	int remlen = len;
+        int remlen = len;
 
-	assert(tmp != NULL);
-	if (remlen >= tmp->bufend - tmp->bufpos)
-	    remlen = tmp->bufend - tmp->bufpos;
-	memcpy(data_c, tmp->bufpos, remlen);
+        assert(tmp != NULL);
+        if (remlen >= tmp->bufend - tmp->bufpos)
+            remlen = tmp->bufend - tmp->bufpos;
+        memcpy(data_c, tmp->bufpos, remlen);
 
-	tmp = tmp->next;
-	len -= remlen;
-	data_c += remlen;
+        tmp = tmp->next;
+        len -= remlen;
+        data_c += remlen;
     }
 }
 
@@ -822,36 +822,36 @@ void debug_memdump(const void *buf, int len, bool L)
     const unsigned char *p = buf;
     char foo[17];
     if (L) {
-	int delta;
-	debug_printf("\t%d (0x%x) bytes:\n", len, len);
-	delta = 15 & (uintptr_t)p;
-	p -= delta;
-	len += delta;
+        int delta;
+        debug_printf("\t%d (0x%x) bytes:\n", len, len);
+        delta = 15 & (uintptr_t)p;
+        p -= delta;
+        len += delta;
     }
     for (; 0 < len; p += 16, len -= 16) {
-	dputs("  ");
-	if (L)
-	    debug_printf("%p: ", p);
-	strcpy(foo, "................");	/* sixteen dots */
-	for (i = 0; i < 16 && i < len; ++i) {
-	    if (&p[i] < (unsigned char *) buf) {
-		dputs("   ");	       /* 3 spaces */
-		foo[i] = ' ';
-	    } else {
-		debug_printf("%c%02.2x",
-			&p[i] != (unsigned char *) buf
-			&& i % 4 ? '.' : ' ', p[i]
-		    );
-		if (p[i] >= ' ' && p[i] <= '~')
-		    foo[i] = (char) p[i];
-	    }
-	}
-	foo[i] = '\0';
-	debug_printf("%*s%s\n", (16 - i) * 3 + 2, "", foo);
+        dputs("  ");
+        if (L)
+            debug_printf("%p: ", p);
+        strcpy(foo, "................");        /* sixteen dots */
+        for (i = 0; i < 16 && i < len; ++i) {
+            if (&p[i] < (unsigned char *) buf) {
+                dputs("   ");          /* 3 spaces */
+                foo[i] = ' ';
+            } else {
+                debug_printf("%c%02.2x",
+                        &p[i] != (unsigned char *) buf
+                        && i % 4 ? '.' : ' ', p[i]
+                    );
+                if (p[i] >= ' ' && p[i] <= '~')
+                    foo[i] = (char) p[i];
+            }
+        }
+        foo[i] = '\0';
+        debug_printf("%*s%s\n", (16 - i) * 3 + 2, "", foo);
     }
 }
 
-#endif				/* def DEBUG */
+#endif                          /* def DEBUG */
 
 #ifndef PLATFORM_HAS_SMEMCLR
 /*

+ 195 - 195
source/putty/wildcard.c

@@ -14,7 +14,7 @@
 
 /*
  * Definition of wildcard syntax:
- * 
+ *
  *  - * matches any sequence of characters, including zero.
  *  - ? matches exactly one character which can be anything.
  *  - [abc] matches exactly one character which is a, b or c.
@@ -51,7 +51,7 @@
  * absence of any other need for the NFA->DFA translation engine,
  * anything more than the simplest possible wildcard matcher is
  * vast code-size overkill.
- * 
+ *
  * Essentially, these wildcards are much simpler than regexps in
  * that they consist of a sequence of rigid fragments (? and [...]
  * can never match more or less than one character) separated by
@@ -80,11 +80,11 @@ const char *wc_error(int value)
     value = abs(value);
     switch (value) {
       case WC_TRAILINGBACKSLASH:
-	return "'\' occurred at end of string (expected another character)";
+        return "'\' occurred at end of string (expected another character)";
       case WC_UNCLOSEDCLASS:
-	return "expected ']' to close character class";
+        return "expected ']' to close character class";
       case WC_INVALIDRANGE:
-	return "character range was not terminated (']' just after '-')";
+        return "character range was not terminated (']' just after '-')";
     }
     return "INTERNAL ERROR: unrecognised wildcard error number";
 }
@@ -109,93 +109,93 @@ static int wc_match_fragment(const char **fragment, const char **target,
      * the first (unescaped) *.
      */
     while (*f && *f != '*' && t < target_end) {
-	/*
-	 * Extract one character from t, and one character's worth
-	 * of pattern from f, and step along both. Return 0 if they
-	 * fail to match.
-	 */
-	if (*f == '\\') {
-	    /*
-	     * Backslash, which means f[1] is to be treated as a
-	     * literal character no matter what it is. It may not
-	     * be the end of the string.
-	     */
-	    if (!f[1])
-		return -WC_TRAILINGBACKSLASH;   /* error */
-	    if (f[1] != *t)
-		return 0;	       /* failed to match */
-	    f += 2;
-	} else if (*f == '?') {
-	    /*
-	     * Question mark matches anything.
-	     */
-	    f++;
-	} else if (*f == '[') {
-	    bool invert = false;
-	    bool matched = false;
-	    /*
-	     * Open bracket introduces a character class.
-	     */
-	    f++;
-	    if (*f == '^') {
-		invert = true;
-		f++;
-	    }
-	    while (*f != ']') {
-		if (*f == '\\')
-		    f++;	       /* backslashes still work */
-		if (!*f)
-		    return -WC_UNCLOSEDCLASS;   /* error again */
-		if (f[1] == '-') {
-		    int lower, upper, ourchr;
-		    lower = (unsigned char) *f++;
-		    f++;	       /* eat the minus */
-		    if (*f == ']')
-			return -WC_INVALIDRANGE;   /* different error! */
-		    if (*f == '\\')
-			f++;	       /* backslashes _still_ work */
-		    if (!*f)
-			return -WC_UNCLOSEDCLASS;   /* error again */
-		    upper = (unsigned char) *f++;
-		    ourchr = (unsigned char) *t;
-		    if (lower > upper) {
-			int t = lower; lower = upper; upper = t;
-		    }
-		    if (ourchr >= lower && ourchr <= upper)
-			matched = true;
-		} else {
-		    matched |= (*t == *f++);
-		}
-	    }
-	    if (invert == matched)
-		return 0;	       /* failed to match character class */
-	    f++;		       /* eat the ] */
-	} else {
-	    /*
-	     * Non-special character matches itself.
-	     */
-	    if (*f != *t)
-		return 0;
-	    f++;
-	}
-	/*
-	 * Now we've done that, increment t past the character we
-	 * matched.
-	 */
-	t++;
+        /*
+         * Extract one character from t, and one character's worth
+         * of pattern from f, and step along both. Return 0 if they
+         * fail to match.
+         */
+        if (*f == '\\') {
+            /*
+             * Backslash, which means f[1] is to be treated as a
+             * literal character no matter what it is. It may not
+             * be the end of the string.
+             */
+            if (!f[1])
+                return -WC_TRAILINGBACKSLASH;   /* error */
+            if (f[1] != *t)
+                return 0;              /* failed to match */
+            f += 2;
+        } else if (*f == '?') {
+            /*
+             * Question mark matches anything.
+             */
+            f++;
+        } else if (*f == '[') {
+            bool invert = false;
+            bool matched = false;
+            /*
+             * Open bracket introduces a character class.
+             */
+            f++;
+            if (*f == '^') {
+                invert = true;
+                f++;
+            }
+            while (*f != ']') {
+                if (*f == '\\')
+                    f++;               /* backslashes still work */
+                if (!*f)
+                    return -WC_UNCLOSEDCLASS;   /* error again */
+                if (f[1] == '-') {
+                    int lower, upper, ourchr;
+                    lower = (unsigned char) *f++;
+                    f++;               /* eat the minus */
+                    if (*f == ']')
+                        return -WC_INVALIDRANGE;   /* different error! */
+                    if (*f == '\\')
+                        f++;           /* backslashes _still_ work */
+                    if (!*f)
+                        return -WC_UNCLOSEDCLASS;   /* error again */
+                    upper = (unsigned char) *f++;
+                    ourchr = (unsigned char) *t;
+                    if (lower > upper) {
+                        int t = lower; lower = upper; upper = t;
+                    }
+                    if (ourchr >= lower && ourchr <= upper)
+                        matched = true;
+                } else {
+                    matched |= (*t == *f++);
+                }
+            }
+            if (invert == matched)
+                return 0;              /* failed to match character class */
+            f++;                       /* eat the ] */
+        } else {
+            /*
+             * Non-special character matches itself.
+             */
+            if (*f != *t)
+                return 0;
+            f++;
+        }
+        /*
+         * Now we've done that, increment t past the character we
+         * matched.
+         */
+        t++;
     }
     if (!*f || *f == '*') {
-	/*
-	 * We have reached the end of f without finding a mismatch;
-	 * so we're done. Update the caller pointers and return 1.
-	 */
-	*fragment = f;
-	*target = t;
-	return 1;
+        /*
+         * We have reached the end of f without finding a mismatch;
+         * so we're done. Update the caller pointers and return 1.
+         */
+        *fragment = f;
+        *target = t;
+        return 1;
     }
     /*
      * Otherwise, we must have reached the end of t before we
-     * reached the end of f; so we've failed. Return 0. 
+     * reached the end of f; so we've failed. Return 0.
      */
     return 0;
 }
@@ -219,74 +219,74 @@ static int wc_match_inner(
      * routine once and give up if it fails.
      */
     if (*wildcard != '*') {
-	ret = wc_match_fragment(&wildcard, &target, target_end);
-	if (ret <= 0)
-	    return ret;		       /* pass back failure or error alike */
+        ret = wc_match_fragment(&wildcard, &target, target_end);
+        if (ret <= 0)
+            return ret;                /* pass back failure or error alike */
     }
 
     while (*wildcard) {
-	assert(*wildcard == '*');
-	while (*wildcard == '*')
-	    wildcard++;
-
-	/*
-	 * It's possible we've just hit the end of the wildcard
-	 * after seeing a *, in which case there's no need to
-	 * bother searching any more because we've won.
-	 */
-	if (!*wildcard)
-	    return 1;
-
-	/*
-	 * Now `wildcard' points at the next fragment. So we
-	 * attempt to match it against `target', and if that fails
-	 * we increment `target' and try again, and so on. When we
-	 * find we're about to try matching against the empty
-	 * string, we give up and return 0.
-	 */
-	ret = 0;
-	while (*target) {
-	    const char *save_w = wildcard, *save_t = target;
-
-	    ret = wc_match_fragment(&wildcard, &target, target_end);
-
-	    if (ret < 0)
-		return ret;	       /* syntax error */
-
-	    if (ret > 0 && !*wildcard && target != target_end) {
-		/*
-		 * Final special case - literally.
-		 * 
-		 * This situation arises when we are matching a
-		 * _terminal_ fragment of the wildcard (that is,
-		 * there is nothing after it, e.g. "*a"), and it
-		 * has matched _too early_. For example, matching
-		 * "*a" against "parka" will match the "a" fragment
-		 * against the _first_ a, and then (if it weren't
-		 * for this special case) matching would fail
-		 * because we're at the end of the wildcard but not
-		 * at the end of the target string.
-		 * 
-		 * In this case what we must do is measure the
-		 * length of the fragment in the target (which is
-		 * why we saved `target'), jump straight to that
-		 * distance from the end of the string using
-		 * strlen, and match the same fragment again there
-		 * (which is why we saved `wildcard'). Then we
-		 * return whatever that operation returns.
-		 */
-		target = target_end - (target - save_t);
-		wildcard = save_w;
-		return wc_match_fragment(&wildcard, &target, target_end);
-	    }
-
-	    if (ret > 0)
-		break;
-	    target++;
-	}
-	if (ret > 0)
-	    continue;
-	return 0;
+        assert(*wildcard == '*');
+        while (*wildcard == '*')
+            wildcard++;
+
+        /*
+         * It's possible we've just hit the end of the wildcard
+         * after seeing a *, in which case there's no need to
+         * bother searching any more because we've won.
+         */
+        if (!*wildcard)
+            return 1;
+
+        /*
+         * Now `wildcard' points at the next fragment. So we
+         * attempt to match it against `target', and if that fails
+         * we increment `target' and try again, and so on. When we
+         * find we're about to try matching against the empty
+         * string, we give up and return 0.
+         */
+        ret = 0;
+        while (*target) {
+            const char *save_w = wildcard, *save_t = target;
+
+            ret = wc_match_fragment(&wildcard, &target, target_end);
+
+            if (ret < 0)
+                return ret;            /* syntax error */
+
+            if (ret > 0 && !*wildcard && target != target_end) {
+                /*
+                 * Final special case - literally.
+                 *
+                 * This situation arises when we are matching a
+                 * _terminal_ fragment of the wildcard (that is,
+                 * there is nothing after it, e.g. "*a"), and it
+                 * has matched _too early_. For example, matching
+                 * "*a" against "parka" will match the "a" fragment
+                 * against the _first_ a, and then (if it weren't
+                 * for this special case) matching would fail
+                 * because we're at the end of the wildcard but not
+                 * at the end of the target string.
+                 *
+                 * In this case what we must do is measure the
+                 * length of the fragment in the target (which is
+                 * why we saved `target'), jump straight to that
+                 * distance from the end of the string using
+                 * strlen, and match the same fragment again there
+                 * (which is why we saved `wildcard'). Then we
+                 * return whatever that operation returns.
+                 */
+                target = target_end - (target - save_t);
+                wildcard = save_w;
+                return wc_match_fragment(&wildcard, &target, target_end);
+            }
+
+            if (ret > 0)
+                break;
+            target++;
+        }
+        if (ret > 0)
+            continue;
+        return 0;
     }
 
     /*
@@ -314,7 +314,7 @@ int wc_match_pl(const char *wildcard, ptrlen target)
  * Expects a target string buffer of anything up to the length of
  * the original wildcard. You can also pass NULL as the output
  * buffer if you're only interested in the return value.
- * 
+ *
  * Returns true on success, or false if a wildcard character was
  * encountered. In the latter case the output string MAY not be
  * zero-terminated and you should not use it for anything!
@@ -322,22 +322,22 @@ int wc_match_pl(const char *wildcard, ptrlen target)
 bool wc_unescape(char *output, const char *wildcard)
 {
     while (*wildcard) {
-	if (*wildcard == '\\') {
-	    wildcard++;
-	    /* We are lenient about trailing backslashes in non-wildcards. */
-	    if (*wildcard) {
-		if (output)
-		    *output++ = *wildcard;
-		wildcard++;
-	    }
-	} else if (*wildcard == '*' || *wildcard == '?' ||
-		   *wildcard == '[' || *wildcard == ']') {
-	    return false;              /* it's a wildcard! */
-	} else {
-	    if (output)
-		*output++ = *wildcard;
-	    wildcard++;
-	}
+        if (*wildcard == '\\') {
+            wildcard++;
+            /* We are lenient about trailing backslashes in non-wildcards. */
+            if (*wildcard) {
+                if (output)
+                    *output++ = *wildcard;
+                wildcard++;
+            }
+        } else if (*wildcard == '*' || *wildcard == '?' ||
+                   *wildcard == '[' || *wildcard == ']') {
+            return false;              /* it's a wildcard! */
+        } else {
+            if (output)
+                *output++ = *wildcard;
+            wildcard++;
+        }
     }
     if (output)
         *output = '\0';
@@ -447,35 +447,35 @@ int main(void)
     fails = passes = 0;
 
     for (i = 0; i < sizeof(fragment_tests)/sizeof(*fragment_tests); i++) {
-	const char *f, *t;
-	int eret, aret;
-	f = fragment_tests[i].wildcard;
-	t = fragment_tests[i].target;
-	eret = fragment_tests[i].expected_result;
-	aret = wc_match_fragment(&f, &t, t + strlen(t));
-	if (aret != eret) {
-	    printf("failed test: /%s/ against /%s/ returned %d not %d\n",
-		   fragment_tests[i].wildcard, fragment_tests[i].target,
-		   aret, eret);
-	    fails++;
-	} else
-	    passes++;
+        const char *f, *t;
+        int eret, aret;
+        f = fragment_tests[i].wildcard;
+        t = fragment_tests[i].target;
+        eret = fragment_tests[i].expected_result;
+        aret = wc_match_fragment(&f, &t, t + strlen(t));
+        if (aret != eret) {
+            printf("failed test: /%s/ against /%s/ returned %d not %d\n",
+                   fragment_tests[i].wildcard, fragment_tests[i].target,
+                   aret, eret);
+            fails++;
+        } else
+            passes++;
     }
 
     for (i = 0; i < sizeof(full_tests)/sizeof(*full_tests); i++) {
-	const char *f, *t;
-	int eret, aret;
-	f = full_tests[i].wildcard;
-	t = full_tests[i].target;
-	eret = full_tests[i].expected_result;
-	aret = wc_match(f, t);
-	if (aret != eret) {
-	    printf("failed test: /%s/ against /%s/ returned %d not %d\n",
-		   full_tests[i].wildcard, full_tests[i].target,
-		   aret, eret);
-	    fails++;
-	} else
-	    passes++;
+        const char *f, *t;
+        int eret, aret;
+        f = full_tests[i].wildcard;
+        t = full_tests[i].target;
+        eret = full_tests[i].expected_result;
+        aret = wc_match(f, t);
+        if (aret != eret) {
+            printf("failed test: /%s/ against /%s/ returned %d not %d\n",
+                   full_tests[i].wildcard, full_tests[i].target,
+                   aret, eret);
+            fails++;
+        } else
+            passes++;
     }
 
     printf("passed %d, failed %d\n", passes, fails);

+ 134 - 134
source/putty/windows/wingss.c

@@ -12,8 +12,8 @@
 
 #include "misc.h"
 
-#define UNIX_EPOCH	11644473600ULL	/* Seconds from Windows epoch */
-#define CNS_PERSEC	10000000ULL	/* # 100ns per second */
+#define UNIX_EPOCH      11644473600ULL  /* Seconds from Windows epoch */
+#define CNS_PERSEC      10000000ULL     /* # 100ns per second */
 
 /*
  * Note, as a special case, 0 relative to the Windows epoch (unspecified) maps
@@ -49,29 +49,29 @@ const struct keyvalwhere gsslibkeywords[] = {
 };
 
 DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
-		      AcquireCredentialsHandleA,
-		      (SEC_CHAR *, SEC_CHAR *, ULONG, PVOID,
-		       PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp));
+                      AcquireCredentialsHandleA,
+                      (SEC_CHAR *, SEC_CHAR *, ULONG, PVOID,
+                       PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp));
 DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
-		      InitializeSecurityContextA,
-		      (PCredHandle, PCtxtHandle, SEC_CHAR *, ULONG, ULONG,
-		       ULONG, PSecBufferDesc, ULONG, PCtxtHandle,
-		       PSecBufferDesc, PULONG, PTimeStamp));
+                      InitializeSecurityContextA,
+                      (PCredHandle, PCtxtHandle, SEC_CHAR *, ULONG, ULONG,
+                       ULONG, PSecBufferDesc, ULONG, PCtxtHandle,
+                       PSecBufferDesc, PULONG, PTimeStamp));
 DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
-		      FreeContextBuffer,
-		      (PVOID));
+                      FreeContextBuffer,
+                      (PVOID));
 DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
-		      FreeCredentialsHandle,
-		      (PCredHandle));
+                      FreeCredentialsHandle,
+                      (PCredHandle));
 DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
-		      DeleteSecurityContext,
-		      (PCtxtHandle));
+                      DeleteSecurityContext,
+                      (PCtxtHandle));
 DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
-		      QueryContextAttributesA,
-		      (PCtxtHandle, ULONG, PVOID));
+                      QueryContextAttributesA,
+                      (PCtxtHandle, ULONG, PVOID));
 DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
-		      MakeSignature,
-		      (PCtxtHandle, ULONG, PSecBufferDesc, ULONG));
+                      MakeSignature,
+                      (PCtxtHandle, ULONG, PSecBufferDesc, ULONG));
 DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
                       VerifySignature,
                       (PCtxtHandle, PSecBufferDesc, ULONG, PULONG));
@@ -121,19 +121,19 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf, LogContext *logctx) // MPEXT
     /* MIT Kerberos GSSAPI implementation */
     module = NULL;
     if (RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\MIT\\Kerberos", &regkey)
-	== ERROR_SUCCESS) {
-	DWORD type, size;
-	LONG ret;
-	char *buffer;
+        == ERROR_SUCCESS) {
+        DWORD type, size;
+        LONG ret;
+        char *buffer;
 
-	/* Find out the string length */
+        /* Find out the string length */
         ret = RegQueryValueEx(regkey, "InstallDir", NULL, &type, NULL, &size);
 
-	if (ret == ERROR_SUCCESS && type == REG_SZ) {
-	    buffer = snewn(size + 20, char);
-	    ret = RegQueryValueEx(regkey, "InstallDir", NULL,
-				  &type, (LPBYTE)buffer, &size);
-	    if (ret == ERROR_SUCCESS && type == REG_SZ) {
+        if (ret == ERROR_SUCCESS && type == REG_SZ) {
+            buffer = snewn(size + 20, char);
+            ret = RegQueryValueEx(regkey, "InstallDir", NULL,
+                                  &type, (LPBYTE)buffer, &size);
+            if (ret == ERROR_SUCCESS && type == REG_SZ) {
                 strcat (buffer, "\\bin");
                 if(p_AddDllDirectory) {
                     /* Add MIT Kerberos' path to the DLL search path,
@@ -148,18 +148,18 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf, LogContext *logctx) // MPEXT
                                         LOAD_LIBRARY_SEARCH_SYSTEM32 |
                                         LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
                                         LOAD_LIBRARY_SEARCH_USER_DIRS);
-	    }
-	    sfree(buffer);
-	}
-	RegCloseKey(regkey);
+            }
+            sfree(buffer);
+        }
+        RegCloseKey(regkey);
     }
     if (module) {
-	struct ssh_gss_library *lib =
-	    &list->libraries[list->nlibraries++];
+        struct ssh_gss_library *lib =
+            &list->libraries[list->nlibraries++];
 
-	lib->id = 0;
-	lib->gsslogmsg = "Using GSSAPI from GSSAPI"MIT_KERB_SUFFIX".DLL";
-	lib->handle = (void *)module;
+        lib->id = 0;
+        lib->gsslogmsg = "Using GSSAPI from GSSAPI"MIT_KERB_SUFFIX".DLL";
+        lib->handle = (void *)module;
 
 #define BIND_GSS_FN(name) \
     lib->u.gssapi.name = (t_gss_##name) GetProcAddress(module, "gss_" #name)
@@ -184,25 +184,25 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf, LogContext *logctx) // MPEXT
     /* Microsoft SSPI Implementation */
     module = load_system32_dll("secur32.dll");
     if (module) {
-	struct ssh_gss_library *lib =
-	    &list->libraries[list->nlibraries++];
+        struct ssh_gss_library *lib =
+            &list->libraries[list->nlibraries++];
 
-	lib->id = 1;
-	lib->gsslogmsg = "Using SSPI from SECUR32.DLL";
-	lib->handle = (void *)module;
+        lib->id = 1;
+        lib->gsslogmsg = "Using SSPI from SECUR32.DLL";
+        lib->handle = (void *)module;
 
 #pragma option push -w-cpt
-	GET_WINDOWS_FUNCTION(module, AcquireCredentialsHandleA);
+        GET_WINDOWS_FUNCTION(module, AcquireCredentialsHandleA);
 #pragma option pop
-	GET_WINDOWS_FUNCTION(module, InitializeSecurityContextA);
-	GET_WINDOWS_FUNCTION(module, FreeContextBuffer);
-	GET_WINDOWS_FUNCTION(module, FreeCredentialsHandle);
-	GET_WINDOWS_FUNCTION(module, DeleteSecurityContext);
-	GET_WINDOWS_FUNCTION(module, QueryContextAttributesA);
-	GET_WINDOWS_FUNCTION(module, MakeSignature);
+        GET_WINDOWS_FUNCTION(module, InitializeSecurityContextA);
+        GET_WINDOWS_FUNCTION(module, FreeContextBuffer);
+        GET_WINDOWS_FUNCTION(module, FreeCredentialsHandle);
+        GET_WINDOWS_FUNCTION(module, DeleteSecurityContext);
+        GET_WINDOWS_FUNCTION(module, QueryContextAttributesA);
+        GET_WINDOWS_FUNCTION(module, MakeSignature);
         GET_WINDOWS_FUNCTION(module, VerifySignature);
 
-	ssh_sspi_bind_fns(lib);
+        ssh_sspi_bind_fns(lib);
     }
 
     /*
@@ -245,13 +245,13 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf, LogContext *logctx) // MPEXT
         }
     }
     if (module) {
-	struct ssh_gss_library *lib =
-	    &list->libraries[list->nlibraries++];
+        struct ssh_gss_library *lib =
+            &list->libraries[list->nlibraries++];
 
-	lib->id = 2;
-	lib->gsslogmsg = dupprintf("Using GSSAPI from user-specified"
-				   " library '%s'", path);
-	lib->handle = (void *)module;
+        lib->id = 2;
+        lib->gsslogmsg = dupprintf("Using GSSAPI from user-specified"
+                                   " library '%s'", path);
+        lib->handle = (void *)module;
 
 #define BIND_GSS_FN(name) \
     lib->u.gssapi.name = (t_gss_##name) GetProcAddress(module, "gss_" #name)
@@ -291,19 +291,19 @@ void ssh_gss_cleanup(struct ssh_gss_liblist *list)
      * another SSH instance still using it.
      */
     for (i = 0; i < list->nlibraries; i++) {
-	FreeLibrary((HMODULE)list->libraries[i].handle);
-	if (list->libraries[i].id == 2) {
-	    /* The 'custom' id involves a dynamically allocated message.
-	     * Note that we must cast away the 'const' to free it. */
-	    sfree((char *)list->libraries[i].gsslogmsg);
-	}
+        FreeLibrary((HMODULE)list->libraries[i].handle);
+        if (list->libraries[i].id == 2) {
+            /* The 'custom' id involves a dynamically allocated message.
+             * Note that we must cast away the 'const' to free it. */
+            sfree((char *)list->libraries[i].gsslogmsg);
+        }
     }
     sfree(list->libraries);
     sfree(list);
 }
 
 static Ssh_gss_stat ssh_sspi_indicate_mech(struct ssh_gss_library *lib,
-					   Ssh_gss_buf *mech)
+                                           Ssh_gss_buf *mech)
 {
     *mech = gss_mech_krb5;
     return SSH_GSS_OK;
@@ -311,13 +311,13 @@ static Ssh_gss_stat ssh_sspi_indicate_mech(struct ssh_gss_library *lib,
 
 
 static Ssh_gss_stat ssh_sspi_import_name(struct ssh_gss_library *lib,
-					 char *host, Ssh_gss_name *srv_name)
+                                         char *host, Ssh_gss_name *srv_name)
 {
     char *pStr;
 
     /* Check hostname */
     if (host == NULL) return SSH_GSS_FAILURE;
-    
+
     /* copy it into form host/FQDN */
     pStr = dupcat("host/", host, NULL);
 
@@ -341,13 +341,13 @@ static Ssh_gss_stat ssh_sspi_acquire_cred(struct ssh_gss_library *lib,
        the current logged-in user */
 
     winctx->maj_stat = p_AcquireCredentialsHandleA(NULL,
-						   "Kerberos",
-						   SECPKG_CRED_OUTBOUND,
-						   NULL,
-						   NULL,
-						   NULL,
-						   NULL,
-						   &winctx->cred_handle,
+                                                   "Kerberos",
+                                                   SECPKG_CRED_OUTBOUND,
+                                                   NULL,
+                                                   NULL,
+                                                   NULL,
+                                                   NULL,
+                                                   &winctx->cred_handle,
                                                    NULL);
 
     if (winctx->maj_stat != SEC_E_OK) {
@@ -451,10 +451,10 @@ static void localexp_to_exp_lifetime(TimeStamp *localexp,
 }
 
 static Ssh_gss_stat ssh_sspi_init_sec_context(struct ssh_gss_library *lib,
-					      Ssh_gss_ctx *ctx,
-					      Ssh_gss_name srv_name,
-					      int to_deleg,
-					      Ssh_gss_buf *recv_tok,
+                                              Ssh_gss_ctx *ctx,
+                                              Ssh_gss_name srv_name,
+                                              int to_deleg,
+                                              Ssh_gss_buf *recv_tok,
                                               Ssh_gss_buf *send_tok,
                                               time_t *expiry,
                                               unsigned long *lifetime)
@@ -465,23 +465,23 @@ static Ssh_gss_stat ssh_sspi_init_sec_context(struct ssh_gss_library *lib,
     SecBufferDesc output_desc= MPEXT_INIT_SEC_BUFFERDESC(SECBUFFER_VERSION,1,&wsend_tok);
     SecBufferDesc input_desc = MPEXT_INIT_SEC_BUFFERDESC(SECBUFFER_VERSION,1,&wrecv_tok);
     unsigned long flags=ISC_REQ_MUTUAL_AUTH|ISC_REQ_REPLAY_DETECT|
-	ISC_REQ_CONFIDENTIALITY|ISC_REQ_ALLOCATE_MEMORY;
+        ISC_REQ_CONFIDENTIALITY|ISC_REQ_ALLOCATE_MEMORY;
     unsigned long ret_flags=0;
     TimeStamp localexp;
-    
+
     /* check if we have to delegate ... */
     if (to_deleg) flags |= ISC_REQ_DELEGATE;
     winctx->maj_stat = p_InitializeSecurityContextA(&winctx->cred_handle,
-						    winctx->context_handle,
-						    (char*) srv_name,
-						    flags,
-						    0,          /* reserved */
-						    SECURITY_NATIVE_DREP,
-						    &input_desc,
-						    0,          /* reserved */
-						    &winctx->context,
-						    &output_desc,
-						    &ret_flags,
+                                                    winctx->context_handle,
+                                                    (char*) srv_name,
+                                                    flags,
+                                                    0,          /* reserved */
+                                                    SECURITY_NATIVE_DREP,
+                                                    &input_desc,
+                                                    0,          /* reserved */
+                                                    &winctx->context,
+                                                    &output_desc,
+                                                    &ret_flags,
                                                     &localexp);
 
     localexp_to_exp_lifetime(&localexp, expiry, lifetime);
@@ -490,16 +490,16 @@ static Ssh_gss_stat ssh_sspi_init_sec_context(struct ssh_gss_library *lib,
     winctx->context_handle = &winctx->context;
     send_tok->value = wsend_tok.pvBuffer;
     send_tok->length = wsend_tok.cbBuffer;
-  
+
     /* check & return our status */
     if (winctx->maj_stat==SEC_E_OK) return SSH_GSS_S_COMPLETE;
     if (winctx->maj_stat==SEC_I_CONTINUE_NEEDED) return SSH_GSS_S_CONTINUE_NEEDED;
-    
+
     return SSH_GSS_FAILURE;
 }
 
 static Ssh_gss_stat ssh_sspi_free_tok(struct ssh_gss_library *lib,
-				      Ssh_gss_buf *send_tok)
+                                      Ssh_gss_buf *send_tok)
 {
     /* check input */
     if (send_tok == NULL) return SSH_GSS_FAILURE;
@@ -507,12 +507,12 @@ static Ssh_gss_stat ssh_sspi_free_tok(struct ssh_gss_library *lib,
     /* free Windows buffer */
     p_FreeContextBuffer(send_tok->value);
     SSH_GSS_CLEAR_BUF(send_tok);
-    
+
     return SSH_GSS_OK;
 }
 
 static Ssh_gss_stat ssh_sspi_release_cred(struct ssh_gss_library *lib,
-					  Ssh_gss_ctx *ctx)
+                                          Ssh_gss_ctx *ctx)
 {
     winSsh_gss_ctx *winctx= (winSsh_gss_ctx *) *ctx;
 
@@ -535,7 +535,7 @@ static Ssh_gss_stat ssh_sspi_release_cred(struct ssh_gss_library *lib,
 
 
 static Ssh_gss_stat ssh_sspi_release_name(struct ssh_gss_library *lib,
-					  Ssh_gss_name *srv_name)
+                                          Ssh_gss_name *srv_name)
 {
     char *pStr= (char *) *srv_name;
 
@@ -547,7 +547,7 @@ static Ssh_gss_stat ssh_sspi_release_name(struct ssh_gss_library *lib,
 }
 
 static Ssh_gss_stat ssh_sspi_display_status(struct ssh_gss_library *lib,
-					    Ssh_gss_ctx ctx, Ssh_gss_buf *buf)
+                                            Ssh_gss_ctx ctx, Ssh_gss_buf *buf)
 {
     winSsh_gss_ctx *winctx = (winSsh_gss_ctx *) ctx;
     const char *msg;
@@ -558,48 +558,48 @@ static Ssh_gss_stat ssh_sspi_display_status(struct ssh_gss_library *lib,
     switch (winctx->maj_stat) {
       case SEC_E_OK: msg="SSPI status OK"; break;
       case SEC_E_INVALID_HANDLE: msg="The handle passed to the function"
-	    " is invalid.";
-	break;
+            " is invalid.";
+        break;
       case SEC_E_TARGET_UNKNOWN: msg="The target was not recognized."; break;
       case SEC_E_LOGON_DENIED: msg="The logon failed."; break;
       case SEC_E_INTERNAL_ERROR: msg="The Local Security Authority cannot"
-	    " be contacted.";
-	break;
+            " be contacted.";
+        break;
       case SEC_E_NO_CREDENTIALS: msg="No credentials are available in the"
-	    " security package.";
-	break;
+            " security package.";
+        break;
       case SEC_E_NO_AUTHENTICATING_AUTHORITY:
-	msg="No authority could be contacted for authentication."
-	    "The domain name of the authenticating party could be wrong,"
-	    " the domain could be unreachable, or there might have been"
-	    " a trust relationship failure.";
-	break;
+        msg="No authority could be contacted for authentication."
+            "The domain name of the authenticating party could be wrong,"
+            " the domain could be unreachable, or there might have been"
+            " a trust relationship failure.";
+        break;
       case SEC_E_INSUFFICIENT_MEMORY:
-	msg="One or more of the SecBufferDesc structures passed as"
-	    " an OUT parameter has a buffer that is too small.";
-	break;
+        msg="One or more of the SecBufferDesc structures passed as"
+            " an OUT parameter has a buffer that is too small.";
+        break;
       case SEC_E_INVALID_TOKEN:
-	msg="The error is due to a malformed input token, such as a"
-	    " token corrupted in transit, a token"
-	    " of incorrect size, or a token passed into the wrong"
-	    " security package. Passing a token to"
-	    " the wrong package can happen if client and server did not"
-	    " negotiate the proper security package.";
-	break;
+        msg="The error is due to a malformed input token, such as a"
+            " token corrupted in transit, a token"
+            " of incorrect size, or a token passed into the wrong"
+            " security package. Passing a token to"
+            " the wrong package can happen if client and server did not"
+            " negotiate the proper security package.";
+        break;
       default:
-	msg = "Internal SSPI error";
-	break;
+        msg = "Internal SSPI error";
+        break;
     }
 
     buf->value = dupstr(msg);
     buf->length = strlen(buf->value);
-    
+
     return SSH_GSS_OK;
 }
 
 static Ssh_gss_stat ssh_sspi_get_mic(struct ssh_gss_library *lib,
-				     Ssh_gss_ctx ctx, Ssh_gss_buf *buf,
-				     Ssh_gss_buf *hash)
+                                     Ssh_gss_ctx ctx, Ssh_gss_buf *buf,
+                                     Ssh_gss_buf *hash)
 {
     winSsh_gss_ctx *winctx= (winSsh_gss_ctx *) ctx;
     SecPkgContext_Sizes ContextSizes;
@@ -607,18 +607,18 @@ static Ssh_gss_stat ssh_sspi_get_mic(struct ssh_gss_library *lib,
     SecBuffer InputSecurityToken[2];
 
     if (winctx == NULL) return SSH_GSS_FAILURE;
-  
+
     winctx->maj_stat = 0;
 
     memset(&ContextSizes, 0, sizeof(ContextSizes));
 
     winctx->maj_stat = p_QueryContextAttributesA(&winctx->context,
-						 SECPKG_ATTR_SIZES,
-						 &ContextSizes);
-    
+                                                 SECPKG_ATTR_SIZES,
+                                                 &ContextSizes);
+
     if (winctx->maj_stat != SEC_E_OK ||
-	ContextSizes.cbMaxSignature == 0)
-	return winctx->maj_stat;
+        ContextSizes.cbMaxSignature == 0)
+        return winctx->maj_stat;
 
     InputBufferDescriptor.cBuffers = 2;
     InputBufferDescriptor.pBuffers = InputSecurityToken;
@@ -631,13 +631,13 @@ static Ssh_gss_stat ssh_sspi_get_mic(struct ssh_gss_library *lib,
     InputSecurityToken[1].pvBuffer = snewn(ContextSizes.cbMaxSignature, char);
 
     winctx->maj_stat = p_MakeSignature(&winctx->context,
-				       0,
-				       &InputBufferDescriptor,
-				       0);
+                                       0,
+                                       &InputBufferDescriptor,
+                                       0);
 
     if (winctx->maj_stat == SEC_E_OK) {
-	hash->length = InputSecurityToken[1].cbBuffer;
-	hash->value = InputSecurityToken[1].pvBuffer;
+        hash->length = InputSecurityToken[1].cbBuffer;
+        hash->value = InputSecurityToken[1].pvBuffer;
     }
 
     return winctx->maj_stat;
@@ -674,7 +674,7 @@ static Ssh_gss_stat ssh_sspi_verify_mic(struct ssh_gss_library *lib,
 }
 
 static Ssh_gss_stat ssh_sspi_free_mic(struct ssh_gss_library *lib,
-				      Ssh_gss_buf *hash)
+                                      Ssh_gss_buf *hash)
 {
     sfree(hash->value);
     return SSH_GSS_OK;

+ 212 - 212
source/putty/windows/winhandl.c

@@ -9,14 +9,14 @@
  * data, the subthread sets an event object which is picked up by
  * the main thread, and the main thread then sets an event in
  * return to instruct the subthread to resume reading.
- * 
+ *
  * Output works precisely the other way round, in a second
  * subthread. The output subthread should not be attempting to
  * write all the time, because it hasn't always got data _to_
  * write; so the output thread waits for an event object notifying
  * it to _attempt_ a write, and then it sets an event in return
  * when one completes.
- * 
+ *
  * (It's terribly annoying having to spawn a subthread for each
  * direction of each handle. Technically it isn't necessary for
  * serial ports, since we could use overlapped I/O within the main
@@ -47,7 +47,7 @@ struct handle_generic {
     /*
      * Initial fields common to both handle_input and handle_output
      * structures.
-     * 
+     *
      * The three HANDLEs are set up at initialisation time and are
      * thereafter read-only to both main thread and subthread.
      * `moribund' is only used by the main thread; `done' is
@@ -55,14 +55,14 @@ struct handle_generic {
      * subthread. `defunct' and `busy' are used only by the main
      * thread.
      */
-    HANDLE h;			       /* the handle itself */
-    HANDLE ev_to_main;		       /* event used to signal main thread */
-    HANDLE ev_from_main;	       /* event used to signal back to us */
+    HANDLE h;                          /* the handle itself */
+    HANDLE ev_to_main;                 /* event used to signal main thread */
+    HANDLE ev_from_main;               /* event used to signal back to us */
     bool moribund;                     /* are we going to kill this soon? */
     bool done;                         /* request subthread to terminate */
     bool defunct;                      /* has the subthread already gone? */
     bool busy;                         /* operation currently in progress? */
-    void *privdata;		       /* for client to remember who they are */
+    void *privdata;                    /* for client to remember who they are */
 };
 
 typedef enum { HT_INPUT, HT_OUTPUT, HT_FOREIGN } HandleType;
@@ -78,14 +78,14 @@ struct handle_input {
     /*
      * Copy of the handle_generic structure.
      */
-    HANDLE h;			       /* the handle itself */
-    HANDLE ev_to_main;		       /* event used to signal main thread */
-    HANDLE ev_from_main;	       /* event used to signal back to us */
+    HANDLE h;                          /* the handle itself */
+    HANDLE ev_to_main;                 /* event used to signal main thread */
+    HANDLE ev_from_main;               /* event used to signal back to us */
     bool moribund;                     /* are we going to kill this soon? */
     bool done;                         /* request subthread to terminate */
     bool defunct;                      /* has the subthread already gone? */
     bool busy;                         /* operation currently in progress? */
-    void *privdata;		       /* for client to remember who they are */
+    void *privdata;                    /* for client to remember who they are */
 
     /*
      * Data set at initialisation and then read-only.
@@ -96,9 +96,9 @@ struct handle_input {
      * Data set by the input thread before signalling ev_to_main,
      * and read by the main thread after receiving that signal.
      */
-    char buffer[4096];		       /* the data read from the handle */
-    DWORD len;			       /* how much data that was */
-    int readerr;		       /* lets us know about read errors */
+    char buffer[4096];                 /* the data read from the handle */
+    DWORD len;                         /* how much data that was */
+    int readerr;                       /* lets us know about read errors */
 
     /*
      * Callback function called by this module when data arrives on
@@ -119,52 +119,52 @@ static DWORD WINAPI handle_input_threadfunc(void *param)
     int readlen;
 
     if (ctx->flags & HANDLE_FLAG_OVERLAPPED) {
-	povl = &ovl;
-	oev = CreateEvent(NULL, true, false, NULL);
+        povl = &ovl;
+        oev = CreateEvent(NULL, true, false, NULL);
     } else {
-	povl = NULL;
+        povl = NULL;
     }
 
     if (ctx->flags & HANDLE_FLAG_UNITBUFFER)
-	readlen = 1;
+        readlen = 1;
     else
-	readlen = sizeof(ctx->buffer);
+        readlen = sizeof(ctx->buffer);
 
     while (1) {
-	if (povl) {
-	    memset(povl, 0, sizeof(OVERLAPPED));
-	    povl->hEvent = oev;
-	}
-	readret = ReadFile(ctx->h, ctx->buffer,readlen, &ctx->len, povl);
-	if (!readret)
-	    ctx->readerr = GetLastError();
-	else
-	    ctx->readerr = 0;
-	if (povl && !readret && ctx->readerr == ERROR_IO_PENDING) {
-	    WaitForSingleObject(povl->hEvent, INFINITE);
-	    readret = GetOverlappedResult(ctx->h, povl, &ctx->len, false);
-	    if (!readret)
-		ctx->readerr = GetLastError();
-	    else
-		ctx->readerr = 0;
-	}
-
-	if (!readret) {
-	    /*
-	     * Windows apparently sends ERROR_BROKEN_PIPE when a
-	     * pipe we're reading from is closed normally from the
-	     * writing end. This is ludicrous; if that situation
-	     * isn't a natural EOF, _nothing_ is. So if we get that
-	     * particular error, we pretend it's EOF.
-	     */
-	    if (ctx->readerr == ERROR_BROKEN_PIPE)
-		ctx->readerr = 0;
-	    ctx->len = 0;
-	}
-
-	if (readret && ctx->len == 0 &&
-	    (ctx->flags & HANDLE_FLAG_IGNOREEOF))
-	    continue;
+        if (povl) {
+            memset(povl, 0, sizeof(OVERLAPPED));
+            povl->hEvent = oev;
+        }
+        readret = ReadFile(ctx->h, ctx->buffer,readlen, &ctx->len, povl);
+        if (!readret)
+            ctx->readerr = GetLastError();
+        else
+            ctx->readerr = 0;
+        if (povl && !readret && ctx->readerr == ERROR_IO_PENDING) {
+            WaitForSingleObject(povl->hEvent, INFINITE);
+            readret = GetOverlappedResult(ctx->h, povl, &ctx->len, false);
+            if (!readret)
+                ctx->readerr = GetLastError();
+            else
+                ctx->readerr = 0;
+        }
+
+        if (!readret) {
+            /*
+             * Windows apparently sends ERROR_BROKEN_PIPE when a
+             * pipe we're reading from is closed normally from the
+             * writing end. This is ludicrous; if that situation
+             * isn't a natural EOF, _nothing_ is. So if we get that
+             * particular error, we pretend it's EOF.
+             */
+            if (ctx->readerr == ERROR_BROKEN_PIPE)
+                ctx->readerr = 0;
+            ctx->len = 0;
+        }
+
+        if (readret && ctx->len == 0 &&
+            (ctx->flags & HANDLE_FLAG_IGNOREEOF))
+            continue;
 
         /*
          * If we just set ctx->len to 0, that means the read operation
@@ -176,13 +176,13 @@ static DWORD WINAPI handle_input_threadfunc(void *param)
          */
         finished = (ctx->len == 0);
 
-	SetEvent(ctx->ev_to_main);
+        SetEvent(ctx->ev_to_main);
 
-	if (finished)
-	    break;
+        if (finished)
+            break;
 
-	WaitForSingleObject(ctx->ev_from_main, INFINITE);
-	if (ctx->done) {
+        WaitForSingleObject(ctx->ev_from_main, INFINITE);
+        if (ctx->done) {
             /*
              * The main thread has asked us to shut down. Send back an
              * event indicating that we've done so. Hereafter we must
@@ -195,7 +195,7 @@ static DWORD WINAPI handle_input_threadfunc(void *param)
     }
 
     if (povl)
-	CloseHandle(oev);
+        CloseHandle(oev);
 
     return 0;
 }
@@ -208,7 +208,7 @@ static DWORD WINAPI handle_input_threadfunc(void *param)
 static void handle_throttle(struct handle_input *ctx, int backlog)
 {
     if (ctx->defunct)
-	return;
+        return;
 
     /*
      * If there's a read operation already in progress, do nothing:
@@ -216,15 +216,15 @@ static void handle_throttle(struct handle_input *ctx, int backlog)
      * position to make a better decision.
      */
     if (ctx->busy)
-	return;
+        return;
 
     /*
      * Otherwise, we must decide whether to start a new read based
      * on the size of the backlog.
      */
     if (backlog < MAX_BACKLOG) {
-	SetEvent(ctx->ev_from_main);
-	ctx->busy = true;
+        SetEvent(ctx->ev_from_main);
+        ctx->busy = true;
     }
 }
 
@@ -239,14 +239,14 @@ struct handle_output {
     /*
      * Copy of the handle_generic structure.
      */
-    HANDLE h;			       /* the handle itself */
-    HANDLE ev_to_main;		       /* event used to signal main thread */
-    HANDLE ev_from_main;	       /* event used to signal back to us */
+    HANDLE h;                          /* the handle itself */
+    HANDLE ev_to_main;                 /* event used to signal main thread */
+    HANDLE ev_from_main;               /* event used to signal back to us */
     bool moribund;                     /* are we going to kill this soon? */
     bool done;                         /* request subthread to terminate */
     bool defunct;                      /* has the subthread already gone? */
     bool busy;                         /* operation currently in progress? */
-    void *privdata;		       /* for client to remember who they are */
+    void *privdata;                    /* for client to remember who they are */
 
     /*
      * Data set at initialisation and then read-only.
@@ -258,19 +258,19 @@ struct handle_output {
      * and read by the input thread after receiving that signal.
      */
     const char *buffer;                /* the data to write */
-    DWORD len;			       /* how much data there is */
+    DWORD len;                         /* how much data there is */
 
     /*
      * Data set by the input thread before signalling ev_to_main,
      * and read by the main thread after receiving that signal.
      */
-    DWORD lenwritten;		       /* how much data we actually wrote */
-    int writeerr;		       /* return value from WriteFile */
+    DWORD lenwritten;                  /* how much data we actually wrote */
+    int writeerr;                      /* return value from WriteFile */
 
     /*
      * Data only ever read or written by the main thread.
      */
-    bufchain queued_data;	       /* data still waiting to be written */
+    bufchain queued_data;              /* data still waiting to be written */
     enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof;
 
     /*
@@ -288,46 +288,46 @@ static DWORD WINAPI handle_output_threadfunc(void *param)
     bool writeret;
 
     if (ctx->flags & HANDLE_FLAG_OVERLAPPED) {
-	povl = &ovl;
-	oev = CreateEvent(NULL, true, false, NULL);
+        povl = &ovl;
+        oev = CreateEvent(NULL, true, false, NULL);
     } else {
-	povl = NULL;
+        povl = NULL;
     }
 
     while (1) {
-	WaitForSingleObject(ctx->ev_from_main, INFINITE);
-	if (ctx->done) {
+        WaitForSingleObject(ctx->ev_from_main, INFINITE);
+        if (ctx->done) {
             /*
              * The main thread has asked us to shut down. Send back an
              * event indicating that we've done so. Hereafter we must
              * not touch ctx at all, because the main thread might
              * have freed it.
              */
-	    SetEvent(ctx->ev_to_main);
-	    break;
-	}
-	if (povl) {
-	    memset(povl, 0, sizeof(OVERLAPPED));
-	    povl->hEvent = oev;
-	}
-
-	writeret = WriteFile(ctx->h, ctx->buffer, ctx->len,
-			     &ctx->lenwritten, povl);
-	if (!writeret)
-	    ctx->writeerr = GetLastError();
-	else
-	    ctx->writeerr = 0;
-	if (povl && !writeret && GetLastError() == ERROR_IO_PENDING) {
-	    writeret = GetOverlappedResult(ctx->h, povl,
-					   &ctx->lenwritten, true);
-	    if (!writeret)
-		ctx->writeerr = GetLastError();
-	    else
-		ctx->writeerr = 0;
-	}
-
-	SetEvent(ctx->ev_to_main);
-	if (!writeret) {
+            SetEvent(ctx->ev_to_main);
+            break;
+        }
+        if (povl) {
+            memset(povl, 0, sizeof(OVERLAPPED));
+            povl->hEvent = oev;
+        }
+
+        writeret = WriteFile(ctx->h, ctx->buffer, ctx->len,
+                             &ctx->lenwritten, povl);
+        if (!writeret)
+            ctx->writeerr = GetLastError();
+        else
+            ctx->writeerr = 0;
+        if (povl && !writeret && GetLastError() == ERROR_IO_PENDING) {
+            writeret = GetOverlappedResult(ctx->h, povl,
+                                           &ctx->lenwritten, true);
+            if (!writeret)
+                ctx->writeerr = GetLastError();
+            else
+                ctx->writeerr = 0;
+        }
+
+        SetEvent(ctx->ev_to_main);
+        if (!writeret) {
             /*
              * The write operation has suffered an error. Telling that
              * to the main thread will cause it to set its 'defunct'
@@ -335,12 +335,12 @@ static DWORD WINAPI handle_output_threadfunc(void *param)
              * opportunity, so we must not touch ctx at all after
              * this.
              */
-	    break;
+            break;
         }
     }
 
     if (povl)
-	CloseHandle(oev);
+        CloseHandle(oev);
 
     return 0;
 }
@@ -348,11 +348,11 @@ static DWORD WINAPI handle_output_threadfunc(void *param)
 static void handle_try_output(struct handle_output *ctx)
 {
     if (!ctx->busy && bufchain_size(&ctx->queued_data)) {
-	ptrlen data = bufchain_prefix(&ctx->queued_data);
-	ctx->buffer = data.ptr;
-	ctx->len = min(data.len, ~(DWORD)0);
-	SetEvent(ctx->ev_from_main);
-	ctx->busy = true;
+        ptrlen data = bufchain_prefix(&ctx->queued_data);
+        ctx->buffer = data.ptr;
+        ctx->len = min(data.len, ~(DWORD)0);
+        SetEvent(ctx->ev_from_main);
+        ctx->busy = true;
     } else if (!ctx->busy && bufchain_size(&ctx->queued_data) == 0 &&
                ctx->outgoingeof == EOF_PENDING) {
         CloseHandle(ctx->h);
@@ -372,14 +372,14 @@ struct handle_foreign {
     /*
      * Copy of the handle_generic structure.
      */
-    HANDLE h;			       /* the handle itself */
-    HANDLE ev_to_main;		       /* event used to signal main thread */
-    HANDLE ev_from_main;	       /* event used to signal back to us */
+    HANDLE h;                          /* the handle itself */
+    HANDLE ev_to_main;                 /* event used to signal main thread */
+    HANDLE ev_from_main;               /* event used to signal back to us */
     bool moribund;                     /* are we going to kill this soon? */
     bool done;                         /* request subthread to terminate */
     bool defunct;                      /* has the subthread already gone? */
     bool busy;                         /* operation currently in progress? */
-    void *privdata;		       /* for client to remember who they are */
+    void *privdata;                    /* for client to remember who they are */
 
     /*
      * Our own data, just consisting of knowledge of who to call back.
@@ -395,10 +395,10 @@ struct handle_foreign {
 struct handle {
     HandleType type;
     union {
-	struct handle_generic g;
-	struct handle_input i;
-	struct handle_output o;
-	struct handle_foreign f;
+        struct handle_generic g;
+        struct handle_input i;
+        struct handle_output o;
+        struct handle_foreign f;
     } u;
 };
 
@@ -410,11 +410,11 @@ static int handle_cmp_evtomain(void *av, void *bv)
     struct handle *b = (struct handle *)bv;
 
     if ((uintptr_t)a->u.g.ev_to_main < (uintptr_t)b->u.g.ev_to_main)
-	return -1;
+        return -1;
     else if ((uintptr_t)a->u.g.ev_to_main > (uintptr_t)b->u.g.ev_to_main)
-	return +1;
+        return +1;
     else
-	return 0;
+        return 0;
 }
 
 static int handle_find_evtomain(void *av, void *bv)
@@ -423,15 +423,15 @@ static int handle_find_evtomain(void *av, void *bv)
     struct handle *b = (struct handle *)bv;
 
     if ((uintptr_t)*a < (uintptr_t)b->u.g.ev_to_main)
-	return -1;
+        return -1;
     else if ((uintptr_t)*a > (uintptr_t)b->u.g.ev_to_main)
-	return +1;
+        return +1;
     else
-	return 0;
+        return 0;
 }
 
 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
-				void *privdata, int flags)
+                                void *privdata, int flags)
 {
     struct handle *h = snew(struct handle);
     DWORD in_threadid; /* required for Win9x */
@@ -448,18 +448,18 @@ struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
     h->u.i.flags = flags;
 
     if (!handles_by_evtomain)
-	handles_by_evtomain = newtree234(handle_cmp_evtomain);
+        handles_by_evtomain = newtree234(handle_cmp_evtomain);
     add234(handles_by_evtomain, h);
 
     CreateThread(NULL, 0, handle_input_threadfunc,
-		 &h->u.i, 0, &in_threadid);
+                 &h->u.i, 0, &in_threadid);
     h->u.i.busy = true;
 
     return h;
 }
 
 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
-				 void *privdata, int flags)
+                                 void *privdata, int flags)
 {
     struct handle *h = snew(struct handle);
     DWORD out_threadid; /* required for Win9x */
@@ -479,11 +479,11 @@ struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
     h->u.o.flags = flags;
 
     if (!handles_by_evtomain)
-	handles_by_evtomain = newtree234(handle_cmp_evtomain);
+        handles_by_evtomain = newtree234(handle_cmp_evtomain);
     add234(handles_by_evtomain, h);
 
     CreateThread(NULL, 0, handle_output_threadfunc,
-		 &h->u.o, 0, &out_threadid);
+                 &h->u.o, 0, &out_threadid);
 
     return h;
 }
@@ -506,7 +506,7 @@ struct handle *handle_add_foreign_event(HANDLE event,
     h->u.f.busy = true;
 
     if (!handles_by_evtomain)
-	handles_by_evtomain = newtree234(handle_cmp_evtomain);
+        handles_by_evtomain = newtree234(handle_cmp_evtomain);
     add234(handles_by_evtomain, h);
 
     return h;
@@ -551,12 +551,12 @@ HANDLE *handle_get_events(int *nevents)
     ret = NULL;
     n = size = 0;
     if (handles_by_evtomain) {
-	for (i = 0; (h = index234(handles_by_evtomain, i)) != NULL; i++) {
-	    if (h->u.g.busy) {
+        for (i = 0; (h = index234(handles_by_evtomain, i)) != NULL; i++) {
+            if (h->u.g.busy) {
                 sgrowarray(ret, size, n);
-		ret[n++] = h->u.g.ev_to_main;
-	    }
-	}
+                ret[n++] = h->u.g.ev_to_main;
+            }
+        }
     }
 
     *nevents = n;
@@ -566,7 +566,7 @@ HANDLE *handle_get_events(int *nevents)
 static void handle_destroy(struct handle *h)
 {
     if (h->type == HT_OUTPUT)
-	bufchain_clear(&h->u.o.queued_data);
+        bufchain_clear(&h->u.o.queued_data);
     CloseHandle(h->u.g.ev_from_main);
     CloseHandle(h->u.g.ev_to_main);
     del234(handles_by_evtomain, h);
@@ -587,24 +587,24 @@ void handle_free(struct handle *h)
          * invalid memory after we free its context from under it. So
          * we set the moribund flag, which will be noticed next time
          * an operation completes.
-	 */
-	h->u.g.moribund = true;
+         */
+        h->u.g.moribund = true;
     } else if (h->u.g.defunct) {
-	/*
-	 * There isn't even a subthread; we can go straight to
-	 * handle_destroy.
-	 */
-	handle_destroy(h);
+        /*
+         * There isn't even a subthread; we can go straight to
+         * handle_destroy.
+         */
+        handle_destroy(h);
     } else {
-	/*
-	 * The subthread is alive but not busy, so we now signal it
-	 * to die. Set the moribund flag to indicate that it will
-	 * want destroying after that.
-	 */
-	h->u.g.moribund = true;
-	h->u.g.done = true;
-	h->u.g.busy = true;
-	SetEvent(h->u.g.ev_from_main);
+        /*
+         * The subthread is alive but not busy, so we now signal it
+         * to die. Set the moribund flag to indicate that it will
+         * want destroying after that.
+         */
+        h->u.g.moribund = true;
+        h->u.g.done = true;
+        h->u.g.busy = true;
+        SetEvent(h->u.g.ev_from_main);
     }
 }
 
@@ -615,79 +615,79 @@ int handle_got_event(HANDLE event) // WINSCP
     assert(handles_by_evtomain);
     h = find234(handles_by_evtomain, &event, handle_find_evtomain);
     if (!h) {
-	/*
-	 * This isn't an error condition. If two or more event
-	 * objects were signalled during the same select operation,
-	 * and processing of the first caused the second handle to
-	 * be closed, then it will sometimes happen that we receive
-	 * an event notification here for a handle which is already
-	 * deceased. In that situation we simply do nothing.
-	 */
-	return 0; // WINSCP
+        /*
+         * This isn't an error condition. If two or more event
+         * objects were signalled during the same select operation,
+         * and processing of the first caused the second handle to
+         * be closed, then it will sometimes happen that we receive
+         * an event notification here for a handle which is already
+         * deceased. In that situation we simply do nothing.
+         */
+        return 0; // WINSCP
     }
 
     if (h->u.g.moribund) {
-	/*
-	 * A moribund handle is one which we have either already
-	 * signalled to die, or are waiting until its current I/O op
-	 * completes to do so. Either way, it's treated as already
-	 * dead from the external user's point of view, so we ignore
-	 * the actual I/O result. We just signal the thread to die if
-	 * we haven't yet done so, or destroy the handle if not.
-	 */
-	if (h->u.g.done) {
-	    handle_destroy(h);
-	} else {
-	    h->u.g.done = true;
-	    h->u.g.busy = true;
-	    SetEvent(h->u.g.ev_from_main);
-	}
-	return 0; // WINSCP
+        /*
+         * A moribund handle is one which we have either already
+         * signalled to die, or are waiting until its current I/O op
+         * completes to do so. Either way, it's treated as already
+         * dead from the external user's point of view, so we ignore
+         * the actual I/O result. We just signal the thread to die if
+         * we haven't yet done so, or destroy the handle if not.
+         */
+        if (h->u.g.done) {
+            handle_destroy(h);
+        } else {
+            h->u.g.done = true;
+            h->u.g.busy = true;
+            SetEvent(h->u.g.ev_from_main);
+        }
+        return 0; // WINSCP
     }
 
     switch (h->type) {
-	int backlog;
+        int backlog;
 
       case HT_INPUT:
-	h->u.i.busy = false;
-
-	/*
-	 * A signal on an input handle means data has arrived.
-	 */
-	if (h->u.i.len == 0) {
-	    /*
-	     * EOF, or (nearly equivalently) read error.
-	     */
-	    h->u.i.defunct = true;
-	    h->u.i.gotdata(h, NULL, 0, h->u.i.readerr);
-	} else {
-	    backlog = h->u.i.gotdata(h, h->u.i.buffer, h->u.i.len, 0);
-	    handle_throttle(&h->u.i, backlog);
-	}
+        h->u.i.busy = false;
+
+        /*
+         * A signal on an input handle means data has arrived.
+         */
+        if (h->u.i.len == 0) {
+            /*
+             * EOF, or (nearly equivalently) read error.
+             */
+            h->u.i.defunct = true;
+            h->u.i.gotdata(h, NULL, 0, h->u.i.readerr);
+        } else {
+            backlog = h->u.i.gotdata(h, h->u.i.buffer, h->u.i.len, 0);
+            handle_throttle(&h->u.i, backlog);
+        }
         return 1; // WINSCP
 
       case HT_OUTPUT:
-	h->u.o.busy = false;
-
-	/*
-	 * A signal on an output handle means we have completed a
-	 * write. Call the callback to indicate that the output
-	 * buffer size has decreased, or to indicate an error.
-	 */
-	if (h->u.o.writeerr) {
-	    /*
-	     * Write error. Send a negative value to the callback,
-	     * and mark the thread as defunct (because the output
-	     * thread is terminating by now).
-	     */
-	    h->u.o.defunct = true;
-	    h->u.o.sentdata(h, 0, h->u.o.writeerr);
-	} else {
-	    bufchain_consume(&h->u.o.queued_data, h->u.o.lenwritten);
+        h->u.o.busy = false;
+
+        /*
+         * A signal on an output handle means we have completed a
+         * write. Call the callback to indicate that the output
+         * buffer size has decreased, or to indicate an error.
+         */
+        if (h->u.o.writeerr) {
+            /*
+             * Write error. Send a negative value to the callback,
+             * and mark the thread as defunct (because the output
+             * thread is terminating by now).
+             */
+            h->u.o.defunct = true;
+            h->u.o.sentdata(h, 0, h->u.o.writeerr);
+        } else {
+            bufchain_consume(&h->u.o.queued_data, h->u.o.lenwritten);
             noise_ultralight(NOISE_SOURCE_IOLEN, h->u.o.lenwritten);
-	    h->u.o.sentdata(h, bufchain_size(&h->u.o.queued_data), 0);
-	    handle_try_output(&h->u.o);
-	}
+            h->u.o.sentdata(h, bufchain_size(&h->u.o.queued_data), 0);
+            handle_try_output(&h->u.o);
+        }
         return 0; // WINSCP
 
       case HT_FOREIGN:

+ 6 - 6
source/putty/windows/winhsock.c

@@ -55,11 +55,11 @@ static size_t handle_gotdata(
     HandleSocket *hs = (HandleSocket *)handle_get_privdata(h);
 
     if (err) {
-	plug_closing(hs->plug, "Read error from handle", 0, 0);
-	return 0;
+        plug_closing(hs->plug, "Read error from handle", 0, 0);
+        return 0;
     } else if (len == 0) {
-	plug_closing(hs->plug, NULL, 0, 0);
-	return 0;
+        plug_closing(hs->plug, NULL, 0, 0);
+        return 0;
     } else {
         assert(hs->frozen != FROZEN && hs->frozen != THAWING);
         if (hs->frozen == FREEZING) {
@@ -79,7 +79,7 @@ static size_t handle_gotdata(
             return INT_MAX;
         } else {
             plug_receive(hs->plug, 0, data, len);
-	    return 0;
+            return 0;
         }
     }
 }
@@ -112,7 +112,7 @@ static Plug *sk_handle_plug(Socket *s, Plug *p)
     HandleSocket *hs = container_of(s, HandleSocket, sock);
     Plug *ret = hs->plug;
     if (p)
-	hs->plug = p;
+        hs->plug = p;
     return ret;
 }
 

+ 72 - 72
source/putty/windows/winmisc.c

@@ -110,62 +110,62 @@ char *get_username(void)
     char *user;
     bool got_username = false;
     DECL_WINDOWS_FUNCTION(static, BOOLEAN, GetUserNameExA,
-			  (EXTENDED_NAME_FORMAT, LPSTR, PULONG));
+                          (EXTENDED_NAME_FORMAT, LPSTR, PULONG));
 
     {
-	static bool tried_usernameex = false;
-	if (!tried_usernameex) {
-	    /* Not available on Win9x, so load dynamically */
-	    HMODULE secur32 = load_system32_dll("secur32.dll");
-	    /* If MIT Kerberos is installed, the following call to
-	       GET_WINDOWS_FUNCTION makes Windows implicitly load
-	       sspicli.dll WITHOUT proper path sanitizing, so better
-	       load it properly before */
-	    HMODULE sspicli = load_system32_dll("sspicli.dll");
+        static bool tried_usernameex = false;
+        if (!tried_usernameex) {
+            /* Not available on Win9x, so load dynamically */
+            HMODULE secur32 = load_system32_dll("secur32.dll");
+            /* If MIT Kerberos is installed, the following call to
+               GET_WINDOWS_FUNCTION makes Windows implicitly load
+               sspicli.dll WITHOUT proper path sanitizing, so better
+               load it properly before */
+            HMODULE sspicli = load_system32_dll("sspicli.dll");
             (void)sspicli; /* squash compiler warning about unused variable */
-	    GET_WINDOWS_FUNCTION(secur32, GetUserNameExA);
-	    tried_usernameex = true;
-	}
+            GET_WINDOWS_FUNCTION(secur32, GetUserNameExA);
+            tried_usernameex = true;
+        }
     }
 
     if (p_GetUserNameExA) {
-	/*
-	 * If available, use the principal -- this avoids the problem
-	 * that the local username is case-insensitive but Kerberos
-	 * usernames are case-sensitive.
-	 */
-
-	/* Get the length */
-	namelen = 0;
-	(void) p_GetUserNameExA(NameUserPrincipal, NULL, &namelen);
-
-	user = snewn(namelen, char);
-	got_username = p_GetUserNameExA(NameUserPrincipal, user, &namelen);
-	if (got_username) {
-	    char *p = strchr(user, '@');
-	    if (p) *p = 0;
-	} else {
-	    sfree(user);
-	}
+        /*
+         * If available, use the principal -- this avoids the problem
+         * that the local username is case-insensitive but Kerberos
+         * usernames are case-sensitive.
+         */
+
+        /* Get the length */
+        namelen = 0;
+        (void) p_GetUserNameExA(NameUserPrincipal, NULL, &namelen);
+
+        user = snewn(namelen, char);
+        got_username = p_GetUserNameExA(NameUserPrincipal, user, &namelen);
+        if (got_username) {
+            char *p = strchr(user, '@');
+            if (p) *p = 0;
+        } else {
+            sfree(user);
+        }
     }
 
     if (!got_username) {
-	/* Fall back to local user name */
-	namelen = 0;
-	if (!GetUserName(NULL, &namelen)) {
-	    /*
-	     * Apparently this doesn't work at least on Windows XP SP2.
-	     * Thus assume a maximum of 256. It will fail again if it
-	     * doesn't fit.
-	     */
-	    namelen = 256;
-	}
-
-	user = snewn(namelen, char);
-	got_username = GetUserName(user, &namelen);
-	if (!got_username) {
-	    sfree(user);
-	}
+        /* Fall back to local user name */
+        namelen = 0;
+        if (!GetUserName(NULL, &namelen)) {
+            /*
+             * Apparently this doesn't work at least on Windows XP SP2.
+             * Thus assume a maximum of 256. It will fail again if it
+             * doesn't fit.
+             */
+            namelen = 256;
+        }
+
+        user = snewn(namelen, char);
+        got_username = GetUserName(user, &namelen);
+        if (!got_username) {
+            sfree(user);
+        }
     }
 
     return got_username ? user : NULL;
@@ -420,35 +420,35 @@ void escape_registry_key(const char *in, strbuf *out)
     static const char hex[16] = "0123456789ABCDEF";
 
     while (*in) {
-	if (*in == ' ' || *in == '\\' || *in == '*' || *in == '?' ||
-	    *in == '%' || *in < ' ' || *in > '~' || (*in == '.'
-						     && !candot)) {
+        if (*in == ' ' || *in == '\\' || *in == '*' || *in == '?' ||
+            *in == '%' || *in < ' ' || *in > '~' || (*in == '.'
+                                                     && !candot)) {
             put_byte(out, '%');
-	    put_byte(out, hex[((unsigned char) *in) >> 4]);
-	    put_byte(out, hex[((unsigned char) *in) & 15]);
-	} else
-	    put_byte(out, *in);
-	in++;
-	candot = true;
+            put_byte(out, hex[((unsigned char) *in) >> 4]);
+            put_byte(out, hex[((unsigned char) *in) & 15]);
+        } else
+            put_byte(out, *in);
+        in++;
+        candot = true;
     }
 }
 
 void unescape_registry_key(const char *in, strbuf *out)
 {
     while (*in) {
-	if (*in == '%' && in[1] && in[2]) {
-	    int i, j;
+        if (*in == '%' && in[1] && in[2]) {
+            int i, j;
 
-	    i = in[1] - '0';
-	    i -= (i > 9 ? 7 : 0);
-	    j = in[2] - '0';
-	    j -= (j > 9 ? 7 : 0);
+            i = in[1] - '0';
+            i -= (i > 9 ? 7 : 0);
+            j = in[2] - '0';
+            j -= (j > 9 ? 7 : 0);
 
-	    put_byte(out, (i << 4) + j);
-	    in += 3;
-	} else {
+            put_byte(out, (i << 4) + j);
+            in += 3;
+        } else {
             put_byte(out, *in++);
-	}
+        }
     }
 }
 
@@ -462,17 +462,17 @@ void dputs(const char *buf)
     DWORD dw;
 
     if (!debug_got_console) {
-	if (AllocConsole()) {
-	    debug_got_console = 1;
-	    debug_hdl = GetStdHandle(STD_OUTPUT_HANDLE);
-	}
+        if (AllocConsole()) {
+            debug_got_console = 1;
+            debug_hdl = GetStdHandle(STD_OUTPUT_HANDLE);
+        }
     }
     if (!debug_fp) {
-	debug_fp = fopen("debug.log", "w");
+        debug_fp = fopen("debug.log", "w");
     }
 
     if (debug_hdl != INVALID_HANDLE_VALUE) {
-	WriteFile(debug_hdl, buf, strlen(buf), &dw, NULL);
+        WriteFile(debug_hdl, buf, strlen(buf), &dw, NULL);
     }
     fputs(buf, debug_fp);
     fflush(debug_fp);

+ 41 - 41
source/putty/windows/winmiscs.c

@@ -25,15 +25,15 @@ void smemclr(void *b, size_t n) {
 
 /*
  * Design:
- * 
+ *
  * We start by reserving as much virtual address space as Windows
  * will sensibly (or not sensibly) let us have. We flag it all as
  * invalid memory.
- * 
+ *
  * Any allocation attempt is satisfied by committing one or more
  * pages, with an uncommitted page on either side. The returned
  * memory region is jammed up against the _end_ of the pages.
- * 
+ *
  * Freeing anything causes instantaneous decommitment of the pages
  * involved, so stale pointers are caught as soon as possible.
  */
@@ -59,10 +59,10 @@ static void minefield_init(void)
     int i;
 
     for (size = 0x40000000; size > 0; size = ((size >> 3) * 7) & ~0xFFF) {
-	minefield_region = VirtualAlloc(NULL, size,
-					MEM_RESERVE, PAGE_NOACCESS);
-	if (minefield_region)
-	    break;
+        minefield_region = VirtualAlloc(NULL, size,
+                                        MEM_RESERVE, PAGE_NOACCESS);
+        if (minefield_region)
+            break;
     }
     minefield_size = size;
 
@@ -80,13 +80,13 @@ static void minefield_init(void)
      * Commit the admin region.
      */
     VirtualAlloc(minefield_admin, minefield_npages * 2,
-		 MEM_COMMIT, PAGE_READWRITE);
+                 MEM_COMMIT, PAGE_READWRITE);
 
     /*
      * Mark all pages as unused (0xFFFF).
      */
     for (i = 0; i < minefield_npages; i++)
-	minefield_admin[i] = 0xFFFF;
+        minefield_admin[i] = 0xFFFF;
 
     /*
      * Hide the admin region.
@@ -119,27 +119,27 @@ static void *minefield_alloc(int size)
     pos = minefield_curpos;
     lim = minefield_npages;
     while (1) {
-	/* Skip over used pages. */
-	while (pos < lim && minefield_admin[pos] != 0xFFFF)
-	    pos++;
-	/* Count unused pages. */
-	start = pos;
-	while (pos < lim && pos - start < npages + 2 &&
-	       minefield_admin[pos] == 0xFFFF)
-	    pos++;
-	if (pos - start == npages + 2)
-	    break;
-	/* If we've reached the limit, reset the limit or stop. */
-	if (pos >= lim) {
-	    if (lim == minefield_npages) {
-		/* go round and start again at zero */
-		lim = minefield_curpos;
-		pos = 0;
-	    } else {
-		minefield_admin_hide(1);
-		return NULL;
-	    }
-	}
+        /* Skip over used pages. */
+        while (pos < lim && minefield_admin[pos] != 0xFFFF)
+            pos++;
+        /* Count unused pages. */
+        start = pos;
+        while (pos < lim && pos - start < npages + 2 &&
+               minefield_admin[pos] == 0xFFFF)
+            pos++;
+        if (pos - start == npages + 2)
+            break;
+        /* If we've reached the limit, reset the limit or stop. */
+        if (pos >= lim) {
+            if (lim == minefield_npages) {
+                /* go round and start again at zero */
+                lim = minefield_curpos;
+                pos = 0;
+            } else {
+                minefield_admin_hide(1);
+                return NULL;
+            }
+        }
     }
 
     minefield_curpos = pos - 1;
@@ -156,13 +156,13 @@ static void *minefield_alloc(int size)
      * Update the admin region.
      */
     for (i = start + 2; i < start + npages + 1; i++)
-	minefield_admin[i] = 0xFFFE;   /* used but no region starts here */
+        minefield_admin[i] = 0xFFFE;   /* used but no region starts here */
     minefield_admin[start + 1] = region_start % PAGESIZE;
 
     minefield_admin_hide(1);
 
     VirtualAlloc((char *) minefield_pages + region_start, size,
-		 MEM_COMMIT, PAGE_READWRITE);
+                 MEM_COMMIT, PAGE_READWRITE);
     return (char *) minefield_pages + region_start;
 }
 
@@ -175,10 +175,10 @@ static void minefield_free(void *ptr)
     region_start = (char *) ptr - (char *) minefield_pages;
     i = region_start / PAGESIZE;
     if (i < 0 || i >= minefield_npages ||
-	minefield_admin[i] != region_start % PAGESIZE)
-	minefield_bomb();
+        minefield_admin[i] != region_start % PAGESIZE)
+        minefield_bomb();
     for (j = i; j < minefield_npages && minefield_admin[j] != 0xFFFF; j++) {
-	minefield_admin[j] = 0xFFFF;
+        minefield_admin[j] = 0xFFFF;
     }
 
     VirtualFree(ptr, j * PAGESIZE - region_start, MEM_DECOMMIT);
@@ -195,8 +195,8 @@ static int minefield_get_size(void *ptr)
     region_start = (char *) ptr - (char *) minefield_pages;
     i = region_start / PAGESIZE;
     if (i < 0 || i >= minefield_npages ||
-	minefield_admin[i] != region_start % PAGESIZE)
-	minefield_bomb();
+        minefield_admin[i] != region_start % PAGESIZE)
+        minefield_bomb();
     for (j = i; j < minefield_npages && minefield_admin[j] != 0xFFFF; j++);
 
     minefield_admin_hide(1);
@@ -207,14 +207,14 @@ static int minefield_get_size(void *ptr)
 void *minefield_c_malloc(size_t size)
 {
     if (!minefield_initialised)
-	minefield_init();
+        minefield_init();
     return minefield_alloc(size);
 }
 
 void minefield_c_free(void *p)
 {
     if (!minefield_initialised)
-	minefield_init();
+        minefield_init();
     minefield_free(p);
 }
 
@@ -227,7 +227,7 @@ void *minefield_c_realloc(void *p, size_t size)
     size_t oldsize;
     void *q;
     if (!minefield_initialised)
-	minefield_init();
+        minefield_init();
     q = minefield_alloc(size);
     oldsize = minefield_get_size(p);
     memcpy(q, p, (oldsize < size ? oldsize : size));
@@ -235,7 +235,7 @@ void *minefield_c_realloc(void *p, size_t size)
     return q;
 }
 
-#endif				/* MINEFIELD */
+#endif                          /* MINEFIELD */
 
 #if defined _MSC_VER && _MSC_VER < 1800
 

Разница между файлами не показана из-за своего большого размера
+ 311 - 311
source/putty/windows/winnet.c


+ 7 - 7
source/putty/windows/winnoise.c

@@ -57,10 +57,10 @@ void noise_get_heavy(void (*func) (void *, int))
     strcat(winpath, "\\*");
     srch = FindFirstFile(winpath, &finddata);
     if (srch != INVALID_HANDLE_VALUE) {
-	do {
-	    func(&finddata, sizeof(finddata));
-	} while (FindNextFile(srch, &finddata));
-	FindClose(srch);
+        do {
+            func(&finddata, sizeof(finddata));
+        } while (FindNextFile(srch, &finddata));
+        FindClose(srch);
     }
 
     pid = GetCurrentProcessId();
@@ -104,10 +104,10 @@ void noise_regular(void)
     random_add_noise(NOISE_SOURCE_MEMINFO, &memstat, sizeof(memstat));
 
     GetThreadTimes(GetCurrentThread(), times, times + 1, times + 2,
-		   times + 3);
+                   times + 3);
     random_add_noise(NOISE_SOURCE_THREADTIME, &times, sizeof(times));
     GetProcessTimes(GetCurrentProcess(), times, times + 1, times + 2,
-		    times + 3);
+                    times + 3);
     random_add_noise(NOISE_SOURCE_PROCTIME, &times, sizeof(times));
 }
 
@@ -128,7 +128,7 @@ void noise_ultralight(NoiseSourceId id, unsigned long data)
     random_add_noise(NOISE_SOURCE_TIME, &wintime, sizeof(DWORD));
 
     if (QueryPerformanceCounter(&perftime))
-	random_add_noise(NOISE_SOURCE_PERFCOUNT, &perftime, sizeof(perftime));
+        random_add_noise(NOISE_SOURCE_PERFCOUNT, &perftime, sizeof(perftime));
 }
 
 uint64_t prng_reseed_time_ms(void)

+ 6 - 6
source/putty/windows/winpgntc.c

@@ -20,9 +20,9 @@ bool agent_exists(void)
     HWND hwnd;
     hwnd = FindWindow("Pageant", "Pageant");
     if (!hwnd)
-	return false;
+        return false;
     else
-	return true;
+        return true;
 }
 
 void agent_cancel_query(agent_pending_query *q)
@@ -52,7 +52,7 @@ agent_pending_query *agent_query(
 
     hwnd = FindWindow("Pageant", "Pageant");
     if (!hwnd)
-	return NULL;		       /* *out == NULL, so failure */
+        return NULL;                   /* *out == NULL, so failure */
     mapname = dupprintf("PageantRequest%08x", (unsigned)GetCurrentThreadId());
 
     psa = NULL;
@@ -90,10 +90,10 @@ agent_pending_query *agent_query(
 #endif /* NO_SECURITY */
 
     filemap = CreateFileMapping(INVALID_HANDLE_VALUE, psa, PAGE_READWRITE,
-				0, AGENT_MAX_MSGLEN, mapname);
+                                0, AGENT_MAX_MSGLEN, mapname);
     if (filemap == NULL || filemap == INVALID_HANDLE_VALUE) {
         sfree(mapname);
-	return NULL;		       /* *out == NULL, so failure */
+        return NULL;                   /* *out == NULL, so failure */
     }
     p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
     strbuf_finalise_agent_query(query);
@@ -113,7 +113,7 @@ agent_pending_query *agent_query(
         if (length_field > 0 && length_field <= AGENT_MAX_MSGLEN - 4) {
             retlen = length_field + 4;
             ret = snewn(retlen, unsigned char);
-	    memcpy(ret, p, retlen);
+            memcpy(ret, p, retlen);
             *out = ret;
             *outlen = retlen;
         } else {

+ 10 - 10
source/putty/windows/winproxy.c

@@ -26,7 +26,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
     PROCESS_INFORMATION pi;
 
     if (conf_get_int(conf, CONF_proxy_type) != PROXY_CMD)
-	return NULL;
+        return NULL;
 
     cmd = format_telnet_command(addr, port, conf);
 
@@ -34,9 +34,9 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
     sk_addr_free(addr);
 
     {
-	char *msg = dupprintf("Starting local proxy command: %s", cmd);
-	plug_log(plug, 2, NULL, 0, msg, 0);
-	sfree(msg);
+        char *msg = dupprintf("Starting local proxy command: %s", cmd);
+        plug_log(plug, 2, NULL, 0, msg, 0);
+        sfree(msg);
     }
 
     /*
@@ -48,16 +48,16 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
     sa.bInheritHandle = true;
     if (!CreatePipe(&us_from_cmd, &cmd_to_us, &sa, 0)) {
         sfree(cmd);
-	return new_error_socket_fmt(
+        return new_error_socket_fmt(
             plug, "Unable to create pipes for proxy command: %s",
             win_strerror(GetLastError()));
     }
 
     if (!CreatePipe(&cmd_from_us, &us_to_cmd, &sa, 0)) {
         sfree(cmd);
-	CloseHandle(us_from_cmd);
-	CloseHandle(cmd_to_us);
-	return new_error_socket_fmt(
+        CloseHandle(us_from_cmd);
+        CloseHandle(cmd_to_us);
+        return new_error_socket_fmt(
             plug, "Unable to create pipes for proxy command: %s",
             win_strerror(GetLastError()));
     }
@@ -89,8 +89,8 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
     si.hStdOutput = cmd_to_us;
     si.hStdError = cmd_err_to_us;
     CreateProcess(NULL, cmd, NULL, NULL, true,
-		  CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS,
-		  NULL, NULL, &si, &pi);
+                  CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS,
+                  NULL, NULL, &si, &pi);
     CloseHandle(pi.hProcess);
     CloseHandle(pi.hThread);
 

+ 12 - 12
source/putty/windows/winsecur.c

@@ -150,7 +150,7 @@ bool getsids(char **error)
  cleanup:
     return ret;
 }
-  
+
 
 bool make_private_security_descriptor(DWORD permissions,
                                       PSECURITY_DESCRIPTOR *psd,
@@ -246,14 +246,14 @@ static bool really_restrict_process_acl(char **error)
     PACL acl = NULL;
 
     static const DWORD nastyace=WRITE_DAC | WRITE_OWNER |
-	PROCESS_CREATE_PROCESS | PROCESS_CREATE_THREAD |
-	PROCESS_DUP_HANDLE |
-	PROCESS_SET_QUOTA | PROCESS_SET_INFORMATION |
-	PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE |
-	PROCESS_SUSPEND_RESUME;
+        PROCESS_CREATE_PROCESS | PROCESS_CREATE_THREAD |
+        PROCESS_DUP_HANDLE |
+        PROCESS_SET_QUOTA | PROCESS_SET_INFORMATION |
+        PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE |
+        PROCESS_SUSPEND_RESUME;
 
     if (!getsids(error))
-	goto cleanup;
+        goto cleanup;
 
     memset(ea, 0, sizeof(ea));
 
@@ -274,7 +274,7 @@ static bool really_restrict_process_acl(char **error)
     acl_err = p_SetEntriesInAclA(2, ea, NULL, &acl);
 
     if (acl_err != ERROR_SUCCESS || acl == NULL) {
-	*error = dupprintf("unable to construct ACL: %s",
+        *error = dupprintf("unable to construct ACL: %s",
                            win_strerror(acl_err));
         goto cleanup;
     }
@@ -283,14 +283,14 @@ static bool really_restrict_process_acl(char **error)
         (GetCurrentProcess(), SE_KERNEL_OBJECT,
          OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
          usersid, NULL, acl, NULL)) {
-	*error = dupprintf("Unable to set process ACL: %s",
+        *error = dupprintf("Unable to set process ACL: %s",
                            win_strerror(GetLastError()));
-	goto cleanup;
+        goto cleanup;
     }
-		      
+
 
     ret=true;
-    
+
   cleanup:
     if (!ret) {
         if (acl) {

+ 10 - 10
source/putty/windows/winsecur.h

@@ -16,23 +16,23 @@
  * Functions loaded from advapi32.dll.
  */
 DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, BOOL, OpenProcessToken,
-		      (HANDLE, DWORD, PHANDLE));
+                      (HANDLE, DWORD, PHANDLE));
 DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, BOOL, GetTokenInformation,
-		      (HANDLE, TOKEN_INFORMATION_CLASS,
+                      (HANDLE, TOKEN_INFORMATION_CLASS,
                        LPVOID, DWORD, PDWORD));
 DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, BOOL, InitializeSecurityDescriptor,
-		      (PSECURITY_DESCRIPTOR, DWORD));
+                      (PSECURITY_DESCRIPTOR, DWORD));
 DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, BOOL, SetSecurityDescriptorOwner,
-		      (PSECURITY_DESCRIPTOR, PSID, BOOL));
+                      (PSECURITY_DESCRIPTOR, PSID, BOOL));
 DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, GetSecurityInfo,
-		      (HANDLE, SE_OBJECT_TYPE, SECURITY_INFORMATION,
-		       PSID *, PSID *, PACL *, PACL *,
-		       PSECURITY_DESCRIPTOR *));
+                      (HANDLE, SE_OBJECT_TYPE, SECURITY_INFORMATION,
+                       PSID *, PSID *, PACL *, PACL *,
+                       PSECURITY_DESCRIPTOR *));
 DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, SetSecurityInfo,
-		      (HANDLE, SE_OBJECT_TYPE, SECURITY_INFORMATION,
-		       PSID, PSID, PACL, PACL));
+                      (HANDLE, SE_OBJECT_TYPE, SECURITY_INFORMATION,
+                       PSID, PSID, PACL, PACL));
 DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, SetEntriesInAclA,
-		      (ULONG, PEXPLICIT_ACCESS, PACL, PACL *));
+                      (ULONG, PEXPLICIT_ACCESS, PACL, PACL *));
 bool got_advapi(void);
 
 /*

+ 166 - 166
source/putty/windows/winstore.c

@@ -40,7 +40,7 @@ static const char *const puttystr = PUTTY_REG_POS "\\Sessions";
 static bool tried_shgetfolderpath = false;
 static HMODULE shell32_module = NULL;
 DECL_WINDOWS_FUNCTION(static, HRESULT, SHGetFolderPathA,
-		      (HWND, int, HANDLE, DWORD, LPSTR));
+                      (HWND, int, HANDLE, DWORD, LPSTR));
 
 struct settings_w {
     HKEY sesskey;
@@ -55,25 +55,25 @@ settings_w *open_settings_w(const char *sessionname, char **errmsg)
     *errmsg = NULL;
 
     if (!sessionname || !*sessionname)
-	sessionname = "Default Settings";
+        sessionname = "Default Settings";
 
     sb = strbuf_new();
     escape_registry_key(sessionname, sb);
 
     ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);
     if (ret != ERROR_SUCCESS) {
-	strbuf_free(sb);
+        strbuf_free(sb);
         *errmsg = dupprintf("Unable to create registry key\n"
                             "HKEY_CURRENT_USER\\%s", puttystr);
-	return NULL;
+        return NULL;
     }
     ret = RegCreateKey(subkey1, sb->s, &sesskey);
     RegCloseKey(subkey1);
     if (ret != ERROR_SUCCESS) {
         *errmsg = dupprintf("Unable to create registry key\n"
                             "HKEY_CURRENT_USER\\%s\\%s", puttystr, sb->s);
-	strbuf_free(sb);
-	return NULL;
+        strbuf_free(sb);
+        return NULL;
     }
     strbuf_free(sb);
 
@@ -88,14 +88,14 @@ void write_setting_s(settings_w *handle, const char *key, const char *value)
 {
     if (handle)
         RegSetValueEx(handle->sesskey, key, 0, REG_SZ, (CONST BYTE *)value,
-		      1 + strlen(value));
+                      1 + strlen(value));
 }
 
 void write_setting_i(settings_w *handle, const char *key, int value)
 {
     if (handle)
         RegSetValueEx(handle->sesskey, key, 0, REG_DWORD,
-		      (CONST BYTE *) &value, sizeof(value));
+                      (CONST BYTE *) &value, sizeof(value));
 }
 
 void close_settings_w(settings_w *handle)
@@ -114,18 +114,18 @@ settings_r *open_settings_r(const char *sessionname)
     strbuf *sb;
 
     if (!sessionname || !*sessionname)
-	sessionname = "Default Settings";
+        sessionname = "Default Settings";
 
     sb = strbuf_new();
     escape_registry_key(sessionname, sb);
 
     if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS) {
-	sesskey = NULL;
+        sesskey = NULL;
     } else {
-	if (RegOpenKey(subkey1, sb->s, &sesskey) != ERROR_SUCCESS) {
-	    sesskey = NULL;
-	}
-	RegCloseKey(subkey1);
+        if (RegOpenKey(subkey1, sb->s, &sesskey) != ERROR_SUCCESS) {
+            sesskey = NULL;
+        }
+        RegCloseKey(subkey1);
     }
 
     strbuf_free(sb);
@@ -146,19 +146,19 @@ char *read_setting_s(settings_r *handle, const char *key)
     char *ret;
 
     if (!handle)
-	return NULL;
+        return NULL;
 
     /* Find out the type and size of the data. */
     if (RegQueryValueEx(handle->sesskey, key, 0,
-			&type, NULL, &size) != ERROR_SUCCESS ||
-	type != REG_SZ)
-	return NULL;
+                        &type, NULL, &size) != ERROR_SUCCESS ||
+        type != REG_SZ)
+        return NULL;
 
     allocsize = size+1;         /* allow for an extra NUL if needed */
     ret = snewn(allocsize, char);
     if (RegQueryValueEx(handle->sesskey, key, 0,
-			&type, (BYTE *)ret, &size) != ERROR_SUCCESS ||
-	type != REG_SZ) {
+                        &type, (BYTE *)ret, &size) != ERROR_SUCCESS ||
+        type != REG_SZ) {
         sfree(ret);
         return NULL;
     }
@@ -176,11 +176,11 @@ int read_setting_i(settings_r *handle, const char *key, int defvalue)
 
     if (!handle ||
         RegQueryValueEx(handle->sesskey, key, 0, &type,
-			(BYTE *) &val, &size) != ERROR_SUCCESS ||
-	size != sizeof(val) || type != REG_DWORD)
-	return defvalue;
+                        (BYTE *) &val, &size) != ERROR_SUCCESS ||
+        size != sizeof(val) || type != REG_DWORD)
+        return defvalue;
     else
-	return val;
+        return val;
 }
 
 FontSpec *read_setting_fontspec(settings_r *handle, const char *name)
@@ -192,7 +192,7 @@ FontSpec *read_setting_fontspec(settings_r *handle, const char *name)
 
     fontname = read_setting_s(handle, name);
     if (!fontname)
-	return NULL;
+        return NULL;
 
     settingname = dupcat(name, "IsBold", NULL);
     isbold = read_setting_i(handle, settingname, -1);
@@ -245,10 +245,10 @@ Filename *read_setting_filename(settings_r *handle, const char *name)
     char *tmp = read_setting_s(handle, name);
     if (tmp) {
         Filename *ret = filename_from_str(tmp);
-	sfree(tmp);
-	return ret;
+        sfree(tmp);
+        return ret;
     } else
-	return NULL;
+        return NULL;
 }
 
 void write_setting_filename(settings_w *handle,
@@ -271,7 +271,7 @@ void del_settings(const char *sessionname)
     strbuf *sb;
 
     if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS)
-	return;
+        return;
 
     sb = strbuf_new();
     escape_registry_key(sessionname, sb);
@@ -294,12 +294,12 @@ settings_e *enum_settings_start(void)
     HKEY key;
 
     if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &key) != ERROR_SUCCESS)
-	return NULL;
+        return NULL;
 
     ret = snew(settings_e);
     if (ret) {
-	ret->key = key;
-	ret->i = 0;
+        ret->key = key;
+        ret->i = 0;
     }
 
     return ret;
@@ -335,7 +335,7 @@ void enum_settings_finish(settings_e *e)
 }
 
 static void hostkey_regname(strbuf *sb, const char *hostname,
-			    int port, const char *keytype)
+                            int port, const char *keytype)
 {
     strbuf_catf(sb, "%s@%d:", keytype, port);
     escape_registry_key(hostname, sb);
@@ -346,7 +346,7 @@ int retrieve_host_key(const char *hostname, int port,
 		    const char *keytype, char *key, int maxlen)
 #else
 int verify_host_key(const char *hostname, int port,
-		    const char *keytype, const char *key)
+                    const char *keytype, const char *key)
 #endif
 {
     char *otherstr;
@@ -371,9 +371,9 @@ int verify_host_key(const char *hostname, int port,
     hostkey_regname(regname, hostname, port, keytype);
 
     if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys",
-		   &rkey) != ERROR_SUCCESS) {
+                   &rkey) != ERROR_SUCCESS) {
         strbuf_free(regname);
-	return 1;		       /* key does not exist in registry */
+        return 1;                      /* key does not exist in registry */
     }
 
     readlen = len;
@@ -382,65 +382,65 @@ int verify_host_key(const char *hostname, int port,
                           &type, (BYTE *)otherstr, &readlen);
 
     if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA &&
-	!strcmp(keytype, "rsa")) {
-	/*
-	 * Key didn't exist. If the key type is RSA, we'll try
-	 * another trick, which is to look up the _old_ key format
-	 * under just the hostname and translate that.
-	 */
-	char *justhost = regname->s + 1 + strcspn(regname->s, ":");
-	char *oldstyle = snewn(len + 10, char);	/* safety margin */
-	readlen = len;
-	ret = RegQueryValueEx(rkey, justhost, NULL, &type,
-			      (BYTE *)oldstyle, &readlen);
-
-	if (ret == ERROR_SUCCESS && type == REG_SZ) {
-	    /*
-	     * The old format is two old-style bignums separated by
-	     * a slash. An old-style bignum is made of groups of
-	     * four hex digits: digits are ordered in sensible
-	     * (most to least significant) order within each group,
-	     * but groups are ordered in silly (least to most)
-	     * order within the bignum. The new format is two
-	     * ordinary C-format hex numbers (0xABCDEFG...XYZ, with
-	     * A nonzero except in the special case 0x0, which
-	     * doesn't appear anyway in RSA keys) separated by a
-	     * comma. All hex digits are lowercase in both formats.
-	     */
-	    char *p = otherstr;
-	    char *q = oldstyle;
-	    int i, j;
-
-	    for (i = 0; i < 2; i++) {
-		int ndigits, nwords;
-		*p++ = '0';
-		*p++ = 'x';
-		ndigits = strcspn(q, "/");	/* find / or end of string */
-		nwords = ndigits / 4;
-		/* now trim ndigits to remove leading zeros */
-		while (q[(ndigits - 1) ^ 3] == '0' && ndigits > 1)
-		    ndigits--;
-		/* now move digits over to new string */
-		for (j = 0; j < ndigits; j++)
-		    p[ndigits - 1 - j] = q[j ^ 3];
-		p += ndigits;
-		q += nwords * 4;
-		if (*q) {
-		    q++;	       /* eat the slash */
-		    *p++ = ',';	       /* add a comma */
-		}
-		*p = '\0';	       /* terminate the string */
-	    }
-
-	    /*
-	     * Now _if_ this key matches, we'll enter it in the new
-	     * format. If not, we'll assume something odd went
-	     * wrong, and hyper-cautiously do nothing.
-	     */
-	    if (!strcmp(otherstr, key))
-		RegSetValueEx(rkey, regname->s, 0, REG_SZ, (BYTE *)otherstr,
-			      strlen(otherstr) + 1);
-	}
+        !strcmp(keytype, "rsa")) {
+        /*
+         * Key didn't exist. If the key type is RSA, we'll try
+         * another trick, which is to look up the _old_ key format
+         * under just the hostname and translate that.
+         */
+        char *justhost = regname->s + 1 + strcspn(regname->s, ":");
+        char *oldstyle = snewn(len + 10, char); /* safety margin */
+        readlen = len;
+        ret = RegQueryValueEx(rkey, justhost, NULL, &type,
+                              (BYTE *)oldstyle, &readlen);
+
+        if (ret == ERROR_SUCCESS && type == REG_SZ) {
+            /*
+             * The old format is two old-style bignums separated by
+             * a slash. An old-style bignum is made of groups of
+             * four hex digits: digits are ordered in sensible
+             * (most to least significant) order within each group,
+             * but groups are ordered in silly (least to most)
+             * order within the bignum. The new format is two
+             * ordinary C-format hex numbers (0xABCDEFG...XYZ, with
+             * A nonzero except in the special case 0x0, which
+             * doesn't appear anyway in RSA keys) separated by a
+             * comma. All hex digits are lowercase in both formats.
+             */
+            char *p = otherstr;
+            char *q = oldstyle;
+            int i, j;
+
+            for (i = 0; i < 2; i++) {
+                int ndigits, nwords;
+                *p++ = '0';
+                *p++ = 'x';
+                ndigits = strcspn(q, "/");      /* find / or end of string */
+                nwords = ndigits / 4;
+                /* now trim ndigits to remove leading zeros */
+                while (q[(ndigits - 1) ^ 3] == '0' && ndigits > 1)
+                    ndigits--;
+                /* now move digits over to new string */
+                for (j = 0; j < ndigits; j++)
+                    p[ndigits - 1 - j] = q[j ^ 3];
+                p += ndigits;
+                q += nwords * 4;
+                if (*q) {
+                    q++;               /* eat the slash */
+                    *p++ = ',';        /* add a comma */
+                }
+                *p = '\0';             /* terminate the string */
+            }
+
+            /*
+             * Now _if_ this key matches, we'll enter it in the new
+             * format. If not, we'll assume something odd went
+             * wrong, and hyper-cautiously do nothing.
+             */
+            if (!strcmp(otherstr, key))
+                RegSetValueEx(rkey, regname->s, 0, REG_SZ, (BYTE *)otherstr,
+                              strlen(otherstr) + 1);
+        }
 
         sfree(oldstyle);
     }
@@ -464,19 +464,19 @@ int verify_host_key(const char *hostname, int port,
 
 #ifndef MPEXT
     if (ret == ERROR_MORE_DATA ||
-	(ret == ERROR_SUCCESS && type == REG_SZ && compare))
-	return 2;		       /* key is different in registry */
+        (ret == ERROR_SUCCESS && type == REG_SZ && compare))
+        return 2;                      /* key is different in registry */
     else
 #endif
     if (ret != ERROR_SUCCESS || type != REG_SZ)
-	return 1;		       /* key does not exist in registry */
+        return 1;                      /* key does not exist in registry */
     else
-	return 0;		       /* key matched OK in registry */
+        return 0;                      /* key matched OK in registry */
 }
 
 #ifndef MPEXT
 bool have_ssh_host_key(const char *hostname, int port,
-		      const char *keytype)
+                      const char *keytype)
 {
     /*
      * If we have a host key, verify_host_key will return 0 or 2.
@@ -487,7 +487,7 @@ bool have_ssh_host_key(const char *hostname, int port,
 #endif
 
 void store_host_key(const char *hostname, int port,
-		    const char *keytype, const char *key)
+                    const char *keytype, const char *key)
 {
     strbuf *regname;
     HKEY rkey;
@@ -496,10 +496,10 @@ void store_host_key(const char *hostname, int port,
     hostkey_regname(regname, hostname, port, keytype);
 
     if (RegCreateKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys",
-		     &rkey) == ERROR_SUCCESS) {
-	RegSetValueEx(rkey, regname->s, 0, REG_SZ,
+                     &rkey) == ERROR_SUCCESS) {
+        RegSetValueEx(rkey, regname->s, 0, REG_SZ,
                       (BYTE *)key, strlen(key) + 1);
-	RegCloseKey(rkey);
+        RegCloseKey(rkey);
     } /* else key does not exist in registry */
 
     strbuf_free(regname);
@@ -516,18 +516,18 @@ static bool try_random_seed(char const *path, int action, HANDLE *ret)
             nonfatal("Unable to delete '%s': %s", path,
                      win_strerror(GetLastError()));
         }
-	*ret = INVALID_HANDLE_VALUE;
-	return false;		       /* so we'll do the next ones too */
+        *ret = INVALID_HANDLE_VALUE;
+        return false;                  /* so we'll do the next ones too */
     }
 
     *ret = CreateFile(path,
-		      action == OPEN_W ? GENERIC_WRITE : GENERIC_READ,
-		      action == OPEN_W ? 0 : (FILE_SHARE_READ |
-					      FILE_SHARE_WRITE),
-		      NULL,
-		      action == OPEN_W ? CREATE_ALWAYS : OPEN_EXISTING,
-		      action == OPEN_W ? FILE_ATTRIBUTE_NORMAL : 0,
-		      NULL);
+                      action == OPEN_W ? GENERIC_WRITE : GENERIC_READ,
+                      action == OPEN_W ? 0 : (FILE_SHARE_READ |
+                                              FILE_SHARE_WRITE),
+                      NULL,
+                      action == OPEN_W ? CREATE_ALWAYS : OPEN_EXISTING,
+                      action == OPEN_W ? FILE_ATTRIBUTE_NORMAL : 0,
+                      NULL);
 
     return (*ret != INVALID_HANDLE_VALUE);
 }
@@ -580,27 +580,27 @@ static HANDLE access_random_seed(int action)
      * versions of Windows.
      */
     if (!tried_shgetfolderpath) {
-	/* This is likely only to bear fruit on systems with IE5+
-	 * installed, or WinMe/2K+. There is some faffing with
-	 * SHFOLDER.DLL we could do to try to find an equivalent
-	 * on older versions of Windows if we cared enough.
-	 * However, the invocation below requires IE5+ anyway,
-	 * so stuff that. */
-	shell32_module = load_system32_dll("shell32.dll");
-	GET_WINDOWS_FUNCTION(shell32_module, SHGetFolderPathA);
-	tried_shgetfolderpath = true;
+        /* This is likely only to bear fruit on systems with IE5+
+         * installed, or WinMe/2K+. There is some faffing with
+         * SHFOLDER.DLL we could do to try to find an equivalent
+         * on older versions of Windows if we cared enough.
+         * However, the invocation below requires IE5+ anyway,
+         * so stuff that. */
+        shell32_module = load_system32_dll("shell32.dll");
+        GET_WINDOWS_FUNCTION(shell32_module, SHGetFolderPathA);
+        tried_shgetfolderpath = true;
     }
     if (p_SHGetFolderPathA) {
         char profile[MAX_PATH + 1];
-	if (SUCCEEDED(p_SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA,
-					 NULL, SHGFP_TYPE_CURRENT, profile)) &&
+        if (SUCCEEDED(p_SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA,
+                                         NULL, SHGFP_TYPE_CURRENT, profile)) &&
             try_random_seed_and_free(dupcat(profile, "\\PUTTY.RND",
                                             (const char *)NULL),
                                      action, &rethandle))
             return rethandle;
 
-	if (SUCCEEDED(p_SHGetFolderPathA(NULL, CSIDL_APPDATA,
-					 NULL, SHGFP_TYPE_CURRENT, profile)) &&
+        if (SUCCEEDED(p_SHGetFolderPathA(NULL, CSIDL_APPDATA,
+                                         NULL, SHGFP_TYPE_CURRENT, profile)) &&
             try_random_seed_and_free(dupcat(profile, "\\PUTTY.RND",
                                             (const char *)NULL),
                                      action, &rethandle))
@@ -612,7 +612,7 @@ static HANDLE access_random_seed(int action)
      * user's home directory.
      */
     {
-	char drv[MAX_PATH], path[MAX_PATH];
+        char drv[MAX_PATH], path[MAX_PATH];
 
         DWORD drvlen = GetEnvironmentVariable("HOMEDRIVE", drv, sizeof(drv));
         DWORD pathlen = GetEnvironmentVariable("HOMEPATH", path, sizeof(path));
@@ -654,16 +654,16 @@ void read_random_seed(noise_consumer_t consumer)
     HANDLE seedf = access_random_seed(OPEN_R);
 
     if (seedf != INVALID_HANDLE_VALUE) {
-	while (1) {
-	    char buf[1024];
-	    DWORD len;
-
-	    if (ReadFile(seedf, buf, sizeof(buf), &len, NULL) && len)
-		consumer(buf, len);
-	    else
-		break;
-	}
-	CloseHandle(seedf);
+        while (1) {
+            char buf[1024];
+            DWORD len;
+
+            if (ReadFile(seedf, buf, sizeof(buf), &len, NULL) && len)
+                consumer(buf, len);
+            else
+                break;
+        }
+        CloseHandle(seedf);
     }
 }
 
@@ -672,10 +672,10 @@ void write_random_seed(void *data, int len)
     HANDLE seedf = access_random_seed(OPEN_W);
 
     if (seedf != INVALID_HANDLE_VALUE) {
-	DWORD lenwritten;
+        DWORD lenwritten;
 
-	WriteFile(seedf, data, len, &lenwritten, NULL);
-	CloseHandle(seedf);
+        WriteFile(seedf, data, len, &lenwritten, NULL);
+        CloseHandle(seedf);
     }
 }
 
@@ -702,7 +702,7 @@ static int transform_jumplist_registry
                          REG_OPTION_NON_VOLATILE, (KEY_READ | KEY_WRITE), NULL,
                          &pjumplist_key, NULL);
     if (ret != ERROR_SUCCESS) {
-	return JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE;
+        return JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE;
     }
 
     /* Get current list of saved sessions in the registry. */
@@ -835,7 +835,7 @@ char *get_jumplist_registry_entries (void)
     char *list_value;
 
     if (transform_jumplist_registry(NULL,NULL,&list_value) != JUMPLISTREG_OK) {
-	list_value = snewn(2, char);
+        list_value = snewn(2, char);
         *list_value = '\0';
         *(list_value + 1) = '\0';
     }
@@ -853,11 +853,11 @@ static void registry_recursive_remove(HKEY key)
 
     i = 0;
     while (RegEnumKey(key, i, name, sizeof(name)) == ERROR_SUCCESS) {
-	if (RegOpenKey(key, name, &subkey) == ERROR_SUCCESS) {
-	    registry_recursive_remove(subkey);
-	    RegCloseKey(subkey);
-	}
-	RegDeleteKey(key, name);
+        if (RegOpenKey(key, name, &subkey) == ERROR_SUCCESS) {
+            registry_recursive_remove(subkey);
+            RegCloseKey(subkey);
+        }
+        RegDeleteKey(key, name);
     }
 }
 
@@ -887,9 +887,9 @@ void cleanup_all(void)
      * Open the main PuTTY registry key and remove everything in it.
      */
     if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS, &key) ==
-	ERROR_SUCCESS) {
-	registry_recursive_remove(key);
-	RegCloseKey(key);
+        ERROR_SUCCESS) {
+        registry_recursive_remove(key);
+        RegCloseKey(key);
     }
     /*
      * Now open the parent key and remove the PuTTY main key. Once
@@ -897,22 +897,22 @@ void cleanup_all(void)
      * children.
      */
     if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_PARENT,
-		   &key) == ERROR_SUCCESS) {
-	RegDeleteKey(key, PUTTY_REG_PARENT_CHILD);
-	ret = RegEnumKey(key, 0, name, sizeof(name));
-	RegCloseKey(key);
-	/*
-	 * If the parent key had no other children, we must delete
-	 * it in its turn. That means opening the _grandparent_
-	 * key.
-	 */
-	if (ret != ERROR_SUCCESS) {
-	    if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_GPARENT,
-			   &key) == ERROR_SUCCESS) {
-		RegDeleteKey(key, PUTTY_REG_GPARENT_CHILD);
-		RegCloseKey(key);
-	    }
-	}
+                   &key) == ERROR_SUCCESS) {
+        RegDeleteKey(key, PUTTY_REG_PARENT_CHILD);
+        ret = RegEnumKey(key, 0, name, sizeof(name));
+        RegCloseKey(key);
+        /*
+         * If the parent key had no other children, we must delete
+         * it in its turn. That means opening the _grandparent_
+         * key.
+         */
+        if (ret != ERROR_SUCCESS) {
+            if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_GPARENT,
+                           &key) == ERROR_SUCCESS) {
+                RegDeleteKey(key, PUTTY_REG_GPARENT_CHILD);
+                RegCloseKey(key);
+            }
+        }
     }
     /*
      * Now we're done.

+ 48 - 48
source/putty/windows/winstuff.h

@@ -9,7 +9,7 @@
 #include <winsock2.h>
 #endif
 #include <windows.h>
-#include <stdio.h>		       /* for FILENAME_MAX */
+#include <stdio.h>                     /* for FILENAME_MAX */
 
 /* We use uintptr_t for Win32/Win64 portability, so we should in
  * principle include stdint.h, which defines it according to the C
@@ -69,7 +69,7 @@ struct FontSpec *fontspec_new(
     CLEARTYPE_QUALITY)
 
 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
-			   * wchar_t strings with environment */
+                           * wchar_t strings with environment */
 
 #define PLATFORM_CLIPBOARDS(X)                      \
     X(CLIP_SYSTEM, "system clipboard")              \
@@ -192,7 +192,7 @@ struct FontSpec *fontspec_new(
 
 #define GETTICKCOUNT GetTickCount
 #define CURSORBLINK GetCaretBlinkTime()
-#define TICKSPERSEC 1000	       /* GetTickCount returns milliseconds */
+#define TICKSPERSEC 1000               /* GetTickCount returns milliseconds */
 
 #define DEFAULT_CODEPAGE CP_ACP
 #define USES_VTLINE_HACK
@@ -217,7 +217,7 @@ typedef void *Ssh_gss_name;
  * Window handles for the windows that can be running during a
  * PuTTY session.
  */
-GLOBAL HWND hwnd;	/* the main terminal window */
+GLOBAL HWND hwnd;       /* the main terminal window */
 GLOBAL HWND logbox;
 
 /*
@@ -306,11 +306,11 @@ void write_aclip(int clipboard, char *, int, bool);
  * `lpstrFilter' in an OPENFILENAME structure.
  */
 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
-			      "All Files (*.*)\0*\0\0\0")
+                              "All Files (*.*)\0*\0\0\0")
 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
-			       "All Files (*.*)\0*\0\0\0")
+                               "All Files (*.*)\0*\0\0\0")
 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
-				 "All Files (*.*)\0*\0\0\0")
+                                 "All Files (*.*)\0*\0\0\0")
 
 /*
  * Exports from winnet.c.
@@ -334,12 +334,12 @@ SockAddr *sk_namedpipe_addr(const char *pipename);
  * here they are.
  */
 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
-		      (SOCKET, HWND, u_int, long));
+                      (SOCKET, HWND, u_int, long));
 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
-		      (SOCKET, WSAEVENT, long));
+                      (SOCKET, WSAEVENT, long));
 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
-		      (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
+                      (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
 #ifdef NEED_DECLARATION_OF_SELECT
 /* This declaration is protected by an ifdef for the sake of building
  * against winelib, in which you have to include winsock2.h before
@@ -349,8 +349,8 @@ DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
  * this function pointer will see its declaration, and _those_ modules
  * - which will be Windows-specific anyway - can take more care. */
 DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
-		      (int, fd_set FAR *, fd_set FAR *,
-		       fd_set FAR *, const struct timeval FAR *));
+                      (int, fd_set FAR *, fd_set FAR *,
+                       fd_set FAR *, const struct timeval FAR *));
 #endif
 
 /*
@@ -409,21 +409,21 @@ struct prefslist {
  * parameter, and hence is passed back to winctrls access functions.
  */
 struct dlgparam {
-    HWND hwnd;			       /* the hwnd of the dialog box */
+    HWND hwnd;                         /* the hwnd of the dialog box */
     struct winctrls *controltrees[8];  /* can have several of these */
     int nctrltrees;
-    char *wintitle;		       /* title of actual window */
-    char *errtitle;		       /* title of error sub-messageboxes */
-    void *data;			       /* data to pass in refresh events */
+    char *wintitle;                    /* title of actual window */
+    char *errtitle;                    /* title of error sub-messageboxes */
+    void *data;                        /* data to pass in refresh events */
     union control *focused, *lastfocused; /* which ctrl has focus now/before */
     bool shortcuts[128];               /* track which shortcuts in use */
     bool coloursel_wanted;             /* has an event handler asked for
-					* a colour selector? */
+                                        * a colour selector? */
     struct {
         unsigned char r, g, b;         /* 0-255 */
         bool ok;
     } coloursel_result;
-    tree234 *privdata;		       /* stores per-control private data */
+    tree234 *privdata;                 /* stores per-control private data */
     bool ended;                        /* has the dialog been ended? */
     int endresult;                     /* and if so, what was the result? */
     bool fixed_pitch_fonts;            /* are we constrained to fixed fonts? */
@@ -433,57 +433,57 @@ struct dlgparam {
  * Exports from winctrls.c.
  */
 void ctlposinit(struct ctlpos *cp, HWND hwnd,
-		int leftborder, int rightborder, int topborder);
+                int leftborder, int rightborder, int topborder);
 HWND doctl(struct ctlpos *cp, RECT r,
-	   char *wclass, int wstyle, int exstyle, char *wtext, int wid);
+           char *wclass, int wstyle, int exstyle, char *wtext, int wid);
 void bartitle(struct ctlpos *cp, char *name, int id);
 void beginbox(struct ctlpos *cp, char *name, int idbox);
 void endbox(struct ctlpos *cp);
 void editboxfw(struct ctlpos *cp, bool password, char *text,
-	       int staticid, int editid);
+               int staticid, int editid);
 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
 void bareradioline(struct ctlpos *cp, int nacross, ...);
 void radiobig(struct ctlpos *cp, char *text, int id, ...);
 void checkbox(struct ctlpos *cp, char *text, int id);
 void statictext(struct ctlpos *cp, char *text, int lines, int id);
 void staticbtn(struct ctlpos *cp, char *stext, int sid,
-	       char *btext, int bid);
+               char *btext, int bid);
 void static2btn(struct ctlpos *cp, char *stext, int sid,
-		char *btext1, int bid1, char *btext2, int bid2);
+                char *btext1, int bid1, char *btext2, int bid2);
 void staticedit(struct ctlpos *cp, char *stext,
-		int sid, int eid, int percentedit);
+                int sid, int eid, int percentedit);
 void staticddl(struct ctlpos *cp, char *stext,
-	       int sid, int lid, int percentlist);
+               int sid, int lid, int percentlist);
 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
 void staticpassedit(struct ctlpos *cp, char *stext,
-		    int sid, int eid, int percentedit);
+                    int sid, int eid, int percentedit);
 void bigeditctrl(struct ctlpos *cp, char *stext,
-		 int sid, int eid, int lines);
+                 int sid, int eid, int lines);
 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
 void editbutton(struct ctlpos *cp, char *stext, int sid,
-		int eid, char *btext, int bid);
+                int eid, char *btext, int bid);
 void sesssaver(struct ctlpos *cp, char *text,
-	       int staticid, int editid, int listid, ...);
+               int staticid, int editid, int listid, ...);
 void envsetter(struct ctlpos *cp, char *stext, int sid,
-	       char *e1stext, int e1sid, int e1id,
-	       char *e2stext, int e2sid, int e2id,
-	       int listid, char *b1text, int b1id, char *b2text, int b2id);
+               char *e1stext, int e1sid, int e1id,
+               char *e2stext, int e2sid, int e2id,
+               int listid, char *b1text, int b1id, char *b2text, int b2id);
 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
-	       char *btext, int bid, int eid, char *s2text, int s2id);
+               char *btext, int bid, int eid, char *s2text, int s2id);
 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
-		char *btext, int bid, ...);
+                char *btext, int bid, ...);
 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
-	       char *stext, int sid, int listid, int upbid, int dnbid);
+               char *stext, int sid, int listid, int upbid, int dnbid);
 int handle_prefslist(struct prefslist *hdl,
-		     int *array, int maxmemb,
-		     bool is_dlmsg, HWND hwnd,
-		     WPARAM wParam, LPARAM lParam);
+                     int *array, int maxmemb,
+                     bool is_dlmsg, HWND hwnd,
+                     WPARAM wParam, LPARAM lParam);
 void progressbar(struct ctlpos *cp, int id);
 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
-	       char *e1stext, int e1sid, int e1id,
-	       char *e2stext, int e2sid, int e2id,
-	       char *btext, int bid,
-	       char *r1text, int r1id, char *r2text, int r2id);
+               char *e1stext, int e1sid, int e1id,
+               char *e2stext, int e2sid, int e2id,
+               char *btext, int bid,
+               char *r1text, int r1id, char *r2text, int r2id);
 
 void dlg_auto_set_fixed_pitch_flag(dlgparam *dlg);
 bool dlg_get_fixed_pitch_flag(dlgparam *dlg);
@@ -538,7 +538,7 @@ struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
 struct winctrl *winctrl_findbyid(struct winctrls *, int);
 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
-		    struct ctlpos *cp, struct controlset *s, int *id);
+                    struct ctlpos *cp, struct controlset *s, int *id);
 bool winctrl_handle_command(struct dlgparam *dp, UINT msg,
                             WPARAM wParam, LPARAM lParam);
 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
@@ -552,7 +552,7 @@ void dp_cleanup(struct dlgparam *dp);
  * Exports from wincfg.c.
  */
 void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help,
-			  bool midsession, int protocol);
+                          bool midsession, int protocol);
 
 /*
  * Exports from windlg.c.
@@ -621,9 +621,9 @@ typedef size_t (*handle_inputfn_t)(
 typedef void (*handle_outputfn_t)(
     struct handle *h, size_t new_backlog, int err);
 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
-				void *privdata, int flags);
+                                void *privdata, int flags);
 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
-				 void *privdata, int flags);
+                                 void *privdata, int flags);
 size_t handle_write(struct handle *h, const void *data, size_t len);
 void handle_write_eof(struct handle *h);
 HANDLE *handle_get_events(int *nevents);
@@ -649,12 +649,12 @@ void handle_sink_init(handle_sink *sink, struct handle *h);
  * winpgntc.c needs to schedule callbacks for asynchronous agent
  * requests. This has to be done differently in GUI and console, so
  * there's an exported function used for the purpose.
- * 
+ *
  * Also, we supply FLAG_SYNCAGENT to force agent requests to be
  * synchronous in pscp and psftp.
  */
 void agent_schedule_callback(void (*callback)(void *, void *, int),
-			     void *callback_ctx, void *data, int len);
+                             void *callback_ctx, void *data, int len);
 #define FLAG_SYNCAGENT 0x1000
 
 /*

+ 178 - 178
source/putty/windows/winucs.c

@@ -28,7 +28,7 @@ static const WCHAR unitab_xterm_std[32] = {
  * duplicate definitions.
  */
 
-/* 
+/*
  * Tables for ISO-8859-{1-10,13-16} derived from those downloaded
  * 2001-10-02 from <http://www.unicode.org/Public/MAPPINGS/> -- jtn
  * Table for ISO-8859-11 derived from same on 2002-11-18. -- bjh21
@@ -448,62 +448,62 @@ void init_ucs(Conf *conf, struct unicode_data *ucsdata)
 
     /* Decide on the Line and Font codepages */
     ucsdata->line_codepage = decode_codepage(conf_get_str(conf,
-							  CONF_line_codepage));
+                                                          CONF_line_codepage));
 
-    if (ucsdata->font_codepage <= 0) { 
-	ucsdata->font_codepage=0; 
-	ucsdata->dbcs_screenfont=false;
+    if (ucsdata->font_codepage <= 0) {
+        ucsdata->font_codepage=0;
+        ucsdata->dbcs_screenfont=false;
     }
 
     vtmode = conf_get_int(conf, CONF_vtmode);
     if (vtmode == VT_OEMONLY) {
-	ucsdata->font_codepage = 437;
-	ucsdata->dbcs_screenfont = false;
-	if (ucsdata->line_codepage <= 0)
-	    ucsdata->line_codepage = GetACP();
+        ucsdata->font_codepage = 437;
+        ucsdata->dbcs_screenfont = false;
+        if (ucsdata->line_codepage <= 0)
+            ucsdata->line_codepage = GetACP();
     } else if (ucsdata->line_codepage <= 0)
-	ucsdata->line_codepage = ucsdata->font_codepage;
+        ucsdata->line_codepage = ucsdata->font_codepage;
 
     /* Collect screen font ucs table */
     if (ucsdata->dbcs_screenfont || ucsdata->font_codepage == 0) {
-	get_unitab(ucsdata->font_codepage, ucsdata->unitab_font, 2);
-	for (i = 128; i < 256; i++)
-	    ucsdata->unitab_font[i] = (WCHAR) (CSET_ACP + i);
+        get_unitab(ucsdata->font_codepage, ucsdata->unitab_font, 2);
+        for (i = 128; i < 256; i++)
+            ucsdata->unitab_font[i] = (WCHAR) (CSET_ACP + i);
     } else {
-	get_unitab(ucsdata->font_codepage, ucsdata->unitab_font, 1);
+        get_unitab(ucsdata->font_codepage, ucsdata->unitab_font, 1);
 
-	/* CP437 fonts are often broken ... */
-	if (ucsdata->font_codepage == 437)
-	    ucsdata->unitab_font[0] = ucsdata->unitab_font[255] = 0xFFFF;
+        /* CP437 fonts are often broken ... */
+        if (ucsdata->font_codepage == 437)
+            ucsdata->unitab_font[0] = ucsdata->unitab_font[255] = 0xFFFF;
     }
     if (vtmode == VT_XWINDOWS)
-	memcpy(ucsdata->unitab_font + 1, unitab_xterm_std,
-	       sizeof(unitab_xterm_std));
+        memcpy(ucsdata->unitab_font + 1, unitab_xterm_std,
+               sizeof(unitab_xterm_std));
 
     /* Collect OEMCP ucs table */
     get_unitab(CP_OEMCP, ucsdata->unitab_oemcp, 1);
 
     /* Collect CP437 ucs table for SCO acs */
     if (vtmode == VT_OEMANSI || vtmode == VT_XWINDOWS)
-	memcpy(ucsdata->unitab_scoacs, ucsdata->unitab_oemcp,
-	       sizeof(ucsdata->unitab_scoacs));
+        memcpy(ucsdata->unitab_scoacs, ucsdata->unitab_oemcp,
+               sizeof(ucsdata->unitab_scoacs));
     else
-	get_unitab(437, ucsdata->unitab_scoacs, 1);
+        get_unitab(437, ucsdata->unitab_scoacs, 1);
 
     /* Collect line set ucs table */
     if (ucsdata->line_codepage == ucsdata->font_codepage &&
-	(ucsdata->dbcs_screenfont ||
-	 vtmode == VT_POORMAN || ucsdata->font_codepage==0)) {
-
-	/* For DBCS and POOR fonts force direct to font */
-	used_dtf = true;
-	for (i = 0; i < 32; i++)
-	    ucsdata->unitab_line[i] = (WCHAR) i;
-	for (i = 32; i < 256; i++)
-	    ucsdata->unitab_line[i] = (WCHAR) (CSET_ACP + i);
-	ucsdata->unitab_line[127] = (WCHAR) 127;
+        (ucsdata->dbcs_screenfont ||
+         vtmode == VT_POORMAN || ucsdata->font_codepage==0)) {
+
+        /* For DBCS and POOR fonts force direct to font */
+        used_dtf = true;
+        for (i = 0; i < 32; i++)
+            ucsdata->unitab_line[i] = (WCHAR) i;
+        for (i = 32; i < 256; i++)
+            ucsdata->unitab_line[i] = (WCHAR) (CSET_ACP + i);
+        ucsdata->unitab_line[127] = (WCHAR) 127;
     } else {
-	get_unitab(ucsdata->line_codepage, ucsdata->unitab_line, 0);
+        get_unitab(ucsdata->line_codepage, ucsdata->unitab_line, 0);
     }
 
 #if 0
@@ -511,101 +511,101 @@ void init_ucs(Conf *conf, struct unicode_data *ucsdata)
           ucsdata->font_codepage, ucsdata->dbcs_screenfont ? " DBCS" : "");
 
     for (i = 0; i < 256; i += 16) {
-	for (j = 0; j < 16; j++) {
-	    debug("%04x%s", ucsdata->unitab_line[i + j], j == 15 ? "" : ",");
-	}
-	debug("\n");
+        for (j = 0; j < 16; j++) {
+            debug("%04x%s", ucsdata->unitab_line[i + j], j == 15 ? "" : ",");
+        }
+        debug("\n");
     }
 #endif
 
     /* VT100 graphics - NB: Broken for non-ascii CP's */
     memcpy(ucsdata->unitab_xterm, ucsdata->unitab_line,
-	   sizeof(ucsdata->unitab_xterm));
+           sizeof(ucsdata->unitab_xterm));
     memcpy(ucsdata->unitab_xterm + '`', unitab_xterm_std,
-	   sizeof(unitab_xterm_std));
+           sizeof(unitab_xterm_std));
     ucsdata->unitab_xterm['_'] = ' ';
 
     /* Generate UCS ->line page table. */
     if (ucsdata->uni_tbl) {
-	for (i = 0; i < 256; i++)
-	    if (ucsdata->uni_tbl[i])
-		sfree(ucsdata->uni_tbl[i]);
-	sfree(ucsdata->uni_tbl);
-	ucsdata->uni_tbl = 0;
+        for (i = 0; i < 256; i++)
+            if (ucsdata->uni_tbl[i])
+                sfree(ucsdata->uni_tbl[i]);
+        sfree(ucsdata->uni_tbl);
+        ucsdata->uni_tbl = 0;
     }
     if (!used_dtf) {
-	for (i = 0; i < 256; i++) {
-	    if (DIRECT_CHAR(ucsdata->unitab_line[i]))
-		continue;
-	    if (DIRECT_FONT(ucsdata->unitab_line[i]))
-		continue;
-	    if (!ucsdata->uni_tbl) {
-		ucsdata->uni_tbl = snewn(256, char *);
-		memset(ucsdata->uni_tbl, 0, 256 * sizeof(char *));
-	    }
-	    j = ((ucsdata->unitab_line[i] >> 8) & 0xFF);
-	    if (!ucsdata->uni_tbl[j]) {
-		ucsdata->uni_tbl[j] = snewn(256, char);
-		memset(ucsdata->uni_tbl[j], 0, 256 * sizeof(char));
-	    }
-	    ucsdata->uni_tbl[j][ucsdata->unitab_line[i] & 0xFF] = i;
-	}
+        for (i = 0; i < 256; i++) {
+            if (DIRECT_CHAR(ucsdata->unitab_line[i]))
+                continue;
+            if (DIRECT_FONT(ucsdata->unitab_line[i]))
+                continue;
+            if (!ucsdata->uni_tbl) {
+                ucsdata->uni_tbl = snewn(256, char *);
+                memset(ucsdata->uni_tbl, 0, 256 * sizeof(char *));
+            }
+            j = ((ucsdata->unitab_line[i] >> 8) & 0xFF);
+            if (!ucsdata->uni_tbl[j]) {
+                ucsdata->uni_tbl[j] = snewn(256, char);
+                memset(ucsdata->uni_tbl[j], 0, 256 * sizeof(char));
+            }
+            ucsdata->uni_tbl[j][ucsdata->unitab_line[i] & 0xFF] = i;
+        }
     }
 
     /* Find the line control characters. */
     for (i = 0; i < 256; i++)
-	if (ucsdata->unitab_line[i] < ' '
-	    || (ucsdata->unitab_line[i] >= 0x7F && 
-		ucsdata->unitab_line[i] < 0xA0))
-	    ucsdata->unitab_ctrl[i] = i;
-	else
-	    ucsdata->unitab_ctrl[i] = 0xFF;
+        if (ucsdata->unitab_line[i] < ' '
+            || (ucsdata->unitab_line[i] >= 0x7F &&
+                ucsdata->unitab_line[i] < 0xA0))
+            ucsdata->unitab_ctrl[i] = i;
+        else
+            ucsdata->unitab_ctrl[i] = 0xFF;
 
     /* Generate line->screen direct conversion links. */
     if (vtmode == VT_OEMANSI || vtmode == VT_XWINDOWS)
-	link_font(ucsdata->unitab_scoacs, ucsdata->unitab_oemcp, CSET_OEMCP);
+        link_font(ucsdata->unitab_scoacs, ucsdata->unitab_oemcp, CSET_OEMCP);
 
     link_font(ucsdata->unitab_line, ucsdata->unitab_font, CSET_ACP);
     link_font(ucsdata->unitab_scoacs, ucsdata->unitab_font, CSET_ACP);
     link_font(ucsdata->unitab_xterm, ucsdata->unitab_font, CSET_ACP);
 
     if (vtmode == VT_OEMANSI || vtmode == VT_XWINDOWS) {
-	link_font(ucsdata->unitab_line, ucsdata->unitab_oemcp, CSET_OEMCP);
-	link_font(ucsdata->unitab_xterm, ucsdata->unitab_oemcp, CSET_OEMCP);
+        link_font(ucsdata->unitab_line, ucsdata->unitab_oemcp, CSET_OEMCP);
+        link_font(ucsdata->unitab_xterm, ucsdata->unitab_oemcp, CSET_OEMCP);
     }
 
     if (ucsdata->dbcs_screenfont &&
-	ucsdata->font_codepage != ucsdata->line_codepage) {
-	/* F***ing Microsoft fonts, Japanese and Korean codepage fonts
-	 * have a currency symbol at 0x5C but their unicode value is 
-	 * still given as U+005C not the correct U+00A5. */
-	ucsdata->unitab_line['\\'] = CSET_OEMCP + '\\';
+        ucsdata->font_codepage != ucsdata->line_codepage) {
+        /* F***ing Microsoft fonts, Japanese and Korean codepage fonts
+         * have a currency symbol at 0x5C but their unicode value is
+         * still given as U+005C not the correct U+00A5. */
+        ucsdata->unitab_line['\\'] = CSET_OEMCP + '\\';
     }
 
     /* Last chance, if !unicode then try poorman links. */
     if (vtmode != VT_UNICODE) {
-	static const char poorman_scoacs[] = 
-	    "CueaaaaceeeiiiAAE**ooouuyOUc$YPsaiounNao?++**!<>###||||++||++++++--|-+||++--|-+----++++++++##||#aBTPEsyt******EN=+><++-=... n2* ";
-	static const char poorman_latin1[] =
-	    " !cL.Y|S\"Ca<--R~o+23'u|.,1o>///?AAAAAAACEEEEIIIIDNOOOOOxOUUUUYPBaaaaaaaceeeeiiiionooooo/ouuuuypy";
-	static const char poorman_vt100[] = "*#****o~**+++++-----++++|****L.";
-
-	for (i = 160; i < 256; i++)
-	    if (!DIRECT_FONT(ucsdata->unitab_line[i]) &&
-		ucsdata->unitab_line[i] >= 160 &&
-		ucsdata->unitab_line[i] < 256) {
-		ucsdata->unitab_line[i] =
-		    (WCHAR) (CSET_ACP +
-			     poorman_latin1[ucsdata->unitab_line[i] - 160]);
-	    }
-	for (i = 96; i < 127; i++)
-	    if (!DIRECT_FONT(ucsdata->unitab_xterm[i]))
-		ucsdata->unitab_xterm[i] =
-	    (WCHAR) (CSET_ACP + poorman_vt100[i - 96]);
-	for(i=128;i<256;i++) 
-	    if (!DIRECT_FONT(ucsdata->unitab_scoacs[i]))
-		ucsdata->unitab_scoacs[i] = 
-		    (WCHAR) (CSET_ACP + poorman_scoacs[i - 128]);
+        static const char poorman_scoacs[] =
+            "CueaaaaceeeiiiAAE**ooouuyOUc$YPsaiounNao?++**!<>###||||++||++++++--|-+||++--|-+----++++++++##||#aBTPEsyt******EN=+><++-=... n2* ";
+        static const char poorman_latin1[] =
+            " !cL.Y|S\"Ca<--R~o+23'u|.,1o>///?AAAAAAACEEEEIIIIDNOOOOOxOUUUUYPBaaaaaaaceeeeiiiionooooo/ouuuuypy";
+        static const char poorman_vt100[] = "*#****o~**+++++-----++++|****L.";
+
+        for (i = 160; i < 256; i++)
+            if (!DIRECT_FONT(ucsdata->unitab_line[i]) &&
+                ucsdata->unitab_line[i] >= 160 &&
+                ucsdata->unitab_line[i] < 256) {
+                ucsdata->unitab_line[i] =
+                    (WCHAR) (CSET_ACP +
+                             poorman_latin1[ucsdata->unitab_line[i] - 160]);
+            }
+        for (i = 96; i < 127; i++)
+            if (!DIRECT_FONT(ucsdata->unitab_xterm[i]))
+                ucsdata->unitab_xterm[i] =
+            (WCHAR) (CSET_ACP + poorman_vt100[i - 96]);
+        for(i=128;i<256;i++)
+            if (!DIRECT_FONT(ucsdata->unitab_scoacs[i]))
+                ucsdata->unitab_scoacs[i] =
+                    (WCHAR) (CSET_ACP + poorman_scoacs[i - 128]);
     }
 }
 
@@ -613,15 +613,15 @@ static void link_font(WCHAR * line_tbl, WCHAR * font_tbl, WCHAR attr)
 {
     int font_index, line_index, i;
     for (line_index = 0; line_index < 256; line_index++) {
-	if (DIRECT_FONT(line_tbl[line_index]))
-	    continue;
-	for(i = 0; i < 256; i++) {
-	    font_index = ((32 + i) & 0xFF);
-	    if (line_tbl[line_index] == font_tbl[font_index]) {
-		line_tbl[line_index] = (WCHAR) (attr + font_index);
-		break;
-	    }
-	}
+        if (DIRECT_FONT(line_tbl[line_index]))
+            continue;
+        for(i = 0; i < 256; i++) {
+            font_index = ((32 + i) & 0xFF);
+            if (line_tbl[line_index] == font_tbl[font_index]) {
+                line_tbl[line_index] = (WCHAR) (attr + font_index);
+                break;
+            }
+        }
     }
 }
 
@@ -652,7 +652,7 @@ int check_compose_internal(int first, int second, int recurse)
 {
 
     static const struct {
-	char first, second;
+        char first, second;
         wchar_t composed;
     } composetbl[] = {
         {0x2b, 0x2b, 0x0023},
@@ -984,16 +984,16 @@ int check_compose_internal(int first, int second, int recurse)
     int nc = -1;
 
     for (c = composetbl; c->first; c++) {
-	if (c->first == first && c->second == second)
-	    return c->composed;
+        if (c->first == first && c->second == second)
+            return c->composed;
     }
 
     if (recurse == 0) {
-	nc = check_compose_internal(second, first, 1);
-	if (nc == -1)
-	    nc = check_compose_internal(toupper(first), toupper(second), 1);
-	if (nc == -1)
-	    nc = check_compose_internal(toupper(second), toupper(first), 1);
+        nc = check_compose_internal(second, first, 1);
+        if (nc == -1)
+            nc = check_compose_internal(toupper(first), toupper(second), 1);
+        if (nc == -1)
+            nc = check_compose_internal(toupper(second), toupper(first), 1);
     }
     return nc;
 }
@@ -1050,7 +1050,7 @@ int decode_codepage(char *cp_name)
         d += 3;
     for (s = d; *s >= '0' && *s <= '9'; s++);
     if (*s == 0 && s != d)
-        codepage = atoi(d);	       /* CP999 or IBM999 */
+        codepage = atoi(d);            /* CP999 or IBM999 */
 
     if (codepage == CP_ACP)
         codepage = GetACP();
@@ -1061,15 +1061,15 @@ int decode_codepage(char *cp_name)
 
   break_break:;
     if (codepage != -1) {
-	if (codepage != CP_UTF8 && codepage < 65536) {
-	    if (GetCPInfo(codepage, &cpinfo) == 0) {
-		codepage = -2;
-	    } else if (cpinfo.MaxCharSize > 1)
-		codepage = -3;
-	}
+        if (codepage != CP_UTF8 && codepage < 65536) {
+            if (GetCPInfo(codepage, &cpinfo) == 0) {
+                codepage = -2;
+            } else if (cpinfo.MaxCharSize > 1)
+                codepage = -3;
+        }
     }
     if (codepage == -1 && *cp_name)
-	codepage = -2;
+        codepage = -2;
     return codepage;
 }
 
@@ -1079,32 +1079,32 @@ const char *cp_name(int codepage)
     static char buf[32];
 
     if (codepage == -1) {
-	sprintf(buf, "Use font encoding");
-	return buf;
+        sprintf(buf, "Use font encoding");
+        return buf;
     }
 
     if (codepage > 0 && codepage < 65536)
-	sprintf(buf, "CP%03d", codepage);
+        sprintf(buf, "CP%03d", codepage);
     else
-	*buf = 0;
+        *buf = 0;
 
     if (codepage >= 65536) {
-	cpno = 0;
-	for (cpi = cp_list; cpi->name; cpi++)
-	    if (cpi == cp_list + (codepage - 65536)) {
-		cpno = cpi;
-		break;
-	    }
-	if (cpno)
-	    for (cpi = cp_list; cpi->name; cpi++) {
-		if (cpno->cp_table == cpi->cp_table)
-		    return cpi->name;
-	    }
+        cpno = 0;
+        for (cpi = cp_list; cpi->name; cpi++)
+            if (cpi == cp_list + (codepage - 65536)) {
+                cpno = cpi;
+                break;
+            }
+        if (cpno)
+            for (cpi = cp_list; cpi->name; cpi++) {
+                if (cpno->cp_table == cpi->cp_table)
+                    return cpi->name;
+            }
     } else {
-	for (cpi = cp_list; cpi->name; cpi++) {
-	    if (codepage == cpi->codepage)
-		return cpi->name;
-	}
+        for (cpi = cp_list; cpi->name; cpi++) {
+            if (codepage == cpi->codepage)
+                return cpi->name;
+        }
     }
     return buf;
 }
@@ -1116,7 +1116,7 @@ const char *cp_name(int codepage)
 const char *cp_enumerate(int index)
 {
     if (index < 0 || index >= lenof(cp_list))
-	return NULL;
+        return NULL;
     return cp_list[index].name;
 }
 
@@ -1126,53 +1126,53 @@ void get_unitab(int codepage, wchar_t * unitab, int ftype)
     int i, max = 256, flg = MB_ERR_INVALID_CHARS;
 
     if (ftype)
-	flg |= MB_USEGLYPHCHARS;
+        flg |= MB_USEGLYPHCHARS;
     if (ftype == 2)
-	max = 128;
+        max = 128;
 
     if (codepage == CP_UTF8) {
-	for (i = 0; i < max; i++)
-	    unitab[i] = i;
-	return;
+        for (i = 0; i < max; i++)
+            unitab[i] = i;
+        return;
     }
 
     if (codepage == CP_ACP)
-	codepage = GetACP();
+        codepage = GetACP();
     else if (codepage == CP_OEMCP)
-	codepage = GetOEMCP();
+        codepage = GetOEMCP();
 
     if (codepage > 0 && codepage < 65536) {
-	for (i = 0; i < max; i++) {
-	    tbuf[0] = i;
+        for (i = 0; i < max; i++) {
+            tbuf[0] = i;
 
-	    if (mb_to_wc(codepage, flg, tbuf, 1, unitab + i, 1)
-		!= 1)
-		unitab[i] = 0xFFFD;
-	}
+            if (mb_to_wc(codepage, flg, tbuf, 1, unitab + i, 1)
+                != 1)
+                unitab[i] = 0xFFFD;
+        }
     } else {
-	int j = 256 - cp_list[codepage & 0xFFFF].cp_size;
-	for (i = 0; i < max; i++)
-	    unitab[i] = i;
-	for (i = j; i < max; i++)
-	    unitab[i] = cp_list[codepage & 0xFFFF].cp_table[i - j];
+        int j = 256 - cp_list[codepage & 0xFFFF].cp_size;
+        for (i = 0; i < max; i++)
+            unitab[i] = i;
+        for (i = j; i < max; i++)
+            unitab[i] = cp_list[codepage & 0xFFFF].cp_table[i - j];
     }
 }
 
 int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
-	     char *mbstr, int mblen, const char *defchr,
-	     struct unicode_data *ucsdata)
+             char *mbstr, int mblen, const char *defchr,
+             struct unicode_data *ucsdata)
 {
     char *p;
     int i;
     if (ucsdata && codepage == ucsdata->line_codepage && ucsdata->uni_tbl) {
-	/* Do this by array lookup if we can. */
-	if (wclen < 0) {
-	    for (wclen = 0; wcstr[wclen++] ;);   /* will include the NUL */
-	}
-	for (p = mbstr, i = 0; i < wclen; i++) {
-	    wchar_t ch = wcstr[i];
-	    int by;
-	    char *p1;
+        /* Do this by array lookup if we can. */
+        if (wclen < 0) {
+            for (wclen = 0; wcstr[wclen++] ;);   /* will include the NUL */
+        }
+        for (p = mbstr, i = 0; i < wclen; i++) {
+            wchar_t ch = wcstr[i];
+            int by;
+            char *p1;
 
             #define WRITECH(chr) do             \
             {                                   \
@@ -1182,32 +1182,32 @@ int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
 
             if (ucsdata->uni_tbl &&
                 (p1 = ucsdata->uni_tbl[(ch >> 8) & 0xFF]) != NULL &&
-		(by = p1[ch & 0xFF]) != '\0')
+                (by = p1[ch & 0xFF]) != '\0')
                 WRITECH(by);
-	    else if (ch < 0x80)
+            else if (ch < 0x80)
                 WRITECH(ch);
             else if (defchr)
                 for (const char *q = defchr; *q; q++)
                     WRITECH(*q);
 #if 1
-	    else
-		WRITECH('.');
+            else
+                WRITECH('.');
 #endif
 
             #undef WRITECH
-	}
-	return p - mbstr;
+        }
+        return p - mbstr;
     } else {
         int defused;
-	return WideCharToMultiByte(codepage, flags, wcstr, wclen,
-				   mbstr, mblen, defchr, &defused);
+        return WideCharToMultiByte(codepage, flags, wcstr, wclen,
+                                   mbstr, mblen, defchr, &defused);
     }
 }
 
 #endif
 
 int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
-	     wchar_t *wcstr, int wclen)
+             wchar_t *wcstr, int wclen)
 {
     return MultiByteToWideChar(codepage, flags, mbstr, mblen, wcstr, wclen);
 }

+ 272 - 272
source/putty/x11fwd.c

@@ -35,7 +35,7 @@ struct XDMSeen {
 };
 
 typedef struct X11Connection {
-    unsigned char firstpkt[12];	       /* first X data packet */
+    unsigned char firstpkt[12];        /* first X data packet */
     tree234 *authtree;
     struct X11Display *disp;
     char *auth_protocol;
@@ -57,7 +57,7 @@ static int xdmseen_cmp(void *a, void *b)
 {
     struct XDMSeen *sa = a, *sb = b;
     return sa->time > sb->time ? 1 :
-	   sa->time < sb->time ? -1 :
+           sa->time < sb->time ? -1 :
            memcmp(sa->clientid, sb->clientid, sizeof(sa->clientid));
 }
 
@@ -92,11 +92,11 @@ struct X11FakeAuth *x11_invent_fake_auth(tree234 *authtree, int authtype)
      */
 
     if (authtype == X11_MIT) {
-	auth->proto = X11_MIT;
+        auth->proto = X11_MIT;
 
-	/* MIT-MAGIC-COOKIE-1. Cookie size is 128 bits (16 bytes). */
+        /* MIT-MAGIC-COOKIE-1. Cookie size is 128 bits (16 bytes). */
         auth->datalen = 16;
-	auth->data = snewn(auth->datalen, unsigned char);
+        auth->data = snewn(auth->datalen, unsigned char);
         auth->xa1_firstblock = NULL;
 
         while (1) {
@@ -105,14 +105,14 @@ struct X11FakeAuth *x11_invent_fake_auth(tree234 *authtree, int authtype)
                 break;
         }
 
-	auth->xdmseen = NULL;
+        auth->xdmseen = NULL;
     } else {
-	assert(authtype == X11_XDM);
-	auth->proto = X11_XDM;
+        assert(authtype == X11_XDM);
+        auth->proto = X11_XDM;
 
-	/* XDM-AUTHORIZATION-1. Cookie size is 16 bytes; byte 8 is zero. */
-	auth->datalen = 16;
-	auth->data = snewn(auth->datalen, unsigned char);
+        /* XDM-AUTHORIZATION-1. Cookie size is 16 bytes; byte 8 is zero. */
+        auth->datalen = 16;
+        auth->data = snewn(auth->datalen, unsigned char);
         auth->xa1_firstblock = snewn(8, unsigned char);
         memset(auth->xa1_firstblock, 0, 8);
 
@@ -132,8 +132,8 @@ struct X11FakeAuth *x11_invent_fake_auth(tree234 *authtree, int authtype)
     auth->protoname = dupstr(x11_authnames[auth->proto]);
     auth->datastring = snewn(auth->datalen * 2 + 1, char);
     for (i = 0; i < auth->datalen; i++)
-	sprintf(auth->datastring + i*2, "%02x",
-		auth->data[i]);
+        sprintf(auth->datastring + i*2, "%02x",
+                auth->data[i]);
 
     auth->disp = NULL;
     auth->share_cs = NULL;
@@ -145,16 +145,16 @@ struct X11FakeAuth *x11_invent_fake_auth(tree234 *authtree, int authtype)
 void x11_free_fake_auth(struct X11FakeAuth *auth)
 {
     if (auth->data)
-	smemclr(auth->data, auth->datalen);
+        smemclr(auth->data, auth->datalen);
     sfree(auth->data);
     sfree(auth->protoname);
     sfree(auth->datastring);
     sfree(auth->xa1_firstblock);
     if (auth->xdmseen != NULL) {
-	struct XDMSeen *seen;
-	while ((seen = delpos234(auth->xdmseen, 0)) != NULL)
-	    sfree(seen);
-	freetree234(auth->xdmseen);
+        struct XDMSeen *seen;
+        while ((seen = delpos234(auth->xdmseen, 0)) != NULL)
+            sfree(seen);
+        freetree234(auth->xdmseen);
     }
     sfree(auth);
 }
@@ -192,112 +192,112 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf,
     *error_msg = NULL;
 
     if (!display || !*display) {
-	localcopy = platform_get_x_display();
-	if (!localcopy || !*localcopy) {
-	    sfree(localcopy);
-	    localcopy = dupstr(":0");  /* plausible default for any platform */
-	}
+        localcopy = platform_get_x_display();
+        if (!localcopy || !*localcopy) {
+            sfree(localcopy);
+            localcopy = dupstr(":0");  /* plausible default for any platform */
+        }
     } else
-	localcopy = dupstr(display);
+        localcopy = dupstr(display);
 
     /*
      * Parse the display name.
      *
      * We expect this to have one of the following forms:
-     * 
+     *
      *  - the standard X format which looks like
      *    [ [ protocol '/' ] host ] ':' displaynumber [ '.' screennumber ]
      *    (X11 also permits a double colon to indicate DECnet, but
      *    that's not our problem, thankfully!)
      *
-     * 	- only seen in the wild on MacOS (so far): a pathname to a
-     * 	  Unix-domain socket, which will typically and confusingly
-     * 	  end in ":0", and which I'm currently distinguishing from
-     * 	  the standard scheme by noting that it starts with '/'.
+     *  - only seen in the wild on MacOS (so far): a pathname to a
+     *    Unix-domain socket, which will typically and confusingly
+     *    end in ":0", and which I'm currently distinguishing from
+     *    the standard scheme by noting that it starts with '/'.
      */
     if (localcopy[0] == '/') {
-	disp->unixsocketpath = localcopy;
-	disp->unixdomain = true;
-	disp->hostname = NULL;
-	disp->displaynum = -1;
-	disp->screennum = 0;
-	disp->addr = NULL;
+        disp->unixsocketpath = localcopy;
+        disp->unixdomain = true;
+        disp->hostname = NULL;
+        disp->displaynum = -1;
+        disp->screennum = 0;
+        disp->addr = NULL;
     } else {
-	char *colon, *dot, *slash;
-	char *protocol, *hostname;
+        char *colon, *dot, *slash;
+        char *protocol, *hostname;
 
-	colon = host_strrchr(localcopy, ':');
-	if (!colon) {
+        colon = host_strrchr(localcopy, ':');
+        if (!colon) {
             *error_msg = dupprintf("display name '%s' has no ':number'"
                                    " suffix", localcopy);
 
-	    sfree(disp);
-	    sfree(localcopy);
-	    return NULL;
-	}
-
-	*colon++ = '\0';
-	dot = strchr(colon, '.');
-	if (dot)
-	    *dot++ = '\0';
-
-	disp->displaynum = atoi(colon);
-	if (dot)
-	    disp->screennum = atoi(dot);
-	else
-	    disp->screennum = 0;
-
-	protocol = NULL;
-	hostname = localcopy;
-	if (colon > localcopy) {
-	    slash = strchr(localcopy, '/');
-	    if (slash) {
-		*slash++ = '\0';
-		protocol = localcopy;
-		hostname = slash;
-	    }
-	}
-
-	disp->hostname = *hostname ? dupstr(hostname) : NULL;
-
-	if (protocol)
-	    disp->unixdomain = (!strcmp(protocol, "local") ||
-				!strcmp(protocol, "unix"));
-	else if (!*hostname || !strcmp(hostname, "unix"))
-	    disp->unixdomain = platform_uses_x11_unix_by_default;
-	else
-	    disp->unixdomain = false;
-
-	if (!disp->hostname && !disp->unixdomain)
-	    disp->hostname = dupstr("localhost");
-
-	disp->unixsocketpath = NULL;
-	disp->addr = NULL;
-
-	sfree(localcopy);
+            sfree(disp);
+            sfree(localcopy);
+            return NULL;
+        }
+
+        *colon++ = '\0';
+        dot = strchr(colon, '.');
+        if (dot)
+            *dot++ = '\0';
+
+        disp->displaynum = atoi(colon);
+        if (dot)
+            disp->screennum = atoi(dot);
+        else
+            disp->screennum = 0;
+
+        protocol = NULL;
+        hostname = localcopy;
+        if (colon > localcopy) {
+            slash = strchr(localcopy, '/');
+            if (slash) {
+                *slash++ = '\0';
+                protocol = localcopy;
+                hostname = slash;
+            }
+        }
+
+        disp->hostname = *hostname ? dupstr(hostname) : NULL;
+
+        if (protocol)
+            disp->unixdomain = (!strcmp(protocol, "local") ||
+                                !strcmp(protocol, "unix"));
+        else if (!*hostname || !strcmp(hostname, "unix"))
+            disp->unixdomain = platform_uses_x11_unix_by_default;
+        else
+            disp->unixdomain = false;
+
+        if (!disp->hostname && !disp->unixdomain)
+            disp->hostname = dupstr("localhost");
+
+        disp->unixsocketpath = NULL;
+        disp->addr = NULL;
+
+        sfree(localcopy);
     }
 
     /*
      * Look up the display hostname, if we need to.
      */
     if (!disp->unixdomain) {
-	const char *err;
+        const char *err;
 
-	disp->port = 6000 + disp->displaynum;
-	disp->addr = name_lookup(disp->hostname, disp->port,
-				 &disp->realhost, conf, ADDRTYPE_UNSPEC,
+        disp->port = 6000 + disp->displaynum;
+        disp->addr = name_lookup(disp->hostname, disp->port,
+                                 &disp->realhost, conf, ADDRTYPE_UNSPEC,
                                  NULL, NULL);
-    
-	if ((err = sk_addr_error(disp->addr)) != NULL) {
+
+        if ((err = sk_addr_error(disp->addr)) != NULL) {
             *error_msg = dupprintf("unable to resolve host name '%s' in "
                                    "display name", disp->hostname);
 
-	    sk_addr_free(disp->addr);
-	    sfree(disp->hostname);
-	    sfree(disp->unixsocketpath);
-	    sfree(disp);
-	    return NULL;
-	}
+            sk_addr_free(disp->addr);
+            sfree(disp->hostname);
+            sfree(disp->unixsocketpath);
+            sfree(disp);
+            return NULL;
+        }
     }
 
     /*
@@ -305,39 +305,39 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf,
      * display (as the standard X connection libraries do).
      */
     if (!disp->unixdomain && sk_address_is_local(disp->addr)) {
-	SockAddr *ux = platform_get_x11_unix_address(NULL, disp->displaynum);
-	const char *err = sk_addr_error(ux);
-	if (!err) {
-	    /* Create trial connection to see if there is a useful Unix-domain
-	     * socket */
-	    Socket *s = sk_new(sk_addr_dup(ux), 0, false, false,
+        SockAddr *ux = platform_get_x11_unix_address(NULL, disp->displaynum);
+        const char *err = sk_addr_error(ux);
+        if (!err) {
+            /* Create trial connection to see if there is a useful Unix-domain
+             * socket */
+            Socket *s = sk_new(sk_addr_dup(ux), 0, false, false,
 	                       false, false, nullplug,
 	    #ifdef MPEXT
 	    0, 0, NULL
 	    #endif
 	    );
-	    err = sk_socket_error(s);
-	    sk_close(s);
-	}
-	if (err) {
-	    sk_addr_free(ux);
-	} else {
-	    sk_addr_free(disp->addr);
-	    disp->unixdomain = true;
-	    disp->addr = ux;
-	    /* Fill in the rest in a moment */
-	}
+            err = sk_socket_error(s);
+            sk_close(s);
+        }
+        if (err) {
+            sk_addr_free(ux);
+        } else {
+            sk_addr_free(disp->addr);
+            disp->unixdomain = true;
+            disp->addr = ux;
+            /* Fill in the rest in a moment */
+        }
     }
 
     if (disp->unixdomain) {
-	if (!disp->addr)
-	    disp->addr = platform_get_x11_unix_address(disp->unixsocketpath,
-						       disp->displaynum);
-	if (disp->unixsocketpath)
-	    disp->realhost = dupstr(disp->unixsocketpath);
-	else
-	    disp->realhost = dupprintf("unix:%d", disp->displaynum);
-	disp->port = 0;
+        if (!disp->addr)
+            disp->addr = platform_get_x11_unix_address(disp->unixsocketpath,
+                                                       disp->displaynum);
+        if (disp->unixsocketpath)
+            disp->realhost = dupstr(disp->unixsocketpath);
+        else
+            disp->realhost = dupprintf("unix:%d", disp->displaynum);
+        disp->port = 0;
     }
 
     /*
@@ -356,7 +356,7 @@ void x11_free_display(struct X11Display *disp)
     sfree(disp->hostname);
     sfree(disp->unixsocketpath);
     if (disp->localauthdata)
-	smemclr(disp->localauthdata, disp->localauthdatalen);
+        smemclr(disp->localauthdata, disp->localauthdatalen);
     sfree(disp->localauthdata);
     sk_addr_free(disp->addr);
     sfree(disp);
@@ -406,47 +406,47 @@ static const char *x11_verify(unsigned long peer_ip, int peer_port,
      * rest of the auth data.
      */
     if (auth->proto == X11_XDM) {
-	unsigned long t;
-	time_t tim;
-	int i;
-	struct XDMSeen *seen, *ret;
+        unsigned long t;
+        time_t tim;
+        int i;
+        struct XDMSeen *seen, *ret;
 
         if (dlen != 24)
             return "XDM-AUTHORIZATION-1 data was wrong length";
-	if (peer_port == -1)
+        if (peer_port == -1)
             return "cannot do XDM-AUTHORIZATION-1 without remote address data";
-	des_decrypt_xdmauth(auth->data+9, data, 24);
+        des_decrypt_xdmauth(auth->data+9, data, 24);
         if (memcmp(auth->data, data, 8) != 0)
             return "XDM-AUTHORIZATION-1 data failed check"; /* cookie wrong */
-	if (GET_32BIT_MSB_FIRST(data+8) != peer_ip)
+        if (GET_32BIT_MSB_FIRST(data+8) != peer_ip)
             return "XDM-AUTHORIZATION-1 data failed check";   /* IP wrong */
-	if ((int)GET_16BIT_MSB_FIRST(data+12) != peer_port)
+        if ((int)GET_16BIT_MSB_FIRST(data+12) != peer_port)
             return "XDM-AUTHORIZATION-1 data failed check";   /* port wrong */
-	t = GET_32BIT_MSB_FIRST(data+14);
-	for (i = 18; i < 24; i++)
-	    if (data[i] != 0)	       /* zero padding wrong */
-		return "XDM-AUTHORIZATION-1 data failed check";
-	tim = time(NULL);
-	if (((unsigned long)t - (unsigned long)tim
+        t = GET_32BIT_MSB_FIRST(data+14);
+        for (i = 18; i < 24; i++)
+            if (data[i] != 0)          /* zero padding wrong */
+                return "XDM-AUTHORIZATION-1 data failed check";
+        tim = time(NULL);
+        if (((unsigned long)t - (unsigned long)tim
              + XDM_MAXSKEW) > 2*XDM_MAXSKEW)
-	    return "XDM-AUTHORIZATION-1 time stamp was too far out";
-	seen = snew(struct XDMSeen);
-	seen->time = t;
-	memcpy(seen->clientid, data+8, 6);
-	assert(auth->xdmseen != NULL);
-	ret = add234(auth->xdmseen, seen);
-	if (ret != seen) {
-	    sfree(seen);
-	    return "XDM-AUTHORIZATION-1 data replayed";
-	}
-	/* While we're here, purge entries too old to be replayed. */
-	for (;;) {
-	    seen = index234(auth->xdmseen, 0);
-	    assert(seen != NULL);
-	    if (t - seen->time <= XDM_MAXSKEW)
-		break;
-	    sfree(delpos234(auth->xdmseen, 0));
-	}
+            return "XDM-AUTHORIZATION-1 time stamp was too far out";
+        seen = snew(struct XDMSeen);
+        seen->time = t;
+        memcpy(seen->clientid, data+8, 6);
+        assert(auth->xdmseen != NULL);
+        ret = add234(auth->xdmseen, seen);
+        if (ret != seen) {
+            sfree(seen);
+            return "XDM-AUTHORIZATION-1 data replayed";
+        }
+        /* While we're here, purge entries too old to be replayed. */
+        for (;;) {
+            seen = index234(auth->xdmseen, 0);
+            assert(seen != NULL);
+            if (t - seen->time <= XDM_MAXSKEW)
+                break;
+            sfree(delpos234(auth->xdmseen, 0));
+        }
     }
     /* implement other protocols here if ever required */
 
@@ -472,7 +472,7 @@ void BinarySink_put_stringpl_xauth(BinarySink *bs, ptrlen pl)
     BinarySink_put_stringpl_xauth(BinarySink_UPCAST(bs),ptrlen)
 
 void x11_get_auth_from_authfile(struct X11Display *disp,
-				const char *authfilename)
+                                const char *authfilename)
 {
     FILE *authfp;
     char *buf;
@@ -519,7 +519,7 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
 
     authfp = fopen(authfilename, "rb");
     if (!authfp)
-	return;
+        return;
 
     ourhostname = get_hostname();
 
@@ -559,94 +559,94 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
         if (get_err(src))
             break;
 
-	/*
-	 * Now we have a full X authority record in memory. See
-	 * whether it matches the display we're trying to
-	 * authenticate to.
-	 *
-	 * The details we've just read should be interpreted as
-	 * follows:
-	 * 
-	 *  - 'family' is the network address family used to
-	 *    connect to the display. 0 means IPv4; 6 means IPv6;
-	 *    256 means Unix-domain sockets.
-	 * 
-	 *  - 'addr' is the network address itself. For IPv4 and
-	 *    IPv6, this is a string of binary data of the
-	 *    appropriate length (respectively 4 and 16 bytes)
-	 *    representing the address in big-endian format, e.g.
-	 *    7F 00 00 01 means IPv4 localhost. For Unix-domain
-	 *    sockets, this is the host name of the machine on
-	 *    which the Unix-domain display resides (so that an
-	 *    .Xauthority file on a shared file system can contain
-	 *    authority entries for Unix-domain displays on
-	 *    several machines without them clashing).
-	 * 
-	 *  - 'displaynum' is the display number. An empty display
-	 *    number is a wildcard for any display number.
-	 * 
-	 *  - 'protoname' is the authorisation protocol, encoded as
-	 *    its canonical string name (i.e. "MIT-MAGIC-COOKIE-1",
-	 *    "XDM-AUTHORIZATION-1" or something we don't recognise).
-	 * 
-	 *  - 'data' is the actual authorisation data, stored in
-	 *    binary form.
-	 */
-
-	if (disp->displaynum < 0 ||
-	    (displaynum >= 0 && disp->displaynum != displaynum))
-	    continue;		       /* not the one */
-
-	for (protocol = 1; protocol < lenof(x11_authnames); protocol++)
-	    if (ptrlen_eq_string(protoname, x11_authnames[protocol]))
-		break;
-	if (protocol == lenof(x11_authnames))
-	    continue;  /* don't recognise this protocol, look for another */
-
-	switch (family) {
-	  case 0:   /* IPv4 */
-	    if (!disp->unixdomain &&
-		sk_addrtype(disp->addr) == ADDRTYPE_IPV4) {
-		char buf[4];
-		sk_addrcopy(disp->addr, buf);
-		if (addr.len == 4 && !memcmp(addr.ptr, buf, 4)) {
-		    match = true;
-		    /* If this is a "localhost" entry, note it down
-		     * but carry on looking for a Unix-domain entry. */
-		    ideal_match = !localhost;
-		}
-	    }
-	    break;
-	  case 6:   /* IPv6 */
-	    if (!disp->unixdomain &&
-		sk_addrtype(disp->addr) == ADDRTYPE_IPV6) {
-		char buf[16];
-		sk_addrcopy(disp->addr, buf);
-		if (addr.len == 16 && !memcmp(addr.ptr, buf, 16)) {
-		    match = true;
-		    ideal_match = !localhost;
-		}
-	    }
-	    break;
-	  case 256: /* Unix-domain / localhost */
-	    if ((disp->unixdomain || localhost)
+        /*
+         * Now we have a full X authority record in memory. See
+         * whether it matches the display we're trying to
+         * authenticate to.
+         *
+         * The details we've just read should be interpreted as
+         * follows:
+         *
+         *  - 'family' is the network address family used to
+         *    connect to the display. 0 means IPv4; 6 means IPv6;
+         *    256 means Unix-domain sockets.
+         *
+         *  - 'addr' is the network address itself. For IPv4 and
+         *    IPv6, this is a string of binary data of the
+         *    appropriate length (respectively 4 and 16 bytes)
+         *    representing the address in big-endian format, e.g.
+         *    7F 00 00 01 means IPv4 localhost. For Unix-domain
+         *    sockets, this is the host name of the machine on
+         *    which the Unix-domain display resides (so that an
+         *    .Xauthority file on a shared file system can contain
+         *    authority entries for Unix-domain displays on
+         *    several machines without them clashing).
+         *
+         *  - 'displaynum' is the display number. An empty display
+         *    number is a wildcard for any display number.
+         *
+         *  - 'protoname' is the authorisation protocol, encoded as
+         *    its canonical string name (i.e. "MIT-MAGIC-COOKIE-1",
+         *    "XDM-AUTHORIZATION-1" or something we don't recognise).
+         *
+         *  - 'data' is the actual authorisation data, stored in
+         *    binary form.
+         */
+
+        if (disp->displaynum < 0 ||
+            (displaynum >= 0 && disp->displaynum != displaynum))
+            continue;                  /* not the one */
+
+        for (protocol = 1; protocol < lenof(x11_authnames); protocol++)
+            if (ptrlen_eq_string(protoname, x11_authnames[protocol]))
+                break;
+        if (protocol == lenof(x11_authnames))
+            continue;  /* don't recognise this protocol, look for another */
+
+        switch (family) {
+          case 0:   /* IPv4 */
+            if (!disp->unixdomain &&
+                sk_addrtype(disp->addr) == ADDRTYPE_IPV4) {
+                char buf[4];
+                sk_addrcopy(disp->addr, buf);
+                if (addr.len == 4 && !memcmp(addr.ptr, buf, 4)) {
+                    match = true;
+                    /* If this is a "localhost" entry, note it down
+                     * but carry on looking for a Unix-domain entry. */
+                    ideal_match = !localhost;
+                }
+            }
+            break;
+          case 6:   /* IPv6 */
+            if (!disp->unixdomain &&
+                sk_addrtype(disp->addr) == ADDRTYPE_IPV6) {
+                char buf[16];
+                sk_addrcopy(disp->addr, buf);
+                if (addr.len == 16 && !memcmp(addr.ptr, buf, 16)) {
+                    match = true;
+                    ideal_match = !localhost;
+                }
+            }
+            break;
+          case 256: /* Unix-domain / localhost */
+            if ((disp->unixdomain || localhost)
                 && ourhostname && ptrlen_eq_string(addr, ourhostname)) {
-		/* A matching Unix-domain socket is always the best
-		 * match. */
-		match = true;
+                /* A matching Unix-domain socket is always the best
+                 * match. */
+                match = true;
                 ideal_match = true;
             }
-	    break;
-	}
-
-	if (match) {
-	    /* Current best guess -- may be overridden if !ideal_match */
-	    disp->localauthproto = protocol;
-	    sfree(disp->localauthdata); /* free previous guess, if any */
-	    disp->localauthdata = snewn(data.len, unsigned char);
-	    memcpy(disp->localauthdata, data.ptr, data.len);
-	    disp->localauthdatalen = data.len;
-	}
+            break;
+        }
+
+        if (match) {
+            /* Current best guess -- may be overridden if !ideal_match */
+            disp->localauthproto = protocol;
+            sfree(disp->localauthdata); /* free previous guess, if any */
+            disp->localauthdata = snewn(data.len, unsigned char);
+            memcpy(disp->localauthdata, data.ptr, data.len);
+            disp->localauthdatalen = data.len;
+        }
     }
 
     fclose(authfp);
@@ -689,7 +689,7 @@ void x11_format_auth_for_authfile(
 }
 
 static void x11_log(Plug *p, int type, SockAddr *addr, int port,
-		    const char *error_msg, int error_code)
+                    const char *error_msg, int error_code)
 {
     /* We have no interface to the logging module here, so we drop these. */
 }
@@ -698,7 +698,7 @@ static void x11_send_init_error(struct X11Connection *conn,
                                 const char *err_message);
 
 static void x11_closing(Plug *plug, const char *error_msg, int error_code,
-			bool calling_back)
+                        bool calling_back)
 {
     struct X11Connection *xconn = container_of(
         plug, struct X11Connection, plug);
@@ -758,10 +758,10 @@ int x11_get_screen_number(char *display)
 
     n = host_strcspn(display, ":");
     if (!display[n])
-	return 0;
+        return 0;
     n = strcspn(display, ".");
     if (!display[n])
-	return 0;
+        return 0;
     return atoi(display + n + 1);
 }
 
@@ -857,8 +857,8 @@ static void x11_chan_free(Channel *chan)
     X11Connection *xconn = container_of(chan, X11Connection, chan);
 
     if (xconn->auth_protocol) {
-	sfree(xconn->auth_protocol);
-	sfree(xconn->auth_data);
+        sfree(xconn->auth_protocol);
+        sfree(xconn->auth_data);
     }
 
     if (xconn->s)
@@ -890,9 +890,9 @@ static void x11_send_init_error(struct X11Connection *xconn,
     msglen = strlen(full_message);
     reply = snewn(8 + msglen+1 + 4, unsigned char); /* include zero */
     msgsize = (msglen + 3) & ~3;
-    reply[0] = 0;	       /* failure */
-    reply[1] = msglen;	       /* length of reason string */
-    memcpy(reply + 2, xconn->firstpkt + 2, 4);	/* major/minor proto vsn */
+    reply[0] = 0;              /* failure */
+    reply[1] = msglen;         /* length of reason string */
+    memcpy(reply + 2, xconn->firstpkt + 2, 4);  /* major/minor proto vsn */
     PUT_16BIT_X11(xconn->firstpkt[0], reply + 6, msgsize >> 2);/* data len */
     memset(reply + 8, 0, msgsize);
     memcpy(reply + 8, full_message, msglen);
@@ -934,9 +934,9 @@ static size_t x11_send(
      * Read the first packet.
      */
     while (len > 0 && xconn->data_read < 12)
-	xconn->firstpkt[xconn->data_read++] = (unsigned char) (len--, *data++);
+        xconn->firstpkt[xconn->data_read++] = (unsigned char) (len--, *data++);
     if (xconn->data_read < 12)
-	return 0;
+        return 0;
 
     /*
      * If we have not allocated the auth_protocol and auth_data
@@ -944,13 +944,13 @@ static size_t x11_send(
      */
     if (!xconn->auth_protocol) {
         char endian = xconn->firstpkt[0];
-	xconn->auth_plen = GET_16BIT_X11(endian, xconn->firstpkt + 6);
-	xconn->auth_dlen = GET_16BIT_X11(endian, xconn->firstpkt + 8);
-	xconn->auth_psize = (xconn->auth_plen + 3) & ~3;
-	xconn->auth_dsize = (xconn->auth_dlen + 3) & ~3;
-	/* Leave room for a terminating zero, to make our lives easier. */
-	xconn->auth_protocol = snewn(xconn->auth_psize + 1, char);
-	xconn->auth_data = snewn(xconn->auth_dsize, unsigned char);
+        xconn->auth_plen = GET_16BIT_X11(endian, xconn->firstpkt + 6);
+        xconn->auth_dlen = GET_16BIT_X11(endian, xconn->firstpkt + 8);
+        xconn->auth_psize = (xconn->auth_plen + 3) & ~3;
+        xconn->auth_dsize = (xconn->auth_dlen + 3) & ~3;
+        /* Leave room for a terminating zero, to make our lives easier. */
+        xconn->auth_protocol = snewn(xconn->auth_psize + 1, char);
+        xconn->auth_data = snewn(xconn->auth_dsize, unsigned char);
     }
 
     /*
@@ -958,19 +958,19 @@ static size_t x11_send(
      */
     while (len > 0 &&
            xconn->data_read < 12 + xconn->auth_psize)
-	xconn->auth_protocol[xconn->data_read++ - 12] = (len--, *data++);
+        xconn->auth_protocol[xconn->data_read++ - 12] = (len--, *data++);
     while (len > 0 &&
            xconn->data_read < 12 + xconn->auth_psize + xconn->auth_dsize)
-	xconn->auth_data[xconn->data_read++ - 12 -
-		      xconn->auth_psize] = (unsigned char) (len--, *data++);
+        xconn->auth_data[xconn->data_read++ - 12 -
+                      xconn->auth_psize] = (unsigned char) (len--, *data++);
     if (xconn->data_read < 12 + xconn->auth_psize + xconn->auth_dsize)
-	return 0;
+        return 0;
 
     /*
      * If we haven't verified the authorisation, do so now.
      */
     if (!xconn->verified) {
-	const char *err;
+        const char *err;
         struct X11FakeAuth *auth_matched = NULL;
         unsigned long peer_ip;
         int peer_port;
@@ -988,7 +988,7 @@ static size_t x11_send(
 
         assert(!xconn->s);
 
-	xconn->auth_protocol[xconn->auth_plen] = '\0';	/* ASCIZ */
+        xconn->auth_protocol[xconn->auth_plen] = '\0';  /* ASCIZ */
 
         peer_ip = 0;                   /* placate optimiser */
         if (x11_parse_ip(xconn->peer_addr, &peer_ip))
@@ -996,10 +996,10 @@ static size_t x11_send(
         else
             peer_port = -1; /* signal no peer address data available */
 
-	err = x11_verify(peer_ip, peer_port,
-			 xconn->authtree, xconn->auth_protocol,
-			 xconn->auth_data, xconn->auth_dlen, &auth_matched);
-	if (err) {
+        err = x11_verify(peer_ip, peer_port,
+                         xconn->authtree, xconn->auth_protocol,
+                         xconn->auth_data, xconn->auth_dlen, &auth_matched);
+        if (err) {
             x11_send_init_error(xconn, err);
             return 0;
         }
@@ -1028,7 +1028,7 @@ static size_t x11_send(
         sshfwd_window_override_removed(xconn->c);
         xconn->disp = auth_matched->disp;
         xconn->s = new_connection(sk_addr_dup(xconn->disp->addr),
-                                  xconn->disp->realhost, xconn->disp->port, 
+                                  xconn->disp->realhost, xconn->disp->port,
                                   false, true, false, false, &xconn->plug,
                                   sshfwd_get_conf(xconn->c));
         if ((err = sk_socket_error(xconn->s)) != NULL) {
@@ -1042,7 +1042,7 @@ static size_t x11_send(
         /*
          * Write a new connection header containing our replacement
          * auth data.
-	 */
+         */
         socketdatalen = 0;             /* placate compiler warning */
         #ifdef MPEXT
         // placate compiler warning
@@ -1065,7 +1065,7 @@ static size_t x11_send(
                                      xconn->disp->localauthdatalen,
                                      new_peer_addr, new_peer_port,
                                      &greeting_len);
-        
+
         sk_write(xconn->s, greeting, greeting_len);
 
         smemclr(greeting, greeting_len);
@@ -1074,7 +1074,7 @@ static size_t x11_send(
         /*
          * Now we're done.
          */
-	xconn->verified = true;
+        xconn->verified = true;
     }
 
     /*

Некоторые файлы не были показаны из-за большого количества измененных файлов