Skip to content
Snippets Groups Projects
  1. Feb 13, 2021
  2. Mar 10, 2020
    • Simon Tatham's avatar
      Change vtable defs to use C99 designated initialisers. · b4e1bca2
      Simon Tatham authored
      This is a sweeping change applied across the whole code base by a spot
      of Emacs Lisp. Now, everywhere I declare a vtable filled with function
      pointers (and the occasional const data member), all the members of
      the vtable structure are initialised by name using the '.fieldname =
      value' syntax introduced in C99.
      
      We were already using this syntax for a handful of things in the new
      key-generation progress report system, so it's not new to the code
      base as a whole.
      
      The advantage is that now, when a vtable only declares a subset of the
      available fields, I can initialise the rest to NULL or zero just by
      leaving them out. This is most dramatic in a couple of the outlying
      vtables in things like psocks (which has a ConnectionLayerVtable
      containing only one non-NULL method), but less dramatically, it means
      that the new 'flags' field in BackendVtable can be completely left out
      of every backend definition except for the SUPDUP one which defines it
      to a nonzero value. Similarly, the test_for_upstream method only used
      by SSH doesn't have to be mentioned in the rest of the backends;
      network Plugs for listening sockets don't have to explicitly null out
      'receive' and 'sent', and vice versa for 'accepting', and so on.
      
      While I'm at it, I've normalised the declarations so they don't use
      the unnecessarily verbose 'struct' keyword. Also a handful of them
      weren't const; now they are.
      b4e1bca2
  3. Feb 16, 2020
    • Simon Tatham's avatar
      Formatting change to braces around one case of a switch. · 8d186c3c
      Simon Tatham authored
      Sometimes, within a switch statement, you want to declare local
      variables specific to the handler for one particular case. Until now
      I've mostly been writing this in the form
      
          switch (discriminant) {
            case SIMPLE:
              do stuff;
              break;
            case COMPLICATED:
              {
                  declare variables;
                  do stuff;
              }
              break;
          }
      
      which is ugly because the two pieces of essentially similar code
      appear at different indent levels, and also inconvenient because you
      have less horizontal space available to write the complicated case
      handler in - particuarly undesirable because _complicated_ case
      handlers are the ones most likely to need all the space they can get!
      
      After encountering a rather nicer idiom in the LLVM source code, and
      after a bit of hackery this morning figuring out how to persuade
      Emacs's auto-indent to do what I wanted with it, I've decided to move
      to an idiom in which the open brace comes right after the case
      statement, and the code within it is indented the same as it would
      have been without the brace. Then the whole case handler (including
      the break) lives inside those braces, and you get something that looks
      more like this:
      
          switch (discriminant) {
            case SIMPLE:
              do stuff;
              break;
            case COMPLICATED: {
              declare variables;
              do stuff;
              break;
            }
          }
      
      This commit is a big-bang change that reformats all the complicated
      case handlers I could find into the new layout. This is particularly
      nice in the Pageant main function, in which almost _every_ case
      handler had a bundle of variables and was long and complicated. (In
      fact that's what motivated me to get round to this.) Some of the
      innermost parts of the terminal escape-sequence handling are also
      breathing a bit easier now the horizontal pressure on them is
      relieved.
      
      (Also, in a few cases, I was able to remove the extra braces
      completely, because the only variable local to the case handler was a
      loop variable which our new C99 policy allows me to move into the
      initialiser clause of its for statement.)
      
      Viewed with whitespace ignored, this is not too disruptive a change.
      Downstream patches that conflict with it may need to be reapplied
      using --ignore-whitespace or similar.
      8d186c3c
  4. Feb 12, 2020
  5. Feb 07, 2020
  6. Oct 01, 2019
    • Simon Tatham's avatar
      Fix handling of string-typed address from SOCKS5 server. · 283bd541
      Simon Tatham authored
      In the variable-length address slot, the main SOCKS5 reply packet can
      contain a binary IP address (4- or 16-byte for v4/v6 respectively), or
      a string intended to be interpreted as a domain name.
      
      I was trying out the Python SOCKS5 proxy 'pproxy' today, which sends a
      string-typed reply if you send it a string-typed domain name to
      connect to. This caused me to notice that PuTTY mishandles the latter
      case, by failing to account for the prefix length byte of that string
      when computing the total size of the reply packet. So we would
      misinterpret the final byte of its reply packet as the initial byte of
      the actual connection, causing us to fail to recognise the SSH greeting.
      283bd541
  7. Sep 08, 2019
    • Simon Tatham's avatar
      Whitespace rationalisation of entire code base. · 5d718ef6
      Simon Tatham authored
      The number of people has been steadily increasing who read our source
      code with an editor that thinks tab stops are 4 spaces apart, as
      opposed to the traditional tty-derived 8 that the PuTTY code expects.
      
      So I've been wondering for ages about just fixing it, and switching to
      a spaces-only policy throughout the code. And I recently found out
      about 'git blame -w', which should make this change not too disruptive
      for the purposes of source-control archaeology; so perhaps now is the
      time.
      
      While I'm at it, I've also taken the opportunity to remove all the
      trailing spaces from source lines (on the basis that git dislikes
      them, and is the only thing that seems to have a strong opinion one
      way or the other).
          
      Apologies to anyone downstream of this code who has complicated patch
      sets to rebase past this change. I don't intend it to be needed again.
      5d718ef6
  8. Jul 28, 2019
    • Simon Tatham's avatar
      Make proxy_for_destination() static. · 7663e555
      Simon Tatham authored
      It's never used outside proxy.c, so there's no need to expose its
      declaration in proxy.h.
      7663e555
    • Simon Tatham's avatar
      Completely remove sk_flush(). · 9545199e
      Simon Tatham authored
      I've only just noticed that it doesn't do anything at all!
      
      Almost every implementation of the Socket vtable provides a flush()
      method which does nothing, optionally with a comment explaining why
      it's OK to do nothing. The sole exception is the wrapper Proxy_Socket,
      which implements the method during its setup phase by setting a
      pending_flush flag, so that when its sub-socket is later created, it
      can call sk_flush on that. But since the sub-socket's sk_flush will do
      nothing, even that is completely pointless!
      
      Source control history says that sk_flush was introduced by Dave
      Hinton in 2001 (commit 7b0e0827), who was going to use it for some
      purpose involving the SSL Telnet support he was working on at the
      time. That SSL support was never finished, and its vestigial
      declarations in network.h were removed in 2015 (commit 42334b65). So
      sk_flush is just another vestige of that abandoned work, which I
      should have removed in the latter commit but overlooked.
      9545199e
  9. Mar 02, 2019
  10. Feb 06, 2019
    • Simon Tatham's avatar
      Make bufchain_prefix return a ptrlen. · 59f7b24b
      Simon Tatham authored
      Now that all the call sites are expecting a size_t instead of an int
      length field, it's no longer particularly difficult to make it
      actually return the pointer,length pair in the form of a ptrlen.
      
      It would be nice to say that simplifies call sites because those
      ptrlens can all be passed straight along to other ptrlen-consuming
      functions. Actually almost none of the call sites are like that _yet_,
      but this makes it possible to move them in that direction in future
      (as part of my general aim to migrate ptrlen-wards as much as I can).
      But also it's just nicer to keep the pointer and length together in
      one variable, and not have to declare them both in advance with two
      extra lines of boilerplate.
      59f7b24b
    • Simon Tatham's avatar
      Make lots of 'int' length fields into size_t. · 0cda34c6
      Simon Tatham authored
      This is a general cleanup which has been overdue for some time: lots
      of length fields are now the machine word type rather than the (in
      practice) fixed 'int'.
      0cda34c6
    • Simon Tatham's avatar
      Remove ProxySocket's sent_bufsize field. · a742abae
      Simon Tatham authored
      I just spotted that it was set once and never read.
      a742abae
    • Simon Tatham's avatar
      Add some missing 'const'. · 0aa8cf7b
      Simon Tatham authored
      plug_receive(), sftp_senddata() and handle_gotdata() in particular now
      take const pointers. Also fixed 'char *receive_data' in struct
      ProxySocket.
      0aa8cf7b
    • Simon Tatham's avatar
      proxy.c: make get_line_end return a bool. · eb16dee2
      Simon Tatham authored
      Now the integer output value is never negative (because the condition
      that used to be signalled by setting it to -1 is now signalled by
      returning false from the actual function), which frees me to make it
      an unsigned type in an upcoming change.
      eb16dee2
  11. Dec 01, 2018
    • Simon Tatham's avatar
      Replace several ad-hoc string formatters with strbuf. · 4251d28f
      Simon Tatham authored
      uxnet.c's sk_namelookup and the sorting-key construction in
      pangofont_enum_fonts() were both using s[n]printf and strncpy into
      buffers that had no real need to be fixed-size; format_telnet_command
      and the GTK Event Log selection-data builder were doing their own
      sresize loops, but now we have strbuf they can just use that and save
      redoing the same work.
      4251d28f
  12. Nov 03, 2018
    • Simon Tatham's avatar
      Convert a lot of 'int' variables to 'bool'. · 3214563d
      Simon Tatham authored
      My normal habit these days, in new code, is to treat int and bool as
      _almost_ completely separate types. I'm still willing to use C's
      implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
      no need to spell it out as blob.len != 0), but generally, if a
      variable is going to be conceptually a boolean, I like to declare it
      bool and assign to it using 'true' or 'false' rather than 0 or 1.
      
      PuTTY is an exception, because it predates the C99 bool, and I've
      stuck to its existing coding style even when adding new code to it.
      But it's been annoying me more and more, so now that I've decided C99
      bool is an acceptable thing to require from our toolchain in the first
      place, here's a quite thorough trawl through the source doing
      'boolification'. Many variables and function parameters are now typed
      as bool rather than int; many assignments of 0 or 1 to those variables
      are now spelled 'true' or 'false'.
      
      I managed this thorough conversion with the help of a custom clang
      plugin that I wrote to trawl the AST and apply heuristics to point out
      where things might want changing. So I've even managed to do a decent
      job on parts of the code I haven't looked at in years!
      
      To make the plugin's work easier, I pushed platform front ends
      generally in the direction of using standard 'bool' in preference to
      platform-specific boolean types like Windows BOOL or GTK's gboolean;
      I've left the platform booleans in places they _have_ to be for the
      platform APIs to work right, but variables only used by my own code
      have been converted wherever I found them.
      
      In a few places there are int values that look very like booleans in
      _most_ of the places they're used, but have a rarely-used third value,
      or a distinction between different nonzero values that most users
      don't care about. In these cases, I've _removed_ uses of 'true' and
      'false' for the return values, to emphasise that there's something
      more subtle going on than a simple boolean answer:
       - the 'multisel' field in dialog.h's list box structure, for which
         the GTK front end in particular recognises a difference between 1
         and 2 but nearly everything else treats as boolean
       - the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
         something about the specific location of the urgent pointer, but
         most clients only care about 0 vs 'something nonzero'
       - the return value of wc_match, where -1 indicates a syntax error in
         the wildcard.
       - the return values from SSH-1 RSA-key loading functions, which use
         -1 for 'wrong passphrase' and 0 for all other failures (so any
         caller which already knows it's not loading an _encrypted private_
         key can treat them as boolean)
       - term->esc_query, and the 'query' parameter in toggle_mode in
         terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
         but can also hold -1 for some other intervening character that we
         don't support.
      
      In a few places there's an integer that I haven't turned into a bool
      even though it really _can_ only take values 0 or 1 (and, as above,
      tried to make the call sites consistent in not calling those values
      true and false), on the grounds that I thought it would make it more
      confusing to imply that the 0 value was in some sense 'negative' or
      bad and the 1 positive or good:
       - the return value of plug_accepting uses the POSIXish convention of
         0=success and nonzero=error; I think if I made it bool then I'd
         also want to reverse its sense, and that's a job for a separate
         piece of work.
       - the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
         represent the default and alternate screens. There's no obvious
         reason why one of those should be considered 'true' or 'positive'
         or 'success' - they're just indices - so I've left it as int.
      
      ssh_scp_recv had particularly confusing semantics for its previous int
      return value: its call sites used '<= 0' to check for error, but it
      never actually returned a negative number, just 0 or 1. Now the
      function and its call sites agree that it's a bool.
      
      In a couple of places I've renamed variables called 'ret', because I
      don't like that name any more - it's unclear whether it means the
      return value (in preparation) for the _containing_ function or the
      return value received from a subroutine call, and occasionally I've
      accidentally used the same variable for both and introduced a bug. So
      where one of those got in my way, I've renamed it to 'toret' or 'retd'
      (the latter short for 'returned') in line with my usual modern
      practice, but I haven't done a thorough job of finding all of them.
      
      Finally, one amusing side effect of doing this is that I've had to
      separate quite a few chained assignments. It used to be perfectly fine
      to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
      the 'true' defined by stdbool.h, that idiom provokes a warning from
      gcc: 'suggest parentheses around assignment used as truth value'!
      3214563d
    • Simon Tatham's avatar
      Switch some Conf settings over to being bool. · 1378bb04
      Simon Tatham authored
      I think this is the full set of things that ought logically to be
      boolean.
      
      One annoyance is that quite a few radio-button controls in config.c
      address Conf fields that are now bool rather than int, which means
      that the shared handler function can't just access them all with
      conf_{get,set}_int. Rather than back out the rigorous separation of
      int and bool in conf.c itself, I've just added a similar alternative
      handler function for the bool-typed ones.
      1378bb04
    • Simon Tatham's avatar
      Adopt C99 <stdbool.h>'s true/false. · a6f1709c
      Simon Tatham authored
      This commit includes <stdbool.h> from defs.h and deletes my
      traditional definitions of TRUE and FALSE, but other than that, it's a
      100% mechanical search-and-replace transforming all uses of TRUE and
      FALSE into the C99-standardised lowercase spellings.
      
      No actual types are changed in this commit; that will come next. This
      is just getting the noise out of the way, so that subsequent commits
      can have a higher proportion of signal.
      a6f1709c
  13. Oct 10, 2018
    • Simon Tatham's avatar
      Refactor the LogContext type. · ad0c502c
      Simon Tatham authored
      LogContext is now the owner of the logevent() function that back ends
      and so forth are constantly calling. Previously, logevent was owned by
      the Frontend, which would store the message into its list for the GUI
      Event Log dialog (or print it to standard error, or whatever) and then
      pass it _back_ to LogContext to write to the currently open log file.
      Now it's the other way round: LogContext gets the message from the
      back end first, writes it to its log file if it feels so inclined, and
      communicates it back to the front end.
      
      This means that lots of parts of the back end system no longer need to
      have a pointer to a full-on Frontend; the only thing they needed it
      for was logging, so now they just have a LogContext (which many of
      them had to have anyway, e.g. for logging SSH packets or session
      traffic).
      
      LogContext itself also doesn't get a full Frontend pointer any more:
      it now talks back to the front end via a little vtable of its own
      called LogPolicy, which contains the method that passes Event Log
      entries through, the old askappend() function that decides whether to
      truncate a pre-existing log file, and an emergency function for
      printing an especially prominent message if the log file can't be
      created. One minor nice effect of this is that console and GUI apps
      can implement that last function subtly differently, so that Unix
      console apps can write it with a plain \n instead of the \r\n
      (harmless but inelegant) that the old centralised implementation
      generated.
      
      One other consequence of this is that the LogContext has to be
      provided to backend_init() so that it's available to backends from the
      instant of creation, rather than being provided via a separate API
      call a couple of function calls later, because backends have typically
      started doing things that need logging (like making network
      connections) before the call to backend_provide_logctx. Fortunately,
      there's no case in the whole code base where we don't already have
      logctx by the time we make a backend (so I don't actually remember why
      I ever delayed providing one). So that shortens the backend API by one
      function, which is always nice.
      
      While I'm tidying up, I've also moved the printf-style logeventf() and
      the handy logevent_and_free() into logging.c, instead of having copies
      of them scattered around other places. This has also let me remove
      some stub functions from a couple of outlying applications like
      Pageant. Finally, I've removed the pointless "_tag" at the end of
      LogContext's official struct name.
      ad0c502c
  14. Oct 06, 2018
    • Simon Tatham's avatar
      Rename FROMFIELD to 'container_of'. · 9396fcc9
      Simon Tatham authored
      Ian Jackson points out that the Linux kernel has a macro of this name
      with the same purpose, and suggests that it's a good idea to use the
      same name as they do, so that at least some people reading one code
      base might recognise it from the other.
      
      I never really thought very hard about what order FROMFIELD's
      parameters should go in, and therefore I'm pleasantly surprised to
      find that my order agrees with the kernel's, so I don't have to
      permute every call site as part of making this change :-)
      9396fcc9
    • Simon Tatham's avatar
      Get rid of #ifdef DEFINE_PLUG_METHOD_MACROS. · ed652a70
      Simon Tatham authored
      I don't actually know why this was ever here; it appeared in the very
      first commit that invented Plug in the first place (7b0e0827) without
      explanation. Perhaps Dave's original idea was that sometimes you'd
      need those macros _not_ to be defined so that the same names could be
      reused as the methods for a particular Plug instance? But I don't
      think that ever actually happened, and the code base builds just fine
      with those macros defined unconditionally just like all the other sets
      of method macros we now have, so let's get rid of this piece of cruft
      that was apparently unnecessary all along.
      ed652a70
    • Simon Tatham's avatar
      Make Socket and Plug into structs. · 884a7df9
      Simon Tatham authored
      I think that means that _every_ one of my traitoids is now a struct
      containing a vtable pointer as one of its fields (albeit sometimes the
      only field), and never just a bare pointer.
      884a7df9
    • Simon Tatham's avatar
      Name vtable structure types more consistently. · b7982308
      Simon Tatham authored
      Now they're all called FooVtable, instead of a mixture of that and
      Foo_vtable.
      b7982308
  15. Oct 04, 2018
    • Simon Tatham's avatar
      Get rid of lots of implicit pointer types. · 96ec2c25
      Simon Tatham authored
      All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
      describe structure types themselves rather than pointers to them. The
      same goes for the codebase-wide trait types Socket and Plug, and the
      supporting types SockAddr and Pinger.
      
      All those things that were typedefed as pointers are older types; the
      newer ones have the explicit * at the point of use, because that's
      what I now seem to be preferring. But whichever one of those is
      better, inconsistently using a mixture of the two styles is worse, so
      let's make everything consistent.
      
      A few types are still implicitly pointers, such as Bignum and some of
      the GSSAPI types; generally this is either because they have to be
      void *, or because they're typedefed differently on different
      platforms and aren't always pointers at all. Can't be helped. But I've
      got rid of the main ones, at least.
      96ec2c25
  16. Sep 19, 2018
    • Simon Tatham's avatar
      Introduce a typedef for frontend handles. · 8dfb2a11
      Simon Tatham authored
      This is another major source of unexplained 'void *' parameters
      throughout the code.
      
      In particular, the currently unused testback.c actually gave the wrong
      pointer type to its internal store of the frontend handle - it cast
      the input void * to a Terminal *, from which it got implicitly cast
      back again when calling from_backend, and nobody noticed. Now it uses
      the right type internally as well as externally.
      8dfb2a11
  17. May 27, 2018
    • Simon Tatham's avatar
      Modernise the Socket/Plug vtable system. · 5129c40b
      Simon Tatham authored
      Now I've got FROMFIELD, I can rework it so that structures providing
      an implementation of the Socket or Plug trait no longer have to have
      the vtable pointer as the very first thing in the structure. In
      particular, this means that the ProxySocket structure can now directly
      implement _both_ the Socket and Plug traits, which is always
      _logically_ how it's worked, but previously it had to be implemented
      via two separate structs linked to each other.
      5129c40b
  18. May 26, 2018
    • Simon Tatham's avatar
      Make lots of generic data parameters into 'void *'. · 7babe66a
      Simon Tatham authored
      This is a cleanup I started to notice a need for during the BinarySink
      work. It removes a lot of faffing about casting things to char * or
      unsigned char * so that some API will accept them, even though lots of
      such APIs really take a plain 'block of raw binary data' argument and
      don't care what C thinks the signedness of that data might be - they
      may well reinterpret it back and forth internally.
      
      So I've tried to arrange for all the function call APIs that ought to
      have a void * (or const void *) to have one, and those that need to do
      pointer arithmetic on the parameter internally can cast it back at the
      top of the function. That saves endless ad-hoc casts at the call
      sites.
      7babe66a
  19. May 25, 2018
  20. May 14, 2017
  21. Feb 04, 2017
  22. Feb 29, 2016
    • Colin Watson's avatar
      Avoid -Wmisleading-indentation warnings with GCC 6. · e71ec6bf
      Colin Watson authored
      GCC 6 warns about potentially misleading indentation, such as:
      
          if (condition) stmt1; stmt2;
      
      Chaining multiple ifs on a single line runs into this warning, even if
      it's probably not actually misleading to a human eye, so just add a
      couple of newlines to pacify the compiler.
      
      (cherry picked from commit d700c334)
      e71ec6bf
  23. Jan 30, 2016
    • Colin Watson's avatar
      Avoid -Wmisleading-indentation warnings with GCC 6. · d700c334
      Colin Watson authored
      GCC 6 warns about potentially misleading indentation, such as:
      
          if (condition) stmt1; stmt2;
      
      Chaining multiple ifs on a single line runs into this warning, even if
      it's probably not actually misleading to a human eye, so just add a
      couple of newlines to pacify the compiler.
      d700c334
  24. Nov 22, 2015
    • Simon Tatham's avatar
      Log the setup of proxied network connections. · 3d4d4004
      Simon Tatham authored
      I've defined a new value for the 'int type' parameter passed to
      plug_log(), which proxy sockets will use to pass their backend
      information on how the setup of their proxied connections are going.
      I've implemented support for the new type code in all _nontrivial_
      plug log functions (which, conveniently, are precisely the ones I just
      refactored into backend_socket_log); the ones which just throw all
      their log data away anyway will do that to the new code as well.
      
      We use the new type code to log the DNS lookup and connection setup
      for connecting to a networked proxy, and also to log the exact command
      string sent down Telnet proxy connections (so the user can easily
      debug mistakes in the configured format string) and the exact command
      executed when spawning a local proxy process. (The latter was already
      supported on Windows by a bodgy logging call taking advantage of
      Windows in particular having no front end pointer; I've converted that
      into a sensible use of the new plug_log facility, and done the same
      thing on Unix.)
      3d4d4004
    • Simon Tatham's avatar
      Tell the truth about DNS lookups in the Event Log. · 37cdfdcd
      Simon Tatham authored
      We've always had the back-end code unconditionally print 'Looking up
      host' before calling name_lookup. But name_lookup doesn't always do an
      actual lookup - in cases where the connection will be proxied and
      we're configured to let the proxy do the DNS for us, it just calls
      sk_nonamelookup to return a dummy SockAddr with the unresolved name
      still in it. It's better to print a message that varies depending on
      whether we're _really_ doing DNS or not, e.g. so that people can tell
      the difference between DNS failure and proxy misconfiguration.
      
      Hence, those log messages are now generated inside name_lookup(),
      which takes a couple of extra parameters for the purpose - a frontend
      pointer to pass to logevent(), and a reason string so that it can say
      what the hostname it's (optionally) looking up is going to be used
      for. (The latter is intended for possible use in logging subsidiary
      lookups for port forwarding, though  the moment I haven't changed
      the current setup where those connection setups aren't logged in
      detail - we just pass NULL in that situation.)
      37cdfdcd
  25. Jun 20, 2015
    • Simon Tatham's avatar
      Log identifying information for the other end of connections. · 41f63b6e
      Simon Tatham authored
      When anyone connects to a PuTTY tool's listening socket - whether it's
      a user of a local->remote port forwarding, a connection-sharing
      downstream or a client of Pageant - we'd like to log as much
      information as we can find out about where the connection came from.
      
      To that end, I've implemented a function sk_peer_info() in the socket
      abstraction, which returns a freeform text string as best it can (or
      NULL, if it can't get anything at all) describing the thing at the
      other end of the connection. For TCP connections, this is done using
      getpeername() to get an IP address and port in the obvious way; for
      Unix-domain sockets, we attempt SO_PEERCRED (conditionalised on some
      moderately hairy autoconfery) to get the pid and owner of the peer. I
      haven't implemented anything for Windows named pipes, but I will if I
      hear of anything useful.
      
      (cherry picked from commit c8f83979)
      
      Conflicts:
      	pageant.c
      
      Cherry-picker's notes: the conflict was because the original commit
      also added a use of the same feature in the centralised Pageant code,
      which doesn't exist on this branch. Also I had to remove 'const' from
      the type of the second parameter to wrap_send_port_open(), since this
      branch hasn't had the same extensive const-fixing as master.
      41f63b6e
  26. May 18, 2015
    • Simon Tatham's avatar
      Log identifying information for the other end of connections. · c8f83979
      Simon Tatham authored
      When anyone connects to a PuTTY tool's listening socket - whether it's
      a user of a local->remote port forwarding, a connection-sharing
      downstream or a client of Pageant - we'd like to log as much
      information as we can find out about where the connection came from.
      
      To that end, I've implemented a function sk_peer_info() in the socket
      abstraction, which returns a freeform text string as best it can (or
      NULL, if it can't get anything at all) describing the thing at the
      other end of the connection. For TCP connections, this is done using
      getpeername() to get an IP address and port in the obvious way; for
      Unix-domain sockets, we attempt SO_PEERCRED (conditionalised on some
      moderately hairy autoconfery) to get the pid and owner of the peer. I
      haven't implemented anything for Windows named pipes, but I will if I
      hear of anything useful.
      c8f83979
  27. May 15, 2015
    • Simon Tatham's avatar
      Giant const-correctness patch of doom! · 89da2ddf
      Simon Tatham authored
      Having found a lot of unfixed constness issues in recent development,
      I thought perhaps it was time to get proactive, so I compiled the
      whole codebase with -Wwrite-strings. That turned up a huge load of
      const problems, which I've fixed in this commit: the Unix build now
      goes cleanly through with -Wwrite-strings, and the Windows build is as
      close as I could get it (there are some lingering issues due to
      occasional Windows API functions like AcquireCredentialsHandle not
      having the right constness).
      
      Notable fallout beyond the purely mechanical changing of types:
       - the stuff saved by cmdline_save_param() is now explicitly
         dupstr()ed, and freed in cmdline_run_saved.
       - I couldn't make both string arguments to cmdline_process_param()
         const, because it intentionally writes to one of them in the case
         where it's the argument to -pw (in the vain hope of being at least
         slightly friendly to 'ps'), so elsewhere I had to temporarily
         dupstr() something for the sake of passing it to that function
       - I had to invent a silly parallel version of const_cmp() so I could
         pass const string literals in to lookup functions.
       - stripslashes() in pscp.c and psftp.c has the annoying strchr nature
      89da2ddf
  28. Nov 17, 2013
    • Simon Tatham's avatar
      Implement connection sharing between instances of PuTTY. · bb78583a
      Simon Tatham authored
      The basic strategy is described at the top of the new source file
      sshshare.c. In very brief: an 'upstream' PuTTY opens a Unix-domain
      socket or Windows named pipe, and listens for connections from other
      PuTTYs wanting to run sessions on the same server. The protocol spoken
      down that socket/pipe is essentially the bare ssh-connection protocol,
      using a trivial binary packet protocol with no encryption, and the
      upstream has to do some fiddly transformations that I've been
      referring to as 'channel-number NAT' to avoid resource clashes between
      the sessions it's managing.
      
      This is quite different from OpenSSH's approach of using the Unix-
      domain socket as a means of passing file descriptors around; the main
      reason for that is that fd-passing is Unix-specific but this system
      has to work on Windows too. However, there are additional advantages,
      such as making it easy for each downstream PuTTY to run its own
      independent set of port and X11 forwardings (though the method for
      making the latter work is quite painful).
      
      Sharing is off by default, but configuration is intended to be very
      easy in the normal case - just tick one box in the SSH config panel
      and everything else happens automatically.
      
      [originally from svn r10083]
      bb78583a
    • Simon Tatham's avatar
      Remove sk_{get,set}_private_ptr completely! · 8be6fbaa
      Simon Tatham authored
      It was only actually used in X11 and port forwarding, to find internal
      state structures given only the Socket that ssh.c held. So now that
      that lookup has been reworked to be the sensible way round,
      private_ptr is no longer used for anything and can be removed.
      
      [originally from svn r10075]
      8be6fbaa
Loading