1
0
Эх сурвалжийг харах

PuTTY snapshot 85770b20 (Add missing expire_timer_context in ssh2_transport_free 2018-11-23)

Source commit: 3ba846b71bb159ae427ba7cacdfb3a8366c31c18
Martin Prikryl 6 жил өмнө
parent
commit
2cb6655162
82 өөрчлөгдсөн 2692 нэмэгдсэн , 2734 устгасан
  1. 7 7
      source/putty/WINDOWS/winhsock.c
  2. 21 21
      source/putty/WINDOWS/winsecur.c
  3. 5 7
      source/putty/WINDOWS/winsecur.h
  4. 5 5
      source/putty/WINDOWS/winucs.c
  5. 9 9
      source/putty/agentf.c
  6. 1 1
      source/putty/be_misc.c
  7. 6 6
      source/putty/callback.c
  8. 45 8
      source/putty/conf.c
  9. 10 9
      source/putty/defs.h
  10. 93 24
      source/putty/doc/udp.but
  11. 82 85
      source/putty/import.c
  12. 0 175
      source/putty/int64.c
  13. 0 29
      source/putty/int64.h
  14. 9 9
      source/putty/logging.c
  15. 67 67
      source/putty/mainchan.c
  16. 18 23
      source/putty/marshal.c
  17. 6 5
      source/putty/marshal.h
  18. 34 76
      source/putty/misc.c
  19. 103 25
      source/putty/misc.h
  20. 17 17
      source/putty/network.h
  21. 1 1
      source/putty/nullplug.c
  22. 4 4
      source/putty/pageant.h
  23. 1 1
      source/putty/pgssapi.h
  24. 31 31
      source/putty/portfwd.c
  25. 29 27
      source/putty/proxy.c
  26. 8 8
      source/putty/proxy.h
  27. 213 204
      source/putty/putty.h
  28. 55 54
      source/putty/ssh.c
  29. 101 86
      source/putty/ssh.h
  30. 6 6
      source/putty/ssh1bpp.c
  31. 1 1
      source/putty/ssh1censor.c
  32. 52 53
      source/putty/ssh1connection-client.c
  33. 43 43
      source/putty/ssh1connection.c
  34. 16 16
      source/putty/ssh1connection.h
  35. 51 51
      source/putty/ssh1login.c
  36. 3 3
      source/putty/ssh2bpp-bare.c
  37. 22 22
      source/putty/ssh2bpp.c
  38. 1 1
      source/putty/ssh2censor.c
  39. 29 29
      source/putty/ssh2connection-client.c
  40. 54 60
      source/putty/ssh2connection.c
  41. 32 32
      source/putty/ssh2connection.h
  42. 19 12
      source/putty/ssh2kex-client.c
  43. 5 5
      source/putty/ssh2transhk.c
  44. 117 112
      source/putty/ssh2transport.c
  45. 24 22
      source/putty/ssh2transport.h
  46. 108 76
      source/putty/ssh2userauth.c
  47. 31 31
      source/putty/sshaes.c
  48. 43 43
      source/putty/sshblowf.c
  49. 4 3
      source/putty/sshbn.c
  50. 14 14
      source/putty/sshbpp.h
  51. 3 3
      source/putty/sshccp.c
  52. 57 57
      source/putty/sshchan.h
  53. 72 72
      source/putty/sshcommon.c
  54. 23 25
      source/putty/sshcrcda.c
  55. 20 19
      source/putty/sshdes.c
  56. 9 1
      source/putty/sshdh.c
  57. 11 10
      source/putty/sshdss.c
  58. 119 116
      source/putty/sshecc.c
  59. 4 3
      source/putty/sshmac.c
  60. 14 23
      source/putty/sshmd5.c
  61. 18 11
      source/putty/sshppl.h
  62. 77 76
      source/putty/sshpubk.c
  63. 18 21
      source/putty/sshrand.c
  64. 81 38
      source/putty/sshrsa.c
  65. 17 22
      source/putty/sshsh256.c
  66. 35 71
      source/putty/sshsh512.c
  67. 27 31
      source/putty/sshsha.c
  68. 33 35
      source/putty/sshshare.c
  69. 9 9
      source/putty/sshverstring.c
  70. 17 24
      source/putty/sshzlib.c
  71. 1 1
      source/putty/storage.h
  72. 2 1
      source/putty/tree234.c
  73. 8 8
      source/putty/wildcard.c
  74. 51 50
      source/putty/windows/winhandl.c
  75. 50 13
      source/putty/windows/winmisc.c
  76. 88 156
      source/putty/windows/winnet.c
  77. 2 2
      source/putty/windows/winnoise.c
  78. 5 5
      source/putty/windows/winpgntc.c
  79. 5 8
      source/putty/windows/winproxy.c
  80. 58 100
      source/putty/windows/winstore.c
  81. 68 33
      source/putty/windows/winstuff.h
  82. 34 31
      source/putty/x11fwd.c

+ 7 - 7
source/putty/WINDOWS/winhsock.c

@@ -36,7 +36,7 @@ typedef struct HandleSocket {
     /* Data received from stderr_H, if we have one. */
     bufchain stderrdata;
 
-    int defer_close, deferred_close;   /* in case of re-entrance */
+    bool defer_close, deferred_close;   /* in case of re-entrance */
 
     char *error;
 
@@ -118,7 +118,7 @@ static void sk_handle_close(Socket *s)
     HandleSocket *hs = container_of(s, HandleSocket, sock);
 
     if (hs->defer_close) {
-        hs->deferred_close = TRUE;
+        hs->deferred_close = true;
         return;
     }
 
@@ -185,10 +185,10 @@ static void handle_socket_unfreeze(void *hsv)
      * Hand it off to the plug. Be careful of re-entrance - that might
      * have the effect of trying to close this socket.
      */
-    hs->defer_close = TRUE;
+    hs->defer_close = true;
     plug_receive(hs->plug, 0, data, len);
     bufchain_consume(&hs->inputdata, len);
-    hs->defer_close = FALSE;
+    hs->defer_close = false;
     if (hs->deferred_close) {
         sk_handle_close(&hs->sock);
         return;
@@ -209,7 +209,7 @@ static void handle_socket_unfreeze(void *hsv)
     }
 }
 
-static void sk_handle_set_frozen(Socket *s, int is_frozen)
+static void sk_handle_set_frozen(Socket *s, bool is_frozen)
 {
     HandleSocket *hs = container_of(s, HandleSocket, sock);
 
@@ -324,7 +324,7 @@ static const SocketVtable HandleSocket_sockvt = {
 };
 
 Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
-                           Plug *plug, int overlapped)
+                           Plug *plug, bool overlapped)
 {
     HandleSocket *hs;
     int flags = (overlapped ? HANDLE_FLAG_OVERLAPPED : 0);
@@ -346,7 +346,7 @@ Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
         hs->stderr_h = handle_input_new(hs->stderr_H, handle_stderr,
                                         hs, flags);
 
-    hs->defer_close = hs->deferred_close = FALSE;
+    hs->defer_close = hs->deferred_close = false;
 
     return &hs->sock;
 }

+ 21 - 21
source/putty/WINDOWS/winsecur.c

@@ -16,14 +16,14 @@
 static PSID worldsid, networksid, usersid;
 
 
-int got_advapi(void)
+bool got_advapi(void)
 {
-    static int attempted = FALSE;
-    static int successful;
+    static bool attempted = false;
+    static bool successful;
     static HMODULE advapi;
 
     if (!attempted) {
-        attempted = TRUE;
+        attempted = true;
         advapi = load_system32_dll("advapi32.dll");
         successful = advapi &&
             GET_WINDOWS_FUNCTION(advapi, GetSecurityInfo) &&
@@ -50,7 +50,7 @@ PSID get_user_sid(void)
     if (!got_advapi())
         goto cleanup;
 
-    if ((proc = OpenProcess(MAXIMUM_ALLOWED, FALSE,
+    if ((proc = OpenProcess(MAXIMUM_ALLOWED, false,
                             GetCurrentProcessId())) == NULL)
         goto cleanup;
 
@@ -92,7 +92,7 @@ PSID get_user_sid(void)
     return ret;
 }
 
-int getsids(char **error)
+bool getsids(char **error)
 {
 #ifdef __clang__
 #pragma clang diagnostic push
@@ -104,7 +104,7 @@ int getsids(char **error)
 #pragma clang diagnostic pop
 #endif
 
-    int ret = FALSE;
+    bool ret = false;
 
     *error = NULL;
 
@@ -135,21 +135,21 @@ int getsids(char **error)
         }
     }
 
-    ret = TRUE;
+    ret = true;
 
  cleanup:
     return ret;
 }
   
 
-int make_private_security_descriptor(DWORD permissions,
-                                     PSECURITY_DESCRIPTOR *psd,
-                                     PACL *acl,
-                                     char **error)
+bool make_private_security_descriptor(DWORD permissions,
+                                      PSECURITY_DESCRIPTOR *psd,
+                                      PACL *acl,
+                                      char **error)
 {
     EXPLICIT_ACCESS ea[3];
     int acl_err;
-    int ret = FALSE;
+    bool ret = false;
 
 
     *psd = NULL;
@@ -197,19 +197,19 @@ int make_private_security_descriptor(DWORD permissions,
         goto cleanup;
     }
 
-    if (!SetSecurityDescriptorOwner(*psd, usersid, FALSE)) {
+    if (!SetSecurityDescriptorOwner(*psd, usersid, false)) {
         *error = dupprintf("unable to set owner in security descriptor: %s",
                            win_strerror(GetLastError()));
         goto cleanup;
     }
 
-    if (!SetSecurityDescriptorDacl(*psd, TRUE, *acl, FALSE)) {
+    if (!SetSecurityDescriptorDacl(*psd, true, *acl, false)) {
         *error = dupprintf("unable to set DACL in security descriptor: %s",
                            win_strerror(GetLastError()));
         goto cleanup;
     }
 
-    ret = TRUE;
+    ret = true;
 
   cleanup:
     if (!ret) {
@@ -228,11 +228,11 @@ int make_private_security_descriptor(DWORD permissions,
     return ret;
 }
 
-static int really_restrict_process_acl(char **error)
+static bool really_restrict_process_acl(char **error)
 {
     EXPLICIT_ACCESS ea[2];
     int acl_err;
-    int ret=FALSE;
+    bool ret = false;
     PACL acl = NULL;
 
     static const DWORD nastyace=WRITE_DAC | WRITE_OWNER |
@@ -279,7 +279,7 @@ static int really_restrict_process_acl(char **error)
     }
 		      
 
-    ret=TRUE;
+    ret=true;
     
   cleanup:
     if (!ret) {
@@ -312,12 +312,12 @@ static int really_restrict_process_acl(char **error)
 void restrict_process_acl(void)
 {
     char *error = NULL;
-    int ret;
+    bool ret;
 
 #if !defined NO_SECURITY
     ret = really_restrict_process_acl(&error);
 #else
-    ret = FALSE;
+    ret = false;
     error = dupstr("ACL restrictions not compiled into this binary");
 #endif
     if (!ret)

+ 5 - 7
source/putty/WINDOWS/winsecur.h

@@ -33,7 +33,7 @@ DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, SetSecurityInfo,
 		       PSID, PSID, PACL, PACL));
 DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, SetEntriesInAclA,
 		      (ULONG, PEXPLICIT_ACCESS, PACL, PACL *));
-int got_advapi(void);
+bool got_advapi(void);
 
 /*
  * Find the SID describing the current user. The return value (if not
@@ -46,14 +46,12 @@ PSID get_user_sid(void);
  * servers, i.e. allowing access only to the current user id and also
  * only local (i.e. not over SMB) connections.
  *
- * If this function returns TRUE, then 'psd' and 'acl' will have been
+ * If this function returns true, then 'psd' and 'acl' will have been
  * filled in with memory allocated using LocalAlloc (and hence must be
- * freed later using LocalFree). If it returns FALSE, then instead
+ * freed later using LocalFree). If it returns false, then instead
  * 'error' has been filled with a dynamically allocated error message.
  */
-int make_private_security_descriptor(DWORD permissions,
-                                     PSECURITY_DESCRIPTOR *psd,
-                                     PACL *acl,
-                                     char **error);
+bool make_private_security_descriptor(
+    DWORD permissions, PSECURITY_DESCRIPTOR *psd, PACL *acl, char **error);
 
 #endif

+ 5 - 5
source/putty/WINDOWS/winucs.c

@@ -440,7 +440,7 @@ static void link_font(WCHAR * line_tbl, WCHAR * font_tbl, WCHAR attr);
 void init_ucs(Conf *conf, struct unicode_data *ucsdata)
 {
     int i, j;
-    int used_dtf = 0;
+    bool used_dtf = false;
     int vtmode;
 
     /* Decide on the Line and Font codepages */
@@ -449,13 +449,13 @@ void init_ucs(Conf *conf, struct unicode_data *ucsdata)
 
     if (ucsdata->font_codepage <= 0) { 
 	ucsdata->font_codepage=0; 
-	ucsdata->dbcs_screenfont=0; 
+	ucsdata->dbcs_screenfont=false;
     }
 
     vtmode = conf_get_int(conf, CONF_vtmode);
     if (vtmode == VT_OEMONLY) {
 	ucsdata->font_codepage = 437;
-	ucsdata->dbcs_screenfont = 0;
+	ucsdata->dbcs_screenfont = false;
 	if (ucsdata->line_codepage <= 0)
 	    ucsdata->line_codepage = GetACP();
     } else if (ucsdata->line_codepage <= 0)
@@ -493,7 +493,7 @@ void init_ucs(Conf *conf, struct unicode_data *ucsdata)
 	 vtmode == VT_POORMAN || ucsdata->font_codepage==0)) {
 
 	/* For DBCS and POOR fonts force direct to font */
-	used_dtf = 1;
+	used_dtf = true;
 	for (i = 0; i < 32; i++)
 	    ucsdata->unitab_line[i] = (WCHAR) i;
 	for (i = 32; i < 256; i++)
@@ -1201,7 +1201,7 @@ int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
     return MultiByteToWideChar(codepage, flags, mbstr, mblen, wcstr, wclen);
 }
 
-int is_dbcs_leadbyte(int codepage, char byte)
+bool is_dbcs_leadbyte(int codepage, char byte)
 {
     return IsDBCSLeadByteEx(codepage, byte);
 }

+ 9 - 9
source/putty/agentf.c

@@ -15,8 +15,8 @@ typedef struct agentf {
     SshChannel *c;
     bufchain inbuffer;
     agent_pending_query *pending;
-    int input_wanted;
-    int rcvd_eof;
+    bool input_wanted;
+    bool rcvd_eof;
 
     Channel chan;
 } agentf;
@@ -142,10 +142,10 @@ static void agentf_callback(void *vctx, void *reply, int replylen)
 }
 
 static void agentf_free(Channel *chan);
-static int agentf_send(Channel *chan, int is_stderr, const void *, int);
+static int agentf_send(Channel *chan, bool is_stderr, const void *, int);
 static void agentf_send_eof(Channel *chan);
 static char *agentf_log_close_msg(Channel *chan);
-static void agentf_set_input_wanted(Channel *chan, int wanted);
+static void agentf_set_input_wanted(Channel *chan, bool wanted);
 
 static const struct ChannelVtable agentf_channelvt = {
     agentf_free,
@@ -178,10 +178,10 @@ Channel *agentf_new(SshChannel *c)
     af->c = c;
     af->chan.vt = &agentf_channelvt;
     af->chan.initial_fixed_window_size = 0;
-    af->rcvd_eof = FALSE;
+    af->rcvd_eof = false;
     bufchain_init(&af->inbuffer);
     af->pending = NULL;
-    af->input_wanted = TRUE;
+    af->input_wanted = true;
     return &af->chan;
 }
 
@@ -196,7 +196,7 @@ static void agentf_free(Channel *chan)
     sfree(af);
 }
 
-static int agentf_send(Channel *chan, int is_stderr,
+static int agentf_send(Channel *chan, bool is_stderr,
                        const void *data, int length)
 {
     assert(chan->vt == &agentf_channelvt);
@@ -220,7 +220,7 @@ static void agentf_send_eof(Channel *chan)
     assert(chan->vt == &agentf_channelvt);
     agentf *af = container_of(chan, agentf, chan);
 
-    af->rcvd_eof = TRUE;
+    af->rcvd_eof = true;
 
     /* Call try_forward, which will respond to the EOF now if
      * appropriate, or wait until the queue of outstanding requests is
@@ -233,7 +233,7 @@ static char *agentf_log_close_msg(Channel *chan)
     return dupstr("Agent-forwarding connection closed");
 }
 
-static void agentf_set_input_wanted(Channel *chan, int wanted)
+static void agentf_set_input_wanted(Channel *chan, bool wanted)
 {
     assert(chan->vt == &agentf_channelvt);
     agentf *af = container_of(chan, agentf, chan);

+ 1 - 1
source/putty/be_misc.c

@@ -11,7 +11,7 @@
 void backend_socket_log(Seat *seat, LogContext *logctx,
                         int type, SockAddr *addr, int port,
                         const char *error_msg, int error_code, Conf *conf,
-                        int session_started)
+                        bool session_started)
 {
     char addrbuf[256], *msg;
 

+ 6 - 6
source/putty/callback.c

@@ -29,7 +29,7 @@ void request_callback_notifications(toplevel_callback_notify_fn_t fn,
 static void run_idempotent_callback(void *ctx)
 {
     struct IdempotentCallback *ic = (struct IdempotentCallback *)ctx;
-    ic->queued = FALSE;
+    ic->queued = false;
     ic->fn(ic->ctx);
 }
 
@@ -37,7 +37,7 @@ void queue_idempotent_callback(struct IdempotentCallback *ic)
 {
     if (ic->queued)
         return;
-    ic->queued = TRUE;
+    ic->queued = true;
     queue_toplevel_callback(run_idempotent_callback, ic);
 }
 
@@ -99,9 +99,9 @@ void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx)
     cb->next = NULL;
 }
 
-int run_toplevel_callbacks(void)
+bool run_toplevel_callbacks(void)
 {
-    int done_something = FALSE;
+    bool done_something = false;
 
     if (cbhead) {
         /*
@@ -122,12 +122,12 @@ int run_toplevel_callbacks(void)
         sfree(cbcurr);
         cbcurr = NULL;
 
-        done_something = TRUE;
+        done_something = true;
     }
     return done_something;
 }
 
-int toplevel_callback_pending(void)
+bool toplevel_callback_pending(void)
 {
     return cbcurr != NULL || cbhead != NULL;
 }

+ 45 - 8
source/putty/conf.c

@@ -13,7 +13,9 @@
 /*
  * Enumeration of types used in keys and values.
  */
-typedef enum { TYPE_NONE, TYPE_INT, TYPE_STR, TYPE_FILENAME, TYPE_FONT } Type;
+typedef enum {
+    TYPE_NONE, TYPE_BOOL, TYPE_INT, TYPE_STR, TYPE_FILENAME, TYPE_FONT
+} Type;
 
 /*
  * Arrays which allow us to look up the subkey and value types for a
@@ -51,6 +53,7 @@ struct constkey {
 
 struct value {
     union {
+	bool boolval;
 	int intval;
 	char *stringval;
 	Filename *fileval;
@@ -171,6 +174,9 @@ static void free_value(struct value *val, int type)
 static void copy_value(struct value *to, struct value *from, int type)
 {
     switch (type) {
+      case TYPE_BOOL:
+	to->u.boolval = from->u.boolval;
+	break;
       case TYPE_INT:
 	to->u.intval = from->u.intval;
 	break;
@@ -256,6 +262,19 @@ Conf *conf_copy(Conf *oldconf)
     return newconf;
 }
 
+bool conf_get_bool(Conf *conf, int primary)
+{
+    struct key key;
+    struct conf_entry *entry;
+
+    assert(subkeytypes[primary] == TYPE_NONE);
+    assert(valuetypes[primary] == TYPE_BOOL);
+    key.primary = primary;
+    entry = find234(conf->tree, &key, NULL);
+    assert(entry);
+    return entry->value.u.boolval;
+}
+
 int conf_get_int(Conf *conf, int primary)
 {
     struct key key;
@@ -384,6 +403,17 @@ FontSpec *conf_get_fontspec(Conf *conf, int primary)
     return entry->value.u.fontval;
 }
 
+void conf_set_bool(Conf *conf, int primary, bool value)
+{
+    struct conf_entry *entry = snew(struct conf_entry);
+
+    assert(subkeytypes[primary] == TYPE_NONE);
+    assert(valuetypes[primary] == TYPE_BOOL);
+    entry->key.primary = primary;
+    entry->value.u.boolval = value;
+    conf_insert(conf, entry);
+}
+
 void conf_set_int(Conf *conf, int primary, int value)
 {
     struct conf_entry *entry = snew(struct conf_entry);
@@ -391,11 +421,12 @@ void conf_set_int(Conf *conf, int primary, int value)
     assert(subkeytypes[primary] == TYPE_NONE);
     assert(valuetypes[primary] == TYPE_INT);
     entry->key.primary = primary;
-    entry->value.u.intval = value; 
+    entry->value.u.intval = value;
     conf_insert(conf, entry);
 }
 
-void conf_set_int_int(Conf *conf, int primary, int secondary, int value)
+void conf_set_int_int(Conf *conf, int primary,
+                      int secondary, int value)
 {
     struct conf_entry *entry = snew(struct conf_entry);
 
@@ -486,6 +517,9 @@ void conf_serialise(BinarySink *bs, Conf *conf)
 	    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;
@@ -504,7 +538,7 @@ void conf_serialise(BinarySink *bs, Conf *conf)
     put_uint32(bs, 0xFFFFFFFFU);
 }
 
-int conf_deserialise(Conf *conf, BinarySource *src)
+bool conf_deserialise(Conf *conf, BinarySource *src)
 {
     struct conf_entry *entry;
     unsigned primary;
@@ -513,11 +547,11 @@ int conf_deserialise(Conf *conf, BinarySource *src)
         primary = get_uint32(src);
 
         if (get_err(src))
-            return FALSE;
+            return false;
         if (primary == 0xFFFFFFFFU)
-            return TRUE;
+            return true;
 	if (primary >= N_CONFIG_OPTIONS)
-	    return FALSE;
+	    return false;
 
 	entry = snew(struct conf_entry);
 	entry->key.primary = primary;
@@ -532,6 +566,9 @@ int conf_deserialise(Conf *conf, BinarySource *src)
 	}
 
 	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;
@@ -548,7 +585,7 @@ int conf_deserialise(Conf *conf, BinarySource *src)
 
         if (get_err(src)) {
             free_entry(entry);
-            return FALSE;
+            return false;
         }
 
 	conf_insert(conf, entry);

+ 10 - 9
source/putty/defs.h

@@ -12,12 +12,16 @@
 #define PUTTY_DEFS_H
 
 #include <stddef.h>
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-#ifndef TRUE
-#define TRUE 1
+#include <stdint.h>
+#include <stdbool.h>
+
+#if defined _MSC_VER && _MSC_VER < 1800
+/* Work around lack of inttypes.h in older MSVC */
+#define PRIx32 "x"
+#define PRIu64 "I64u"
+#define SCNu64 "I64u"
+#else
+#include <inttypes.h>
 #endif
 
 typedef struct conf_tag Conf;
@@ -32,9 +36,6 @@ typedef struct strbuf strbuf;
 
 struct RSAKey;
 
-#include <stdint.h>
-typedef uint32_t uint32;
-
 typedef struct BinarySink BinarySink;
 typedef struct BinarySource BinarySource;
 

+ 93 - 24
source/putty/doc/udp.but

@@ -33,22 +33,75 @@ All the modules in the main source directory - notably \e{all} of
 the code for the various back ends - are platform-generic. We want
 to keep them that way.
 
-This also means you should stick to what you are guaranteed by
-ANSI/ISO C (that is, the original C89/C90 standard, not C99). Try
-not to make assumptions about the precise size of basic types such
-as \c{int} and \c{long int}; don't use pointer casts to do
-endianness-dependent operations, and so on.
-
-(There are one or two aspects of ANSI C portability which we
-\e{don't} care about. In particular, we expect PuTTY to be compiled
-on 32-bit architectures \e{or bigger}; so it's safe to assume that
-\c{int} is at least 32 bits wide, not just the 16 you are guaranteed
-by ANSI C.  Similarly, we assume that the execution character
-encoding is a superset of the printable characters of ASCII, though
-we don't assume the numeric values of control characters,
-particularly \cw{'\\n'} and \cw{'\\r'}. Also, the X forwarding code
-assumes that \c{time_t} has the Unix format and semantics, i.e. an
-integer giving the number of seconds since 1970.)
+This also means you should stick to the C semantics guaranteed by the
+C standard: try not to make assumptions about the precise size of
+basic types such as \c{int} and \c{long int}; don't use pointer casts
+to do endianness-dependent operations, and so on.
+
+(Even \e{within} a platform front end you should still be careful of
+some of these portability issues. The Windows front end compiles on
+both 32- and 64-bit x86 and also Arm.)
+
+Our current choice of C standards version is C99: you can assume that
+C99 features are available (in particular \cw{<stdint.h>},
+\cw{<stdbool.h>} and \c{inline}), but you shouldn't use things that
+are new in C11 (such as \cw{<uchar.h>} or \cw{_Generic}).
+
+One small exception to that: for historical reasons, we still build in
+one configuration which lacks \cw{<inttypes.h>}. So that file is
+included centrally in \c{defs.h}, and has a set of workaround
+definitions for the \cw{PRIx64}-type macros we use. If you need to use
+another one of those macros, you need to add a workaround definition
+in \c{defs.h}, and don't casually re-include \cw{<inttypes.h>}
+anywhere else in the source file.
+
+Here are a few portability assumptions that we \e{do} currently allow
+(because we'd already have to thoroughly vet the existing code if they
+ever needed to change, and it doesn't seem worth doing that unless we
+really have to):
+
+\b You can assume \c{int} is \e{at least} 32 bits wide. (We've never
+tried to port PuTTY to a platform with 16-bit \cw{int}, and it doesn't
+look likely to be necessary in future.)
+
+\b Similarly, you can assume \c{char} is exactly 8 bits. (Exceptions
+to that are even less likely to be relevant to us than short
+\cw{int}.)
+
+\b You can assume that using \c{memset} to write zero bytes over a
+whole structure will have the effect of setting all its pointer fields
+to \cw{NULL}. (The standard itself guarantees this for \e{integer}
+fields, but not for pointers.)
+
+\b You can assume that \c{time_t} has POSIX semantics, i.e. that it
+represents an integer number of non-leap seconds since 1970-01-01
+00:00:00 UTC. (Times in this format are used in X authorisation, but
+we could work around that by carefully distinguishing local \c{time_t}
+from time values used in the wire protocol; but these semantics of
+\c{time_t} are also baked into the shared library API used by the
+GSSAPI authentication code, which would be much harder to change.)
+
+\b You can assume that the execution character encoding is a superset
+of the printable characters of ASCII. (In particular, it's fine to do
+arithmetic on a \c{char} value representing a Latin alphabetic
+character, without bothering to allow for EBCDIC or other
+non-consecutive encodings of the alphabet.)
+
+On the other hand, here are some particular things \e{not} to assume:
+
+\b Don't assume anything about the \e{signedness} of \c{char}. In
+particular, you \e{must} cast \c{char} values to \c{unsigned char}
+before passing them to any \cw{<ctype.h>} function (because those
+expect a non-negative character value, or \cw{EOF}). If you need a
+particular signedness, explicitly specify \c{signed char} or
+\c{unsigned char}, or use C99 \cw{int8_t} or \cw{uint8_t}.
+
+\b From past experience with MacOS, we're still a bit nervous about
+\cw{'\\n'} and \cw{'\\r'} potentially having unusual meanings on a
+given platform. So it's fine to say \c{\\n} in a string you're passing
+to \c{printf}, but in any context where those characters appear in a
+standardised wire protocol or a binary file format, they should be
+spelled \cw{'\\012'} and \cw{'\\015'} respectively.
 
 \H{udp-multi-backend} Multiple backends treated equally
 
@@ -312,11 +365,12 @@ as well!
 source archive saying this, but many people don't seem to read it,
 so it's worth repeating here.)
 
-\H{udp-ssh-coroutines} Coroutines in \cw{ssh.c}
+\H{udp-ssh-coroutines} Coroutines in the SSH code
 
-Large parts of the code in \cw{ssh.c} are structured using a set of
-macros that implement (something close to) Donald Knuth's
-\q{coroutines} concept in C.
+Large parts of the code in the various SSH modules (in fact most of
+the protocol layers) are structured using a set of macros that
+implement (something close to) Donald Knuth's \q{coroutines} concept
+in C.
 
 Essentially, the purpose of these macros are to arrange that a
 function can call \cw{crReturn()} to return to its caller, and the
@@ -325,16 +379,31 @@ next time it is called control will resume from just after that
 
 This means that any local (automatic) variables declared in such a
 function will be corrupted every time you call \cw{crReturn}. If you
-need a variable to persist for longer than that, you \e{must} make
-it a field in one of the persistent state structures: either the
-local state structures \c{s} or \c{st} in each function, or the
-backend-wide structure \c{ssh}.
+need a variable to persist for longer than that, you \e{must} make it
+a field in some appropriate structure containing the persistent state
+of the coroutine \dash typically the main state structure for an SSH
+protocol layer.
 
 See
 \W{https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html}\c{https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html}
 for a more in-depth discussion of what these macros are for and how
 they work.
 
+Another caveat: most of these coroutines are not \e{guaranteed} to run
+to completion, because the SSH connection (or whatever) that they're
+part of might be interrupted at any time by an unexpected network
+event or user action. So whenever a coroutine-managed variable refers
+to a resource that needs releasing, you should also ensure that the
+cleanup function for its containing state structure can reliably
+release it even if the coroutine is aborted at an arbitrary point.
+
+For example, if an SSH packet protocol layer has to have a field that
+sometimes points to a piece of allocated memory, then you should
+ensure that when you free that memory you reset the pointer field to
+\cw{NULL}. Then, no matter when the protocol layer's cleanup function
+is called, it can reliably free the memory if there is any, and not
+crash if there isn't.
+
 \H{udp-compile-once} Single compilation of each source file
 
 The PuTTY build system for any given platform works on the following

+ 82 - 85
source/putty/import.c

@@ -12,39 +12,37 @@
 #include "ssh.h"
 #include "misc.h"
 
-int openssh_pem_encrypted(const Filename *filename);
-int openssh_new_encrypted(const Filename *filename);
-struct ssh2_userkey *openssh_pem_read(const Filename *filename,
-                                      char *passphrase,
-                                      const char **errmsg_p);
-struct ssh2_userkey *openssh_new_read(const Filename *filename,
-                                      char *passphrase,
-                                      const char **errmsg_p);
-int openssh_auto_write(const Filename *filename, struct ssh2_userkey *key,
-                       char *passphrase);
-int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
-                      char *passphrase);
-int openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
-                      char *passphrase);
-
-int sshcom_encrypted(const Filename *filename, char **comment);
-struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
-				 const char **errmsg_p);
-int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
-		 char *passphrase);
+static bool openssh_pem_encrypted(const Filename *file);
+static bool openssh_new_encrypted(const Filename *file);
+static struct ssh2_userkey *openssh_pem_read(
+    const Filename *file, const char *passphrase, const char **errmsg_p);
+static struct ssh2_userkey *openssh_new_read(
+    const Filename *file, const char *passphrase, const char **errmsg_p);
+static bool openssh_auto_write(
+    const Filename *file, struct ssh2_userkey *key, const char *passphrase);
+static bool openssh_pem_write(
+    const Filename *file, struct ssh2_userkey *key, const char *passphrase);
+static bool openssh_new_write(
+    const Filename *file, struct ssh2_userkey *key, const char *passphrase);
+
+static bool sshcom_encrypted(const Filename *file, char **comment);
+static struct ssh2_userkey *sshcom_read(
+    const Filename *file, const char *passphrase, const char **errmsg_p);
+static bool sshcom_write(
+    const Filename *file, struct ssh2_userkey *key, const char *passphrase);
 
 /*
  * Given a key type, determine whether we know how to import it.
  */
-int import_possible(int type)
+bool import_possible(int type)
 {
     if (type == SSH_KEYTYPE_OPENSSH_PEM)
-	return 1;
+	return true;
     if (type == SSH_KEYTYPE_OPENSSH_NEW)
-	return 1;
+	return true;
     if (type == SSH_KEYTYPE_SSHCOM)
-	return 1;
-    return 0;
+	return true;
+    return false;
 }
 
 /*
@@ -63,7 +61,7 @@ int import_target_type(int type)
 /*
  * Determine whether a foreign key is encrypted.
  */
-int import_encrypted(const Filename *filename, int type, char **comment)
+bool import_encrypted(const Filename *filename, int type, char **comment)
 {
     if (type == SSH_KEYTYPE_OPENSSH_PEM) {
 	/* OpenSSH PEM format doesn't contain a key comment at all */
@@ -77,7 +75,7 @@ int import_encrypted(const Filename *filename, int type, char **comment)
     } else if (type == SSH_KEYTYPE_SSHCOM) {
 	return sshcom_encrypted(filename, comment);
     }
-    return 0;
+    return false;
 }
 
 /*
@@ -107,17 +105,17 @@ struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
 /*
  * Export an SSH-1 key.
  */
-int export_ssh1(const Filename *filename, int type, struct RSAKey *key,
-		char *passphrase)
+bool export_ssh1(const Filename *filename, int type, struct RSAKey *key,
+                 char *passphrase)
 {
-    return 0;
+    return false;
 }
 
 /*
  * Export an SSH-2 key.
  */
-int export_ssh2(const Filename *filename, int type,
-                struct ssh2_userkey *key, char *passphrase)
+bool export_ssh2(const Filename *filename, int type,
+                 struct ssh2_userkey *key, char *passphrase)
 {
     if (type == SSH_KEYTYPE_OPENSSH_AUTO)
 	return openssh_auto_write(filename, key, passphrase);
@@ -125,7 +123,7 @@ int export_ssh2(const Filename *filename, int type,
 	return openssh_new_write(filename, key, passphrase);
     if (type == SSH_KEYTYPE_SSHCOM)
 	return sshcom_write(filename, key, passphrase);
-    return 0;
+    return false;
 }
 
 /*
@@ -276,7 +274,7 @@ typedef enum {
 
 struct openssh_pem_key {
     openssh_pem_keytype keytype;
-    int encrypted;
+    bool encrypted;
     openssh_pem_enc encryption;
     char iv[32];
     strbuf *keyblob;
@@ -309,14 +307,14 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
     char *line = NULL;
     const char *errmsg;
     char *p;
-    int headers_done;
+    bool headers_done;
     char base64_bit[4];
     int base64_chars = 0;
 
     ret = snew(struct openssh_pem_key);
     ret->keyblob = strbuf_new();
 
-    fp = f_open(filename, "r", FALSE);
+    fp = f_open(filename, "r", false);
     if (!fp) {
 	errmsg = "unable to open key file";
 	goto error;
@@ -355,10 +353,10 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
     sfree(line);
     line = NULL;
 
-    ret->encrypted = FALSE;
+    ret->encrypted = false;
     memset(ret->iv, 0, sizeof(ret->iv));
 
-    headers_done = 0;
+    headers_done = false;
     while (1) {
 	if (!(line = fgetline(fp))) {
 	    errmsg = "unexpected end of file";
@@ -385,7 +383,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
 		}
 		p += 2;
 		if (!strcmp(p, "ENCRYPTED"))
-		    ret->encrypted = TRUE;
+		    ret->encrypted = true;
 	    } else if (!strcmp(line, "DEK-Info")) {
 		int i, ivlen;
 
@@ -415,7 +413,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
 		}
 	    }
 	} else {
-	    headers_done = 1;
+	    headers_done = true;
 
 	    p = line;
 	    while (isbase64(*p)) {
@@ -482,13 +480,13 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
     return NULL;
 }
 
-int openssh_pem_encrypted(const Filename *filename)
+static bool openssh_pem_encrypted(const Filename *filename)
 {
     struct openssh_pem_key *key = load_openssh_pem_key(filename, NULL);
-    int ret;
+    bool ret;
 
     if (!key)
-	return 0;
+	return false;
     ret = key->encrypted;
     strbuf_free(key->keyblob);
     smemclr(key, sizeof(*key));
@@ -496,9 +494,8 @@ int openssh_pem_encrypted(const Filename *filename)
     return ret;
 }
 
-struct ssh2_userkey *openssh_pem_read(const Filename *filename,
-                                      char *passphrase,
-                                      const char **errmsg_p)
+static struct ssh2_userkey *openssh_pem_read(
+    const Filename *filename, const char *passphrase, const char **errmsg_p)
 {
     struct openssh_pem_key *key = load_openssh_pem_key(filename, errmsg_p);
     struct ssh2_userkey *retkey;
@@ -775,8 +772,8 @@ struct ssh2_userkey *openssh_pem_read(const Filename *filename,
     return retval;
 }
 
-int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
-                      char *passphrase)
+static bool openssh_pem_write(
+    const Filename *filename, struct ssh2_userkey *key, const char *passphrase)
 {
     strbuf *pubblob, *privblob, *outblob;
     unsigned char *spareblob;
@@ -786,7 +783,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
     const char *header, *footer;
     char zero[1];
     unsigned char iv[8];
-    int ret = 0;
+    bool ret = false;
     FILE *fp;
     BinarySource src[1];
 
@@ -1048,7 +1045,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
      * And save it. We'll use Unix line endings just in case it's
      * subsequently transferred in binary mode.
      */
-    fp = f_open(filename, "wb", TRUE);      /* ensure Unix line endings */
+    fp = f_open(filename, "wb", true);      /* ensure Unix line endings */
     if (!fp)
 	goto error;
     fputs(header, fp);
@@ -1061,7 +1058,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
     base64_encode(fp, outblob->u, outblob->len, 64);
     fputs(footer, fp);
     fclose(fp);
-    ret = 1;
+    ret = true;
 
     error:
     if (outblob)
@@ -1125,7 +1122,7 @@ static struct openssh_new_key *load_openssh_new_key(const Filename *filename,
     ret->keyblob = NULL;
     ret->keyblob_len = ret->keyblob_size = 0;
 
-    fp = f_open(filename, "r", FALSE);
+    fp = f_open(filename, "r", false);
     if (!fp) {
 	errmsg = "unable to open key file";
 	goto error;
@@ -1319,13 +1316,13 @@ static struct openssh_new_key *load_openssh_new_key(const Filename *filename,
     return NULL;
 }
 
-int openssh_new_encrypted(const Filename *filename)
+static bool openssh_new_encrypted(const Filename *filename)
 {
     struct openssh_new_key *key = load_openssh_new_key(filename, NULL);
-    int ret;
+    bool ret;
 
     if (!key)
-	return 0;
+	return false;
     ret = (key->cipher != ON_E_NONE);
     smemclr(key->keyblob, key->keyblob_size);
     sfree(key->keyblob);
@@ -1334,9 +1331,8 @@ int openssh_new_encrypted(const Filename *filename)
     return ret;
 }
 
-struct ssh2_userkey *openssh_new_read(const Filename *filename,
-                                      char *passphrase,
-                                      const char **errmsg_p)
+static struct ssh2_userkey *openssh_new_read(
+    const Filename *filename, const char *passphrase, const char **errmsg_p)
 {
     struct openssh_new_key *key = load_openssh_new_key(filename, errmsg_p);
     struct ssh2_userkey *retkey = NULL;
@@ -1515,13 +1511,13 @@ struct ssh2_userkey *openssh_new_read(const Filename *filename,
     return retval;
 }
 
-int openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
-                      char *passphrase)
+static bool openssh_new_write(
+    const Filename *filename, struct ssh2_userkey *key, const char *passphrase)
 {
     strbuf *pubblob, *privblob, *cblob;
     int padvalue, i;
     unsigned checkint;
-    int ret = 0;
+    bool ret = false;
     unsigned char bcrypt_salt[16];
     const int bcrypt_rounds = 16;
     FILE *fp;
@@ -1621,14 +1617,14 @@ int openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
      * And save it. We'll use Unix line endings just in case it's
      * subsequently transferred in binary mode.
      */
-    fp = f_open(filename, "wb", TRUE);      /* ensure Unix line endings */
+    fp = f_open(filename, "wb", true);      /* ensure Unix line endings */
     if (!fp)
 	goto error;
     fputs("-----BEGIN OPENSSH PRIVATE KEY-----\n", fp);
     base64_encode(fp, cblob->u, cblob->len, 64);
     fputs("-----END OPENSSH PRIVATE KEY-----\n", fp);
     fclose(fp);
-    ret = 1;
+    ret = true;
 
     error:
     if (cblob)
@@ -1644,8 +1640,8 @@ int openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
  * The switch function openssh_auto_write(), which chooses one of the
  * concrete OpenSSH output formats based on the key type.
  */
-int openssh_auto_write(const Filename *filename, struct ssh2_userkey *key,
-                       char *passphrase)
+static bool openssh_auto_write(
+    const Filename *filename, struct ssh2_userkey *key, const char *passphrase)
 {
     /*
      * The old OpenSSH format supports a fixed list of key types. We
@@ -1753,7 +1749,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
     int hdrstart, len;
     const char *errmsg;
     char *p;
-    int headers_done;
+    bool headers_done;
     char base64_bit[4];
     int base64_chars = 0;
 
@@ -1762,7 +1758,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
     ret->keyblob = NULL;
     ret->keyblob_len = ret->keyblob_size = 0;
 
-    fp = f_open(filename, "r", FALSE);
+    fp = f_open(filename, "r", false);
     if (!fp) {
 	errmsg = "unable to open key file";
 	goto error;
@@ -1780,7 +1776,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
     sfree(line);
     line = NULL;
 
-    headers_done = 0;
+    headers_done = false;
     while (1) {
 	if (!(line = fgetline(fp))) {
 	    errmsg = "unexpected end of file";
@@ -1840,7 +1836,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
                 ret->comment[sizeof(ret->comment)-1] = '\0';
             }
 	} else {
-	    headers_done = 1;
+	    headers_done = true;
 
 	    p = line;
 	    while (isbase64(*p)) {
@@ -1905,12 +1901,12 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
     return NULL;
 }
 
-int sshcom_encrypted(const Filename *filename, char **comment)
+static bool sshcom_encrypted(const Filename *filename, char **comment)
 {
     struct sshcom_key *key = load_sshcom_key(filename, NULL);
     BinarySource src[1];
     ptrlen str;
-    int answer = FALSE;
+    bool answer = false;
 
     *comment = NULL;
     if (!key)
@@ -1926,7 +1922,7 @@ int sshcom_encrypted(const Filename *filename, char **comment)
     if (get_err(src))
         goto done;                     /* key is invalid */
     if (!ptrlen_eq_string(str, "none"))
-        answer = TRUE;
+        answer = true;
 
     done:
     if (key) {
@@ -1970,8 +1966,8 @@ static ptrlen BinarySource_get_mp_sshcom_as_string(BinarySource *src)
 #define get_mp_sshcom_as_string(bs) \
     BinarySource_get_mp_sshcom_as_string(BinarySource_UPCAST(bs))
 
-struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
-				 const char **errmsg_p)
+static struct ssh2_userkey *sshcom_read(
+    const Filename *filename, const char *passphrase, const char **errmsg_p)
 {
     struct sshcom_key *key = load_sshcom_key(filename, errmsg_p);
     const char *errmsg;
@@ -1981,7 +1977,7 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
     const char prefix_rsa[] = "if-modn{sign{rsa";
     const char prefix_dsa[] = "dl-modp{sign{dsa";
     enum { RSA, DSA } type;
-    int encrypted;
+    bool encrypted;
     struct ssh2_userkey *ret = NULL, *retkey;
     const ssh_keyalg *alg;
     strbuf *blob = NULL;
@@ -2017,9 +2013,9 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
      */
     str = get_string(src);
     if (ptrlen_eq_string(str, "none"))
-        encrypted = 0;
+        encrypted = false;
     else if (ptrlen_eq_string(str, "3des-cbc"))
-        encrypted = 1;
+        encrypted = true;
     else {
         errmsg = "key encryption is of unknown type";
         goto error;
@@ -2181,17 +2177,18 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
     return ret;
 }
 
-int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
-		 char *passphrase)
+static bool sshcom_write(
+    const Filename *filename, struct ssh2_userkey *key, const char *passphrase)
 {
     strbuf *pubblob, *privblob, *outblob;
     ptrlen numbers[6];
-    int nnumbers, initial_zero, lenpos, i;
+    int nnumbers, lenpos, i;
+    bool initial_zero;
     BinarySource src[1];
     const char *type;
     char *ciphertext;
     int cipherlen;
-    int ret = 0;
+    bool ret = false;
     FILE *fp;
 
     /*
@@ -2234,7 +2231,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
         numbers[5] = p;
 
         nnumbers = 6;
-	initial_zero = 0;
+	initial_zero = false;
 	type = "if-modn{sign{rsa-pkcs1-sha1},encrypt{rsa-pkcs1v2-oaep}}";
     } else if (ssh_key_alg(key->key) == &ssh_dss) {
         ptrlen p, q, g, y, x;
@@ -2261,7 +2258,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
         numbers[4] = x;
 
         nnumbers = 5;
-	initial_zero = 1;
+	initial_zero = true;
 	type = "dl-modp{sign{dsa-nist-sha1},dh{plain}}";
     } else {
         goto error;                    /* unsupported key type */
@@ -2338,7 +2335,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
      * And save it. We'll use Unix line endings just in case it's
      * subsequently transferred in binary mode.
      */
-    fp = f_open(filename, "wb", TRUE);      /* ensure Unix line endings */
+    fp = f_open(filename, "wb", true);      /* ensure Unix line endings */
     if (!fp)
 	goto error;
     fputs("---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----\n", fp);
@@ -2362,7 +2359,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
     base64_encode(fp, outblob->u, outblob->len, 70);
     fputs("---- END SSH2 ENCRYPTED PRIVATE KEY ----\n", fp);
     fclose(fp);
-    ret = 1;
+    ret = true;
 
     error:
     if (outblob)

+ 0 - 175
source/putty/int64.c

@@ -1,175 +0,0 @@
-/*
- * Handling of the int64 and uint64 types. Done in 32-bit integers,
- * for (pre-C99) portability. Hopefully once C99 becomes widespread
- * we can kiss this lot goodbye...
- */
-
-#include <assert.h>
-#include <string.h>
-
-#include "int64.h"
-
-uint64 uint64_div10(uint64 x, int *remainder)
-{
-    uint64 y;
-    unsigned int rem, r2;
-    y.hi = x.hi / 10;
-    y.lo = x.lo / 10;
-    rem = x.lo % 10;
-    /*
-     * Now we have to add in the remainder left over from x.hi.
-     */
-    r2 = x.hi % 10;
-    y.lo += r2 * 429496729;
-    rem += r2 * 6;
-    y.lo += rem / 10;
-    rem %= 10;
-
-    if (remainder)
-	*remainder = rem;
-    return y;
-}
-
-void uint64_decimal(uint64 x, char *buffer)
-{
-    char buf[20];
-    int start = 20;
-    int d;
-
-    do {
-	x = uint64_div10(x, &d);
-	assert(start > 0);
-	buf[--start] = d + '0';
-    } while (x.hi || x.lo);
-
-    memcpy(buffer, buf + start, sizeof(buf) - start);
-    buffer[sizeof(buf) - start] = '\0';
-}
-
-uint64 uint64_make(unsigned long hi, unsigned long lo)
-{
-    uint64 y;
-    y.hi = hi & 0xFFFFFFFFU;
-    y.lo = lo & 0xFFFFFFFFU;
-    return y;
-}
-
-uint64 uint64_add(uint64 x, uint64 y)
-{
-    x.lo = (x.lo + y.lo) & 0xFFFFFFFFU;
-    x.hi += y.hi + (x.lo < y.lo ? 1 : 0);
-    return x;
-}
-
-uint64 uint64_add32(uint64 x, unsigned long y)
-{
-    uint64 yy;
-    yy.hi = 0;
-    yy.lo = y;
-    return uint64_add(x, yy);
-}
-
-int uint64_compare(uint64 x, uint64 y)
-{
-    if (x.hi != y.hi)
-	return x.hi < y.hi ? -1 : +1;
-    if (x.lo != y.lo)
-	return x.lo < y.lo ? -1 : +1;
-    return 0;
-}
-
-uint64 uint64_subtract(uint64 x, uint64 y)
-{
-    x.lo = (x.lo - y.lo) & 0xFFFFFFFFU;
-    x.hi = (x.hi - y.hi - (x.lo > (y.lo ^ 0xFFFFFFFFU) ? 1 : 0)) & 0xFFFFFFFFU;
-    return x;
-}
-
-double uint64_to_double(uint64 x)
-{
-    return (4294967296.0 * x.hi) + (double)x.lo;
-}
-
-uint64 uint64_shift_right(uint64 x, int shift)
-{
-    if (shift < 32) {
-	x.lo >>= shift;
-	x.lo |= (x.hi << (32-shift)) & 0xFFFFFFFFU;
-	x.hi >>= shift;
-    } else {
-	x.lo = x.hi >> (shift-32);
-	x.hi = 0;
-    }
-    return x;
-}
-
-uint64 uint64_shift_left(uint64 x, int shift)
-{
-    if (shift < 32) {
-	x.hi = (x.hi << shift) & 0xFFFFFFFFU;
-	x.hi |= (x.lo >> (32-shift));
-	x.lo = (x.lo << shift) & 0xFFFFFFFFU;
-    } else {
-	x.hi = (x.lo << (shift-32)) & 0xFFFFFFFFU;
-	x.lo = 0;
-    }
-    return x;
-}
-
-uint64 uint64_from_decimal(const char *str)
-{
-    uint64 ret;
-    ret.hi = ret.lo = 0;
-    while (*str >= '0' && *str <= '9') {
-	ret = uint64_add(uint64_shift_left(ret, 3),
-			 uint64_shift_left(ret, 1));
-	ret = uint64_add32(ret, *str - '0');
-	str++;
-    }
-    return ret;
-}
-
-#ifdef TESTMODE
-
-#include <stdio.h>
-
-int main(void)
-{
-    uint64 x, y, z;
-    char buf[80];
-
-    x = uint64_make(0x3456789AUL, 0xDEF01234UL);
-    printf("%08lx.%08lx\n", x.hi, x.lo);
-    uint64_decimal(x, buf);
-    printf("%s\n", buf);
-
-    y = uint64_add32(x, 0xFFFFFFFFU);
-    printf("%08lx.%08lx\n", y.hi, y.lo);
-    uint64_decimal(y, buf);
-    printf("%s\n", buf);
-
-    z = uint64_subtract(y, x);
-    printf("%08lx.%08lx\n", z.hi, z.lo);
-    uint64_decimal(z, buf);
-    printf("%s\n", buf);
-
-    z = uint64_subtract(x, y);
-    printf("%08lx.%08lx\n", z.hi, z.lo);
-    uint64_decimal(z, buf);
-    printf("%s\n", buf);
-
-    y = uint64_shift_right(x, 4);
-    printf("%08lx.%08lx\n", y.hi, y.lo);
-
-    y = uint64_shift_right(x, 36);
-    printf("%08lx.%08lx\n", y.hi, y.lo);
-
-    y = uint64_shift_left(x, 4);
-    printf("%08lx.%08lx\n", x.hi, x.lo);
-
-    y = uint64_shift_left(x, 36);
-    printf("%08lx.%08lx\n", x.hi, x.lo);
-
-    return 0;
-}
-#endif

+ 0 - 29
source/putty/int64.h

@@ -1,29 +0,0 @@
-/*
- * Header for int64.c.
- */
-
-#ifndef PUTTY_INT64_H
-#define PUTTY_INT64_H
-
-#include "defs.h"
-
-typedef struct {
-    unsigned long hi, lo;
-} uint64;
-
-uint64 uint64_div10(uint64 x, int *remainder);
-void uint64_decimal(uint64 x, char *buffer);
-uint64 uint64_make(unsigned long hi, unsigned long lo);
-uint64 uint64_add(uint64 x, uint64 y);
-uint64 uint64_add32(uint64 x, unsigned long y);
-int uint64_compare(uint64 x, uint64 y);
-uint64 uint64_subtract(uint64 x, uint64 y);
-double uint64_to_double(uint64 x);
-uint64 uint64_shift_right(uint64 x, int shift);
-uint64 uint64_shift_left(uint64 x, int shift);
-uint64 uint64_from_decimal(const char *str);
-
-void BinarySink_put_uint64(BinarySink *, uint64);
-uint64 BinarySource_get_uint64(BinarySource *);
-
-#endif

+ 9 - 9
source/putty/logging.c

@@ -87,22 +87,22 @@ static void logfopen_callback(void *vctx, int mode)
     char buf[256], *event;
     struct tm tm;
     const char *fmode;
-    int shout = FALSE;
+    bool shout = false;
 
     if (mode == 0) {
 	ctx->state = L_ERROR;	       /* disable logging */
     } else {
 	fmode = (mode == 1 ? "ab" : "wb");
-	ctx->lgfp = f_open(ctx->currlogfilename, fmode, FALSE);
+	ctx->lgfp = f_open(ctx->currlogfilename, fmode, false);
 	if (ctx->lgfp) {
 	    ctx->state = L_OPEN;
         } else {
 	    ctx->state = L_ERROR;
-            shout = TRUE;
+            shout = true;
         }
     }
 
-    if (ctx->state == L_OPEN && conf_get_int(ctx->conf, CONF_logheader)) {
+    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);
@@ -419,15 +419,15 @@ void log_free(LogContext *ctx)
 
 void log_reconfig(LogContext *ctx, Conf *conf)
 {
-    int reset_logging;
+    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;
+	reset_logging = true;
     else
-	reset_logging = FALSE;
+	reset_logging = false;
 
     if (reset_logging)
 	logfclose(ctx);
@@ -463,7 +463,7 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port,
     s = filename_to_str(src);
 
     while (*s) {
-        int sanitise = FALSE;
+        bool sanitise = false;
 	/* Let (bufp, len) be the string to append. */
 	bufp = buf;		       /* don't usually override this */
 	if (*s == '&') {
@@ -501,7 +501,7 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port,
              * 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;
+            sanitise = true;
 	} else {
 	    buf[0] = *s++;
 	    size = 1;

+ 67 - 67
source/putty/mainchan.c

@@ -14,16 +14,16 @@
 static void mainchan_free(Channel *chan);
 static void mainchan_open_confirmation(Channel *chan);
 static void mainchan_open_failure(Channel *chan, const char *errtext);
-static int mainchan_send(Channel *chan, int is_stderr, const void *, int);
+static int mainchan_send(Channel *chan, bool is_stderr, const void *, int);
 static void mainchan_send_eof(Channel *chan);
-static void mainchan_set_input_wanted(Channel *chan, int wanted);
+static void mainchan_set_input_wanted(Channel *chan, bool wanted);
 static char *mainchan_log_close_msg(Channel *chan);
-static int mainchan_rcvd_exit_status(Channel *chan, int status);
-static int mainchan_rcvd_exit_signal(
-    Channel *chan, ptrlen signame, int core_dumped, ptrlen msg);
-static int mainchan_rcvd_exit_signal_numeric(
-    Channel *chan, int signum, int core_dumped, ptrlen msg);
-static void mainchan_request_response(Channel *chan, int success);
+static bool mainchan_rcvd_exit_status(Channel *chan, int status);
+static bool mainchan_rcvd_exit_signal(
+    Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg);
+static bool mainchan_rcvd_exit_signal_numeric(
+    Channel *chan, int signum, bool core_dumped, ptrlen msg);
+static void mainchan_request_response(Channel *chan, bool success);
 
 static const struct ChannelVtable mainchan_channelvt = {
     mainchan_free,
@@ -54,31 +54,31 @@ typedef enum MainChanType {
     MAINCHAN_SESSION, MAINCHAN_DIRECT_TCPIP
 } MainChanType;
 
-typedef struct mainchan {
+struct mainchan {
     SshChannel *sc;
     Conf *conf;
     PacketProtocolLayer *ppl;
     ConnectionLayer *cl;
 
     MainChanType type;
-    int is_simple;
+    bool is_simple;
 
-    int req_x11, req_agent, req_pty, req_cmd_primary, req_cmd_fallback;
+    bool req_x11, req_agent, req_pty, req_cmd_primary, req_cmd_fallback;
     int n_req_env, n_env_replies, n_env_fails;
-    int eof_pending, eof_sent, got_pty, ready;
+    bool eof_pending, eof_sent, got_pty, ready;
 
     int term_width, term_height;
 
     Channel chan;
-} mainchan;
+};
 
 mainchan *mainchan_new(
     PacketProtocolLayer *ppl, ConnectionLayer *cl, Conf *conf,
-    int term_width, int term_height, int is_simple, SshChannel **sc_out)
+    int term_width, int term_height, bool is_simple, SshChannel **sc_out)
 {
     mainchan *mc;
 
-    if (conf_get_int(conf, CONF_ssh_no_shell))
+    if (conf_get_bool(conf, CONF_ssh_no_shell))
         return NULL;                   /* no main channel at all */
 
     mc = snew(mainchan);
@@ -139,9 +139,9 @@ static void mainchan_open_confirmation(Channel *chan)
         char *key, *val, *cmd;
         struct X11Display *x11disp;
         struct X11FakeAuth *x11auth;
-        int retry_cmd_now = FALSE;
+        bool retry_cmd_now = false;
 
-	if (conf_get_int(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),
@@ -154,49 +154,49 @@ static void mainchan_open_confirmation(Channel *chan)
                     mc->cl, conf_get_int(mc->conf, CONF_x11_auth), x11disp);
 
                 sshfwd_request_x11_forwarding(
-                    mc->sc, TRUE, x11auth->protoname, x11auth->datastring,
-                    x11disp->screennum, FALSE);
-                mc->req_x11 = TRUE;
+                    mc->sc, true, x11auth->protoname, x11auth->datastring,
+                    x11disp->screennum, false);
+                mc->req_x11 = true;
             }
         }
 
 	if (ssh_agent_forwarding_permitted(mc->cl)) {
-            sshfwd_request_agent_forwarding(mc->sc, TRUE);
-            mc->req_agent = TRUE;
+            sshfwd_request_agent_forwarding(mc->sc, true);
+            mc->req_agent = true;
         }
 
-	if (!conf_get_int(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;
+                mc->sc, true, mc->conf, mc->term_width, mc->term_height);
+            mc->req_pty = true;
         }
 
         for (val = conf_get_str_strs(mc->conf, CONF_environmt, NULL, &key);
              val != NULL;
              val = conf_get_str_strs(mc->conf, CONF_environmt, key, &key)) {
-            sshfwd_send_env_var(mc->sc, TRUE, key, val);
+            sshfwd_send_env_var(mc->sc, true, key, val);
             mc->n_req_env++;
         }
         if (mc->n_req_env)
             ppl_logevent(("Sent %d environment variables", mc->n_req_env));
 
         cmd = conf_get_str(mc->conf, CONF_remote_cmd);
-        if (conf_get_int(mc->conf, CONF_ssh_subsys)) {
-            retry_cmd_now = !sshfwd_start_subsystem(mc->sc, TRUE, cmd);
+        if (conf_get_bool(mc->conf, CONF_ssh_subsys)) {
+            retry_cmd_now = !sshfwd_start_subsystem(mc->sc, true, cmd);
         } else if (*cmd) {
-            sshfwd_start_command(mc->sc, TRUE, cmd);
+            sshfwd_start_command(mc->sc, true, cmd);
         } else {
-            sshfwd_start_shell(mc->sc, TRUE);
+            sshfwd_start_shell(mc->sc, true);
         }
 
         if (retry_cmd_now)
             mainchan_try_fallback_command(mc);
         else
-            mc->req_cmd_primary = TRUE;
+            mc->req_cmd_primary = true;
 
     } else {
-        ssh_set_ldisc_option(mc->cl, LD_ECHO, TRUE);
-        ssh_set_ldisc_option(mc->cl, LD_EDIT, TRUE);
+        ssh_set_ldisc_option(mc->cl, LD_ECHO, true);
+        ssh_set_ldisc_option(mc->cl, LD_EDIT, true);
         mainchan_ready(mc);
     }
 }
@@ -204,22 +204,22 @@ static void mainchan_open_confirmation(Channel *chan)
 static void mainchan_try_fallback_command(mainchan *mc)
 {
     const char *cmd = conf_get_str(mc->conf, CONF_remote_cmd2);
-    if (conf_get_int(mc->conf, CONF_ssh_subsys2)) {
-        sshfwd_start_subsystem(mc->sc, TRUE, cmd);
+    if (conf_get_bool(mc->conf, CONF_ssh_subsys2)) {
+        sshfwd_start_subsystem(mc->sc, true, cmd);
     } else {
-        sshfwd_start_command(mc->sc, TRUE, cmd);
+        sshfwd_start_command(mc->sc, true, cmd);
     }
-    mc->req_cmd_fallback = TRUE;
+    mc->req_cmd_fallback = true;
 }
 
-static void mainchan_request_response(Channel *chan, int success)
+static void mainchan_request_response(Channel *chan, bool success)
 {
     assert(chan->vt == &mainchan_channelvt);
     mainchan *mc = container_of(chan, mainchan, chan);
     PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */
 
     if (mc->req_x11) {
-        mc->req_x11 = FALSE;
+        mc->req_x11 = false;
 
         if (success) {
             ppl_logevent(("X11 forwarding enabled"));
@@ -231,7 +231,7 @@ static void mainchan_request_response(Channel *chan, int success)
     }
 
     if (mc->req_agent) {
-        mc->req_agent = FALSE;
+        mc->req_agent = false;
 
         if (success) {
             ppl_logevent(("Agent forwarding enabled"));
@@ -243,16 +243,16 @@ static void mainchan_request_response(Channel *chan, int success)
     }
 
     if (mc->req_pty) {
-        mc->req_pty = FALSE;
+        mc->req_pty = false;
 
         if (success) {
             ppl_logevent(("Allocated pty"));
-            mc->got_pty = TRUE;
+            mc->got_pty = true;
         } else {
             ppl_logevent(("Server refused to allocate pty"));
             ppl_printf(("Server refused to allocate pty\r\n"));
-            ssh_set_ldisc_option(mc->cl, LD_ECHO, TRUE);
-            ssh_set_ldisc_option(mc->cl, LD_EDIT, TRUE);
+            ssh_set_ldisc_option(mc->cl, LD_ECHO, true);
+            ssh_set_ldisc_option(mc->cl, LD_EDIT, true);
         }
         return;
     }
@@ -282,7 +282,7 @@ static void mainchan_request_response(Channel *chan, int success)
     }
 
     if (mc->req_cmd_primary) {
-        mc->req_cmd_primary = FALSE;
+        mc->req_cmd_primary = false;
 
         if (success) {
             ppl_logevent(("Started a shell/command"));
@@ -302,7 +302,7 @@ static void mainchan_request_response(Channel *chan, int success)
     }
 
     if (mc->req_cmd_fallback) {
-        mc->req_cmd_fallback = FALSE;
+        mc->req_cmd_fallback = false;
 
         if (success) {
             ppl_logevent(("Started a shell/command"));
@@ -318,14 +318,14 @@ static void mainchan_request_response(Channel *chan, int success)
 
 static void mainchan_ready(mainchan *mc)
 {
-    mc->ready = TRUE;
+    mc->ready = true;
 
-    ssh_set_wants_user_input(mc->cl, TRUE);
+    ssh_set_wants_user_input(mc->cl, true);
     ssh_ppl_got_user_input(mc->ppl); /* in case any is already queued */
 
     /* If an EOF arrived before we were ready, handle it now. */
     if (mc->eof_pending) {
-        mc->eof_pending = FALSE;
+        mc->eof_pending = false;
 	mainchan_special_cmd(mc, SS_EOF, 0);
     }
 
@@ -362,7 +362,7 @@ static void mainchan_open_failure(Channel *chan, const char *errtext)
     queue_toplevel_callback(mainchan_open_failure_abort, ctx);
 }
 
-static int mainchan_send(Channel *chan, int is_stderr,
+static int mainchan_send(Channel *chan, bool is_stderr,
                          const void *data, int length)
 {
     assert(chan->vt == &mainchan_channelvt);
@@ -376,7 +376,7 @@ static void mainchan_send_eof(Channel *chan)
     mainchan *mc = container_of(chan, mainchan, chan);
     PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */
 
-    if (!mc->eof_sent & (seat_eof(mc->ppl->seat) || mc->got_pty)) {
+    if (!mc->eof_sent && (seat_eof(mc->ppl->seat) || mc->got_pty)) {
         /*
          * Either seat_eof told us that the front end wants us to
          * close the outgoing side of the connection as soon as we see
@@ -386,12 +386,12 @@ static void mainchan_send_eof(Channel *chan)
          */
         sshfwd_write_eof(mc->sc);
         ppl_logevent(("Sent EOF message"));
+        mc->eof_sent = true;
+        ssh_set_wants_user_input(mc->cl, false); /* stop reading from stdin */
     }
-    mc->eof_sent = TRUE;
-    ssh_set_wants_user_input(mc->cl, FALSE); /* now stop reading from stdin */
 }
 
-static void mainchan_set_input_wanted(Channel *chan, int wanted)
+static void mainchan_set_input_wanted(Channel *chan, bool wanted)
 {
     assert(chan->vt == &mainchan_channelvt);
     mainchan *mc = container_of(chan, mainchan, chan);
@@ -410,7 +410,7 @@ static char *mainchan_log_close_msg(Channel *chan)
     return dupstr("Main session channel closed");
 }
 
-static int mainchan_rcvd_exit_status(Channel *chan, int status)
+static bool mainchan_rcvd_exit_status(Channel *chan, int status)
 {
     assert(chan->vt == &mainchan_channelvt);
     mainchan *mc = container_of(chan, mainchan, chan);
@@ -418,12 +418,12 @@ static int mainchan_rcvd_exit_status(Channel *chan, int status)
 
     ssh_got_exitcode(mc->ppl->ssh, status);
     ppl_logevent(("Session sent command exit status %d", status));
-    return TRUE;
+    return true;
 }
 
 static void mainchan_log_exit_signal_common(
     mainchan *mc, const char *sigdesc,
-    int core_dumped, ptrlen msg)
+    bool core_dumped, ptrlen msg)
 {
     PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */
 
@@ -434,8 +434,8 @@ static void mainchan_log_exit_signal_common(
                   sigdesc, core_msg, msg_pre, PTRLEN_PRINTF(msg), msg_post));
 }
 
-static int mainchan_rcvd_exit_signal(
-    Channel *chan, ptrlen signame, int core_dumped, ptrlen msg)
+static bool mainchan_rcvd_exit_signal(
+    Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg)
 {
     assert(chan->vt == &mainchan_channelvt);
     mainchan *mc = container_of(chan, mainchan, chan);
@@ -466,11 +466,11 @@ static int mainchan_rcvd_exit_signal(
         signame_str = dupprintf("signal SIG%.*s", PTRLEN_PRINTF(signame));
     mainchan_log_exit_signal_common(mc, signame_str, core_dumped, msg);
     sfree(signame_str);
-    return TRUE;
+    return true;
 }
 
-static int mainchan_rcvd_exit_signal_numeric(
-    Channel *chan, int signum, int core_dumped, ptrlen msg)
+static bool mainchan_rcvd_exit_signal_numeric(
+    Channel *chan, int signum, bool core_dumped, ptrlen msg)
 {
     assert(chan->vt == &mainchan_channelvt);
     mainchan *mc = container_of(chan, mainchan, chan);
@@ -480,7 +480,7 @@ static int mainchan_rcvd_exit_signal_numeric(
     signum_str = dupprintf("signal %d", signum);
     mainchan_log_exit_signal_common(mc, signum_str, core_dumped, msg);
     sfree(signum_str);
-    return TRUE;
+    return true;
 }
 
 void mainchan_get_specials(
@@ -533,17 +533,17 @@ void mainchan_special_cmd(mainchan *mc, SessionSpecialCode code, int arg)
              * Buffer the EOF to send as soon as the main channel is
              * fully set up.
              */
-            mc->eof_pending = TRUE;
+            mc->eof_pending = true;
         } else if (!mc->eof_sent) {
             sshfwd_write_eof(mc->sc);
-            mc->eof_sent = TRUE;
+            mc->eof_sent = true;
         }
     } else if (code == SS_BRK) {
         sshfwd_send_serial_break(
-            mc->sc, FALSE, 0 /* default break length */);
+            mc->sc, false, 0 /* default break length */);
     } else if ((signame = ssh_signal_lookup(code)) != NULL) {
         /* It's a signal. */
-        sshfwd_send_signal(mc->sc, FALSE, signame);
+        sshfwd_send_signal(mc->sc, false, signame);
         ppl_logevent(("Sent signal SIG%s", signame));
     }
 }

+ 18 - 23
source/putty/marshal.c

@@ -4,7 +4,6 @@
 
 #include "marshal.h"
 #include "misc.h"
-#include "int64.h"
 
 void BinarySink_put_data(BinarySink *bs, const void *data, size_t len)
 {
@@ -27,7 +26,7 @@ void BinarySink_put_byte(BinarySink *bs, unsigned char val)
     bs->write(bs, &val, 1);
 }
 
-void BinarySink_put_bool(BinarySink *bs, int val)
+void BinarySink_put_bool(BinarySink *bs, bool val)
 {
     unsigned char cval = val ? 1 : 0;
     bs->write(bs, &cval, 1);
@@ -47,10 +46,11 @@ void BinarySink_put_uint32(BinarySink *bs, unsigned long val)
     bs->write(bs, data, sizeof(data));
 }
 
-void BinarySink_put_uint64(BinarySink *bs, uint64 val)
+void BinarySink_put_uint64(BinarySink *bs, uint64_t val)
 {
-    BinarySink_put_uint32(bs, val.hi);
-    BinarySink_put_uint32(bs, val.lo);
+    unsigned char data[8];
+    PUT_64BIT_MSB_FIRST(data, val);
+    bs->write(bs, data, sizeof(data));
 }
 
 void BinarySink_put_string(BinarySink *bs, const void *data, size_t len)
@@ -84,28 +84,28 @@ void BinarySink_put_asciz(BinarySink *bs, const char *str)
     bs->write(bs, str, strlen(str) + 1);
 }
 
-int BinarySink_put_pstring(BinarySink *bs, const char *str)
+bool BinarySink_put_pstring(BinarySink *bs, const char *str)
 {
     size_t len = strlen(str);
     if (len > 255)
-        return FALSE; /* can't write a Pascal-style string this long */
+        return false; /* can't write a Pascal-style string this long */
     BinarySink_put_byte(bs, len);
     bs->write(bs, str, len);
-    return TRUE;
+    return true;
 }
 
 /* ---------------------------------------------------------------------- */
 
-static int BinarySource_data_avail(BinarySource *src, size_t wanted)
+static bool BinarySource_data_avail(BinarySource *src, size_t wanted)
 {
     if (src->err)
-        return FALSE;
+        return false;
 
     if (wanted <= src->len - src->pos)
-        return TRUE;
+        return true;
 
     src->err = BSE_OUT_OF_DATA;
-    return FALSE;
+    return false;
 }
 
 #define avail(wanted) BinarySource_data_avail(src, wanted)
@@ -134,12 +134,12 @@ unsigned char BinarySource_get_byte(BinarySource *src)
     return *ucp;
 }
 
-int BinarySource_get_bool(BinarySource *src)
+bool BinarySource_get_bool(BinarySource *src)
 {
     const unsigned char *ucp;
 
     if (!avail(1))
-        return 0;
+        return false;
 
     ucp = consume(1);
     return *ucp != 0;
@@ -167,20 +167,15 @@ unsigned long BinarySource_get_uint32(BinarySource *src)
     return GET_32BIT_MSB_FIRST(ucp);
 }
 
-uint64 BinarySource_get_uint64(BinarySource *src)
+uint64_t BinarySource_get_uint64(BinarySource *src)
 {
     const unsigned char *ucp;
-    uint64 toret;
 
-    if (!avail(8)) {
-        toret.hi = toret.lo = 0;
-        return toret;
-    }
+    if (!avail(8))
+        return 0;
 
     ucp = consume(8);
-    toret.hi = GET_32BIT_MSB_FIRST(ucp);
-    toret.lo = GET_32BIT_MSB_FIRST(ucp + 4);
-    return toret;
+    return GET_64BIT_MSB_FIRST(ucp);
 }
 
 ptrlen BinarySource_get_string(BinarySource *src)

+ 6 - 5
source/putty/marshal.h

@@ -76,8 +76,7 @@ struct BinarySink {
  * first parameter of any of these put_* macros.
  */
 
-/* Basic big-endian integer types. uint64 is the structure type
- * defined in int64.h, not the C99 built-in type. */
+/* Basic big-endian integer types. */
 #define put_byte(bs, val) \
     BinarySink_put_byte(BinarySink_UPCAST(bs), val)
 #define put_uint16(bs, val) \
@@ -143,16 +142,17 @@ struct BinarySink {
 void BinarySink_put_data(BinarySink *, const void *data, size_t len);
 void BinarySink_put_padding(BinarySink *, size_t len, unsigned char padbyte);
 void BinarySink_put_byte(BinarySink *, unsigned char);
-void BinarySink_put_bool(BinarySink *, int);
+void BinarySink_put_bool(BinarySink *, bool);
 void BinarySink_put_uint16(BinarySink *, unsigned long);
 void BinarySink_put_uint32(BinarySink *, unsigned long);
+void BinarySink_put_uint64(BinarySink *, uint64_t);
 void BinarySink_put_string(BinarySink *, const void *data, size_t len);
 void BinarySink_put_stringpl(BinarySink *, ptrlen);
 void BinarySink_put_stringz(BinarySink *, const char *str);
 struct strbuf;
 void BinarySink_put_stringsb(BinarySink *, struct strbuf *);
 void BinarySink_put_asciz(BinarySink *, const char *str);
-int BinarySink_put_pstring(BinarySink *, const char *str);
+bool BinarySink_put_pstring(BinarySink *, const char *str);
 
 /* ---------------------------------------------------------------------- */
 
@@ -274,9 +274,10 @@ struct BinarySource {
 
 ptrlen BinarySource_get_data(BinarySource *, size_t);
 unsigned char BinarySource_get_byte(BinarySource *);
-int BinarySource_get_bool(BinarySource *);
+bool BinarySource_get_bool(BinarySource *);
 unsigned BinarySource_get_uint16(BinarySource *);
 unsigned long BinarySource_get_uint32(BinarySource *);
+uint64_t BinarySource_get_uint64(BinarySource *);
 ptrlen BinarySource_get_string(BinarySource *);
 const char *BinarySource_get_asciz(BinarySource *);
 ptrlen BinarySource_get_pstring(BinarySource *);

+ 34 - 76
source/putty/misc.c

@@ -97,7 +97,7 @@ char ctrlparse(char *s, char **next)
  * various standard string.h functions.
  */
 static const char *host_strchr_internal(const char *s, const char *set,
-                                        int first)
+                                        bool first)
 {
     int brackets = 0;
     const char *ret = NULL;
@@ -123,7 +123,7 @@ static const char *host_strchr_internal(const char *s, const char *set,
 }
 size_t host_strcspn(const char *s, const char *set)
 {
-    const char *answer = host_strchr_internal(s, set, TRUE);
+    const char *answer = host_strchr_internal(s, set, true);
     if (answer)
         return answer - s;
     else
@@ -134,14 +134,14 @@ char *host_strchr(const char *s, int c)
     char set[2];
     set[0] = c;
     set[1] = '\0';
-    return (char *) host_strchr_internal(s, set, TRUE);
+    return (char *) host_strchr_internal(s, set, true);
 }
 char *host_strrchr(const char *s, int c)
 {
     char set[2];
     set[0] = c;
     set[1] = '\0';
-    return (char *) host_strchr_internal(s, set, FALSE);
+    return (char *) host_strchr_internal(s, set, false);
 }
 
 #ifdef TEST_HOST_STRFOO
@@ -235,12 +235,12 @@ prompts_t *new_prompts(void)
     p->prompts = NULL;
     p->n_prompts = 0;
     p->data = NULL;
-    p->to_server = TRUE; /* to be on the safe side */
+    p->to_server = true; /* to be on the safe side */
     p->name = p->instruction = NULL;
-    p->name_reqd = p->instr_reqd = FALSE;
+    p->name_reqd = p->instr_reqd = false;
     return p;
 }
-void add_prompt(prompts_t *p, char *promptstr, int echo)
+void add_prompt(prompts_t *p, char *promptstr, bool echo)
 {
     prompt_t *pr = snew(prompt_t);
     pr->prompt = promptstr;
@@ -349,29 +349,6 @@ void burnstr(char *string)             /* sfree(str), only clear it first */
     }
 }
 
-int toint(unsigned u)
-{
-    /*
-     * Convert an unsigned to an int, without running into the
-     * undefined behaviour which happens by the strict C standard if
-     * the value overflows. You'd hope that sensible compilers would
-     * do the sensible thing in response to a cast, but actually I
-     * don't trust modern compilers not to do silly things like
-     * assuming that _obviously_ you wouldn't have caused an overflow
-     * and so they can elide an 'if (i < 0)' test immediately after
-     * the cast.
-     *
-     * Sensible compilers ought of course to optimise this entire
-     * function into 'just return the input value'!
-     */
-    if (u <= (unsigned)INT_MAX)
-        return (int)u;
-    else if (u >= (unsigned)INT_MIN)   /* wrap in cast _to_ unsigned is OK */
-        return INT_MIN + (int)(u - (unsigned)INT_MIN);
-    else
-        return INT_MIN; /* fallback; should never occur on binary machines */
-}
-
 int string_length_for_printf(size_t s)
 {
     /* Truncate absurdly long strings (should one show up) to fit
@@ -826,13 +803,13 @@ void bufchain_fetch_consume(bufchain *ch, void *data, int len)
     bufchain_consume(ch, len);
 }
 
-int bufchain_try_fetch_consume(bufchain *ch, void *data, int len)
+bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len)
 {
     if (ch->buffersize >= len) {
         bufchain_fetch_consume(ch, data, len);
-        return TRUE;
+        return true;
     } else {
-        return FALSE;
+        return false;
     }
 }
 
@@ -1014,7 +991,7 @@ void debug_printf(const char *fmt, ...)
 }
 
 
-void debug_memdump(const void *buf, int len, int L)
+void debug_memdump(const void *buf, int len, bool L)
 {
     int i;
     const unsigned char *p = buf;
@@ -1055,7 +1032,7 @@ void debug_memdump(const void *buf, int len, int L)
  * Determine whether or not a Conf represents a session which can
  * sensibly be launched right now.
  */
-int conf_launchable(Conf *conf)
+bool conf_launchable(Conf *conf)
 {
     if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
 	return conf_get_str(conf, CONF_serline)[0] != 0;
@@ -1113,13 +1090,13 @@ void smemclr(void *b, size_t n) {
 
 /*
  * Validate a manual host key specification (either entered in the
- * GUI, or via -hostkey). If valid, we return TRUE, and update 'key'
+ * GUI, or via -hostkey). If valid, we return true, and update 'key'
  * to contain a canonicalised version of the key string in 'key'
  * (which is guaranteed to take up at most as much space as the
  * original version), suitable for putting into the Conf. If not
- * valid, we return FALSE.
+ * valid, we return false.
  */
-int validate_manual_hostkey(char *key)
+bool validate_manual_hostkey(char *key)
 {
     char *p, *q, *r, *s;
 
@@ -1154,7 +1131,7 @@ int validate_manual_hostkey(char *key)
             for (i = 0; i < 16*3 - 1; i++)
                 key[i] = tolower(q[i]);
             key[16*3 - 1] = '\0';
-            return TRUE;
+            return true;
         }
       not_fingerprint:;
 
@@ -1200,15 +1177,15 @@ int validate_manual_hostkey(char *key)
                 goto not_ssh2_blob;    /* sorry */
 
             strcpy(key, q);
-            return TRUE;
+            return true;
         }
       not_ssh2_blob:;
     }
 
-    return FALSE;
+    return false;
 }
 
-int smemeq(const void *av, const void *bv, size_t len)
+bool smemeq(const void *av, const void *bv, size_t len)
 {
     const unsigned char *a = (const unsigned char *)av;
     const unsigned char *b = (const unsigned char *)bv;
@@ -1235,36 +1212,18 @@ int nullstrcmp(const char *a, const char *b)
     return strcmp(a, b);
 }
 
-ptrlen make_ptrlen(const void *ptr, size_t len)
-{
-    ptrlen pl;
-    pl.ptr = ptr;
-    pl.len = len;
-    return pl;
-}
-
-ptrlen ptrlen_from_asciz(const char *str)
-{
-    return make_ptrlen(str, strlen(str));
-}
-
-ptrlen ptrlen_from_strbuf(strbuf *sb)
-{
-    return make_ptrlen(sb->u, sb->len);
-}
-
-int ptrlen_eq_string(ptrlen pl, const char *str)
+bool ptrlen_eq_string(ptrlen pl, const char *str)
 {
     size_t len = strlen(str);
     return (pl.len == len && !memcmp(pl.ptr, str, len));
 }
 
-int ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2)
+bool ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2)
 {
     return (pl1.len == pl2.len && !memcmp(pl1.ptr, pl2.ptr, pl1.len));
 }
 
-int ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail)
+bool ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail)
 {
     if (whole.len >= prefix.len &&
         !memcmp(whole.ptr, prefix.ptr, prefix.len)) {
@@ -1272,9 +1231,9 @@ int ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail)
             tail->ptr = (const char *)whole.ptr + prefix.len;
             tail->len = whole.len - prefix.len;
         }
-        return TRUE;
+        return true;
     }
-    return FALSE;
+    return false;
 }
 
 char *mkstr(ptrlen pl)
@@ -1285,12 +1244,12 @@ char *mkstr(ptrlen pl)
     return p;
 }
 
-int strstartswith(const char *s, const char *t)
+bool strstartswith(const char *s, const char *t)
 {
     return !memcmp(s, t, strlen(t));
 }
 
-int strendswith(const char *s, const char *t)
+bool strendswith(const char *s, const char *t)
 {
     size_t slen = strlen(s), tlen = strlen(t);
     return slen >= tlen && !strcmp(s + (slen - tlen), t);
@@ -1299,7 +1258,6 @@ int strendswith(const char *s, const char *t)
 char *buildinfo(const char *newline)
 {
     strbuf *buf = strbuf_new();
-    extern const char commitid[];      /* in commitid.c */
 
     strbuf_catf(buf, "Build platform: %d-bit %s",
                 (int)(CHAR_BIT * sizeof(void *)),
@@ -1390,8 +1348,8 @@ char *buildinfo(const char *newline)
 }
 
 int nullseat_output(
-    Seat *seat, int is_stderr, const void *data, int len) { return 0; }
-int nullseat_eof(Seat *seat) { return TRUE; }
+    Seat *seat, bool is_stderr, const void *data, int len) { return 0; }
+bool nullseat_eof(Seat *seat) { return true; }
 int nullseat_get_userpass_input(
     Seat *seat, prompts_t *p, bufchain *input) { return 0; }
 void nullseat_notify_remote_exit(Seat *seat) {}
@@ -1409,13 +1367,13 @@ int nullseat_confirm_weak_crypto_primitive(
 int nullseat_confirm_weak_cached_hostkey(
     Seat *seat, const char *algname, const char *betteralgs,
     void (*callback)(void *ctx, int result), void *ctx) { return 0; }
-int nullseat_is_never_utf8(Seat *seat) { return FALSE; }
-int nullseat_is_always_utf8(Seat *seat) { return TRUE; }
-void nullseat_echoedit_update(Seat *seat, int echoing, int editing) {}
+bool nullseat_is_never_utf8(Seat *seat) { return false; }
+bool nullseat_is_always_utf8(Seat *seat) { return true; }
+void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing) {}
 const char *nullseat_get_x_display(Seat *seat) { return NULL; }
-int nullseat_get_windowid(Seat *seat, long *id_out) { return FALSE; }
-int nullseat_get_window_pixel_size(
-    Seat *seat, int *width, int *height) { return FALSE; }
+bool nullseat_get_windowid(Seat *seat, long *id_out) { return false; }
+bool nullseat_get_window_pixel_size(
+    Seat *seat, int *width, int *height) { return false; }
 
 void sk_free_peer_info(SocketPeerInfo *pi)
 {

+ 103 - 25
source/putty/misc.h

@@ -12,6 +12,7 @@
 #include <stdio.h>		       /* for FILE * */
 #include <stdarg.h>		       /* for va_list */
 #include <time.h>                      /* for struct tm */
+#include <limits.h>                    /* for INT_MAX/MIN */
 
 unsigned long parse_blocksize(const char *bs);
 char ctrlparse(char *s, char **next);
@@ -57,12 +58,34 @@ void strbuf_finalise_agent_query(strbuf *buf);
 wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string, int len);
 wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string);
 
-int toint(unsigned);
+static inline int toint(unsigned u)
+{
+    /*
+     * Convert an unsigned to an int, without running into the
+     * undefined behaviour which happens by the strict C standard if
+     * the value overflows. You'd hope that sensible compilers would
+     * do the sensible thing in response to a cast, but actually I
+     * don't trust modern compilers not to do silly things like
+     * assuming that _obviously_ you wouldn't have caused an overflow
+     * and so they can elide an 'if (i < 0)' test immediately after
+     * the cast.
+     *
+     * Sensible compilers ought of course to optimise this entire
+     * function into 'just return the input value', and since it's
+     * also declared inline, elide it completely in their output.
+     */
+    if (u <= (unsigned)INT_MAX)
+        return (int)u;
+    else if (u >= (unsigned)INT_MIN)   /* wrap in cast _to_ unsigned is OK */
+        return INT_MIN + (int)(u - (unsigned)INT_MIN);
+    else
+        return INT_MIN; /* fallback; should never occur on binary machines */
+}
 
 char *fgetline(FILE *fp);
 char *chomp(char *str);
-int strstartswith(const char *s, const char *t);
-int strendswith(const char *s, const char *t);
+bool strstartswith(const char *s, const char *t);
+bool strendswith(const char *s, const char *t);
 
 void base64_encode_atom(const unsigned char *data, int n, char *out);
 int base64_decode_atom(const char *atom, unsigned char *out);
@@ -82,11 +105,11 @@ void bufchain_prefix(bufchain *ch, void **data, int *len);
 void bufchain_consume(bufchain *ch, int len);
 void bufchain_fetch(bufchain *ch, void *data, int len);
 void bufchain_fetch_consume(bufchain *ch, void *data, int len);
-int bufchain_try_fetch_consume(bufchain *ch, void *data, int len);
+bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len);
 
 void sanitise_term_data(bufchain *out, const void *vdata, int len);
 
-int validate_manual_hostkey(char *key);
+bool validate_manual_hostkey(char *key);
 
 struct tm ltime(void);
 
@@ -96,12 +119,27 @@ struct tm ltime(void);
  */
 int nullstrcmp(const char *a, const char *b);
 
-ptrlen make_ptrlen(const void *ptr, size_t len);
-ptrlen ptrlen_from_asciz(const char *str);
-ptrlen ptrlen_from_strbuf(strbuf *sb);
-int ptrlen_eq_string(ptrlen pl, const char *str);
-int ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2);
-int ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail);
+static inline ptrlen make_ptrlen(const void *ptr, size_t len)
+{
+    ptrlen pl;
+    pl.ptr = ptr;
+    pl.len = len;
+    return pl;
+}
+
+static inline ptrlen ptrlen_from_asciz(const char *str)
+{
+    return make_ptrlen(str, strlen(str));
+}
+
+static inline ptrlen ptrlen_from_strbuf(strbuf *sb)
+{
+    return make_ptrlen(sb->u, sb->len);
+}
+
+bool ptrlen_eq_string(ptrlen pl, const char *str);
+bool ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2);
+bool ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail);
 char *mkstr(ptrlen pl);
 int string_length_for_printf(size_t);
 /* Derive two printf arguments from a ptrlen, suitable for "%.*s" */
@@ -124,9 +162,9 @@ void smemclr(void *b, size_t len);
 /* Compare two fixed-length chunks of memory for equality, without
  * data-dependent control flow (so an attacker with a very accurate
  * stopwatch can't try to guess where the first mismatching byte was).
- * Returns 0 for mismatch or 1 for equality (unlike memcmp), hinted at
- * by the 'eq' in the name. */
-int smemeq(const void *av, const void *bv, size_t len);
+ * Returns false for mismatch or true for equality (unlike memcmp),
+ * hinted at by the 'eq' in the name. */
+bool smemeq(const void *av, const void *bv, size_t len);
 
 char *buildinfo(const char *newline);
 
@@ -145,10 +183,10 @@ char *buildinfo(const char *newline);
 
 #ifdef DEBUG
 void debug_printf(const char *fmt, ...);
-void debug_memdump(const void *buf, int len, int L);
+void debug_memdump(const void *buf, int len, bool L);
 #define debug(x) (debug_printf x)
-#define dmemdump(buf,len) debug_memdump (buf, len, 0);
-#define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
+#define dmemdump(buf,len) debug_memdump (buf, len, false);
+#define dmemdumpl(buf,len) debug_memdump (buf, len, true);
 #else
 #define debug(x)
 #define dmemdump(buf,len)
@@ -166,11 +204,31 @@ void debug_memdump(const void *buf, int len, int L);
 #define max(x,y) ( (x) > (y) ? (x) : (y) )
 #endif
 
+#define GET_64BIT_LSB_FIRST(cp) \
+  (((uint64_t)(unsigned char)(cp)[0]) | \
+  ((uint64_t)(unsigned char)(cp)[1] << 8) | \
+  ((uint64_t)(unsigned char)(cp)[2] << 16) | \
+  ((uint64_t)(unsigned char)(cp)[3] << 24) | \
+  ((uint64_t)(unsigned char)(cp)[4] << 32) | \
+  ((uint64_t)(unsigned char)(cp)[5] << 40) | \
+  ((uint64_t)(unsigned char)(cp)[6] << 48) | \
+  ((uint64_t)(unsigned char)(cp)[7] << 56))
+
+#define PUT_64BIT_LSB_FIRST(cp, value) ( \
+  (cp)[0] = (unsigned char)(value), \
+  (cp)[1] = (unsigned char)((value) >> 8), \
+  (cp)[2] = (unsigned char)((value) >> 16), \
+  (cp)[3] = (unsigned char)((value) >> 24), \
+  (cp)[4] = (unsigned char)((value) >> 32), \
+  (cp)[5] = (unsigned char)((value) >> 40), \
+  (cp)[6] = (unsigned char)((value) >> 48), \
+  (cp)[7] = (unsigned char)((value) >> 56) )
+
 #define GET_32BIT_LSB_FIRST(cp) \
-  (((unsigned long)(unsigned char)(cp)[0]) | \
-  ((unsigned long)(unsigned char)(cp)[1] << 8) | \
-  ((unsigned long)(unsigned char)(cp)[2] << 16) | \
-  ((unsigned long)(unsigned char)(cp)[3] << 24))
+  (((uint32_t)(unsigned char)(cp)[0]) | \
+  ((uint32_t)(unsigned char)(cp)[1] << 8) | \
+  ((uint32_t)(unsigned char)(cp)[2] << 16) | \
+  ((uint32_t)(unsigned char)(cp)[3] << 24))
 
 #define PUT_32BIT_LSB_FIRST(cp, value) ( \
   (cp)[0] = (unsigned char)(value), \
@@ -187,10 +245,10 @@ void debug_memdump(const void *buf, int len, int L);
   (cp)[1] = (unsigned char)((value) >> 8) )
 
 #define GET_32BIT_MSB_FIRST(cp) \
-  (((unsigned long)(unsigned char)(cp)[0] << 24) | \
-  ((unsigned long)(unsigned char)(cp)[1] << 16) | \
-  ((unsigned long)(unsigned char)(cp)[2] << 8) | \
-  ((unsigned long)(unsigned char)(cp)[3]))
+  (((uint32_t)(unsigned char)(cp)[0] << 24) | \
+  ((uint32_t)(unsigned char)(cp)[1] << 16) | \
+  ((uint32_t)(unsigned char)(cp)[2] << 8) | \
+  ((uint32_t)(unsigned char)(cp)[3]))
 
 #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
 
@@ -202,6 +260,26 @@ void debug_memdump(const void *buf, int len, int L);
 
 #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
 
+#define GET_64BIT_MSB_FIRST(cp) \
+  (((uint64_t)(unsigned char)(cp)[0] << 56) | \
+  ((uint64_t)(unsigned char)(cp)[1] << 48) | \
+  ((uint64_t)(unsigned char)(cp)[2] << 40) | \
+  ((uint64_t)(unsigned char)(cp)[3] << 32) | \
+  ((uint64_t)(unsigned char)(cp)[4] << 24) | \
+  ((uint64_t)(unsigned char)(cp)[5] << 16) | \
+  ((uint64_t)(unsigned char)(cp)[6] << 8) | \
+  ((uint64_t)(unsigned char)(cp)[7]))
+
+#define PUT_64BIT_MSB_FIRST(cp, value) ( \
+  (cp)[0] = (unsigned char)((value) >> 56), \
+  (cp)[1] = (unsigned char)((value) >> 48), \
+  (cp)[2] = (unsigned char)((value) >> 40), \
+  (cp)[3] = (unsigned char)((value) >> 32), \
+  (cp)[4] = (unsigned char)((value) >> 24), \
+  (cp)[5] = (unsigned char)((value) >> 16), \
+  (cp)[6] = (unsigned char)((value) >> 8), \
+  (cp)[7] = (unsigned char)(value) )
+
 #define GET_16BIT_MSB_FIRST(cp) \
   (((unsigned long)(unsigned char)(cp)[0] << 8) | \
   ((unsigned long)(unsigned char)(cp)[1]))

+ 17 - 17
source/putty/network.h

@@ -32,7 +32,7 @@ struct SocketVtable {
     int (*write_oob) (Socket *s, const void *data, int len);
     void (*write_eof) (Socket *s);
     void (*flush) (Socket *s);
-    void (*set_frozen) (Socket *s, int is_frozen);
+    void (*set_frozen) (Socket *s, bool is_frozen);
     /* ignored by tcp, but vital for ssl */
     const char *(*socket_error) (Socket *s);
     SocketPeerInfo *(*peer_info) (Socket *s);
@@ -66,7 +66,7 @@ struct PlugVtable {
      *    indicate this.
      */
     void (*closing)
-     (Plug *p, const char *error_msg, int error_code, int calling_back);
+     (Plug *p, const char *error_msg, int error_code, bool calling_back);
     /* error_msg is NULL iff it is not an error (ie it closed normally) */
     /* calling_back != 0 iff there is a Plug function */
     /* currently running (would cure the fixme in try_send()) */
@@ -100,22 +100,22 @@ struct PlugVtable {
 /* NB, control of 'addr' is passed via new_connection, which takes
  * responsibility for freeing it */
 Socket *new_connection(SockAddr *addr, const char *hostname,
-                       int port, int privport,
-                       int oobinline, int nodelay, int keepalive,
+                       int port, bool privport,
+                       bool oobinline, bool nodelay, bool keepalive,
                        Plug *plug, Conf *conf);
 Socket *new_listener(const char *srcaddr, int port, Plug *plug,
-                     int local_host_only, Conf *conf, int addressfamily);
+                     bool local_host_only, Conf *conf, int addressfamily);
 SockAddr *name_lookup(const char *host, int port, char **canonicalname,
                       Conf *conf, int addressfamily, LogContext *logctx,
                       const char *lookup_reason_for_logging);
-int proxy_for_destination (SockAddr *addr, const char *hostname, int port,
-                           Conf *conf);
+bool proxy_for_destination (SockAddr *addr, const char *hostname, int port,
+                            Conf *conf);
 
 /* platform-dependent callback from new_connection() */
 /* (same caveat about addr as new_connection()) */
 Socket *platform_new_connection(SockAddr *addr, const char *hostname,
-                                int port, int privport,
-                                int oobinline, int nodelay, int keepalive,
+                                int port, bool privport,
+                                bool oobinline, bool nodelay, bool keepalive,
                                 Plug *plug, Conf *conf);
 
 /* socket functions */
@@ -126,10 +126,10 @@ 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);
 void sk_getaddr(SockAddr *addr, char *buf, int buflen);
-int sk_addr_needs_port(SockAddr *addr);
-int sk_hostname_is_local(const char *name);
-int sk_address_is_local(SockAddr *addr);
-int sk_address_is_special_local(SockAddr *addr);
+bool sk_addr_needs_port(SockAddr *addr);
+bool sk_hostname_is_local(const char *name);
+bool sk_address_is_local(SockAddr *addr);
+bool sk_address_is_special_local(SockAddr *addr);
 int sk_addrtype(SockAddr *addr);
 void sk_addrcopy(SockAddr *addr, char *buf);
 void sk_addr_free(SockAddr *addr);
@@ -142,11 +142,11 @@ SockAddr *sk_addr_dup(SockAddr *addr);
 
 /* NB, control of 'addr' is passed via sk_new, which takes responsibility
  * for freeing it, as for new_connection() */
-Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
-               int nodelay, int keepalive, Plug *p);
+Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline,
+               bool nodelay, bool keepalive, Plug *p);
 
 Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
-                       int local_host_only, int address_family);
+                       bool local_host_only, int address_family);
 
 #define sk_plug(s,p) (((s)->vt->plug) (s, p))
 #define sk_close(s) (((s)->vt->close) (s))
@@ -278,7 +278,7 @@ extern Plug *const nullplug;
 void backend_socket_log(Seat *seat, LogContext *logctx,
                         int type, SockAddr *addr, int port,
                         const char *error_msg, int error_code, Conf *conf,
-                        int session_started);
+                        bool session_started);
 void log_proxy_stderr(Plug *plug, bufchain *buf, const void *vdata, int len);
 
 #endif

+ 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,
-			     int calling_back)
+			     bool calling_back)
 {
 }
 

+ 4 - 4
source/putty/pageant.h

@@ -60,10 +60,10 @@ struct RSAKey *pageant_nth_ssh1_key(int i);
 struct ssh2_userkey *pageant_nth_ssh2_key(int i);
 int pageant_count_ssh1_keys(void);
 int pageant_count_ssh2_keys(void);
-int pageant_add_ssh1_key(struct RSAKey *rkey);
-int pageant_add_ssh2_key(struct ssh2_userkey *skey);
-int pageant_delete_ssh1_key(struct RSAKey *rkey);
-int pageant_delete_ssh2_key(struct ssh2_userkey *skey);
+bool pageant_add_ssh1_key(struct RSAKey *rkey);
+bool pageant_add_ssh2_key(struct ssh2_userkey *skey);
+bool pageant_delete_ssh1_key(struct RSAKey *rkey);
+bool pageant_delete_ssh2_key(struct ssh2_userkey *skey);
 
 /*
  * This callback must be provided by the Pageant front end code.

+ 1 - 1
source/putty/pgssapi.h

@@ -24,7 +24,7 @@ typedef gss_OID const_gss_OID;	       /* for our prototypes below */
  ******************************************************************************/
 
 /* GSSAPI Type Definitions */
-typedef uint32 OM_uint32;
+typedef uint32_t OM_uint32;
 
 typedef struct gss_OID_desc_struct {
     OM_uint32 length;

+ 31 - 31
source/putty/portfwd.c

@@ -27,8 +27,8 @@ typedef struct PortForwarding {
     ConnectionLayer *cl;   /* the connection layer itself */
     /* Note that ssh need not be filled in if c is non-NULL */
     Socket *s;
-    int input_wanted;
-    int ready;
+    bool input_wanted;
+    bool ready;
     SocksState socks_state;
     /*
      * `hostname' and `port' are the real hostname and port, once
@@ -51,7 +51,7 @@ typedef struct PortForwarding {
 struct PortListener {
     ConnectionLayer *cl;
     Socket *s;
-    int is_dynamic;
+    bool is_dynamic;
     /*
      * `hostname' and `port' are the real hostname and port, for
      * ordinary forwardings.
@@ -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,
-			int 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,
-			int calling_back)
+			bool calling_back)
 {
     struct PortListener *pl = (struct PortListener *) plug;
     pfl_terminate(pl);
@@ -254,7 +254,7 @@ static void pfd_receive(Plug *plug, int urgent, char *data, int len)
                     return;
                 if (socks_version == 4 && message_type == 1) {
                     /* CONNECT message */
-                    int name_based = FALSE;
+                    bool name_based = false;
 
                     port = get_uint16(src);
                     ipv4 = get_uint32(src);
@@ -264,7 +264,7 @@ static void pfd_receive(Plug *plug, int urgent, char *data, int len)
                          * extension to specify a hostname, which comes
                          * after the username.
                          */
-                        name_based = TRUE;
+                        name_based = true;
                     }
                     get_asciz(src);        /* skip username */
                     socks4_hostname = name_based ? get_asciz(src) : NULL;
@@ -437,9 +437,9 @@ static const PlugVtable PortForwarding_plugvt = {
 static void pfd_chan_free(Channel *chan);
 static void pfd_open_confirmation(Channel *chan);
 static void pfd_open_failure(Channel *chan, const char *errtext);
-static int pfd_send(Channel *chan, int is_stderr, const void *data, int len);
+static int pfd_send(Channel *chan, bool is_stderr, const void *data, int len);
 static void pfd_send_eof(Channel *chan);
-static void pfd_set_input_wanted(Channel *chan, int wanted);
+static void pfd_set_input_wanted(Channel *chan, bool wanted);
 static char *pfd_log_close_msg(Channel *chan);
 
 static const struct ChannelVtable PortForwarding_channelvt = {
@@ -475,13 +475,13 @@ Channel *portfwd_raw_new(ConnectionLayer *cl, Plug **plug)
     pf->plug.vt = &PortForwarding_plugvt;
     pf->chan.initial_fixed_window_size = 0;
     pf->chan.vt = &PortForwarding_channelvt;
-    pf->input_wanted = TRUE;
+    pf->input_wanted = true;
 
     pf->c = NULL;
 
     pf->cl = cl;
-    pf->input_wanted = TRUE;
-    pf->ready = 0;
+    pf->input_wanted = true;
+    pf->ready = false;
 
     pf->socks_state = SOCKS_NONE;
     pf->hostname = NULL;
@@ -526,7 +526,7 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
     s = constructor(ctx, plug);
     if ((err = sk_socket_error(s)) != NULL) {
 	portfwd_raw_free(chan);
-	return TRUE;
+	return 1;
     }
 
     pf = container_of(chan, struct PortForwarding, chan);
@@ -581,13 +581,13 @@ static char *pfl_listen(const char *desthost, int destport,
     if (desthost) {
 	pl->hostname = dupstr(desthost);
 	pl->port = destport;
-	pl->is_dynamic = FALSE;
+	pl->is_dynamic = false;
     } else
-	pl->is_dynamic = TRUE;
+	pl->is_dynamic = true;
     pl->cl = cl;
 
     pl->s = new_listener(srcaddr, port, &pl->plug,
-                         !conf_get_int(conf, CONF_lport_acceptall),
+                         !conf_get_bool(conf, CONF_lport_acceptall),
                          conf, address_family);
     if ((err = sk_socket_error(pl->s)) != NULL) {
         char *err_ret = dupstr(err);
@@ -626,7 +626,7 @@ static void pfl_terminate(struct PortListener *pl)
     free_portlistener_state(pl);
 }
 
-static void pfd_set_input_wanted(Channel *chan, int wanted)
+static void pfd_set_input_wanted(Channel *chan, bool wanted)
 {
     assert(chan->vt == &PortForwarding_channelvt);
     PortForwarding *pf = container_of(chan, PortForwarding, chan);
@@ -644,7 +644,7 @@ static void pfd_chan_free(Channel *chan)
 /*
  * Called to send data down the raw connection.
  */
-static int pfd_send(Channel *chan, int is_stderr, const void *data, int len)
+static int pfd_send(Channel *chan, bool is_stderr, const void *data, int len)
 {
     assert(chan->vt == &PortForwarding_channelvt);
     PortForwarding *pf = container_of(chan, PortForwarding, chan);
@@ -663,7 +663,7 @@ static void pfd_open_confirmation(Channel *chan)
     assert(chan->vt == &PortForwarding_channelvt);
     PortForwarding *pf = container_of(chan, PortForwarding, chan);
 
-    pf->ready = 1;
+    pf->ready = true;
     sk_set_frozen(pf->s, 0);
     sk_write(pf->s, NULL, 0);
     if (pf->socksbuf) {
@@ -1024,7 +1024,7 @@ void portfwdmgr_config(PortFwdManager *mgr, Conf *conf)
 
                 if (pfr->saddr) {
                     shost = pfr->saddr;
-                } else if (conf_get_int(conf, CONF_rport_acceptall)) {
+                } else if (conf_get_bool(conf, CONF_rport_acceptall)) {
                     shost = "";
                 } else {
                     shost = "localhost";
@@ -1050,8 +1050,8 @@ void portfwdmgr_config(PortFwdManager *mgr, Conf *conf)
     }
 }
 
-int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
-                      const char *keyhost, int keyport, Conf *conf)
+bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
+                       const char *keyhost, int keyport, Conf *conf)
 {
     PortFwdRecord *pfr;
 
@@ -1072,7 +1072,7 @@ int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
          * We had this record already. Return failure.
          */
         pfr_free(pfr);
-        return FALSE;
+        return false;
     }
 
     char *err = pfl_listen(keyhost, keyport, host, port,
@@ -1085,13 +1085,13 @@ int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
         sfree(err);
         del234(mgr->forwardings, pfr);
         pfr_free(pfr);
-        return FALSE;
+        return false;
     }
 
-    return TRUE;
+    return true;
 }
 
-int portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port)
+bool portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port)
 {
     PortFwdRecord pfr_key;
 
@@ -1108,12 +1108,12 @@ int portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port)
     PortFwdRecord *pfr = del234(mgr->forwardings, &pfr_key);
 
     if (!pfr)
-        return FALSE;
+        return false;
 
     logeventf(mgr->cl->logctx, "Closing listening port %s:%d", host, port);
 
     pfr_free(pfr);
-    return TRUE;
+    return true;
 }
 
 /*
@@ -1152,14 +1152,14 @@ char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret,
     pf->plug.vt = &PortForwarding_plugvt;
     pf->chan.initial_fixed_window_size = 0;
     pf->chan.vt = &PortForwarding_channelvt;
-    pf->input_wanted = TRUE;
-    pf->ready = 1;
+    pf->input_wanted = true;
+    pf->ready = true;
     pf->c = c;
     pf->cl = mgr->cl;
     pf->socks_state = SOCKS_NONE;
 
     pf->s = new_connection(addr, dummy_realhost, port,
-                           0, 1, 0, 0, &pf->plug, mgr->conf);
+                           false, true, false, false, &pf->plug, mgr->conf);
     sfree(dummy_realhost);
     if ((err = sk_socket_error(pf->s)) != NULL) {
         char *err_ret = dupstr(err);

+ 29 - 27
source/putty/proxy.c

@@ -33,7 +33,7 @@ void proxy_activate (ProxySocket *p)
     /* we want to ignore new receive events until we have sent
      * all of our buffered receive data.
      */
-    sk_set_frozen(p->sub_socket, 1);
+    sk_set_frozen(p->sub_socket, true);
 
     /* how many bytes of output have we buffered? */
     output_before = bufchain_size(&p->pending_oob_output_data) +
@@ -124,7 +124,7 @@ static void sk_proxy_write_eof (Socket *s)
     ProxySocket *ps = container_of(s, ProxySocket, sock);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
-        ps->pending_eof = 1;
+        ps->pending_eof = true;
 	return;
     }
     sk_write_eof(ps->sub_socket);
@@ -135,13 +135,13 @@ static void sk_proxy_flush (Socket *s)
     ProxySocket *ps = container_of(s, ProxySocket, sock);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
-	ps->pending_flush = 1;
+	ps->pending_flush = true;
 	return;
     }
     sk_flush(ps->sub_socket);
 }
 
-static void sk_proxy_set_frozen (Socket *s, int is_frozen)
+static void sk_proxy_set_frozen (Socket *s, bool is_frozen)
 {
     ProxySocket *ps = container_of(s, ProxySocket, sock);
 
@@ -200,7 +200,7 @@ static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port,
 }
 
 static void plug_proxy_closing (Plug *p, const char *error_msg,
-				int error_code, int calling_back)
+				int error_code, bool calling_back)
 {
     ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
 
@@ -224,7 +224,7 @@ static void plug_proxy_receive (Plug *p, int urgent, char *data, int len)
 	 * process, hopefully it won't affect the protocol above us
 	 */
 	bufchain_add(&ps->pending_input_data, data, len);
-	ps->receive_urgent = urgent;
+	ps->receive_urgent = (urgent != 0);
 	ps->receive_data = data;
 	ps->receive_len = len;
 	ps->negotiate(ps, PROXY_CHANGE_RECEIVE);
@@ -262,7 +262,7 @@ static int plug_proxy_accepting(Plug *p,
  * This function can accept a NULL pointer as `addr', in which case
  * it will only check the host name.
  */
-int proxy_for_destination (SockAddr *addr, const char *hostname,
+bool proxy_for_destination (SockAddr *addr, const char *hostname,
                            int port, Conf *conf)
 {
     int s = 0, e = 0;
@@ -277,16 +277,16 @@ int proxy_for_destination (SockAddr *addr, const char *hostname,
      * them.
      */
     if (addr && sk_address_is_special_local(addr))
-        return 0;                      /* do not proxy */
+        return false;                  /* do not proxy */
 
     /*
      * Check the host name and IP against the hard-coded
      * representations of `localhost'.
      */
-    if (!conf_get_int(conf, CONF_even_proxy_localhost) &&
+    if (!conf_get_bool(conf, CONF_even_proxy_localhost) &&
 	(sk_hostname_is_local(hostname) ||
 	 (addr && sk_address_is_local(addr))))
-	return 0;		       /* do not proxy */
+	return false;                  /* do not proxy */
 
     /* we want a string representation of the IP address for comparisons */
     if (addr) {
@@ -324,25 +324,27 @@ int proxy_for_destination (SockAddr *addr, const char *hostname,
 	    if ((addr && strnicmp(hostip + hostip_len - (e - s - 1),
 				  exclude_list + s + 1, e - s - 1) == 0) ||
 		strnicmp(hostname + hostname_len - (e - s - 1),
-			 exclude_list + s + 1, e - s - 1) == 0)
-		return 0; /* IP/hostname range excluded. do not use proxy. */
-
+                         exclude_list + s + 1, e - s - 1) == 0) {
+                /* IP/hostname range excluded. do not use proxy. */
+                return false;
+            }
 	} else if (exclude_list[e-1] == '*') {
 	    /* wildcard at end of entry */
 
 	    if ((addr && strnicmp(hostip, exclude_list + s, e - s - 1) == 0) ||
-		strnicmp(hostname, exclude_list + s, e - s - 1) == 0)
-		return 0; /* IP/hostname range excluded. do not use proxy. */
-
+                strnicmp(hostname, exclude_list + s, e - s - 1) == 0) {
+                /* IP/hostname range excluded. do not use proxy. */
+                return false;
+            }
 	} else {
 	    /* no wildcard at either end, so let's try an absolute
 	     * match (ie. a specific IP)
 	     */
 
 	    if (addr && strnicmp(hostip, exclude_list + s, e - s) == 0)
-		return 0; /* IP/hostname excluded. do not use proxy. */
+		return false; /* IP/hostname excluded. do not use proxy. */
 	    if (strnicmp(hostname, exclude_list + s, e - s) == 0)
-		return 0; /* IP/hostname excluded. do not use proxy. */
+		return false; /* IP/hostname excluded. do not use proxy. */
 	}
 
 	s = e;
@@ -354,7 +356,7 @@ int proxy_for_destination (SockAddr *addr, const char *hostname,
     }
 
     /* no matches in the exclude list, so use the proxy */
-    return 1;
+    return true;
 }
 
 static char *dns_log_msg(const char *host, int addressfamily,
@@ -410,8 +412,8 @@ static const struct PlugVtable ProxySocket_plugvt = {
 };
 
 Socket *new_connection(SockAddr *addr, const char *hostname,
-                       int port, int privport,
-                       int oobinline, int nodelay, int keepalive,
+                       int port, bool privport,
+                       bool oobinline, bool nodelay, bool keepalive,
                        Plug *plug, Conf *conf)
 {
     if (conf_get_int(conf, CONF_proxy_type) != PROXY_NONE &&
@@ -439,9 +441,9 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
 	ret->remote_port = port;
 
 	ret->error = NULL;
-	ret->pending_flush = 0;
-	ret->pending_eof = 0;
-	ret->freeze = 0;
+	ret->pending_flush = false;
+	ret->pending_eof = false;
+	ret->freeze = false;
 
 	bufchain_init(&ret->pending_input_data);
 	bufchain_init(&ret->pending_output_data);
@@ -530,7 +532,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
 }
 
 Socket *new_listener(const char *srcaddr, int port, Plug *plug,
-                     int local_host_only, Conf *conf, int addressfamily)
+                     bool local_host_only, Conf *conf, int addressfamily)
 {
     /* TODO: SOCKS (and potentially others) support inbound
      * TODO: connections via the proxy. support them.
@@ -778,7 +780,7 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
 
         strbuf *command = strbuf_new();
         char hostname[512];
-        int write_hostname = FALSE;
+        bool write_hostname = false;
 
         put_byte(command, 4);          /* SOCKS version 4 */
         put_byte(command, 1);          /* CONNECT command */
@@ -795,7 +797,7 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
           case ADDRTYPE_NAME:
             sk_getaddr(p->remote_addr, hostname, lenof(hostname));
             put_uint32(command, 1);
-            write_hostname = TRUE;
+            write_hostname = true;
             break;
           case ADDRTYPE_IPV6:
             p->error = "Proxy error: SOCKS version 4 does not support IPv6";

+ 8 - 8
source/putty/proxy.h

@@ -25,9 +25,9 @@ struct ProxySocket {
 
     bufchain pending_output_data;
     bufchain pending_oob_output_data;
-    int pending_flush;
+    bool pending_flush;
     bufchain pending_input_data;
-    int pending_eof;
+    bool pending_eof;
 
 #define PROXY_STATE_NEW    -1
 #define PROXY_STATE_ACTIVE  0
@@ -37,10 +37,10 @@ struct ProxySocket {
 		* of the initialization/setup/negotiation with the
 		* proxy server.
 		*/
-    int 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.
-		 */
+    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.
+                  */
 
 #define PROXY_CHANGE_NEW      -1
 #define PROXY_CHANGE_CLOSING   0
@@ -64,10 +64,10 @@ struct ProxySocket {
     /* closing */
     const char *closing_error_msg;
     int closing_error_code;
-    int closing_calling_back;
+    bool closing_calling_back;
 
     /* receive */
-    int receive_urgent;
+    bool receive_urgent;
     char *receive_data;
     int receive_len;
 

+ 213 - 204
source/putty/putty.h

@@ -153,7 +153,7 @@ struct sesslist {
 
 struct unicode_data {
     char **uni_tbl;
-    int dbcs_screenfont;
+    bool dbcs_screenfont;
     int font_codepage;
     int line_codepage;
     wchar_t unitab_scoacs[256];
@@ -497,7 +497,7 @@ struct BackendVtable {
     const char *(*init) (Seat *seat, Backend **backend_out,
                          LogContext *logctx, Conf *conf,
                          const char *host, int port,
-                         char **realhost, int nodelay, int keepalive);
+                         char **realhost, bool nodelay, bool keepalive);
 
     void (*free) (Backend *be);
     /* Pass in a replacement configuration. */
@@ -509,13 +509,13 @@ struct BackendVtable {
     void (*size) (Backend *be, int width, int height);
     void (*special) (Backend *be, SessionSpecialCode code, int arg);
     const SessionSpecial *(*get_specials) (Backend *be);
-    int (*connected) (Backend *be);
+    bool (*connected) (Backend *be);
     int (*exitcode) (Backend *be);
-    /* If back->sendok() returns FALSE, the backend doesn't currently
+    /* If back->sendok() returns false, the backend doesn't currently
      * want input data, so the frontend should avoid acquiring any if
      * possible (passing back-pressure on to its sender). */
-    int (*sendok) (Backend *be);
-    int (*ldisc_option_state) (Backend *be, int);
+    bool (*sendok) (Backend *be);
+    bool (*ldisc_option_state) (Backend *be, int);
     void (*provide_ldisc) (Backend *be, Ldisc *ldisc);
     /* Tells the back end that the front end  buffer is clearing. */
     void (*unthrottle) (Backend *be, int bufsize);
@@ -523,7 +523,7 @@ struct BackendVtable {
 
     /* Only implemented in the SSH protocol: check whether a
      * connection-sharing upstream exists for a given configuration. */
-    int (*test_for_upstream)(const char *host, int port, Conf *conf);
+    bool (*test_for_upstream)(const char *host, int port, Conf *conf);
 
     const char *name;
     int protocol;
@@ -593,9 +593,9 @@ GLOBAL int default_protocol;
 GLOBAL int default_port;
 
 /*
- * This is set TRUE by cmdline.c iff a session is loaded with "-load".
+ * This is set true by cmdline.c iff a session is loaded with "-load".
  */
-GLOBAL int loaded_session;
+GLOBAL bool loaded_session;
 /*
  * This is set to the name of the loaded session.
  */
@@ -619,7 +619,7 @@ GLOBAL char *cmdline_session_name;
  */
 typedef struct {
     char *prompt;
-    int echo;
+    bool echo;
     /*
      * 'result' must be a dynamically allocated array of exactly
      * 'resultsize' chars. The code for actually reading input may
@@ -642,11 +642,11 @@ typedef struct {
      * information (so the caller should ensure that the supplied text is
      * sufficient).
      */
-    int to_server;
+    bool to_server;
     char *name;		/* Short description, perhaps for dialog box title */
-    int name_reqd;	/* Display of `name' required or optional? */
+    bool name_reqd;     /* Display of `name' required or optional? */
     char *instruction;	/* Long description, maybe with embedded newlines */
-    int instr_reqd;	/* Display of `instruction' required or optional? */
+    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) */
     prompt_t **prompts;
@@ -654,7 +654,7 @@ typedef struct {
 			 * seat_get_userpass_input(); initially NULL */
 } prompts_t;
 prompts_t *new_prompts();
-void add_prompt(prompts_t *p, char *promptstr, int echo);
+void add_prompt(prompts_t *p, char *promptstr, bool echo);
 void prompt_set_result(prompt_t *pr, const char *newstr);
 void prompt_ensure_result_size(prompt_t *pr, int len);
 /* Burn the evidence. (Assumes _all_ strings want free()ing.) */
@@ -668,7 +668,7 @@ void free_prompts(prompts_t *p);
  * background.
  */
 typedef struct optionalrgb {
-    unsigned char enabled;
+    bool enabled;
     unsigned char r, g, b;
 } optionalrgb;
 extern const optionalrgb optionalrgb_none;
@@ -742,15 +742,15 @@ struct SeatVtable {
      *
      * The return value is the current size of the output backlog.
      */
-    int (*output)(Seat *seat, int is_stderr, const void *data, int len);
+    int (*output)(Seat *seat, bool is_stderr, const void *data, int len);
 
     /*
      * Called when the back end wants to indicate that EOF has arrived
-     * on the server-to-client stream. Returns FALSE to indicate that
+     * on the server-to-client stream. Returns false to indicate that
      * we intend to keep the session open in the other direction, or
-     * TRUE to indicate that if they're closing so are we.
+     * true to indicate that if they're closing so are we.
      */
-    int (*eof)(Seat *seat);
+    bool (*eof)(Seat *seat);
 
     /*
      * Try to get answers from a set of interactive login prompts. The
@@ -884,14 +884,14 @@ struct SeatVtable {
      * user in the UTF-8 character set. (Affects e.g. visual erase
      * handling in local line editing.)
      */
-    int (*is_utf8)(Seat *seat);
+    bool (*is_utf8)(Seat *seat);
 
     /*
      * Notify the seat that the back end, and/or the ldisc between
      * them, have changed their idea of whether they currently want
      * local echo and/or local line editing enabled.
      */
-    void (*echoedit_update)(Seat *seat, int echoing, int editing);
+    void (*echoedit_update)(Seat *seat, bool echoing, bool editing);
 
     /*
      * Return the local X display string relevant to a seat, or NULL
@@ -901,18 +901,18 @@ struct SeatVtable {
 
     /*
      * Return the X11 id of the X terminal window relevant to a seat,
-     * by returning TRUE and filling in the output pointer. Return
-     * FALSE if there isn't one or if the concept is meaningless.
+     * by returning true and filling in the output pointer. Return
+     * false if there isn't one or if the concept is meaningless.
      */
-    int (*get_windowid)(Seat *seat, long *id_out);
+    bool (*get_windowid)(Seat *seat, long *id_out);
 
     /*
      * Return the size of the terminal window in pixels. If the
      * concept is meaningless or the information is unavailable,
-     * return FALSE; otherwise fill in the output pointers and return
-     * TRUE.
+     * return false; otherwise fill in the output pointers and return
+     * true.
      */
-    int (*get_window_pixel_size)(Seat *seat, int *width, int *height);
+    bool (*get_window_pixel_size)(Seat *seat, int *width, int *height);
 };
 
 #define seat_output(seat, is_stderr, data, len) \
@@ -953,9 +953,9 @@ void seat_connection_fatal(Seat *seat, const char *fmt, ...);
 
 /* Handy aliases for seat_output which set is_stderr to a fixed value. */
 #define seat_stdout(seat, data, len) \
-    seat_output(seat, FALSE, data, len)
+    seat_output(seat, false, data, len)
 #define seat_stderr(seat, data, len) \
-    seat_output(seat, TRUE, data, len)
+    seat_output(seat, true, data, len)
 
 /*
  * Stub methods for seat implementations that want to use the obvious
@@ -964,8 +964,8 @@ void seat_connection_fatal(Seat *seat, const char *fmt, ...);
  * These are generally obvious, except for is_utf8, where you might
  * plausibly want to return either fixed answer 'no' or 'yes'.
  */
-int nullseat_output(Seat *seat, int is_stderr, const void *data, int len);
-int nullseat_eof(Seat *seat);
+int nullseat_output(Seat *seat, bool is_stderr, const void *data, int len);
+bool nullseat_eof(Seat *seat);
 int nullseat_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input);
 void nullseat_notify_remote_exit(Seat *seat);
 void nullseat_connection_fatal(Seat *seat, const char *message);
@@ -982,12 +982,12 @@ int nullseat_confirm_weak_crypto_primitive(
 int nullseat_confirm_weak_cached_hostkey(
     Seat *seat, const char *algname, const char *betteralgs,
     void (*callback)(void *ctx, int result), void *ctx);
-int nullseat_is_never_utf8(Seat *seat);
-int nullseat_is_always_utf8(Seat *seat);
-void nullseat_echoedit_update(Seat *seat, int echoing, int editing);
+bool nullseat_is_never_utf8(Seat *seat);
+bool nullseat_is_always_utf8(Seat *seat);
+void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing);
 const char *nullseat_get_x_display(Seat *seat);
-int nullseat_get_windowid(Seat *seat, long *id_out);
-int nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
+bool nullseat_get_windowid(Seat *seat, long *id_out);
+bool nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
 
 /*
  * Seat functions provided by the platform's console-application
@@ -1029,7 +1029,7 @@ struct TermWinVtable {
      * of TermWin handles it by loading the currently configured font
      * into the HDC and doing a GDI query.)
      */
-    int (*setup_draw_ctx)(TermWin *);
+    bool (*setup_draw_ctx)(TermWin *);
     /* Draw text in the window, during a painting operation */
     void (*draw_text)(TermWin *, int x, int y, wchar_t *text, int len,
                       unsigned long attrs, int line_attrs, truecolour tc);
@@ -1045,14 +1045,14 @@ struct TermWinVtable {
 
     void (*set_cursor_pos)(TermWin *, int x, int y);
 
-    void (*set_raw_mouse_mode)(TermWin *, int enable);
+    void (*set_raw_mouse_mode)(TermWin *, bool enable);
 
     void (*set_scrollbar)(TermWin *, int total, int start, int page);
 
     void (*bell)(TermWin *, int mode);
 
     void (*clip_write)(TermWin *, int clipboard, wchar_t *text, int *attrs,
-                       truecolour *colours, int len, int must_deselect);
+                       truecolour *colours, int len, bool must_deselect);
     void (*clip_request_paste)(TermWin *, int clipboard);
 
     void (*refresh)(TermWin *);
@@ -1066,20 +1066,20 @@ struct TermWinVtable {
      * {min,normal,max} switch. The idea is that when you un-minimise
      * the window it remembers whether to go back to normal or
      * maximised. */
-    void (*set_minimised)(TermWin *, int minimised);
-    int (*is_minimised)(TermWin *);
-    void (*set_maximised)(TermWin *, int maximised);
+    void (*set_minimised)(TermWin *, bool minimised);
+    bool (*is_minimised)(TermWin *);
+    void (*set_maximised)(TermWin *, bool maximised);
     void (*move)(TermWin *, int x, int y);
-    void (*set_zorder)(TermWin *, int top);
+    void (*set_zorder)(TermWin *, bool top);
 
-    int (*palette_get)(TermWin *, int n, int *r, int *g, int *b);
+    bool (*palette_get)(TermWin *, int n, int *r, int *g, int *b);
     void (*palette_set)(TermWin *, int n, int r, int g, int b);
     void (*palette_reset)(TermWin *);
 
     void (*get_pos)(TermWin *, int *x, int *y);
     void (*get_pixels)(TermWin *, int *x, int *y);
-    const char *(*get_title)(TermWin *, int icon);
-    int (*is_utf8)(TermWin *);
+    const char *(*get_title)(TermWin *, bool icon);
+    bool (*is_utf8)(TermWin *);
 };
 
 #define win_setup_draw_ctx(win) \
@@ -1155,37 +1155,37 @@ void cleanup_exit(int);
     /* X(value-type, subkey-type, keyword) */ \
     X(STR, NONE, host) \
     X(INT, NONE, port) \
-    X(INT, NONE, protocol) \
-    X(INT, NONE, addressfamily) \
-    X(INT, NONE, close_on_exit) \
-    X(INT, NONE, warn_on_close) \
+    X(INT, NONE, protocol) /* PROT_SSH, PROT_TELNET etc */ \
+    X(INT, NONE, addressfamily) /* ADDRTYPE_IPV[46] or ADDRTYPE_UNSPEC */ \
+    X(INT, NONE, close_on_exit) /* FORCE_ON, FORCE_OFF, AUTO */ \
+    X(BOOL, NONE, warn_on_close) \
     X(INT, NONE, ping_interval) /* in seconds */ \
-    X(INT, NONE, tcp_nodelay) \
-    X(INT, NONE, tcp_keepalives) \
+    X(BOOL, NONE, tcp_nodelay) \
+    X(BOOL, NONE, tcp_keepalives) \
     X(STR, NONE, loghost) /* logical host being contacted, for host key check */ \
     /* Proxy options */ \
     X(STR, NONE, proxy_exclude_list) \
-    X(INT, NONE, proxy_dns) \
-    X(INT, NONE, even_proxy_localhost) \
-    X(INT, NONE, proxy_type) \
+    X(INT, NONE, proxy_dns) /* FORCE_ON, FORCE_OFF, AUTO */ \
+    X(BOOL, NONE, even_proxy_localhost) \
+    X(INT, NONE, proxy_type) /* PROXY_NONE, PROXY_SOCKS4, ... */ \
     X(STR, NONE, proxy_host) \
     X(INT, NONE, proxy_port) \
     X(STR, NONE, proxy_username) \
     X(STR, NONE, proxy_password) \
     X(STR, NONE, proxy_telnet_command) \
-    X(INT, NONE, proxy_log_to_term) \
+    X(INT, NONE, proxy_log_to_term) /* FORCE_ON, FORCE_OFF, AUTO */ \
     /* SSH options */ \
     X(STR, NONE, remote_cmd) \
     X(STR, NONE, remote_cmd2) /* fallback if remote_cmd fails; never loaded or saved */ \
-    X(INT, NONE, nopty) \
-    X(INT, NONE, compression) \
+    X(BOOL, NONE, nopty) \
+    X(BOOL, NONE, compression) \
     X(INT, INT, ssh_kexlist) \
     X(INT, INT, ssh_hklist) \
     X(INT, NONE, ssh_rekey_time) /* in minutes */ \
     X(STR, NONE, ssh_rekey_data) /* string encoding e.g. "100K", "2M", "1G" */ \
-    X(INT, NONE, tryagent) \
-    X(INT, NONE, agentfwd) \
-    X(INT, NONE, change_username) /* allow username switching in SSH-2 */ \
+    X(BOOL, NONE, tryagent) \
+    X(BOOL, NONE, agentfwd) \
+    X(BOOL, NONE, change_username) /* allow username switching in SSH-2 */ \
     X(INT, INT, ssh_cipherlist) \
     X(FILENAME, NONE, keyfile) \
     /* \
@@ -1202,20 +1202,20 @@ void cleanup_exit(int);
      * downgrades PuTTY. So it's easier to use these numbers internally too. \
      */ \
     X(INT, NONE, sshprot) \
-    X(INT, NONE, ssh2_des_cbc) /* "des-cbc" unrecommended SSH-2 cipher */ \
-    X(INT, NONE, ssh_no_userauth) /* bypass "ssh-userauth" (SSH-2 only) */ \
-    X(INT, NONE, ssh_show_banner) /* show USERAUTH_BANNERs (SSH-2 only) */ \
-    X(INT, NONE, try_tis_auth) \
-    X(INT, NONE, try_ki_auth) \
-    X(INT, NONE, try_gssapi_auth) /* attempt gssapi auth via ssh userauth */ \
-    X(INT, NONE, try_gssapi_kex) /* attempt gssapi auth via ssh kex */ \
-    X(INT, NONE, gssapifwd) /* forward tgt via gss */ \
+    X(BOOL, NONE, ssh2_des_cbc) /* "des-cbc" unrecommended SSH-2 cipher */ \
+    X(BOOL, NONE, ssh_no_userauth) /* bypass "ssh-userauth" (SSH-2 only) */ \
+    X(BOOL, NONE, ssh_show_banner) /* show USERAUTH_BANNERs (SSH-2 only) */ \
+    X(BOOL, NONE, try_tis_auth) \
+    X(BOOL, NONE, try_ki_auth) \
+    X(BOOL, NONE, try_gssapi_auth) /* attempt gssapi auth via ssh userauth */ \
+    X(BOOL, NONE, try_gssapi_kex) /* attempt gssapi auth via ssh kex */ \
+    X(BOOL, NONE, gssapifwd) /* forward tgt via gss */ \
     X(INT, NONE, gssapirekey) /* KEXGSS refresh interval (mins) */ \
     X(INT, INT, ssh_gsslist) /* preference order for local GSS libs */ \
     X(FILENAME, NONE, ssh_gss_custom) \
-    X(INT, NONE, ssh_subsys) /* run a subsystem rather than a command */ \
-    X(INT, NONE, ssh_subsys2) /* fallback to go with remote_cmd_ptr2 */ \
-    X(INT, NONE, ssh_no_shell) /* avoid running a shell */ \
+    X(BOOL, NONE, ssh_subsys) /* run a subsystem rather than a command */ \
+    X(BOOL, NONE, ssh_subsys2) /* fallback to go with remote_cmd_ptr2 */ \
+    X(BOOL, NONE, ssh_no_shell) /* avoid running a shell */ \
     X(STR, NONE, ssh_nc_host) /* host to connect to in `nc' mode */ \
     X(INT, NONE, ssh_nc_port) /* port to connect to in `nc' mode */ \
     /* Telnet options */ \
@@ -1224,127 +1224,128 @@ void cleanup_exit(int);
     X(STR, STR, ttymodes) /* values are "Vvalue" or "A" */ \
     X(STR, STR, environmt) \
     X(STR, NONE, username) \
-    X(INT, NONE, username_from_env) \
+    X(BOOL, NONE, username_from_env) \
     X(STR, NONE, localusername) \
-    X(INT, NONE, rfc_environ) \
-    X(INT, NONE, passive_telnet) \
+    X(BOOL, NONE, rfc_environ) \
+    X(BOOL, NONE, passive_telnet) \
     /* Serial port options */ \
     X(STR, NONE, serline) \
     X(INT, NONE, serspeed) \
     X(INT, NONE, serdatabits) \
     X(INT, NONE, serstopbits) \
-    X(INT, NONE, serparity) \
-    X(INT, NONE, serflow) \
+    X(INT, NONE, serparity) /* SER_PAR_NONE, SER_PAR_ODD, ... */ \
+    X(INT, NONE, serflow) /* SER_FLOW_NONE, SER_FLOW_XONXOFF, ... */ \
     /* Keyboard options */ \
-    X(INT, NONE, bksp_is_delete) \
-    X(INT, NONE, rxvt_homeend) \
-    X(INT, NONE, funky_type) \
-    X(INT, NONE, no_applic_c) /* totally disable app cursor keys */ \
-    X(INT, NONE, no_applic_k) /* totally disable app keypad */ \
-    X(INT, NONE, no_mouse_rep) /* totally disable mouse reporting */ \
-    X(INT, NONE, no_remote_resize) /* disable remote resizing */ \
-    X(INT, NONE, no_alt_screen) /* disable alternate screen */ \
-    X(INT, NONE, no_remote_wintitle) /* disable remote retitling */ \
-    X(INT, NONE, no_remote_clearscroll) /* disable ESC[3J */ \
-    X(INT, NONE, no_dbackspace) /* disable destructive backspace */ \
-    X(INT, NONE, no_remote_charset) /* disable remote charset config */ \
-    X(INT, NONE, remote_qtitle_action) /* remote win title query action */ \
-    X(INT, NONE, app_cursor) \
-    X(INT, NONE, app_keypad) \
-    X(INT, NONE, nethack_keypad) \
-    X(INT, NONE, telnet_keyboard) \
-    X(INT, NONE, telnet_newline) \
-    X(INT, NONE, alt_f4) /* is it special? */ \
-    X(INT, NONE, alt_space) /* is it special? */ \
-    X(INT, NONE, alt_only) /* is it special? */ \
-    X(INT, NONE, localecho) \
-    X(INT, NONE, localedit) \
-    X(INT, NONE, alwaysontop) \
-    X(INT, NONE, fullscreenonaltenter) \
-    X(INT, NONE, scroll_on_key) \
-    X(INT, NONE, scroll_on_disp) \
-    X(INT, NONE, erase_to_scrollback) \
-    X(INT, NONE, compose_key) \
-    X(INT, NONE, ctrlaltkeys) \
-    X(INT, NONE, osx_option_meta) \
-    X(INT, NONE, osx_command_meta) \
+    X(BOOL, NONE, bksp_is_delete) \
+    X(BOOL, NONE, rxvt_homeend) \
+    X(INT, NONE, funky_type) /* FUNKY_XTERM, FUNKY_LINUX, ... */ \
+    X(BOOL, NONE, no_applic_c) /* totally disable app cursor keys */ \
+    X(BOOL, NONE, no_applic_k) /* totally disable app keypad */ \
+    X(BOOL, NONE, no_mouse_rep) /* totally disable mouse reporting */ \
+    X(BOOL, NONE, no_remote_resize) /* disable remote resizing */ \
+    X(BOOL, NONE, no_alt_screen) /* disable alternate screen */ \
+    X(BOOL, NONE, no_remote_wintitle) /* disable remote retitling */ \
+    X(BOOL, NONE, no_remote_clearscroll) /* disable ESC[3J */ \
+    X(BOOL, NONE, no_dbackspace) /* disable destructive backspace */ \
+    X(BOOL, NONE, no_remote_charset) /* disable remote charset config */ \
+    X(INT, NONE, remote_qtitle_action) /* remote win title query action
+                                       * (TITLE_NONE, TITLE_EMPTY, ...) */ \
+    X(BOOL, NONE, app_cursor) \
+    X(BOOL, NONE, app_keypad) \
+    X(BOOL, NONE, nethack_keypad) \
+    X(BOOL, NONE, telnet_keyboard) \
+    X(BOOL, NONE, telnet_newline) \
+    X(BOOL, NONE, alt_f4) /* is it special? */ \
+    X(BOOL, NONE, alt_space) /* is it special? */ \
+    X(BOOL, NONE, alt_only) /* is it special? */ \
+    X(INT, NONE, localecho) /* FORCE_ON, FORCE_OFF, AUTO */ \
+    X(INT, NONE, localedit) /* FORCE_ON, FORCE_OFF, AUTO */ \
+    X(BOOL, NONE, alwaysontop) \
+    X(BOOL, NONE, fullscreenonaltenter) \
+    X(BOOL, NONE, scroll_on_key) \
+    X(BOOL, NONE, scroll_on_disp) \
+    X(BOOL, NONE, erase_to_scrollback) \
+    X(BOOL, NONE, compose_key) \
+    X(BOOL, NONE, ctrlaltkeys) \
+    X(BOOL, NONE, osx_option_meta) \
+    X(BOOL, NONE, osx_command_meta) \
     X(STR, NONE, wintitle) /* initial window title */ \
     /* Terminal options */ \
     X(INT, NONE, savelines) \
-    X(INT, NONE, dec_om) \
-    X(INT, NONE, wrap_mode) \
-    X(INT, NONE, lfhascr) \
+    X(BOOL, NONE, dec_om) \
+    X(BOOL, NONE, wrap_mode) \
+    X(BOOL, NONE, lfhascr) \
     X(INT, NONE, cursor_type) /* 0=block 1=underline 2=vertical */ \
-    X(INT, NONE, blink_cur) \
-    X(INT, NONE, beep) \
-    X(INT, NONE, beep_ind) \
-    X(INT, NONE, bellovl) /* bell overload protection active? */ \
+    X(BOOL, NONE, blink_cur) \
+    X(INT, NONE, beep) /* BELL_DISABLED, BELL_DEFAULT, ... */ \
+    X(INT, NONE, beep_ind) /* B_IND_DISABLED, B_IND_FLASH, ... */ \
+    X(BOOL, NONE, bellovl) /* bell overload protection active? */ \
     X(INT, NONE, bellovl_n) /* number of bells to cause overload */ \
     X(INT, NONE, bellovl_t) /* time interval for overload (seconds) */ \
     X(INT, NONE, bellovl_s) /* period of silence to re-enable bell (s) */ \
     X(FILENAME, NONE, bell_wavefile) \
-    X(INT, NONE, scrollbar) \
-    X(INT, NONE, scrollbar_in_fullscreen) \
-    X(INT, NONE, resize_action) \
-    X(INT, NONE, bce) \
-    X(INT, NONE, blinktext) \
-    X(INT, NONE, win_name_always) \
+    X(BOOL, NONE, scrollbar) \
+    X(BOOL, NONE, scrollbar_in_fullscreen) \
+    X(INT, NONE, resize_action) /* RESIZE_TERM, RESIZE_DISABLED, ... */ \
+    X(BOOL, NONE, bce) \
+    X(BOOL, NONE, blinktext) \
+    X(BOOL, NONE, win_name_always) \
     X(INT, NONE, width) \
     X(INT, NONE, height) \
     X(FONT, NONE, font) \
-    X(INT, NONE, font_quality) \
+    X(INT, NONE, font_quality) /* FQ_DEFAULT, FQ_ANTIALIASED, ... */ \
     X(FILENAME, NONE, logfilename) \
-    X(INT, NONE, logtype) \
-    X(INT, NONE, logxfovr) \
-    X(INT, NONE, logflush) \
-    X(INT, NONE, logheader) \
-    X(INT, NONE, logomitpass) \
-    X(INT, NONE, logomitdata) \
-    X(INT, NONE, hide_mouseptr) \
-    X(INT, NONE, sunken_edge) \
-    X(INT, NONE, window_border) \
+    X(INT, NONE, logtype) /* LGTYP_NONE, LGTYPE_ASCII, ... */ \
+    X(INT, NONE, logxfovr) /* LGXF_OVR, LGXF_APN, LGXF_ASK */ \
+    X(BOOL, NONE, logflush) \
+    X(BOOL, NONE, logheader) \
+    X(BOOL, NONE, logomitpass) \
+    X(BOOL, NONE, logomitdata) \
+    X(BOOL, NONE, hide_mouseptr) \
+    X(BOOL, NONE, sunken_edge) \
+    X(INT, NONE, window_border) /* in pixels */ \
     X(STR, NONE, answerback) \
     X(STR, NONE, printer) \
-    X(INT, NONE, arabicshaping) \
-    X(INT, NONE, bidi) \
+    X(BOOL, NONE, arabicshaping) \
+    X(BOOL, NONE, bidi) \
     /* Colour options */ \
-    X(INT, NONE, ansi_colour) \
-    X(INT, NONE, xterm_256_colour) \
-    X(INT, NONE, true_colour) \
-    X(INT, NONE, system_colour) \
-    X(INT, NONE, try_palette) \
-    X(INT, NONE, bold_style) \
+    X(BOOL, NONE, ansi_colour) \
+    X(BOOL, NONE, xterm_256_colour) \
+    X(BOOL, NONE, true_colour) \
+    X(BOOL, NONE, system_colour) \
+    X(BOOL, NONE, try_palette) \
+    X(INT, NONE, bold_style) /* 1=font 2=colour (3=both) */ \
     X(INT, INT, colours) \
     /* Selection options */ \
-    X(INT, NONE, mouse_is_xterm) \
-    X(INT, NONE, rect_select) \
-    X(INT, NONE, paste_controls) \
-    X(INT, NONE, rawcnp) \
-    X(INT, NONE, utf8linedraw) \
-    X(INT, NONE, rtf_paste) \
-    X(INT, NONE, mouse_override) \
+    X(INT, NONE, mouse_is_xterm) /* 0=compromise 1=xterm 2=Windows */ \
+    X(BOOL, NONE, rect_select) \
+    X(BOOL, NONE, paste_controls) \
+    X(BOOL, NONE, rawcnp) \
+    X(BOOL, NONE, utf8linedraw) \
+    X(BOOL, NONE, rtf_paste) \
+    X(BOOL, NONE, mouse_override) \
     X(INT, INT, wordness) \
-    X(INT, NONE, mouseautocopy) \
-    X(INT, NONE, mousepaste) \
-    X(INT, NONE, ctrlshiftins) \
-    X(INT, NONE, ctrlshiftcv) \
+    X(BOOL, NONE, mouseautocopy) \
+    X(INT, NONE, mousepaste) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
+    X(INT, NONE, ctrlshiftins) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
+    X(INT, NONE, ctrlshiftcv) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
     X(STR, NONE, mousepaste_custom) \
     X(STR, NONE, ctrlshiftins_custom) \
     X(STR, NONE, ctrlshiftcv_custom) \
     /* translations */ \
-    X(INT, NONE, vtmode) \
+    X(INT, NONE, vtmode) /* VT_XWINDOWS, VT_OEMANSI, ... */ \
     X(STR, NONE, line_codepage) \
-    X(INT, NONE, cjk_ambig_wide) \
-    X(INT, NONE, utf8_override) \
-    X(INT, NONE, xlat_capslockcyr) \
+    X(BOOL, NONE, cjk_ambig_wide) \
+    X(BOOL, NONE, utf8_override) \
+    X(BOOL, NONE, xlat_capslockcyr) \
     /* X11 forwarding */ \
-    X(INT, NONE, x11_forward) \
+    X(BOOL, NONE, x11_forward) \
     X(STR, NONE, x11_display) \
-    X(INT, NONE, x11_auth) \
+    X(INT, NONE, x11_auth) /* X11_NO_AUTH, X11_MIT, X11_XDM */ \
     X(FILENAME, NONE, xauthfile) \
     /* port forwarding */ \
-    X(INT, NONE, lport_acceptall) /* accept conns from hosts other than localhost */ \
-    X(INT, NONE, rport_acceptall) /* same for remote forwarded ports (SSH-2 only) */ \
+    X(BOOL, NONE, lport_acceptall) /* accept conns from hosts other than localhost */ \
+    X(BOOL, NONE, rport_acceptall) /* same for remote forwarded ports (SSH-2 only) */ \
     /*                                                                \
      * Subkeys for 'portfwd' can have the following forms:            \
      *                                                                \
@@ -1356,7 +1357,7 @@ void cleanup_exit(int);
      * should be of the form 'host:port'.                             \
      */ \
     X(STR, STR, portfwd) \
-    /* SSH bug compatibility modes */ \
+    /* SSH bug compatibility modes. All FORCE_ON/FORCE_OFF/AUTO */ \
     X(INT, NONE, sshbug_ignore1) \
     X(INT, NONE, sshbug_plainpw1) \
     X(INT, NONE, sshbug_rsa1) \
@@ -1375,10 +1376,10 @@ void cleanup_exit(int);
      * other than the main one, which means it can safely use a very  \
      * large window in SSH-2.                                         \
      */ \
-    X(INT, NONE, ssh_simple) \
-    X(INT, NONE, ssh_connection_sharing) \
-    X(INT, NONE, ssh_connection_sharing_upstream) \
-    X(INT, NONE, ssh_connection_sharing_downstream) \
+    X(BOOL, NONE, ssh_simple) \
+    X(BOOL, NONE, ssh_connection_sharing) \
+    X(BOOL, NONE, ssh_connection_sharing_upstream) \
+    X(BOOL, NONE, ssh_connection_sharing_downstream) \
     /*
      * ssh_manual_hostkeys is conceptually a set rather than a
      * dictionary: the string subkeys are the important thing, and the
@@ -1386,16 +1387,17 @@ void cleanup_exit(int);
      */ \
     X(STR, STR, ssh_manual_hostkeys) \
     /* Options for pterm. Should split out into platform-dependent part. */ \
-    X(INT, NONE, stamp_utmp) \
-    X(INT, NONE, login_shell) \
-    X(INT, NONE, scrollbar_on_left) \
-    X(INT, NONE, shadowbold) \
+    X(BOOL, NONE, stamp_utmp) \
+    X(BOOL, NONE, login_shell) \
+    X(BOOL, NONE, scrollbar_on_left) \
+    X(BOOL, NONE, shadowbold) \
     X(FONT, NONE, boldfont) \
     X(FONT, NONE, widefont) \
     X(FONT, NONE, wideboldfont) \
-    X(INT, NONE, shadowboldoffset) \
-    X(INT, NONE, crhaslf) \
+    X(INT, NONE, shadowboldoffset) /* in pixels */ \
+    X(BOOL, NONE, crhaslf) \
     X(STR, NONE, winclass) \
+    /* end of list */
 
 /* Now define the actual enum of option keywords using that macro. */
 #define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_ ## keyword,
@@ -1410,6 +1412,7 @@ void conf_free(Conf *conf);
 Conf *conf_copy(Conf *oldconf);
 void conf_copy_into(Conf *dest, Conf *src);
 /* Mandatory accessor functions: enforce by assertion that keys exist. */
+bool conf_get_bool(Conf *conf, int key);
 int conf_get_int(Conf *conf, int key);
 int conf_get_int_int(Conf *conf, int key, int subkey);
 char *conf_get_str(Conf *conf, int key);   /* result still owned by conf */
@@ -1426,6 +1429,7 @@ char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);
 /* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */
 char *conf_get_str_nthstrkey(Conf *conf, int key, int n);
 /* Functions to set entries in configuration. Always copy their inputs. */
+void conf_set_bool(Conf *conf, int key, bool value);
 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);
@@ -1436,7 +1440,7 @@ void conf_set_filename(Conf *conf, int key, const Filename *val);
 void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
 /* Serialisation functions for Duplicate Session */
 void conf_serialise(BinarySink *bs, Conf *conf);
-int conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
+bool conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
 
 /*
  * Functions to copy, free, serialise and deserialise FontSpecs.
@@ -1472,7 +1476,7 @@ char *save_settings(const char *section, Conf *conf);
 void save_open_settings(settings_w *sesskey, Conf *conf);
 void load_settings(const char *section, Conf *conf);
 void load_open_settings(settings_r *sesskey, Conf *conf);
-void get_sesslist(struct sesslist *, int allocate);
+void get_sesslist(struct sesslist *, bool allocate);
 void do_defaults(const char *, Conf *);
 void registry_cleanup(void);
 
@@ -1492,6 +1496,7 @@ void registry_cleanup(void);
  * transferred to the caller, and must be freed.
  */
 char *platform_default_s(const char *name);
+bool platform_default_b(const char *name, bool def);
 int platform_default_i(const char *name, int def);
 Filename *platform_default_filename(const char *name);
 FontSpec *platform_default_fontspec(const char *name);
@@ -1503,35 +1508,35 @@ FontSpec *platform_default_fontspec(const char *name);
 Terminal *term_init(Conf *, struct unicode_data *, TermWin *);
 void term_free(Terminal *);
 void term_size(Terminal *, int, int, int);
-void term_paint(Terminal *, int, int, int, int, int);
+void term_paint(Terminal *, int, int, int, int, bool);
 void term_scroll(Terminal *, int, int);
 void term_scroll_to_selection(Terminal *, int);
-void term_pwron(Terminal *, int);
+void term_pwron(Terminal *, bool);
 void term_clrsb(Terminal *);
 void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
-		int,int,int,int,int);
+		int, int, bool, bool, bool);
 void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
 	      unsigned int);
 void term_lost_clipboard_ownership(Terminal *, int clipboard);
 void term_update(Terminal *);
 void term_invalidate(Terminal *);
-void term_blink(Terminal *, int set_cursor);
+void term_blink(Terminal *, bool set_cursor);
 void term_do_paste(Terminal *, const wchar_t *, int);
 void term_nopaste(Terminal *);
-int term_ldisc(Terminal *, int option);
+bool term_ldisc(Terminal *, int option);
 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 *); 
-int term_data(Terminal *, int is_stderr, const void *data, int len);
+int term_data(Terminal *, bool is_stderr, const void *data, int len);
 void term_provide_backend(Terminal *term, Backend *backend);
 void term_provide_logctx(Terminal *term, LogContext *logctx);
-void term_set_focus(Terminal *term, int has_focus);
+void term_set_focus(Terminal *term, bool has_focus);
 char *term_get_ttymode(Terminal *term, const char *mode);
 int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input);
 
-int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl);
+int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl);
 
 /*
  * Exports from logging.c.
@@ -1649,15 +1654,15 @@ extern const struct BackendVtable ssh_backend;
 Ldisc *ldisc_create(Conf *, Terminal *, Backend *, Seat *);
 void ldisc_configure(Ldisc *, Conf *);
 void ldisc_free(Ldisc *);
-void ldisc_send(Ldisc *, const void *buf, int len, int interactive);
+void ldisc_send(Ldisc *, const void *buf, int len, bool interactive);
 void ldisc_echoedit_update(Ldisc *);
 
 /*
  * Exports from ldiscucs.c.
  */
 void lpage_send(Ldisc *, int codepage, const char *buf, int len,
-                int interactive);
-void luni_send(Ldisc *, const wchar_t * widebuf, int len, int interactive);
+                bool interactive);
+void luni_send(Ldisc *, const wchar_t * widebuf, int len, bool interactive);
 
 /*
  * Exports from sshrand.c.
@@ -1686,7 +1691,7 @@ void pinger_free(Pinger *);
  */
 
 #include "misc.h"
-int conf_launchable(Conf *conf);
+bool conf_launchable(Conf *conf);
 char const *conf_dest(Conf *conf);
 
 /*
@@ -1697,13 +1702,14 @@ void prepare_session(Conf *conf);
 /*
  * Exports from sercfg.c.
  */
-void ser_setup_config_box(struct controlbox *b, int midsession,
+void ser_setup_config_box(struct controlbox *b, bool midsession,
 			  int parity_mask, int flow_mask);
 
 /*
  * Exports from version.c.
  */
 extern const char ver[];
+extern const char commitid[];
 
 /*
  * Exports from unicode.c.
@@ -1712,7 +1718,7 @@ extern const char ver[];
 #define CP_UTF8 65001
 #endif
 /* void init_ucs(void); -- this is now in platform-specific headers */
-int is_dbcs_leadbyte(int codepage, char byte);
+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);
 int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
@@ -1762,7 +1768,7 @@ agent_pending_query *agent_query(
     void (*callback)(void *, void *, int), void *callback_ctx);
 void agent_cancel_query(agent_pending_query *);
 void agent_query_synchronous(strbuf *in, void **out, int *outlen);
-int agent_exists(void);
+bool agent_exists(void);
 
 /*
  * Exports from wildcard.c
@@ -1770,7 +1776,7 @@ int agent_exists(void);
 const char *wc_error(int value);
 int wc_match_pl(const char *wildcard, ptrlen target);
 int wc_match(const char *wildcard, const char *target);
-int wc_unescape(char *output, const char *wildcard);
+bool wc_unescape(char *output, const char *wildcard);
 
 /*
  * Exports from frontend (windlg.c etc)
@@ -1780,15 +1786,15 @@ void pgp_fingerprints(void);
  * have_ssh_host_key() just returns true if a key of that type is
  * already cached and false otherwise.
  */
-int have_ssh_host_key(const char *host, int port, const char *keytype);
+bool have_ssh_host_key(const char *host, int port, const char *keytype);
 
 /*
  * Exports from console frontends (wincons.c, uxcons.c)
  * that aren't equivalents to things in windlg.c et al.
  */
-extern int console_batch_mode;
+extern bool console_batch_mode;
 int console_get_userpass_input(prompts_t *p);
-int is_interactive(void);
+bool is_interactive(void);
 void console_print_error_msg(const char *prefix, const char *msg);
 void console_print_error_msg_fmt_v(
     const char *prefix, const char *fmt, va_list ap);
@@ -1820,7 +1826,7 @@ int cmdline_process_param(const char *, char *, int, Conf *);
 void cmdline_run_saved(Conf *);
 void cmdline_cleanup(void);
 int cmdline_get_passwd_input(prompts_t *p);
-int cmdline_host_ok(Conf *);
+bool cmdline_host_ok(Conf *);
 #define TOOLTYPE_FILETRANSFER 1
 #define TOOLTYPE_NONNETWORK 2
 #define TOOLTYPE_HOST_ARG 4
@@ -1848,7 +1854,10 @@ void conf_filesel_handler(union control *ctrl, dlgparam *dlg,
 			  void *data, int event);
 void conf_fontsel_handler(union control *ctrl, dlgparam *dlg,
 			  void *data, int event);
-void setup_config_box(struct controlbox *b, int midsession,
+/* 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);
 
 /*
@@ -1860,7 +1869,7 @@ typedef struct bidi_char {
 } bidi_char;
 int do_bidi(bidi_char *line, int count);
 int do_shape(bidi_char *line, bidi_char *to, int count);
-int is_rtl(int c);
+bool is_rtl(int c);
 
 /*
  * X11 auth mechanisms we know about.
@@ -1891,8 +1900,8 @@ enum {
  */
 Filename *filename_from_str(const char *string);
 const char *filename_to_str(const Filename *fn);
-int filename_equal(const Filename *f1, const Filename *f2);
-int filename_is_null(const Filename *fn);
+bool filename_equal(const Filename *f1, const Filename *f2);
+bool filename_is_null(const Filename *fn);
 Filename *filename_copy(const Filename *fn);
 void filename_free(Filename *fn);
 void filename_serialise(BinarySink *bs, const Filename *f);
@@ -1900,7 +1909,7 @@ Filename *filename_deserialise(BinarySource *src);
 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 */
-int open_for_write_would_lose_data(const Filename *fn);
+bool open_for_write_would_lose_data(const Filename *fn);
 
 /*
  * Exports and imports from timing.c.
@@ -1922,9 +1931,9 @@ int open_for_write_would_lose_data(const Filename *fn);
  * run_timers() is called from the front end when it has reason to
  * think some timers have reached their moment, or when it simply
  * needs to know how long to wait next. We pass it the time we
- * think it is. It returns TRUE and places the time when the next
+ * think it is. It returns true and places the time when the next
  * timer needs to go off in `next', or alternatively it returns
- * FALSE if there are no timers at all pending.
+ * false if there are no timers at all pending.
  * 
  * timer_change_notify() must be supplied by the front end; it
  * notifies the front end that a new timer has been added to the
@@ -1995,7 +2004,7 @@ int open_for_write_would_lose_data(const Filename *fn);
 typedef void (*timer_fn_t)(void *ctx, unsigned long now);
 unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
 void expire_timer_context(void *ctx);
-int run_timers(unsigned long now, unsigned long *next);
+bool run_timers(unsigned long now, unsigned long *next);
 void timer_change_notify(unsigned long next);
 unsigned long timing_last_clock(void);
 
@@ -2020,15 +2029,15 @@ unsigned long timing_last_clock(void);
  * call) then it can call toplevel_callback_pending(), which will
  * return true if at least one callback is in the queue.
  *
- * run_toplevel_callbacks() returns TRUE if it ran any actual code.
+ * run_toplevel_callbacks() returns true if it ran any actual code.
  * This can be used as a means of speculatively terminating a select
  * loop, as in PSFTP, for example - if a callback has run then perhaps
  * it might have done whatever the loop's caller was waiting for.
  */
 typedef void (*toplevel_callback_fn_t)(void *ctx);
 void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx);
-int run_toplevel_callbacks(void);
-int toplevel_callback_pending(void);
+bool run_toplevel_callbacks(void);
+bool toplevel_callback_pending(void);
 void delete_callbacks_for_context(void *ctx);
 
 /*
@@ -2043,7 +2052,7 @@ void delete_callbacks_for_context(void *ctx);
 struct IdempotentCallback {
     toplevel_callback_fn_t fn;
     void *ctx;
-    int queued;
+    bool queued;
 };
 void queue_idempotent_callback(struct IdempotentCallback *ic);
 

+ 55 - 54
source/putty/ssh.c

@@ -46,9 +46,9 @@ struct Ssh {
     /* The last list returned from get_specials. */
     SessionSpecial *specials;
 
-    int bare_connection;
+    bool bare_connection;
     ssh_sharing_state *connshare;
-    int attempting_connshare;
+    bool attempting_connshare;
 
     struct ssh_connection_shared_gss_state gss_state;
 
@@ -56,20 +56,20 @@ struct Ssh {
     int savedport;
     char *fullhostname;
 
-    int fallback_cmd;
+    bool fallback_cmd;
     int exitcode;
 
     int version;
     int conn_throttle_count;
     int overall_bufsize;
-    int throttled_all;
-    int frozen;
+    bool throttled_all;
+    bool frozen;
 
     /* in case we find these out before we have a ConnectionLayer to tell */
     int term_width, term_height;
 
     bufchain in_raw, out_raw, user_input;
-    int pending_close;
+    bool pending_close;
     IdempotentCallback ic_out_raw;
 
     PacketLogSettings pls;
@@ -98,18 +98,18 @@ struct Ssh {
     ConnectionLayer cl_dummy;
 
     /*
-     * session_started is FALSE until we initialise the main protocol
+     * session_started is false until we initialise the main protocol
      * layers. So it distinguishes between base_layer==NULL meaning
      * that the SSH protocol hasn't been set up _yet_, and
      * base_layer==NULL meaning the SSH protocol has run and finished.
      * It's also used to mark the point where we stop counting proxy
      * command diagnostics as pre-session-startup.
      */
-    int session_started;
+    bool session_started;
 
     Pinger *pinger;
 
-    int need_random_unref;
+    bool need_random_unref;
 };
 
 
@@ -117,7 +117,7 @@ struct Ssh {
         logevent_and_free((ssh)->logctx, dupprintf params))
 
 static void ssh_shutdown(Ssh *ssh);
-static void ssh_throttle_all(Ssh *ssh, int enable, int bufsize);
+static void ssh_throttle_all(Ssh *ssh, bool enable, int bufsize);
 static void ssh_bpp_output_raw_data_callback(void *vctx);
 
 LogContext *ssh_get_logctx(Ssh *ssh)
@@ -153,7 +153,7 @@ static void ssh_got_ssh_version(struct ssh_version_receiver *rcv,
     BinaryPacketProtocol *old_bpp;
     PacketProtocolLayer *connection_layer;
 
-    ssh->session_started = TRUE;
+    ssh->session_started = true;
 
     /*
      * We don't support choosing a major protocol version dynamically,
@@ -177,10 +177,10 @@ static void ssh_got_ssh_version(struct ssh_version_receiver *rcv,
              * ourselves), since then the assumption that we have only
              * one channel to worry about is not true after all.
              */
-            int is_simple =
-                (conf_get_int(ssh->conf, CONF_ssh_simple) && !ssh->connshare);
+            bool is_simple =
+                (conf_get_bool(ssh->conf, CONF_ssh_simple) && !ssh->connshare);
 
-            ssh->bpp = ssh2_bpp_new(ssh->logctx, &ssh->stats, FALSE);
+            ssh->bpp = ssh2_bpp_new(ssh->logctx, &ssh->stats, false);
             ssh_connect_bpp(ssh);
 
 #ifndef NO_GSSAPI
@@ -218,7 +218,7 @@ static void ssh_got_ssh_version(struct ssh_version_receiver *rcv,
                 ssh_verstring_get_remote(old_bpp), &ssh->cl);
             ssh_connect_ppl(ssh, connection_layer);
 
-            if (conf_get_int(ssh->conf, CONF_ssh_no_userauth)) {
+            if (conf_get_bool(ssh->conf, CONF_ssh_no_userauth)) {
                 userauth_layer = NULL;
                 transport_child_layer = connection_layer;
             } else {
@@ -227,12 +227,12 @@ static void ssh_got_ssh_version(struct ssh_version_receiver *rcv,
                 userauth_layer = ssh2_userauth_new(
                     connection_layer, ssh->savedhost, ssh->fullhostname,
                     conf_get_filename(ssh->conf, CONF_keyfile),
-                    conf_get_int(ssh->conf, CONF_tryagent), username,
-                    conf_get_int(ssh->conf, CONF_change_username),
-                    conf_get_int(ssh->conf, CONF_try_ki_auth),
-                    conf_get_int(ssh->conf, CONF_try_gssapi_auth),
-                    conf_get_int(ssh->conf, CONF_try_gssapi_kex),
-                    conf_get_int(ssh->conf, CONF_gssapifwd),
+                    conf_get_bool(ssh->conf, CONF_tryagent), username,
+                    conf_get_bool(ssh->conf, CONF_change_username),
+                    conf_get_bool(ssh->conf, CONF_try_ki_auth),
+                    conf_get_bool(ssh->conf, CONF_try_gssapi_auth),
+                    conf_get_bool(ssh->conf, CONF_try_gssapi_kex),
+                    conf_get_bool(ssh->conf, CONF_gssapifwd),
                     &ssh->gss_state);
                 ssh_connect_ppl(ssh, userauth_layer);
                 transport_child_layer = userauth_layer;
@@ -246,7 +246,7 @@ static void ssh_got_ssh_version(struct ssh_version_receiver *rcv,
                 ssh_verstring_get_local(old_bpp),
                 ssh_verstring_get_remote(old_bpp),
                 &ssh->gss_state,
-                &ssh->stats, transport_child_layer, FALSE);
+                &ssh->stats, transport_child_layer, false);
             ssh_connect_ppl(ssh, ssh->base_layer);
 
             if (userauth_layer)
@@ -272,7 +272,7 @@ static void ssh_got_ssh_version(struct ssh_version_receiver *rcv,
         ssh_connect_bpp(ssh);
 
         connection_layer = ssh2_connection_new(
-            ssh, NULL, FALSE, ssh->conf, ssh_verstring_get_remote(old_bpp),
+            ssh, NULL, false, ssh->conf, ssh_verstring_get_remote(old_bpp),
             &ssh->cl);
         ssh_connect_ppl(ssh, connection_layer);
         ssh->base_layer = connection_layer;
@@ -316,7 +316,7 @@ static void ssh_bpp_output_raw_data_callback(void *vctx)
         bufchain_consume(&ssh->out_raw, len);
 
         if (backlog > SSH_MAX_BACKLOG) {
-            ssh_throttle_all(ssh, 1, backlog);
+            ssh_throttle_all(ssh, true, backlog);
             return;
         }
     }
@@ -380,13 +380,13 @@ static void ssh_initiate_connection_close(Ssh *ssh)
     /* Force any remaining queued SSH packets through the BPP, and
      * schedule closing the network socket after they go out. */
     ssh_bpp_handle_output(ssh->bpp);
-    ssh->pending_close = TRUE;
+    ssh->pending_close = true;
     queue_idempotent_callback(&ssh->ic_out_raw);
 
     /* Now we expect the other end to close the connection too in
      * response, so arrange that we'll receive notification of that
      * via ssh_remote_eof. */
-    ssh->bpp->expect_close = TRUE;
+    ssh->bpp->expect_close = true;
 }
 
 #define GET_FORMATTED_MSG                       \
@@ -515,13 +515,13 @@ 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,
-			int calling_back)
+			bool calling_back)
 {
     Ssh *ssh = container_of(plug, Ssh, plug);
     if (error_msg) {
         ssh_remote_error(ssh, "Network error: %s", error_msg);
     } else if (ssh->bpp) {
-        ssh->bpp->input_eof = TRUE;
+        ssh->bpp->input_eof = true;
         queue_idempotent_callback(&ssh->bpp->ic_in_raw);
     }
 }
@@ -550,7 +550,7 @@ static void ssh_sent(Plug *plug, int bufsize)
      * some more data off its bufchain.
      */
     if (bufsize < SSH_MAX_BACKLOG) {
-	ssh_throttle_all(ssh, 0, bufsize);
+	ssh_throttle_all(ssh, false, bufsize);
         queue_idempotent_callback(&ssh->ic_out_raw);
     }
 }
@@ -592,11 +592,11 @@ static void ssh_hostport_setup(const char *host, int port, Conf *conf,
     }
 }
 
-static int ssh_test_for_upstream(const char *host, int port, Conf *conf)
+static bool ssh_test_for_upstream(const char *host, int port, Conf *conf)
 {
     char *savedhost;
     int savedport;
-    int ret;
+    bool ret;
 
     random_ref(); /* platform may need this to determine share socket name */
     ssh_hostport_setup(host, port, conf, &savedhost, &savedport, NULL);
@@ -621,8 +621,9 @@ static const PlugVtable Ssh_plugvt = {
  * Also places the canonical host name into `realhost'. It must be
  * freed by the caller.
  */
-static const char *connect_to_host(Ssh *ssh, const char *host, int port,
-				   char **realhost, int nodelay, int keepalive)
+static const char *connect_to_host(
+    Ssh *ssh, const char *host, int port, char **realhost,
+    bool nodelay, bool keepalive)
 {
     SockAddr *addr;
     const char *err;
@@ -644,18 +645,18 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port,
      * downstream and need to do our connection setup differently.
      */
     ssh->connshare = NULL;
-    ssh->attempting_connshare = TRUE;  /* affects socket logging behaviour */
+    ssh->attempting_connshare = true;  /* affects socket logging behaviour */
     ssh->s = ssh_connection_sharing_init(
         ssh->savedhost, ssh->savedport, ssh->conf, ssh->logctx,
         &ssh->plug, &ssh->connshare);
     if (ssh->connshare)
         ssh_connshare_provide_connlayer(ssh->connshare, &ssh->cl_dummy);
-    ssh->attempting_connshare = FALSE;
+    ssh->attempting_connshare = false;
     if (ssh->s != NULL) {
         /*
          * We are a downstream.
          */
-        ssh->bare_connection = TRUE;
+        ssh->bare_connection = true;
         ssh->fullhostname = NULL;
         *realhost = dupstr(host);      /* best we can do */
 
@@ -686,7 +687,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port,
         ssh->fullhostname = dupstr(*realhost);   /* save in case of GSSAPI */
 
         ssh->s = new_connection(addr, *realhost, port,
-                                0, 1, nodelay, keepalive,
+                                false, true, nodelay, keepalive,
                                 &ssh->plug, ssh->conf);
         if ((err = sk_socket_error(ssh->s)) != NULL) {
             ssh->s = NULL;
@@ -718,7 +719,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port,
     ssh->bpp = ssh_verstring_new(
         ssh->conf, ssh->logctx, ssh->bare_connection,
         ssh->version == 1 ? "1.5" : "2.0", &ssh->version_receiver,
-        FALSE, "PuTTY");
+        false, "PuTTY");
     ssh_connect_bpp(ssh);
     queue_idempotent_callback(&ssh->bpp->ic_in_raw);
 
@@ -739,15 +740,15 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port,
 void ssh_throttle_conn(Ssh *ssh, int adjust)
 {
     int old_count = ssh->conn_throttle_count;
-    int frozen;
+    bool frozen;
 
     ssh->conn_throttle_count += adjust;
     assert(ssh->conn_throttle_count >= 0);
 
     if (ssh->conn_throttle_count && !old_count) {
-        frozen = TRUE;
+        frozen = true;
     } else if (!ssh->conn_throttle_count && old_count) {
-        frozen = FALSE;
+        frozen = false;
     } else {
         return;                /* don't change current frozen state */
     }
@@ -769,7 +770,7 @@ void ssh_throttle_conn(Ssh *ssh, int adjust)
  * Throttle or unthrottle _all_ local data streams (for when sends
  * on the SSH connection itself back up).
  */
-static void ssh_throttle_all(Ssh *ssh, int enable, int bufsize)
+static void ssh_throttle_all(Ssh *ssh, bool enable, int bufsize)
 {
     if (enable == ssh->throttled_all)
 	return;
@@ -781,8 +782,8 @@ static void ssh_throttle_all(Ssh *ssh, int enable, int bufsize)
 
 static void ssh_cache_conf_values(Ssh *ssh)
 {
-    ssh->pls.omit_passwords = conf_get_int(ssh->conf, CONF_logomitpass);
-    ssh->pls.omit_data = conf_get_int(ssh->conf, CONF_logomitdata);
+    ssh->pls.omit_passwords = conf_get_bool(ssh->conf, CONF_logomitpass);
+    ssh->pls.omit_data = conf_get_bool(ssh->conf, CONF_logomitdata);
 }
 
 /*
@@ -793,7 +794,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,
-			    int nodelay, int keepalive)
+			    bool nodelay, bool keepalive)
 {
     const char *p;
     Ssh *ssh;
@@ -819,7 +820,7 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle,
     ssh->cl_dummy.logctx = ssh->logctx = logctx;
 
     random_ref(); /* do this now - may be needed by sharing setup code */
-    ssh->need_random_unref = TRUE;
+    ssh->need_random_unref = true;
 
     p = connect_to_host(ssh, host, port, realhost, nodelay, keepalive);
     if (p != NULL) {
@@ -827,7 +828,7 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle,
          * frees this useless Ssh object, in case the caller is
          * impatient and just exits without bothering, in which case
          * the random seed won't be re-saved. */
-        ssh->need_random_unref = FALSE;
+        ssh->need_random_unref = false;
         random_unref();
 	return p;
     }
@@ -838,7 +839,7 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle,
 static void ssh_free(Backend *be)
 {
     Ssh *ssh = container_of(be, Ssh, backend);
-    int need_random_unref;
+    bool need_random_unref;
 
     ssh_shutdown(ssh);
 
@@ -1015,13 +1016,13 @@ static void ssh_unthrottle(Backend *be, int bufsize)
     ssh_stdout_unthrottle(ssh->cl, bufsize);
 }
 
-static int ssh_connected(Backend *be)
+static bool ssh_connected(Backend *be)
 {
     Ssh *ssh = container_of(be, Ssh, backend);
     return ssh->s != NULL;
 }
 
-static int ssh_sendok(Backend *be)
+static bool ssh_sendok(Backend *be)
 {
     Ssh *ssh = container_of(be, Ssh, backend);
     return ssh->base_layer && ssh_ppl_want_user_input(ssh->base_layer);
@@ -1035,10 +1036,10 @@ void ssh_ldisc_update(Ssh *ssh)
 	ldisc_echoedit_update(ssh->ldisc);
 }
 
-static int ssh_ldisc(Backend *be, int option)
+static bool ssh_ldisc(Backend *be, int option)
 {
     Ssh *ssh = container_of(be, Ssh, backend);
-    return ssh->cl ? ssh_ldisc_option(ssh->cl, option) : FALSE;
+    return ssh->cl ? ssh_ldisc_option(ssh->cl, option) : false;
 }
 
 static void ssh_provide_ldisc(Backend *be, Ldisc *ldisc)
@@ -1082,7 +1083,7 @@ static int ssh_cfg_info(Backend *be)
  * that fails. This variable is the means by which scp.c can reach
  * into the SSH code and find out which one it got.
  */
-extern int ssh_fallback_cmd(Backend *be)
+extern bool ssh_fallback_cmd(Backend *be)
 {
     Ssh *ssh = container_of(be, Ssh, backend);
     return ssh->fallback_cmd;
@@ -1090,7 +1091,7 @@ extern int ssh_fallback_cmd(Backend *be)
 
 void ssh_got_fallback_cmd(Ssh *ssh)
 {
-    ssh->fallback_cmd = TRUE;
+    ssh->fallback_cmd = true;
 }
 
 const struct BackendVtable ssh_backend = {

+ 101 - 86
source/putty/ssh.h

@@ -4,7 +4,6 @@
 #include "puttymem.h"
 #include "tree234.h"
 #include "network.h"
-#include "int64.h"
 #include "misc.h"
 
 struct ssh_channel;
@@ -53,7 +52,7 @@ struct ssh_channel;
 typedef struct PacketQueueNode PacketQueueNode;
 struct PacketQueueNode {
     PacketQueueNode *next, *prev;
-    int on_free_queue;     /* is this packet scheduled for freeing? */
+    bool on_free_queue;     /* is this packet scheduled for freeing? */
 };
 
 typedef struct PktIn {
@@ -90,12 +89,12 @@ typedef struct PacketQueueBase {
 
 typedef struct PktInQueue {
     PacketQueueBase pqb;
-    PktIn *(*after)(PacketQueueBase *, PacketQueueNode *prev, int pop);
+    PktIn *(*after)(PacketQueueBase *, PacketQueueNode *prev, bool pop);
 } PktInQueue;
 
 typedef struct PktOutQueue {
     PacketQueueBase pqb;
-    PktOut *(*after)(PacketQueueBase *, PacketQueueNode *prev, int pop);
+    PktOut *(*after)(PacketQueueBase *, PacketQueueNode *prev, bool pop);
 } PktOutQueue;
 
 void pq_base_push(PacketQueueBase *pqb, PacketQueueNode *node);
@@ -109,22 +108,22 @@ void pq_in_clear(PktInQueue *pq);
 void pq_out_clear(PktOutQueue *pq);
 
 #define pq_push(pq, pkt)                                        \
-    TYPECHECK((pq)->after(&(pq)->pqb, NULL, FALSE) == pkt,      \
+    TYPECHECK((pq)->after(&(pq)->pqb, NULL, false) == pkt,      \
               pq_base_push(&(pq)->pqb, &(pkt)->qnode))
 #define pq_push_front(pq, pkt)                                  \
-    TYPECHECK((pq)->after(&(pq)->pqb, NULL, FALSE) == pkt,      \
+    TYPECHECK((pq)->after(&(pq)->pqb, NULL, false) == pkt,      \
               pq_base_push_front(&(pq)->pqb, &(pkt)->qnode))
-#define pq_peek(pq) ((pq)->after(&(pq)->pqb, &(pq)->pqb.end, FALSE))
-#define pq_pop(pq) ((pq)->after(&(pq)->pqb, &(pq)->pqb.end, TRUE))
+#define pq_peek(pq) ((pq)->after(&(pq)->pqb, &(pq)->pqb.end, false))
+#define pq_pop(pq) ((pq)->after(&(pq)->pqb, &(pq)->pqb.end, true))
 #define pq_concatenate(dst, q1, q2)                                     \
-    TYPECHECK((q1)->after(&(q1)->pqb, NULL, FALSE) ==                   \
-              (dst)->after(&(dst)->pqb, NULL, FALSE) &&                 \
-              (q2)->after(&(q2)->pqb, NULL, FALSE) ==                   \
-              (dst)->after(&(dst)->pqb, NULL, FALSE),                   \
+    TYPECHECK((q1)->after(&(q1)->pqb, NULL, false) ==                   \
+              (dst)->after(&(dst)->pqb, NULL, false) &&                 \
+              (q2)->after(&(q2)->pqb, NULL, false) ==                   \
+              (dst)->after(&(dst)->pqb, NULL, false),                   \
               pq_base_concatenate(&(dst)->pqb, &(q1)->pqb, &(q2)->pqb))
 
 #define pq_first(pq) pq_peek(pq)
-#define pq_next(pq, pkt) ((pq)->after(&(pq)->pqb, &(pkt)->qnode, FALSE))
+#define pq_next(pq, pkt) ((pq)->after(&(pq)->pqb, &(pkt)->qnode, false))
 
 /*
  * Packet type contexts, so that ssh2_pkt_type can correctly decode
@@ -147,17 +146,17 @@ typedef enum {
 } Pkt_ACtx;
 
 typedef struct PacketLogSettings {
-    int omit_passwords, omit_data;
+    bool omit_passwords, omit_data;
     Pkt_KCtx kctx;
     Pkt_ACtx actx;
 } PacketLogSettings;
 
 #define MAX_BLANKS 4 /* no packet needs more censored sections than this */
 int ssh1_censor_packet(
-    const PacketLogSettings *pls, int type, int sender_is_client,
+    const PacketLogSettings *pls, int type, bool sender_is_client,
     ptrlen pkt, logblank_t *blanks);
 int ssh2_censor_packet(
-    const PacketLogSettings *pls, int type, int sender_is_client,
+    const PacketLogSettings *pls, int type, bool sender_is_client,
     ptrlen pkt, logblank_t *blanks);
 
 PktOut *ssh_new_packet(void);
@@ -168,7 +167,7 @@ Socket *ssh_connection_sharing_init(
     Plug *sshplug, ssh_sharing_state **state);
 void ssh_connshare_provide_connlayer(ssh_sharing_state *sharestate,
                                      ConnectionLayer *cl);
-int ssh_share_test_for_upstream(const char *host, int port, Conf *conf);
+bool ssh_share_test_for_upstream(const char *host, int port, Conf *conf);
 void share_got_pkt_from_server(ssh_sharing_connstate *ctx, int type,
                                const void *pkt, int pktlen);
 void share_activate(ssh_sharing_state *sharestate,
@@ -186,6 +185,12 @@ void share_setup_x11_channel(ssh_sharing_connstate *cs, share_channel *chan,
                              int protomajor, int protominor,
                              const void *initial_data, int initial_len);
 
+/* Per-application overrides for what roles we can take in connection
+ * sharing, regardless of user configuration (e.g. pscp will never be
+ * an upstream) */
+extern const bool share_can_be_downstream;
+extern const bool share_can_be_upstream;
+
 struct X11Display;
 struct X11FakeAuth;
 
@@ -260,7 +265,7 @@ struct ConnectionLayerVtable {
     void (*sharing_no_more_downstreams)(ConnectionLayer *cl);
 
     /* Query whether the connection layer is doing agent forwarding */
-    int (*agent_forwarding_permitted)(ConnectionLayer *cl);
+    bool (*agent_forwarding_permitted)(ConnectionLayer *cl);
 
     /* Set the size of the main terminal window (if any) */
     void (*terminal_size)(ConnectionLayer *cl, int width, int height);
@@ -275,15 +280,15 @@ struct ConnectionLayerVtable {
      * backed up, so it should tell all currently open channels to
      * cease reading from their local input sources if they can. (Or
      * tell it that that state of affairs has gone away again.) */
-    void (*throttle_all_channels)(ConnectionLayer *cl, int throttled);
+    void (*throttle_all_channels)(ConnectionLayer *cl, bool throttled);
 
     /* Ask the connection layer about its current preference for
      * line-discipline options. */
-    int (*ldisc_option)(ConnectionLayer *cl, int option);
+    bool (*ldisc_option)(ConnectionLayer *cl, int option);
 
     /* Communicate _to_ the connection layer (from the main session
      * channel) what its preference for line-discipline options is. */
-    void (*set_ldisc_option)(ConnectionLayer *cl, int option, int value);
+    void (*set_ldisc_option)(ConnectionLayer *cl, int option, bool value);
 
     /* Communicate to the connection layer whether X and agent
      * forwarding were successfully enabled (for purposes of
@@ -293,7 +298,7 @@ struct ConnectionLayerVtable {
 
     /* Communicate to the connection layer whether the main session
      * channel currently wants user input. */
-    void (*set_wants_user_input)(ConnectionLayer *cl, int wanted);
+    void (*set_wants_user_input)(ConnectionLayer *cl, bool wanted);
 };
 
 struct ConnectionLayer {
@@ -355,9 +360,9 @@ void portfwdmgr_close_all(PortFwdManager *mgr);
 char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret,
                          char *hostname, int port, SshChannel *c,
                          int addressfamily);
-int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
-                      const char *keyhost, int keyport, Conf *conf);
-int portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port);
+bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
+                       const char *keyhost, int keyport, Conf *conf);
+bool portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port);
 Channel *portfwd_raw_new(ConnectionLayer *cl, Plug **plug);
 void portfwd_raw_free(Channel *pfchan);
 void portfwd_raw_setup(Channel *pfchan, Socket *s, SshChannel *sc);
@@ -416,9 +421,11 @@ struct ec_point {
     const struct ec_curve *curve;
     Bignum x, y;
     Bignum z;  /* Jacobian denominator */
-    unsigned char infinity;
+    bool infinity;
 };
 
+/* A couple of ECC functions exported for use outside sshecc.c */
+struct ec_point *ecp_mul(const struct ec_point *a, const Bignum b);
 void ec_point_free(struct ec_point *point);
 
 /* Weierstrass form curve */
@@ -465,12 +472,12 @@ const ssh_keyalg *ec_alg_by_oid(int len, const void *oid,
                                         const struct ec_curve **curve);
 const unsigned char *ec_alg_oid(const ssh_keyalg *alg, int *oidlen);
 extern const int ec_nist_curve_lengths[], n_ec_nist_curve_lengths;
-int ec_nist_alg_and_curve_by_bits(int bits,
-                                  const struct ec_curve **curve,
-                                  const ssh_keyalg **alg);
-int ec_ed_alg_and_curve_by_bits(int bits,
-                                const struct ec_curve **curve,
-                                const ssh_keyalg **alg);
+bool ec_nist_alg_and_curve_by_bits(int bits,
+                                   const struct ec_curve **curve,
+                                   const ssh_keyalg **alg);
+bool ec_ed_alg_and_curve_by_bits(int bits,
+                                 const struct ec_curve **curve,
+                                 const ssh_keyalg **alg);
 
 struct ec_key {
     struct ec_point publicKey;
@@ -494,21 +501,19 @@ void BinarySource_get_rsa_ssh1_pub(
     BinarySource *src, struct RSAKey *result, RsaSsh1Order order);
 void BinarySource_get_rsa_ssh1_priv(
     BinarySource *src, struct RSAKey *rsa);
-int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key);
+bool rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key);
 Bignum rsa_ssh1_decrypt(Bignum input, struct RSAKey *key);
-int rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf);
+bool rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf);
 void rsasanitise(struct RSAKey *key);
 int rsastr_len(struct RSAKey *key);
 void rsastr_fmt(char *str, struct RSAKey *key);
 char *rsa_ssh1_fingerprint(struct RSAKey *key);
-int rsa_verify(struct RSAKey *key);
+bool rsa_verify(struct RSAKey *key);
 void rsa_ssh1_public_blob(BinarySink *bs, struct RSAKey *key,
                           RsaSsh1Order order);
 int rsa_ssh1_public_blob_len(void *data, int maxlen);
 void freersakey(struct RSAKey *key);
 
-typedef uint32 word32;
-
 unsigned long crc32_compute(const void *s, size_t len);
 unsigned long crc32_update(unsigned long crc_input, const void *s, size_t len);
 
@@ -516,8 +521,8 @@ unsigned long crc32_update(unsigned long crc_input, const void *s, size_t len);
 struct crcda_ctx;
 struct crcda_ctx *crcda_make_context(void);
 void crcda_free_context(struct crcda_ctx *ctx);
-int detect_attack(struct crcda_ctx *ctx, unsigned char *buf, uint32 len,
-		  unsigned char *IV);
+bool detect_attack(struct crcda_ctx *ctx, unsigned char *buf, uint32_t len,
+                   unsigned char *IV);
 
 /*
  * SSH2 RSA key exchange functions
@@ -556,14 +561,14 @@ struct ssh2_cipheralg;
 typedef const struct ssh2_cipheralg *ssh2_cipher;
 
 typedef struct {
-    uint32 h[4];
+    uint32_t h[4];
 } MD5_Core_State;
 
 struct MD5Context {
     MD5_Core_State core;
     unsigned char block[64];
     int blkused;
-    uint32 lenhi, lenlo;
+    uint64_t len;
     BinarySink_IMPLEMENTATION;
 };
 
@@ -578,13 +583,13 @@ void hmacmd5_key(struct hmacmd5_context *ctx, void const *key, int len);
 void hmacmd5_do_hmac(struct hmacmd5_context *ctx,
                      const void *blk, int len, unsigned char *hmac);
 
-int supports_sha_ni(void);
+bool supports_sha_ni(void);
 
 typedef struct SHA_State {
-    uint32 h[5];
+    uint32_t h[5];
     unsigned char block[64];
     int blkused;
-    uint32 lenhi, lenlo;
+    uint64_t len;
     void (*sha1)(struct SHA_State * s, const unsigned char *p, int len);
     BinarySink_IMPLEMENTATION;
 } SHA_State;
@@ -596,10 +601,10 @@ void hmac_sha1_simple(const void *key, int keylen,
                       const void *data, int datalen,
 		      unsigned char *output);
 typedef struct SHA256_State {
-    uint32 h[8];
+    uint32_t h[8];
     unsigned char block[64];
     int blkused;
-    uint32 lenhi, lenlo;
+    uint64_t len;
     void (*sha256)(struct SHA256_State * s, const unsigned char *p, int len);
     BinarySink_IMPLEMENTATION;
 } SHA256_State;
@@ -608,10 +613,10 @@ void SHA256_Final(SHA256_State * s, unsigned char *output);
 void SHA256_Simple(const void *p, int len, unsigned char *output);
 
 typedef struct {
-    uint64 h[8];
+    uint64_t h[8];
     unsigned char block[128];
     int blkused;
-    uint32 len[4];
+    uint64_t lenhi, lenlo;
     BinarySink_IMPLEMENTATION;
 } SHA512_State;
 #define SHA384_State SHA512_State
@@ -721,9 +726,9 @@ struct ssh2_macalg {
 #define ssh2_mac_alg(ctx) ((ctx)->vt)
 
 /* Centralised 'methods' for ssh2_mac, defined in sshmac.c */
-int ssh2_mac_verresult(ssh2_mac *, const void *);
+bool ssh2_mac_verresult(ssh2_mac *, const void *);
 void ssh2_mac_generate(ssh2_mac *, void *, int, unsigned long seq);
-int ssh2_mac_verify(ssh2_mac *, const void *, int, unsigned long seq);
+bool ssh2_mac_verify(ssh2_mac *, const void *, int, unsigned long seq);
 
 typedef struct ssh_hash {
     const struct ssh_hashalg *vt;
@@ -765,8 +770,9 @@ struct ssh_keyalg {
 
     /* Methods that operate on an existing ssh_key */
     void (*freekey) (ssh_key *key);
-    void (*sign) (ssh_key *key, const void *data, int datalen, BinarySink *);
-    int (*verify) (ssh_key *key, ptrlen sig, ptrlen data);
+    void (*sign) (ssh_key *key, const void *data, int datalen,
+                  unsigned flags, BinarySink *);
+    bool (*verify) (ssh_key *key, ptrlen sig, ptrlen data);
     void (*public_blob)(ssh_key *key, BinarySink *);
     void (*private_blob)(ssh_key *key, BinarySink *);
     void (*openssh_blob) (ssh_key *key, BinarySink *);
@@ -779,6 +785,7 @@ struct ssh_keyalg {
     const char *ssh_id;    /* string identifier in the SSH protocol */
     const char *cache_id;  /* identifier used in PuTTY's host key cache */
     const void *extra;     /* private to the public key methods */
+    const unsigned supported_flags;    /* signature-type flags we understand */
 };
 
 #define ssh_key_new_pub(alg, data) ((alg)->new_pub(alg, data))
@@ -786,7 +793,8 @@ struct ssh_keyalg {
 #define ssh_key_new_priv_openssh(alg, bs) ((alg)->new_priv_openssh(alg, bs))
 
 #define ssh_key_free(key) ((*(key))->freekey(key))
-#define ssh_key_sign(key, data, len, bs) ((*(key))->sign(key, data, len, bs))
+#define ssh_key_sign(key, data, len, flags, bs) \
+    ((*(key))->sign(key, data, len, flags, bs))
 #define ssh_key_verify(key, sig, data) ((*(key))->verify(key, sig, data))
 #define ssh_key_public_blob(key, bs) ((*(key))->public_blob(key, bs))
 #define ssh_key_private_blob(key, bs) ((*(key))->private_blob(key, bs))
@@ -799,6 +807,12 @@ struct ssh_keyalg {
 #define ssh_key_ssh_id(key) ((*(key))->ssh_id)
 #define ssh_key_cache_id(key) ((*(key))->cache_id)
 
+/*
+ * Enumeration of signature flags from draft-miller-ssh-agent-02
+ */
+#define SSH_AGENT_RSA_SHA2_256 2
+#define SSH_AGENT_RSA_SHA2_512 4
+
 typedef struct ssh_compressor {
     const struct ssh_compression_alg *vt;
 } ssh_compressor;
@@ -818,8 +832,8 @@ struct ssh_compression_alg {
                      int minlen);
     ssh_decompressor *(*decompress_new)(void);
     void (*decompress_free)(ssh_decompressor *);
-    int (*decompress)(ssh_decompressor *, unsigned char *block, int len,
-                      unsigned char **outblock, int *outlen);
+    bool (*decompress)(ssh_decompressor *, unsigned char *block, int len,
+                       unsigned char **outblock, int *outlen);
     const char *text_name;
 };
 
@@ -896,9 +910,9 @@ extern const char sshver[];
  * that fails. This variable is the means by which scp.c can reach
  * into the SSH code and find out which one it got.
  */
-extern int ssh_fallback_cmd(Backend *backend);
+extern bool ssh_fallback_cmd(Backend *backend);
 
-void SHATransform(word32 * digest, word32 * data);
+void SHATransform(uint32_t *digest, uint32_t *data);
 
 /*
  * Check of compiler version
@@ -933,7 +947,7 @@ enum {
 };
 struct X11Display {
     /* Broken-down components of the display name itself */
-    int unixdomain;
+    bool unixdomain;
     char *hostname;
     int displaynum;
     int screennum;
@@ -999,12 +1013,12 @@ struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype);
 void x11_free_fake_auth(struct X11FakeAuth *auth);
 Channel *x11_new_channel(tree234 *authtree, SshChannel *c,
                          const char *peeraddr, int peerport,
-                         int connection_sharing_possible);
+                         bool connection_sharing_possible);
 char *x11_display(const char *display);
 /* Platform-dependent X11 functions */
 extern void platform_get_x11_auth(struct X11Display *display, Conf *);
     /* examine a mostly-filled-in X11Display and fill in localauth* */
-extern const int platform_uses_x11_unix_by_default;
+extern const bool platform_uses_x11_unix_by_default;
     /* choose default X transport in the absence of a specified one */
 SockAddr *platform_get_x11_unix_address(const char *path, int displaynum);
     /* make up a SockAddr naming the address for displaynum */
@@ -1077,22 +1091,23 @@ Bignum BinarySource_get_mp_ssh2(BinarySource *);
 void diagbn(char *prefix, Bignum md);
 #endif
 
-int dh_is_gex(const struct ssh_kex *kex);
+bool dh_is_gex(const struct ssh_kex *kex);
 struct dh_ctx;
 struct dh_ctx *dh_setup_group(const struct ssh_kex *kex);
 struct dh_ctx *dh_setup_gex(Bignum pval, Bignum gval);
+int dh_modulus_bit_size(const struct dh_ctx *ctx);
 void dh_cleanup(struct dh_ctx *);
 Bignum dh_create_e(struct dh_ctx *, int nbits);
 const char *dh_validate_f(struct dh_ctx *, Bignum f);
 Bignum dh_find_K(struct dh_ctx *, Bignum f);
 
-int rsa_ssh1_encrypted(const Filename *filename, char **comment);
+bool rsa_ssh1_encrypted(const Filename *filename, char **comment);
 int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
                      char **commentptr, const char **errorstr);
 int rsa_ssh1_loadkey(const Filename *filename, struct RSAKey *key,
                      const char *passphrase, const char **errorstr);
-int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
-                     char *passphrase);
+bool rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
+                      char *passphrase);
 
 extern int base64_decode_atom(const char *atom, unsigned char *out);
 extern int base64_lines(int datalen);
@@ -1104,15 +1119,15 @@ extern void base64_encode(FILE *fp, const unsigned char *data, int datalen,
 extern struct ssh2_userkey ssh2_wrong_passphrase;
 #define SSH2_WRONG_PASSPHRASE (&ssh2_wrong_passphrase)
 
-int ssh2_userkey_encrypted(const Filename *filename, char **comment);
+bool ssh2_userkey_encrypted(const Filename *filename, char **comment);
 struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
 				       const char *passphrase,
                                        const char **errorstr);
-int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
-                         BinarySink *bs,
-                         char **commentptr, const char **errorstr);
-int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
-		      char *passphrase);
+bool ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
+                          BinarySink *bs,
+                          char **commentptr, const char **errorstr);
+bool ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
+                       char *passphrase);
 const ssh_keyalg *find_pubkey_alg(const char *name);
 const ssh_keyalg *find_pubkey_alg_len(ptrlen name);
 
@@ -1170,17 +1185,17 @@ char *ssh2_fingerprint(ssh_key *key);
 int key_type(const Filename *filename);
 const char *key_type_to_str(int type);
 
-int import_possible(int type);
+bool import_possible(int type);
 int import_target_type(int type);
-int import_encrypted(const Filename *filename, int type, char **comment);
+bool import_encrypted(const Filename *filename, int type, char **comment);
 int import_ssh1(const Filename *filename, int type,
 		struct RSAKey *key, char *passphrase, const char **errmsg_p);
 struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
 				 char *passphrase, const char **errmsg_p);
-int export_ssh1(const Filename *filename, int type,
-		struct RSAKey *key, char *passphrase);
-int export_ssh2(const Filename *filename, int type,
-                struct ssh2_userkey *key, char *passphrase);
+bool export_ssh1(const Filename *filename, int type,
+                 struct RSAKey *key, char *passphrase);
+bool export_ssh2(const Filename *filename, int type,
+                 struct ssh2_userkey *key, char *passphrase);
 
 void des3_decrypt_pubkey(const void *key, void *blk, int len);
 void des3_encrypt_pubkey(const void *key, void *blk, int len);
@@ -1234,7 +1249,7 @@ enum { SHARE_NONE, SHARE_DOWNSTREAM, SHARE_UPSTREAM };
 int platform_ssh_share(const char *name, Conf *conf,
                        Plug *downplug, Plug *upplug, Socket **sock,
                        char **logtext, char **ds_err, char **us_err,
-                       int can_upstream, int can_downstream);
+                       bool can_upstream, bool can_downstream);
 void platform_ssh_share_cleanup(const char *name);
 
 /*
@@ -1452,7 +1467,7 @@ enum {
 
 struct ssh_ttymodes {
     /* A boolean per mode, indicating whether it's set. */
-    int have_mode[TTYMODE_LIMIT];
+    bool have_mode[TTYMODE_LIMIT];
 
     /* The actual value for each mode. */
     unsigned mode_val[TTYMODE_LIMIT];
@@ -1466,7 +1481,7 @@ void write_ttymodes_to_packet(BinarySink *bs, int ssh_version,
 
 const char *ssh1_pkt_type(int type);
 const char *ssh2_pkt_type(Pkt_KCtx pkt_kctx, Pkt_ACtx pkt_actx, int type);
-int ssh2_pkt_type_code_valid(unsigned type);
+bool ssh2_pkt_type_code_valid(unsigned type);
 
 /*
  * Need this to warn about support for the original SSH-2 keyfile
@@ -1508,11 +1523,11 @@ unsigned alloc_channel_id_general(tree234 *channels, size_t localid_offset);
     TYPECHECK(&((type *)0)->localid == (unsigned *)0, \
               alloc_channel_id_general(tree, offsetof(type, localid)))
 
-int first_in_commasep_string(char const *needle, char const *haystack,
-                             int haylen);
-int in_commasep_string(char const *needle, char const *haystack, int haylen);
+bool first_in_commasep_string(char const *needle, char const *haystack,
+                              int haylen);
+bool in_commasep_string(char const *needle, char const *haystack, int haylen);
 void add_to_commasep(strbuf *buf, const char *data);
-int get_commasep_word(ptrlen *list, ptrlen *word);
+bool get_commasep_word(ptrlen *list, ptrlen *word);
 
 int verify_ssh_manual_host_key(
     Conf *conf, const char *fingerprint, ssh_key *key);
@@ -1522,8 +1537,8 @@ ssh_transient_hostkey_cache *ssh_transient_hostkey_cache_new(void);
 void ssh_transient_hostkey_cache_free(ssh_transient_hostkey_cache *thc);
 void ssh_transient_hostkey_cache_add(
     ssh_transient_hostkey_cache *thc, ssh_key *key);
-int ssh_transient_hostkey_cache_verify(
+bool ssh_transient_hostkey_cache_verify(
     ssh_transient_hostkey_cache *thc, ssh_key *key);
-int ssh_transient_hostkey_cache_has(
+bool ssh_transient_hostkey_cache_has(
     ssh_transient_hostkey_cache *thc, const ssh_keyalg *alg);
-int ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc);
+bool ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc);

+ 6 - 6
source/putty/ssh1bpp.c

@@ -21,7 +21,7 @@ struct ssh1_bpp_state {
 
     struct crcda_ctx *crcda_ctx;
 
-    int pending_compression_request;
+    bool pending_compression_request;
     ssh_compressor *compctx;
     ssh_decompressor *decompctx;
 
@@ -145,7 +145,7 @@ static void ssh1_bpp_handle_input(BinaryPacketProtocol *bpp)
          */
         s->pktin = snew_plus(PktIn, s->biglen);
         s->pktin->qnode.prev = s->pktin->qnode.next = NULL;
-        s->pktin->qnode.on_free_queue = FALSE;
+        s->pktin->qnode.on_free_queue = false;
         s->pktin->type = 0;
 
         s->maxlen = s->biglen;
@@ -209,7 +209,7 @@ static void ssh1_bpp_handle_input(BinaryPacketProtocol *bpp)
         if (s->bpp.logctx) {
             logblank_t blanks[MAX_BLANKS];
             int nblanks = ssh1_censor_packet(
-                s->bpp.pls, s->pktin->type, FALSE,
+                s->bpp.pls, s->pktin->type, false,
                 make_ptrlen(s->data, s->length), blanks);
             log_packet(s->bpp.logctx, PKT_INCOMING, s->pktin->type,
                        ssh1_pkt_type(s->pktin->type),
@@ -244,7 +244,7 @@ static void ssh1_bpp_handle_input(BinaryPacketProtocol *bpp)
                      * schedule a run of our output side in case we
                      * had any packets queued up in the meantime.
                      */
-                    s->pending_compression_request = FALSE;
+                    s->pending_compression_request = false;
                     queue_idempotent_callback(&s->bpp.ic_out_pq);
                 }
                 break;
@@ -287,7 +287,7 @@ static void ssh1_bpp_format_packet(struct ssh1_bpp_state *s, PktOut *pkt)
                                      pkt->length - pkt->prefix);
         logblank_t blanks[MAX_BLANKS];
         int nblanks = ssh1_censor_packet(
-            s->bpp.pls, pkt->type, TRUE, pktdata, blanks);
+            s->bpp.pls, pkt->type, true, pktdata, blanks);
         log_packet(s->bpp.logctx, PKT_OUTGOING, pkt->type,
                    ssh1_pkt_type(pkt->type),
                    pktdata.ptr, pktdata.len, nblanks, blanks,
@@ -353,7 +353,7 @@ static void ssh1_bpp_handle_output(BinaryPacketProtocol *bpp)
              * the pending flag, and stop processing packets this
              * time.
              */
-            s->pending_compression_request = TRUE;
+            s->pending_compression_request = true;
             break;
         }
     }

+ 1 - 1
source/putty/ssh1censor.c

@@ -10,7 +10,7 @@
 #include "ssh.h"
 
 int ssh1_censor_packet(
-    const PacketLogSettings *pls, int type, int sender_is_client,
+    const PacketLogSettings *pls, int type, bool sender_is_client,
     ptrlen pkt, logblank_t *blanks)
 {
     int nblanks = 0;

+ 52 - 53
source/putty/ssh1connection-client.c

@@ -24,12 +24,12 @@ void ssh1_connection_direction_specific_setup(
          */
         s->mainchan = mainchan_new(
             &s->ppl, &s->cl, s->conf, s->term_width, s->term_height,
-            FALSE /* is_simple */, NULL);
+            false /* is_simple */, NULL);
     }
 }
 
 typedef void (*sf_handler_fn_t)(struct ssh1_connection_state *s,
-                                int success, void *ctx);
+                                bool success, void *ctx);
 
 struct outstanding_succfail {
     sf_handler_fn_t handler;
@@ -43,14 +43,14 @@ struct outstanding_succfail {
      * expect to get an acknowledgment regardless, so we arrange to
      * send that ack immediately after the rest of the queue empties.
      */
-    int trivial;
+    bool trivial;
 };
 
 static void ssh1_connection_process_trivial_succfails(void *vs);
 
 static void ssh1_queue_succfail_handler(
     struct ssh1_connection_state *s, sf_handler_fn_t handler, void *ctx,
-    int trivial)
+    bool trivial)
 {
     struct outstanding_succfail *osf = snew(struct outstanding_succfail);
     osf->handler = handler;
@@ -71,7 +71,7 @@ static void ssh1_queue_succfail_handler(
 }
 
 static void ssh1_connection_process_succfail(
-    struct ssh1_connection_state *s, int success)
+    struct ssh1_connection_state *s, bool success)
 {
     struct outstanding_succfail *prevhead = s->succfail_head;
     s->succfail_head = s->succfail_head->next;
@@ -85,10 +85,10 @@ static void ssh1_connection_process_trivial_succfails(void *vs)
 {
     struct ssh1_connection_state *s = (struct ssh1_connection_state *)vs;
     while (s->succfail_head && s->succfail_head->trivial)
-        ssh1_connection_process_succfail(s, TRUE);
+        ssh1_connection_process_succfail(s, true);
 }
 
-int ssh1_handle_direction_specific_packet(
+bool ssh1_handle_direction_specific_packet(
     struct ssh1_connection_state *s, PktIn *pktin)
 {
     PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
@@ -107,7 +107,7 @@ int ssh1_handle_direction_specific_packet(
             ssh_remote_error(s->ppl.ssh,
                              "Received %s with no outstanding request",
                              ssh1_pkt_type(pktin->type));
-            return TRUE;
+            return true;
         }
 
         ssh1_connection_process_succfail(
@@ -115,7 +115,7 @@ int ssh1_handle_direction_specific_packet(
         queue_toplevel_callback(
             ssh1_connection_process_trivial_succfails, s);
 
-        return TRUE;
+        return true;
 
       case SSH1_SMSG_X11_OPEN:
         remid = get_uint32(pktin);
@@ -133,9 +133,9 @@ int ssh1_handle_direction_specific_packet(
             ssh1_channel_init(c);
             c->remoteid = remid;
             c->chan = x11_new_channel(s->x11authtree, &c->sc,
-                                      NULL, -1, FALSE);
+                                      NULL, -1, false);
             c->remoteid = remid;
-            c->halfopen = FALSE;
+            c->halfopen = false;
 
             pktout = ssh_bpp_new_pktout(
                 s->ppl.bpp, SSH1_MSG_CHANNEL_OPEN_CONFIRMATION);
@@ -145,7 +145,7 @@ int ssh1_handle_direction_specific_packet(
             ppl_logevent(("Opened X11 forward channel"));
         }
 
-        return TRUE;
+        return true;
 
       case SSH1_SMSG_AGENT_OPEN:
         remid = get_uint32(pktin);
@@ -162,7 +162,7 @@ int ssh1_handle_direction_specific_packet(
             ssh1_channel_init(c);
             c->remoteid = remid;
             c->chan = agentf_new(&c->sc);
-            c->halfopen = FALSE;
+            c->halfopen = false;
 
             pktout = ssh_bpp_new_pktout(
                 s->ppl.bpp, SSH1_MSG_CHANNEL_OPEN_CONFIRMATION);
@@ -171,7 +171,7 @@ int ssh1_handle_direction_specific_packet(
             pq_push(s->ppl.out_pq, pktout);
         }
 
-        return TRUE;
+        return true;
 
       case SSH1_MSG_PORT_OPEN:
         remid = get_uint32(pktin);
@@ -211,7 +211,7 @@ int ssh1_handle_direction_specific_packet(
             } else {
                 ssh1_channel_init(c);
                 c->remoteid = remid;
-                c->halfopen = FALSE;
+                c->halfopen = false;
                 pktout = ssh_bpp_new_pktout(
                     s->ppl.bpp, SSH1_MSG_CHANNEL_OPEN_CONFIRMATION);
                 put_uint32(pktout, c->remoteid);
@@ -223,7 +223,7 @@ int ssh1_handle_direction_specific_packet(
 
         sfree(pf.dhost);
 
-        return TRUE;
+        return true;
 
       case SSH1_SMSG_STDOUT_DATA:
       case SSH1_SMSG_STDERR_DATA:
@@ -233,12 +233,12 @@ int ssh1_handle_direction_specific_packet(
                 s->ppl.seat, pktin->type == SSH1_SMSG_STDERR_DATA,
                 data.ptr, data.len);
             if (!s->stdout_throttling && bufsize > SSH1_BUFFER_LIMIT) {
-                s->stdout_throttling = 1;
+                s->stdout_throttling = true;
                 ssh_throttle_conn(s->ppl.ssh, +1);
             }
         }
 
-        return TRUE;
+        return true;
 
       case SSH1_SMSG_EXIT_STATUS:
         {
@@ -246,28 +246,28 @@ int ssh1_handle_direction_specific_packet(
             ppl_logevent(("Server sent command exit status %d", exitcode));
             ssh_got_exitcode(s->ppl.ssh, exitcode);
 
-            s->session_terminated = TRUE;
+            s->session_terminated = true;
         }
-        return TRUE;
+        return true;
 
       default:
-        return FALSE;
+        return false;
     }
 }
 
 static void ssh1mainchan_succfail_wantreply(struct ssh1_connection_state *s,
-                                            int success, void *ctx)
+                                            bool success, void *ctx)
 {
     chan_request_response(s->mainchan_chan, success);
 }
 
 static void ssh1mainchan_succfail_nowantreply(struct ssh1_connection_state *s,
-                                              int success, void *ctx)
+                                              bool success, void *ctx)
 {
 }
 
 static void ssh1mainchan_queue_response(struct ssh1_connection_state *s,
-                                        int want_reply, int trivial)
+                                        bool want_reply, bool trivial)
 {
     sf_handler_fn_t handler = (want_reply ? ssh1mainchan_succfail_wantreply :
                                ssh1mainchan_succfail_nowantreply);
@@ -275,8 +275,8 @@ static void ssh1mainchan_queue_response(struct ssh1_connection_state *s,
 }
 
 static void ssh1mainchan_request_x11_forwarding(
-    SshChannel *sc, int want_reply, const char *authproto,
-    const char *authdata, int screen_number, int oneshot)
+    SshChannel *sc, bool want_reply, const char *authproto,
+    const char *authdata, int screen_number, bool oneshot)
 {
     struct ssh1_connection_state *s =
         container_of(sc, struct ssh1_connection_state, mainchan_sc);
@@ -289,11 +289,11 @@ static void ssh1mainchan_request_x11_forwarding(
         put_uint32(pktout, screen_number);
     pq_push(s->ppl.out_pq, pktout);
 
-    ssh1mainchan_queue_response(s, want_reply, FALSE);
+    ssh1mainchan_queue_response(s, want_reply, false);
 }
 
 static void ssh1mainchan_request_agent_forwarding(
-    SshChannel *sc, int want_reply)
+    SshChannel *sc, bool want_reply)
 {
     struct ssh1_connection_state *s =
         container_of(sc, struct ssh1_connection_state, mainchan_sc);
@@ -303,11 +303,11 @@ static void ssh1mainchan_request_agent_forwarding(
         s->ppl.bpp, SSH1_CMSG_AGENT_REQUEST_FORWARDING);
     pq_push(s->ppl.out_pq, pktout);
 
-    ssh1mainchan_queue_response(s, want_reply, FALSE);
+    ssh1mainchan_queue_response(s, want_reply, false);
 }
 
 static void ssh1mainchan_request_pty(
-    SshChannel *sc, int want_reply, Conf *conf, int w, int h)
+    SshChannel *sc, bool want_reply, Conf *conf, int w, int h)
 {
     struct ssh1_connection_state *s =
         container_of(sc, struct ssh1_connection_state, mainchan_sc);
@@ -324,17 +324,16 @@ static void ssh1mainchan_request_pty(
         get_ttymodes_from_conf(s->ppl.seat, conf));
     pq_push(s->ppl.out_pq, pktout);
 
-    ssh1mainchan_queue_response(s, want_reply, FALSE);
+    ssh1mainchan_queue_response(s, want_reply, false);
 }
 
-static int ssh1mainchan_send_env_var(
-    SshChannel *sc, int want_reply, const char *var, const char *value)
+static bool ssh1mainchan_send_env_var(
+    SshChannel *sc, bool want_reply, const char *var, const char *value)
 {
-    return FALSE;              /* SSH-1 doesn't support this at all */
+    return false;              /* SSH-1 doesn't support this at all */
 }
 
-static void ssh1mainchan_start_shell(
-    SshChannel *sc, int want_reply)
+static void ssh1mainchan_start_shell(SshChannel *sc, bool want_reply)
 {
     struct ssh1_connection_state *s =
         container_of(sc, struct ssh1_connection_state, mainchan_sc);
@@ -343,11 +342,11 @@ static void ssh1mainchan_start_shell(
     pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_CMSG_EXEC_SHELL);
     pq_push(s->ppl.out_pq, pktout);
 
-    ssh1mainchan_queue_response(s, want_reply, TRUE);
+    ssh1mainchan_queue_response(s, want_reply, true);
 }
 
 static void ssh1mainchan_start_command(
-    SshChannel *sc, int want_reply, const char *command)
+    SshChannel *sc, bool want_reply, const char *command)
 {
     struct ssh1_connection_state *s =
         container_of(sc, struct ssh1_connection_state, mainchan_sc);
@@ -357,25 +356,25 @@ static void ssh1mainchan_start_command(
     put_stringz(pktout, command);
     pq_push(s->ppl.out_pq, pktout);
 
-    ssh1mainchan_queue_response(s, want_reply, TRUE);
+    ssh1mainchan_queue_response(s, want_reply, true);
 }
 
-static int ssh1mainchan_start_subsystem(
-    SshChannel *sc, int want_reply, const char *subsystem)
+static bool ssh1mainchan_start_subsystem(
+    SshChannel *sc, bool want_reply, const char *subsystem)
 {
-    return FALSE;              /* SSH-1 doesn't support this at all */
+    return false;              /* SSH-1 doesn't support this at all */
 }
 
-static int ssh1mainchan_send_serial_break(
-    SshChannel *sc, int want_reply, int length)
+static bool ssh1mainchan_send_serial_break(
+    SshChannel *sc, bool want_reply, int length)
 {
-    return FALSE;              /* SSH-1 doesn't support this at all */
+    return false;              /* SSH-1 doesn't support this at all */
 }
 
-static int ssh1mainchan_send_signal(
-    SshChannel *sc, int want_reply, const char *signame)
+static bool ssh1mainchan_send_signal(
+    SshChannel *sc, bool want_reply, const char *signame)
 {
-    return FALSE;              /* SSH-1 doesn't support this at all */
+    return false;              /* SSH-1 doesn't support this at all */
 }
 
 static void ssh1mainchan_send_terminal_size_change(
@@ -398,7 +397,7 @@ static void ssh1mainchan_hint_channel_is_simple(SshChannel *sc)
 }
 
 static int ssh1mainchan_write(
-    SshChannel *sc, int is_stderr, const void *data, int len)
+    SshChannel *sc, bool is_stderr, const void *data, int len)
 {
     struct ssh1_connection_state *s =
         container_of(sc, struct ssh1_connection_state, mainchan_sc);
@@ -463,7 +462,7 @@ SshChannel *ssh1_session_open(ConnectionLayer *cl, Channel *chan)
 }
 
 static void ssh1_rportfwd_response(struct ssh1_connection_state *s,
-                                   int success, void *ctx)
+                                   bool success, void *ctx)
 {
     PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
     struct ssh_rportfwd *rpf = (struct ssh_rportfwd *)ctx;
@@ -512,7 +511,7 @@ struct ssh_rportfwd *ssh1_rportfwd_alloc(
     put_uint32(pktout, rpf->dport);
     pq_push(s->ppl.out_pq, pktout);
 
-    ssh1_queue_succfail_handler(s, ssh1_rportfwd_response, rpf, FALSE);
+    ssh1_queue_succfail_handler(s, ssh1_rportfwd_response, rpf, false);
 
     return rpf;
 }
@@ -520,12 +519,12 @@ struct ssh_rportfwd *ssh1_rportfwd_alloc(
 SshChannel *ssh1_serverside_x11_open(
     ConnectionLayer *cl, Channel *chan, const SocketPeerInfo *pi)
 {
-    assert(FALSE && "Should never be called in the client");
+    assert(false && "Should never be called in the client");
     return NULL;
 }
 
 SshChannel *ssh1_serverside_agent_open(ConnectionLayer *cl, Channel *chan)
 {
-    assert(FALSE && "Should never be called in the client");
+    assert(false && "Should never be called in the client");
     return NULL;
 }

+ 43 - 43
source/putty/ssh1connection.c

@@ -31,7 +31,7 @@ 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);
-static int ssh1_connection_want_user_input(PacketProtocolLayer *ppl);
+static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl);
 static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl);
 static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
 
@@ -53,16 +53,16 @@ static SshChannel *ssh1_lportfwd_open(
     const char *description, const SocketPeerInfo *pi, Channel *chan);
 static struct X11FakeAuth *ssh1_add_x11_display(
     ConnectionLayer *cl, int authtype, struct X11Display *disp);
-static int ssh1_agent_forwarding_permitted(ConnectionLayer *cl);
+static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl);
 static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height);
 static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize);
 static int ssh1_stdin_backlog(ConnectionLayer *cl);
-static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled);
-static int ssh1_ldisc_option(ConnectionLayer *cl, int option);
-static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, int value);
+static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled);
+static bool ssh1_ldisc_option(ConnectionLayer *cl, int option);
+static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value);
 static void ssh1_enable_x_fwd(ConnectionLayer *cl);
 static void ssh1_enable_agent_fwd(ConnectionLayer *cl);
-static void ssh1_set_wants_user_input(ConnectionLayer *cl, int wanted);
+static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted);
 
 static const struct ConnectionLayerVtable ssh1_connlayer_vtable = {
     ssh1_rportfwd_alloc,
@@ -92,7 +92,7 @@ static const struct ConnectionLayerVtable ssh1_connlayer_vtable = {
 };
 
 static int ssh1channel_write(
-    SshChannel *c, int is_stderr, const void *buf, int len);
+    SshChannel *c, bool is_stderr, const void *buf, int len);
 static void ssh1channel_write_eof(SshChannel *c);
 static void ssh1channel_initiate_close(SshChannel *c, const char *err);
 static void ssh1channel_unthrottle(SshChannel *c, int bufsize);
@@ -224,19 +224,19 @@ void ssh1_connection_set_protoflags(PacketProtocolLayer *ppl,
     s->remote_protoflags = remote;
 }
 
-static int ssh1_connection_filter_queue(struct ssh1_connection_state *s)
+static bool ssh1_connection_filter_queue(struct ssh1_connection_state *s)
 {
     PktIn *pktin;
     ptrlen data;
     struct ssh1_channel *c;
     unsigned localid;
-    int expect_halfopen;
+    bool expect_halfopen;
 
     while (1) {
         if (ssh1_common_filter_queue(&s->ppl))
-            return TRUE;
+            return true;
         if ((pktin = pq_peek(s->ppl.in_pq)) == NULL)
-            return FALSE;
+            return false;
 
         switch (pktin->type) {
           case SSH1_MSG_CHANNEL_DATA:
@@ -263,15 +263,15 @@ static int ssh1_connection_filter_queue(struct ssh1_connection_state *s)
                     ssh1_pkt_type(pktin->type),
                     !c ? "nonexistent" : c->halfopen ? "half-open" : "open",
                     localid);
-                return TRUE;
+                return true;
             }
  
             switch (pktin->type) {
               case SSH1_MSG_CHANNEL_OPEN_CONFIRMATION:
                 assert(c->halfopen);
                 c->remoteid = get_uint32(pktin);
-                c->halfopen = FALSE;
-                c->throttling_conn = FALSE;
+                c->halfopen = false;
+                c->throttling_conn = false;
 
                 chan_open_confirmation(c->chan);
 
@@ -288,7 +288,7 @@ static int ssh1_connection_filter_queue(struct ssh1_connection_state *s)
                  * message. We'll have handled that in this code by
                  * having already turned c->chan into a zombie, so its
                  * want_close method (which ssh1_channel_check_close
-                 * will consult) will already be returning TRUE.
+                 * will consult) will already be returning true.
                  */
                 ssh1_channel_check_close(c);
 
@@ -310,10 +310,10 @@ static int ssh1_connection_filter_queue(struct ssh1_connection_state *s)
                 data = get_string(pktin);
                 if (!get_err(pktin)) {
                     int bufsize = chan_send(
-                        c->chan, FALSE, data.ptr, data.len);
+                        c->chan, false, data.ptr, data.len);
 
                     if (!c->throttling_conn && bufsize > SSH1_BUFFER_LIMIT) {
-                        c->throttling_conn = TRUE;
+                        c->throttling_conn = true;
                         ssh_throttle_conn(s->ppl.ssh, +1);
                     }
                 }
@@ -335,7 +335,7 @@ static int ssh1_connection_filter_queue(struct ssh1_connection_state *s)
                             "Received CHANNEL_CLOSE_CONFIRMATION for channel"
                             " %u for which we never sent CHANNEL_CLOSE\n",
                             c->localid);
-                        return TRUE;
+                        return true;
                     }
 
                     c->closes |= CLOSES_RCVD_CLOSECONF;
@@ -351,9 +351,9 @@ static int ssh1_connection_filter_queue(struct ssh1_connection_state *s)
             if (ssh1_handle_direction_specific_packet(s, pktin)) {
                 pq_pop(s->ppl.in_pq);
                 if (ssh1_check_termination(s))
-                    return TRUE;
+                    return true;
             } else {
-                return FALSE;
+                return false;
             }
         }
     }
@@ -377,7 +377,7 @@ static void ssh1_connection_process_queue(PacketProtocolLayer *ppl)
     crBegin(s->crState);
 
     portfwdmgr_config(s->portfwdmgr, s->conf);
-    s->portfwdmgr_configured = TRUE;
+    s->portfwdmgr_configured = true;
 
     while (!s->finished_setup) {
         ssh1_connection_direction_specific_setup(s);
@@ -460,7 +460,7 @@ static void ssh1_channel_try_eof(struct ssh1_channel *c)
     if (c->halfopen)
         return;                 /* can't close: not even opened yet */
 
-    c->pending_eof = FALSE;            /* we're about to send it */
+    c->pending_eof = false;            /* we're about to send it */
 
     pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_CHANNEL_CLOSE);
     put_uint32(pktout, c->remoteid);
@@ -511,7 +511,7 @@ static void ssh1_channel_destroy(struct ssh1_channel *c)
     queue_toplevel_callback(ssh1_check_termination_callback, s);
 }
 
-int ssh1_check_termination(struct ssh1_connection_state *s)
+bool ssh1_check_termination(struct ssh1_connection_state *s)
 {
     /*
      * Decide whether we should terminate the SSH connection now.
@@ -525,10 +525,10 @@ int ssh1_check_termination(struct ssh1_connection_state *s)
         pq_push(s->ppl.out_pq, pktout);
 
         ssh_user_close(s->ppl.ssh, "Session finished");
-        return TRUE;
+        return true;
     }
 
-    return FALSE;
+    return false;
 }
 
 /*
@@ -539,8 +539,8 @@ void ssh1_channel_init(struct ssh1_channel *c)
 {
     struct ssh1_connection_state *s = c->connlayer;
     c->closes = 0;
-    c->pending_eof = FALSE;
-    c->throttling_conn = FALSE;
+    c->pending_eof = false;
+    c->throttling_conn = false;
     c->sc.vt = &ssh1channel_vtable;
     c->sc.cl = &s->cl;
     c->localid = alloc_channel_id(s->channels, struct ssh1_channel);
@@ -561,7 +561,7 @@ static void ssh1channel_write_eof(SshChannel *sc)
     if (c->closes & CLOSES_SENT_CLOSE)
         return;
 
-    c->pending_eof = TRUE;
+    c->pending_eof = true;
     ssh1_channel_try_eof(c);
 }
 
@@ -573,7 +573,7 @@ static void ssh1channel_initiate_close(SshChannel *sc, const char *err)
     reason = err ? dupprintf("due to local error: %s", err) : NULL;
     ssh1_channel_close_local(c, reason);
     sfree(reason);
-    c->pending_eof = FALSE;   /* this will confuse a zombie channel */
+    c->pending_eof = false;   /* this will confuse a zombie channel */
 
     ssh1_channel_check_close(c);
 }
@@ -584,13 +584,13 @@ static void ssh1channel_unthrottle(SshChannel *sc, int bufsize)
     struct ssh1_connection_state *s = c->connlayer;
 
     if (c->throttling_conn && bufsize <= SSH1_BUFFER_LIMIT) {
-	c->throttling_conn = 0;
+	c->throttling_conn = false;
 	ssh_throttle_conn(s->ppl.ssh, -1);
     }
 }
 
 static int ssh1channel_write(
-    SshChannel *sc, int is_stderr, const void *buf, int len)
+    SshChannel *sc, bool is_stderr, const void *buf, int len)
 {
     struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc);
     struct ssh1_connection_state *s = c->connlayer;
@@ -634,7 +634,7 @@ static SshChannel *ssh1_lportfwd_open(
 
     c->connlayer = s;
     ssh1_channel_init(c);
-    c->halfopen = TRUE;
+    c->halfopen = true;
     c->chan = chan;
 
     ppl_logevent(("Opening connection to %s:%d for %s",
@@ -659,11 +659,11 @@ static void ssh1_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf)
      */
 }
 
-static int ssh1_agent_forwarding_permitted(ConnectionLayer *cl)
+static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl)
 {
     struct ssh1_connection_state *s =
         container_of(cl, struct ssh1_connection_state, cl);
-    return conf_get_int(s->conf, CONF_agentfwd) && agent_exists();
+    return conf_get_bool(s->conf, CONF_agentfwd) && agent_exists();
 }
 
 static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl,
@@ -701,7 +701,7 @@ static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize)
         container_of(cl, struct ssh1_connection_state, cl);
 
     if (s->stdout_throttling && bufsize < SSH1_BUFFER_LIMIT) {
-        s->stdout_throttling = 0;
+        s->stdout_throttling = false;
         ssh_throttle_conn(s->ppl.ssh, -1);
     }
 }
@@ -711,7 +711,7 @@ static int ssh1_stdin_backlog(ConnectionLayer *cl)
     return 0;
 }
 
-static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled)
+static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled)
 {
     struct ssh1_connection_state *s =
         container_of(cl, struct ssh1_connection_state, cl);
@@ -722,7 +722,7 @@ static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled)
         chan_set_input_wanted(c->chan, !throttled);
 }
 
-static int ssh1_ldisc_option(ConnectionLayer *cl, int option)
+static bool ssh1_ldisc_option(ConnectionLayer *cl, int option)
 {
     struct ssh1_connection_state *s =
         container_of(cl, struct ssh1_connection_state, cl);
@@ -730,7 +730,7 @@ static int ssh1_ldisc_option(ConnectionLayer *cl, int option)
     return s->ldisc_opts[option];
 }
 
-static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, int value)
+static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value)
 {
     struct ssh1_connection_state *s =
         container_of(cl, struct ssh1_connection_state, cl);
@@ -743,7 +743,7 @@ static void ssh1_enable_x_fwd(ConnectionLayer *cl)
     struct ssh1_connection_state *s =
         container_of(cl, struct ssh1_connection_state, cl);
 
-    s->X11_fwd_enabled = TRUE;
+    s->X11_fwd_enabled = true;
 }
 
 static void ssh1_enable_agent_fwd(ConnectionLayer *cl)
@@ -751,19 +751,19 @@ static void ssh1_enable_agent_fwd(ConnectionLayer *cl)
     struct ssh1_connection_state *s =
         container_of(cl, struct ssh1_connection_state, cl);
 
-    s->agent_fwd_enabled = TRUE;
+    s->agent_fwd_enabled = true;
 }
 
-static void ssh1_set_wants_user_input(ConnectionLayer *cl, int wanted)
+static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted)
 {
     struct ssh1_connection_state *s =
         container_of(cl, struct ssh1_connection_state, cl);
 
     s->want_user_input = wanted;
-    s->finished_setup = TRUE;
+    s->finished_setup = true;
 }
 
-static int ssh1_connection_want_user_input(PacketProtocolLayer *ppl)
+static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl)
 {
     struct ssh1_connection_state *s =
         container_of(ppl, struct ssh1_connection_state, ppl);

+ 16 - 16
source/putty/ssh1connection.h

@@ -21,25 +21,25 @@ struct ssh1_connection_state {
     Channel *mainchan_chan;            /* the other end of mainchan_sc */
     mainchan *mainchan;                /* and its subtype */
 
-    int got_pty;
-    int ldisc_opts[LD_N_OPTIONS];
-    int stdout_throttling;
-    int want_user_input;
-    int session_terminated;
+    bool got_pty;
+    bool ldisc_opts[LD_N_OPTIONS];
+    bool stdout_throttling;
+    bool want_user_input;
+    bool session_terminated;
     int term_width, term_height, term_width_orig, term_height_orig;
 
-    int X11_fwd_enabled;
+    bool X11_fwd_enabled;
     struct X11Display *x11disp;
     struct X11FakeAuth *x11auth;
     tree234 *x11authtree;
 
-    int agent_fwd_enabled;
+    bool agent_fwd_enabled;
 
     tree234 *rportfwds;
     PortFwdManager *portfwdmgr;
-    int portfwdmgr_configured;
+    bool portfwdmgr_configured;
 
-    int finished_setup;
+    bool finished_setup;
 
     /*
      * These store the list of requests that we're waiting for
@@ -49,7 +49,7 @@ struct ssh1_connection_state {
      */
     struct outstanding_succfail *succfail_head, *succfail_tail;
 
-    int compressing;                   /* used in server mode only */
+    bool compressing;                  /* used in server mode only */
 
     ConnectionLayer cl;
     PacketProtocolLayer ppl;
@@ -61,7 +61,7 @@ struct ssh1_channel {
     unsigned remoteid, localid;
     int type;
     /* True if we opened this channel but server hasn't confirmed. */
-    int halfopen;
+    bool halfopen;
 
     /* Bitmap of whether we've sent/received CHANNEL_CLOSE and
      * CHANNEL_CLOSE_CONFIRMATION. */
@@ -79,13 +79,13 @@ struct ssh1_channel {
      * we set this flag instead to remind us to do so once our buffer
      * is clear.
      */
-    int pending_eof;
+    bool pending_eof;
 
     /*
      * True if this channel is causing the underlying connection to be
      * throttled.
      */
-    int throttling_conn;
+    bool throttling_conn;
 
     /*
      * True if we currently have backed-up data on the direction of
@@ -93,7 +93,7 @@ struct ssh1_channel {
      * would prefer the 'Channel' implementation not to read further
      * local input if possible.
      */
-    int throttled_by_backlog;
+    bool throttled_by_backlog;
 
     Channel *chan;      /* handle the client side of this channel, if not */
     SshChannel sc;      /* entry point for chan to talk back to */
@@ -113,7 +113,7 @@ SshChannel *ssh1_serverside_agent_open(ConnectionLayer *cl, Channel *chan);
 
 void ssh1_connection_direction_specific_setup(
     struct ssh1_connection_state *s);
-int ssh1_handle_direction_specific_packet(
+bool ssh1_handle_direction_specific_packet(
     struct ssh1_connection_state *s, PktIn *pktin);
 
-int ssh1_check_termination(struct ssh1_connection_state *s);
+bool ssh1_check_termination(struct ssh1_connection_state *s);

+ 51 - 51
source/putty/ssh1login.c

@@ -20,7 +20,7 @@ struct ssh1_login_state {
 
     char *savedhost;
     int savedport;
-    int try_agent_auth;
+    bool try_agent_auth;
 
     int remote_protoflags;
     int local_protoflags;
@@ -31,14 +31,14 @@ struct ssh1_login_state {
     int len;
     unsigned char *rsabuf;
     unsigned long supported_ciphers_mask, supported_auths_mask;
-    int tried_publickey, tried_agent;
-    int tis_auth_refused, ccard_auth_refused;
+    bool tried_publickey, tried_agent;
+    bool tis_auth_refused, ccard_auth_refused;
     unsigned char cookie[8];
     unsigned char session_id[16];
     int cipher_type;
     strbuf *publickey_blob;
     char *publickey_comment;
-    int privatekey_available, privatekey_encrypted;
+    bool privatekey_available, privatekey_encrypted;
     prompts_t *cur_prompt;
     int userpass_ret;
     char c;
@@ -47,14 +47,14 @@ struct ssh1_login_state {
     ptrlen agent_response;
     BinarySource asrc[1];          /* response from SSH agent */
     int keyi, nkeys;
-    int authed;
+    bool authed;
     struct RSAKey key;
     Bignum challenge;
     ptrlen comment;
     int dlgret;
     Filename *keyfile;
     struct RSAKey servkey, hostkey;
-    int want_user_input;
+    bool want_user_input;
 
     PacketProtocolLayer ppl;
 };
@@ -64,7 +64,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *);
 static void ssh1_login_dialog_callback(void *, int);
 static void ssh1_login_special_cmd(PacketProtocolLayer *ppl,
                                    SessionSpecialCode code, int arg);
-static int ssh1_login_want_user_input(PacketProtocolLayer *ppl);
+static bool ssh1_login_want_user_input(PacketProtocolLayer *ppl);
 static void ssh1_login_got_user_input(PacketProtocolLayer *ppl);
 static void ssh1_login_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
 
@@ -120,7 +120,7 @@ static void ssh1_login_free(PacketProtocolLayer *ppl)
     sfree(s);
 }
 
-static int ssh1_login_filter_queue(struct ssh1_login_state *s)
+static bool ssh1_login_filter_queue(struct ssh1_login_state *s)
 {
     return ssh1_common_filter_queue(&s->ppl);
 }
@@ -279,7 +279,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
     ppl_logevent(("Encrypted session key"));
 
     {
-        int cipher_chosen = 0, warn = 0;
+        bool cipher_chosen = false, warn = false;
         const char *cipher_string = NULL;
         int i;
 	for (i = 0; !cipher_chosen && i < CIPHER_MAX; i++) {
@@ -287,7 +287,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                 s->conf, CONF_ssh_cipherlist, i);
             if (next_cipher == CIPHER_WARN) {
                 /* If/when we choose a cipher, warn about it */
-                warn = 1;
+                warn = true;
             } else if (next_cipher == CIPHER_AES) {
                 /* XXX Probably don't need to mention this. */
                 ppl_logevent(("AES not supported in SSH-1, skipping"));
@@ -301,7 +301,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                     cipher_string = "single-DES"; break;
                 }
                 if (s->supported_ciphers_mask & (1 << s->cipher_type))
-                    cipher_chosen = 1;
+                    cipher_chosen = true;
             }
         }
         if (!cipher_chosen) {
@@ -394,9 +394,9 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
 
     if ((s->username = get_remote_username(s->conf)) == NULL) {
         s->cur_prompt = new_prompts();
-        s->cur_prompt->to_server = TRUE;
+        s->cur_prompt->to_server = true;
         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) {
@@ -408,9 +408,9 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
             if (s->userpass_ret >= 0)
                 break;
 
-            s->want_user_input = TRUE;
+            s->want_user_input = true;
             crReturnV;
-            s->want_user_input = FALSE;
+            s->want_user_input = false;
         }
         if (!s->userpass_ret) {
             /*
@@ -436,11 +436,11 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
 
     if (!(s->supported_auths_mask & (1 << SSH1_AUTH_RSA))) {
         /* We must not attempt PK auth. Pretend we've already tried it. */
-        s->tried_publickey = s->tried_agent = TRUE;
+        s->tried_publickey = s->tried_agent = true;
     } else {
-        s->tried_publickey = s->tried_agent = FALSE;
+        s->tried_publickey = s->tried_agent = false;
     }
-    s->tis_auth_refused = s->ccard_auth_refused = FALSE;
+    s->tis_auth_refused = s->ccard_auth_refused = false;
 
     /*
      * Load the public half of any configured keyfile for later use.
@@ -481,7 +481,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
 
     /* Check whether we're configured to try Pageant, and also whether
      * it's available. */
-    s->try_agent_auth = (conf_get_int(s->conf, CONF_tryagent) &&
+    s->try_agent_auth = (conf_get_bool(s->conf, CONF_tryagent) &&
                          agent_exists());
 
     while (pktin->type == SSH1_SMSG_FAILURE) {
@@ -491,8 +491,8 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
             /*
              * Attempt RSA authentication using Pageant.
              */
-            s->authed = FALSE;
-            s->tried_agent = 1;
+            s->authed = false;
+            s->tried_agent = true;
             ppl_logevent(("Pageant is running. Requesting keys."));
 
             /* Request the keys held by the agent. */
@@ -535,7 +535,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                                     s->publickey_blob->len)) {
                             ppl_logevent(("Pageant key #%d matches "
                                           "configured key file", s->keyi));
-                            s->tried_publickey = 1;
+                            s->tried_publickey = true;
                         } else
                             /* Skip non-configured key */
                             continue;
@@ -597,7 +597,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                                                     "agent\r\n", PTRLEN_PRINTF(
                                                         s->comment)));
                                     }
-                                    s->authed = TRUE;
+                                    s->authed = true;
                                 } else
                                     ppl_logevent(("Pageant's response not "
                                                   "accepted"));
@@ -632,13 +632,13 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
              * Try public key authentication with the specified
              * key file.
              */
-            int got_passphrase; /* need not be kept over crReturn */
+            bool got_passphrase; /* need not be kept over crReturn */
             if (flags & FLAG_VERBOSE)
                 ppl_printf(("Trying public key authentication.\r\n"));
             ppl_logevent(("Trying public key \"%s\"",
                           filename_to_str(s->keyfile)));
-            s->tried_publickey = 1;
-            got_passphrase = FALSE;
+            s->tried_publickey = true;
+            got_passphrase = false;
             while (!got_passphrase) {
                 /*
                  * Get a passphrase, if necessary.
@@ -652,11 +652,11 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                     passphrase = NULL;
                 } else {
                     s->cur_prompt = new_prompts(s->ppl.seat);
-                    s->cur_prompt->to_server = FALSE;
+                    s->cur_prompt->to_server = false;
                     s->cur_prompt->name = dupstr("SSH key passphrase");
                     add_prompt(s->cur_prompt,
                                dupprintf("Passphrase for key \"%.100s\": ",
-                                         s->publickey_comment), FALSE);
+                                         s->publickey_comment), false);
                     s->userpass_ret = seat_get_userpass_input(
                         s->ppl.seat, s->cur_prompt, NULL);
                     while (1) {
@@ -668,9 +668,9 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                         if (s->userpass_ret >= 0)
                             break;
 
-                        s->want_user_input = TRUE;
+                        s->want_user_input = true;
                         crReturnV;
-                        s->want_user_input = FALSE;
+                        s->want_user_input = false;
                     }
                     if (!s->userpass_ret) {
                         /* Failed to get a passphrase. Terminate. */
@@ -693,19 +693,19 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                 }
                 if (retd == 1) {
                     /* Correct passphrase. */
-                    got_passphrase = TRUE;
+                    got_passphrase = true;
                 } else if (retd == 0) {
                     ppl_printf(("Couldn't load private key from %s (%s).\r\n",
                                 filename_to_str(s->keyfile), error));
-                    got_passphrase = FALSE;
+                    got_passphrase = false;
                     break;             /* go and try something else */
                 } else if (retd == -1) {
                     ppl_printf(("Wrong passphrase.\r\n"));
-                    got_passphrase = FALSE;
+                    got_passphrase = false;
                     /* and try again */
                 } else {
                     assert(0 && "unexpected return from rsa_ssh1_loadkey()");
-                    got_passphrase = FALSE;   /* placate optimisers */
+                    got_passphrase = false;   /* placate optimisers */
                 }
             }
 
@@ -793,7 +793,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
          */
         s->cur_prompt = new_prompts(s->ppl.seat);
 
-        if (conf_get_int(s->conf, CONF_try_tis_auth) &&
+        if (conf_get_bool(s->conf, CONF_try_tis_auth) &&
             (s->supported_auths_mask & (1 << SSH1_AUTH_TIS)) &&
             !s->tis_auth_refused) {
             s->pwpkt_type = SSH1_CMSG_AUTH_TIS_RESPONSE;
@@ -805,7 +805,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                 ppl_logevent(("TIS authentication declined"));
                 if (flags & FLAG_INTERACTIVE)
                     ppl_printf(("TIS authentication refused.\r\n"));
-                s->tis_auth_refused = 1;
+                s->tis_auth_refused = true;
                 continue;
             } else if (pktin->type == SSH1_SMSG_AUTH_TIS_CHALLENGE) {
                 ptrlen challenge;
@@ -818,7 +818,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                     return;
                 }
                 ppl_logevent(("Received TIS challenge"));
-                s->cur_prompt->to_server = TRUE;
+                s->cur_prompt->to_server = true;
                 s->cur_prompt->name = dupstr("SSH TIS authentication");
                 /* Prompt heuristic comes from OpenSSH */
                 if (!memchr(challenge.ptr, '\n', challenge.len)) {
@@ -832,8 +832,8 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                     dupprintf("Using TIS authentication.%s%s",
                               (*instr_suf) ? "\n" : "",
                               instr_suf);
-                s->cur_prompt->instr_reqd = TRUE;
-                add_prompt(s->cur_prompt, prompt, FALSE);
+                s->cur_prompt->instr_reqd = true;
+                add_prompt(s->cur_prompt, prompt, false);
                 sfree(instr_suf);
             } else {
                 ssh_proto_error(s->ppl.ssh, "Received unexpected packet"
@@ -842,7 +842,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                                 ssh1_pkt_type(pktin->type));
                 return;
             }
-        } else if (conf_get_int(s->conf, CONF_try_tis_auth) &&
+        } else if (conf_get_bool(s->conf, CONF_try_tis_auth) &&
             (s->supported_auths_mask & (1 << SSH1_AUTH_CCARD)) &&
             !s->ccard_auth_refused) {
             s->pwpkt_type = SSH1_CMSG_AUTH_CCARD_RESPONSE;
@@ -853,7 +853,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
             if (pktin->type == SSH1_SMSG_FAILURE) {
                 ppl_logevent(("CryptoCard authentication declined"));
                 ppl_printf(("CryptoCard authentication refused.\r\n"));
-                s->ccard_auth_refused = 1;
+                s->ccard_auth_refused = true;
                 continue;
             } else if (pktin->type == SSH1_SMSG_AUTH_CCARD_CHALLENGE) {
                 ptrlen challenge;
@@ -866,9 +866,9 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                     return;
                 }
                 ppl_logevent(("Received CryptoCard challenge"));
-                s->cur_prompt->to_server = TRUE;
+                s->cur_prompt->to_server = true;
                 s->cur_prompt->name = dupstr("SSH CryptoCard authentication");
-                s->cur_prompt->name_reqd = FALSE;
+                s->cur_prompt->name_reqd = false;
                 /* Prompt heuristic comes from OpenSSH */
                 if (!memchr(challenge.ptr, '\n', challenge.len)) {
                     instr_suf = dupstr("");
@@ -881,8 +881,8 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                     dupprintf("Using CryptoCard authentication.%s%s",
                               (*instr_suf) ? "\n" : "",
                               instr_suf);
-                s->cur_prompt->instr_reqd = TRUE;
-                add_prompt(s->cur_prompt, prompt, FALSE);
+                s->cur_prompt->instr_reqd = true;
+                add_prompt(s->cur_prompt, prompt, false);
                 sfree(instr_suf);
             } else {
                 ssh_proto_error(s->ppl.ssh, "Received unexpected packet"
@@ -898,11 +898,11 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
                              "available");
                 return;
             }
-            s->cur_prompt->to_server = TRUE;
+            s->cur_prompt->to_server = true;
             s->cur_prompt->name = dupstr("SSH password");
             add_prompt(s->cur_prompt, dupprintf("%s@%s's password: ",
                                                 s->username, s->savedhost),
-                       FALSE);
+                       false);
         }
 
         /*
@@ -921,9 +921,9 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
             if (s->userpass_ret >= 0)
                 break;
 
-            s->want_user_input = TRUE;
+            s->want_user_input = true;
             crReturnV;
-            s->want_user_input = FALSE;
+            s->want_user_input = false;
         }
         if (!s->userpass_ret) {
             /*
@@ -1059,7 +1059,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
 
     ppl_logevent(("Authentication successful"));
 
-    if (conf_get_int(s->conf, CONF_compression)) {
+    if (conf_get_bool(s->conf, CONF_compression)) {
         ppl_logevent(("Requesting compression"));
         pkt = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_CMSG_REQUEST_COMPRESSION);
         put_uint32(pkt, 6);         /* gzip compression level */
@@ -1145,7 +1145,7 @@ static void ssh1_login_special_cmd(PacketProtocolLayer *ppl,
     }
 }
 
-static int ssh1_login_want_user_input(PacketProtocolLayer *ppl)
+static bool ssh1_login_want_user_input(PacketProtocolLayer *ppl)
 {
     struct ssh1_login_state *s =
         container_of(ppl, struct ssh1_login_state, ppl);

+ 3 - 3
source/putty/ssh2bpp-bare.c

@@ -85,7 +85,7 @@ static void ssh2_bare_bpp_handle_input(BinaryPacketProtocol *bpp)
          */
         s->pktin = snew_plus(PktIn, s->packetlen);
         s->pktin->qnode.prev = s->pktin->qnode.next = NULL;
-        s->pktin->qnode.on_free_queue = FALSE;
+        s->pktin->qnode.on_free_queue = false;
         s->maxlen = 0;
         s->data = snew_plus_get_aux(s->pktin);
 
@@ -111,7 +111,7 @@ static void ssh2_bare_bpp_handle_input(BinaryPacketProtocol *bpp)
         if (s->bpp.logctx) {
             logblank_t blanks[MAX_BLANKS];
             int nblanks = ssh2_censor_packet(
-                s->bpp.pls, s->pktin->type, FALSE,
+                s->bpp.pls, s->pktin->type, false,
                 make_ptrlen(s->data, s->packetlen), blanks);
             log_packet(s->bpp.logctx, PKT_INCOMING, s->pktin->type,
                        ssh2_pkt_type(s->bpp.pls->kctx, s->bpp.pls->actx,
@@ -158,7 +158,7 @@ static void ssh2_bare_bpp_format_packet(struct ssh2_bare_bpp_state *s,
         ptrlen pktdata = make_ptrlen(pkt->data + 5, pkt->length - 5);
         logblank_t blanks[MAX_BLANKS];
         int nblanks = ssh2_censor_packet(
-            s->bpp.pls, pkt->type, TRUE, pktdata, blanks);
+            s->bpp.pls, pkt->type, true, pktdata, blanks);
         log_packet(s->bpp.logctx, PKT_OUTGOING, pkt->type,
                    ssh2_pkt_type(s->bpp.pls->kctx, s->bpp.pls->actx,
                                  pkt->type),

+ 22 - 22
source/putty/ssh2bpp.c

@@ -13,7 +13,7 @@ struct ssh2_bpp_direction {
     unsigned long sequence;
     ssh2_cipher *cipher;
     ssh2_mac *mac;
-    int etm_mode;
+    bool etm_mode;
     const struct ssh_compression_alg *pending_compression;
 };
 
@@ -26,7 +26,7 @@ struct ssh2_bpp_state {
     unsigned cipherblk;
     PktIn *pktin;
     struct DataTransferStats *stats;
-    int cbc_ignore_workaround;
+    bool cbc_ignore_workaround;
 
     struct ssh2_bpp_direction in, out;
     /* comp and decomp logically belong in the per-direction
@@ -34,9 +34,9 @@ struct ssh2_bpp_state {
     ssh_decompressor *in_decomp;
     ssh_compressor *out_comp;
 
-    int is_server;
-    int pending_newkeys;
-    int pending_compression, seen_userauth_success;
+    bool is_server;
+    bool pending_newkeys;
+    bool pending_compression, seen_userauth_success;
 
     BinaryPacketProtocol bpp;
 };
@@ -55,7 +55,7 @@ static const struct BinaryPacketProtocolVtable ssh2_bpp_vtable = {
 };
 
 BinaryPacketProtocol *ssh2_bpp_new(
-    LogContext *logctx, struct DataTransferStats *stats, int is_server)
+    LogContext *logctx, struct DataTransferStats *stats, bool is_server)
 {
     struct ssh2_bpp_state *s = snew(struct ssh2_bpp_state);
     memset(s, 0, sizeof(*s));
@@ -90,8 +90,8 @@ static void ssh2_bpp_free(BinaryPacketProtocol *bpp)
 void ssh2_bpp_new_outgoing_crypto(
     BinaryPacketProtocol *bpp,
     const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
-    const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
-    const struct ssh_compression_alg *compression, int delayed_compression)
+    const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key,
+    const struct ssh_compression_alg *compression, bool delayed_compression)
 {
     struct ssh2_bpp_state *s;
     assert(bpp->vt == &ssh2_bpp_vtable);
@@ -117,7 +117,7 @@ void ssh2_bpp_new_outgoing_crypto(
                       ssh2_cipher_alg(s->out.cipher)->text_name));
     } else {
         s->out.cipher = NULL;
-        s->cbc_ignore_workaround = FALSE;
+        s->cbc_ignore_workaround = false;
     }
     s->out.etm_mode = etm_mode;
     if (mac) {
@@ -157,8 +157,8 @@ void ssh2_bpp_new_outgoing_crypto(
 void ssh2_bpp_new_incoming_crypto(
     BinaryPacketProtocol *bpp,
     const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
-    const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
-    const struct ssh_compression_alg *compression, int delayed_compression)
+    const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key,
+    const struct ssh_compression_alg *compression, bool delayed_compression)
 {
     struct ssh2_bpp_state *s;
     assert(bpp->vt == &ssh2_bpp_vtable);
@@ -217,14 +217,14 @@ void ssh2_bpp_new_incoming_crypto(
 
     /* Clear the pending_newkeys flag, so that handle_input below will
      * start consuming the input data again. */
-    s->pending_newkeys = FALSE;
+    s->pending_newkeys = false;
 
     /* And schedule a run of handle_input, in case there's already
      * input data in the queue. */
     queue_idempotent_callback(&s->bpp.ic_in_raw);
 }
 
-int ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp)
+bool ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp)
 {
     struct ssh2_bpp_state *s;
     assert(bpp->vt == &ssh2_bpp_vtable);
@@ -349,7 +349,7 @@ static void ssh2_bpp_handle_input(BinaryPacketProtocol *bpp)
             s->pktin = snew_plus(PktIn, s->maxlen);
             s->pktin->qnode.prev = s->pktin->qnode.next = NULL;
             s->pktin->type = 0;
-            s->pktin->qnode.on_free_queue = FALSE;
+            s->pktin->qnode.on_free_queue = false;
             s->data = snew_plus_get_aux(s->pktin);
             memcpy(s->data, s->buf, s->maxlen);
         } else if (s->in.mac && s->in.etm_mode) {
@@ -399,7 +399,7 @@ static void ssh2_bpp_handle_input(BinaryPacketProtocol *bpp)
             s->pktin = snew_plus(PktIn, OUR_V2_PACKETLIMIT + s->maclen);
             s->pktin->qnode.prev = s->pktin->qnode.next = NULL;
             s->pktin->type = 0;
-            s->pktin->qnode.on_free_queue = FALSE;
+            s->pktin->qnode.on_free_queue = false;
             s->data = snew_plus_get_aux(s->pktin);
             memcpy(s->data, s->buf, 4);
 
@@ -465,7 +465,7 @@ static void ssh2_bpp_handle_input(BinaryPacketProtocol *bpp)
             s->pktin = snew_plus(PktIn, s->maxlen);
             s->pktin->qnode.prev = s->pktin->qnode.next = NULL;
             s->pktin->type = 0;
-            s->pktin->qnode.on_free_queue = FALSE;
+            s->pktin->qnode.on_free_queue = false;
             s->data = snew_plus_get_aux(s->pktin);
             memcpy(s->data, s->buf, s->cipherblk);
 
@@ -562,7 +562,7 @@ static void ssh2_bpp_handle_input(BinaryPacketProtocol *bpp)
         if (s->bpp.logctx) {
             logblank_t blanks[MAX_BLANKS];
             int nblanks = ssh2_censor_packet(
-                s->bpp.pls, s->pktin->type, FALSE,
+                s->bpp.pls, s->pktin->type, false,
                 make_ptrlen(s->data, s->length), blanks);
             log_packet(s->bpp.logctx, PKT_INCOMING, s->pktin->type,
                        ssh2_pkt_type(s->bpp.pls->kctx, s->bpp.pls->actx,
@@ -590,7 +590,7 @@ static void ssh2_bpp_handle_input(BinaryPacketProtocol *bpp)
                  * the transport layer has initialised the new keys by
                  * calling ssh2_bpp_new_incoming_crypto above.
                  */
-                s->pending_newkeys = TRUE;
+                s->pending_newkeys = true;
                 crWaitUntilV(!s->pending_newkeys);
                 continue;
             }
@@ -611,7 +611,7 @@ static void ssh2_bpp_handle_input(BinaryPacketProtocol *bpp)
                  * that a delayed compression method enabled in any
                  * future rekey will be treated as un-delayed.
                  */
-                s->seen_userauth_success = TRUE;
+                s->seen_userauth_success = true;
             }
 
             if (s->pending_compression && userauth_range(type)) {
@@ -627,7 +627,7 @@ static void ssh2_bpp_handle_input(BinaryPacketProtocol *bpp)
                  * to authenticate. The next userauth packet we send
                  * will re-block the output direction.
                  */
-                s->pending_compression = FALSE;
+                s->pending_compression = false;
                 queue_idempotent_callback(&s->bpp.ic_out_pq);
             }
         }
@@ -665,7 +665,7 @@ static void ssh2_bpp_format_packet_inner(struct ssh2_bpp_state *s, PktOut *pkt)
                                      pkt->length - pkt->prefix);
         logblank_t blanks[MAX_BLANKS];
         int nblanks = ssh2_censor_packet(
-            s->bpp.pls, pkt->type, TRUE, pktdata, blanks);
+            s->bpp.pls, pkt->type, true, pktdata, blanks);
         log_packet(s->bpp.logctx, PKT_OUTGOING, pkt->type,
                    ssh2_pkt_type(s->bpp.pls->kctx, s->bpp.pls->actx,
                                  pkt->type),
@@ -894,7 +894,7 @@ static void ssh2_bpp_handle_output(BinaryPacketProtocol *bpp)
              * USERAUTH_SUCCESS. Block (non-userauth) outgoing packets
              * until we see the reply.
              */
-            s->pending_compression = TRUE;
+            s->pending_compression = true;
             return;
         } else if (type == SSH2_MSG_USERAUTH_SUCCESS && s->is_server) {
             ssh2_bpp_enable_pending_compression(s);

+ 1 - 1
source/putty/ssh2censor.c

@@ -10,7 +10,7 @@
 #include "ssh.h"
 
 int ssh2_censor_packet(
-    const PacketLogSettings *pls, int type, int sender_is_client,
+    const PacketLogSettings *pls, int type, bool sender_is_client,
     ptrlen pkt, logblank_t *blanks)
 {
     int nblanks = 0;

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

@@ -124,14 +124,14 @@ ChanopenResult ssh2_connection_parse_channel_open(
     }
 }
 
-int ssh2_connection_parse_global_request(
+bool ssh2_connection_parse_global_request(
     struct ssh2_connection_state *s, ptrlen type, PktIn *pktin)
 {
     /*
      * We don't know of any global requests that an SSH client needs
      * to honour.
      */
-    return FALSE;
+    return false;
 }
 
 PktOut *ssh2_portfwd_chanopen(
@@ -240,7 +240,7 @@ struct ssh_rportfwd *ssh2_rportfwd_alloc(
         PktOut *pktout = ssh_bpp_new_pktout(
             s->ppl.bpp, SSH2_MSG_GLOBAL_REQUEST);
         put_stringz(pktout, "tcpip-forward");
-        put_bool(pktout, 1);       /* want reply */
+        put_bool(pktout, true);       /* want reply */
         put_stringz(pktout, rpf->shost);
         put_uint32(pktout, rpf->sport);
         pq_push(s->ppl.out_pq, pktout);
@@ -268,7 +268,7 @@ void ssh2_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf)
         PktOut *pktout = ssh_bpp_new_pktout(
             s->ppl.bpp, SSH2_MSG_GLOBAL_REQUEST);
         put_stringz(pktout, "cancel-tcpip-forward");
-        put_bool(pktout, 0);           /* _don't_ want reply */
+        put_bool(pktout, false);           /* _don't_ want reply */
         put_stringz(pktout, rpf->shost);
         put_uint32(pktout, rpf->sport);
         pq_push(s->ppl.out_pq, pktout);
@@ -290,7 +290,7 @@ SshChannel *ssh2_session_open(ConnectionLayer *cl, Channel *chan)
 
     c->connlayer = s;
     ssh2_channel_init(c);
-    c->halfopen = TRUE;
+    c->halfopen = true;
     c->chan = chan;
 
     ppl_logevent(("Opening main session channel"));
@@ -304,13 +304,13 @@ SshChannel *ssh2_session_open(ConnectionLayer *cl, Channel *chan)
 SshChannel *ssh2_serverside_x11_open(
     ConnectionLayer *cl, Channel *chan, const SocketPeerInfo *pi)
 {
-    assert(FALSE && "Should never be called in the client");
+    assert(false && "Should never be called in the client");
     return 0;                          /* placate optimiser */
 }
 
 SshChannel *ssh2_serverside_agent_open(ConnectionLayer *cl, Channel *chan)
 {
-    assert(FALSE && "Should never be called in the client");
+    assert(false && "Should never be called in the client");
     return 0;                          /* placate optimiser */
 }
 
@@ -320,7 +320,7 @@ static void ssh2_channel_response(
     chan_request_response(c->chan, pkt->type == SSH2_MSG_CHANNEL_SUCCESS);
 }
 
-void ssh2channel_start_shell(SshChannel *sc, int want_reply)
+void ssh2channel_start_shell(SshChannel *sc, bool want_reply)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     struct ssh2_connection_state *s = c->connlayer;
@@ -331,7 +331,7 @@ void ssh2channel_start_shell(SshChannel *sc, int want_reply)
 }
 
 void ssh2channel_start_command(
-    SshChannel *sc, int want_reply, const char *command)
+    SshChannel *sc, bool want_reply, const char *command)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     struct ssh2_connection_state *s = c->connlayer;
@@ -342,8 +342,8 @@ void ssh2channel_start_command(
     pq_push(s->ppl.out_pq, pktout);
 }
 
-int ssh2channel_start_subsystem(
-    SshChannel *sc, int want_reply, const char *subsystem)
+bool ssh2channel_start_subsystem(
+    SshChannel *sc, bool want_reply, const char *subsystem)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     struct ssh2_connection_state *s = c->connlayer;
@@ -353,29 +353,29 @@ int ssh2channel_start_subsystem(
     put_stringz(pktout, subsystem);
     pq_push(s->ppl.out_pq, pktout);
 
-    return TRUE;
+    return true;
 }
 
 void ssh2channel_send_exit_status(SshChannel *sc, int status)
 {
-    assert(FALSE && "Should never be called in the client");
+    assert(false && "Should never be called in the client");
 }
 
 void ssh2channel_send_exit_signal(
-    SshChannel *sc, ptrlen signame, int core_dumped, ptrlen msg)
+    SshChannel *sc, ptrlen signame, bool core_dumped, ptrlen msg)
 {
-    assert(FALSE && "Should never be called in the client");
+    assert(false && "Should never be called in the client");
 }
 
 void ssh2channel_send_exit_signal_numeric(
-    SshChannel *sc, int signum, int core_dumped, ptrlen msg)
+    SshChannel *sc, int signum, bool core_dumped, ptrlen msg)
 {
-    assert(FALSE && "Should never be called in the client");
+    assert(false && "Should never be called in the client");
 }
 
 void ssh2channel_request_x11_forwarding(
-    SshChannel *sc, int want_reply, const char *authproto,
-    const char *authdata, int screen_number, int oneshot)
+    SshChannel *sc, bool want_reply, const char *authproto,
+    const char *authdata, int screen_number, bool oneshot)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     struct ssh2_connection_state *s = c->connlayer;
@@ -389,7 +389,7 @@ void ssh2channel_request_x11_forwarding(
     pq_push(s->ppl.out_pq, pktout);
 }
 
-void ssh2channel_request_agent_forwarding(SshChannel *sc, int want_reply)
+void ssh2channel_request_agent_forwarding(SshChannel *sc, bool want_reply)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     struct ssh2_connection_state *s = c->connlayer;
@@ -401,7 +401,7 @@ void ssh2channel_request_agent_forwarding(SshChannel *sc, int want_reply)
 }
 
 void ssh2channel_request_pty(
-    SshChannel *sc, int want_reply, Conf *conf, int w, int h)
+    SshChannel *sc, bool want_reply, Conf *conf, int w, int h)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     struct ssh2_connection_state *s = c->connlayer;
@@ -422,8 +422,8 @@ void ssh2channel_request_pty(
     pq_push(s->ppl.out_pq, pktout);
 }
 
-int ssh2channel_send_env_var(
-    SshChannel *sc, int want_reply, const char *var, const char *value)
+bool ssh2channel_send_env_var(
+    SshChannel *sc, bool want_reply, const char *var, const char *value)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     struct ssh2_connection_state *s = c->connlayer;
@@ -434,10 +434,10 @@ int ssh2channel_send_env_var(
     put_stringz(pktout, value);
     pq_push(s->ppl.out_pq, pktout);
 
-    return TRUE;
+    return true;
 }
 
-int ssh2channel_send_serial_break(SshChannel *sc, int want_reply, int length)
+bool ssh2channel_send_serial_break(SshChannel *sc, bool want_reply, int length)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     struct ssh2_connection_state *s = c->connlayer;
@@ -447,11 +447,11 @@ int ssh2channel_send_serial_break(SshChannel *sc, int want_reply, int length)
     put_uint32(pktout, length);
     pq_push(s->ppl.out_pq, pktout);
 
-    return TRUE;
+    return true;
 }
 
-int ssh2channel_send_signal(
-    SshChannel *sc, int want_reply, const char *signame)
+bool ssh2channel_send_signal(
+    SshChannel *sc, bool want_reply, const char *signame)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     struct ssh2_connection_state *s = c->connlayer;
@@ -461,7 +461,7 @@ int ssh2channel_send_signal(
     put_stringz(pktout, signame);
     pq_push(s->ppl.out_pq, pktout);
 
-    return TRUE;
+    return true;
 }
 
 void ssh2channel_send_terminal_size_change(SshChannel *sc, int w, int h)

+ 54 - 60
source/putty/ssh2connection.c

@@ -14,11 +14,11 @@
 
 static void ssh2_connection_free(PacketProtocolLayer *); 
 static void ssh2_connection_process_queue(PacketProtocolLayer *);
-static int ssh2_connection_get_specials(
+static bool ssh2_connection_get_specials(
     PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
 static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl,
                                         SessionSpecialCode code, int arg);
-static int ssh2_connection_want_user_input(PacketProtocolLayer *ppl);
+static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl);
 static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl);
 static void ssh2_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
 
@@ -53,16 +53,16 @@ static void ssh2_delete_sharing_channel(
 static void ssh2_sharing_queue_global_request(
     ConnectionLayer *cl, ssh_sharing_connstate *share_ctx);
 static void ssh2_sharing_no_more_downstreams(ConnectionLayer *cl);
-static int ssh2_agent_forwarding_permitted(ConnectionLayer *cl);
+static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl);
 static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height);
 static void ssh2_stdout_unthrottle(ConnectionLayer *cl, int bufsize);
 static int ssh2_stdin_backlog(ConnectionLayer *cl);
-static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled);
-static int ssh2_ldisc_option(ConnectionLayer *cl, int option);
-static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, int value);
+static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled);
+static bool ssh2_ldisc_option(ConnectionLayer *cl, int option);
+static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value);
 static void ssh2_enable_x_fwd(ConnectionLayer *cl);
 static void ssh2_enable_agent_fwd(ConnectionLayer *cl);
-static void ssh2_set_wants_user_input(ConnectionLayer *cl, int wanted);
+static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted);
 
 static const struct ConnectionLayerVtable ssh2_connlayer_vtable = {
     ssh2_rportfwd_alloc,
@@ -119,7 +119,7 @@ static char *ssh2_channel_open_failure_error_text(PktIn *pktin)
 }
 
 static int ssh2channel_write(
-    SshChannel *c, int is_stderr, const void *buf, int len);
+    SshChannel *c, bool is_stderr, const void *buf, int len);
 static void ssh2channel_write_eof(SshChannel *c);
 static void ssh2channel_initiate_close(SshChannel *c, const char *err);
 static void ssh2channel_unthrottle(SshChannel *c, int bufsize);
@@ -239,7 +239,7 @@ static void ssh2_channel_free(struct ssh2_channel *c)
 }
 
 PacketProtocolLayer *ssh2_connection_new(
-    Ssh *ssh, ssh_sharing_state *connshare, int is_simple,
+    Ssh *ssh, ssh_sharing_state *connshare, bool is_simple,
     Conf *conf, const char *peer_verstring, ConnectionLayer **cl_out)
 {
     struct ssh2_connection_state *s = snew(struct ssh2_connection_state);
@@ -256,7 +256,7 @@ PacketProtocolLayer *ssh2_connection_new(
      * any at all channels (because our purpose is probably to be a
      * background port forwarder).
      */
-    s->persistent = conf_get_int(s->conf, CONF_ssh_no_shell);
+    s->persistent = conf_get_bool(s->conf, CONF_ssh_no_shell);
 
     s->connshare = connshare;
     s->peer_verstring = dupstr(peer_verstring);
@@ -313,7 +313,7 @@ static void ssh2_connection_free(PacketProtocolLayer *ppl)
     sfree(s);
 }
 
-static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
+static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s)
 {
     PktIn *pktin;
     PktOut *pktout;
@@ -321,22 +321,15 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
     struct ssh2_channel *c;
     struct outstanding_channel_request *ocr;
     unsigned localid, remid, winsize, pktsize, ext_type;
-    int want_reply, reply_success, expect_halfopen;
+    bool want_reply, reply_success, expect_halfopen;
     ChanopenResult chanopen_result;
     PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
 
-    /* Cross-reference to ssh2transport.c to handle the common packets
-     * between login and connection: DISCONNECT, DEBUG and IGNORE. If
-     * we have an instance of ssh2transport below us, then those
-     * messages won't come here anyway, but they could if we're
-     * running in bare ssh2-connection mode. */
-    extern int ssh2_common_filter_queue(PacketProtocolLayer *ppl);
-
     while (1) {
         if (ssh2_common_filter_queue(&s->ppl))
-            return TRUE;
+            return true;
         if ((pktin = pq_peek(s->ppl.in_pq)) == NULL)
-            return FALSE;
+            return false;
 
         switch (pktin->type) {
           case SSH2_MSG_GLOBAL_REQUEST:
@@ -363,7 +356,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                     "Received %s with no outstanding global request",
                     ssh2_pkt_type(s->ppl.bpp->pls->kctx, s->ppl.bpp->pls->actx,
                                   pktin->type));
-                return TRUE;
+                return true;
             }
 
             s->globreq_head->handler(s, pktin, s->globreq_head->ctx);
@@ -405,7 +398,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
             }
 
             c->remoteid = remid;
-            c->halfopen = FALSE;
+            c->halfopen = false;
             if (chanopen_result.outcome == CHANOPEN_RESULT_FAILURE) {
                 pktout = ssh_bpp_new_pktout(
                     s->ppl.bpp, SSH2_MSG_CHANNEL_OPEN_FAILURE);
@@ -479,14 +472,14 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                                 (!c ? "nonexistent" :
                                  c->halfopen ? "half-open" : "open"),
                                 localid);
-                return TRUE;
+                return true;
             }
  
             switch (pktin->type) {
               case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:
                 assert(c->halfopen);
                 c->remoteid = get_uint32(pktin);
-                c->halfopen = FALSE;
+                c->halfopen = false;
                 c->remwindow = get_uint32(pktin);
                 c->remmaxpkt = get_uint32(pktin);
 
@@ -505,7 +498,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                  * message. We'll have handled that in this code by
                  * having already turned c->chan into a zombie, so its
                  * want_close method (which ssh2_channel_check_close
-                 * will consult) will already be returning TRUE.
+                 * will consult) will already be returning true.
                  */
                 ssh2_channel_check_close(c);
 
@@ -569,7 +562,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                     if ((bufsize > c->locmaxwin ||
                          (s->ssh_is_simple && bufsize>0)) &&
                         !c->throttling_conn) {
-                        c->throttling_conn = TRUE;
+                        c->throttling_conn = true;
                         ssh_throttle_conn(s->ppl.ssh, +1);
                     }
                 }
@@ -586,7 +579,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                 type = get_string(pktin);
                 want_reply = get_bool(pktin);
 
-                reply_success = FALSE;
+                reply_success = false;
 
                 if (c->closes & CLOSES_SENT_CLOSE) {
                     /*
@@ -596,7 +589,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                      * side's CHANNEL_CLOSE and arrive after they have
                      * wound the channel up completely.
                      */
-                    want_reply = FALSE;
+                    want_reply = false;
                 }
 
                 /*
@@ -610,7 +603,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                 } else if (ptrlen_eq_string(type, "exit-signal")) {
                     ptrlen signame;
                     int signum;
-                    int core = FALSE;
+                    bool core = false;
                     ptrlen errmsg;
                     int format;
 
@@ -657,7 +650,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                         break;
                       default:
                         /* Couldn't parse this message in either format */
-                        reply_success = FALSE;
+                        reply_success = false;
                         break;
                     }
                 } else if (ptrlen_eq_string(type, "shell")) {
@@ -669,7 +662,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                     ptrlen subsys = get_string(pktin);
                     reply_success = chan_run_subsystem(c->chan, subsys);
                 } else if (ptrlen_eq_string(type, "x11-req")) {
-                    int oneshot = get_bool(pktin);
+                    bool oneshot = get_bool(pktin);
                     ptrlen authproto = get_string(pktin);
                     ptrlen authdata = get_string(pktin);
                     unsigned screen_number = get_uint32(pktin);
@@ -694,7 +687,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                     if (get_err(bs_modes) || get_avail(bs_modes) > 0) {
                         ppl_logevent(("Unable to decode terminal mode "
                                       "string"));
-                        reply_success = FALSE;
+                        reply_success = false;
                     } else {
                         reply_success = chan_allocate_pty(
                             c->chan, termtype, width, height,
@@ -740,7 +733,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
                         "channel request",
                         ssh2_pkt_type(s->ppl.bpp->pls->kctx,
                                       s->ppl.bpp->pls->actx, pktin->type));
-                    return TRUE;
+                    return true;
                 }
                 ocr->handler(c, pktin, ocr->ctx);
                 c->chanreq_head = ocr->next;
@@ -839,7 +832,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
             break;
 
           default:
-            return FALSE;
+            return false;
         }
     }
 }
@@ -966,7 +959,7 @@ static void ssh2_connection_process_queue(PacketProtocolLayer *ppl)
      * Enable port forwardings.
      */
     portfwdmgr_config(s->portfwdmgr, s->conf);
-    s->portfwdmgr_configured = TRUE;
+    s->portfwdmgr_configured = true;
 
     /*
      * Create the main session channel, if any.
@@ -1051,7 +1044,7 @@ static void ssh2_channel_try_eof(struct ssh2_channel *c)
     if (bufchain_size(&c->outbuffer) > 0 || bufchain_size(&c->errbuffer) > 0)
         return;              /* can't send EOF: pending outgoing data */
 
-    c->pending_eof = FALSE;            /* we're about to send it */
+    c->pending_eof = false;            /* we're about to send it */
 
     pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_EOF);
     put_uint32(pktout, c->remoteid);
@@ -1120,7 +1113,7 @@ static void ssh2_try_send_and_unthrottle(struct ssh2_channel *c)
 	return;                   /* don't send on channels we've EOFed */
     bufsize = ssh2_try_send(c);
     if (bufsize == 0) {
-        c->throttled_by_backlog = FALSE;
+        c->throttled_by_backlog = false;
         ssh2_channel_check_throttle(c);
     }
 }
@@ -1227,9 +1220,9 @@ void ssh2_channel_init(struct ssh2_channel *c)
 {
     struct ssh2_connection_state *s = c->connlayer;
     c->closes = 0;
-    c->pending_eof = FALSE;
-    c->throttling_conn = FALSE;
-    c->throttled_by_backlog = FALSE;
+    c->pending_eof = false;
+    c->throttling_conn = false;
+    c->throttled_by_backlog = false;
     c->sharectx = NULL;
     c->locwindow = c->locmaxwin = c->remlocwin =
         s->ssh_is_simple ? OUR_V2_BIGWIN : OUR_V2_WINSIZE;
@@ -1313,7 +1306,7 @@ static void ssh2channel_write_eof(SshChannel *sc)
     if (c->closes & CLOSES_SENT_EOF)
         return;
 
-    c->pending_eof = TRUE;
+    c->pending_eof = true;
     ssh2_channel_try_eof(c);
 }
 
@@ -1325,7 +1318,7 @@ static void ssh2channel_initiate_close(SshChannel *sc, const char *err)
     reason = err ? dupprintf("due to local error: %s", err) : NULL;
     ssh2_channel_close_local(c, reason);
     sfree(reason);
-    c->pending_eof = FALSE;   /* this will confuse a zombie channel */
+    c->pending_eof = false;   /* this will confuse a zombie channel */
 
     ssh2_channel_check_close(c);
 }
@@ -1341,13 +1334,13 @@ static void ssh2channel_unthrottle(SshChannel *sc, int bufsize)
         ssh2_set_window(c, buflimit - bufsize);
 
     if (c->throttling_conn && bufsize <= buflimit) {
-	c->throttling_conn = 0;
+	c->throttling_conn = false;
 	ssh_throttle_conn(s->ppl.ssh, -1);
     }
 }
 
 static int ssh2channel_write(
-    SshChannel *sc, int is_stderr, const void *buf, int len)
+    SshChannel *sc, bool is_stderr, const void *buf, int len)
 {
     struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
     assert(!(c->closes & CLOSES_SENT_EOF));
@@ -1414,7 +1407,7 @@ static SshChannel *ssh2_lportfwd_open(
 
     c->connlayer = s;
     ssh2_channel_init(c);
-    c->halfopen = TRUE;
+    c->halfopen = true;
     c->chan = chan;
 
     pktout = ssh2_portfwd_chanopen(s, c, hostname, port, description, pi);
@@ -1522,23 +1515,23 @@ static void ssh2_send_packet_from_downstream(
     pq_push(s->ppl.out_pq, pkt);
 }
 
-static int ssh2_agent_forwarding_permitted(ConnectionLayer *cl)
+static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl)
 {
     struct ssh2_connection_state *s =
         container_of(cl, struct ssh2_connection_state, cl);
-    return conf_get_int(s->conf, CONF_agentfwd) && agent_exists();
+    return conf_get_bool(s->conf, CONF_agentfwd) && agent_exists();
 }
 
-static int ssh2_connection_get_specials(
+static bool ssh2_connection_get_specials(
     PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx)
 {
     struct ssh2_connection_state *s =
         container_of(ppl, struct ssh2_connection_state, ppl);
-    int toret = FALSE;
+    bool toret = false;
 
     if (s->mainchan) {
         mainchan_get_specials(s->mainchan, add_special, ctx);
-        toret = TRUE;
+        toret = true;
     }
 
     /*
@@ -1551,7 +1544,7 @@ static int ssh2_connection_get_specials(
             add_special(ctx, NULL, SS_SEP, 0);
 
         add_special(ctx, "IGNORE message", SS_NOP, 0);
-        toret = TRUE;
+        toret = true;
     }
 
     return toret;
@@ -1608,7 +1601,7 @@ static int ssh2_stdin_backlog(ConnectionLayer *cl)
         bufchain_size(&c->outbuffer) + bufchain_size(&c->errbuffer) : 0;
 }
 
-static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled)
+static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled)
 {
     struct ssh2_connection_state *s =
         container_of(cl, struct ssh2_connection_state, cl);
@@ -1618,10 +1611,11 @@ static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled)
     s->all_channels_throttled = throttled;
 
     for (i = 0; NULL != (c = index234(s->channels, i)); i++)
-        ssh2_channel_check_throttle(c);
+        if (!c->sharectx)
+            ssh2_channel_check_throttle(c);
 }
 
-static int ssh2_ldisc_option(ConnectionLayer *cl, int option)
+static bool ssh2_ldisc_option(ConnectionLayer *cl, int option)
 {
     struct ssh2_connection_state *s =
         container_of(cl, struct ssh2_connection_state, cl);
@@ -1629,7 +1623,7 @@ static int ssh2_ldisc_option(ConnectionLayer *cl, int option)
     return s->ldisc_opts[option];
 }
 
-static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, int value)
+static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value)
 {
     struct ssh2_connection_state *s =
         container_of(cl, struct ssh2_connection_state, cl);
@@ -1642,7 +1636,7 @@ static void ssh2_enable_x_fwd(ConnectionLayer *cl)
     struct ssh2_connection_state *s =
         container_of(cl, struct ssh2_connection_state, cl);
 
-    s->X11_fwd_enabled = TRUE;
+    s->X11_fwd_enabled = true;
 }
 
 static void ssh2_enable_agent_fwd(ConnectionLayer *cl)
@@ -1650,10 +1644,10 @@ static void ssh2_enable_agent_fwd(ConnectionLayer *cl)
     struct ssh2_connection_state *s =
         container_of(cl, struct ssh2_connection_state, cl);
 
-    s->agent_fwd_enabled = TRUE;
+    s->agent_fwd_enabled = true;
 }
 
-static void ssh2_set_wants_user_input(ConnectionLayer *cl, int wanted)
+static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted)
 {
     struct ssh2_connection_state *s =
         container_of(cl, struct ssh2_connection_state, cl);
@@ -1661,7 +1655,7 @@ static void ssh2_set_wants_user_input(ConnectionLayer *cl, int wanted)
     s->want_user_input = wanted;
 }
 
-static int ssh2_connection_want_user_input(PacketProtocolLayer *ppl)
+static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl)
 {
     struct ssh2_connection_state *s =
         container_of(ppl, struct ssh2_connection_state, ppl);

+ 32 - 32
source/putty/ssh2connection.h

@@ -14,28 +14,28 @@ struct ssh2_connection_state {
 
     mainchan *mainchan;
     SshChannel *mainchan_sc;
-    int ldisc_opts[LD_N_OPTIONS];
+    bool ldisc_opts[LD_N_OPTIONS];
     int session_attempt, session_status;
     int term_width, term_height;
-    int want_user_input;
+    bool want_user_input;
 
-    int ssh_is_simple;
-    int persistent;
+    bool ssh_is_simple;
+    bool persistent;
 
     Conf *conf;
 
     tree234 *channels;		       /* indexed by local id */
-    int all_channels_throttled;
+    bool all_channels_throttled;
 
-    int X11_fwd_enabled;
+    bool X11_fwd_enabled;
     tree234 *x11authtree;
 
-    int got_pty;
-    int agent_fwd_enabled;
+    bool got_pty;
+    bool agent_fwd_enabled;
 
     tree234 *rportfwds;
     PortFwdManager *portfwdmgr;
-    int portfwdmgr_configured;
+    bool portfwdmgr_configured;
 
     const SftpServerVtable *sftpserver_vt;
 
@@ -62,7 +62,7 @@ struct ssh2_channel {
     unsigned remoteid, localid;
     int type;
     /* True if we opened this channel but server hasn't confirmed. */
-    int halfopen;
+    bool halfopen;
 
     /* Bitmap of whether we've sent/received CHANNEL_EOF and
      * CHANNEL_CLOSE. */
@@ -80,13 +80,13 @@ struct ssh2_channel {
      * we set this flag instead to remind us to do so once our buffer
      * is clear.
      */
-    int pending_eof;
+    bool pending_eof;
 
     /*
      * True if this channel is causing the underlying connection to be
      * throttled.
      */
-    int throttling_conn;
+    bool throttling_conn;
 
     /*
      * True if we currently have backed-up data on the direction of
@@ -94,7 +94,7 @@ struct ssh2_channel {
      * would prefer the 'Channel' implementation not to read further
      * local input if possible.
      */
-    int throttled_by_backlog;
+    bool throttled_by_backlog;
 
     bufchain outbuffer, errbuffer;
     unsigned remwindow, remmaxpkt;
@@ -172,28 +172,28 @@ SshChannel *ssh2_serverside_agent_open(ConnectionLayer *cl, Channel *chan);
 
 void ssh2channel_send_exit_status(SshChannel *c, int status);
 void ssh2channel_send_exit_signal(
-    SshChannel *c, ptrlen signame, int core_dumped, ptrlen msg);
+    SshChannel *c, ptrlen signame, bool core_dumped, ptrlen msg);
 void ssh2channel_send_exit_signal_numeric(
-    SshChannel *c, int signum, int core_dumped, ptrlen msg);
+    SshChannel *c, int signum, bool core_dumped, ptrlen msg);
 void ssh2channel_request_x11_forwarding(
-    SshChannel *c, int want_reply, const char *authproto,
-    const char *authdata, int screen_number, int oneshot);
-void ssh2channel_request_agent_forwarding(SshChannel *c, int want_reply);
+    SshChannel *c, bool want_reply, const char *authproto,
+    const char *authdata, int screen_number, bool oneshot);
+void ssh2channel_request_agent_forwarding(SshChannel *c, bool want_reply);
 void ssh2channel_request_pty(
-    SshChannel *c, int want_reply, Conf *conf, int w, int h);
-int ssh2channel_send_env_var(
-    SshChannel *c, int want_reply, const char *var, const char *value);
-void ssh2channel_start_shell(SshChannel *c, int want_reply);
+    SshChannel *c, bool want_reply, Conf *conf, int w, int h);
+bool ssh2channel_send_env_var(
+    SshChannel *c, bool want_reply, const char *var, const char *value);
+void ssh2channel_start_shell(SshChannel *c, bool want_reply);
 void ssh2channel_start_command(
-    SshChannel *c, int want_reply, const char *command);
-int ssh2channel_start_subsystem(
-    SshChannel *c, int want_reply, const char *subsystem);
-int ssh2channel_send_env_var(
-    SshChannel *c, int want_reply, const char *var, const char *value);
-int ssh2channel_send_serial_break(
-    SshChannel *c, int want_reply, int length);
-int ssh2channel_send_signal(
-    SshChannel *c, int want_reply, const char *signame);
+    SshChannel *c, bool want_reply, const char *command);
+bool ssh2channel_start_subsystem(
+    SshChannel *c, bool want_reply, const char *subsystem);
+bool ssh2channel_send_env_var(
+    SshChannel *c, bool want_reply, const char *var, const char *value);
+bool ssh2channel_send_serial_break(
+    SshChannel *c, bool want_reply, int length);
+bool ssh2channel_send_signal(
+    SshChannel *c, bool want_reply, const char *signame);
 void ssh2channel_send_terminal_size_change(SshChannel *c, int w, int h);
 
 #define CHANOPEN_RETURN_FAILURE(code, msgparams) do             \
@@ -225,7 +225,7 @@ ChanopenResult ssh2_connection_parse_channel_open(
     struct ssh2_connection_state *s, ptrlen type,
     PktIn *pktin, SshChannel *sc);
 
-int ssh2_connection_parse_global_request(
+bool ssh2_connection_parse_global_request(
     struct ssh2_connection_state *s, ptrlen type, PktIn *pktin);
 
 #endif /* PUTTY_SSH2CONNECTION_H */

+ 19 - 12
source/putty/ssh2kex-client.c

@@ -87,17 +87,24 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
             s->dh_ctx = dh_setup_gex(s->p, s->g);
             s->kex_init_value = SSH2_MSG_KEX_DH_GEX_INIT;
             s->kex_reply_value = SSH2_MSG_KEX_DH_GEX_REPLY;
+
+            ppl_logevent(("Doing Diffie-Hellman key exchange using %d-bit "
+                          "modulus and hash %s with a server-supplied group",
+                          dh_modulus_bit_size(s->dh_ctx),
+                          s->kex_alg->hash->text_name));
         } else {
             s->ppl.bpp->pls->kctx = SSH2_PKTCTX_DHGROUP;
             s->dh_ctx = dh_setup_group(s->kex_alg);
             s->kex_init_value = SSH2_MSG_KEXDH_INIT;
             s->kex_reply_value = SSH2_MSG_KEXDH_REPLY;
-            ppl_logevent(("Using Diffie-Hellman with standard group \"%s\"",
+
+            ppl_logevent(("Doing Diffie-Hellman key exchange using %d-bit "
+                          "modulus and hash %s with standard group \"%s\"",
+                          dh_modulus_bit_size(s->dh_ctx),
+                          s->kex_alg->hash->text_name,
                           s->kex_alg->groupname));
         }
 
-        ppl_logevent(("Doing Diffie-Hellman key exchange with hash %s",
-                      s->kex_alg->hash->text_name));
         /*
          * Now generate and send e for Diffie-Hellman.
          */
@@ -230,8 +237,8 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
         ptrlen data;
 
         s->ppl.bpp->pls->kctx = SSH2_PKTCTX_GSSKEX;
-        s->init_token_sent = 0;
-        s->complete_rcvd = 0;
+        s->init_token_sent = false;
+        s->complete_rcvd = false;
         s->hkey = NULL;
         s->fingerprint = NULL;
         s->keystr = NULL;
@@ -349,7 +356,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
                    s->gss_stat == SSH_GSS_S_CONTINUE_NEEDED);
 
             if (!s->init_token_sent) {
-                s->init_token_sent = 1;
+                s->init_token_sent = true;
                 pktout = ssh_bpp_new_pktout(s->ppl.bpp,
                                             SSH2_MSG_KEXGSS_INIT);
                 if (s->gss_sndtok.length == 0) {
@@ -385,7 +392,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
                 s->gss_rcvtok.length = data.len;
                 continue;
               case SSH2_MSG_KEXGSS_COMPLETE:
-                s->complete_rcvd = 1;
+                s->complete_rcvd = true;
                 s->f = get_mp_ssh2(pktin);
                 data = get_string(pktin);
                 s->mic.value = (char *)data.ptr;
@@ -618,7 +625,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
             return;
         }
 
-        s->gss_kex_used = TRUE;
+        s->gss_kex_used = true;
 
         /*-
          * If this the first KEX, save the GSS context for "gssapi-keyex"
@@ -695,7 +702,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
                  * cache.
                  */
                 if (s->hostkey_alg) {
-                    s->need_gss_transient_hostkey = TRUE;
+                    s->need_gss_transient_hostkey = true;
                 } else {
                     /*
                      * If we negotiated the "null" host key algorithm
@@ -718,7 +725,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
                      */
                     if (!s->warned_about_no_gss_transient_hostkey) {
                         ppl_logevent(("No fallback host key available"));
-                        s->warned_about_no_gss_transient_hostkey = TRUE;
+                        s->warned_about_no_gss_transient_hostkey = true;
                     }
                 }
             }
@@ -738,7 +745,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
                 ppl_logevent(("Post-GSS rekey provided fallback host key:"));
                 ppl_logevent(("%s", s->fingerprint));
                 ssh_transient_hostkey_cache_add(s->thc, s->hkey);
-                s->need_gss_transient_hostkey = FALSE;
+                s->need_gss_transient_hostkey = false;
             } else if (!ssh_transient_hostkey_cache_verify(s->thc, s->hkey)) {
                 ppl_logevent(("Non-GSS rekey after initial GSS kex "
                               "used host key:"));
@@ -836,7 +843,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
             s->fingerprint = NULL;
             store_host_key(s->savedhost, s->savedport,
                            ssh_key_cache_id(s->hkey), s->keystr);
-            s->cross_certifying = FALSE;
+            s->cross_certifying = false;
             /*
              * Don't forget to store the new key as the one we'll be
              * re-checking in future normal rekeys.

+ 5 - 5
source/putty/ssh2transhk.c

@@ -87,11 +87,11 @@ void ssh_transient_hostkey_cache_add(
     assert(retd == ent);
 }
 
-int ssh_transient_hostkey_cache_verify(
+bool ssh_transient_hostkey_cache_verify(
     ssh_transient_hostkey_cache *thc, ssh_key *key)
 {
     struct ssh_transient_hostkey_cache_entry *ent;
-    int toret = FALSE;
+    bool toret = false;
 
     if ((ent = find234(thc->cache, (void *)ssh_key_alg(key),
                        ssh_transient_hostkey_cache_find)) != NULL) {
@@ -101,7 +101,7 @@ int ssh_transient_hostkey_cache_verify(
         if (this_blob->len == ent->pub_blob->len &&
             !memcmp(this_blob->s, ent->pub_blob->s,
                     this_blob->len))
-            toret = TRUE;
+            toret = true;
 
         strbuf_free(this_blob);
     }
@@ -109,7 +109,7 @@ int ssh_transient_hostkey_cache_verify(
     return toret;
 }
 
-int ssh_transient_hostkey_cache_has(
+bool ssh_transient_hostkey_cache_has(
     ssh_transient_hostkey_cache *thc, const ssh_keyalg *alg)
 {
     struct ssh_transient_hostkey_cache_entry *ent =
@@ -118,7 +118,7 @@ int ssh_transient_hostkey_cache_has(
     return ent != NULL;
 }
 
-int ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc)
+bool ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc)
 {
     return count234(thc->cache) > 0;
 }

+ 117 - 112
source/putty/ssh2transport.c

@@ -44,11 +44,11 @@ static void ssh_comp_none_block(ssh_compressor *handle,
                                 int minlen)
 {
 }
-static int ssh_decomp_none_block(ssh_decompressor *handle,
-                                 unsigned char *block, int len,
-                                 unsigned char **outblock, int *outlen)
+static bool ssh_decomp_none_block(ssh_decompressor *handle,
+                                  unsigned char *block, int len,
+                                  unsigned char **outblock, int *outlen)
 {
-    return 0;
+    return false;
 }
 const static struct ssh_compression_alg ssh_comp_none = {
     "none", NULL,
@@ -62,11 +62,11 @@ const static struct ssh_compression_alg *const compressions[] = {
 
 static void ssh2_transport_free(PacketProtocolLayer *);
 static void ssh2_transport_process_queue(PacketProtocolLayer *);
-static int ssh2_transport_get_specials(
+static bool ssh2_transport_get_specials(
     PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
 static void ssh2_transport_special_cmd(PacketProtocolLayer *ppl,
                                        SessionSpecialCode code, int arg);
-static int ssh2_transport_want_user_input(PacketProtocolLayer *ppl);
+static bool ssh2_transport_want_user_input(PacketProtocolLayer *ppl);
 static void ssh2_transport_got_user_input(PacketProtocolLayer *ppl);
 static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
 
@@ -87,11 +87,11 @@ static const struct PacketProtocolLayerVtable ssh2_transport_vtable = {
 
 #ifndef NO_GSSAPI
 static void ssh2_transport_gss_update(struct ssh2_transport_state *s,
-                                      int definitely_rekeying);
+                                      bool definitely_rekeying);
 #endif
 
-static int ssh2_transport_timer_update(struct ssh2_transport_state *s,
-                                       unsigned long rekey_time);
+static bool ssh2_transport_timer_update(struct ssh2_transport_state *s,
+                                        unsigned long rekey_time);
 
 static const char *const kexlist_descr[NKEXLIST] = {
     "key exchange algorithm",
@@ -109,7 +109,7 @@ PacketProtocolLayer *ssh2_transport_new(
     const char *client_greeting, const char *server_greeting,
     struct ssh_connection_shared_gss_state *shgss,
     struct DataTransferStats *stats, PacketProtocolLayer *higher_layer,
-    int is_server)
+    bool is_server)
 {
     struct ssh2_transport_state *s = snew(struct ssh2_transport_state);
     memset(s, 0, sizeof(*s));
@@ -141,7 +141,7 @@ PacketProtocolLayer *ssh2_transport_new(
     s->shgss->ctx = NULL;
 #endif
     s->thc = ssh_transient_hostkey_cache_new();
-    s->gss_kex_used = FALSE;
+    s->gss_kex_used = false;
 
     s->outgoing_kexinit = strbuf_new();
     s->incoming_kexinit = strbuf_new();
@@ -215,6 +215,8 @@ static void ssh2_transport_free(PacketProtocolLayer *ppl)
     strbuf_free(s->outgoing_kexinit);
     strbuf_free(s->incoming_kexinit);
     ssh_transient_hostkey_cache_free(s->thc);
+
+    expire_timer_context(s);
     sfree(s);
 }
 
@@ -298,7 +300,7 @@ static struct kexinit_algorithm *ssh2_kexinit_addalg(struct kexinit_algorithm
     return NULL;
 }
 
-int ssh2_common_filter_queue(PacketProtocolLayer *ppl)
+bool ssh2_common_filter_queue(PacketProtocolLayer *ppl)
 {
     static const char *const ssh2_disconnect_reasons[] = {
         NULL,
@@ -336,7 +338,7 @@ int ssh2_common_filter_queue(PacketProtocolLayer *ppl)
                  ssh2_disconnect_reasons[reason] : "unknown"),
                 PTRLEN_PRINTF(msg));
             pq_pop(ppl->in_pq);
-            return TRUE;               /* indicate that we've been freed */
+            return true;               /* indicate that we've been freed */
 
           case SSH2_MSG_DEBUG:
             /* XXX maybe we should actually take notice of the return value */
@@ -352,22 +354,22 @@ int ssh2_common_filter_queue(PacketProtocolLayer *ppl)
             break;
 
           default:
-            return FALSE;
+            return false;
         }
     }
 
-    return FALSE;
+    return false;
 }
 
-static int ssh2_transport_filter_queue(struct ssh2_transport_state *s)
+static bool ssh2_transport_filter_queue(struct ssh2_transport_state *s)
 {
     PktIn *pktin;
 
     while (1) {
         if (ssh2_common_filter_queue(&s->ppl))
-            return TRUE;
+            return true;
         if ((pktin = pq_peek(s->ppl.in_pq)) == NULL)
-            return FALSE;
+            return false;
 
         /* Pass on packets to the next layer if they're outside
          * the range reserved for the transport protocol. */
@@ -381,7 +383,7 @@ static int ssh2_transport_filter_queue(struct ssh2_transport_state *s)
                                 ssh2_pkt_type(s->ppl.bpp->pls->kctx,
                                               s->ppl.bpp->pls->actx,
                                               pktin->type));
-                return TRUE;
+                return true;
             }
 
             pq_pop(s->ppl.in_pq);
@@ -389,7 +391,7 @@ static int ssh2_transport_filter_queue(struct ssh2_transport_state *s)
         } else {
             /* Anything else is a transport-layer packet that the main
              * process_queue coroutine should handle. */
-            return FALSE;
+            return false;
         }
     }
 }
@@ -407,9 +409,10 @@ static void ssh2_write_kexinit_lists(
     const char *hk_host, int hk_port, const ssh_keyalg *hk_prev,
     ssh_transient_hostkey_cache *thc,
     ssh_key *const *our_hostkeys, int our_nhostkeys,
-    int first_time, int can_gssapi_keyex, int transient_hostkey_mode)
+    bool first_time, bool can_gssapi_keyex, bool transient_hostkey_mode)
 {
-    int i, j, k, warn;
+    int i, j, k;
+    bool warn;
 
     int n_preferred_kex;
     const struct ssh_kexes *preferred_kex[KEX_MAX + 1]; /* +1 for GSSAPI */
@@ -485,7 +488,7 @@ static void ssh2_write_kexinit_lists(
             preferred_ciphers[n_preferred_ciphers++] = &ssh2_blowfish;
             break;
           case CIPHER_DES:
-            if (conf_get_int(conf, CONF_ssh2_des_cbc))
+            if (conf_get_bool(conf, CONF_ssh2_des_cbc))
                 preferred_ciphers[n_preferred_ciphers++] = &ssh2_des;
             break;
           case CIPHER_3DES:
@@ -513,7 +516,7 @@ static void ssh2_write_kexinit_lists(
     /*
      * Set up preferred compression.
      */
-    if (conf_get_int(conf, CONF_compression))
+    if (conf_get_bool(conf, CONF_compression))
         preferred_comp = &ssh_zlib;
     else
         preferred_comp = &ssh_comp_none;
@@ -522,10 +525,10 @@ static void ssh2_write_kexinit_lists(
         for (j = 0; j < MAXKEXLIST; j++)
             kexlists[i][j].name = NULL;
     /* List key exchange algorithms. */
-    warn = FALSE;
+    warn = false;
     for (i = 0; i < n_preferred_kex; i++) {
         const struct ssh_kexes *k = preferred_kex[i];
-        if (!k) warn = TRUE;
+        if (!k) warn = true;
         else for (j = 0; j < k->nkexes; j++) {
                 alg = ssh2_kexinit_addalg(kexlists[KEXLIST_KEX],
                                           k->list[j]->name);
@@ -543,7 +546,7 @@ static void ssh2_write_kexinit_lists(
             alg = ssh2_kexinit_addalg(kexlists[KEXLIST_HOSTKEY],
                                       ssh_key_alg(our_hostkeys[i])->ssh_id);
             alg->u.hk.hostkey = ssh_key_alg(our_hostkeys[i]);
-            alg->u.hk.warn = FALSE;
+            alg->u.hk.warn = false;
         }
     } else if (first_time) {
         /*
@@ -558,10 +561,10 @@ static void ssh2_write_kexinit_lists(
          * they surely _do_ want to be alerted that a server
          * they're actually connecting to is using it.
          */
-        warn = FALSE;
+        warn = false;
         for (i = 0; i < n_preferred_hk; i++) {
             if (preferred_hk[i] == HK_WARN)
-                warn = TRUE;
+                warn = true;
             for (j = 0; j < lenof(ssh2_hostkey_algs); j++) {
                 if (ssh2_hostkey_algs[j].id != preferred_hk[i])
                     continue;
@@ -574,10 +577,10 @@ static void ssh2_write_kexinit_lists(
                 }
             }
         }
-        warn = FALSE;
+        warn = false;
         for (i = 0; i < n_preferred_hk; i++) {
             if (preferred_hk[i] == HK_WARN)
-                warn = TRUE;
+                warn = true;
             for (j = 0; j < lenof(ssh2_hostkey_algs); j++) {
                 if (ssh2_hostkey_algs[j].id != preferred_hk[i])
                     continue;
@@ -601,10 +604,10 @@ static void ssh2_write_kexinit_lists(
          * in which case the cache will currently be empty, which
          * isn't helpful!
          */
-        warn = FALSE;
+        warn = false;
         for (i = 0; i < n_preferred_hk; i++) {
             if (preferred_hk[i] == HK_WARN)
-                warn = TRUE;
+                warn = true;
             for (j = 0; j < lenof(ssh2_hostkey_algs); j++) {
                 if (ssh2_hostkey_algs[j].id != preferred_hk[i])
                     continue;
@@ -629,7 +632,7 @@ static void ssh2_write_kexinit_lists(
         assert(hk_prev);
         alg = ssh2_kexinit_addalg(kexlists[KEXLIST_HOSTKEY], hk_prev->ssh_id);
         alg->u.hk.hostkey = hk_prev;
-        alg->u.hk.warn = FALSE;
+        alg->u.hk.warn = false;
     }
     if (can_gssapi_keyex) {
         alg = ssh2_kexinit_addalg(kexlists[KEXLIST_HOSTKEY], "null");
@@ -637,7 +640,7 @@ static void ssh2_write_kexinit_lists(
     }
     /* List encryption algorithms (client->server then server->client). */
     for (k = KEXLIST_CSCIPHER; k <= KEXLIST_SCCIPHER; k++) {
-        warn = FALSE;
+        warn = false;
 #ifdef FUZZING
         alg = ssh2_kexinit_addalg(kexlists[k], "none");
         alg->u.cipher.cipher = NULL;
@@ -645,7 +648,7 @@ static void ssh2_write_kexinit_lists(
 #endif /* FUZZING */
         for (i = 0; i < n_preferred_ciphers; i++) {
             const struct ssh2_ciphers *c = preferred_ciphers[i];
-            if (!c) warn = TRUE;
+            if (!c) warn = true;
             else for (j = 0; j < c->nciphers; j++) {
                     alg = ssh2_kexinit_addalg(kexlists[k],
                                               c->list[j]->name);
@@ -671,12 +674,12 @@ static void ssh2_write_kexinit_lists(
 #ifdef FUZZING
         alg = ssh2_kexinit_addalg(kexlists[j], "none");
         alg->u.mac.mac = NULL;
-        alg->u.mac.etm = FALSE;
+        alg->u.mac.etm = false;
 #endif /* FUZZING */
         for (i = 0; i < nmacs; i++) {
             alg = ssh2_kexinit_addalg(kexlists[j], maclist[i]->name);
             alg->u.mac.mac = maclist[i];
-            alg->u.mac.etm = FALSE;
+            alg->u.mac.etm = false;
         }
         for (i = 0; i < nmacs; i++) {
             /* For each MAC, there may also be an ETM version,
@@ -684,7 +687,7 @@ static void ssh2_write_kexinit_lists(
             if (maclist[i]->etm_name) {
                 alg = ssh2_kexinit_addalg(kexlists[j], maclist[i]->etm_name);
                 alg->u.mac.mac = maclist[i];
-                alg->u.mac.etm = TRUE;
+                alg->u.mac.etm = true;
             }
         }
     }
@@ -697,22 +700,22 @@ static void ssh2_write_kexinit_lists(
         /* Prefer non-delayed versions */
         alg = ssh2_kexinit_addalg(kexlists[j], preferred_comp->name);
         alg->u.comp.comp = preferred_comp;
-        alg->u.comp.delayed = FALSE;
+        alg->u.comp.delayed = false;
         if (preferred_comp->delayed_name) {
             alg = ssh2_kexinit_addalg(kexlists[j],
                                       preferred_comp->delayed_name);
             alg->u.comp.comp = preferred_comp;
-            alg->u.comp.delayed = TRUE;
+            alg->u.comp.delayed = true;
         }
         for (i = 0; i < lenof(compressions); i++) {
             const struct ssh_compression_alg *c = compressions[i];
             alg = ssh2_kexinit_addalg(kexlists[j], c->name);
             alg->u.comp.comp = c;
-            alg->u.comp.delayed = FALSE;
+            alg->u.comp.delayed = false;
             if (c->delayed_name) {
                 alg = ssh2_kexinit_addalg(kexlists[j], c->delayed_name);
                 alg->u.comp.comp = c;
-                alg->u.comp.delayed = TRUE;
+                alg->u.comp.delayed = true;
             }
         }
     }
@@ -735,18 +738,18 @@ static void ssh2_write_kexinit_lists(
     put_stringz(pktout, "");
 }
 
-static int ssh2_scan_kexinits(
+static bool ssh2_scan_kexinits(
     ptrlen client_kexinit, ptrlen server_kexinit,
     struct kexinit_algorithm kexlists[NKEXLIST][MAXKEXLIST],
     const struct ssh_kex **kex_alg, const ssh_keyalg **hostkey_alg,
     transport_direction *cs, transport_direction *sc,
-    int *warn_kex, int *warn_hk, int *warn_cscipher, int *warn_sccipher,
-    Ssh *ssh, int *ignore_guess_cs_packet, int *ignore_guess_sc_packet,
+    bool *warn_kex, bool *warn_hk, bool *warn_cscipher, bool *warn_sccipher,
+    Ssh *ssh, bool *ignore_guess_cs_packet, bool *ignore_guess_sc_packet,
     int *n_server_hostkeys, int server_hostkeys[MAXKEXLIST])
 {
     BinarySource client[1], server[1];
     int i;
-    int guess_correct;
+    bool guess_correct;
     ptrlen clists[NKEXLIST], slists[NKEXLIST];
     const struct kexinit_algorithm *selected[NKEXLIST];
 
@@ -757,13 +760,14 @@ static int ssh2_scan_kexinits(
     get_data(client, 1 + 16);
     get_data(server, 1 + 16);
 
-    guess_correct = TRUE;
+    guess_correct = true;
 
     /* Find the matching string in each list, and map it to its
      * kexinit_algorithm structure. */
     for (i = 0; i < NKEXLIST; i++) {
         ptrlen clist, slist, cword, sword, found;
-        int cfirst, sfirst, j;
+        bool cfirst, sfirst;
+        int j;
 
         clists[i] = get_string(client);
         slists[i] = get_string(server);
@@ -772,13 +776,13 @@ static int ssh2_scan_kexinits(
              * agree" that we'd generate if we pressed on regardless
              * and treated the empty get_string() result as genuine */
             ssh_proto_error(ssh, "KEXINIT packet was incomplete");
-            return FALSE;
+            return false;
         }
 
-        for (cfirst = TRUE, clist = clists[i];
-             get_commasep_word(&clist, &cword); cfirst = FALSE)
-            for (sfirst = TRUE, slist = slists[i];
-                 get_commasep_word(&slist, &sword); sfirst = FALSE)
+        for (cfirst = true, clist = clists[i];
+             get_commasep_word(&clist, &cword); cfirst = false)
+            for (sfirst = true, slist = slists[i];
+                 get_commasep_word(&slist, &sword); sfirst = false)
                 if (ptrlen_eq_ptrlen(cword, sword)) {
                     found = cword;
                     goto found_match;
@@ -798,7 +802,7 @@ static int ssh2_scan_kexinits(
          * PROTOCOL.chacha20poly1305 or as far as I can see by their
          * code.)
          */
-        guess_correct = FALSE;
+        guess_correct = false;
 
         continue;
 
@@ -819,7 +823,7 @@ static int ssh2_scan_kexinits(
          * packet (if any) is officially wrong.
          */
         if ((i == KEXLIST_KEX || i == KEXLIST_HOSTKEY) && !(cfirst || sfirst))
-            guess_correct = FALSE;
+            guess_correct = false;
     }
 
     /*
@@ -867,7 +871,7 @@ static int ssh2_scan_kexinits(
              */
             ssh_sw_abort(ssh, "Couldn't agree a %s (available: %.*s)",
                          kexlist_descr[i], PTRLEN_PRINTF(slists[i]));
-            return FALSE;
+            return false;
         }
 
         switch (i) {
@@ -922,7 +926,7 @@ static int ssh2_scan_kexinits(
             break;
 
           default:
-            assert(FALSE && "Bad list index in scan_kexinits");
+            assert(false && "Bad list index in scan_kexinits");
         }
     }
 
@@ -943,7 +947,7 @@ static int ssh2_scan_kexinits(
                 server_hostkeys[(*n_server_hostkeys)++] = i;
     }
 
-    return TRUE;
+    return true;
 }
 
 void ssh2transport_finalise_exhash(struct ssh2_transport_state *s)
@@ -979,9 +983,9 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
     s->in.mac = s->out.mac = NULL;
     s->in.comp = s->out.comp = NULL;
 
-    s->got_session_id = FALSE;
-    s->need_gss_transient_hostkey = FALSE;
-    s->warned_about_no_gss_transient_hostkey = FALSE;
+    s->got_session_id = false;
+    s->need_gss_transient_hostkey = false;
+    s->warned_about_no_gss_transient_hostkey = false;
 
   begin_key_exchange:
 
@@ -992,8 +996,8 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
          * GSS key exchange even if we could. (See comments below,
          * where the flag was set on the previous key exchange.)
          */
-        s->can_gssapi_keyex = FALSE;
-    } else if (conf_get_int(s->conf, CONF_try_gssapi_kex)) {
+        s->can_gssapi_keyex = false;
+    } else if (conf_get_bool(s->conf, CONF_try_gssapi_kex)) {
         /*
          * We always check if we have GSS creds before we come up with
          * the kex algorithm list, otherwise future rekeys will fail
@@ -1007,7 +1011,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
          * state is "fresh".
          */
         if (s->rekey_class != RK_GSS_UPDATE)
-            ssh2_transport_gss_update(s, TRUE);
+            ssh2_transport_gss_update(s, true);
 
         /* Do GSSAPI KEX when capable */
         s->can_gssapi_keyex = s->gss_status & GSS_KEX_CAPABLE;
@@ -1025,10 +1029,10 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
          * fresh ones.
          */
         if (!s->got_session_id && (s->gss_status & GSS_CTXT_MAYFAIL) != 0)
-            s->can_gssapi_keyex = 0;
-        s->gss_delegate = conf_get_int(s->conf, CONF_gssapifwd);
+            s->can_gssapi_keyex = false;
+        s->gss_delegate = conf_get_bool(s->conf, CONF_gssapifwd);
     } else {
-        s->can_gssapi_keyex = FALSE;
+        s->can_gssapi_keyex = false;
     }
 #endif
 
@@ -1053,7 +1057,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
         !s->got_session_id, s->can_gssapi_keyex,
         s->gss_kex_used && !s->need_gss_transient_hostkey);
     /* First KEX packet does _not_ follow, because we're not that brave. */
-    put_bool(s->outgoing_kexinit, FALSE);
+    put_bool(s->outgoing_kexinit, false);
     put_uint32(s->outgoing_kexinit, 0);             /* reserved */
 
     /*
@@ -1067,7 +1071,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
     /*
      * Flag that KEX is in progress.
      */
-    s->kex_in_progress = TRUE;
+    s->kex_in_progress = true;
 
     /*
      * Wait for the other side's KEXINIT, and save it.
@@ -1097,7 +1101,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
                 s->kexlists, &s->kex_alg, &s->hostkey_alg, &s->out, &s->in,
                 &s->warn_kex, &s->warn_hk, &s->warn_cscipher,
                 &s->warn_sccipher, s->ppl.ssh, NULL, &s->ignorepkt, &nhk, hks))
-            return; /* FALSE means a fatal error function was called */
+            return; /* false means a fatal error function was called */
 
         /*
          * In addition to deciding which host key we're actually going
@@ -1147,13 +1151,13 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
         for (j = 0; j < s->n_uncert_hostkeys; j++) {
             const struct ssh_signkey_with_user_pref_id *hktype =
                 &ssh2_hostkey_algs[s->uncert_hostkeys[j]];
-            int better = FALSE;
+            bool better = false;
             for (k = 0; k < HK_MAX; k++) {
                 int id = conf_get_int_int(s->conf, CONF_ssh_hklist, k);
                 if (id == HK_WARN) {
                     break;
                 } else if (id == hktype->id) {
-                    better = TRUE;
+                    better = true;
                     break;
                 }
             }
@@ -1245,7 +1249,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
         memcpy(s->session_id, s->exchange_hash, sizeof(s->exchange_hash));
         s->session_id_len = s->kex_alg->hash->hlen;
         assert(s->session_id_len <= sizeof(s->session_id));
-        s->got_session_id = TRUE;
+        s->got_session_id = true;
     }
 
     /*
@@ -1254,7 +1258,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
     pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_NEWKEYS);
     pq_push(s->ppl.out_pq, pktout);
     /* Start counting down the outgoing-data limit for these cipher keys. */
-    s->stats->out.running = TRUE;
+    s->stats->out.running = true;
     s->stats->out.remaining = s->max_data_size;
 
     /*
@@ -1317,7 +1321,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
         return;
     }
     /* Start counting down the incoming-data limit for these cipher keys. */
-    s->stats->in.running = TRUE;
+    s->stats->in.running = true;
     s->stats->in.remaining = s->max_data_size;
 
     /*
@@ -1377,7 +1381,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
     /*
      * Otherwise, schedule a timer for our next rekey.
      */
-    s->kex_in_progress = FALSE;
+    s->kex_in_progress = false;
     s->last_rekey = GETTICKCOUNT();
     (void) ssh2_transport_timer_update(s, 0);
 
@@ -1429,7 +1433,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
             pq_push(s->ppl.out_pq, pktout);
         }
 
-        s->higher_layer_ok = TRUE;
+        s->higher_layer_ok = true;
         queue_idempotent_callback(&s->higher_layer->ic_process_queue);
     }
 
@@ -1504,7 +1508,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
                               s->rekey_reason));
                 /* Reset the counters, so that at least this message doesn't
                  * hit the event log _too_ often. */
-                s->stats->in.running = s->stats->out.running = TRUE;
+                s->stats->in.running = s->stats->out.running = true;
                 s->stats->in.remaining = s->stats->out.remaining =
                     s->max_data_size;
                 (void) ssh2_transport_timer_update(s, 0);
@@ -1556,7 +1560,7 @@ static void ssh2_transport_timer(void *ctx, unsigned long now)
      * but not if this is unsafe.
      */
     if (conf_get_int(s->conf, CONF_gssapirekey)) {
-        ssh2_transport_gss_update(s, FALSE);
+        ssh2_transport_gss_update(s, false);
         if ((s->gss_status & GSS_KEX_CAPABLE) != 0 &&
             (s->gss_status & GSS_CTXT_MAYFAIL) == 0 &&
             (s->gss_status & (GSS_CRED_UPDATED|GSS_CTXT_EXPIRES)) != 0) {
@@ -1575,11 +1579,12 @@ static void ssh2_transport_timer(void *ctx, unsigned long now)
 /*
  * The rekey_time is zero except when re-configuring.
  *
- * We either schedule the next timer and return 0, or return 1 to run the
- * callback now, which will call us again to re-schedule on completion.
+ * We either schedule the next timer and return false, or return true
+ * to run the callback now, which will call us again to re-schedule on
+ * completion.
  */
-static int ssh2_transport_timer_update(struct ssh2_transport_state *s,
-                                       unsigned long rekey_time)
+static bool ssh2_transport_timer_update(struct ssh2_transport_state *s,
+                                        unsigned long rekey_time)
 {
     unsigned long mins;
     unsigned long ticks;
@@ -1598,7 +1603,7 @@ static int ssh2_transport_timer_update(struct ssh2_transport_state *s,
 
         /* If overdue, caller will rekey synchronously now */
         if (now - s->last_rekey > ticks)
-            return 1;
+            return true;
         ticks = next - now;
     }
 
@@ -1633,7 +1638,7 @@ static int ssh2_transport_timer_update(struct ssh2_transport_state *s,
 
     /* Schedule the next timer */
     s->next_rekey = schedule_timer(ticks, ssh2_transport_timer, s);
-    return 0;
+    return false;
 }
 
 void ssh2_transport_dialog_callback(void *loginv, int ret)
@@ -1658,7 +1663,7 @@ void ssh2_transport_dialog_callback(void *loginv, int ret)
  * newly obtained context as a proxy for the expiration of the TGT.
  */
 static void ssh2_transport_gss_update(struct ssh2_transport_state *s,
-                                      int definitely_rekeying)
+                                      bool definitely_rekeying)
 {
     PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
     int gss_stat;
@@ -1676,8 +1681,8 @@ static void ssh2_transport_gss_update(struct ssh2_transport_state *s,
      */
     if (s->shgss->libs->nlibraries == 0)
         return;
-    if (!conf_get_int(s->conf, CONF_try_gssapi_auth) &&
-        !conf_get_int(s->conf, CONF_try_gssapi_kex))
+    if (!conf_get_bool(s->conf, CONF_try_gssapi_auth) &&
+        !conf_get_bool(s->conf, CONF_try_gssapi_kex))
         return;
 
     /* Import server name and cache it */
@@ -1754,7 +1759,7 @@ static void ssh2_transport_gss_update(struct ssh2_transport_state *s,
      * refresh them. We must avoid setting GSS_CRED_UPDATED or
      * GSS_CTXT_EXPIRES when credential delegation is disabled.
      */
-    if (conf_get_int(s->conf, CONF_gssapifwd) == 0)
+    if (!conf_get_bool(s->conf, CONF_gssapifwd))
         return;
 
     if (s->gss_cred_expiry != GSS_NO_EXPIRATION &&
@@ -1792,17 +1797,17 @@ void ssh2_transport_notify_auth_done(PacketProtocolLayer *ppl)
 
 #endif /* NO_GSSAPI */
 
-static int ssh2_transport_get_specials(
+static bool ssh2_transport_get_specials(
     PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx)
 {
     struct ssh2_transport_state *s =
         container_of(ppl, struct ssh2_transport_state, ppl);
-    int need_separator = FALSE;
-    int toret;
+    bool need_separator = false;
+    bool toret;
 
     if (ssh_ppl_get_specials(s->higher_layer, add_special, ctx)) {
-        need_separator = TRUE;
-        toret = TRUE;
+        need_separator = true;
+        toret = true;
     }
 
     /*
@@ -1813,11 +1818,11 @@ static int ssh2_transport_get_specials(
     if (!(s->ppl.remote_bugs & BUG_SSH2_REKEY)) {
         if (need_separator) {
             add_special(ctx, NULL, SS_SEP, 0);
-            need_separator = FALSE;
+            need_separator = false;
         }
 
         add_special(ctx, "Repeat key exchange", SS_REKEY, 0);
-        toret = TRUE;
+        toret = true;
 
         if (s->n_uncert_hostkeys) {
             int i;
@@ -1852,7 +1857,7 @@ static void ssh2_transport_special_cmd(PacketProtocolLayer *ppl,
     } else if (code == SS_XCERT) {
 	if (!s->kex_in_progress) {
             s->hostkey_alg = ssh2_hostkey_algs[arg].alg;
-            s->cross_certifying = TRUE;
+            s->cross_certifying = true;
             s->rekey_reason = "cross-certifying new host key";
             s->rekey_class = RK_NORMAL;
             queue_idempotent_callback(&s->ppl.ic_process_queue);
@@ -1884,7 +1889,7 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
 {
     struct ssh2_transport_state *s;
     const char *rekey_reason = NULL;
-    int rekey_mandatory = FALSE;
+    bool rekey_mandatory = false;
     unsigned long old_max_data_size, rekey_time;
     int i;
 
@@ -1903,11 +1908,11 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
         if (s->max_data_size < old_max_data_size) {
             unsigned long diff = old_max_data_size - s->max_data_size;
 
-            /* Intentionally use bitwise OR instead of logical, so
-             * that we decrement both counters even if the first one
-             * runs out */
-            if ((DTS_CONSUME(s->stats, out, diff) != 0) |
-                (DTS_CONSUME(s->stats, in, diff) != 0))
+            /* We must decrement both counters, so avoid short-circuit
+             * evaluation skipping one */
+            bool out_expired = DTS_CONSUME(s->stats, out, diff);
+            bool in_expired = DTS_CONSUME(s->stats, in, diff);
+            if (out_expired || in_expired)
                 rekey_reason = "data limit lowered";
         } else {
             unsigned long diff = s->max_data_size - old_max_data_size;
@@ -1918,22 +1923,22 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
         }
     }
 
-    if (conf_get_int(s->conf, CONF_compression) !=
-	conf_get_int(conf, CONF_compression)) {
+    if (conf_get_bool(s->conf, CONF_compression) !=
+	conf_get_bool(conf, CONF_compression)) {
         rekey_reason = "compression setting changed";
-        rekey_mandatory = TRUE;
+        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)) {
         rekey_reason = "cipher settings changed";
-        rekey_mandatory = TRUE;
+        rekey_mandatory = true;
     }
-    if (conf_get_int(s->conf, CONF_ssh2_des_cbc) !=
-	conf_get_int(conf, CONF_ssh2_des_cbc)) {
+    if (conf_get_bool(s->conf, CONF_ssh2_des_cbc) !=
+	conf_get_bool(conf, CONF_ssh2_des_cbc)) {
         rekey_reason = "cipher settings changed";
-        rekey_mandatory = TRUE;
+        rekey_mandatory = true;
     }
 
     conf_free(s->conf);
@@ -1953,7 +1958,7 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
     ssh_ppl_reconfigure(s->higher_layer, conf);
 }
 
-static int ssh2_transport_want_user_input(PacketProtocolLayer *ppl)
+static bool ssh2_transport_want_user_input(PacketProtocolLayer *ppl)
 {
     struct ssh2_transport_state *s =
         container_of(ppl, struct ssh2_transport_state, ppl);

+ 24 - 22
source/putty/ssh2transport.h

@@ -29,23 +29,23 @@ struct kexinit_algorithm {
     union {
         struct {
             const struct ssh_kex *kex;
-            int warn;
+            bool warn;
         } kex;
         struct {
             const ssh_keyalg *hostkey;
-            int warn;
+            bool warn;
         } hk;
         struct {
             const struct ssh2_cipheralg *cipher;
-            int warn;
+            bool warn;
         } cipher;
         struct {
             const struct ssh2_macalg *mac;
-            int etm;
+            bool etm;
         } mac;
         struct {
             const struct ssh_compression_alg *comp;
-            int delayed;
+            bool delayed;
         } comp;
     } u;
 };
@@ -105,9 +105,9 @@ typedef enum RekeyClass {
 typedef struct transport_direction {
     const struct ssh2_cipheralg *cipher;
     const struct ssh2_macalg *mac;
-    int etm_mode;
+    bool etm_mode;
     const struct ssh_compression_alg *comp;
-    int comp_delayed;
+    bool comp_delayed;
     int mkkey_adjust;
 } transport_direction;
 
@@ -132,7 +132,8 @@ struct ssh2_transport_state {
     char *hostkey_str; /* string representation, for easy checking in rekeys */
     unsigned char session_id[SSH2_KEX_MAX_HASH_LEN];
     int session_id_len;
-    int dh_min_size, dh_max_size, dh_got_size_bounds;
+    int dh_min_size, dh_max_size;
+    bool dh_got_size_bounds;
     struct dh_ctx *dh_ctx;
     ssh_hash *exhash;
 
@@ -140,10 +141,10 @@ struct ssh2_transport_state {
 
     char *client_greeting, *server_greeting;
 
-    int kex_in_progress;
+    bool kex_in_progress;
     unsigned long next_rekey, last_rekey;
     const char *deferred_rekey_reason;
-    int higher_layer_ok;
+    bool higher_layer_ok;
 
     /*
      * Fully qualified host name, which we need if doing GSSAPI.
@@ -161,9 +162,10 @@ struct ssh2_transport_state {
 #endif
     ssh_transient_hostkey_cache *thc;
 
-    int gss_kex_used;
+    bool gss_kex_used;
 
-    int nbits, pbits, warn_kex, warn_hk, warn_cscipher, warn_sccipher;
+    int nbits, pbits;
+    bool warn_kex, warn_hk, warn_cscipher, warn_sccipher;
     Bignum p, g, e, f, K;
     strbuf *outgoing_kexinit, *incoming_kexinit;
     strbuf *client_kexinit, *server_kexinit; /* aliases to the above */
@@ -176,22 +178,22 @@ struct ssh2_transport_state {
     struct RSAKey *rsa_kex_key;             /* for RSA kex */
     struct ec_key *ecdh_key;              /* for ECDH kex */
     unsigned char exchange_hash[SSH2_KEX_MAX_HASH_LEN];
-    int can_gssapi_keyex;
-    int need_gss_transient_hostkey;
-    int warned_about_no_gss_transient_hostkey;
-    int got_session_id;
+    bool can_gssapi_keyex;
+    bool need_gss_transient_hostkey;
+    bool warned_about_no_gss_transient_hostkey;
+    bool got_session_id;
     int dlgret;
-    int guessok;
-    int ignorepkt;
+    bool guessok;
+    bool ignorepkt;
     struct kexinit_algorithm kexlists[NKEXLIST][MAXKEXLIST];
 #ifndef NO_GSSAPI
     Ssh_gss_buf gss_buf;
     Ssh_gss_buf gss_rcvtok, gss_sndtok;
     Ssh_gss_stat gss_stat;
     Ssh_gss_buf mic;
-    int init_token_sent;
-    int complete_rcvd;
-    int gss_delegate;
+    bool init_token_sent;
+    bool complete_rcvd;
+    bool gss_delegate;
 #endif
 
     /*
@@ -205,7 +207,7 @@ struct ssh2_transport_state {
      * Flag indicating that the current rekey is intended to finish
      * with a newly cross-certified host key.
      */
-    int cross_certifying;
+    bool cross_certifying;
 
     ssh_key *const *hostkeys;
     int nhostkeys;

+ 108 - 76
source/putty/ssh2userauth.c

@@ -23,10 +23,10 @@ struct ssh2_userauth_state {
 
     PacketProtocolLayer *transport_layer, *successor_layer;
     Filename *keyfile;
-    int tryagent, change_username;
+    bool tryagent, change_username;
     char *hostname, *fullhostname;
     char *default_username;
-    int try_ki_auth, try_gssapi_auth, try_gssapi_kex_auth, gssapi_fwd;
+    bool try_ki_auth, try_gssapi_auth, try_gssapi_kex_auth, gssapi_fwd;
 
     ptrlen session_id;
     enum {
@@ -39,28 +39,28 @@ struct ssh2_userauth_state {
         AUTH_TYPE_KEYBOARD_INTERACTIVE,
         AUTH_TYPE_KEYBOARD_INTERACTIVE_QUIET
     } type;
-    int need_pw, can_pubkey, can_passwd, can_keyb_inter;
+    bool need_pw, can_pubkey, can_passwd, can_keyb_inter;
     int userpass_ret;
-    int tried_pubkey_config, done_agent;
+    bool tried_pubkey_config, done_agent;
     struct ssh_connection_shared_gss_state *shgss;
 #ifndef NO_GSSAPI
-    int can_gssapi;
-    int can_gssapi_keyex_auth;
-    int tried_gssapi;
-    int tried_gssapi_keyex_auth;
+    bool can_gssapi;
+    bool can_gssapi_keyex_auth;
+    bool tried_gssapi;
+    bool tried_gssapi_keyex_auth;
     time_t gss_cred_expiry;
     Ssh_gss_buf gss_buf;
     Ssh_gss_buf gss_rcvtok, gss_sndtok;
     Ssh_gss_stat gss_stat;
 #endif
-    int kbd_inter_refused;
+    bool kbd_inter_refused;
     prompts_t *cur_prompt;
     int num_prompts;
     char *username;
     char *password;
-    int got_username;
+    bool got_username;
     strbuf *publickey_blob;
-    int privatekey_available, privatekey_encrypted;
+    bool privatekey_available, privatekey_encrypted;
     char *publickey_algorithm;
     char *publickey_comment;
     void *agent_response_to_free;
@@ -71,7 +71,7 @@ struct ssh2_userauth_state {
     ptrlen pk, alg, comment;
     int len;
     PktOut *pktout;
-    int want_user_input;
+    bool want_user_input;
 
     agent_pending_query *auth_agent_query;
     bufchain banner;
@@ -81,11 +81,11 @@ struct ssh2_userauth_state {
 
 static void ssh2_userauth_free(PacketProtocolLayer *); 
 static void ssh2_userauth_process_queue(PacketProtocolLayer *);
-static int ssh2_userauth_get_specials(
+static bool ssh2_userauth_get_specials(
     PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
 static void ssh2_userauth_special_cmd(PacketProtocolLayer *ppl,
                                       SessionSpecialCode code, int arg);
-static int ssh2_userauth_want_user_input(PacketProtocolLayer *ppl);
+static bool ssh2_userauth_want_user_input(PacketProtocolLayer *ppl);
 static void ssh2_userauth_got_user_input(PacketProtocolLayer *ppl);
 static void ssh2_userauth_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
 
@@ -114,11 +114,10 @@ static const struct PacketProtocolLayerVtable ssh2_userauth_vtable = {
 PacketProtocolLayer *ssh2_userauth_new(
     PacketProtocolLayer *successor_layer,
     const char *hostname, const char *fullhostname,
-    Filename *keyfile, int tryagent,
-    const char *default_username, int change_username,
-    int try_ki_auth,
-    int try_gssapi_auth, int try_gssapi_kex_auth,
-    int gssapi_fwd, struct ssh_connection_shared_gss_state *shgss)
+    Filename *keyfile, bool tryagent,
+    const char *default_username, bool change_username,
+    bool try_ki_auth, bool try_gssapi_auth, bool try_gssapi_kex_auth,
+    bool gssapi_fwd, struct ssh_connection_shared_gss_state *shgss)
 {
     struct ssh2_userauth_state *s = snew(struct ssh2_userauth_state);
     memset(s, 0, sizeof(*s));
@@ -206,8 +205,8 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
     crBegin(s->crState);
 
 #ifndef NO_GSSAPI
-    s->tried_gssapi = FALSE;
-    s->tried_gssapi_keyex_auth = FALSE;
+    s->tried_gssapi = false;
+    s->tried_gssapi_keyex_auth = false;
 #endif
 
     /*
@@ -351,7 +350,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
      *    the username they will want to be able to get back and
      *    retype it!
      */
-    s->got_username = FALSE;
+    s->got_username = false;
     while (1) {
         /*
          * Get a username.
@@ -364,9 +363,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
              */
         } else if ((s->username = s->default_username) == NULL) {
             s->cur_prompt = new_prompts();
-            s->cur_prompt->to_server = TRUE;
+            s->cur_prompt->to_server = true;
             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) {
@@ -378,9 +377,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 if (s->userpass_ret >= 0)
                     break;
 
-                s->want_user_input = TRUE;
+                s->want_user_input = true;
                 crReturnV;
-                s->want_user_input = FALSE;
+                s->want_user_input = false;
             }
             if (!s->userpass_ret) {
                 /*
@@ -397,7 +396,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
             if ((flags & FLAG_VERBOSE) || (flags & FLAG_INTERACTIVE))
                 ppl_printf(("Using username \"%s\".\r\n", s->username));
         }
-        s->got_username = TRUE;
+        s->got_username = true;
 
         /*
          * Send an authentication request using method "none": (a)
@@ -413,11 +412,11 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
         pq_push(s->ppl.out_pq, s->pktout);
         s->type = AUTH_TYPE_NONE;
 
-        s->tried_pubkey_config = FALSE;
-        s->kbd_inter_refused = FALSE;
+        s->tried_pubkey_config = false;
+        s->kbd_inter_refused = false;
 
         /* Reset agent request state. */
-        s->done_agent = FALSE;
+        s->done_agent = false;
         if (s->agent_response.ptr) {
             if (s->pkblob_pos_in_agent) {
                 s->asrc->pos = s->pkblob_pos_in_agent;
@@ -590,7 +589,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 /* gssapi-keyex authentication */
 
                 s->type = AUTH_TYPE_GSSAPI;
-                s->tried_gssapi_keyex_auth = TRUE;
+                s->tried_gssapi_keyex_auth = true;
                 s->ppl.bpp->pls->actx = SSH2_PKTCTX_GSSAPI;
 
                 if (s->shgss->lib->gsslogmsg)
@@ -632,7 +631,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 put_stringz(s->pktout, s->successor_layer->vt->name);
                 put_stringz(s->pktout, "publickey");
                                                     /* method */
-                put_bool(s->pktout, FALSE); /* no signature included */
+                put_bool(s->pktout, false); /* no signature included */
                 put_stringpl(s->pktout, s->alg);
                 put_stringpl(s->pktout, s->pk);
                 pq_push(s->ppl.out_pq, s->pktout);
@@ -663,7 +662,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     put_stringz(s->pktout, s->successor_layer->vt->name);
                     put_stringz(s->pktout, "publickey");
                                                         /* method */
-                    put_bool(s->pktout, TRUE);  /* signature included */
+                    put_bool(s->pktout, true);  /* signature included */
                     put_stringpl(s->pktout, s->alg);
                     put_stringpl(s->pktout, s->pk);
 
@@ -707,12 +706,12 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
 
                 /* Do we have any keys left to try? */
                 if (s->pkblob_pos_in_agent) {
-                    s->done_agent = TRUE;
-                    s->tried_pubkey_config = TRUE;
+                    s->done_agent = true;
+                    s->tried_pubkey_config = true;
                 } else {
                     s->keyi++;
                     if (s->keyi >= s->nkeys)
-                        s->done_agent = TRUE;
+                        s->done_agent = true;
                 }
 
             } else if (s->can_pubkey && s->publickey_blob &&
@@ -723,7 +722,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
 
                 s->ppl.bpp->pls->actx = SSH2_PKTCTX_PUBLICKEY;
 
-                s->tried_pubkey_config = TRUE;
+                s->tried_pubkey_config = true;
 
                 /*
                  * Try the public key supplied in the configuration.
@@ -736,7 +735,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 put_stringz(s->pktout, s->username);
                 put_stringz(s->pktout, s->successor_layer->vt->name);
                 put_stringz(s->pktout, "publickey");    /* method */
-                put_bool(s->pktout, FALSE);
+                put_bool(s->pktout, false);
                                                 /* no signature included */
                 put_stringz(s->pktout, s->publickey_algorithm);
                 put_string(s->pktout, s->publickey_blob->s,
@@ -769,12 +768,12 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                          * Get a passphrase from the user.
                          */
                         s->cur_prompt = new_prompts();
-                        s->cur_prompt->to_server = FALSE;
+                        s->cur_prompt->to_server = false;
                         s->cur_prompt->name = dupstr("SSH key passphrase");
                         add_prompt(s->cur_prompt,
                                    dupprintf("Passphrase for key \"%.100s\": ",
                                              s->publickey_comment),
-                                   FALSE);
+                                   false);
                         s->userpass_ret = seat_get_userpass_input(
                             s->ppl.seat, s->cur_prompt, NULL);
                         while (1) {
@@ -787,9 +786,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                             if (s->userpass_ret >= 0)
                                 break;
 
-                            s->want_user_input = TRUE;
+                            s->want_user_input = true;
                             crReturnV;
-                            s->want_user_input = FALSE;
+                            s->want_user_input = false;
                         }
                         if (!s->userpass_ret) {
                             /* Failed to get a passphrase. Terminate. */
@@ -845,7 +844,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     put_stringz(s->pktout, s->username);
                     put_stringz(s->pktout, s->successor_layer->vt->name);
                     put_stringz(s->pktout, "publickey"); /* method */
-                    put_bool(s->pktout, TRUE); /* signature follows */
+                    put_bool(s->pktout, true); /* signature follows */
                     put_stringz(s->pktout, ssh_key_ssh_id(key->key));
                     pkblob = strbuf_new();
                     ssh_key_public_blob(key->key, BinarySink_UPCAST(pkblob));
@@ -864,7 +863,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     put_data(sigdata, s->pktout->data + 5,
                              s->pktout->length - 5);
                     sigblob = strbuf_new();
-                    ssh_key_sign(key->key, sigdata->s, sigdata->len,
+                    ssh_key_sign(key->key, sigdata->s, sigdata->len, 0,
                                  BinarySink_UPCAST(sigblob));
                     strbuf_free(sigdata);
                     ssh2_userauth_add_sigblob(
@@ -889,7 +888,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 ptrlen data;
 
                 s->type = AUTH_TYPE_GSSAPI;
-                s->tried_gssapi = TRUE;
+                s->tried_gssapi = true;
                 s->ppl.bpp->pls->actx = SSH2_PKTCTX_GSSAPI;
 
                 if (s->shgss->lib->gsslogmsg)
@@ -1016,11 +1015,44 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
 
                     if (s->gss_stat == SSH_GSS_S_CONTINUE_NEEDED) {
                         crMaybeWaitUntilV((pktin = ssh2_userauth_pop(s)) != NULL);
-                        if (pktin->type != SSH2_MSG_USERAUTH_GSSAPI_TOKEN) {
+
+                        if (pktin->type == SSH2_MSG_USERAUTH_GSSAPI_ERRTOK) {
+                            /*
+                             * Per RFC 4462 section 3.9, this packet
+                             * type MUST immediately precede an
+                             * ordinary USERAUTH_FAILURE.
+                             *
+                             * We currently don't know how to do
+                             * anything with the GSSAPI error token
+                             * contained in this packet, so we ignore
+                             * it and just wait for the following
+                             * FAILURE.
+                             */
+                            crMaybeWaitUntilV(
+                                (pktin = ssh2_userauth_pop(s)) != NULL);
+                            if (pktin->type != SSH2_MSG_USERAUTH_FAILURE) {
+                                ssh_proto_error(
+                                    s->ppl.ssh, "Received unexpected packet "
+                                    "after SSH_MSG_USERAUTH_GSSAPI_ERRTOK "
+                                    "(expected SSH_MSG_USERAUTH_FAILURE): "
+                                    "type %d (%s)", pktin->type,
+                                    ssh2_pkt_type(s->ppl.bpp->pls->kctx,
+                                                  s->ppl.bpp->pls->actx,
+                                                  pktin->type));
+                                return;
+                            }
+                        }
+
+                        if (pktin->type == SSH2_MSG_USERAUTH_FAILURE) {
+                            ppl_logevent(("GSSAPI authentication failed"));
+                            s->gss_stat = SSH_GSS_FAILURE;
+                            pq_push_front(s->ppl.in_pq, pktin);
+                            break;
+                        } else if (pktin->type !=
+                                   SSH2_MSG_USERAUTH_GSSAPI_TOKEN) {
                             ppl_logevent(("GSSAPI authentication -"
                                           " bad server response"));
                             s->gss_stat = SSH_GSS_FAILURE;
-                            pq_push_front(s->ppl.in_pq, pktin);
                             break;
                         }
                         data = get_string(pktin);
@@ -1073,7 +1105,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                      * Give up on it entirely. */
                     pq_push_front(s->ppl.in_pq, pktin);
                     s->type = AUTH_TYPE_KEYBOARD_INTERACTIVE_QUIET;
-                    s->kbd_inter_refused = TRUE; /* don't try it again */
+                    s->kbd_inter_refused = true; /* don't try it again */
                     continue;
                 }
 
@@ -1093,7 +1125,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     inst = get_string(pktin);
                     get_string(pktin); /* skip language tag */
                     s->cur_prompt = new_prompts();
-                    s->cur_prompt->to_server = TRUE;
+                    s->cur_prompt->to_server = true;
 
                     /*
                      * Get any prompt(s) from the packet.
@@ -1101,7 +1133,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     s->num_prompts = get_uint32(pktin);
                     for (i = 0; i < s->num_prompts; i++) {
                         ptrlen prompt;
-                        int echo;
+                        bool echo;
                         static char noprompt[] =
                             "<server failed to send prompt>: ";
 
@@ -1119,11 +1151,11 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                          * local prompts? */
                         s->cur_prompt->name =
                             dupprintf("SSH server: %.*s", PTRLEN_PRINTF(name));
-                        s->cur_prompt->name_reqd = TRUE;
+                        s->cur_prompt->name_reqd = true;
                     } else {
                         s->cur_prompt->name =
                             dupstr("SSH server authentication");
-                        s->cur_prompt->name_reqd = FALSE;
+                        s->cur_prompt->name_reqd = false;
                     }
                     /* We add a prefix to try to make it clear that a prompt
                      * has come from the server.
@@ -1138,9 +1170,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                                       "authentication.%s%.*s",
                                       inst.len ? "\n" : "",
                                       PTRLEN_PRINTF(inst));
-                        s->cur_prompt->instr_reqd = TRUE;
+                        s->cur_prompt->instr_reqd = true;
                     } else {
-                        s->cur_prompt->instr_reqd = FALSE;
+                        s->cur_prompt->instr_reqd = false;
                     }
 
                     /*
@@ -1158,9 +1190,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                         if (s->userpass_ret >= 0)
                             break;
 
-                        s->want_user_input = TRUE;
+                        s->want_user_input = true;
                         crReturnV;
-                        s->want_user_input = FALSE;
+                        s->want_user_input = false;
                     }
                     if (!s->userpass_ret) {
                         /*
@@ -1213,16 +1245,16 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 /*
                  * Plain old password authentication.
                  */
-                int changereq_first_time; /* not live over crReturn */
+                bool changereq_first_time; /* not live over crReturn */
 
                 s->ppl.bpp->pls->actx = SSH2_PKTCTX_PASSWORD;
 
                 s->cur_prompt = new_prompts();
-                s->cur_prompt->to_server = TRUE;
+                s->cur_prompt->to_server = true;
                 s->cur_prompt->name = dupstr("SSH password");
                 add_prompt(s->cur_prompt, dupprintf("%s@%s's password: ",
                                                     s->username, s->hostname),
-                           FALSE);
+                           false);
 
                 s->userpass_ret = seat_get_userpass_input(
                     s->ppl.seat, s->cur_prompt, NULL);
@@ -1235,9 +1267,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     if (s->userpass_ret >= 0)
                         break;
 
-                    s->want_user_input = TRUE;
+                    s->want_user_input = true;
                     crReturnV;
-                    s->want_user_input = FALSE;
+                    s->want_user_input = false;
                 }
                 if (!s->userpass_ret) {
                     /*
@@ -1274,7 +1306,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 put_stringz(s->pktout, s->username);
                 put_stringz(s->pktout, s->successor_layer->vt->name);
                 put_stringz(s->pktout, "password");
-                put_bool(s->pktout, FALSE);
+                put_bool(s->pktout, false);
                 put_stringz(s->pktout, s->password);
                 s->pktout->minlen = 256;
                 pq_push(s->ppl.out_pq, s->pktout);
@@ -1286,7 +1318,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                  * request.
                  */
                 crMaybeWaitUntilV((pktin = ssh2_userauth_pop(s)) != NULL);
-                changereq_first_time = TRUE;
+                changereq_first_time = true;
 
                 while (pktin->type == SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ) {
 
@@ -1296,7 +1328,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                      * Loop until the server accepts it.
                      */
 
-                    int got_new = FALSE; /* not live over crReturn */
+                    bool got_new = false; /* not live over crReturn */
                     ptrlen prompt;  /* not live over crReturn */
                     
                     {
@@ -1312,10 +1344,10 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     prompt = get_string(pktin);
 
                     s->cur_prompt = new_prompts();
-                    s->cur_prompt->to_server = TRUE;
+                    s->cur_prompt->to_server = true;
                     s->cur_prompt->name = dupstr("New SSH password");
                     s->cur_prompt->instruction = mkstr(prompt);
-                    s->cur_prompt->instr_reqd = TRUE;
+                    s->cur_prompt->instr_reqd = true;
                     /*
                      * There's no explicit requirement in the protocol
                      * for the "old" passwords in the original and
@@ -1330,11 +1362,11 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                      */
                     add_prompt(s->cur_prompt,
                                dupstr("Current password (blank for previously entered password): "),
-                               FALSE);
+                               false);
                     add_prompt(s->cur_prompt, dupstr("Enter new password: "),
-                               FALSE);
+                               false);
                     add_prompt(s->cur_prompt, dupstr("Confirm new password: "),
-                               FALSE);
+                               false);
 
                     /*
                      * Loop until the user manages to enter the same
@@ -1353,9 +1385,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                             if (s->userpass_ret >= 0)
                                 break;
 
-                            s->want_user_input = TRUE;
+                            s->want_user_input = true;
                             crReturnV;
-                            s->want_user_input = FALSE;
+                            s->want_user_input = false;
                         }
                         if (!s->userpass_ret) {
                             /*
@@ -1409,7 +1441,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     put_stringz(s->pktout, s->username);
                     put_stringz(s->pktout, s->successor_layer->vt->name);
                     put_stringz(s->pktout, "password");
-                    put_bool(s->pktout, TRUE);
+                    put_bool(s->pktout, true);
                     put_stringz(s->pktout, s->password);
                     put_stringz(s->pktout,
                                        s->cur_prompt->prompts[1]->result);
@@ -1424,7 +1456,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                      * new password.)
                      */
                     crMaybeWaitUntilV((pktin = ssh2_userauth_pop(s)) != NULL);
-                    changereq_first_time = FALSE;
+                    changereq_first_time = false;
 
                 }
 
@@ -1634,11 +1666,11 @@ static PktOut *ssh2_userauth_gss_packet(
 }
 #endif
 
-static int ssh2_userauth_get_specials(
+static bool ssh2_userauth_get_specials(
     PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx)
 {
     /* No specials provided by this layer. */
-    return FALSE;
+    return false;
 }
 
 static void ssh2_userauth_special_cmd(PacketProtocolLayer *ppl,
@@ -1647,7 +1679,7 @@ static void ssh2_userauth_special_cmd(PacketProtocolLayer *ppl,
     /* No specials provided by this layer. */
 }
 
-static int ssh2_userauth_want_user_input(PacketProtocolLayer *ppl)
+static bool ssh2_userauth_want_user_input(PacketProtocolLayer *ppl)
 {
     struct ssh2_userauth_state *s =
         container_of(ppl, struct ssh2_userauth_state, ppl);

+ 31 - 31
source/putty/sshaes.c

@@ -49,22 +49,22 @@
 #endif
 
 struct AESContext {
-    word32 keysched_buf[(MAX_NR + 1) * NB + 3];
-    word32 invkeysched_buf[(MAX_NR + 1) * NB + 3];
-    word32 *keysched, *invkeysched;
-    word32 iv[NB];
+    uint32_t keysched_buf[(MAX_NR + 1) * NB + 3];
+    uint32_t invkeysched_buf[(MAX_NR + 1) * NB + 3];
+    uint32_t *keysched, *invkeysched;
+    uint32_t iv[NB];
     int Nr; /* number of rounds */
     void (*encrypt_cbc)(unsigned char*, int, AESContext*);
     void (*decrypt_cbc)(unsigned char*, int, AESContext*);
     void (*sdctr)(unsigned char*, int, AESContext*);
-    int isNI;
+    bool isNI;
 };
 
 static void aes_encrypt_cbc_sw(unsigned char*, int, AESContext*);
 static void aes_decrypt_cbc_sw(unsigned char*, int, AESContext*);
 static void aes_sdctr_sw(unsigned char*, int, AESContext*);
 
-INLINE static int supports_aes_ni();
+INLINE static bool supports_aes_ni();
 static void aes_setup_ni(AESContext * ctx,
                          const unsigned char *key, int keylen);
 
@@ -156,7 +156,7 @@ static const unsigned char Sboxinv[256] = {
     0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
 };
 
-static const word32 E0[256] = {
+static const uint32_t E0[256] = {
     0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d,
     0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554,
     0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d,
@@ -222,7 +222,7 @@ static const word32 E0[256] = {
     0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11,
     0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a,
 };
-static const word32 E1[256] = {
+static const uint32_t E1[256] = {
     0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b,
     0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5,
     0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b,
@@ -288,7 +288,7 @@ static const word32 E1[256] = {
     0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f,
     0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616,
 };
-static const word32 E2[256] = {
+static const uint32_t E2[256] = {
     0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b,
     0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5,
     0x30506030, 0x01030201, 0x67a9ce67, 0x2b7d562b,
@@ -354,7 +354,7 @@ static const word32 E2[256] = {
     0x41c38241, 0x99b02999, 0x2d775a2d, 0x0f111e0f,
     0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16,
 };
-static const word32 E3[256] = {
+static const uint32_t E3[256] = {
     0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6,
     0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491,
     0x30305060, 0x01010302, 0x6767a9ce, 0x2b2b7d56,
@@ -420,7 +420,7 @@ static const word32 E3[256] = {
     0x4141c382, 0x9999b029, 0x2d2d775a, 0x0f0f111e,
     0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c,
 };
-static const word32 D0[256] = {
+static const uint32_t D0[256] = {
     0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96,
     0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393,
     0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25,
@@ -486,7 +486,7 @@ static const word32 D0[256] = {
     0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190,
     0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742,
 };
-static const word32 D1[256] = {
+static const uint32_t D1[256] = {
     0x5051f4a7, 0x537e4165, 0xc31a17a4, 0x963a275e,
     0xcb3bab6b, 0xf11f9d45, 0xabacfa58, 0x934be303,
     0x552030fa, 0xf6ad766d, 0x9188cc76, 0x25f5024c,
@@ -552,7 +552,7 @@ static const word32 D1[256] = {
     0x7139a801, 0xde080cb3, 0x9cd8b4e4, 0x906456c1,
     0x617bcb84, 0x70d532b6, 0x74486c5c, 0x42d0b857,
 };
-static const word32 D2[256] = {
+static const uint32_t D2[256] = {
     0xa75051f4, 0x65537e41, 0xa4c31a17, 0x5e963a27,
     0x6bcb3bab, 0x45f11f9d, 0x58abacfa, 0x03934be3,
     0xfa552030, 0x6df6ad76, 0x769188cc, 0x4c25f502,
@@ -618,7 +618,7 @@ static const word32 D2[256] = {
     0x017139a8, 0xb3de080c, 0xe49cd8b4, 0xc1906456,
     0x84617bcb, 0xb670d532, 0x5c74486c, 0x5742d0b8,
 };
-static const word32 D3[256] = {
+static const uint32_t D3[256] = {
     0xf4a75051, 0x4165537e, 0x17a4c31a, 0x275e963a,
     0xab6bcb3b, 0x9d45f11f, 0xfa58abac, 0xe303934b,
     0x30fa5520, 0x766df6ad, 0xcc769188, 0x024c25f5,
@@ -700,11 +700,11 @@ static void aes_setup(AESContext * ctx, const unsigned char *key, int keylen)
     /* Ensure the key schedule arrays are 16-byte aligned */
     bufaddr = (size_t)ctx->keysched_buf;
     ctx->keysched = ctx->keysched_buf +
-        (0xF & -bufaddr) / sizeof(word32);
+        (0xF & -bufaddr) / sizeof(uint32_t);
     assert((size_t)ctx->keysched % 16 == 0);
     bufaddr = (size_t)ctx->invkeysched_buf;
     ctx->invkeysched = ctx->invkeysched_buf +
-        (0xF & -bufaddr) / sizeof(word32);
+        (0xF & -bufaddr) / sizeof(uint32_t);
     assert((size_t)ctx->invkeysched % 16 == 0);
 
     ctx->isNI = supports_aes_ni();
@@ -726,7 +726,7 @@ static void aes_setup(AESContext * ctx, const unsigned char *key, int keylen)
 	if (i < Nk)
 	    ctx->keysched[i] = GET_32BIT_MSB_FIRST(key + 4 * i);
 	else {
-	    word32 temp = ctx->keysched[i - 1];
+	    uint32_t temp = ctx->keysched[i - 1];
 	    if (i % Nk == 0) {
 		int a, b, c, d;
 		a = (temp >> 16) & 0xFF;
@@ -758,7 +758,7 @@ static void aes_setup(AESContext * ctx, const unsigned char *key, int keylen)
      */
     for (i = 0; i <= ctx->Nr; i++) {
         for (j = 0; j < NB; j++) {
-	    word32 temp;
+	    uint32_t temp;
             temp = ctx->keysched[(ctx->Nr - i) * NB + j];
 	    if (i != 0 && i != ctx->Nr) {
 		/*
@@ -826,7 +826,7 @@ static void aes_setup(AESContext * ctx, const unsigned char *key, int keylen)
  */
 static void aes_encrypt_cbc_sw(unsigned char *blk, int len, AESContext * ctx)
 {
-    word32 block[4];
+    uint32_t block[4];
     unsigned char* finish = blk + len;
     int i;
 
@@ -835,8 +835,8 @@ static void aes_encrypt_cbc_sw(unsigned char *blk, int len, AESContext * ctx)
     memcpy(block, ctx->iv, sizeof(block));
 
     while (blk < finish) {
-        word32 *keysched = ctx->keysched;
-        word32 newstate[4];
+        uint32_t *keysched = ctx->keysched;
+        uint32_t newstate[4];
 	for (i = 0; i < 4; i++)
             block[i] ^= GET_32BIT_MSB_FIRST(blk + 4 * i);
         ADD_ROUND_KEY;
@@ -872,7 +872,7 @@ static void aes_encrypt_cbc_sw(unsigned char *blk, int len, AESContext * ctx)
 
 static void aes_sdctr_sw(unsigned char *blk, int len, AESContext *ctx)
 {
-    word32 iv[4];
+    uint32_t iv[4];
     unsigned char* finish = blk + len;
     int i;
 
@@ -881,8 +881,8 @@ static void aes_sdctr_sw(unsigned char *blk, int len, AESContext *ctx)
     memcpy(iv, ctx->iv, sizeof(iv));
 
     while (blk < finish) {
-        word32 *keysched = ctx->keysched;
-        word32 newstate[4], block[4], tmp;
+        uint32_t *keysched = ctx->keysched;
+        uint32_t newstate[4], block[4], tmp;
         memcpy(block, iv, sizeof(block));
         ADD_ROUND_KEY;
         switch (ctx->Nr) {
@@ -922,7 +922,7 @@ static void aes_sdctr_sw(unsigned char *blk, int len, AESContext *ctx)
 
 static void aes_decrypt_cbc_sw(unsigned char *blk, int len, AESContext * ctx)
 {
-    word32 iv[4];
+    uint32_t iv[4];
     unsigned char* finish = blk + len;
     int i;
 
@@ -931,8 +931,8 @@ static void aes_decrypt_cbc_sw(unsigned char *blk, int len, AESContext * ctx)
     memcpy(iv, ctx->iv, sizeof(iv));
 
     while (blk < finish) {
-        word32 *keysched = ctx->invkeysched;
-        word32 newstate[4], ct[4], block[4];
+        uint32_t *keysched = ctx->invkeysched;
+        uint32_t newstate[4], ct[4], block[4];
         for (i = 0; i < 4; i++)
             block[i] = ct[i] = GET_32BIT_MSB_FIRST(blk + 4 * i);
         ADD_ROUND_KEY;
@@ -1219,7 +1219,7 @@ const struct ssh2_ciphers ssh2_aes = {
 #if defined(__clang__) || defined(__GNUC__)
 
 #include <cpuid.h>
-INLINE static int supports_aes_ni()
+INLINE static bool supports_aes_ni()
 {
     unsigned int CPUInfo[4];
     __cpuid(1, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
@@ -1228,7 +1228,7 @@ INLINE static int supports_aes_ni()
 
 #else /* defined(__clang__) || defined(__GNUC__) */
 
-INLINE static int supports_aes_ni()
+INLINE static bool supports_aes_ni()
 {
     unsigned int CPUInfo[4];
     __cpuid(CPUInfo, 1);
@@ -1755,9 +1755,9 @@ static void aes_setup_ni(AESContext * ctx, const unsigned char *key, int keylen)
     assert(0);
 }
 
-INLINE static int supports_aes_ni()
+INLINE static bool supports_aes_ni()
 {
-    return 0;
+    return false;
 }
 
 #endif /* COMPILER_SUPPORTS_AES_NI */

+ 43 - 43
source/putty/sshblowf.c

@@ -10,8 +10,8 @@
 #include "sshblowf.h"
 
 struct BlowfishContext {
-    word32 S0[256], S1[256], S2[256], S3[256], P[18];
-    word32 iv0, iv1;		       /* for CBC mode */
+    uint32_t S0[256], S1[256], S2[256], S3[256], P[18];
+    uint32_t iv0, iv1;		       /* for CBC mode */
 };
 
 /*
@@ -27,7 +27,7 @@ struct BlowfishContext {
 open my $spig, "spigot -n -B16 -d8336 pi |";
 read $spig, $ignore, 2; # throw away the leading "3."
 for my $name ("parray", "sbox0".."sbox3") {
-    print "static const word32 ${name}[] = {\n";
+    print "static const uint32_t ${name}[] = {\n";
     my $len = $name eq "parray" ? 18 : 256;
     for my $i (1..$len) {
         read $spig, $word, 8;
@@ -39,13 +39,13 @@ for my $name ("parray", "sbox0".."sbox3") {
 close $spig;
 
  */
-static const word32 parray[] = {
+static const uint32_t parray[] = {
     0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0,
     0x082EFA98, 0xEC4E6C89, 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
     0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917, 0x9216D5D9, 0x8979FB1B,
 };
 
-static const word32 sbox0[] = {
+static const uint32_t sbox0[] = {
     0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96,
     0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
     0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658,
@@ -91,7 +91,7 @@ static const word32 sbox0[] = {
     0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A,
 };
 
-static const word32 sbox1[] = {
+static const uint32_t sbox1[] = {
     0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623, 0xAD6EA6B0, 0x49A7DF7D,
     0x9CEE60B8, 0x8FEDB266, 0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
     0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E, 0x3F54989A, 0x5B429D65,
@@ -137,7 +137,7 @@ static const word32 sbox1[] = {
     0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7,
 };
 
-static const word32 sbox2[] = {
+static const uint32_t sbox2[] = {
     0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934, 0x411520F7, 0x7602D4F7,
     0xBCF46B2E, 0xD4A20068, 0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
     0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840, 0x4D95FC1D, 0x96B591AF,
@@ -183,7 +183,7 @@ static const word32 sbox2[] = {
     0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0,
 };
 
-static const word32 sbox3[] = {
+static const uint32_t sbox3[] = {
     0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B, 0x5CB0679E, 0x4FA33742,
     0xD3822740, 0x99BC9BBE, 0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
     0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4, 0x5748AB2F, 0xBC946E79,
@@ -233,15 +233,15 @@ static const word32 sbox3[] = {
 #define F(x) Fprime( ((x>>24)&0xFF), ((x>>16)&0xFF), ((x>>8)&0xFF), (x&0xFF) )
 #define ROUND(n) ( xL ^= P[n], t = xL, xL = F(xL) ^ xR, xR = t )
 
-static void blowfish_encrypt(word32 xL, word32 xR, word32 * output,
+static void blowfish_encrypt(uint32_t xL, uint32_t xR, uint32_t *output,
 			     BlowfishContext * ctx)
 {
-    word32 *S0 = ctx->S0;
-    word32 *S1 = ctx->S1;
-    word32 *S2 = ctx->S2;
-    word32 *S3 = ctx->S3;
-    word32 *P = ctx->P;
-    word32 t;
+    uint32_t *S0 = ctx->S0;
+    uint32_t *S1 = ctx->S1;
+    uint32_t *S2 = ctx->S2;
+    uint32_t *S3 = ctx->S3;
+    uint32_t *P = ctx->P;
+    uint32_t t;
 
     ROUND(0);
     ROUND(1);
@@ -266,15 +266,15 @@ static void blowfish_encrypt(word32 xL, word32 xR, word32 * output,
     output[1] = xL;
 }
 
-static void blowfish_decrypt(word32 xL, word32 xR, word32 * output,
+static void blowfish_decrypt(uint32_t xL, uint32_t xR, uint32_t *output,
 			     BlowfishContext * ctx)
 {
-    word32 *S0 = ctx->S0;
-    word32 *S1 = ctx->S1;
-    word32 *S2 = ctx->S2;
-    word32 *S3 = ctx->S3;
-    word32 *P = ctx->P;
-    word32 t;
+    uint32_t *S0 = ctx->S0;
+    uint32_t *S1 = ctx->S1;
+    uint32_t *S2 = ctx->S2;
+    uint32_t *S3 = ctx->S3;
+    uint32_t *P = ctx->P;
+    uint32_t t;
 
     ROUND(17);
     ROUND(16);
@@ -302,7 +302,7 @@ static void blowfish_decrypt(word32 xL, word32 xR, word32 * output,
 static void blowfish_lsb_encrypt_cbc(unsigned char *blk, int len,
                                      BlowfishContext * ctx)
 {
-    word32 xL, xR, out[2], iv0, iv1;
+    uint32_t xL, xR, out[2], iv0, iv1;
 
     assert((len & 7) == 0);
 
@@ -330,7 +330,7 @@ static void blowfish_lsb_encrypt_cbc(unsigned char *blk, int len,
 void blowfish_lsb_encrypt_ecb(void *vblk, int len, BlowfishContext * ctx)
 {
     unsigned char *blk = (unsigned char *)vblk;
-    word32 xL, xR, out[2];
+    uint32_t xL, xR, out[2];
 
     assert((len & 7) == 0);
 
@@ -348,7 +348,7 @@ void blowfish_lsb_encrypt_ecb(void *vblk, int len, BlowfishContext * ctx)
 static void blowfish_lsb_decrypt_cbc(unsigned char *blk, int len,
 				     BlowfishContext * ctx)
 {
-    word32 xL, xR, out[2], iv0, iv1;
+    uint32_t xL, xR, out[2], iv0, iv1;
 
     assert((len & 7) == 0);
 
@@ -376,7 +376,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)
 {
-    word32 xL, xR, out[2], iv0, iv1;
+    uint32_t xL, xR, out[2], iv0, iv1;
 
     assert((len & 7) == 0);
 
@@ -404,7 +404,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)
 {
-    word32 xL, xR, out[2], iv0, iv1;
+    uint32_t xL, xR, out[2], iv0, iv1;
 
     assert((len & 7) == 0);
 
@@ -432,7 +432,7 @@ static void blowfish_msb_decrypt_cbc(unsigned char *blk, int len,
 static void blowfish_msb_sdctr(unsigned char *blk, int len,
 				     BlowfishContext * ctx)
 {
-    word32 b[2], iv0, iv1, tmp;
+    uint32_t b[2], iv0, iv1, tmp;
 
     assert((len & 7) == 0);
 
@@ -477,12 +477,12 @@ void blowfish_expandkey(BlowfishContext * ctx,
 {
     const unsigned char *key = (const unsigned char *)vkey;
     const unsigned char *salt = (const unsigned char *)vsalt;
-    word32 *S0 = ctx->S0;
-    word32 *S1 = ctx->S1;
-    word32 *S2 = ctx->S2;
-    word32 *S3 = ctx->S3;
-    word32 *P = ctx->P;
-    word32 str[2];
+    uint32_t *S0 = ctx->S0;
+    uint32_t *S1 = ctx->S1;
+    uint32_t *S2 = ctx->S2;
+    uint32_t *S3 = ctx->S3;
+    uint32_t *P = ctx->P;
+    uint32_t str[2];
     int i, j;
     int saltpos;
     unsigned char dummysalt[1];
@@ -496,19 +496,19 @@ void blowfish_expandkey(BlowfishContext * ctx,
 
     for (i = 0; i < 18; i++) {
 	P[i] ^=
-	    ((word32) (unsigned char) (key[(i * 4 + 0) % keybytes])) << 24;
+	    ((uint32_t) (unsigned char) (key[(i * 4 + 0) % keybytes])) << 24;
 	P[i] ^=
-	    ((word32) (unsigned char) (key[(i * 4 + 1) % keybytes])) << 16;
+	    ((uint32_t) (unsigned char) (key[(i * 4 + 1) % keybytes])) << 16;
 	P[i] ^=
-	    ((word32) (unsigned char) (key[(i * 4 + 2) % keybytes])) << 8;
-	P[i] ^= ((word32) (unsigned char) (key[(i * 4 + 3) % keybytes]));
+	    ((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;
 
     for (i = 0; i < 18; i += 2) {
         for (j = 0; j < 8; j++)
-            str[j/4] ^= ((word32)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
+            str[j/4] ^= ((uint32_t)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
 
 	blowfish_encrypt(str[0], str[1], str, ctx);
 	P[i] = str[0];
@@ -517,28 +517,28 @@ void blowfish_expandkey(BlowfishContext * ctx,
 
     for (i = 0; i < 256; i += 2) {
         for (j = 0; j < 8; j++)
-            str[j/4] ^= ((word32)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
+            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];
     }
     for (i = 0; i < 256; i += 2) {
         for (j = 0; j < 8; j++)
-            str[j/4] ^= ((word32)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
+            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];
     }
     for (i = 0; i < 256; i += 2) {
         for (j = 0; j < 8; j++)
-            str[j/4] ^= ((word32)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
+            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];
     }
     for (i = 0; i < 256; i += 2) {
         for (j = 0; j < 8; j++)
-            str[j/4] ^= ((word32)salt[saltpos++ % saltbytes]) << (24-8*(j%4));
+            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];

+ 4 - 3
source/putty/sshbn.c

@@ -2085,7 +2085,8 @@ Bignum modinv(Bignum number, Bignum modulus)
 char *bignum_decimal(Bignum x)
 {
     int ndigits, ndigit;
-    int i, iszero;
+    int i;
+    bool iszero;
     BignumInt carry;
     char *ret;
     BignumInt *workspace;
@@ -2130,7 +2131,7 @@ char *bignum_decimal(Bignum x)
     ndigit = ndigits - 1;
     ret[ndigit] = '\0';
     do {
-	iszero = 1;
+	iszero = true;
 	carry = 0;
 	for (i = 0; i < (int)x[0]; i++) {
             /*
@@ -2159,7 +2160,7 @@ char *bignum_decimal(Bignum x)
 	    carry = r;
 
 	    if (workspace[i])
-		iszero = 0;
+		iszero = false;
 	}
 	ret[--ndigit] = (char) (carry + '0');
     } while (!iszero);

+ 14 - 14
source/putty/sshbpp.h

@@ -17,7 +17,7 @@ struct BinaryPacketProtocolVtable {
 struct BinaryPacketProtocol {
     const struct BinaryPacketProtocolVtable *vt;
     bufchain *in_raw, *out_raw;
-    int input_eof;   /* set this if in_raw will never be added to again */
+    bool input_eof;   /* set this if in_raw will never be added to again */
     PktInQueue in_pq;
     PktOutQueue out_pq;
     PacketLogSettings *pls;
@@ -39,7 +39,7 @@ struct BinaryPacketProtocol {
      * error message (either because it's not to be treated as an
      * error at all, or because some other error message has already
      * been emitted). */
-    int expect_close;
+    bool expect_close;
 };
 
 #define ssh_bpp_handle_input(bpp) ((bpp)->vt->handle_input(bpp))
@@ -68,7 +68,7 @@ void ssh_bpp_common_setup(BinaryPacketProtocol *);
 /* Common helper functions between the SSH-2 full and bare BPPs */
 void ssh2_bpp_queue_disconnect(BinaryPacketProtocol *bpp,
                                const char *msg, int category);
-int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin);
+bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin);
 
 /* Convenience macro for BPPs to send formatted strings to the Event
  * Log. Assumes a function parameter called 'bpp' is in scope, and
@@ -92,28 +92,28 @@ int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin);
  */
 struct DataTransferStats {
     struct {
-        int running;
+        bool running;
         unsigned long remaining;
     } in, out;
 };
 #define DTS_CONSUME(stats, direction, size)             \
     ((stats)->direction.running &&                      \
      (stats)->direction.remaining <= (size) ?           \
-     ((stats)->direction.running = FALSE, TRUE) :       \
-     ((stats)->direction.remaining -= (size), FALSE))
+     ((stats)->direction.running = false, true) :       \
+     ((stats)->direction.remaining -= (size), false))
 
 BinaryPacketProtocol *ssh2_bpp_new(
-    LogContext *logctx, struct DataTransferStats *stats, int is_server);
+    LogContext *logctx, struct DataTransferStats *stats, bool is_server);
 void ssh2_bpp_new_outgoing_crypto(
     BinaryPacketProtocol *bpp,
     const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
-    const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
-    const struct ssh_compression_alg *compression, int delayed_compression);
+    const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key,
+    const struct ssh_compression_alg *compression, bool delayed_compression);
 void ssh2_bpp_new_incoming_crypto(
     BinaryPacketProtocol *bpp,
     const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
-    const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
-    const struct ssh_compression_alg *compression, int delayed_compression);
+    const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key,
+    const struct ssh_compression_alg *compression, bool delayed_compression);
 
 /*
  * A query method specific to the interface between ssh2transport and
@@ -124,7 +124,7 @@ void ssh2_bpp_new_incoming_crypto(
  * to start a rekey because then we'd stop responding to anything
  * _other_ than transport-layer packets and deadlock the protocol.
  */
-int ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp);
+bool ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp);
 
 BinaryPacketProtocol *ssh2_bare_bpp_new(LogContext *logctx);
 
@@ -139,9 +139,9 @@ struct ssh_version_receiver {
                             int major_version);
 };
 BinaryPacketProtocol *ssh_verstring_new(
-    Conf *conf, LogContext *logctx, int bare_connection_mode,
+    Conf *conf, LogContext *logctx, bool bare_connection_mode,
     const char *protoversion, struct ssh_version_receiver *rcv,
-    int server_mode, const char *impl_name);
+    bool server_mode, const char *impl_name);
 const char *ssh_verstring_get_remote(BinaryPacketProtocol *);
 const char *ssh_verstring_get_local(BinaryPacketProtocol *);
 int ssh_verstring_get_bugs(BinaryPacketProtocol *);

+ 3 - 3
source/putty/sshccp.c

@@ -45,7 +45,7 @@ struct chacha20 {
      * 4-11 are the key
      * 12-13 are the counter
      * 14-15 are the IV */
-    uint32 state[16];
+    uint32_t state[16];
     /* The output of the state above ready to xor */
     unsigned char current[64];
     /* The index of the above currently used to allow a true streaming cipher */
@@ -55,7 +55,7 @@ struct chacha20 {
 static INLINE void chacha20_round(struct chacha20 *ctx)
 {
     int i;
-    uint32 copy[16];
+    uint32_t copy[16];
 
     /* Take a copy */
     memcpy(copy, ctx->state, sizeof(copy));
@@ -114,7 +114,7 @@ static INLINE void chacha20_round(struct chacha20 *ctx)
     /* Increment round counter */
     ++ctx->state[12];
     /* Check for overflow, not done in one line so the 32 bits are chopped by the type */
-    if (!(uint32)(ctx->state[12])) {
+    if (!(uint32_t)(ctx->state[12])) {
         ++ctx->state[13];
     }
 }

+ 57 - 57
source/putty/sshchan.h

@@ -19,42 +19,42 @@ struct ChannelVtable {
     void (*open_confirmation)(Channel *);
     void (*open_failed)(Channel *, const char *error_text);
 
-    int (*send)(Channel *, int is_stderr, const void *buf, int len);
+    int (*send)(Channel *, bool is_stderr, const void *buf, int len);
     void (*send_eof)(Channel *);
-    void (*set_input_wanted)(Channel *, int wanted);
+    void (*set_input_wanted)(Channel *, bool wanted);
 
     char *(*log_close_msg)(Channel *);
 
-    int (*want_close)(Channel *, int sent_local_eof, int rcvd_remote_eof);
+    bool (*want_close)(Channel *, bool sent_local_eof, bool rcvd_remote_eof);
 
     /* A method for every channel request we know of. All of these
-     * return TRUE for success or FALSE for failure. */
-    int (*rcvd_exit_status)(Channel *, int status);
-    int (*rcvd_exit_signal)(
-        Channel *chan, ptrlen signame, int core_dumped, ptrlen msg);
-    int (*rcvd_exit_signal_numeric)(
-        Channel *chan, int signum, int core_dumped, ptrlen msg);
-    int (*run_shell)(Channel *chan);
-    int (*run_command)(Channel *chan, ptrlen command);
-    int (*run_subsystem)(Channel *chan, ptrlen subsys);
-    int (*enable_x11_forwarding)(
-        Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata,
+     * return true for success or false for failure. */
+    bool (*rcvd_exit_status)(Channel *, int status);
+    bool (*rcvd_exit_signal)(
+        Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg);
+    bool (*rcvd_exit_signal_numeric)(
+        Channel *chan, int signum, bool core_dumped, ptrlen msg);
+    bool (*run_shell)(Channel *chan);
+    bool (*run_command)(Channel *chan, ptrlen command);
+    bool (*run_subsystem)(Channel *chan, ptrlen subsys);
+    bool (*enable_x11_forwarding)(
+        Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata,
         unsigned screen_number);
-    int (*enable_agent_forwarding)(Channel *chan);
-    int (*allocate_pty)(
+    bool (*enable_agent_forwarding)(Channel *chan);
+    bool (*allocate_pty)(
         Channel *chan, ptrlen termtype, unsigned width, unsigned height,
         unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes);
-    int (*set_env)(Channel *chan, ptrlen var, ptrlen value);
-    int (*send_break)(Channel *chan, unsigned length);
-    int (*send_signal)(Channel *chan, ptrlen signame);
-    int (*change_window_size)(
+    bool (*set_env)(Channel *chan, ptrlen var, ptrlen value);
+    bool (*send_break)(Channel *chan, unsigned length);
+    bool (*send_signal)(Channel *chan, ptrlen signame);
+    bool (*change_window_size)(
         Channel *chan, unsigned width, unsigned height,
         unsigned pixwidth, unsigned pixheight);
 
     /* A method for signalling success/failure responses to channel
      * requests initiated from the SshChannel vtable with want_reply
      * true. */
-    void (*request_response)(Channel *, int success);
+    void (*request_response)(Channel *, bool success);
 };
 
 struct Channel {
@@ -111,31 +111,31 @@ void chan_remotely_opened_failure(Channel *chan, const char *errtext);
 
 /* want_close for any channel that wants the default behaviour of not
  * closing until both directions have had an EOF */
-int chan_default_want_close(Channel *, int, int);
+bool chan_default_want_close(Channel *, bool, bool);
 
 /* default implementations that refuse all the channel requests */
-int chan_no_exit_status(Channel *, int);
-int chan_no_exit_signal(Channel *, ptrlen, int, ptrlen);
-int chan_no_exit_signal_numeric(Channel *, int, int, ptrlen);
-int chan_no_run_shell(Channel *chan);
-int chan_no_run_command(Channel *chan, ptrlen command);
-int chan_no_run_subsystem(Channel *chan, ptrlen subsys);
-int chan_no_enable_x11_forwarding(
-    Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata,
+bool chan_no_exit_status(Channel *, int);
+bool chan_no_exit_signal(Channel *, ptrlen, bool, ptrlen);
+bool chan_no_exit_signal_numeric(Channel *, int, bool, ptrlen);
+bool chan_no_run_shell(Channel *chan);
+bool chan_no_run_command(Channel *chan, ptrlen command);
+bool chan_no_run_subsystem(Channel *chan, ptrlen subsys);
+bool chan_no_enable_x11_forwarding(
+    Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata,
     unsigned screen_number);
-int chan_no_enable_agent_forwarding(Channel *chan);
-int chan_no_allocate_pty(
+bool chan_no_enable_agent_forwarding(Channel *chan);
+bool chan_no_allocate_pty(
     Channel *chan, ptrlen termtype, unsigned width, unsigned height,
     unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes);
-int chan_no_set_env(Channel *chan, ptrlen var, ptrlen value);
-int chan_no_send_break(Channel *chan, unsigned length);
-int chan_no_send_signal(Channel *chan, ptrlen signame);
-int chan_no_change_window_size(
+bool chan_no_set_env(Channel *chan, ptrlen var, ptrlen value);
+bool chan_no_send_break(Channel *chan, unsigned length);
+bool chan_no_send_signal(Channel *chan, ptrlen signame);
+bool chan_no_change_window_size(
     Channel *chan, unsigned width, unsigned height,
     unsigned pixwidth, unsigned pixheight);
 
 /* default implementation that never expects to receive a response */
-void chan_no_request_response(Channel *, int);
+void chan_no_request_response(Channel *, bool);
 
 /*
  * Constructor for a trivial do-nothing implementation of
@@ -156,7 +156,7 @@ Channel *zombiechan_new(void);
  */
 
 struct SshChannelVtable {
-    int (*write)(SshChannel *c, int is_stderr, const void *, int);
+    int (*write)(SshChannel *c, bool is_stderr, const void *, int);
     void (*write_eof)(SshChannel *c);
     void (*initiate_close)(SshChannel *c, const char *err);
     void (*unthrottle)(SshChannel *c, int bufsize);
@@ -174,7 +174,7 @@ struct SshChannelVtable {
      * want_reply flag, which will cause a callback to
      * chan_request_response when the result is available.
      *
-     * The ones that return 'int' use it to indicate that the SSH
+     * The ones that return 'bool' use it to indicate that the SSH
      * protocol in use doesn't support this request at all.
      *
      * (It's also intentional that not all of them have a want_reply
@@ -185,28 +185,28 @@ struct SshChannelVtable {
      */
     void (*send_exit_status)(SshChannel *c, int status);
     void (*send_exit_signal)(
-        SshChannel *c, ptrlen signame, int core_dumped, ptrlen msg);
+        SshChannel *c, ptrlen signame, bool core_dumped, ptrlen msg);
     void (*send_exit_signal_numeric)(
-        SshChannel *c, int signum, int core_dumped, ptrlen msg);
+        SshChannel *c, int signum, bool core_dumped, ptrlen msg);
     void (*request_x11_forwarding)(
-        SshChannel *c, int want_reply, const char *authproto,
-        const char *authdata, int screen_number, int oneshot);
+        SshChannel *c, bool want_reply, const char *authproto,
+        const char *authdata, int screen_number, bool oneshot);
     void (*request_agent_forwarding)(
-        SshChannel *c, int want_reply);
+        SshChannel *c, bool want_reply);
     void (*request_pty)(
-        SshChannel *c, int want_reply, Conf *conf, int w, int h);
-    int (*send_env_var)(
-        SshChannel *c, int want_reply, const char *var, const char *value);
+        SshChannel *c, bool want_reply, Conf *conf, int w, int h);
+    bool (*send_env_var)(
+        SshChannel *c, bool want_reply, const char *var, const char *value);
     void (*start_shell)(
-        SshChannel *c, int want_reply);
+        SshChannel *c, bool want_reply);
     void (*start_command)(
-        SshChannel *c, int want_reply, const char *command);
-    int (*start_subsystem)(
-        SshChannel *c, int want_reply, const char *subsystem);
-    int (*send_serial_break)(
-        SshChannel *c, int want_reply, int length); /* length=0 for default */
-    int (*send_signal)(
-        SshChannel *c, int want_reply, const char *signame);
+        SshChannel *c, bool want_reply, const char *command);
+    bool (*start_subsystem)(
+        SshChannel *c, bool want_reply, const char *subsystem);
+    bool (*send_serial_break)(
+        SshChannel *c, bool want_reply, int length); /* length=0 for default */
+    bool (*send_signal)(
+        SshChannel *c, bool want_reply, const char *signame);
     void (*send_terminal_size_change)(
         SshChannel *c, int w, int h);
     void (*hint_channel_is_simple)(SshChannel *c);
@@ -217,7 +217,7 @@ struct SshChannel {
     ConnectionLayer *cl;
 };
 
-#define sshfwd_write(c, buf, len) ((c)->vt->write(c, FALSE, buf, len))
+#define sshfwd_write(c, buf, len) ((c)->vt->write(c, false, buf, len))
 #define sshfwd_write_ext(c, stderr, buf, len) \
     ((c)->vt->write(c, stderr, buf, len))
 #define sshfwd_write_eof(c) ((c)->vt->write_eof(c))
@@ -265,7 +265,7 @@ struct SshChannel {
 
 mainchan *mainchan_new(
     PacketProtocolLayer *ppl, ConnectionLayer *cl, Conf *conf,
-    int term_width, int term_height, int is_simple, SshChannel **sc_out);
+    int term_width, int term_height, bool is_simple, SshChannel **sc_out);
 void mainchan_get_specials(
     mainchan *mc, add_special_fn_t add_special, void *ctx);
 void mainchan_special_cmd(mainchan *mc, SessionSpecialCode code, int arg);

+ 72 - 72
source/putty/sshcommon.c

@@ -52,7 +52,7 @@ void pq_base_push_front(PacketQueueBase *pqb, PacketQueueNode *node)
 }
 
 static PacketQueueNode pktin_freeq_head = {
-    &pktin_freeq_head, &pktin_freeq_head, TRUE
+    &pktin_freeq_head, &pktin_freeq_head, true
 };
 
 static void pktin_free_queue_callback(void *vctx)
@@ -68,11 +68,11 @@ static void pktin_free_queue_callback(void *vctx)
 }
 
 static IdempotentCallback ic_pktin_free = {
-    pktin_free_queue_callback, NULL, FALSE
+    pktin_free_queue_callback, NULL, false
 };
 
 static PktIn *pq_in_after(PacketQueueBase *pqb,
-                          PacketQueueNode *prev, int pop)
+                          PacketQueueNode *prev, bool pop)
 {
     PacketQueueNode *node = prev->next;
     if (node == &pqb->end)
@@ -86,7 +86,7 @@ static PktIn *pq_in_after(PacketQueueBase *pqb,
         node->next = &pktin_freeq_head;
         node->next->prev = node;
         node->prev->next = node;
-        node->on_free_queue = TRUE;
+        node->on_free_queue = true;
         queue_idempotent_callback(&ic_pktin_free);
     }
 
@@ -94,7 +94,7 @@ static PktIn *pq_in_after(PacketQueueBase *pqb,
 }
 
 static PktOut *pq_out_after(PacketQueueBase *pqb,
-                            PacketQueueNode *prev, int pop)
+                            PacketQueueNode *prev, bool pop)
 {
     PacketQueueNode *node = prev->next;
     if (node == &pqb->end)
@@ -224,7 +224,7 @@ PktOut *ssh_new_packet(void)
     pkt->downstream_id = 0;
     pkt->additional_log_text = NULL;
     pkt->qnode.next = pkt->qnode.prev = NULL;
-    pkt->qnode.on_free_queue = FALSE;
+    pkt->qnode.on_free_queue = false;
 
     return pkt;
 }
@@ -261,11 +261,11 @@ void ssh_free_pktout(PktOut *pkt)
  */
 
 static void zombiechan_free(Channel *chan);
-static int zombiechan_send(Channel *chan, int is_stderr, const void *, int);
-static void zombiechan_set_input_wanted(Channel *chan, int wanted);
+static int zombiechan_send(Channel *chan, bool is_stderr, const void *, int);
+static void zombiechan_set_input_wanted(Channel *chan, bool wanted);
 static void zombiechan_do_nothing(Channel *chan);
 static void zombiechan_open_failure(Channel *chan, const char *);
-static int zombiechan_want_close(Channel *chan, int sent_eof, int rcvd_eof);
+static bool zombiechan_want_close(Channel *chan, bool sent_eof, bool rcvd_eof);
 static char *zombiechan_log_close_msg(Channel *chan) { return NULL; }
 
 static const struct ChannelVtable zombiechan_channelvt = {
@@ -317,21 +317,21 @@ static void zombiechan_open_failure(Channel *chan, const char *errtext)
     assert(chan->vt == &zombiechan_channelvt);
 }
 
-static int zombiechan_send(Channel *chan, int is_stderr,
+static int zombiechan_send(Channel *chan, bool is_stderr,
                            const void *data, int length)
 {
     assert(chan->vt == &zombiechan_channelvt);
     return 0;
 }
 
-static void zombiechan_set_input_wanted(Channel *chan, int enable)
+static void zombiechan_set_input_wanted(Channel *chan, bool enable)
 {
     assert(chan->vt == &zombiechan_channelvt);
 }
 
-static int zombiechan_want_close(Channel *chan, int sent_eof, int rcvd_eof)
+static bool zombiechan_want_close(Channel *chan, bool sent_eof, bool rcvd_eof)
 {
-    return TRUE;
+    return true;
 }
 
 /* ----------------------------------------------------------------------
@@ -349,8 +349,8 @@ void chan_remotely_opened_failure(Channel *chan, const char *errtext)
     assert(0 && "this channel type should never receive OPEN_FAILURE");
 }
 
-int chan_default_want_close(
-    Channel *chan, int sent_local_eof, int rcvd_remote_eof)
+bool chan_default_want_close(
+    Channel *chan, bool sent_local_eof, bool rcvd_remote_eof)
 {
     /*
      * Default close policy: we start initiating the CHANNEL_CLOSE
@@ -359,80 +359,80 @@ int chan_default_want_close(
     return sent_local_eof && rcvd_remote_eof;
 }
 
-int chan_no_exit_status(Channel *chan, int status)
+bool chan_no_exit_status(Channel *chan, int status)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_exit_signal(
-    Channel *chan, ptrlen signame, int core_dumped, ptrlen msg)
+bool chan_no_exit_signal(
+    Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_exit_signal_numeric(
-    Channel *chan, int signum, int core_dumped, ptrlen msg)
+bool chan_no_exit_signal_numeric(
+    Channel *chan, int signum, bool core_dumped, ptrlen msg)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_run_shell(Channel *chan)
+bool chan_no_run_shell(Channel *chan)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_run_command(Channel *chan, ptrlen command)
+bool chan_no_run_command(Channel *chan, ptrlen command)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_run_subsystem(Channel *chan, ptrlen subsys)
+bool chan_no_run_subsystem(Channel *chan, ptrlen subsys)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_enable_x11_forwarding(
-    Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata,
+bool chan_no_enable_x11_forwarding(
+    Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata,
     unsigned screen_number)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_enable_agent_forwarding(Channel *chan)
+bool chan_no_enable_agent_forwarding(Channel *chan)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_allocate_pty(
+bool chan_no_allocate_pty(
     Channel *chan, ptrlen termtype, unsigned width, unsigned height,
     unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_set_env(Channel *chan, ptrlen var, ptrlen value)
+bool chan_no_set_env(Channel *chan, ptrlen var, ptrlen value)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_send_break(Channel *chan, unsigned length)
+bool chan_no_send_break(Channel *chan, unsigned length)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_send_signal(Channel *chan, ptrlen signame)
+bool chan_no_send_signal(Channel *chan, ptrlen signame)
 {
-    return FALSE;
+    return false;
 }
 
-int chan_no_change_window_size(
+bool chan_no_change_window_size(
     Channel *chan, unsigned width, unsigned height,
     unsigned pixwidth, unsigned pixheight)
 {
-    return FALSE;
+    return false;
 }
 
-void chan_no_request_response(Channel *chan, int success)
+void chan_no_request_response(Channel *chan, bool success)
 {
     assert(0 && "this channel type should never send a want-reply request");
 }
@@ -558,7 +558,7 @@ struct ssh_ttymodes get_ttymodes_from_conf(Seat *seat, Conf *conf)
                 assert(0 && "Bad mode->type");
             }
 
-            modes.have_mode[mode->opcode] = TRUE;
+            modes.have_mode[mode->opcode] = true;
             modes.mode_val[mode->opcode] = ival;
         }
 
@@ -572,9 +572,9 @@ struct ssh_ttymodes get_ttymodes_from_conf(Seat *seat, Conf *conf)
         ospeed = ispeed = 38400;           /* last-resort defaults */
         sscanf(conf_get_str(conf, CONF_termspeed), "%u,%u", &ospeed, &ispeed);
         /* Currently we unconditionally set these */
-        modes.have_mode[TTYMODE_ISPEED] = TRUE;
+        modes.have_mode[TTYMODE_ISPEED] = true;
         modes.mode_val[TTYMODE_ISPEED] = ispeed;
-        modes.have_mode[TTYMODE_OSPEED] = TRUE;
+        modes.have_mode[TTYMODE_OSPEED] = true;
         modes.mode_val[TTYMODE_OSPEED] = ospeed;
     }
 
@@ -613,7 +613,7 @@ struct ssh_ttymodes read_ttymodes_from_packet(
 
         our_opcode = our_ttymode_opcode(real_opcode, ssh_version);
         assert(our_opcode < TTYMODE_LIMIT);
-        modes.have_mode[our_opcode] = TRUE;
+        modes.have_mode[our_opcode] = true;
 
         if (ssh_version == 1 && real_opcode >= 1 && real_opcode <= 127)
             modes.mode_val[our_opcode] = get_byte(bs);
@@ -687,12 +687,12 @@ unsigned alloc_channel_id_general(tree234 *channels, size_t localid_offset)
  * lists of protocol identifiers in SSH-2.
  */
 
-int first_in_commasep_string(char const *needle, char const *haystack,
-                             int haylen)
+bool first_in_commasep_string(char const *needle, char const *haystack,
+                              int haylen)
 {
     int needlen;
     if (!needle || !haystack)          /* protect against null pointers */
-        return 0;
+        return false;
     needlen = strlen(needle);
 
     if (haylen >= needlen &&       /* haystack is long enough */
@@ -700,28 +700,28 @@ int first_in_commasep_string(char const *needle, char const *haystack,
         (haylen == needlen || haystack[needlen] == ',')
         /* either , or EOS follows */
         )
-        return 1;
-    return 0;
+        return true;
+    return false;
 }
 
-int in_commasep_string(char const *needle, char const *haystack, int haylen)
+bool in_commasep_string(char const *needle, char const *haystack, int haylen)
 {
     char *p;
 
     if (!needle || !haystack)          /* protect against null pointers */
-        return FALSE;
+        return false;
     /*
      * Is it at the start of the string?
      */
     if (first_in_commasep_string(needle, haystack, haylen))
-        return TRUE;
+        return true;
     /*
      * If not, search for the next comma and resume after that.
      * If no comma found, terminate.
      */
     p = memchr(haystack, ',', haylen);
     if (!p)
-        return FALSE;
+        return false;
     /* + 1 to skip over comma */
     return in_commasep_string(needle, p + 1, haylen - (p + 1 - haystack));
 }
@@ -733,7 +733,7 @@ void add_to_commasep(strbuf *buf, const char *data)
     put_data(buf, data, strlen(data));
 }
 
-int get_commasep_word(ptrlen *list, ptrlen *word)
+bool get_commasep_word(ptrlen *list, ptrlen *word)
 {
     const char *comma;
 
@@ -749,7 +749,7 @@ int get_commasep_word(ptrlen *list, ptrlen *word)
     }
 
     if (!list->len)
-        return FALSE;
+        return false;
 
     comma = memchr(list->ptr, ',', list->len);
     if (!comma) {
@@ -762,7 +762,7 @@ int get_commasep_word(ptrlen *list, ptrlen *word)
         list->ptr = (const char *)list->ptr + wordlen + 1;
         list->len -= wordlen + 1;
     }
-    return TRUE;
+    return true;
 }
 
 /* ----------------------------------------------------------------------
@@ -873,7 +873,7 @@ void ssh_bpp_common_setup(BinaryPacketProtocol *bpp)
 {
     pq_in_init(&bpp->in_pq);
     pq_out_init(&bpp->out_pq);
-    bpp->input_eof = FALSE;
+    bpp->input_eof = false;
     bpp->ic_in_raw.fn = ssh_bpp_input_raw_data_callback;
     bpp->ic_in_raw.ctx = bpp;
     bpp->ic_out_pq.fn = ssh_bpp_output_packet_callback;
@@ -905,7 +905,7 @@ void ssh2_bpp_queue_disconnect(BinaryPacketProtocol *bpp,
     (0 SSH2_MESSAGE_TYPES(BITMAP_UNIVERSAL, BITMAP_CONDITIONAL, \
                           BITMAP_CONDITIONAL, (32*y)))
 
-int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin)
+bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin)
 {
     static const unsigned valid_bitmap[] = {
         SSH2_BITMAP_WORD(0),
@@ -923,10 +923,10 @@ int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin)
         PktOut *pkt = ssh_bpp_new_pktout(bpp, SSH2_MSG_UNIMPLEMENTED);
         put_uint32(pkt, pktin->sequence);
         pq_push(&bpp->out_pq, pkt);
-        return TRUE;
+        return true;
     }
 
-    return FALSE;
+    return false;
 }
 
 #undef BITMAP_UNIVERSAL
@@ -992,7 +992,7 @@ int verify_ssh_manual_host_key(
  * Common functions shared between SSH-1 layers.
  */
 
-int ssh1_common_get_specials(
+bool ssh1_common_get_specials(
     PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx)
 {
     /*
@@ -1002,13 +1002,13 @@ int ssh1_common_get_specials(
      */
     if (!(ppl->remote_bugs & BUG_CHOKES_ON_SSH1_IGNORE)) {
         add_special(ctx, "IGNORE message", SS_NOP, 0);
-        return TRUE;
+        return true;
     }
 
-    return FALSE;
+    return false;
 }
 
-int ssh1_common_filter_queue(PacketProtocolLayer *ppl)
+bool ssh1_common_filter_queue(PacketProtocolLayer *ppl)
 {
     PktIn *pktin;
     ptrlen msg;
@@ -1021,7 +1021,7 @@ int ssh1_common_filter_queue(PacketProtocolLayer *ppl)
                              "Remote side sent disconnect message:\n\"%.*s\"",
                              PTRLEN_PRINTF(msg));
             pq_pop(ppl->in_pq);
-            return TRUE;               /* indicate that we've been freed */
+            return true;               /* indicate that we've been freed */
 
           case SSH1_MSG_DEBUG:
             msg = get_string(pktin);
@@ -1035,11 +1035,11 @@ int ssh1_common_filter_queue(PacketProtocolLayer *ppl)
             break;
 
           default:
-            return FALSE;
+            return false;
         }
     }
 
-    return FALSE;
+    return false;
 }
 
 void ssh1_compute_session_id(

+ 23 - 25
source/putty/sshcrcda.c

@@ -25,16 +25,13 @@
 #include "misc.h"
 #include "ssh.h"
 
-typedef unsigned char uchar;
-typedef unsigned short uint16;
-
 /* SSH Constants */
 #define SSH_MAXBLOCKS	(32 * 1024)
 #define SSH_BLOCKSIZE	(8)
 
 /* Hashing constants */
 #define HASH_MINSIZE	(8 * 1024)
-#define HASH_ENTRYSIZE	(sizeof(uint16))
+#define HASH_ENTRYSIZE	(sizeof(uint16_t))
 #define HASH_FACTOR(x)	((x)*3/2)
 #define HASH_UNUSEDCHAR	(0xff)
 #define HASH_UNUSED	(0xffff)
@@ -47,12 +44,12 @@ typedef unsigned short uint16;
 
 #define CMP(a, b)	(memcmp(a, b, SSH_BLOCKSIZE))
 
-uchar ONE[4] = { 1, 0, 0, 0 };
-uchar ZERO[4] = { 0, 0, 0, 0 };
+uint8_t ONE[4] = { 1, 0, 0, 0 };
+uint8_t ZERO[4] = { 0, 0, 0, 0 };
 
 struct crcda_ctx {
-    uint16 *h;
-    uint32 n;
+    uint16_t *h;
+    uint32_t n;
 };
 
 struct crcda_ctx *crcda_make_context(void)
@@ -72,16 +69,16 @@ void crcda_free_context(struct crcda_ctx *ctx)
     }
 }
 
-static void crc_update(uint32 *a, void *b)
+static void crc_update(uint32_t *a, void *b)
 {
     *a = crc32_update(*a, b, 4);
 }
 
 /* detect if a block is used in a particular pattern */
-static int check_crc(uchar *S, uchar *buf, uint32 len, uchar *IV)
+static bool check_crc(uint8_t *S, uint8_t *buf, uint32_t len, uint8_t *IV)
 {
-    uint32 crc;
-    uchar *c;
+    uint32_t crc;
+    uint8_t *c;
 
     crc = 0;
     if (IV && !CMP(S, IV)) {
@@ -101,12 +98,13 @@ static int check_crc(uchar *S, uchar *buf, uint32 len, uchar *IV)
 }
 
 /* Detect a crc32 compensation attack on a packet */
-int detect_attack(struct crcda_ctx *ctx, uchar *buf, uint32 len, uchar *IV)
+bool detect_attack(
+    struct crcda_ctx *ctx, uint8_t *buf, uint32_t len, uint8_t *IV)
 {
-    register uint32 i, j;
-    uint32 l;
-    register uchar *c;
-    uchar *d;
+    register uint32_t i, j;
+    uint32_t l;
+    register uint8_t *c;
+    uint8_t *d;
 
     assert(!(len > (SSH_MAXBLOCKS * SSH_BLOCKSIZE) ||
              len % SSH_BLOCKSIZE != 0));
@@ -115,11 +113,11 @@ int detect_attack(struct crcda_ctx *ctx, uchar *buf, uint32 len, uchar *IV)
 
     if (ctx->h == NULL) {
         ctx->n = l;
-        ctx->h = snewn(ctx->n, uint16);
+        ctx->h = snewn(ctx->n, uint16_t);
     } else {
         if (l > ctx->n) {
             ctx->n = l;
-            ctx->h = sresize(ctx->h, ctx->n, uint16);
+            ctx->h = sresize(ctx->h, ctx->n, uint16_t);
         }
     }
 
@@ -127,20 +125,20 @@ int detect_attack(struct crcda_ctx *ctx, uchar *buf, uint32 len, uchar *IV)
         for (c = buf; c < buf + len; c += SSH_BLOCKSIZE) {
             if (IV && (!CMP(c, IV))) {
                 if ((check_crc(c, buf, len, IV)))
-                    return 1;          /* attack detected */
+                    return true;          /* attack detected */
                 else
                     break;
             }
             for (d = buf; d < c; d += SSH_BLOCKSIZE) {
                 if (!CMP(c, d)) {
                     if ((check_crc(c, buf, len, IV)))
-                        return 1;      /* attack detected */
+                        return true;      /* attack detected */
                     else
                         break;
                 }
             }
         }
-        return 0;                      /* ok */
+        return false;                  /* ok */
     }
     memset(ctx->h, HASH_UNUSEDCHAR, ctx->n * HASH_ENTRYSIZE);
 
@@ -153,18 +151,18 @@ int detect_attack(struct crcda_ctx *ctx, uchar *buf, uint32 len, uchar *IV)
             if (ctx->h[i] == HASH_IV) {
                 if (!CMP(c, IV)) {
                     if (check_crc(c, buf, len, IV))
-                        return 1;      /* attack detected */
+                        return true;      /* attack detected */
                     else
                         break;
                 }
             } else if (!CMP(c, buf + ctx->h[i] * SSH_BLOCKSIZE)) {
                 if (check_crc(c, buf, len, IV))
-                    return 1;          /* attack detected */
+                    return true;          /* attack detected */
                 else
                     break;
             }
         }
         ctx->h[i] = j;
     }
-    return 0;                          /* ok */
+    return false;                          /* ok */
 }

+ 20 - 19
source/putty/sshdes.c

@@ -277,16 +277,16 @@
  */
 
 typedef struct {
-    word32 k0246[16], k1357[16];
-    word32 iv0, iv1;
+    uint32_t k0246[16], k1357[16];
+    uint32_t iv0, iv1;
 } DESContext;
 
 #define rotl(x, c) ( (x << c) | (x >> (32-c)) )
 #define rotl28(x, c) ( ( (x << c) | (x >> (28-c)) ) & 0x0FFFFFFF)
 
-static word32 bitsel(word32 * input, const int *bitnums, int size)
+static uint32_t bitsel(uint32_t *input, const int *bitnums, int size)
 {
-    word32 ret = 0;
+    uint32_t ret = 0;
     while (size--) {
 	int bitpos = *bitnums++;
 	ret <<= 1;
@@ -296,7 +296,8 @@ static word32 bitsel(word32 * input, const int *bitnums, int size)
     return ret;
 }
 
-static void des_key_setup(word32 key_msw, word32 key_lsw, DESContext * sched)
+static void des_key_setup(
+    uint32_t key_msw, uint32_t key_lsw, DESContext *sched)
 {
 
     static const int PC1_Cbits[] = {
@@ -326,8 +327,8 @@ static void des_key_setup(word32 key_msw, word32 key_lsw, DESContext * sched)
     static const int leftshifts[] =
 	{ 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 };
 
-    word32 C, D;
-    word32 buf[2];
+    uint32_t C, D;
+    uint32_t buf[2];
     int i;
 
     buf[0] = key_lsw;
@@ -348,7 +349,7 @@ static void des_key_setup(word32 key_msw, word32 key_lsw, DESContext * sched)
     sched->iv0 = sched->iv1 = 0;
 }
 
-static const word32 SPboxes[8][64] = {
+static const uint32_t SPboxes[8][64] = {
     {0x01010400, 0x00000000, 0x00010000, 0x01010404,
      0x01010004, 0x00010404, 0x00000004, 0x00010000,
      0x00000400, 0x01010400, 0x01010404, 0x00000400,
@@ -520,10 +521,10 @@ static const word32 SPboxes[8][64] = {
     bitswap(R, L, 16, 0x0000FFFF), \
     bitswap(R, L,  4, 0x0F0F0F0F))
 
-static void des_encipher(word32 * output, word32 L, word32 R,
-			 DESContext * sched)
+static void des_encipher(
+    uint32_t *output, uint32_t L, uint32_t R, DESContext *sched)
 {
-    word32 swap, s0246, s1357;
+    uint32_t swap, s0246, s1357;
 
     IP(L, R);
 
@@ -560,10 +561,10 @@ static void des_encipher(word32 * output, word32 L, word32 R,
     output[1] = R;
 }
 
-static void des_decipher(word32 * output, word32 L, word32 R,
-			 DESContext * sched)
+static void des_decipher(
+    uint32_t *output, uint32_t L, uint32_t R, DESContext *sched)
 {
-    word32 swap, s0246, s1357;
+    uint32_t swap, s0246, s1357;
 
     IP(L, R);
 
@@ -603,7 +604,7 @@ static void des_decipher(word32 * output, word32 L, word32 R,
 static void des_cbc_encrypt(unsigned char *blk,
 			    unsigned int len, DESContext * sched)
 {
-    word32 out[2], iv0, iv1;
+    uint32_t out[2], iv0, iv1;
     unsigned int i;
 
     assert((len & 7) == 0);
@@ -627,7 +628,7 @@ static void des_cbc_encrypt(unsigned char *blk,
 static void des_cbc_decrypt(unsigned char *blk,
 			    unsigned int len, DESContext * sched)
 {
-    word32 out[2], iv0, iv1, xL, xR;
+    uint32_t out[2], iv0, iv1, xL, xR;
     unsigned int i;
 
     assert((len & 7) == 0);
@@ -661,7 +662,7 @@ static void des_3cbc_encrypt(unsigned char *blk,
 static void des_cbc3_encrypt(unsigned char *blk,
 			     unsigned int len, DESContext * scheds)
 {
-    word32 out[2], iv0, iv1;
+    uint32_t out[2], iv0, iv1;
     unsigned int i;
 
     assert((len & 7) == 0);
@@ -695,7 +696,7 @@ static void des_3cbc_decrypt(unsigned char *blk,
 static void des_cbc3_decrypt(unsigned char *blk,
 			     unsigned int len, DESContext * scheds)
 {
-    word32 out[2], iv0, iv1, xL, xR;
+    uint32_t out[2], iv0, iv1, xL, xR;
     unsigned int i;
 
     assert((len & 7) == 0);
@@ -723,7 +724,7 @@ static void des_cbc3_decrypt(unsigned char *blk,
 static void des_sdctr3(unsigned char *blk,
 			     unsigned int len, DESContext * scheds)
 {
-    word32 b[2], iv0, iv1, tmp;
+    uint32_t b[2], iv0, iv1, tmp;
     unsigned int i;
 
     assert((len & 7) == 0);

+ 9 - 1
source/putty/sshdh.c

@@ -178,7 +178,7 @@ static void dh_init(struct dh_ctx *ctx)
     ctx->x = ctx->e = NULL;
 }
 
-int dh_is_gex(const struct ssh_kex *kex)
+bool dh_is_gex(const struct ssh_kex *kex)
 {
     const struct dh_extra *extra = (const struct dh_extra *)kex->extra;
     return extra->pdata == NULL;
@@ -209,6 +209,14 @@ struct dh_ctx *dh_setup_gex(Bignum pval, Bignum gval)
     return ctx;
 }
 
+/*
+ * Return size of DH modulus p.
+ */
+int dh_modulus_bit_size(const struct dh_ctx *ctx)
+{
+    return bignum_bitcount(ctx->p);
+}
+
 /*
  * Clean up and free a context.
  */

+ 11 - 10
source/putty/sshdss.c

@@ -104,16 +104,16 @@ static char *dss_cache_str(ssh_key *key)
     return p;
 }
 
-static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
+static bool dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
 {
     struct dss_key *dss = container_of(key, struct dss_key, sshk);
     BinarySource src[1];
     unsigned char hash[20];
     Bignum r, s, w, gu1p, yu2p, gu1yu2p, u1, u2, sha, v;
-    int ret;
+    bool toret;
 
     if (!dss->p)
-	return 0;
+	return false;
 
     BinarySource_BARE_INIT(src, sig.ptr, sig.len);
 
@@ -134,7 +134,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
 
         if (get_err(src) || !ptrlen_eq_string(type, "ssh-dss") ||
             sig.len != 40)
-            return 0;
+            return false;
     }
 
     /* Now we're sitting on a 40-byte string for sure. */
@@ -145,13 +145,13 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
             freebn(r);
         if (s)
             freebn(s);
-	return 0;
+	return false;
     }
 
     if (!bignum_cmp(s, Zero)) {
         freebn(r);
         freebn(s);
-        return 0;
+        return false;
     }
 
     /*
@@ -161,7 +161,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
     if (!w) {
         freebn(r);
         freebn(s);
-        return 0;
+        return false;
     }
 
     /*
@@ -188,7 +188,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
      * Step 5. v should now be equal to r.
      */
 
-    ret = !bignum_cmp(v, r);
+    toret = !bignum_cmp(v, r);
 
     freebn(w);
     freebn(sha);
@@ -201,7 +201,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
     freebn(r);
     freebn(s);
 
-    return ret;
+    return toret;
 }
 
 static void dss_public_blob(ssh_key *key, BinarySink *bs)
@@ -447,7 +447,7 @@ Bignum *dss_gen_k(const char *id_string, Bignum modulus, Bignum private_key,
 }
 
 static void dss_sign(ssh_key *key, const void *data, int datalen,
-                     BinarySink *bs)
+                     unsigned flags, BinarySink *bs)
 {
     struct dss_key *dss = container_of(key, struct dss_key, sshk);
     Bignum k, gkp, hash, kinv, hxr, r, s;
@@ -504,4 +504,5 @@ const ssh_keyalg ssh_dss = {
     "ssh-dss",
     "dss",
     NULL,
+    0, /* no supported flags */
 };

+ 119 - 116
source/putty/sshecc.c

@@ -64,7 +64,7 @@ static void initialise_wcurve(struct ec_curve *curve, int bits,
     curve->w.G.x = bignum_from_bytes(Gx, length);
     curve->w.G.y = bignum_from_bytes(Gy, length);
     curve->w.G.curve = curve;
-    curve->w.G.infinity = 0;
+    curve->w.G.infinity = false;
 }
 
 static void initialise_mcurve(struct ec_curve *curve, int bits,
@@ -89,7 +89,7 @@ static void initialise_mcurve(struct ec_curve *curve, int bits,
     curve->m.G.y = NULL;
     curve->m.G.z = NULL;
     curve->m.G.curve = curve;
-    curve->m.G.infinity = 0;
+    curve->m.G.infinity = false;
 }
 
 static void initialise_ecurve(struct ec_curve *curve, int bits,
@@ -113,13 +113,13 @@ static void initialise_ecurve(struct ec_curve *curve, int bits,
     curve->e.B.x = bignum_from_bytes(Bx, length);
     curve->e.B.y = bignum_from_bytes(By, length);
     curve->e.B.curve = curve;
-    curve->e.B.infinity = 0;
+    curve->e.B.infinity = false;
 }
 
 static struct ec_curve *ec_p256(void)
 {
     static struct ec_curve curve = { 0 };
-    static unsigned char initialised = 0;
+    static bool initialised = false;
 
     if (!initialised)
     {
@@ -164,7 +164,7 @@ static struct ec_curve *ec_p256(void)
         curve.textname = curve.name = "nistp256";
 
         /* Now initialised, no need to do it again */
-        initialised = 1;
+        initialised = true;
     }
 
     return &curve;
@@ -173,7 +173,7 @@ static struct ec_curve *ec_p256(void)
 static struct ec_curve *ec_p384(void)
 {
     static struct ec_curve curve = { 0 };
-    static unsigned char initialised = 0;
+    static bool initialised = false;
 
     if (!initialised)
     {
@@ -230,7 +230,7 @@ static struct ec_curve *ec_p384(void)
         curve.textname = curve.name = "nistp384";
 
         /* Now initialised, no need to do it again */
-        initialised = 1;
+        initialised = true;
     }
 
     return &curve;
@@ -239,7 +239,7 @@ static struct ec_curve *ec_p384(void)
 static struct ec_curve *ec_p521(void)
 {
     static struct ec_curve curve = { 0 };
-    static unsigned char initialised = 0;
+    static bool initialised = false;
 
     if (!initialised)
     {
@@ -314,7 +314,7 @@ static struct ec_curve *ec_p521(void)
         curve.textname = curve.name = "nistp521";
 
         /* Now initialised, no need to do it again */
-        initialised = 1;
+        initialised = true;
     }
 
     return &curve;
@@ -323,7 +323,7 @@ static struct ec_curve *ec_p521(void)
 static struct ec_curve *ec_curve25519(void)
 {
     static struct ec_curve curve = { 0 };
-    static unsigned char initialised = 0;
+    static bool initialised = false;
 
     if (!initialised)
     {
@@ -359,7 +359,7 @@ static struct ec_curve *ec_curve25519(void)
         curve.textname = "Curve25519";
 
         /* Now initialised, no need to do it again */
-        initialised = 1;
+        initialised = true;
     }
 
     return &curve;
@@ -368,7 +368,7 @@ static struct ec_curve *ec_curve25519(void)
 static struct ec_curve *ec_ed25519(void)
 {
     static struct ec_curve curve = { 0 };
-    static unsigned char initialised = 0;
+    static bool initialised = false;
 
     if (!initialised)
     {
@@ -411,7 +411,7 @@ static struct ec_curve *ec_ed25519(void)
         curve.textname = "Ed25519";
 
         /* Now initialised, no need to do it again */
-        initialised = 1;
+        initialised = true;
     }
 
     return &curve;
@@ -419,13 +419,13 @@ static struct ec_curve *ec_ed25519(void)
 
 /* Return 1 if a is -3 % p, otherwise return 0
  * This is used because there are some maths optimisations */
-static int ec_aminus3(const struct ec_curve *curve)
+static bool ec_aminus3(const struct ec_curve *curve)
 {
-    int ret;
+    bool ret;
     Bignum _p;
 
     if (curve->type != EC_WEIERSTRASS) {
-        return 0;
+        return false;
     }
 
     _p = bignum_add_long(curve->w.a, 3);
@@ -512,20 +512,20 @@ void ec_point_free(struct ec_point *point)
     if (point->x) freebn(point->x);
     if (point->y) freebn(point->y);
     if (point->z) freebn(point->z);
-    point->infinity = 0;
+    point->infinity = false;
     sfree(point);
 }
 
 static struct ec_point *ec_point_new(const struct ec_curve *curve,
                                      const Bignum x, const Bignum y, const Bignum z,
-                                     unsigned char infinity)
+                                     bool infinity)
 {
     struct ec_point *point = snewn(1, struct ec_point);
     point->curve = curve;
     point->x = x;
     point->y = y;
     point->z = z;
-    point->infinity = infinity ? 1 : 0;
+    point->infinity = infinity;
     return point;
 }
 
@@ -539,14 +539,14 @@ static struct ec_point *ec_point_copy(const struct ec_point *a)
                         a->infinity);
 }
 
-static int ec_point_verify(const struct ec_point *a)
+static bool ec_point_verify(const struct ec_point *a)
 {
     if (a->infinity) {
-        return 1;
+        return true;
     } else if (a->curve->type == EC_EDWARDS) {
         /* Check y^2 - x^2 - 1 - d * x^2 * y^2 == 0 */
         Bignum y2, x2, tmp, tmp2, tmp3;
-        int ret;
+        bool ret;
 
         y2 = ecf_square(a->y, a->curve);
         x2 = ecf_square(a->x, a->curve);
@@ -564,7 +564,7 @@ static int ec_point_verify(const struct ec_point *a)
         return ret;
     } else if (a->curve->type == EC_WEIERSTRASS) {
         /* Verify y^2 = x^3 + ax + b */
-        int ret = 0;
+        bool ret = false;
 
         Bignum lhs = NULL, x3 = NULL, ax = NULL, x3ax = NULL, x3axm = NULL, x3axb = NULL, rhs = NULL;
 
@@ -586,13 +586,13 @@ static int ec_point_verify(const struct ec_point *a)
         rhs = bigmod(x3axb, a->curve->p);
         freebn(x3axb);
 
-        ret = bignum_cmp(lhs, rhs) ? 0 : 1;
+        ret = !bignum_cmp(lhs, rhs);
         freebn(lhs);
         freebn(rhs);
 
         return ret;
     } else {
-        return 0;
+        return false;
     }
 }
 
@@ -600,17 +600,17 @@ static int ec_point_verify(const struct ec_point *a)
  * Elliptic curve point maths
  */
 
-/* Returns 1 on success and 0 on memory error */
-static int ecp_normalise(struct ec_point *a)
+/* Returns true on success and false on memory error */
+static bool ecp_normalise(struct ec_point *a)
 {
     if (!a) {
         /* No point */
-        return 0;
+        return false;
     }
 
     if (a->infinity) {
         /* Point is at infinity - i.e. normalised */
-        return 1;
+        return true;
     }
 
     if (a->curve->type == EC_WEIERSTRASS) {
@@ -621,17 +621,17 @@ static int ecp_normalise(struct ec_point *a)
 
         if (!a->x || !a->y) {
             /* No point defined */
-            return 0;
+            return false;
         } else if (!a->z) {
             /* Already normalised */
-            return 1;
+            return true;
         }
 
         Z2 = ecf_square(a->z, a->curve);
         Z2inv = modinv(Z2, a->curve->p);
         if (!Z2inv) {
             freebn(Z2);
-            return 0;
+            return false;
         }
         tx = modmul(a->x, Z2inv, a->curve->p);
         freebn(Z2inv);
@@ -642,7 +642,7 @@ static int ecp_normalise(struct ec_point *a)
         freebn(Z3);
         if (!Z3inv) {
             freebn(tx);
-            return 0;
+            return false;
         }
         ty = modmul(a->y, Z3inv, a->curve->p);
         freebn(Z3inv);
@@ -653,7 +653,7 @@ static int ecp_normalise(struct ec_point *a)
         a->y = ty;
         freebn(a->z);
         a->z = NULL;
-        return 1;
+        return true;
     } else if (a->curve->type == EC_MONTGOMERY) {
         /* In Montgomery (X : Z) represents the x co-ord (X / Z, ?) */
 
@@ -661,15 +661,15 @@ static int ecp_normalise(struct ec_point *a)
 
         if (!a->x) {
             /* No point defined */
-            return 0;
+            return false;
         } else if (!a->z) {
             /* Already normalised */
-            return 1;
+            return true;
         }
 
         tmp = modinv(a->z, a->curve->p);
         if (!tmp) {
-            return 0;
+            return false;
         }
         tmp2 = modmul(a->x, tmp, a->curve->p);
         freebn(tmp);
@@ -678,23 +678,23 @@ static int ecp_normalise(struct ec_point *a)
         a->z = NULL;
         freebn(a->x);
         a->x = tmp2;
-        return 1;
+        return true;
     } else if (a->curve->type == EC_EDWARDS) {
         /* Always normalised */
-        return 1;
+        return true;
     } else {
-        return 0;
+        return false;
     }
 }
 
-static struct ec_point *ecp_doublew(const struct ec_point *a, const int aminus3)
+static struct ec_point *ecp_doublew(const struct ec_point *a, bool aminus3)
 {
     Bignum S, M, outx, outy, outz;
 
     if (bignum_cmp(a->y, Zero) == 0)
     {
         /* Identity */
-        return ec_point_new(a->curve, NULL, NULL, NULL, 1);
+        return ec_point_new(a->curve, NULL, NULL, NULL, true);
     }
 
     /* S = 4*X*Y^2 */
@@ -802,7 +802,7 @@ static struct ec_point *ecp_doublew(const struct ec_point *a, const int aminus3)
         freebn(YZ);
     }
 
-    return ec_point_new(a->curve, outx, outy, outz, 0);
+    return ec_point_new(a->curve, outx, outy, outz, false);
 }
 
 static struct ec_point *ecp_doublem(const struct ec_point *a)
@@ -865,20 +865,20 @@ static struct ec_point *ecp_doublem(const struct ec_point *a)
         freebn(tmp);
     }
 
-    return ec_point_new(a->curve, outx, NULL, outz, 0);
+    return ec_point_new(a->curve, outx, NULL, outz, false);
 }
 
 /* Forward declaration for Edwards curve doubling */
 static struct ec_point *ecp_add(const struct ec_point *a,
                                 const struct ec_point *b,
-                                const int aminus3);
+                                bool aminus3);
 
-static struct ec_point *ecp_double(const struct ec_point *a, const int aminus3)
+static struct ec_point *ecp_double(const struct ec_point *a, bool aminus3)
 {
     if (a->infinity)
     {
         /* Identity */
-        return ec_point_new(a->curve, NULL, NULL, NULL, 1);
+        return ec_point_new(a->curve, NULL, NULL, NULL, true);
     }
 
     if (a->curve->type == EC_EDWARDS)
@@ -897,7 +897,7 @@ static struct ec_point *ecp_double(const struct ec_point *a, const int aminus3)
 
 static struct ec_point *ecp_addw(const struct ec_point *a,
                                  const struct ec_point *b,
-                                 const int aminus3)
+                                 bool aminus3)
 {
     Bignum U1, U2, S1, S2, outx, outy, outz;
 
@@ -949,7 +949,7 @@ static struct ec_point *ecp_addw(const struct ec_point *a,
             freebn(S1);
             freebn(S2);
             /* Infinity */
-            return ec_point_new(a->curve, NULL, NULL, NULL, 1);
+            return ec_point_new(a->curve, NULL, NULL, NULL, true);
         }
     }
 
@@ -1019,7 +1019,7 @@ static struct ec_point *ecp_addw(const struct ec_point *a,
         }
     }
 
-    return ec_point_new(a->curve, outx, outy, outz, 0);
+    return ec_point_new(a->curve, outx, outy, outz, false);
 }
 
 static struct ec_point *ecp_addm(const struct ec_point *a,
@@ -1070,7 +1070,7 @@ static struct ec_point *ecp_addm(const struct ec_point *a,
         freebn(tmp2);
     }
 
-    return ec_point_new(a->curve, outx, NULL, outz, 0);
+    return ec_point_new(a->curve, outx, NULL, outz, false);
 }
 
 static struct ec_point *ecp_adde(const struct ec_point *a,
@@ -1135,12 +1135,12 @@ static struct ec_point *ecp_adde(const struct ec_point *a,
         freebn(tmp2);
     }
 
-    return ec_point_new(a->curve, outx, outy, NULL, 0);
+    return ec_point_new(a->curve, outx, outy, NULL, false);
 }
 
 static struct ec_point *ecp_add(const struct ec_point *a,
                                 const struct ec_point *b,
-                                const int aminus3)
+                                bool aminus3)
 {
     if (a->curve != b->curve) {
         return NULL;
@@ -1163,13 +1163,14 @@ static struct ec_point *ecp_add(const struct ec_point *a,
     return NULL;
 }
 
-static struct ec_point *ecp_mul_(const struct ec_point *a, const Bignum b, int aminus3)
+static struct ec_point *ecp_mul_(
+    const struct ec_point *a, const Bignum b, bool aminus3)
 {
     struct ec_point *A, *ret;
     int bits, i;
 
     A = ec_point_copy(a);
-    ret = ec_point_new(a->curve, NULL, NULL, NULL, 1);
+    ret = ec_point_new(a->curve, NULL, NULL, NULL, true);
 
     bits = bignum_bitcount(b);
     for (i = 0; i < bits; ++i)
@@ -1209,18 +1210,18 @@ static struct ec_point *ecp_mule(const struct ec_point *a, const Bignum b)
     int i;
     struct ec_point *ret;
 
-    ret = ec_point_new(a->curve, NULL, NULL, NULL, 1);
+    ret = ec_point_new(a->curve, NULL, NULL, NULL, true);
 
     for (i = bignum_bitcount(b); i >= 0 && ret; --i)
     {
         {
-            struct ec_point *tmp = ecp_double(ret, 0);
+            struct ec_point *tmp = ecp_double(ret, false);
             ec_point_free(ret);
             ret = tmp;
         }
         if (ret && bignum_bit(b, i))
         {
-            struct ec_point *tmp = ecp_add(ret, a, 0);
+            struct ec_point *tmp = ecp_add(ret, a, false);
             ec_point_free(ret);
             ret = tmp;
         }
@@ -1235,7 +1236,7 @@ static struct ec_point *ecp_mulm(const struct ec_point *p, const Bignum n)
     int bits, i;
 
     /* P1 <- P and P2 <- [2]P */
-    P2 = ecp_double(p, 0);
+    P2 = ecp_double(p, false);
     P1 = ec_point_copy(p);
 
     /* for i = bits − 2 down to 0 */
@@ -1250,7 +1251,7 @@ static struct ec_point *ecp_mulm(const struct ec_point *p, const Bignum n)
             P2 = tmp;
 
             /* P1 <- [2]P1 */
-            tmp = ecp_double(P1, 0);
+            tmp = ecp_double(P1, false);
             ec_point_free(P1);
             P1 = tmp;
         }
@@ -1262,7 +1263,7 @@ static struct ec_point *ecp_mulm(const struct ec_point *p, const Bignum n)
             P1 = tmp;
 
             /* P2 <- [2]P2 */
-            tmp = ecp_double(P2, 0);
+            tmp = ecp_double(P2, false);
             ec_point_free(P2);
             P2 = tmp;
         }
@@ -1294,7 +1295,7 @@ static struct ec_point *ecp_summul(const Bignum a, const Bignum b,
                                    const struct ec_point *point)
 {
     struct ec_point *aG, *bP, *ret;
-    int aminus3;
+    bool aminus3;
 
     if (point->curve->type != EC_WEIERSTRASS) {
         return NULL;
@@ -1446,23 +1447,23 @@ struct ec_point *ec_public(const Bignum privateKey, const struct ec_curve *curve
  * Basic sign and verify routines
  */
 
-static int _ecdsa_verify(const struct ec_point *publicKey,
-                         const unsigned char *data, const int dataLen,
-                         const Bignum r, const Bignum s)
+static bool _ecdsa_verify(const struct ec_point *publicKey,
+                          const unsigned char *data, const int dataLen,
+                          const Bignum r, const Bignum s)
 {
     int z_bits, n_bits;
     Bignum z;
-    int valid = 0;
+    bool valid = false;
 
     if (publicKey->curve->type != EC_WEIERSTRASS) {
-        return 0;
+        return false;
     }
 
     /* Sanity checks */
     if (bignum_cmp(r, Zero) == 0 || bignum_cmp(r, publicKey->curve->w.n) >= 0
         || bignum_cmp(s, Zero) == 0 || bignum_cmp(s, publicKey->curve->w.n) >= 0)
     {
-        return 0;
+        return false;
     }
 
     /* z = left most bitlen(curve->n) of data */
@@ -1491,7 +1492,7 @@ static int _ecdsa_verify(const struct ec_point *publicKey,
         w = modinv(s, publicKey->curve->w.n);
         if (!w) {
             freebn(z);
-            return 0;
+            return false;
         }
         u1 = modmul(z, w, publicKey->curve->w.n);
         u2 = modmul(r, w, publicKey->curve->w.n);
@@ -1502,13 +1503,13 @@ static int _ecdsa_verify(const struct ec_point *publicKey,
         freebn(u2);
         if (!tmp) {
             freebn(z);
-            return 0;
+            return false;
         }
 
         x = bigmod(tmp->x, publicKey->curve->w.n);
         ec_point_free(tmp);
 
-        valid = (bignum_cmp(r, x) == 0) ? 1 : 0;
+        valid = (bignum_cmp(r, x) == 0);
         freebn(x);
     }
 
@@ -1597,16 +1598,16 @@ static Bignum BinarySource_get_mp_le(BinarySource *src)
 }
 #define get_mp_le(src) BinarySource_get_mp_le(BinarySource_UPCAST(src))
 
-static int decodepoint_ed(const char *p, int length, struct ec_point *point)
+static bool decodepoint_ed(const char *p, int length, struct ec_point *point)
 {
     /* Got some conversion to do, first read in the y co-ord */
-    int negative;
+    bool negative;
 
     point->y = bignum_from_bytes_le((const unsigned char*)p, length);
     if ((unsigned)bignum_bitcount(point->y) > point->curve->fieldBits) {
         freebn(point->y);
         point->y = NULL;
-        return 0;
+        return false;
     }
     /* Read x bit and then reset it */
     negative = bignum_bit(point->y, point->curve->fieldBits - 1);
@@ -1618,7 +1619,7 @@ static int decodepoint_ed(const char *p, int length, struct ec_point *point)
     if (!point->x) {
         freebn(point->y);
         point->y = NULL;
-        return 0;
+        return false;
     }
     if (negative) {
         Bignum tmp = modsub(point->curve->p, point->x, point->curve->p);
@@ -1632,20 +1633,20 @@ static int decodepoint_ed(const char *p, int length, struct ec_point *point)
         point->x = NULL;
         freebn(point->y);
         point->y = NULL;
-        return 0;
+        return false;
     }
 
-    return 1;
+    return true;
 }
 
-static int decodepoint(const char *p, int length, struct ec_point *point)
+static bool decodepoint(const char *p, int length, struct ec_point *point)
 {
     if (point->curve->type == EC_EDWARDS) {
         return decodepoint_ed(p, length, point);
     }
 
     if (length < 1 || p[0] != 0x04) /* Only support uncompressed point */
-        return 0;
+        return false;
     /* Skip compression flag */
     ++p;
     --length;
@@ -1654,7 +1655,7 @@ static int decodepoint(const char *p, int length, struct ec_point *point)
         point->x = NULL;
         point->y = NULL;
         point->z = NULL;
-        return 0;
+        return false;
     }
     length = length / 2;
     point->x = bignum_from_bytes(p, length);
@@ -1668,16 +1669,16 @@ static int decodepoint(const char *p, int length, struct ec_point *point)
         point->x = NULL;
         freebn(point->y);
         point->y = NULL;
-        return 0;
+        return false;
     }
 
-    return 1;
+    return true;
 }
 
-static int BinarySource_get_point(BinarySource *src, struct ec_point *point)
+static bool BinarySource_get_point(BinarySource *src, struct ec_point *point)
 {
     ptrlen str = get_string(src);
-    if (get_err(src)) return 0;
+    if (get_err(src)) return false;
     return decodepoint(str.ptr, str.len, point);
 }
 #define get_point(src, pt) BinarySource_get_point(BinarySource_UPCAST(src), pt)
@@ -1737,7 +1738,7 @@ static ssh_key *ecdsa_new_pub(const ssh_keyalg *self, ptrlen data)
     ec->sshk = self;
 
     ec->publicKey.curve = curve;
-    ec->publicKey.infinity = 0;
+    ec->publicKey.infinity = false;
     ec->publicKey.x = NULL;
     ec->publicKey.y = NULL;
     ec->publicKey.z = NULL;
@@ -1925,7 +1926,7 @@ static ssh_key *ed25519_new_priv_openssh(const ssh_keyalg *self,
     ec->sshk = self;
 
     ec->publicKey.curve = ec_ed25519();
-    ec->publicKey.infinity = 0;
+    ec->publicKey.infinity = false;
     ec->privateKey = NULL;
     ec->publicKey.x = NULL;
     ec->publicKey.z = NULL;
@@ -2019,7 +2020,7 @@ static ssh_key *ecdsa_new_priv_openssh(const ssh_keyalg *self,
     ec->sshk = self;
 
     ec->publicKey.curve = curve;
-    ec->publicKey.infinity = 0;
+    ec->publicKey.infinity = false;
     ec->publicKey.x = NULL;
     ec->publicKey.y = NULL;
     ec->publicKey.z = NULL;
@@ -2106,27 +2107,27 @@ static int ecdsa_pubkey_bits(const ssh_keyalg *self, ptrlen blob)
     return ret;
 }
 
-static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
+static bool ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
 {
     struct ec_key *ec = container_of(key, struct ec_key, sshk);
     const struct ecsign_extra *extra =
         (const struct ecsign_extra *)ec->sshk->extra;
     BinarySource src[1];
     ptrlen sigstr;
-    int ret;
+    bool ret;
 
     if (!ec->publicKey.x || !ec->publicKey.y || !ec->publicKey.curve)
-        return 0;
+        return false;
 
     BinarySource_BARE_INIT(src, sig.ptr, sig.len);
 
     /* Check the signature starts with the algorithm name */
     if (!ptrlen_eq_string(get_string(src), ec->sshk->ssh_id))
-        return 0;
+        return false;
 
     sigstr = get_string(src);
     if (get_err(src))
-        return 0;
+        return false;
 
     if (ec->publicKey.curve->type == EC_EDWARDS) {
         struct ec_point *r;
@@ -2135,22 +2136,22 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
 
         /* Check that the signature is two times the length of a point */
         if (sigstr.len != pointlen * 2) {
-            return 0;
+            return false;
         }
 
         /* Check it's the 256 bit field so that SHA512 is the correct hash */
         if (ec->publicKey.curve->fieldBits != 256) {
-            return 0;
+            return false;
         }
 
         /* Get the signature */
-        r = ec_point_new(ec->publicKey.curve, NULL, NULL, NULL, 0);
+        r = ec_point_new(ec->publicKey.curve, NULL, NULL, NULL, false);
         if (!r) {
-            return 0;
+            return false;
         }
         if (!decodepoint(sigstr.ptr, pointlen, r)) {
             ec_point_free(r);
-            return 0;
+            return false;
         }
         s = bignum_from_bytes_le(
             (const char *)sigstr.ptr + pointlen, pointlen);
@@ -2193,7 +2194,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
             if (!lhs) {
                 ec_point_free(r);
                 freebn(h);
-                return 0;
+                return false;
             }
 
             /* rhs = r + h*publicKey */
@@ -2202,14 +2203,14 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
             if (!tmp) {
                 ec_point_free(lhs);
                 ec_point_free(r);
-                return 0;
+                return false;
             }
-            rhs = ecp_add(r, tmp, 0);
+            rhs = ecp_add(r, tmp, false);
             ec_point_free(r);
             ec_point_free(tmp);
             if (!rhs) {
                 ec_point_free(lhs);
-                return 0;
+                return false;
             }
 
             /* Check the point is the same */
@@ -2217,7 +2218,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
             if (ret) {
                 ret = !bignum_cmp(lhs->y, rhs->y);
                 if (ret) {
-                    ret = 1;
+                    ret = true;
                 }
             }
             ec_point_free(lhs);
@@ -2236,7 +2237,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
         if (get_err(src)) {
             freebn(r);
             freebn(s);
-            return 0;
+            return false;
         }
 
         digestLen = extra->hash->hlen;
@@ -2256,7 +2257,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
 }
 
 static void ecdsa_sign(ssh_key *key, const void *data, int datalen,
-                       BinarySink *bs)
+                       unsigned flags, BinarySink *bs)
 {
     struct ec_key *ec = container_of(key, struct ec_key, sshk);
     const struct ecsign_extra *extra =
@@ -2412,6 +2413,7 @@ const ssh_keyalg ssh_ecdsa_ed25519 = {
     "ssh-ed25519",
     "ssh-ed25519",
     &sign_extra_ed25519,
+    0, /* no supported flags */
 };
 
 /* OID: 1.2.840.10045.3.1.7 (ansiX9p256r1) */
@@ -2440,6 +2442,7 @@ const ssh_keyalg ssh_ecdsa_nistp256 = {
     "ecdsa-sha2-nistp256",
     "ecdsa-sha2-nistp256",
     &sign_extra_nistp256,
+    0, /* no supported flags */
 };
 
 /* OID: 1.3.132.0.34 (secp384r1) */
@@ -2468,6 +2471,7 @@ const ssh_keyalg ssh_ecdsa_nistp384 = {
     "ecdsa-sha2-nistp384",
     "ecdsa-sha2-nistp384",
     &sign_extra_nistp384,
+    0, /* no supported flags */
 };
 
 /* OID: 1.3.132.0.35 (secp521r1) */
@@ -2496,6 +2500,7 @@ const ssh_keyalg ssh_ecdsa_nistp521 = {
     "ecdsa-sha2-nistp521",
     "ecdsa-sha2-nistp521",
     &sign_extra_nistp521,
+    0, /* no supported flags */
 };
 
 /* ----------------------------------------------------------------------
@@ -2643,7 +2648,7 @@ Bignum ssh_ecdhkex_getkey(struct ec_key *ec,
 
     if (ec->publicKey.curve->type == EC_WEIERSTRASS) {
         remote.curve = ec->publicKey.curve;
-        remote.infinity = 0;
+        remote.infinity = false;
         if (!decodepoint(remoteKey, remoteKeyLen, &remote)) {
             return NULL;
         }
@@ -2654,7 +2659,7 @@ Bignum ssh_ecdhkex_getkey(struct ec_key *ec,
         }
 
         remote.curve = ec->publicKey.curve;
-        remote.infinity = 0;
+        remote.infinity = false;
         remote.x = bignum_from_bytes_le((const unsigned char *)remoteKey,
                                         remoteKeyLen);
         remote.y = NULL;
@@ -2746,28 +2751,26 @@ const unsigned char *ec_alg_oid(const ssh_keyalg *alg,
 const int ec_nist_curve_lengths[] = { 256, 384, 521 };
 const int n_ec_nist_curve_lengths = lenof(ec_nist_curve_lengths);
 
-int ec_nist_alg_and_curve_by_bits(int bits,
-                                  const struct ec_curve **curve,
-                                  const ssh_keyalg **alg)
+bool ec_nist_alg_and_curve_by_bits(
+    int bits, const struct ec_curve **curve, const ssh_keyalg **alg)
 {
     switch (bits) {
       case 256: *alg = &ssh_ecdsa_nistp256; break;
       case 384: *alg = &ssh_ecdsa_nistp384; break;
       case 521: *alg = &ssh_ecdsa_nistp521; break;
-      default: return FALSE;
+      default: return false;
     }
     *curve = ((struct ecsign_extra *)(*alg)->extra)->curve();
-    return TRUE;
+    return true;
 }
 
-int ec_ed_alg_and_curve_by_bits(int bits,
-                                const struct ec_curve **curve,
-                                const ssh_keyalg **alg)
+bool ec_ed_alg_and_curve_by_bits(
+    int bits, const struct ec_curve **curve, const ssh_keyalg **alg)
 {
     switch (bits) {
       case 256: *alg = &ssh_ecdsa_ed25519; break;
-      default: return FALSE;
+      default: return false;
     }
     *curve = ((struct ecsign_extra *)(*alg)->extra)->curve();
-    return TRUE;
+    return true;
 }

+ 4 - 3
source/putty/sshmac.c

@@ -7,10 +7,10 @@
 
 #include "ssh.h"
 
-int ssh2_mac_verresult(ssh2_mac *mac, const void *candidate)
+bool ssh2_mac_verresult(ssh2_mac *mac, const void *candidate)
 {
     unsigned char correct[64]; /* at least as big as all known MACs */
-    int toret;
+    bool toret;
 
     assert(mac->vt->len <= sizeof(correct));
     ssh2_mac_genresult(mac, correct);
@@ -35,7 +35,8 @@ void ssh2_mac_generate(ssh2_mac *mac, void *blk, int len, unsigned long seq)
     return ssh2_mac_genresult(mac, (unsigned char *)blk + len);
 }
 
-int ssh2_mac_verify(ssh2_mac *mac, const void *blk, int len, unsigned long seq)
+bool ssh2_mac_verify(
+    ssh2_mac *mac, const void *blk, int len, unsigned long seq)
 {
     ssh2_mac_prepare(mac, blk, len, seq);
     return ssh2_mac_verresult(mac, (const unsigned char *)blk + len);

+ 14 - 23
source/putty/sshmd5.c

@@ -15,7 +15,7 @@
 #define H(x,y,z) ( (x) ^ (y) ^ (z) )
 #define I(x,y,z) ( (y) ^ ( (x) | ~(z) ) )
 
-#define rol(x,y) ( ((x) << (y)) | (((uint32)x) >> (32-y)) )
+#define rol(x,y) ( ((x) << (y)) | (((uint32_t)x) >> (32-y)) )
 
 #define subround(f,w,x,y,z,k,s,ti) \
        w = x + rol(w + f(x,y,z) + block[k] + ti, s)
@@ -28,9 +28,9 @@ static void MD5_Core_Init(MD5_Core_State * s)
     s->h[3] = 0x10325476;
 }
 
-static void MD5_Block(MD5_Core_State * s, uint32 * block)
+static void MD5_Block(MD5_Core_State *s, uint32_t *block)
 {
-    uint32 a, b, c, d;
+    uint32_t a, b, c, d;
 
     a = s->h[0];
     b = s->h[1];
@@ -122,7 +122,7 @@ void MD5Init(struct MD5Context *s)
 {
     MD5_Core_Init(&s->core);
     s->blkused = 0;
-    s->lenhi = s->lenlo = 0;
+    s->len = 0;
     BinarySink_INIT(s, MD5_BinarySink_write);
 }
 
@@ -130,8 +130,8 @@ static void MD5_BinarySink_write(BinarySink *bs, const void *data, size_t len)
 {
     struct MD5Context *s = BinarySink_DOWNCAST(bs, struct MD5Context);
     const unsigned char *q = (const unsigned char *)data;
-    uint32 wordblock[16];
-    uint32 lenw = len;
+    uint32_t wordblock[16];
+    uint32_t lenw = len;
     int i;
 
     assert(lenw == len);
@@ -139,8 +139,7 @@ static void MD5_BinarySink_write(BinarySink *bs, const void *data, size_t len)
     /*
      * Update the length field.
      */
-    s->lenlo += lenw;
-    s->lenhi += (s->lenlo < lenw);
+    s->len += lenw;
 
     if (s->blkused + len < BLKSIZE) {
 	/*
@@ -159,10 +158,10 @@ static void MD5_BinarySink_write(BinarySink *bs, const void *data, size_t len)
 	    /* Now process the block. Gather bytes little-endian into words */
 	    for (i = 0; i < 16; i++) {
 		wordblock[i] =
-		    (((uint32) s->block[i * 4 + 3]) << 24) |
-		    (((uint32) s->block[i * 4 + 2]) << 16) |
-		    (((uint32) s->block[i * 4 + 1]) << 8) |
-		    (((uint32) s->block[i * 4 + 0]) << 0);
+		    (((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;
@@ -177,28 +176,20 @@ void MD5Final(unsigned char output[16], struct MD5Context *s)
     int i;
     unsigned pad;
     unsigned char c[64];
-    uint32 lenhi, lenlo;
+    uint64_t len;
 
     if (s->blkused >= 56)
 	pad = 56 + 64 - s->blkused;
     else
 	pad = 56 - s->blkused;
 
-    lenhi = (s->lenhi << 3) | (s->lenlo >> (32 - 3));
-    lenlo = (s->lenlo << 3);
+    len = (s->len << 3);
 
     memset(c, 0, pad);
     c[0] = 0x80;
     put_data(s, c, pad);
 
-    c[7] = (lenhi >> 24) & 0xFF;
-    c[6] = (lenhi >> 16) & 0xFF;
-    c[5] = (lenhi >> 8) & 0xFF;
-    c[4] = (lenhi >> 0) & 0xFF;
-    c[3] = (lenlo >> 24) & 0xFF;
-    c[2] = (lenlo >> 16) & 0xFF;
-    c[1] = (lenlo >> 8) & 0xFF;
-    c[0] = (lenlo >> 0) & 0xFF;
+    PUT_64BIT_LSB_FIRST(c, len);
 
     put_data(s, c, 8);
 

+ 18 - 11
source/putty/sshppl.h

@@ -12,11 +12,11 @@ typedef void (*packet_handler_fn_t)(PacketProtocolLayer *ppl, PktIn *pktin);
 struct PacketProtocolLayerVtable {
     void (*free)(PacketProtocolLayer *); 
     void (*process_queue)(PacketProtocolLayer *ppl);
-    int (*get_specials)(
+    bool (*get_specials)(
         PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
     void (*special_cmd)(
         PacketProtocolLayer *ppl, SessionSpecialCode code, int arg);
-    int (*want_user_input)(PacketProtocolLayer *ppl);
+    bool (*want_user_input)(PacketProtocolLayer *ppl);
     void (*got_user_input)(PacketProtocolLayer *ppl);
     void (*reconfigure)(PacketProtocolLayer *ppl, Conf *conf);
 
@@ -97,17 +97,17 @@ PacketProtocolLayer *ssh2_transport_new(
     const char *client_greeting, const char *server_greeting,
     struct ssh_connection_shared_gss_state *shgss,
     struct DataTransferStats *stats, PacketProtocolLayer *higher_layer,
-    int is_server);
+    bool is_server);
 PacketProtocolLayer *ssh2_userauth_new(
     PacketProtocolLayer *successor_layer,
     const char *hostname, const char *fullhostname,
-    Filename *keyfile, int tryagent,
-    const char *default_username, int change_username,
-    int try_ki_auth,
-    int try_gssapi_auth, int try_gssapi_kex_auth,
-    int gssapi_fwd, struct ssh_connection_shared_gss_state *shgss);
+    Filename *keyfile, bool tryagent,
+    const char *default_username, bool change_username,
+    bool try_ki_auth,
+    bool try_gssapi_auth, bool try_gssapi_kex_auth,
+    bool gssapi_fwd, struct ssh_connection_shared_gss_state *shgss);
 PacketProtocolLayer *ssh2_connection_new(
-    Ssh *ssh, ssh_sharing_state *connshare, int is_simple,
+    Ssh *ssh, ssh_sharing_state *connshare, bool is_simple,
     Conf *conf, const char *peer_verstring, ConnectionLayer **cl_out);
 
 /* Can't put this in the userauth constructor without having a
@@ -134,15 +134,22 @@ void ssh_ppl_user_output_string_and_free(PacketProtocolLayer *ppl, char *text);
 ptrlen ssh2_transport_get_session_id(PacketProtocolLayer *ssh2_transport_ptr);
 void ssh2_transport_notify_auth_done(PacketProtocolLayer *ssh2_transport_ptr);
 
+/* Shared method between ssh2 layers (defined in ssh2transport.c) to
+ * handle the common packets between login and connection: DISCONNECT,
+ * DEBUG and IGNORE. Those messages are handled by the ssh2transport
+ * layer if we have one, but in bare ssh2-connection mode they have to
+ * be handled by ssh2connection. */
+bool ssh2_common_filter_queue(PacketProtocolLayer *ppl);
+
 /* Methods for ssh1login to pass protocol flags to ssh1connection */
 void ssh1_connection_set_protoflags(
     PacketProtocolLayer *ppl, int local, int remote);
 
 /* Shared get_specials method between the two ssh1 layers */
-int ssh1_common_get_specials(PacketProtocolLayer *, add_special_fn_t, void *);
+bool ssh1_common_get_specials(PacketProtocolLayer *, add_special_fn_t, void *);
 
 /* Other shared functions between ssh1 layers  */
-int ssh1_common_filter_queue(PacketProtocolLayer *ppl);
+bool ssh1_common_filter_queue(PacketProtocolLayer *ppl);
 void ssh1_compute_session_id(
     unsigned char *session_id, const unsigned char *cookie,
     struct RSAKey *hostkey, struct RSAKey *servkey);

+ 77 - 76
source/putty/sshpubk.c

@@ -23,7 +23,7 @@
 
 static int key_type_fp(FILE *fp);
 
-static int rsa_ssh1_load_main(FILE * fp, struct RSAKey *key, int pub_only,
+static int rsa_ssh1_load_main(FILE * fp, struct RSAKey *key, bool pub_only,
                               char **commentptr, const char *passphrase,
                               const char **error)
 {
@@ -148,7 +148,7 @@ int rsa_ssh1_loadkey(const Filename *filename, struct RSAKey *key,
     int ret = 0;
     const char *error = NULL;
 
-    fp = f_open(filename, "rb", FALSE);
+    fp = f_open(filename, "rb", false);
     if (!fp) {
 	error = "can't open file";
 	goto end;
@@ -162,7 +162,7 @@ int rsa_ssh1_loadkey(const Filename *filename, struct RSAKey *key,
 	/*
 	 * This routine will take care of calling fclose() for us.
 	 */
-	ret = rsa_ssh1_load_main(fp, key, FALSE, NULL, passphrase, &error);
+	ret = rsa_ssh1_load_main(fp, key, false, NULL, passphrase, &error);
 	fp = NULL;
 	goto end;
     }
@@ -184,14 +184,14 @@ int rsa_ssh1_loadkey(const Filename *filename, struct RSAKey *key,
  * See whether an RSA key is encrypted. Return its comment field as
  * well.
  */
-int rsa_ssh1_encrypted(const Filename *filename, char **comment)
+bool rsa_ssh1_encrypted(const Filename *filename, char **comment)
 {
     FILE *fp;
     char buf[64];
 
-    fp = f_open(filename, "rb", FALSE);
+    fp = f_open(filename, "rb", false);
     if (!fp)
-	return 0;		       /* doesn't even exist */
+	return false;                  /* doesn't even exist */
 
     /*
      * Read the first line of the file and see if it's a v1 private
@@ -202,10 +202,10 @@ int rsa_ssh1_encrypted(const Filename *filename, char **comment)
 	/*
 	 * This routine will take care of calling fclose() for us.
 	 */
-	return rsa_ssh1_load_main(fp, NULL, FALSE, comment, NULL, &dummy);
+	return rsa_ssh1_load_main(fp, NULL, false, comment, NULL, &dummy) == 1;
     }
     fclose(fp);
-    return 0;			       /* wasn't the right kind of file */
+    return false;                  /* wasn't the right kind of file */
 }
 
 /*
@@ -222,9 +222,9 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
     const char *error = NULL;
 
     /* Default return if we fail. */
-    ret = FALSE;
+    ret = 0;
 
-    fp = f_open(filename, "rb", FALSE);
+    fp = f_open(filename, "rb", false);
     if (!fp) {
 	error = "can't open file";
 	goto end;
@@ -236,10 +236,10 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
      */
     if (fgets(buf, sizeof(buf), fp) && !strcmp(buf, rsa_signature)) {
 	memset(&key, 0, sizeof(key));
-	if (rsa_ssh1_load_main(fp, &key, TRUE, commentptr, NULL, &error)) {
+	if (rsa_ssh1_load_main(fp, &key, true, commentptr, NULL, &error)) {
             rsa_ssh1_public_blob(bs, &key, RSA_SSH1_EXPONENT_FIRST);
 	    freersakey(&key);
-	    ret = TRUE;
+	    ret = 1;
 	}
 	fp = NULL; /* rsa_ssh1_load_main unconditionally closes fp */
     } else {
@@ -291,7 +291,7 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
         freersakey(&key);
         sfree(line);
         fclose(fp);
-        return TRUE;
+        return 1;
 
       not_public_either:
         sfree(line);
@@ -307,10 +307,10 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
 }
 
 /*
- * Save an RSA key file. Return nonzero on success.
+ * Save an RSA key file. Return true on success.
  */
-int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
-                     char *passphrase)
+bool rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
+                      char *passphrase)
 {
     strbuf *buf = strbuf_new();
     int estart;
@@ -375,14 +375,14 @@ int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
     /*
      * Done. Write the result to the file.
      */
-    fp = f_open(filename, "wb", TRUE);
+    fp = f_open(filename, "wb", true);
     if (fp) {
-	int ret = (fwrite(buf->u, 1, buf->len, fp) == (size_t) (buf->len));
+	bool ret = (fwrite(buf->u, 1, buf->len, fp) == (size_t) (buf->len));
         if (fclose(fp))
-            ret = 0;
+            ret = false;
 	return ret;
     } else
-	return 0;
+	return false;
 }
 
 /* ----------------------------------------------------------------------
@@ -468,7 +468,7 @@ int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
  * an HMAC (this was generated for unencrypted keys).
  */
 
-static int read_header(FILE * fp, char *header)
+static bool read_header(FILE * fp, char *header)
 {
     int len = 39;
     int c;
@@ -476,20 +476,20 @@ static int read_header(FILE * fp, char *header)
     while (1) {
 	c = fgetc(fp);
 	if (c == '\n' || c == '\r' || c == EOF)
-	    return 0;		       /* failure */
+	    return false;              /* failure */
 	if (c == ':') {
 	    c = fgetc(fp);
 	    if (c != ' ')
-		return 0;
+		return false;
 	    *header = '\0';
-	    return 1;		       /* success! */
+	    return true;               /* success! */
 	}
 	if (len == 0)
-	    return 0;		       /* failure */
+	    return false;              /* failure */
 	*header++ = c;
 	len--;
     }
-    return 0;			       /* failure */
+    return false;                      /* failure */
 }
 
 static char *read_body(FILE * fp)
@@ -523,7 +523,7 @@ static char *read_body(FILE * fp)
     }
 }
 
-static int read_blob(FILE *fp, int nlines, BinarySink *bs)
+static bool read_blob(FILE *fp, int nlines, BinarySink *bs)
 {
     unsigned char *blob;
     char *line;
@@ -536,13 +536,13 @@ static int read_blob(FILE *fp, int nlines, BinarySink *bs)
 	line = read_body(fp);
 	if (!line) {
 	    sfree(blob);
-	    return FALSE;
+	    return false;
 	}
 	linelen = strlen(line);
 	if (linelen % 4 != 0 || linelen > 64) {
 	    sfree(blob);
 	    sfree(line);
-	    return FALSE;
+	    return false;
 	}
 	for (j = 0; j < linelen; j += 4) {
             unsigned char decoded[3];
@@ -550,13 +550,13 @@ static int read_blob(FILE *fp, int nlines, BinarySink *bs)
 	    if (!k) {
 		sfree(line);
 		sfree(blob);
-		return FALSE;
+		return false;
 	    }
 	    put_data(bs, decoded, k);
 	}
 	sfree(line);
     }
-    return TRUE;
+    return true;
 }
 
 /*
@@ -597,7 +597,8 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
     struct ssh2_userkey *ret;
     int cipher, cipherblk;
     strbuf *public_blob, *private_blob;
-    int i, is_mac, old_fmt;
+    int i;
+    bool is_mac, old_fmt;
     int passlen = passphrase ? strlen(passphrase) : 0;
     const char *error = NULL;
 
@@ -605,7 +606,7 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
     encryption = comment = mac = NULL;
     public_blob = private_blob = NULL;
 
-    fp = f_open(filename, "rb", FALSE);
+    fp = f_open(filename, "rb", false);
     if (!fp) {
 	error = "can't open file";
 	goto error;
@@ -617,11 +618,11 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
 	goto error;
     }
     if (0 == strcmp(header, "PuTTY-User-Key-File-2")) {
-	old_fmt = 0;
+	old_fmt = false;
     } else if (0 == strcmp(header, "PuTTY-User-Key-File-1")) {
 	/* this is an old key file; warn and then continue */
 	old_keyfile_warning();
-	old_fmt = 1;
+	old_fmt = true;
     } else if (0 == strncmp(header, "PuTTY-User-Key-File-", 20)) {
 	/* this is a key file FROM THE FUTURE; refuse it, but with a
          * more specific error message than the generic one below */
@@ -691,11 +692,11 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
     if (0 == strcmp(header, "Private-MAC")) {
 	if ((mac = read_body(fp)) == NULL)
 	    goto error;
-	is_mac = 1;
+	is_mac = true;
     } else if (0 == strcmp(header, "Private-Hash") && old_fmt) {
 	if ((mac = read_body(fp)) == NULL)
 	    goto error;
-	is_mac = 0;
+	is_mac = false;
     } else
 	goto error;
 
@@ -732,12 +733,12 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
 	char realmac[41];
 	unsigned char binary[20];
 	strbuf *macdata;
-        int free_macdata;
+        bool free_macdata;
 
 	if (old_fmt) {
 	    /* MAC (or hash) only covers the private blob. */
 	    macdata = private_blob;
-	    free_macdata = FALSE;
+	    free_macdata = false;
 	} else {
             macdata = strbuf_new();
 	    put_stringz(macdata, alg->ssh_id);
@@ -747,7 +748,7 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
                        public_blob->len);
 	    put_string(macdata, private_blob->s,
                        private_blob->len);
-	    free_macdata = TRUE;
+	    free_macdata = true;
 	}
 
 	if (is_mac) {
@@ -834,9 +835,9 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
     return ret;
 }
 
-int rfc4716_loadpub(FILE *fp, char **algorithm,
-                    BinarySink *bs,
-                    char **commentptr, const char **errorstr)
+bool rfc4716_loadpub(FILE *fp, char **algorithm,
+                     BinarySink *bs,
+                     char **commentptr, const char **errorstr)
 {
     const char *error;
     char *line, *colon, *value;
@@ -957,7 +958,7 @@ int rfc4716_loadpub(FILE *fp, char **algorithm,
         sfree(comment);
     put_data(bs, pubblob, pubbloblen);
     sfree(pubblob);
-    return TRUE;
+    return true;
 
   error:
     sfree(line);
@@ -965,12 +966,12 @@ int rfc4716_loadpub(FILE *fp, char **algorithm,
     sfree(pubblob);
     if (errorstr)
         *errorstr = error;
-    return FALSE;
+    return false;
 }
 
-int openssh_loadpub(FILE *fp, char **algorithm,
-                    BinarySink *bs,
-                    char **commentptr, const char **errorstr)
+bool openssh_loadpub(FILE *fp, char **algorithm,
+                     BinarySink *bs,
+                     char **commentptr, const char **errorstr)
 {
     const char *error;
     char *line, *base64;
@@ -1033,7 +1034,7 @@ int openssh_loadpub(FILE *fp, char **algorithm,
     sfree(line);
     put_data(bs, pubblob, pubbloblen);
     sfree(pubblob);
-    return TRUE;
+    return true;
 
   error:
     sfree(line);
@@ -1041,12 +1042,12 @@ int openssh_loadpub(FILE *fp, char **algorithm,
     sfree(pubblob);
     if (errorstr)
         *errorstr = error;
-    return FALSE;
+    return false;
 }
 
-int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
-                         BinarySink *bs,
-                         char **commentptr, const char **errorstr)
+bool ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
+                          BinarySink *bs,
+                          char **commentptr, const char **errorstr)
 {
     FILE *fp;
     char header[40], *b;
@@ -1055,7 +1056,7 @@ int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
     const char *error = NULL;
     char *comment = NULL;
 
-    fp = f_open(filename, "rb", FALSE);
+    fp = f_open(filename, "rb", false);
     if (!fp) {
 	error = "can't open file";
 	goto error;
@@ -1065,11 +1066,11 @@ int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
      * we'll be asked to read a public blob from one of those. */
     type = key_type_fp(fp);
     if (type == SSH_KEYTYPE_SSH2_PUBLIC_RFC4716) {
-        int ret = rfc4716_loadpub(fp, algorithm, bs, commentptr, errorstr);
+        bool ret = rfc4716_loadpub(fp, algorithm, bs, commentptr, errorstr);
         fclose(fp);
         return ret;
     } else if (type == SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH) {
-        int ret = openssh_loadpub(fp, algorithm, bs, commentptr, errorstr);
+        bool ret = openssh_loadpub(fp, algorithm, bs, commentptr, errorstr);
         fclose(fp);
         return ret;
     } else if (type != SSH_KEYTYPE_SSH2) {
@@ -1128,7 +1129,7 @@ int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
     fclose(fp);
     if (algorithm)
 	*algorithm = dupstr(alg->ssh_id);
-    return TRUE;
+    return true;
 
     /*
      * Error processing.
@@ -1142,52 +1143,52 @@ int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
         sfree(comment);
         *commentptr = NULL;
     }
-    return FALSE;
+    return false;
 }
 
-int ssh2_userkey_encrypted(const Filename *filename, char **commentptr)
+bool ssh2_userkey_encrypted(const Filename *filename, char **commentptr)
 {
     FILE *fp;
     char header[40], *b, *comment;
-    int ret;
+    bool ret;
 
     if (commentptr)
 	*commentptr = NULL;
 
-    fp = f_open(filename, "rb", FALSE);
+    fp = f_open(filename, "rb", false);
     if (!fp)
-	return 0;
+	return false;
     if (!read_header(fp, header)
 	|| (0 != strcmp(header, "PuTTY-User-Key-File-2") &&
 	    0 != strcmp(header, "PuTTY-User-Key-File-1"))) {
 	fclose(fp);
-	return 0;
+	return false;
     }
     if ((b = read_body(fp)) == NULL) {
 	fclose(fp);
-	return 0;
+	return false;
     }
     sfree(b);			       /* we don't care about key type here */
     /* Read the Encryption header line. */
     if (!read_header(fp, header) || 0 != strcmp(header, "Encryption")) {
 	fclose(fp);
-	return 0;
+	return false;
     }
     if ((b = read_body(fp)) == NULL) {
 	fclose(fp);
-	return 0;
+	return false;
     }
 
     /* Read the Comment header line. */
     if (!read_header(fp, header) || 0 != strcmp(header, "Comment")) {
 	fclose(fp);
 	sfree(b);
-	return 1;
+	return true;
     }
     if ((comment = read_body(fp)) == NULL) {
 	fclose(fp);
 	sfree(b);
-	return 1;
+	return true;
     }
 
     if (commentptr)
@@ -1197,9 +1198,9 @@ int ssh2_userkey_encrypted(const Filename *filename, char **commentptr)
 
     fclose(fp);
     if (!strcmp(b, "aes256-cbc"))
-	ret = 1;
+	ret = true;
     else
-	ret = 0;
+	ret = false;
     sfree(b);
     return ret;
 }
@@ -1233,8 +1234,8 @@ void base64_encode(FILE *fp, const unsigned char *data, int datalen, int cpl)
     fputc('\n', fp);
 }
 
-int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
-		      char *passphrase)
+bool ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
+                       char *passphrase)
 {
     FILE *fp;
     strbuf *pub_blob, *priv_blob;
@@ -1323,13 +1324,13 @@ int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
 	smemclr(&s, sizeof(s));
     }
 
-    fp = f_open(filename, "w", TRUE);
+    fp = f_open(filename, "w", true);
     if (!fp) {
         strbuf_free(pub_blob);
         strbuf_free(priv_blob);
         smemclr(priv_blob_encrypted, priv_encrypted_len);
         sfree(priv_blob_encrypted);
-        return 0;
+        return false;
     }
     fprintf(fp, "PuTTY-User-Key-File-2: %s\n", ssh_key_ssh_id(key->key));
     fprintf(fp, "Encryption: %s\n", cipherstr);
@@ -1348,7 +1349,7 @@ int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
     strbuf_free(priv_blob);
     smemclr(priv_blob_encrypted, priv_encrypted_len);
     sfree(priv_blob_encrypted);
-    return 1;
+    return true;
 }
 
 /* ----------------------------------------------------------------------
@@ -1586,7 +1587,7 @@ int key_type(const Filename *filename)
     FILE *fp;
     int ret;
 
-    fp = f_open(filename, "r", FALSE);
+    fp = f_open(filename, "r", false);
     if (!fp)
 	return SSH_KEYTYPE_UNOPENABLE;
     ret = key_type_fp(fp);

+ 18 - 21
source/putty/sshrand.c

@@ -9,9 +9,6 @@
 /* Collect environmental noise every 5 minutes */
 #define NOISE_REGULAR_INTERVAL (5*60*TICKSPERSEC)
 
-void noise_get_heavy(void (*func) (void *, int));
-void noise_get_light(void (*func) (void *, int));
-
 /*
  * `pool' itself is a pool of random data which we actually use: we
  * return bytes from `pool', at position `poolpos', until `poolpos'
@@ -42,7 +39,7 @@ struct RandPool {
     unsigned char incomingb[HASHINPUT];
     int incomingpos;
 
-    int stir_pending;
+    bool stir_pending;
 };
 
 int random_active = 0;
@@ -70,8 +67,8 @@ int random_diagnostics = 0;
 
 static void random_stir(void)
 {
-    word32 block[HASHINPUT / sizeof(word32)];
-    word32 digest[HASHSIZE / sizeof(word32)];
+    uint32_t block[HASHINPUT / sizeof(uint32_t)];
+    uint32_t digest[HASHSIZE / sizeof(uint32_t)];
     int i, j, k;
 
     /*
@@ -80,7 +77,7 @@ static void random_stir(void)
      */
     if (pool.stir_pending)
 	return;
-    pool.stir_pending = TRUE;
+    pool.stir_pending = true;
 
     noise_get_light(random_add_noise);
 
@@ -91,24 +88,24 @@ static void random_stir(void)
         for (p = 0; p < POOLSIZE; p += HASHSIZE) {
             printf("   ");
             for (q = 0; q < HASHSIZE; q += 4) {
-                printf(" %08x", *(word32 *)(pool.pool + p + q));            
+                printf(" %08x", *(uint32_t *)(pool.pool + p + q));            
             }
             printf("\n");
         }
         printf("incoming:\n   ");
         for (q = 0; q < HASHSIZE; q += 4) {
-            printf(" %08x", *(word32 *)(pool.incoming + q));
+            printf(" %08x", *(uint32_t *)(pool.incoming + q));
         }
         printf("\nincomingb:\n   ");
         for (q = 0; q < HASHINPUT; q += 4) {
-            printf(" %08x", *(word32 *)(pool.incomingb + q));
+            printf(" %08x", *(uint32_t *)(pool.incomingb + q));
         }
         printf("\n");
         random_diagnostics++;
     }
 #endif
 
-    SHATransform((word32 *) pool.incoming, (word32 *) pool.incomingb);
+    SHATransform((uint32_t *) pool.incoming, (uint32_t *) pool.incomingb);
     pool.incomingpos = 0;
 
     /*
@@ -144,7 +141,7 @@ static void random_stir(void)
 	     */
 
 	    for (k = 0; k < sizeof(digest) / sizeof(*digest); k++)
-		digest[k] ^= ((word32 *) (pool.pool + j))[k];
+		digest[k] ^= ((uint32_t *) (pool.pool + j))[k];
 
 	    /*
 	     * Munge our unrevealed first block of the pool into
@@ -157,7 +154,7 @@ static void random_stir(void)
 	     */
 
 	    for (k = 0; k < sizeof(digest) / sizeof(*digest); k++)
-		((word32 *) (pool.pool + j))[k] = digest[k];
+		((uint32_t *) (pool.pool + j))[k] = digest[k];
 	}
 
 #ifdef RANDOM_DIAGNOSTICS
@@ -167,17 +164,17 @@ static void random_stir(void)
             for (p = 0; p < POOLSIZE; p += HASHSIZE) {
                 printf("   ");
                 for (q = 0; q < HASHSIZE; q += 4) {
-                    printf(" %08x", *(word32 *)(pool.pool + p + q));            
+                    printf(" %08x", *(uint32_t *)(pool.pool + p + q));
                 }
                 printf("\n");
             }
             printf("incoming:\n   ");
             for (q = 0; q < HASHSIZE; q += 4) {
-                printf(" %08x", *(word32 *)(pool.incoming + q));
+                printf(" %08x", *(uint32_t *)(pool.incoming + q));
             }
             printf("\nincomingb:\n   ");
             for (q = 0; q < HASHINPUT; q += 4) {
-                printf(" %08x", *(word32 *)(pool.incomingb + q));
+                printf(" %08x", *(uint32_t *)(pool.incomingb + q));
             }
             printf("\n");
         }
@@ -193,7 +190,7 @@ static void random_stir(void)
 
     pool.poolpos = sizeof(pool.incoming);
 
-    pool.stir_pending = FALSE;
+    pool.stir_pending = false;
 
 #ifdef RANDOM_DIAGNOSTICS
     {
@@ -202,17 +199,17 @@ static void random_stir(void)
         for (p = 0; p < POOLSIZE; p += HASHSIZE) {
             printf("   ");
             for (q = 0; q < HASHSIZE; q += 4) {
-                printf(" %08x", *(word32 *)(pool.pool + p + q));            
+                printf(" %08x", *(uint32_t *)(pool.pool + p + q));            
             }
             printf("\n");
         }
         printf("incoming:\n   ");
         for (q = 0; q < HASHSIZE; q += 4) {
-            printf(" %08x", *(word32 *)(pool.incoming + q));
+            printf(" %08x", *(uint32_t *)(pool.incoming + q));
         }
         printf("\nincomingb:\n   ");
         for (q = 0; q < HASHINPUT; q += 4) {
-            printf(" %08x", *(word32 *)(pool.incomingb + q));
+            printf(" %08x", *(uint32_t *)(pool.incomingb + q));
         }
         printf("\n");
         random_diagnostics--;
@@ -238,7 +235,7 @@ void random_add_noise(void *noise, int length)
 	       HASHINPUT - pool.incomingpos);
 	p += HASHINPUT - pool.incomingpos;
 	length -= HASHINPUT - pool.incomingpos;
-	SHATransform((word32 *) pool.incoming, (word32 *) pool.incomingb);
+	SHATransform((uint32_t *) pool.incoming, (uint32_t *) pool.incomingb);
 	for (i = 0; i < HASHSIZE; i++) {
 	    pool.pool[pool.poolpos++] ^= pool.incoming[i];
 	    if (pool.poolpos >= POOLSIZE)

+ 81 - 38
source/putty/sshrsa.c

@@ -42,14 +42,14 @@ void BinarySource_get_rsa_ssh1_priv(
     rsa->private_exponent = get_mp_ssh1(src);
 }
 
-int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key)
+bool rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key)
 {
     Bignum b1, b2;
     int i;
     unsigned char *p;
 
     if (key->bytes < length + 4)
-	return 0;		       /* RSA key too short! */
+	return false;                  /* RSA key too short! */
 
     memmove(data + key->bytes - length, data, length);
     data[0] = 0;
@@ -74,7 +74,7 @@ int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key)
     freebn(b1);
     freebn(b2);
 
-    return 1;
+    return true;
 }
 
 /*
@@ -285,10 +285,10 @@ Bignum rsa_ssh1_decrypt(Bignum input, struct RSAKey *key)
     return rsa_privkey_op(input, key);
 }
 
-int rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf)
+bool rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf)
 {
     strbuf *data = strbuf_new();
-    int success = FALSE;
+    bool success = false;
     BinarySource src[1];
 
     {
@@ -313,7 +313,7 @@ int rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf)
     }
 
     /* Everything else is the payload */
-    success = TRUE;
+    success = true;
     put_data(outbuf, get_ptr(src), get_avail(src));
 
   out:
@@ -391,7 +391,7 @@ char *rsa_ssh1_fingerprint(struct RSAKey *key)
  * data. We also check the private data itself: we ensure that p >
  * q and that iqmp really is the inverse of q mod p.
  */
-int rsa_verify(struct RSAKey *key)
+bool rsa_verify(struct RSAKey *key)
 {
     Bignum n, ed, pm1, qm1;
     int cmp;
@@ -401,7 +401,7 @@ int rsa_verify(struct RSAKey *key)
     cmp = bignum_cmp(n, key->modulus);
     freebn(n);
     if (cmp != 0)
-	return 0;
+	return false;
 
     /* e * d must be congruent to 1, modulo (p-1) and modulo (q-1). */
     pm1 = copybn(key->p);
@@ -411,7 +411,7 @@ int rsa_verify(struct RSAKey *key)
     cmp = bignum_cmp(ed, One);
     freebn(ed);
     if (cmp != 0)
-	return 0;
+	return false;
 
     qm1 = copybn(key->q);
     decbn(qm1);
@@ -420,7 +420,7 @@ int rsa_verify(struct RSAKey *key)
     cmp = bignum_cmp(ed, One);
     freebn(ed);
     if (cmp != 0)
-	return 0;
+	return false;
 
     /*
      * Ensure p > q.
@@ -438,7 +438,7 @@ int rsa_verify(struct RSAKey *key)
 	freebn(key->iqmp);
 	key->iqmp = modinv(key->q, key->p);
         if (!key->iqmp)
-            return 0;
+            return false;
     }
 
     /*
@@ -448,9 +448,9 @@ int rsa_verify(struct RSAKey *key)
     cmp = bignum_cmp(n, One);
     freebn(n);
     if (cmp != 0)
-	return 0;
+	return false;
 
-    return 1;
+    return true;
 }
 
 void rsa_ssh1_public_blob(BinarySink *bs, struct RSAKey *key,
@@ -676,20 +676,37 @@ static int rsa2_pubkey_bits(const ssh_keyalg *self, ptrlen pub)
  *    iso(1) identified-organization(3) oiw(14) secsig(3)
  *    algorithms(2) 26 }
  */
-static const unsigned char asn1_weird_stuff[] = {
+static const unsigned char sha1_asn1_prefix[] = {
     0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B,
     0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14,
 };
 
-#define ASN1_LEN ( (int) sizeof(asn1_weird_stuff) )
+/*
+ * Two more similar pieces of ASN.1 used for signatures using SHA-256
+ * and SHA-512, in the same format but differing only in various
+ * length fields and OID.
+ */
+static const unsigned char sha256_asn1_prefix[] = {
+    0x00, 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60,
+    0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
+    0x05, 0x00, 0x04, 0x20,
+};
+static const unsigned char sha512_asn1_prefix[] = {
+    0x00, 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60,
+    0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
+    0x05, 0x00, 0x04, 0x40,
+};
+
+#define SHA1_ASN1_PREFIX_LEN sizeof(sha1_asn1_prefix)
 
-static int rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
+static bool rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
 {
     struct RSAKey *rsa = container_of(key, struct RSAKey, sshk);
     BinarySource src[1];
     ptrlen type, in_pl;
     Bignum in, out;
-    int bytes, i, j, ret;
+    int bytes, i, j;
+    bool toret;
     unsigned char hash[20];
 
     BinarySource_BARE_INIT(src, sig.ptr, sig.len);
@@ -706,64 +723,89 @@ static int 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 0;
+	return false;
 
     in = bignum_from_bytes(in_pl.ptr, in_pl.len);
     out = modpow(in, rsa->exponent, rsa->modulus);
     freebn(in);
 
-    ret = 1;
+    toret = true;
 
     bytes = (bignum_bitcount(rsa->modulus)+7) / 8;
     /* Top (partial) byte should be zero. */
     if (bignum_byte(out, bytes - 1) != 0)
-	ret = 0;
+	toret = false;
     /* First whole byte should be 1. */
     if (bignum_byte(out, bytes - 2) != 1)
-	ret = 0;
+	toret = false;
     /* Most of the rest should be FF. */
-    for (i = bytes - 3; i >= 20 + ASN1_LEN; i--) {
+    for (i = bytes - 3; i >= 20 + SHA1_ASN1_PREFIX_LEN; i--) {
 	if (bignum_byte(out, i) != 0xFF)
-	    ret = 0;
+	    toret = false;
     }
-    /* Then we expect to see the asn1_weird_stuff. */
-    for (i = 20 + ASN1_LEN - 1, j = 0; i >= 20; i--, j++) {
-	if (bignum_byte(out, i) != asn1_weird_stuff[j])
-	    ret = 0;
+    /* Then we expect to see the sha1_asn1_prefix. */
+    for (i = 20 + SHA1_ASN1_PREFIX_LEN - 1, j = 0; i >= 20; i--, j++) {
+	if (bignum_byte(out, i) != sha1_asn1_prefix[j])
+	    toret = false;
     }
     /* Finally, we expect to see the SHA-1 hash of the signed data. */
     SHA_Simple(data.ptr, data.len, hash);
     for (i = 19, j = 0; i >= 0; i--, j++) {
 	if (bignum_byte(out, i) != hash[j])
-	    ret = 0;
+	    toret = false;
     }
     freebn(out);
 
-    return ret;
+    return toret;
 }
 
 static void rsa2_sign(ssh_key *key, const void *data, int datalen,
-                      BinarySink *bs)
+                      unsigned flags, BinarySink *bs)
 {
     struct RSAKey *rsa = container_of(key, struct RSAKey, sshk);
     unsigned char *bytes;
     int nbytes;
-    unsigned char hash[20];
+    unsigned char hash[64];
     Bignum in, out;
     int i, j;
+    const struct ssh_hashalg *halg;
+    ssh_hash *h;
+    const unsigned char *asn1_prefix;
+    unsigned asn1_prefix_size;
+    const char *sign_alg_name;
+
+    if (flags & SSH_AGENT_RSA_SHA2_256) {
+        halg = &ssh_sha256;
+        asn1_prefix = sha256_asn1_prefix;
+        asn1_prefix_size = sizeof(sha256_asn1_prefix);
+        sign_alg_name = "rsa-sha2-256";
+    } else if (flags & SSH_AGENT_RSA_SHA2_512) {
+        halg = &ssh_sha512;
+        asn1_prefix = sha512_asn1_prefix;
+        asn1_prefix_size = sizeof(sha512_asn1_prefix);
+        sign_alg_name = "rsa-sha2-512";
+    } else {
+        halg = &ssh_sha1;
+        asn1_prefix = sha1_asn1_prefix;
+        asn1_prefix_size = sizeof(sha1_asn1_prefix);
+        sign_alg_name = "ssh-rsa";
+    }
 
-    SHA_Simple(data, datalen, hash);
+    h = ssh_hash_new(halg);
+    put_data(h, data, datalen);
+    ssh_hash_final(h, hash);
 
     nbytes = (bignum_bitcount(rsa->modulus) - 1) / 8;
-    assert(1 <= nbytes - 20 - ASN1_LEN);
+    assert(1 <= nbytes - halg->hlen - asn1_prefix_size);
     bytes = snewn(nbytes, unsigned char);
 
     bytes[0] = 1;
-    for (i = 1; i < nbytes - 20 - ASN1_LEN; i++)
+    for (i = 1; i < nbytes - halg->hlen - asn1_prefix_size; i++)
 	bytes[i] = 0xFF;
-    for (i = nbytes - 20 - ASN1_LEN, j = 0; i < nbytes - 20; i++, j++)
-	bytes[i] = asn1_weird_stuff[j];
-    for (i = nbytes - 20, j = 0; i < nbytes; i++, j++)
+    for (i = nbytes - halg->hlen - asn1_prefix_size, j = 0;
+         i < nbytes - halg->hlen; i++, j++)
+	bytes[i] = asn1_prefix[j];
+    for (i = nbytes - halg->hlen, j = 0; i < nbytes; i++, j++)
 	bytes[i] = hash[j];
 
     in = bignum_from_bytes(bytes, nbytes);
@@ -772,7 +814,7 @@ static void rsa2_sign(ssh_key *key, const void *data, int datalen,
     out = rsa_privkey_op(in, rsa);
     freebn(in);
 
-    put_stringz(bs, "ssh-rsa");
+    put_stringz(bs, sign_alg_name);
     nbytes = (bignum_bitcount(out) + 7) / 8;
     put_uint32(bs, nbytes);
     for (i = 0; i < nbytes; i++)
@@ -799,6 +841,7 @@ const ssh_keyalg ssh_rsa = {
     "ssh-rsa",
     "rsa2",
     NULL,
+    SSH_AGENT_RSA_SHA2_256 | SSH_AGENT_RSA_SHA2_512,
 };
 
 struct RSAKey *ssh_rsakex_newkey(const void *data, int len)

+ 17 - 22
source/putty/sshsh256.c

@@ -11,8 +11,8 @@
  * Core SHA256 algorithm: processes 16-word blocks into a message digest.
  */
 
-#define ror(x,y) ( ((x) << (32-y)) | (((uint32)(x)) >> (y)) )
-#define shr(x,y) ( (((uint32)(x)) >> (y)) )
+#define ror(x,y) ( ((x) << (32-y)) | (((uint32_t)(x)) >> (y)) )
+#define shr(x,y) ( (((uint32_t)(x)) >> (y)) )
 #define Ch(x,y,z) ( ((x) & (y)) ^ (~(x) & (z)) )
 #define Maj(x,y,z) ( ((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)) )
 #define bigsigma0(x) ( ror((x),2) ^ ror((x),13) ^ ror((x),22) )
@@ -34,9 +34,9 @@ void SHA256_Core_Init(SHA256_State *s) {
     s->h[7] = 0x5be0cd19;
 }
 
-void SHA256_Block(SHA256_State *s, uint32 *block) {
-    uint32 w[80];
-    uint32 a,b,c,d,e,f,g,h;
+void SHA256_Block(SHA256_State *s, uint32_t *block) {
+    uint32_t w[80];
+    uint32_t a,b,c,d,e,f,g,h;
     static const int k[] = {
         0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
         0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
@@ -68,7 +68,7 @@ void SHA256_Block(SHA256_State *s, uint32 *block) {
     e = s->h[4]; f = s->h[5]; g = s->h[6]; h = s->h[7];
 
     for (t = 0; t < 64; t+=8) {
-        uint32 t1, t2;
+        uint32_t t1, t2;
 
 #define ROUND(j,a,b,c,d,e,f,g,h) \
 	t1 = h + bigsigma1(e) + Ch(e,f,g) + k[j] + w[j]; \
@@ -103,7 +103,7 @@ static void SHA256_BinarySink_write(BinarySink *bs,
 void SHA256_Init(SHA256_State *s) {
     SHA256_Core_Init(s);
     s->blkused = 0;
-    s->lenhi = s->lenlo = 0;
+    s->len = 0;
     if (supports_sha_ni())
         s->sha256 = &SHA256_ni;
     else
@@ -117,19 +117,16 @@ static void SHA256_BinarySink_write(BinarySink *bs,
     struct SHA256_State *s = BinarySink_DOWNCAST(bs, struct SHA256_State);
     unsigned char *q = (unsigned char *)p;
 
-    uint32 lenw = len;
-    assert(len == lenw);
-
     /*
      * Update the length field.
      */
-    s->lenlo += lenw;
-    s->lenhi += (s->lenlo < lenw);
+    s->len += len;
+
     (*(s->sha256))(s, q, len);
 }
 
 static void SHA256_sw(SHA256_State *s, const unsigned char *q, int len) {
-    uint32 wordblock[16];
+    uint32_t wordblock[16];
     int i;
 
     if (s->blkused && s->blkused+len < BLKSIZE) {
@@ -149,10 +146,10 @@ static void SHA256_sw(SHA256_State *s, const unsigned char *q, int len) {
             /* Now process the block. Gather bytes big-endian into words */
             for (i = 0; i < 16; i++) {
                 wordblock[i] =
-                    ( ((uint32)s->block[i*4+0]) << 24 ) |
-                    ( ((uint32)s->block[i*4+1]) << 16 ) |
-                    ( ((uint32)s->block[i*4+2]) <<  8 ) |
-                    ( ((uint32)s->block[i*4+3]) <<  0 );
+                    ( ((uint32_t)s->block[i*4+0]) << 24 ) |
+                    ( ((uint32_t)s->block[i*4+1]) << 16 ) |
+                    ( ((uint32_t)s->block[i*4+2]) <<  8 ) |
+                    ( ((uint32_t)s->block[i*4+3]) <<  0 );
             }
             SHA256_Block(s, wordblock);
             s->blkused = 0;
@@ -166,22 +163,20 @@ void SHA256_Final(SHA256_State *s, unsigned char *digest) {
     int i;
     int pad;
     unsigned char c[64];
-    uint32 lenhi, lenlo;
+    uint64_t len;
 
     if (s->blkused >= 56)
         pad = 56 + 64 - s->blkused;
     else
         pad = 56 - s->blkused;
 
-    lenhi = (s->lenhi << 3) | (s->lenlo >> (32-3));
-    lenlo = (s->lenlo << 3);
+    len = (s->len << 3);
 
     memset(c, 0, pad);
     c[0] = 0x80;
     put_data(s, &c, pad);
 
-    put_uint32(s, lenhi);
-    put_uint32(s, lenlo);
+    put_uint64(s, len);
 
     for (i = 0; i < 8; i++) {
 	digest[i*4+0] = (s->h[i] >> 24) & 0xFF;

+ 35 - 71
source/putty/sshsh512.c

@@ -15,21 +15,17 @@
  * Arithmetic implementations. Note that AND, XOR and NOT can
  * overlap destination with one source, but the others can't.
  */
-#define add(r,x,y) ( r.lo = y.lo + x.lo, \
-		     r.hi = y.hi + x.hi + ((uint32)r.lo < (uint32)y.lo) )
-#define rorB(r,x,y) ( r.lo = ((uint32)x.hi >> ((y)-32)) | ((uint32)x.lo << (64-(y))), \
-		      r.hi = ((uint32)x.lo >> ((y)-32)) | ((uint32)x.hi << (64-(y))) )
-#define rorL(r,x,y) ( r.lo = ((uint32)x.lo >> (y)) | ((uint32)x.hi << (32-(y))), \
-		      r.hi = ((uint32)x.hi >> (y)) | ((uint32)x.lo << (32-(y))) )
-#define shrB(r,x,y) ( r.lo = (uint32)x.hi >> ((y)-32), r.hi = 0 )
-#define shrL(r,x,y) ( r.lo = ((uint32)x.lo >> (y)) | ((uint32)x.hi << (32-(y))), \
-		      r.hi = (uint32)x.hi >> (y) )
-#define and(r,x,y) ( r.lo = x.lo & y.lo, r.hi = x.hi & y.hi )
-#define xor(r,x,y) ( r.lo = x.lo ^ y.lo, r.hi = x.hi ^ y.hi )
-#define not(r,x) ( r.lo = ~x.lo, r.hi = ~x.hi )
-#define INIT(h,l) { h, l }
-#define BUILD(r,h,l) ( r.hi = h, r.lo = l )
-#define EXTRACT(h,l,r) ( h = r.hi, l = r.lo )
+#define add(r,x,y) ( r = (x) + (y) )
+#define rorB(r,x,y) ( r = ((x) >> (y)) | ((x) << (64-(y))) )
+#define rorL(r,x,y) ( r = ((x) >> (y)) | ((x) << (64-(y))) )
+#define shrB(r,x,y) ( r = (x) >> (y) )
+#define shrL(r,x,y) ( r = (x) >> (y) )
+#define and(r,x,y) ( r = (x) & (y) )
+#define xor(r,x,y) ( r = (x) ^ (y) )
+#define not(r,x) ( r = ~(x) )
+#define INIT(h,l) ((((uint64_t)(h)) << 32) | (l))
+#define BUILD(r,h,l) ( r = ((((uint64_t)(h)) << 32) | (l)) )
+#define EXTRACT(h,l,r) ( h = (r) >> 32, l = (r) & 0xFFFFFFFFU )
 
 /* ----------------------------------------------------------------------
  * Core SHA512 algorithm: processes 16-doubleword blocks into a
@@ -49,7 +45,7 @@
 			     shrL(t,x,6), xor(r,r,t) )
 
 static void SHA512_Core_Init(SHA512_State *s) {
-    static const uint64 iv[] = {
+    static const uint64_t iv[] = {
 	INIT(0x6a09e667, 0xf3bcc908),
 	INIT(0xbb67ae85, 0x84caa73b),
 	INIT(0x3c6ef372, 0xfe94f82b),
@@ -65,7 +61,7 @@ static void SHA512_Core_Init(SHA512_State *s) {
 }
 
 static void SHA384_Core_Init(SHA512_State *s) {
-    static const uint64 iv[] = {
+    static const uint64_t iv[] = {
         INIT(0xcbbb9d5d, 0xc1059ed8),
         INIT(0x629a292a, 0x367cd507),
         INIT(0x9159015a, 0x3070dd17),
@@ -80,10 +76,10 @@ static void SHA384_Core_Init(SHA512_State *s) {
         s->h[i] = iv[i];
 }
 
-static void SHA512_Block(SHA512_State *s, uint64 *block) {
-    uint64 w[80];
-    uint64 a,b,c,d,e,f,g,h;
-    static const uint64 k[] = {
+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),
@@ -132,7 +128,7 @@ static void SHA512_Block(SHA512_State *s, uint64 *block) {
         w[t] = block[t];
 
     for (t = 16; t < 80; t++) {
-	uint64 p, q, r, tmp;
+	uint64_t p, q, r, tmp;
 	smallsigma1(p, tmp, w[t-2]);
 	smallsigma0(q, tmp, w[t-15]);
 	add(r, p, q);
@@ -144,7 +140,7 @@ static void SHA512_Block(SHA512_State *s, uint64 *block) {
     e = s->h[4]; f = s->h[5]; g = s->h[6]; h = s->h[7];
 
     for (t = 0; t < 80; t+=8) {
-        uint64 tmp, p, q, r;
+        uint64_t tmp, p, q, r;
 
 #define ROUND(j,a,b,c,d,e,f,g,h) \
 	bigsigma1(p, tmp, e); \
@@ -171,7 +167,7 @@ static void SHA512_Block(SHA512_State *s, uint64 *block) {
     }
 
     {
-	uint64 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);
@@ -190,20 +186,16 @@ static void SHA512_BinarySink_write(BinarySink *bs,
                                     const void *p, size_t len);
 
 void SHA512_Init(SHA512_State *s) {
-    int i;
     SHA512_Core_Init(s);
     s->blkused = 0;
-    for (i = 0; i < 4; i++)
-	s->len[i] = 0;
+    s->lenhi = s->lenlo = 0;
     BinarySink_INIT(s, SHA512_BinarySink_write);
 }
 
 void SHA384_Init(SHA512_State *s) {
-    int i;
     SHA384_Core_Init(s);
     s->blkused = 0;
-    for (i = 0; i < 4; i++)
-        s->len[i] = 0;
+    s->lenhi = s->lenlo = 0;
     BinarySink_INIT(s, SHA512_BinarySink_write);
 }
 
@@ -212,19 +204,14 @@ static void SHA512_BinarySink_write(BinarySink *bs,
 {
     SHA512_State *s = BinarySink_DOWNCAST(bs, SHA512_State);
     unsigned char *q = (unsigned char *)p;
-    uint64 wordblock[16];
-    uint32 lenw = len;
+    uint64_t wordblock[16];
     int i;
 
-    assert(lenw == len);
-
     /*
      * Update the length field.
      */
-    for (i = 0; i < 4; i++) {
-	s->len[i] += lenw;
-	lenw = (s->len[i] < lenw);
-    }
+    s->lenlo += len;
+    s->lenhi += (s->lenlo < len);
 
     if (s->blkused && s->blkused+len < BLKSIZE) {
         /*
@@ -241,18 +228,8 @@ static void SHA512_BinarySink_write(BinarySink *bs,
             q += BLKSIZE - s->blkused;
             len -= BLKSIZE - s->blkused;
             /* Now process the block. Gather bytes big-endian into words */
-            for (i = 0; i < 16; i++) {
-		uint32 h, l;
-                h = ( ((uint32)s->block[i*8+0]) << 24 ) |
-                    ( ((uint32)s->block[i*8+1]) << 16 ) |
-                    ( ((uint32)s->block[i*8+2]) <<  8 ) |
-                    ( ((uint32)s->block[i*8+3]) <<  0 );
-                l = ( ((uint32)s->block[i*8+4]) << 24 ) |
-                    ( ((uint32)s->block[i*8+5]) << 16 ) |
-                    ( ((uint32)s->block[i*8+6]) <<  8 ) |
-                    ( ((uint32)s->block[i*8+7]) <<  0 );
-		BUILD(wordblock[i], h, l);
-            }
+            for (i = 0; i < 16; i++)
+                wordblock[i] = GET_64BIT_MSB_FIRST(s->block + i*8);
             SHA512_Block(s, wordblock);
             s->blkused = 0;
         }
@@ -265,38 +242,25 @@ void SHA512_Final(SHA512_State *s, unsigned char *digest) {
     int i;
     int pad;
     unsigned char c[BLKSIZE];
-    uint32 len[4];
+    uint64_t lenhi, lenlo;
 
     if (s->blkused >= BLKSIZE-16)
         pad = (BLKSIZE-16) + BLKSIZE - s->blkused;
     else
         pad = (BLKSIZE-16) - s->blkused;
 
-    for (i = 4; i-- ;) {
-	uint32 lenhi = s->len[i];
-	uint32 lenlo = i > 0 ? s->len[i-1] : 0;
-	len[i] = (lenhi << 3) | (lenlo >> (32-3));
-    }
+    lenhi = (s->lenhi << 3) | (s->lenlo >> (32-3));
+    lenlo = (s->lenlo << 3);
 
     memset(c, 0, pad);
     c[0] = 0x80;
     put_data(s, &c, pad);
 
-    for (i = 0; i < 4; i++)
-        put_uint32(s, len[3-i]);
-
-    for (i = 0; i < 8; i++) {
-	uint32 h, l;
-	EXTRACT(h, l, s->h[i]);
-	digest[i*8+0] = (h >> 24) & 0xFF;
-	digest[i*8+1] = (h >> 16) & 0xFF;
-	digest[i*8+2] = (h >>  8) & 0xFF;
-	digest[i*8+3] = (h >>  0) & 0xFF;
-	digest[i*8+4] = (l >> 24) & 0xFF;
-	digest[i*8+5] = (l >> 16) & 0xFF;
-	digest[i*8+6] = (l >>  8) & 0xFF;
-	digest[i*8+7] = (l >>  0) & 0xFF;
-    }
+    put_uint64(s, lenhi);
+    put_uint64(s, lenlo);
+
+    for (i = 0; i < 8; i++)
+        PUT_64BIT_MSB_FIRST(digest + i*8, s->h[i]);
 }
 
 void SHA384_Final(SHA512_State *s, unsigned char *digest) {

+ 27 - 31
source/putty/sshsha.c

@@ -13,12 +13,12 @@
  * Core SHA algorithm: processes 16-word blocks into a message digest.
  */
 
-#define rol(x,y) ( ((x) << (y)) | (((uint32)x) >> (32-y)) )
+#define rol(x,y) ( ((x) << (y)) | (((uint32_t)x) >> (32-y)) )
 
 static void sha1_sw(SHA_State * s, const unsigned char *q, int len);
 static void sha1_ni(SHA_State * s, const unsigned char *q, int len);
 
-static void SHA_Core_Init(uint32 h[5])
+static void SHA_Core_Init(uint32_t h[5])
 {
     h[0] = 0x67452301;
     h[1] = 0xefcdab89;
@@ -27,10 +27,10 @@ static void SHA_Core_Init(uint32 h[5])
     h[4] = 0xc3d2e1f0;
 }
 
-void SHATransform(word32 * digest, word32 * block)
+void SHATransform(uint32_t * digest, uint32_t * block)
 {
-    word32 w[80];
-    word32 a, b, c, d, e;
+    uint32_t w[80];
+    uint32_t a, b, c, d, e;
     int t;
 
 #ifdef RANDOM_DIAGNOSTICS
@@ -52,7 +52,7 @@ void SHATransform(word32 * digest, word32 * block)
 	w[t] = block[t];
 
     for (t = 16; t < 80; t++) {
-	word32 tmp = w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16];
+	uint32_t tmp = w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16];
 	w[t] = rol(tmp, 1);
     }
 
@@ -63,7 +63,7 @@ void SHATransform(word32 * digest, word32 * block)
     e = digest[4];
 
     for (t = 0; t < 20; t++) {
-	word32 tmp =
+	uint32_t tmp =
 	    rol(a, 5) + ((b & c) | (d & ~b)) + e + w[t] + 0x5a827999;
 	e = d;
 	d = c;
@@ -72,7 +72,7 @@ void SHATransform(word32 * digest, word32 * block)
 	a = tmp;
     }
     for (t = 20; t < 40; t++) {
-	word32 tmp = rol(a, 5) + (b ^ c ^ d) + e + w[t] + 0x6ed9eba1;
+	uint32_t tmp = rol(a, 5) + (b ^ c ^ d) + e + w[t] + 0x6ed9eba1;
 	e = d;
 	d = c;
 	c = rol(b, 30);
@@ -80,7 +80,7 @@ void SHATransform(word32 * digest, word32 * block)
 	a = tmp;
     }
     for (t = 40; t < 60; t++) {
-	word32 tmp = rol(a,
+	uint32_t tmp = rol(a,
 			 5) + ((b & c) | (b & d) | (c & d)) + e + w[t] +
 	    0x8f1bbcdc;
 	e = d;
@@ -90,7 +90,7 @@ void SHATransform(word32 * digest, word32 * block)
 	a = tmp;
     }
     for (t = 60; t < 80; t++) {
-	word32 tmp = rol(a, 5) + (b ^ c ^ d) + e + w[t] + 0xca62c1d6;
+	uint32_t tmp = rol(a, 5) + (b ^ c ^ d) + e + w[t] + 0xca62c1d6;
 	e = d;
 	d = c;
 	c = rol(b, 30);
@@ -130,7 +130,7 @@ void SHA_Init(SHA_State * s)
 {
     SHA_Core_Init(s->h);
     s->blkused = 0;
-    s->lenhi = s->lenlo = 0;
+    s->len = 0;
     if (supports_sha_ni())
         s->sha1 = &sha1_ni;
     else
@@ -142,20 +142,18 @@ static void SHA_BinarySink_write(BinarySink *bs, const void *p, size_t len)
 {
     struct SHA_State *s = BinarySink_DOWNCAST(bs, struct SHA_State);
     const unsigned char *q = (const unsigned char *) p;
-    uint32 lenw = len;
-    assert(lenw == len);
 
     /*
      * Update the length field.
      */
-    s->lenlo += lenw;
-    s->lenhi += (s->lenlo < lenw);
+    s->len += len;
+
     (*(s->sha1))(s, q, len);
 }
 
 static void sha1_sw(SHA_State * s, const unsigned char *q, int len)
 {
-    uint32 wordblock[16];
+    uint32_t wordblock[16];
     int i;
 
     if (s->blkused && s->blkused + len < 64) {
@@ -175,10 +173,10 @@ static void sha1_sw(SHA_State * s, const unsigned char *q, int len)
 	    /* Now process the block. Gather bytes big-endian into words */
 	    for (i = 0; i < 16; i++) {
 		wordblock[i] =
-		    (((uint32) s->block[i * 4 + 0]) << 24) |
-		    (((uint32) s->block[i * 4 + 1]) << 16) |
-		    (((uint32) s->block[i * 4 + 2]) << 8) |
-		    (((uint32) s->block[i * 4 + 3]) << 0);
+		    (((uint32_t) s->block[i * 4 + 0]) << 24) |
+		    (((uint32_t) s->block[i * 4 + 1]) << 16) |
+		    (((uint32_t) s->block[i * 4 + 2]) << 8) |
+		    (((uint32_t) s->block[i * 4 + 3]) << 0);
 	    }
 	    SHATransform(s->h, wordblock);
 	    s->blkused = 0;
@@ -193,22 +191,20 @@ void SHA_Final(SHA_State * s, unsigned char *output)
     int i;
     int pad;
     unsigned char c[64];
-    uint32 lenhi, lenlo;
+    uint64_t len;
 
     if (s->blkused >= 56)
 	pad = 56 + 64 - s->blkused;
     else
 	pad = 56 - s->blkused;
 
-    lenhi = (s->lenhi << 3) | (s->lenlo >> (32 - 3));
-    lenlo = (s->lenlo << 3);
+    len = (s->len << 3);
 
     memset(c, 0, pad);
     c[0] = 0x80;
     put_data(s, &c, pad);
 
-    put_uint32(s, lenhi);
-    put_uint32(s, lenlo);
+    put_uint64(s, len);
 
     for (i = 0; i < 5; i++) {
 	output[i * 4] = (s->h[i] >> 24) & 0xFF;
@@ -440,12 +436,12 @@ const struct ssh2_macalg ssh_hmac_sha1_96_buggy = {
 #if defined(__clang__) || defined(__GNUC__)
 
 #include <cpuid.h>
-int supports_sha_ni(void)
+bool supports_sha_ni(void)
 {
     unsigned int CPUInfo[4];
     __cpuid(0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
     if (CPUInfo[0] < 7)
-        return 0;
+        return false;
 
     __cpuid_count(7, 0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
     return CPUInfo[1] & (1 << 29); /* SHA */
@@ -453,12 +449,12 @@ int supports_sha_ni(void)
 
 #else /* defined(__clang__) || defined(__GNUC__) */
 
-int supports_sha_ni(void)
+bool supports_sha_ni(void)
 {
     unsigned int CPUInfo[4];
     __cpuid(CPUInfo, 0);  
     if (CPUInfo[0] < 7)
-        return 0;
+        return false;
 
     __cpuidex(CPUInfo, 7, 0);
     return CPUInfo[1] & (1 << 29); /* Check SHA */
@@ -690,9 +686,9 @@ static void sha1_ni(SHA_State * s, const unsigned char *q, int len)
     assert(0);
 }
 
-int supports_sha_ni(void)
+bool supports_sha_ni(void)
 {
-    return 0;
+    return false;
 }
 
 #endif  /* COMPILER_SUPPORTS_AES_NI */

+ 33 - 35
source/putty/sshshare.c

@@ -160,7 +160,8 @@ struct ssh_sharing_connstate {
 
     int crLine;                        /* coroutine state for share_receive */
 
-    int sent_verstring, got_verstring, curr_packetlen;
+    bool sent_verstring, got_verstring;
+    int curr_packetlen;
 
     unsigned char recvbuf[0x4010];
     int recvlen;
@@ -235,13 +236,13 @@ struct share_channel {
     int x11_auth_proto;
     char *x11_auth_data;
     int x11_auth_datalen;
-    int x11_one_shot;
+    bool x11_one_shot;
 };
 
 struct share_forwarding {
     char *host;
     int port;
-    int active;             /* has the server sent REQUEST_SUCCESS? */
+    bool active;            /* has the server sent REQUEST_SUCCESS? */
     struct ssh_rportfwd *rpf;
 };
 
@@ -263,7 +264,7 @@ struct share_xchannel {
      * channel messages from the server until such time as the server
      * sends us CHANNEL_CLOSE.
      */
-    int live;
+    bool live;
 
     /*
      * When we receive OPEN_CONFIRMATION, we will need to send a
@@ -291,7 +292,7 @@ enum {
 struct share_globreq {
     struct share_globreq *next;
     int type;
-    int want_reply;
+    bool want_reply;
     struct share_forwarding *fwd;
 };
 
@@ -571,7 +572,7 @@ static struct share_channel *share_add_channel
     chan->x11_auth_data = NULL;
     chan->x11_auth_proto = -1;
     chan->x11_auth_datalen = 0;
-    chan->x11_one_shot = 0;
+    chan->x11_one_shot = false;
     if (add234(cs->channels_by_us, chan) != chan) {
         sfree(chan);
         return NULL;
@@ -631,7 +632,7 @@ static struct share_xchannel *share_add_xchannel
     struct share_xchannel *xc = snew(struct share_xchannel);
     xc->upstream_id = upstream_id;
     xc->server_id = server_id;
-    xc->live = TRUE;
+    xc->live = true;
     xc->msghead = xc->msgtail = NULL;
     if (add234(cs->xchannels_by_us, xc) != xc) {
         sfree(xc);
@@ -676,7 +677,7 @@ static struct share_forwarding *share_add_forwarding
     struct share_forwarding *fwd = snew(struct share_forwarding);
     fwd->host = dupstr(host);
     fwd->port = port;
-    fwd->active = FALSE;
+    fwd->active = false;
     if (add234(cs->forwardings, fwd) != fwd) {
         /* Duplicate?! */
         sfree(fwd);
@@ -875,7 +876,7 @@ static void share_try_cleanup(struct ssh_sharing_connstate *cs)
         if (fwd->active) {
             strbuf *packet = strbuf_new();
             put_stringz(packet, "cancel-tcpip-forward");
-            put_bool(packet, FALSE);       /* !want_reply */
+            put_bool(packet, false);       /* !want_reply */
             put_stringz(packet, fwd->host);
             put_uint32(packet, fwd->port);
             ssh_send_packet_from_downstream(
@@ -936,7 +937,7 @@ static void share_disconnect(struct ssh_sharing_connstate *cs,
 }
 
 static void share_closing(Plug *plug, const char *error_msg, int error_code,
-			  int calling_back)
+			  bool calling_back)
 {
     struct ssh_sharing_connstate *cs = container_of(
         plug, struct ssh_sharing_connstate, plug);
@@ -997,7 +998,7 @@ void share_dead_xchannel_respond(struct ssh_sharing_connstate *cs,
      * Handle queued incoming messages from the server destined for an
      * xchannel which is dead (i.e. downstream sent OPEN_FAILURE).
      */
-    int delete = FALSE;
+    bool delete = false;
     while (xc->msghead) {
         struct share_xchannel_message *msg = xc->msghead;
         xc->msghead = msg->next;
@@ -1024,7 +1025,7 @@ void share_dead_xchannel_respond(struct ssh_sharing_connstate *cs,
             /*
              * On CHANNEL_CLOSE we can discard the channel completely.
              */
-            delete = TRUE;
+            delete = true;
         }
 
         sfree(msg);
@@ -1092,7 +1093,7 @@ void share_xchannel_failure(struct ssh_sharing_connstate *cs,
      * Now mark the xchannel as dead, and respond to anything sent on
      * it until we see CLOSE for it in turn.
      */
-    xc->live = FALSE;
+    xc->live = false;
     share_dead_xchannel_respond(cs, xc);
 }
 
@@ -1157,7 +1158,7 @@ void share_setup_x11_channel(ssh_sharing_connstate *cs, share_channel *chan,
         sfree(chan->x11_auth_data);
         chan->x11_auth_proto = -1;
         chan->x11_auth_datalen = 0;
-        chan->x11_one_shot = 0;
+        chan->x11_one_shot = false;
     }
 }
 
@@ -1183,7 +1184,7 @@ void share_got_pkt_from_server(ssh_sharing_connstate *cs, int type,
             if (type == SSH2_MSG_REQUEST_FAILURE) {
                 share_remove_forwarding(cs, globreq->fwd);
             } else {
-                globreq->fwd->active = TRUE;
+                globreq->fwd->active = true;
             }
         } else if (globreq->type == GLOBREQ_CANCEL_TCPIP_FORWARD) {
             if (type == SSH2_MSG_REQUEST_SUCCESS) {
@@ -1312,7 +1313,7 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs,
     char *err = NULL;
     BinarySource src[1];
     size_t wantreplypos;
-    int orig_wantreply;
+    bool orig_wantreply;
 
     BinarySource_BARE_INIT(src, pkt, pktlen);
 
@@ -1635,7 +1636,8 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs,
              * a downstream, and if the latter, which one.
              */
             if (ptrlen_eq_string(request_name, "x11-req")) {
-                int want_reply, single_connection, screen;
+                bool want_reply, single_connection;
+                int screen;
                 ptrlen auth_data;
                 int auth_proto;
 
@@ -1795,7 +1797,7 @@ static void share_receive(Plug *plug, int urgent, char *data, int len)
         cs->recvlen--;                 /* trim off \r before \n */
     log_downstream(cs, "Downstream version string: %.*s",
                    cs->recvlen, cs->recvbuf);
-    cs->got_verstring = TRUE;
+    cs->got_verstring = true;
 
     /*
      * Loop round reading packets.
@@ -1844,7 +1846,7 @@ static void share_sent(Plug *plug, int bufsize)
 }
 
 static void share_listen_closing(Plug *plug, const char *error_msg,
-				 int error_code, int calling_back)
+				 int error_code, bool calling_back)
 {
     ssh_sharing_state *sharestate =
         container_of(plug, ssh_sharing_state, plug);
@@ -1861,7 +1863,7 @@ static void share_send_verstring(ssh_sharing_connstate *cs)
     sk_write(cs->sock, fullstring, strlen(fullstring));
     sfree(fullstring);
 
-    cs->sent_verstring = TRUE;
+    cs->sent_verstring = true;
 }
 
 int share_ndownstreams(ssh_sharing_state *sharestate)
@@ -1942,11 +1944,11 @@ static int share_listen_accepting(Plug *plug,
 
     add234(cs->parent->connections, cs);
 
-    cs->sent_verstring = FALSE;
+    cs->sent_verstring = false;
     if (sharestate->server_verstring)
         share_send_verstring(cs);
 
-    cs->got_verstring = FALSE;
+    cs->got_verstring = false;
     cs->recvlen = 0;
     cs->crLine = 0;
     cs->halfchannels = newtree234(share_halfchannel_cmp);
@@ -1966,11 +1968,6 @@ static int share_listen_accepting(Plug *plug,
     return 0;
 }
 
-/* Per-application overrides for what roles we can take (e.g. pscp
- * will never be an upstream) */
-extern const int share_can_be_downstream;
-extern const int share_can_be_upstream;
-
 /*
  * Decide on the string used to identify the connection point between
  * upstream and downstream (be it a Windows named pipe or a
@@ -2015,7 +2012,7 @@ char *ssh_share_sockname(const char *host, int port, Conf *conf)
     return sockname;
 }
 
-int ssh_share_test_for_upstream(const char *host, int port, Conf *conf)
+bool ssh_share_test_for_upstream(const char *host, int port, Conf *conf)
 {
     char *sockname, *logtext, *ds_err, *us_err;
     int result;
@@ -2026,7 +2023,7 @@ int ssh_share_test_for_upstream(const char *host, int port, Conf *conf)
     sock = NULL;
     logtext = ds_err = us_err = NULL;
     result = platform_ssh_share(sockname, conf, nullplug, (Plug *)NULL, &sock,
-                                &logtext, &ds_err, &us_err, FALSE, TRUE);
+                                &logtext, &ds_err, &us_err, false, true);
 
     sfree(logtext);
     sfree(ds_err);
@@ -2035,11 +2032,11 @@ int ssh_share_test_for_upstream(const char *host, int port, Conf *conf)
 
     if (result == SHARE_NONE) {
         assert(sock == NULL);
-        return FALSE;
+        return false;
     } else {
         assert(result == SHARE_DOWNSTREAM);
         sk_close(sock);
-        return TRUE;
+        return true;
     }
 }
 
@@ -2071,18 +2068,19 @@ Socket *ssh_connection_sharing_init(
     const char *host, int port, Conf *conf, LogContext *logctx,
     Plug *sshplug, ssh_sharing_state **state)
 {
-    int result, can_upstream, can_downstream;
+    int result;
+    bool can_upstream, can_downstream;
     char *logtext, *ds_err, *us_err;
     char *sockname;
     Socket *sock, *toret = NULL;
     struct ssh_sharing_state *sharestate;
 
-    if (!conf_get_int(conf, CONF_ssh_connection_sharing))
+    if (!conf_get_bool(conf, CONF_ssh_connection_sharing))
         return NULL;                   /* do not share anything */
     can_upstream = share_can_be_upstream &&
-        conf_get_int(conf, CONF_ssh_connection_sharing_upstream);
+        conf_get_bool(conf, CONF_ssh_connection_sharing_upstream);
     can_downstream = share_can_be_downstream &&
-        conf_get_int(conf, CONF_ssh_connection_sharing_downstream);
+        conf_get_bool(conf, CONF_ssh_connection_sharing_downstream);
     if (!can_upstream && !can_downstream)
         return NULL;
 

+ 9 - 9
source/putty/sshverstring.c

@@ -21,9 +21,9 @@ struct ssh_verstring_state {
     char *our_protoversion;
     struct ssh_version_receiver *receiver;
 
-    int send_early;
+    bool send_early;
 
-    int found_prefix;
+    bool found_prefix;
     int major_protoversion;
     int remote_bugs;
     char prefix[PREFIX_MAXLEN];
@@ -55,13 +55,13 @@ static const struct BinaryPacketProtocolVtable ssh_verstring_vtable = {
 };
 
 static void ssh_detect_bugs(struct ssh_verstring_state *s);
-static int ssh_version_includes_v1(const char *ver);
-static int ssh_version_includes_v2(const char *ver);
+static bool ssh_version_includes_v1(const char *ver);
+static bool ssh_version_includes_v2(const char *ver);
 
 BinaryPacketProtocol *ssh_verstring_new(
-    Conf *conf, LogContext *logctx, int bare_connection_mode,
+    Conf *conf, LogContext *logctx, bool bare_connection_mode,
     const char *protoversion, struct ssh_version_receiver *rcv,
-    int server_mode, const char *impl_name)
+    bool server_mode, const char *impl_name)
 {
     struct ssh_verstring_state *s = snew(struct ssh_verstring_state);
 
@@ -141,12 +141,12 @@ static int ssh_versioncmp(const char *a, const char *b)
     return 0;
 }
 
-static int ssh_version_includes_v1(const char *ver)
+static bool ssh_version_includes_v1(const char *ver)
 {
     return ssh_versioncmp(ver, "2.0") < 0;
 }
 
-static int ssh_version_includes_v2(const char *ver)
+static bool ssh_version_includes_v2(const char *ver)
 {
     return ssh_versioncmp(ver, "1.99") >= 0;
 }
@@ -265,7 +265,7 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
         }
     }
 
-    s->found_prefix = TRUE;
+    s->found_prefix = true;
 
     /*
      * Start a buffer to store the full greeting line.

+ 17 - 24
source/putty/sshzlib.c

@@ -59,13 +59,6 @@
 #define sresize(x, n, type) ( (type *) realloc((x), (n) * sizeof(type)) )
 #define sfree(x) ( free((x)) )
 
-#ifndef FALSE
-#define FALSE 0
-#endif
-#ifndef TRUE
-#define TRUE 1
-#endif
-
 typedef struct { const struct dummy *vt; } ssh_compressor;
 typedef struct { const struct dummy *vt; } ssh_decompressor;
 static const struct dummy { int i; } ssh_zlib;
@@ -97,11 +90,11 @@ static int lz77_init(struct LZ77Context *ctx);
 /*
  * Supply data to be compressed. Will update the private fields of
  * the LZ77Context, and will call literal() and match() to output.
- * If `compress' is FALSE, it will never emit a match, but will
+ * If `compress' is false, it will never emit a match, but will
  * instead call literal() for everything.
  */
 static void lz77_compress(struct LZ77Context *ctx,
-			  unsigned char *data, int len, int compress);
+			  unsigned char *data, int len, bool compress);
 
 /*
  * Modifiable parameters.
@@ -206,7 +199,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,
-			  unsigned char *data, int len, int compress)
+			  unsigned char *data, int len, bool compress)
 {
     struct LZ77InternalContext *st = ctx->ictx;
     int i, distance, off, nmatch, matchlen, advance;
@@ -377,7 +370,7 @@ struct Outbuf {
     int outlen, outsize;
     unsigned long outbits;
     int noutbits;
-    int firstblock;
+    bool firstblock;
 };
 
 static void outbits(struct Outbuf *out, unsigned long bits, int nbits)
@@ -621,7 +614,7 @@ ssh_compressor *zlib_compress_init(void)
 
     out = snew(struct Outbuf);
     out->outbits = out->noutbits = 0;
-    out->firstblock = 1;
+    out->firstblock = true;
     comp->ectx.userdata = out;
 
     return &comp->sc;
@@ -643,7 +636,7 @@ void zlib_compress_block(ssh_compressor *sc, unsigned char *block, int len,
     struct ssh_zlib_compressor *comp =
         container_of(sc, struct ssh_zlib_compressor, sc);
     struct Outbuf *out = (struct Outbuf *) comp->ectx.userdata;
-    int in_block;
+    bool in_block;
 
     out->outbuf = NULL;
     out->outlen = out->outsize = 0;
@@ -655,11 +648,11 @@ void zlib_compress_block(ssh_compressor *sc, unsigned char *block, int len,
      */
     if (out->firstblock) {
 	outbits(out, 0x9C78, 16);
-	out->firstblock = 0;
+	out->firstblock = false;
 
-	in_block = FALSE;
+	in_block = false;
     } else
-	in_block = TRUE;
+	in_block = true;
 
     if (!in_block) {
         /*
@@ -674,7 +667,7 @@ void zlib_compress_block(ssh_compressor *sc, unsigned char *block, int len,
     /*
      * Do the compression.
      */
-    lz77_compress(&comp->ectx, block, len, TRUE);
+    lz77_compress(&comp->ectx, block, len, true);
 
     /*
      * End the block (by transmitting code 256, which is
@@ -974,8 +967,8 @@ static void zlib_emit_char(struct zlib_decompress_ctx *dctx, int c)
 
 #define EATBITS(n) ( dctx->nbits -= (n), dctx->bits >>= (n) )
 
-int zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len,
-			  unsigned char **outblock, int *outlen)
+bool zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len,
+                           unsigned char **outblock, int *outlen)
 {
     struct zlib_decompress_ctx *dctx =
         container_of(dc, struct zlib_decompress_ctx, dc);
@@ -1216,13 +1209,13 @@ int zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len,
   finished:
     *outblock = dctx->outblk;
     *outlen = dctx->outlen;
-    return 1;
+    return true;
 
   decode_error:
     sfree(dctx->outblk);
     *outblock = dctx->outblk = NULL;
     *outlen = 0;
-    return 0;
+    return false;
 }
 
 #ifdef ZLIB_STANDALONE
@@ -1235,7 +1228,7 @@ int main(int argc, char **argv)
     unsigned char buf[16], *outbuf;
     int ret, outlen;
     ssh_decompressor *handle;
-    int noheader = FALSE, opts = TRUE;
+    int noheader = false, opts = true;
     char *filename = NULL;
     FILE *fp;
 
@@ -1244,9 +1237,9 @@ int main(int argc, char **argv)
 
         if (p[0] == '-' && opts) {
             if (!strcmp(p, "-d"))
-                noheader = TRUE;
+                noheader = true;
             else if (!strcmp(p, "--"))
-                opts = FALSE;          /* next thing is filename */
+                opts = false;          /* next thing is filename */
             else {
                 fprintf(stderr, "unknown command line option '%s'\n", p);
                 return 1;

+ 1 - 1
source/putty/storage.h

@@ -69,7 +69,7 @@ void del_settings(const char *sessionname);
  * Enumerate all saved sessions.
  */
 settings_e *enum_settings_start(void);
-char *enum_settings_next(settings_e *handle, char *buffer, int buflen);
+bool enum_settings_next(settings_e *handle, strbuf *out);
 void enum_settings_finish(settings_e *handle);
 
 /* ----------------------------------------------------------------------

+ 2 - 1
source/putty/tree234.c

@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <assert.h>
 
+#include "defs.h"
 #include "tree234.h"
 
 #ifdef TEST
@@ -529,7 +530,7 @@ void *findrelpos234(tree234 * t, void *e, cmpfn234 cmp,
     search234_state ss;
     int reldir = (relation == REL234_LT || relation == REL234_LE ? -1 :
                   relation == REL234_GT || relation == REL234_GE ? +1 : 0);
-    int equal_permitted = (relation != REL234_LT && relation != REL234_GT);
+    bool equal_permitted = (relation != REL234_LT && relation != REL234_GT);
     void *toret;
 
     /* Only LT / GT relations are permitted with a null query element. */

+ 8 - 8
source/putty/wildcard.c

@@ -131,14 +131,14 @@ static int wc_match_fragment(const char **fragment, const char **target,
 	     */
 	    f++;
 	} else if (*f == '[') {
-	    int invert = 0;
-	    int matched = 0;
+	    bool invert = false;
+	    bool matched = false;
 	    /*
 	     * Open bracket introduces a character class.
 	     */
 	    f++;
 	    if (*f == '^') {
-		invert = 1;
+		invert = true;
 		f++;
 	    }
 	    while (*f != ']') {
@@ -162,7 +162,7 @@ static int wc_match_fragment(const char **fragment, const char **target,
 			int t = lower; lower = upper; upper = t;
 		    }
 		    if (ourchr >= lower && ourchr <= upper)
-			matched = 1;
+			matched = true;
 		} else {
 		    matched |= (*t == *f++);
 		}
@@ -315,11 +315,11 @@ int wc_match_pl(const char *wildcard, ptrlen target)
  * the original wildcard. You can also pass NULL as the output
  * buffer if you're only interested in the return value.
  * 
- * Returns 1 on success, or 0 if a wildcard character was
+ * 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!
  */
-int wc_unescape(char *output, const char *wildcard)
+bool wc_unescape(char *output, const char *wildcard)
 {
     while (*wildcard) {
 	if (*wildcard == '\\') {
@@ -332,7 +332,7 @@ int wc_unescape(char *output, const char *wildcard)
 	    }
 	} else if (*wildcard == '*' || *wildcard == '?' ||
 		   *wildcard == '[' || *wildcard == ']') {
-	    return 0;		       /* it's a wildcard! */
+	    return false;              /* it's a wildcard! */
 	} else {
 	    if (output)
 		*output++ = *wildcard;
@@ -341,7 +341,7 @@ int wc_unescape(char *output, const char *wildcard)
     }
     if (output)
         *output = '\0';
-    return 1;			       /* it's clean */
+    return true;                       /* it's clean */
 }
 
 #ifdef TESTMODE

+ 51 - 50
source/putty/windows/winhandl.c

@@ -58,10 +58,10 @@ struct handle_generic {
     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 */
-    int moribund;		       /* are we going to kill this soon? */
-    int done;			       /* request subthread to terminate */
-    int defunct;		       /* has the subthread already gone? */
-    int busy;			       /* operation currently in progress? */
+    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 */
 };
 
@@ -81,10 +81,10 @@ struct handle_input {
     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 */
-    int moribund;		       /* are we going to kill this soon? */
-    int done;			       /* request subthread to terminate */
-    int defunct;		       /* has the subthread already gone? */
-    int busy;			       /* operation currently in progress? */
+    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 */
 
     /*
@@ -115,11 +115,12 @@ static DWORD WINAPI handle_input_threadfunc(void *param)
     struct handle_input *ctx = (struct handle_input *) param;
     OVERLAPPED ovl, *povl;
     HANDLE oev;
-    int readret, readlen, finished;
+    bool readret, finished;
+    int readlen;
 
     if (ctx->flags & HANDLE_FLAG_OVERLAPPED) {
 	povl = &ovl;
-	oev = CreateEvent(NULL, TRUE, FALSE, NULL);
+	oev = CreateEvent(NULL, true, false, NULL);
     } else {
 	povl = NULL;
     }
@@ -141,7 +142,7 @@ static DWORD WINAPI handle_input_threadfunc(void *param)
 	    ctx->readerr = 0;
 	if (povl && !readret && ctx->readerr == ERROR_IO_PENDING) {
 	    WaitForSingleObject(povl->hEvent, INFINITE);
-	    readret = GetOverlappedResult(ctx->h, povl, &ctx->len, FALSE);
+	    readret = GetOverlappedResult(ctx->h, povl, &ctx->len, false);
 	    if (!readret)
 		ctx->readerr = GetLastError();
 	    else
@@ -223,7 +224,7 @@ static void handle_throttle(struct handle_input *ctx, int backlog)
      */
     if (backlog < MAX_BACKLOG) {
 	SetEvent(ctx->ev_from_main);
-	ctx->busy = TRUE;
+	ctx->busy = true;
     }
 }
 
@@ -241,10 +242,10 @@ struct handle_output {
     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 */
-    int moribund;		       /* are we going to kill this soon? */
-    int done;			       /* request subthread to terminate */
-    int defunct;		       /* has the subthread already gone? */
-    int busy;			       /* operation currently in progress? */
+    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 */
 
     /*
@@ -284,11 +285,11 @@ static DWORD WINAPI handle_output_threadfunc(void *param)
     struct handle_output *ctx = (struct handle_output *) param;
     OVERLAPPED ovl, *povl;
     HANDLE oev;
-    int writeret;
+    bool writeret;
 
     if (ctx->flags & HANDLE_FLAG_OVERLAPPED) {
 	povl = &ovl;
-	oev = CreateEvent(NULL, TRUE, FALSE, NULL);
+	oev = CreateEvent(NULL, true, false, NULL);
     } else {
 	povl = NULL;
     }
@@ -318,7 +319,7 @@ static DWORD WINAPI handle_output_threadfunc(void *param)
 	    ctx->writeerr = 0;
 	if (povl && !writeret && GetLastError() == ERROR_IO_PENDING) {
 	    writeret = GetOverlappedResult(ctx->h, povl,
-					   &ctx->lenwritten, TRUE);
+					   &ctx->lenwritten, true);
 	    if (!writeret)
 		ctx->writeerr = GetLastError();
 	    else
@@ -354,7 +355,7 @@ static void handle_try_output(struct handle_output *ctx)
 	ctx->buffer = senddata;
 	ctx->len = sendlen;
 	SetEvent(ctx->ev_from_main);
-	ctx->busy = TRUE;
+	ctx->busy = true;
     } else if (!ctx->busy && bufchain_size(&ctx->queued_data) == 0 &&
                ctx->outgoingeof == EOF_PENDING) {
         CloseHandle(ctx->h);
@@ -377,10 +378,10 @@ struct handle_foreign {
     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 */
-    int moribund;		       /* are we going to kill this soon? */
-    int done;			       /* request subthread to terminate */
-    int defunct;		       /* has the subthread already gone? */
-    int busy;			       /* operation currently in progress? */
+    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 */
 
     /*
@@ -440,12 +441,12 @@ struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
 
     h->type = HT_INPUT;
     h->u.i.h = handle;
-    h->u.i.ev_to_main = CreateEvent(NULL, FALSE, FALSE, NULL);
-    h->u.i.ev_from_main = CreateEvent(NULL, FALSE, FALSE, NULL);
+    h->u.i.ev_to_main = CreateEvent(NULL, false, false, NULL);
+    h->u.i.ev_from_main = CreateEvent(NULL, false, false, NULL);
     h->u.i.gotdata = gotdata;
-    h->u.i.defunct = FALSE;
-    h->u.i.moribund = FALSE;
-    h->u.i.done = FALSE;
+    h->u.i.defunct = false;
+    h->u.i.moribund = false;
+    h->u.i.done = false;
     h->u.i.privdata = privdata;
     h->u.i.flags = flags;
 
@@ -455,7 +456,7 @@ struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
 
     CreateThread(NULL, 0, handle_input_threadfunc,
 		 &h->u.i, 0, &in_threadid);
-    h->u.i.busy = TRUE;
+    h->u.i.busy = true;
 
     return h;
 }
@@ -468,12 +469,12 @@ struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
 
     h->type = HT_OUTPUT;
     h->u.o.h = handle;
-    h->u.o.ev_to_main = CreateEvent(NULL, FALSE, FALSE, NULL);
-    h->u.o.ev_from_main = CreateEvent(NULL, FALSE, FALSE, NULL);
-    h->u.o.busy = FALSE;
-    h->u.o.defunct = FALSE;
-    h->u.o.moribund = FALSE;
-    h->u.o.done = FALSE;
+    h->u.o.ev_to_main = CreateEvent(NULL, false, false, NULL);
+    h->u.o.ev_from_main = CreateEvent(NULL, false, false, NULL);
+    h->u.o.busy = false;
+    h->u.o.defunct = false;
+    h->u.o.moribund = false;
+    h->u.o.done = false;
     h->u.o.privdata = privdata;
     bufchain_init(&h->u.o.queued_data);
     h->u.o.outgoingeof = EOF_NO;
@@ -499,13 +500,13 @@ struct handle *handle_add_foreign_event(HANDLE event,
     h->u.f.h = INVALID_HANDLE_VALUE;
     h->u.f.ev_to_main = event;
     h->u.f.ev_from_main = INVALID_HANDLE_VALUE;
-    h->u.f.defunct = TRUE;  /* we have no thread in the first place */
-    h->u.f.moribund = FALSE;
-    h->u.f.done = FALSE;
+    h->u.f.defunct = true;  /* we have no thread in the first place */
+    h->u.f.moribund = false;
+    h->u.f.done = false;
     h->u.f.privdata = NULL;
     h->u.f.callback = callback;
     h->u.f.ctx = ctx;
-    h->u.f.busy = TRUE;
+    h->u.f.busy = true;
 
     if (!handles_by_evtomain)
 	handles_by_evtomain = newtree234(handle_cmp_evtomain);
@@ -592,7 +593,7 @@ void handle_free(struct handle *h)
          * 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
@@ -605,9 +606,9 @@ void handle_free(struct handle *h)
 	 * 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;
+	h->u.g.moribund = true;
+	h->u.g.done = true;
+	h->u.g.busy = true;
 	SetEvent(h->u.g.ev_from_main);
     }
 }
@@ -642,8 +643,8 @@ void handle_got_event(HANDLE event)
 	if (h->u.g.done) {
 	    handle_destroy(h);
 	} else {
-	    h->u.g.done = TRUE;
-	    h->u.g.busy = TRUE;
+	    h->u.g.done = true;
+	    h->u.g.busy = true;
 	    SetEvent(h->u.g.ev_from_main);
 	}
 	return;
@@ -653,7 +654,7 @@ void handle_got_event(HANDLE event)
 	int backlog;
 
       case HT_INPUT:
-	h->u.i.busy = FALSE;
+	h->u.i.busy = false;
 
 	/*
 	 * A signal on an input handle means data has arrived.
@@ -662,7 +663,7 @@ void handle_got_event(HANDLE event)
 	    /*
 	     * EOF, or (nearly equivalently) read error.
 	     */
-	    h->u.i.defunct = TRUE;
+	    h->u.i.defunct = true;
 	    h->u.i.gotdata(h, NULL, -h->u.i.readerr);
 	} else {
 	    backlog = h->u.i.gotdata(h, h->u.i.buffer, h->u.i.len);
@@ -671,7 +672,7 @@ void handle_got_event(HANDLE event)
         break;
 
       case HT_OUTPUT:
-	h->u.o.busy = FALSE;
+	h->u.o.busy = false;
 
 	/*
 	 * A signal on an output handle means we have completed a
@@ -684,7 +685,7 @@ void handle_got_event(HANDLE event)
 	     * and mark the thread as defunct (because the output
 	     * thread is terminating by now).
 	     */
-	    h->u.o.defunct = TRUE;
+	    h->u.o.defunct = true;
 	    h->u.o.sentdata(h, -h->u.o.writeerr);
 	} else {
 	    bufchain_consume(&h->u.o.queued_data, h->u.o.lenwritten);

+ 50 - 13
source/putty/windows/winmisc.c

@@ -35,12 +35,12 @@ const char *filename_to_str(const Filename *fn)
     return fn->path;
 }
 
-int filename_equal(const Filename *f1, const Filename *f2)
+bool filename_equal(const Filename *f1, const Filename *f2)
 {
     return !strcmp(f1->path, f2->path);
 }
 
-int filename_is_null(const Filename *fn)
+bool filename_is_null(const Filename *fn)
 {
     return !*fn->path;
 }
@@ -81,12 +81,12 @@ char *get_username(void)
 {
     DWORD namelen;
     char *user;
-    int got_username = FALSE;
+    bool got_username = false;
     DECL_WINDOWS_FUNCTION(static, BOOLEAN, GetUserNameExA,
 			  (EXTENDED_NAME_FORMAT, LPSTR, PULONG));
 
     {
-	static int tried_usernameex = FALSE;
+	static bool tried_usernameex = false;
 	if (!tried_usernameex) {
 	    /* Not available on Win9x, so load dynamically */
 	    HMODULE secur32 = load_system32_dll("secur32.dll");
@@ -97,7 +97,7 @@ char *get_username(void)
 	    HMODULE sspicli = load_system32_dll("sspicli.dll");
             (void)sspicli; /* squash compiler warning about unused variable */
 	    GET_WINDOWS_FUNCTION(secur32, GetUserNameExA);
-	    tried_usernameex = TRUE;
+	    tried_usernameex = true;
 	}
     }
 
@@ -125,7 +125,7 @@ char *get_username(void)
     if (!got_username) {
 	/* Fall back to local user name */
 	namelen = 0;
-	if (GetUserName(NULL, &namelen) == FALSE) {
+	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
@@ -559,8 +559,7 @@ void *minefield_c_realloc(void *p, size_t size)
 
 #endif				/* MINEFIELD */
 
-FontSpec *fontspec_new(const char *name,
-                        int bold, int height, int charset)
+FontSpec *fontspec_new(const char *name, bool bold, int height, int charset)
 {
     FontSpec *f = snew(FontSpec);
     f->name = dupstr(name);
@@ -594,7 +593,7 @@ FontSpec *fontspec_deserialise(BinarySource *src)
     return fontspec_new(name, isbold, height, charset);
 }
 
-int open_for_write_would_lose_data(const Filename *fn)
+bool open_for_write_would_lose_data(const Filename *fn)
 {
     WIN32_FILE_ATTRIBUTE_DATA attrs;
     if (!GetFileAttributesEx(fn->path, GetFileExInfoStandard, &attrs)) {
@@ -604,7 +603,7 @@ int open_for_write_would_lose_data(const Filename *fn)
          * let the subsequent attempt to open the file for real give a
          * more useful error message.
          */
-        return FALSE;
+        return false;
     }
     if (attrs.dwFileAttributes & (FILE_ATTRIBUTE_DEVICE |
                                   FILE_ATTRIBUTE_DIRECTORY)) {
@@ -613,7 +612,7 @@ int open_for_write_would_lose_data(const Filename *fn)
          * opening it for writing will not cause truncation. (It may
          * not _succeed_ either, but that's not our problem here!)
          */
-        return FALSE;
+        return false;
     }
     if (attrs.nFileSizeHigh == 0 && attrs.nFileSizeLow == 0) {
         /*
@@ -622,7 +621,45 @@ int open_for_write_would_lose_data(const Filename *fn)
          * opening it for writing won't truncate any data away because
          * there's nothing to truncate anyway.
          */
-        return FALSE;
+        return false;
+    }
+    return true;
+}
+
+void escape_registry_key(const char *in, strbuf *out)
+{
+    bool candot = false;
+    static const char hex[16] = "0123456789ABCDEF";
+
+    while (*in) {
+	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;
+    }
+}
+
+void unescape_registry_key(const char *in, strbuf *out)
+{
+    while (*in) {
+	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);
+
+	    put_byte(out, (i << 4) + j);
+	    in += 3;
+	} else {
+            put_byte(out, *in++);
+	}
     }
-    return TRUE;
 }

+ 88 - 156
source/putty/windows/winnet.c

@@ -53,20 +53,20 @@ struct NetSocket {
     SOCKET s;
     Plug *plug;
     bufchain output_data;
-    int connected;
-    int writable;
-    int frozen; /* this causes readability notifications to be ignored */
-    int frozen_readable; /* this means we missed at least one readability
-			  * notification while we were frozen */
-    int localhost_only;		       /* for listening sockets */
+    bool connected;
+    bool writable;
+    bool frozen; /* this causes readability notifications to be ignored */
+    bool frozen_readable; /* this means we missed at least one readability
+                           * notification while we were frozen */
+    bool localhost_only;               /* for listening sockets */
     char oobdata[1];
     int sending_oob;
-    int oobinline, nodelay, keepalive, privport;
+    bool oobinline, nodelay, keepalive, privport;
     enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof;
     SockAddr *addr;
     SockAddrStep step;
     int port;
-    int pending_error;		       /* in case send() returns error */
+    int pending_error;             /* in case send() returns error */
     /*
      * We sometimes need pairs of Socket structures to be linked:
      * if we are listening on the same IPv6 and v4 port, for
@@ -81,9 +81,9 @@ struct NetSocket {
 struct SockAddr {
     int refcount;
     char *error;
-    int resolved;
-    int namedpipe; /* indicates that this SockAddr is phony, holding a Windows
-                    * named pipe pathname instead of a network address */
+    bool resolved;
+    bool namedpipe; /* indicates that this SockAddr is phony, holding a Windows
+                     * named pipe pathname instead of a network address */
 #ifndef NO_IPV6
     struct addrinfo *ais;	       /* Addresses IPv6 style. */
 #endif
@@ -206,21 +206,21 @@ static HMODULE winsock2_module = NULL;
 static HMODULE wship6_module = NULL;
 #endif
 
-int sk_startup(int hi, int lo)
+static bool sk_startup(int hi, int lo)
 {
     WORD winsock_ver;
 
     winsock_ver = MAKEWORD(hi, lo);
 
     if (p_WSAStartup(winsock_ver, &wsadata)) {
-	return FALSE;
+	return false;
     }
 
     if (LOBYTE(wsadata.wVersion) != LOBYTE(winsock_ver)) {
-	return FALSE;
+	return false;
     }
 
-    return TRUE;
+    return true;
 }
 
 /* Actually define this function pointer, which won't have been
@@ -351,34 +351,8 @@ void sk_cleanup(void)
 #endif
 }
 
-struct errstring {
-    int error;
-    char *text;
-};
-
-static int errstring_find(void *av, void *bv)
-{
-    int *a = (int *)av;
-    struct errstring *b = (struct errstring *)bv;
-    if (*a < b->error)
-        return -1;
-    if (*a > b->error)
-        return +1;
-    return 0;
-}
-static int errstring_compare(void *av, void *bv)
-{
-    struct errstring *a = (struct errstring *)av;
-    return errstring_find(&a->error, bv);
-}
-
-static tree234 *errstrings = NULL;
-
 const char *winsock_error_string(int error)
 {
-    const char prefix[] = "Network error: ";
-    struct errstring *es;
-
     /*
      * Error codes we know about and have historically had reasonably
      * sensible error messages for.
@@ -458,50 +432,9 @@ const char *winsock_error_string(int error)
     }
 
     /*
-     * Generic code to handle any other error.
-     *
-     * Slightly nasty hack here: we want to return a static string
-     * which the caller will never have to worry about freeing, but on
-     * the other hand if we call FormatMessage to get it then it will
-     * want to either allocate a buffer or write into one we own.
-     *
-     * So what we do is to maintain a tree234 of error strings we've
-     * already used. New ones are allocated from the heap, but then
-     * put in this tree and kept forever.
+     * Handle any other error code by delegating to win_strerror.
      */
-
-    if (!errstrings)
-        errstrings = newtree234(errstring_compare);
-
-    es = find234(errstrings, &error, errstring_find);
-
-    if (!es) {
-        int bufsize, bufused;
-
-        es = snew(struct errstring);
-        es->error = error;
-        /* maximum size for FormatMessage is 64K */
-        bufsize = 65535 + sizeof(prefix);
-        es->text = snewn(bufsize, char);
-        strcpy(es->text, prefix);
-        bufused = strlen(es->text);
-        if (!FormatMessage((FORMAT_MESSAGE_FROM_SYSTEM |
-                            FORMAT_MESSAGE_IGNORE_INSERTS), NULL, error,
-                           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                           es->text + bufused, bufsize - bufused, NULL)) {
-            sprintf(es->text + bufused,
-                    "Windows error code %d (and FormatMessage returned %u)",
-                    error, (unsigned int)GetLastError());
-        } else {
-            int len = strlen(es->text);
-            if (len > 0 && es->text[len-1] == '\n')
-                es->text[len-1] = '\0';
-        }
-        es->text = sresize(es->text, strlen(es->text) + 1, char);
-        add234(errstrings, es);
-    }
-
-    return es->text;
+    return win_strerror(error);
 }
 
 SockAddr *sk_namelookup(const char *host, char **canonicalname,
@@ -524,9 +457,9 @@ SockAddr *sk_namelookup(const char *host, char **canonicalname,
 #ifndef NO_IPV6
     ret->ais = NULL;
 #endif
-    ret->namedpipe = FALSE;
+    ret->namedpipe = false;
     ret->addresses = NULL;
-    ret->resolved = FALSE;
+    ret->resolved = false;
     ret->refcount = 1;
     *realhost = '\0';
 
@@ -549,7 +482,7 @@ SockAddr *sk_namelookup(const char *host, char **canonicalname,
                 sfree(trimmed_host);
             }
 	    if (err == 0)
-		ret->resolved = TRUE;
+		ret->resolved = true;
 	} else
 #endif
 	{
@@ -558,7 +491,7 @@ SockAddr *sk_namelookup(const char *host, char **canonicalname,
 	     * (NOTE: we don't use gethostbyname as a fallback!)
 	     */
 	    if ( (h = p_gethostbyname(host)) )
-		ret->resolved = TRUE;
+		ret->resolved = true;
 	    else
 		err = p_WSAGetLastError();
 	}
@@ -614,7 +547,7 @@ SockAddr *sk_namelookup(const char *host, char **canonicalname,
 	ret->addresses = snewn(1, unsigned long);
 	ret->naddresses = 1;
 	ret->addresses[0] = p_ntohl(a);
-	ret->resolved = TRUE;
+	ret->resolved = true;
 	strncpy(realhost, host, sizeof(realhost));
     }
     realhost[lenof(realhost)-1] = '\0';
@@ -627,11 +560,11 @@ SockAddr *sk_nonamelookup(const char *host)
 {
     SockAddr *ret = snew(SockAddr);
     ret->error = NULL;
-    ret->resolved = FALSE;
+    ret->resolved = false;
 #ifndef NO_IPV6
     ret->ais = NULL;
 #endif
-    ret->namedpipe = FALSE;
+    ret->namedpipe = false;
     ret->addresses = NULL;
     ret->naddresses = 0;
     ret->refcount = 1;
@@ -644,11 +577,11 @@ SockAddr *sk_namedpipe_addr(const char *pipename)
 {
     SockAddr *ret = snew(SockAddr);
     ret->error = NULL;
-    ret->resolved = FALSE;
+    ret->resolved = false;
 #ifndef NO_IPV6
     ret->ais = NULL;
 #endif
-    ret->namedpipe = TRUE;
+    ret->namedpipe = true;
     ret->addresses = NULL;
     ret->naddresses = 0;
     ret->refcount = 1;
@@ -657,22 +590,22 @@ SockAddr *sk_namedpipe_addr(const char *pipename)
     return ret;
 }
 
-int sk_nextaddr(SockAddr *addr, SockAddrStep *step)
+static bool sk_nextaddr(SockAddr *addr, SockAddrStep *step)
 {
 #ifndef NO_IPV6
     if (step->ai) {
 	if (step->ai->ai_next) {
 	    step->ai = step->ai->ai_next;
-	    return TRUE;
+	    return true;
 	} else
-	    return FALSE;
+	    return false;
     }
 #endif
     if (step->curraddr+1 < addr->naddresses) {
 	step->curraddr++;
-	return TRUE;
+	return true;
     } else {
-	return FALSE;
+	return false;
     }
 }
 
@@ -739,12 +672,12 @@ static SockAddr sk_extractaddr_tmp(
     return toret;
 }
 
-int sk_addr_needs_port(SockAddr *addr)
+bool sk_addr_needs_port(SockAddr *addr)
 {
-    return addr->namedpipe ? FALSE : TRUE;
+    return !addr->namedpipe;
 }
 
-int sk_hostname_is_local(const char *name)
+bool sk_hostname_is_local(const char *name)
 {
     return !strcmp(name, "localhost") ||
 	   !strcmp(name, "::1") ||
@@ -754,10 +687,10 @@ int sk_hostname_is_local(const char *name)
 static INTERFACE_INFO local_interfaces[16];
 static int n_local_interfaces;       /* 0=not yet, -1=failed, >0=number */
 
-static int ipv4_is_local_addr(struct in_addr addr)
+static bool ipv4_is_local_addr(struct in_addr addr)
 {
     if (ipv4_is_loopback(addr))
-	return 1;		       /* loopback addresses are local */
+	return true;                   /* loopback addresses are local */
     if (!n_local_interfaces) {
 	SOCKET s = p_socket(AF_INET, SOCK_DGRAM, 0);
 	DWORD retbytes;
@@ -778,13 +711,13 @@ static int ipv4_is_local_addr(struct in_addr addr)
 	    SOCKADDR_IN *address =
 		(SOCKADDR_IN *)&local_interfaces[i].iiAddress;
 	    if (address->sin_addr.s_addr == addr.s_addr)
-		return 1;	       /* this address is local */
+		return true;           /* this address is local */
 	}
     }
-    return 0;		       /* this address is not local */
+    return false;                      /* this address is not local */
 }
 
-int sk_address_is_local(SockAddr *addr)
+bool sk_address_is_local(SockAddr *addr)
 {
     SockAddrStep step;
     int family;
@@ -811,13 +744,13 @@ int sk_address_is_local(SockAddr *addr)
 	}
     } else {
 	assert(family == AF_UNSPEC);
-	return 0;		       /* we don't know; assume not */
+	return false;                  /* we don't know; assume not */
     }
 }
 
-int sk_address_is_special_local(SockAddr *addr)
+bool sk_address_is_special_local(SockAddr *addr)
 {
-    return 0;                /* no Unix-domain socket analogue here */
+    return false;            /* no Unix-domain socket analogue here */
 }
 
 int sk_addrtype(SockAddr *addr)
@@ -851,7 +784,7 @@ void sk_addrcopy(SockAddr *addr, char *buf)
 	    memcpy(buf, &((struct sockaddr_in6 *)step.ai->ai_addr)->sin6_addr,
 		   sizeof(struct in6_addr));
 	else
-	    assert(FALSE);
+	    assert(false);
     } else
 #endif
     if (family == AF_INET) {
@@ -902,12 +835,10 @@ static void sk_net_close(Socket *s);
 static int sk_net_write(Socket *s, const void *data, int len);
 static int sk_net_write_oob(Socket *s, const void *data, int len);
 static void sk_net_write_eof(Socket *s);
-static void sk_net_set_frozen(Socket *s, int is_frozen);
+static void sk_net_set_frozen(Socket *s, bool is_frozen);
 static const char *sk_net_socket_error(Socket *s);
 static SocketPeerInfo *sk_net_peer_info(Socket *s);
 
-extern char *do_select(SOCKET skt, int startup);
-
 static const SocketVtable NetSocket_sockvt = {
     sk_net_plug,
     sk_net_close,
@@ -934,12 +865,12 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug)
     ret->error = NULL;
     ret->plug = plug;
     bufchain_init(&ret->output_data);
-    ret->writable = 1;		       /* to start with */
+    ret->writable = true;              /* to start with */
     ret->sending_oob = 0;
     ret->outgoingeof = EOF_NO;
-    ret->frozen = 1;
-    ret->frozen_readable = 0;
-    ret->localhost_only = 0;	       /* unused, but best init anyway */
+    ret->frozen = true;
+    ret->frozen_readable = false;
+    ret->localhost_only = false;    /* unused, but best init anyway */
     ret->pending_error = 0;
     ret->parent = ret->child = NULL;
     ret->addr = NULL;
@@ -952,11 +883,11 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug)
 	return &ret->sock;
     }
 
-    ret->oobinline = 0;
+    ret->oobinline = false;
 
     /* Set up a select mechanism. This could be an AsyncSelect on a
      * window, or an EventSelect on an event object. */
-    errstr = do_select(ret->s, 1);
+    errstr = do_select(ret->s, true);
     if (errstr) {
 	ret->error = errstr;
 	return &ret->sock;
@@ -980,7 +911,7 @@ static DWORD try_connect(NetSocket *sock)
     int family;
 
     if (sock->s != INVALID_SOCKET) {
-	do_select(sock->s, 0);
+	do_select(sock->s, false);
         p_closesocket(sock->s);
     }
 
@@ -1015,17 +946,17 @@ static DWORD try_connect(NetSocket *sock)
 	SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0);
 
     if (sock->oobinline) {
-	BOOL b = TRUE;
+	BOOL b = true;
 	p_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (void *) &b, sizeof(b));
     }
 
     if (sock->nodelay) {
-	BOOL b = TRUE;
+	BOOL b = true;
 	p_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (void *) &b, sizeof(b));
     }
 
     if (sock->keepalive) {
-	BOOL b = TRUE;
+	BOOL b = true;
 	p_setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *) &b, sizeof(b));
     }
 
@@ -1112,7 +1043,7 @@ static DWORD try_connect(NetSocket *sock)
 
     /* Set up a select mechanism. This could be an AsyncSelect on a
      * window, or an EventSelect on an event object. */
-    errstr = do_select(s, 1);
+    errstr = do_select(s, true);
     if (errstr) {
 	sock->error = errstr;
 	err = 1;
@@ -1145,7 +1076,7 @@ static DWORD try_connect(NetSocket *sock)
 	 * If we _don't_ get EWOULDBLOCK, the connect has completed
 	 * and we should set the socket as writable.
 	 */
-	sock->writable = 1;
+	sock->writable = true;
     }
 
     err = 0;
@@ -1165,8 +1096,8 @@ static DWORD try_connect(NetSocket *sock)
     return err;
 }
 
-Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
-               int nodelay, int keepalive, Plug *plug)
+Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline,
+               bool nodelay, bool keepalive, Plug *plug)
 {
     NetSocket *ret;
     DWORD err;
@@ -1179,13 +1110,13 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
     ret->error = NULL;
     ret->plug = plug;
     bufchain_init(&ret->output_data);
-    ret->connected = 0;		       /* to start with */
-    ret->writable = 0;		       /* to start with */
+    ret->connected = false;            /* to start with */
+    ret->writable = false;             /* to start with */
     ret->sending_oob = 0;
     ret->outgoingeof = EOF_NO;
-    ret->frozen = 0;
-    ret->frozen_readable = 0;
-    ret->localhost_only = 0;	       /* unused, but best init anyway */
+    ret->frozen = false;
+    ret->frozen_readable = false;
+    ret->localhost_only = false;    /* unused, but best init anyway */
     ret->pending_error = 0;
     ret->parent = ret->child = NULL;
     ret->oobinline = oobinline;
@@ -1206,7 +1137,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
 }
 
 Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
-                       int local_host_only, int orig_address_family)
+                       bool local_host_only, int orig_address_family)
 {
     SOCKET s;
 #ifndef NO_IPV6
@@ -1230,11 +1161,11 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
     ret->error = NULL;
     ret->plug = plug;
     bufchain_init(&ret->output_data);
-    ret->writable = 0;		       /* to start with */
+    ret->writable = false;             /* to start with */
     ret->sending_oob = 0;
     ret->outgoingeof = EOF_NO;
-    ret->frozen = 0;
-    ret->frozen_readable = 0;
+    ret->frozen = false;
+    ret->frozen_readable = false;
     ret->localhost_only = local_host_only;
     ret->pending_error = 0;
     ret->parent = ret->child = NULL;
@@ -1273,7 +1204,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
 
     SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0);
 
-    ret->oobinline = 0;
+    ret->oobinline = false;
 
     p_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on));
 
@@ -1308,7 +1239,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
 	} else
 #endif
 	{
-	    int got_addr = 0;
+            bool got_addr = false;
 	    a.sin_family = AF_INET;
 
 	    /*
@@ -1320,7 +1251,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
 		if (a.sin_addr.s_addr != INADDR_NONE) {
 		    /* Override localhost_only with specified listen addr. */
 		    ret->localhost_only = ipv4_is_loopback(a.sin_addr);
-		    got_addr = 1;
+		    got_addr = true;
 		}
 	    }
 
@@ -1366,7 +1297,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
 
     /* Set up a select mechanism. This could be an AsyncSelect on a
      * window, or an EventSelect on an event object. */
-    errstr = do_select(s, 1);
+    errstr = do_select(s, true);
     if (errstr) {
 	p_closesocket(s);
 	ret->error = errstr;
@@ -1401,14 +1332,13 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
 
 static void sk_net_close(Socket *sock)
 {
-    extern char *do_select(SOCKET skt, int startup);
     NetSocket *s = container_of(sock, NetSocket, sock);
 
     if (s->child)
 	sk_net_close(&s->child->sock);
 
     del234(sktree, s);
-    do_select(s->s, 0);
+    do_select(s->s, false);
     p_closesocket(s->s);
     if (s->addr)
 	sk_addr_free(s->addr);
@@ -1470,7 +1400,7 @@ void try_send(NetSocket *s)
 		 * a small number - so we check that case and treat
 		 * it just like WSAEWOULDBLOCK.)
 		 */
-		s->writable = FALSE;
+		s->writable = false;
 		return;
 	    } else {
 		/*
@@ -1578,7 +1508,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
     DWORD err;
     char buf[20480];		       /* nice big buffer for plenty of speed */
     NetSocket *s;
-    u_long atmark;
+    bool atmark;
 
     /* wParam is the socket itself */
 
@@ -1612,7 +1542,8 @@ void select_result(WPARAM wParam, LPARAM lParam)
 
     switch (WSAGETSELECTEVENT(lParam)) {
       case FD_CONNECT:
-	s->connected = s->writable = 1;
+	s->connected = true;
+        s->writable = true;
 	/*
 	 * Once a socket is connected, we can stop falling
 	 * back through the candidate addresses to connect
@@ -1626,7 +1557,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
       case FD_READ:
 	/* In the case the socket is still frozen, we don't even bother */
 	if (s->frozen) {
-	    s->frozen_readable = 1;
+	    s->frozen_readable = true;
 	    break;
 	}
 
@@ -1637,8 +1568,8 @@ void select_result(WPARAM wParam, LPARAM lParam)
 	 * (data prior to urgent).
 	 */
 	if (s->oobinline) {
-	    atmark = 1;
-	    p_ioctlsocket(s->s, SIOCATMARK, &atmark);
+            u_long atmark_from_ioctl = 1;
+	    p_ioctlsocket(s->s, SIOCATMARK, &atmark_from_ioctl);
 	    /*
 	     * Avoid checking the return value from ioctlsocket(),
 	     * on the grounds that some WinSock wrappers don't
@@ -1646,8 +1577,9 @@ void select_result(WPARAM wParam, LPARAM lParam)
 	     * which is equivalent to `no OOB pending', so the
 	     * effect will be to non-OOB-ify any OOB data.
 	     */
+            atmark = atmark_from_ioctl;
 	} else
-	    atmark = 1;
+	    atmark = true;
 
 	ret = p_recv(s->s, buf, sizeof(buf), 0);
 	noise_ultralight(ret);
@@ -1684,7 +1616,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
       case FD_WRITE:
 	{
 	    int bufsize_before, bufsize_after;
-	    s->writable = 1;
+	    s->writable = true;
 	    bufsize_before = s->sending_oob + bufchain_size(&s->output_data);
 	    try_send(s);
 	    bufsize_after = s->sending_oob + bufchain_size(&s->output_data);
@@ -1812,20 +1744,20 @@ static SocketPeerInfo *sk_net_peer_info(Socket *sock)
     return pi;
 }
 
-static void sk_net_set_frozen(Socket *sock, int is_frozen)
+static void sk_net_set_frozen(Socket *sock, bool is_frozen)
 {
     NetSocket *s = container_of(sock, NetSocket, sock);
     if (s->frozen == is_frozen)
 	return;
     s->frozen = is_frozen;
     if (!is_frozen) {
-	do_select(s->s, 1);
+	do_select(s->s, true);
 	if (s->frozen_readable) {
 	    char c;
 	    p_recv(s->s, &c, 1, MSG_PEEK);
 	}
     }
-    s->frozen_readable = 0;
+    s->frozen_readable = false;
 }
 
 void socket_reselect_all(void)
@@ -1835,7 +1767,7 @@ void socket_reselect_all(void)
 
     for (i = 0; (s = index234(sktree, i)) != NULL; i++) {
 	if (!s->frozen)
-	    do_select(s->s, 1);
+	    do_select(s->s, true);
     }
 }
 
@@ -1856,14 +1788,14 @@ SOCKET next_socket(int *state)
     return s ? s->s : INVALID_SOCKET;
 }
 
-extern int socket_writable(SOCKET skt)
+bool socket_writable(SOCKET skt)
 {
     NetSocket *s = find234(sktree, (void *)skt, cmpforsearch);
 
     if (s)
 	return bufchain_size(&s->output_data) > 0;
     else
-	return 0;
+	return false;
 }
 
 int net_service_lookup(char *service)

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

@@ -19,9 +19,9 @@ DECL_WINDOWS_FUNCTION(static, BOOL, CryptReleaseContext,
                       (HCRYPTPROV, DWORD));
 static HMODULE wincrypt_module = NULL;
 
-int win_read_random(void *buf, unsigned wanted)
+bool win_read_random(void *buf, unsigned wanted)
 {
-    int toret = FALSE;
+    bool toret = false;
     HCRYPTPROV crypt_provider;
 
     if (!wincrypt_module) {

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

@@ -15,14 +15,14 @@
 
 #define AGENT_COPYDATA_ID 0x804e50ba   /* random goop */
 
-int agent_exists(void)
+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)
@@ -75,9 +75,9 @@ agent_pending_query *agent_query(
             if (psd) {
                 if (p_InitializeSecurityDescriptor
                     (psd, SECURITY_DESCRIPTOR_REVISION) &&
-                    p_SetSecurityDescriptorOwner(psd, usersid, FALSE)) {
+                    p_SetSecurityDescriptorOwner(psd, usersid, false)) {
                     sa.nLength = sizeof(sa);
-                    sa.bInheritHandle = TRUE;
+                    sa.bInheritHandle = true;
                     sa.lpSecurityDescriptor = psd;
                     psa = &sa;
                 } else {

+ 5 - 8
source/putty/windows/winproxy.c

@@ -12,12 +12,9 @@
 #include "network.h"
 #include "proxy.h"
 
-Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
-                           Plug *plug, int overlapped);
-
 Socket *platform_new_connection(SockAddr *addr, const char *hostname,
-                                int port, int privport,
-                                int oobinline, int nodelay, int keepalive,
+                                int port, bool privport,
+                                bool oobinline, bool nodelay, bool keepalive,
                                 Plug *plug, Conf *conf)
 {
     char *cmd;
@@ -48,7 +45,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
      */
     sa.nLength = sizeof(sa);
     sa.lpSecurityDescriptor = NULL;    /* default */
-    sa.bInheritHandle = TRUE;
+    sa.bInheritHandle = true;
     if (!CreatePipe(&us_from_cmd, &cmd_to_us, &sa, 0)) {
         sfree(cmd);
 	return new_error_socket_fmt(
@@ -91,7 +88,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
     si.hStdInput = cmd_from_us;
     si.hStdOutput = cmd_to_us;
     si.hStdError = cmd_err_to_us;
-    CreateProcess(NULL, cmd, NULL, NULL, TRUE,
+    CreateProcess(NULL, cmd, NULL, NULL, true,
 		  CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS,
 		  NULL, NULL, &si, &pi);
     CloseHandle(pi.hProcess);
@@ -106,5 +103,5 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
         CloseHandle(cmd_err_to_us);
 
     return make_handle_socket(us_to_cmd, us_from_cmd, us_from_cmd_err,
-                              plug, FALSE);
+                              plug, false);
 }

+ 58 - 100
source/putty/windows/winstore.c

@@ -22,58 +22,11 @@ static const char *const reg_jumplist_key = PUTTY_REG_POS "\\Jumplist";
 static const char *const reg_jumplist_value = "Recent sessions";
 static const char *const puttystr = PUTTY_REG_POS "\\Sessions";
 
-static const char hex[16] = "0123456789ABCDEF";
-
-static int tried_shgetfolderpath = FALSE;
+static bool tried_shgetfolderpath = false;
 static HMODULE shell32_module = NULL;
 DECL_WINDOWS_FUNCTION(static, HRESULT, SHGetFolderPathA, 
 		      (HWND, int, HANDLE, DWORD, LPSTR));
 
-static void mungestr(const char *in, char *out)
-{
-    int candot = 0;
-
-    while (*in) {
-	if (*in == ' ' || *in == '\\' || *in == '*' || *in == '?' ||
-	    *in == '%' || *in < ' ' || *in > '~' || (*in == '.'
-						     && !candot)) {
-	    *out++ = '%';
-	    *out++ = hex[((unsigned char) *in) >> 4];
-	    *out++ = hex[((unsigned char) *in) & 15];
-	} else
-	    *out++ = *in;
-	in++;
-	candot = 1;
-    }
-    *out = '\0';
-    return;
-}
-
-static void unmungestr(const char *in, char *out, int outlen)
-{
-    while (*in) {
-	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);
-
-	    *out++ = (i << 4) + j;
-	    if (!--outlen)
-		return;
-	    in += 3;
-	} else {
-	    *out++ = *in++;
-	    if (!--outlen)
-		return;
-	}
-    }
-    *out = '\0';
-    return;
-}
-
 struct settings_w {
     HKEY sesskey;
 };
@@ -82,32 +35,32 @@ settings_w *open_settings_w(const char *sessionname, char **errmsg)
 {
     HKEY subkey1, sesskey;
     int ret;
-    char *p;
+    strbuf *sb;
 
     *errmsg = NULL;
 
     if (!sessionname || !*sessionname)
 	sessionname = "Default Settings";
 
-    p = snewn(3 * strlen(sessionname) + 1, char);
-    mungestr(sessionname, p);
+    sb = strbuf_new();
+    escape_registry_key(sessionname, sb);
 
     ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);
     if (ret != ERROR_SUCCESS) {
-	sfree(p);
+	strbuf_free(sb);
         *errmsg = dupprintf("Unable to create registry key\n"
                             "HKEY_CURRENT_USER\\%s", puttystr);
 	return NULL;
     }
-    ret = RegCreateKey(subkey1, p, &sesskey);
+    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, p);
-	sfree(p);
+                            "HKEY_CURRENT_USER\\%s\\%s", puttystr, sb->s);
+	strbuf_free(sb);
 	return NULL;
     }
-    sfree(p);
+    strbuf_free(sb);
 
     settings_w *toret = snew(settings_w);
     toret->sesskey = sesskey;
@@ -141,24 +94,24 @@ struct settings_r {
 settings_r *open_settings_r(const char *sessionname)
 {
     HKEY subkey1, sesskey;
-    char *p;
+    strbuf *sb;
 
     if (!sessionname || !*sessionname)
 	sessionname = "Default Settings";
 
-    p = snewn(3 * strlen(sessionname) + 1, char);
-    mungestr(sessionname, p);
+    sb = strbuf_new();
+    escape_registry_key(sessionname, sb);
 
     if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS) {
 	sesskey = NULL;
     } else {
-	if (RegOpenKey(subkey1, p, &sesskey) != ERROR_SUCCESS) {
+	if (RegOpenKey(subkey1, sb->s, &sesskey) != ERROR_SUCCESS) {
 	    sesskey = NULL;
 	}
 	RegCloseKey(subkey1);
     }
 
-    sfree(p);
+    strbuf_free(sb);
 
     settings_r *toret = snew(settings_r);
     toret->sesskey = sesskey;
@@ -291,15 +244,15 @@ void close_settings_r(settings_r *handle)
 void del_settings(const char *sessionname)
 {
     HKEY subkey1;
-    char *p;
+    strbuf *sb;
 
     if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS)
 	return;
 
-    p = snewn(3 * strlen(sessionname) + 1, char);
-    mungestr(sessionname, p);
-    RegDeleteKey(subkey1, p);
-    sfree(p);
+    sb = strbuf_new();
+    escape_registry_key(sessionname, sb);
+    RegDeleteKey(subkey1, sb->s);
+    strbuf_free(sb);
 
     RegCloseKey(subkey1);
 
@@ -328,18 +281,27 @@ settings_e *enum_settings_start(void)
     return ret;
 }
 
-char *enum_settings_next(settings_e *e, char *buffer, int buflen)
+bool enum_settings_next(settings_e *e, strbuf *sb)
 {
-    char *otherbuf;
-    otherbuf = snewn(3 * buflen, char);
-    if (RegEnumKey(e->key, e->i++, otherbuf, 3 * buflen) == ERROR_SUCCESS) {
-	unmungestr(otherbuf, buffer, buflen);
-	sfree(otherbuf);
-	return buffer;
-    } else {
-	sfree(otherbuf);
-	return NULL;
+    size_t regbuf_size = 256;
+    char *regbuf = snewn(regbuf_size, char);
+    bool success;
+
+    while (1) {
+        DWORD retd = RegEnumKey(e->key, e->i++, regbuf, regbuf_size);
+        if (retd != ERROR_MORE_DATA) {
+            success = (retd == ERROR_SUCCESS);
+            break;
+        }
+        regbuf_size = regbuf_size * 5 / 4 + 256;
+        regbuf = sresize(regbuf, regbuf_size, char);
     }
+
+    if (success)
+        unescape_registry_key(regbuf, sb);
+
+    sfree(regbuf);
+    return success;
 }
 
 void enum_settings_finish(settings_e *e)
@@ -348,21 +310,18 @@ void enum_settings_finish(settings_e *e)
     sfree(e);
 }
 
-static void hostkey_regname(char *buffer, const char *hostname,
+static void hostkey_regname(strbuf *sb, const char *hostname,
 			    int port, const char *keytype)
 {
-    int len;
-    strcpy(buffer, keytype);
-    strcat(buffer, "@");
-    len = strlen(buffer);
-    len += sprintf(buffer + len, "%d:", port);
-    mungestr(hostname, buffer + strlen(buffer));
+    strbuf_catf(sb, "%s@%d:", keytype, port);
+    escape_registry_key(hostname, sb);
 }
 
 int verify_host_key(const char *hostname, int port,
 		    const char *keytype, const char *key)
 {
-    char *otherstr, *regname;
+    char *otherstr;
+    strbuf *regname;
     int len;
     HKEY rkey;
     DWORD readlen;
@@ -375,19 +334,18 @@ int verify_host_key(const char *hostname, int port,
      * Now read a saved key in from the registry and see what it
      * says.
      */
-    regname = snewn(3 * (strlen(hostname) + strlen(keytype)) + 15, char);
-
+    regname = strbuf_new();
     hostkey_regname(regname, hostname, port, keytype);
 
     if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys",
 		   &rkey) != ERROR_SUCCESS) {
-        sfree(regname);
+        strbuf_free(regname);
 	return 1;		       /* key does not exist in registry */
     }
 
     readlen = len;
     otherstr = snewn(len, char);
-    ret = RegQueryValueEx(rkey, regname, NULL,
+    ret = RegQueryValueEx(rkey, regname->s, NULL,
                           &type, (BYTE *)otherstr, &readlen);
 
     if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA &&
@@ -397,7 +355,7 @@ int verify_host_key(const char *hostname, int port,
 	 * another trick, which is to look up the _old_ key format
 	 * under just the hostname and translate that.
 	 */
-	char *justhost = regname + 1 + strcspn(regname, ":");
+	char *justhost = regname->s + 1 + strcspn(regname->s, ":");
 	char *oldstyle = snewn(len + 10, char);	/* safety margin */
 	readlen = len;
 	ret = RegQueryValueEx(rkey, justhost, NULL, &type,
@@ -447,7 +405,7 @@ int verify_host_key(const char *hostname, int port,
 	     * wrong, and hyper-cautiously do nothing.
 	     */
 	    if (!strcmp(otherstr, key))
-		RegSetValueEx(rkey, regname, 0, REG_SZ, (BYTE *)otherstr,
+		RegSetValueEx(rkey, regname->s, 0, REG_SZ, (BYTE *)otherstr,
 			      strlen(otherstr) + 1);
 	}
 
@@ -459,7 +417,7 @@ int verify_host_key(const char *hostname, int port,
     compare = strcmp(otherstr, key);
 
     sfree(otherstr);
-    sfree(regname);
+    strbuf_free(regname);
 
     if (ret == ERROR_MORE_DATA ||
 	(ret == ERROR_SUCCESS && type == REG_SZ && compare))
@@ -470,7 +428,7 @@ int verify_host_key(const char *hostname, int port,
 	return 0;		       /* key matched OK in registry */
 }
 
-int have_ssh_host_key(const char *hostname, int port,
+bool have_ssh_host_key(const char *hostname, int port,
 		      const char *keytype)
 {
     /*
@@ -483,27 +441,27 @@ int have_ssh_host_key(const char *hostname, int port,
 void store_host_key(const char *hostname, int port,
 		    const char *keytype, const char *key)
 {
-    char *regname;
+    strbuf *regname;
     HKEY rkey;
 
-    regname = snewn(3 * (strlen(hostname) + strlen(keytype)) + 15, char);
-
+    regname = strbuf_new();
     hostkey_regname(regname, hostname, port, keytype);
 
     if (RegCreateKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys",
 		     &rkey) == ERROR_SUCCESS) {
-	RegSetValueEx(rkey, regname, 0, REG_SZ, (BYTE *)key, strlen(key) + 1);
+	RegSetValueEx(rkey, regname->s, 0, REG_SZ,
+                      (BYTE *)key, strlen(key) + 1);
 	RegCloseKey(rkey);
     } /* else key does not exist in registry */
 
-    sfree(regname);
+    strbuf_free(regname);
 }
 
 /*
  * Open (or delete) the random seed file.
  */
 enum { DEL, OPEN_R, OPEN_W };
-static int try_random_seed(char const *path, int action, HANDLE *ret)
+static bool try_random_seed(char const *path, int action, HANDLE *ret)
 {
     if (action == DEL) {
         if (!DeleteFile(path) && GetLastError() != ERROR_FILE_NOT_FOUND) {
@@ -511,7 +469,7 @@ static int try_random_seed(char const *path, int action, HANDLE *ret)
                      win_strerror(GetLastError()));
         }
 	*ret = INVALID_HANDLE_VALUE;
-	return FALSE;		       /* so we'll do the next ones too */
+	return false;		       /* so we'll do the next ones too */
     }
 
     *ret = CreateFile(path,
@@ -576,7 +534,7 @@ static HANDLE access_random_seed(int action)
 	 * so stuff that. */
 	shell32_module = load_system32_dll("shell32.dll");
 	GET_WINDOWS_FUNCTION(shell32_module, SHGetFolderPathA);
-	tried_shgetfolderpath = TRUE;
+	tried_shgetfolderpath = true;
     }
     if (p_SHGetFolderPathA) {
 	if (SUCCEEDED(p_SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA,

+ 68 - 33
source/putty/windows/winstuff.h

@@ -44,12 +44,12 @@ struct Filename {
 
 struct FontSpec {
     char *name;
-    int isbold;
+    bool isbold;
     int height;
     int charset;
 };
-struct FontSpec *fontspec_new(const char *name,
-                               int bold, int height, int charset);
+struct FontSpec *fontspec_new(
+    const char *name, bool bold, int height, int charset);
 
 #ifndef CLEARTYPE_QUALITY
 #define CLEARTYPE_QUALITY 5
@@ -228,20 +228,23 @@ GLOBAL HINSTANCE hinst;
  */
 void init_help(void);
 void shutdown_help(void);
-int has_help(void);
+bool has_help(void);
 void launch_help(HWND hwnd, const char *topic);
 void quit_help(HWND hwnd);
 
 /*
  * The terminal and logging context are notionally local to the
  * Windows front end, but they must be shared between window.c and
- * windlg.c. Likewise the Seat structure for the Windows GUI.
+ * windlg.c. Likewise the Seat structure for the Windows GUI, and the
+ * Conf for the main session..
  */
 GLOBAL Terminal *term;
 GLOBAL LogContext *logctx;
+GLOBAL Conf *conf;
 
 /*
- * GUI seat methods in windlg.c.
+ * GUI seat methods in windlg.c, so that the vtable definition in
+ * window.c can refer to them.
  */
 int win_seat_verify_ssh_host_key(
     Seat *seat, const char *host, int port,
@@ -254,12 +257,18 @@ int win_seat_confirm_weak_cached_hostkey(
     Seat *seat, const char *algname, const char *betteralgs,
     void (*callback)(void *ctx, int result), void *ctx);
 
+/*
+ * The Windows GUI seat object itself, so that its methods can be
+ * called outside window.c.
+ */
+extern Seat *const win_seat;
+
 /*
  * Windows-specific clipboard helper function shared with windlg.c,
  * which takes the data string in the system code page instead of
  * Unicode.
  */
-void write_aclip(int clipboard, char *, int, int);
+void write_aclip(int clipboard, char *, int, bool);
 
 #define WM_NETEVENT  (WM_APP + 5)
 
@@ -303,7 +312,17 @@ void write_aclip(int clipboard, char *, int, int);
 /*
  * Exports from winnet.c.
  */
-extern void select_result(WPARAM, LPARAM);
+/* Report an event notification from WSA*Select */
+void select_result(WPARAM, LPARAM);
+/* Enumerate all currently live OS-level SOCKETs */
+SOCKET first_socket(int *);
+SOCKET next_socket(int *);
+/* Ask winnet.c whether we currently want to try to write to a SOCKET */
+bool socket_writable(SOCKET skt);
+/* Force a refresh of the SOCKET list by re-calling do_select for each one */
+void socket_reselect_all(void);
+/* Make a SockAddr which just holds a named pipe address. */
+SockAddr *sk_namedpipe_addr(const char *pipename);
 
 /*
  * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
@@ -331,9 +350,19 @@ DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
 		       fd_set FAR *, const struct timeval FAR *));
 #endif
 
-extern int socket_writable(SOCKET skt);
+/*
+ * Provided by each client of winnet.c, and called by winnet.c to turn
+ * on or off WSA*Select for a given socket.
+ */
+char *do_select(SOCKET skt, bool startup);
 
-extern void socket_reselect_all(void);
+/*
+ * Network-subsystem-related functions provided in other Windows modules.
+ */
+Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
+                           Plug *plug, bool overlapped); /* winhsock */
+Socket *new_named_pipe_client(const char *pipename, Plug *plug); /* winnpc */
+Socket *new_named_pipe_listener(const char *pipename, Plug *plug); /* winnps */
 
 /*
  * Exports from winctrls.c.
@@ -354,7 +383,7 @@ void init_common_controls(void);       /* also does some DLL-loading */
  * Exports from winutils.c.
  */
 typedef struct filereq_tag filereq; /* cwd for file requester */
-BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
+bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save);
 filereq *filereq_new(void);
 void filereq_free(filereq *state);
 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
@@ -369,7 +398,7 @@ struct prefslist {
     int listid, upbid, dnbid;
     int srcitem;
     int dummyitem;
-    int dragging;
+    bool dragging;
 };
 
 /*
@@ -384,13 +413,17 @@ struct dlgparam {
     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 */
-    char shortcuts[128];	       /* track which shortcuts in use */
-    int coloursel_wanted;	       /* has an event handler asked for
+    bool shortcuts[128];               /* track which shortcuts in use */
+    bool coloursel_wanted;             /* has an event handler asked for
 					* a colour selector? */
-    struct { unsigned char r, g, b, ok; } coloursel_result;   /* 0-255 */
+    struct {
+        unsigned char r, g, b;         /* 0-255 */
+        bool ok;
+    } coloursel_result;
     tree234 *privdata;		       /* stores per-control private data */
-    int ended, endresult;	       /* has the dialog been ended? */
-    int fixed_pitch_fonts;             /* are we constrained to fixed fonts? */
+    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? */
 };
 
 /*
@@ -403,7 +436,7 @@ HWND doctl(struct ctlpos *cp, RECT r,
 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, int password, char *text,
+void editboxfw(struct ctlpos *cp, bool password, char *text,
 	       int staticid, int editid);
 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
 void bareradioline(struct ctlpos *cp, int nacross, ...);
@@ -440,7 +473,7 @@ void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
 	       char *stext, int sid, int listid, int upbid, int dnbid);
 int handle_prefslist(struct prefslist *hdl,
 		     int *array, int maxmemb,
-		     int is_dlmsg, HWND hwnd,
+		     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,
@@ -450,8 +483,8 @@ void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
 	       char *r1text, int r1id, char *r2text, int r2id);
 
 void dlg_auto_set_fixed_pitch_flag(dlgparam *dlg);
-int dlg_get_fixed_pitch_flag(dlgparam *dlg);
-void dlg_set_fixed_pitch_flag(dlgparam *dlg, int flag);
+bool dlg_get_fixed_pitch_flag(dlgparam *dlg);
+void dlg_set_fixed_pitch_flag(dlgparam *dlg, bool flag);
 
 #define MAX_SHORTCUTS_PER_CTRL 16
 
@@ -503,10 +536,10 @@ 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);
-int winctrl_handle_command(struct dlgparam *dp, UINT msg,
-			   WPARAM wParam, LPARAM lParam);
+bool winctrl_handle_command(struct dlgparam *dp, UINT msg,
+                            WPARAM wParam, LPARAM lParam);
 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
-int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
+bool winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
 
 void dp_init(struct dlgparam *dp);
 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
@@ -515,15 +548,15 @@ void dp_cleanup(struct dlgparam *dp);
 /*
  * Exports from wincfg.c.
  */
-void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
-			  int midsession, int protocol);
+void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help,
+			  bool midsession, int protocol);
 
 /*
  * Exports from windlg.c.
  */
 void defuse_showwindow(void);
-int do_config(void);
-int do_reconfig(HWND, int);
+bool do_config(void);
+bool do_reconfig(HWND, int);
 void showeventlog(HWND);
 void showabout(HWND);
 void force_normal(HWND hwnd);
@@ -539,7 +572,9 @@ void dll_hijacking_protection(void);
 HMODULE load_system32_dll(const char *libname);
 const char *win_strerror(int error);
 void restrict_process_acl(void);
-GLOBAL int restricted_acl;
+GLOBAL bool restricted_acl;
+void escape_registry_key(const char *in, strbuf *out);
+void unescape_registry_key(const char *in, strbuf *out);
 
 /* A few pieces of up-to-date Windows API definition needed for older
  * compilers. */
@@ -561,7 +596,7 @@ DECLSPEC_IMPORT DLL_DIRECTORY_COOKIE WINAPI AddDllDirectory (PCWSTR NewDirectory
  * Exports from sizetip.c.
  */
 void UpdateSizeTip(HWND src, int cx, int cy);
-void EnableSizeTip(int bEnable);
+void EnableSizeTip(bool bEnable);
 
 /*
  * Exports from unicode.c.
@@ -617,12 +652,12 @@ extern const struct BackendVtable serial_backend;
 void add_session_to_jumplist(const char * const sessionname);
 void remove_session_from_jumplist(const char * const sessionname);
 void clear_jumplist(void);
-BOOL set_explicit_app_user_model_id();
+bool set_explicit_app_user_model_id(void);
 
 /*
  * Exports from winnoise.c.
  */
-int win_read_random(void *buf, unsigned wanted); /* returns TRUE on success */
+bool win_read_random(void *buf, unsigned wanted); /* returns true on success */
 
 /*
  * Extra functions in winstore.c over and above the interface in
@@ -654,7 +689,7 @@ char *get_jumplist_registry_entries(void);
 #define CLIPNAME_EXPLICIT "System clipboard"
 #define CLIPNAME_EXPLICIT_OBJECT "system clipboard"
 /* These defaults are the ones PuTTY has historically had */
-#define CLIPUI_DEFAULT_AUTOCOPY TRUE
+#define CLIPUI_DEFAULT_AUTOCOPY true
 #define CLIPUI_DEFAULT_MOUSE CLIPUI_EXPLICIT
 #define CLIPUI_DEFAULT_INS CLIPUI_EXPLICIT
 

+ 34 - 31
source/putty/x11fwd.c

@@ -34,9 +34,9 @@ typedef struct X11Connection {
     char *auth_protocol;
     unsigned char *auth_data;
     int data_read, auth_plen, auth_psize, auth_dlen, auth_dsize;
-    int verified;
-    int input_wanted;
-    int no_data_sent_to_x_client;
+    bool verified;
+    bool input_wanted;
+    bool no_data_sent_to_x_client;
     char *peer_addr;
     int peer_port;
     SshChannel *c;               /* channel structure held by SSH backend */
@@ -209,7 +209,7 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf,
      */
     if (localcopy[0] == '/') {
 	disp->unixsocketpath = localcopy;
-	disp->unixdomain = TRUE;
+	disp->unixdomain = true;
 	disp->hostname = NULL;
 	disp->displaynum = -1;
 	disp->screennum = 0;
@@ -258,7 +258,7 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf,
 	else if (!*hostname || !strcmp(hostname, "unix"))
 	    disp->unixdomain = platform_uses_x11_unix_by_default;
 	else
-	    disp->unixdomain = FALSE;
+	    disp->unixdomain = false;
 
 	if (!disp->hostname && !disp->unixdomain)
 	    disp->hostname = dupstr("localhost");
@@ -302,7 +302,8 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf,
 	if (!err) {
 	    /* Create trial connection to see if there is a useful Unix-domain
 	     * socket */
-	    Socket *s = sk_new(sk_addr_dup(ux), 0, 0, 0, 0, 0, nullplug);
+	    Socket *s = sk_new(sk_addr_dup(ux), 0, false, false,
+                               false, false, nullplug);
 	    err = sk_socket_error(s);
 	    sk_close(s);
 	}
@@ -310,7 +311,7 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf,
 	    sk_addr_free(ux);
 	} else {
 	    sk_addr_free(disp->addr);
-	    disp->unixdomain = TRUE;
+	    disp->unixdomain = true;
 	    disp->addr = ux;
 	    /* Fill in the rest in a moment */
 	}
@@ -469,7 +470,7 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
     ptrlen addr, protoname, data;
     char *displaynum_string;
     int displaynum;
-    int ideal_match = FALSE;
+    bool ideal_match = false;
     char *ourhostname;
 
     /* A maximally sized (wildly implausible) .Xauthority record
@@ -502,7 +503,7 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
      * that is; so if we can't find a Unix-domain-socket entry we'll
      * fall back to an IP-based entry if we can find one.
      */
-    int localhost = !disp->unixdomain && sk_address_is_local(disp->addr);
+    bool localhost = !disp->unixdomain && sk_address_is_local(disp->addr);
 
     authfp = fopen(authfilename, "rb");
     if (!authfp)
@@ -527,7 +528,7 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
     BinarySource_BARE_INIT(src, buf, size);
 
     while (!ideal_match) {
-        int match = FALSE;
+        bool match = false;
 
         if (src->pos >= MAX_RECORD_SIZE) {
             size -= src->pos;
@@ -597,7 +598,7 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
 		char buf[4];
 		sk_addrcopy(disp->addr, buf);
 		if (addr.len == 4 && !memcmp(addr.ptr, buf, 4)) {
-		    match = TRUE;
+		    match = true;
 		    /* If this is a "localhost" entry, note it down
 		     * but carry on looking for a Unix-domain entry. */
 		    ideal_match = !localhost;
@@ -610,17 +611,19 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
 		char buf[16];
 		sk_addrcopy(disp->addr, buf);
 		if (addr.len == 16 && !memcmp(addr.ptr, buf, 16)) {
-		    match = TRUE;
+		    match = true;
 		    ideal_match = !localhost;
 		}
 	    }
 	    break;
 	  case 256: /* Unix-domain / localhost */
 	    if ((disp->unixdomain || localhost)
-                && ourhostname && ptrlen_eq_string(addr, ourhostname))
+                && ourhostname && ptrlen_eq_string(addr, ourhostname)) {
 		/* A matching Unix-domain socket is always the best
 		 * match. */
-		match = ideal_match = TRUE;
+		match = true;
+                ideal_match = true;
+            }
 	    break;
 	}
 
@@ -660,7 +663,7 @@ void x11_format_auth_for_authfile(
         put_uint16(bs, 6); /* indicates IPv6 */
         put_stringpl_xauth(bs, make_ptrlen(ipv6buf, 16));
     } else {
-        assert(FALSE && "Bad address type in x11_format_auth_for_authfile");
+        assert(false && "Bad address type in x11_format_auth_for_authfile");
     }
 
     {
@@ -683,7 +686,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,
-			int calling_back)
+			bool calling_back)
 {
     struct X11Connection *xconn = container_of(
         plug, struct X11Connection, plug);
@@ -720,7 +723,7 @@ static void x11_receive(Plug *plug, int urgent, char *data, int len)
     struct X11Connection *xconn = container_of(
         plug, struct X11Connection, plug);
 
-    xconn->no_data_sent_to_x_client = FALSE;
+    xconn->no_data_sent_to_x_client = false;
     sshfwd_write(xconn->c, data, len);
 }
 
@@ -759,9 +762,9 @@ static const PlugVtable X11Connection_plugvt = {
 };
 
 static void x11_chan_free(Channel *chan);
-static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len);
+static int x11_send(Channel *chan, bool is_stderr, const void *vdata, int len);
 static void x11_send_eof(Channel *chan);
-static void x11_set_input_wanted(Channel *chan, int wanted);
+static void x11_set_input_wanted(Channel *chan, bool wanted);
 static char *x11_log_close_msg(Channel *chan);
 
 static const struct ChannelVtable X11Connection_channelvt = {
@@ -795,7 +798,7 @@ static const struct ChannelVtable X11Connection_channelvt = {
  */
 Channel *x11_new_channel(tree234 *authtree, SshChannel *c,
                          const char *peeraddr, int peerport,
-                         int connection_sharing_possible)
+                         bool connection_sharing_possible)
 {
     struct X11Connection *xconn;
 
@@ -809,10 +812,10 @@ Channel *x11_new_channel(tree234 *authtree, SshChannel *c,
         (connection_sharing_possible ? 128 : 0);
     xconn->auth_protocol = NULL;
     xconn->authtree = authtree;
-    xconn->verified = 0;
+    xconn->verified = false;
     xconn->data_read = 0;
-    xconn->input_wanted = TRUE;
-    xconn->no_data_sent_to_x_client = TRUE;
+    xconn->input_wanted = true;
+    xconn->no_data_sent_to_x_client = true;
     xconn->c = c;
 
     /*
@@ -852,7 +855,7 @@ static void x11_chan_free(Channel *chan)
     sfree(xconn);
 }
 
-static void x11_set_input_wanted(Channel *chan, int wanted)
+static void x11_set_input_wanted(Channel *chan, bool wanted)
 {
     assert(chan->vt == &X11Connection_channelvt);
     X11Connection *xconn = container_of(chan, X11Connection, chan);
@@ -882,12 +885,12 @@ static void x11_send_init_error(struct X11Connection *xconn,
     memcpy(reply + 8, full_message, msglen);
     sshfwd_write(xconn->c, reply, 8 + msgsize);
     sshfwd_write_eof(xconn->c);
-    xconn->no_data_sent_to_x_client = FALSE;
+    xconn->no_data_sent_to_x_client = false;
     sfree(reply);
     sfree(full_message);
 }
 
-static int x11_parse_ip(const char *addr_string, unsigned long *ip)
+static bool x11_parse_ip(const char *addr_string, unsigned long *ip)
 {
 
     /*
@@ -898,16 +901,16 @@ static int x11_parse_ip(const char *addr_string, unsigned long *ip)
     if (addr_string &&
         4 == sscanf(addr_string, "%d.%d.%d.%d", i+0, i+1, i+2, i+3)) {
         *ip = (i[0] << 24) | (i[1] << 16) | (i[2] << 8) | i[3];
-        return TRUE;
+        return true;
     } else {
-        return FALSE;
+        return false;
     }
 }
 
 /*
  * Called to send data down the raw connection.
  */
-static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len)
+static int x11_send(Channel *chan, bool is_stderr, const void *vdata, int len)
 {
     assert(chan->vt == &X11Connection_channelvt);
     X11Connection *xconn = container_of(chan, X11Connection, chan);
@@ -1010,7 +1013,7 @@ static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len)
         xconn->disp = auth_matched->disp;
         xconn->s = new_connection(sk_addr_dup(xconn->disp->addr),
                                   xconn->disp->realhost, xconn->disp->port, 
-                                  0, 1, 0, 0, &xconn->plug,
+                                  false, true, false, false, &xconn->plug,
                                   sshfwd_get_conf(xconn->c));
         if ((err = sk_socket_error(xconn->s)) != NULL) {
             char *err_message = dupprintf("unable to connect to"
@@ -1051,7 +1054,7 @@ static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len)
         /*
          * Now we're done.
          */
-	xconn->verified = 1;
+	xconn->verified = true;
     }
 
     /*