Skip to content
Snippets Groups Projects
  1. 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
  2. Jan 04, 2020
    • Simon Tatham's avatar
      winnpc.c: add low-level connect_to_named_pipe() function. · 39248737
      Simon Tatham authored
      This contains most of the guts of the previously monolithic function
      new_named_pipe_client(), but it directly returns the HANDLE to the
      opened pipe, or a string error message on failure.
      
      new_named_pipe_client() is now a thin veneer on top of that, which
      returns a Socket * by wrapping up the HANDLE into a HandleSocket or
      the error message into an ErrorSocket as appropriate.
      
      So it's now possible to connect to a named pipe, using all our usual
      infrastructure (including in particular the ownership check of the
      server, to defend against spoofing attacks), without having to have a
      Socket-capable event loop in progress.
      39248737
  3. 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
  4. Jul 28, 2019
    • 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
  5. Oct 21, 2018
    • Simon Tatham's avatar
      Improve sk_peer_info. · 82c83c18
      Simon Tatham authored
      Previously, it returned a human-readable string suitable for log
      files, which tried to say something useful about the remote end of a
      socket. Now it returns a whole SocketPeerInfo structure, of which that
      human-friendly log string is just one field, but also some of the same
      information - remote IP address and port, in particular - is provided
      in machine-readable form where it's available.
      82c83c18
  6. Oct 07, 2018
    • Simon Tatham's avatar
      Make new_error_socket() into a printf-style function. · cea1329b
      Simon Tatham authored
      Almost all the call sites were doing a cumbersome dupprintf-use-free
      cycle to get a formatted message into an ErrorSocket anyway, so it
      seems more sensible to give them an easier way of doing so.
      
      The few call sites that were passing a constant string literal
      _shouldn't_ have been - they'll be all the better for adding a
      strerror suffix to the message they were previously giving!
      cea1329b
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. Nov 17, 2013
    • 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
    • Simon Tatham's avatar
      Add a Socket implementation which just holds an error message. · a6139c1a
      Simon Tatham authored
      This isn't yet used, but I plan to use it in situations where you have
      to report errors by returning a valid Socket on which the client wlil
      call sk_socket_error, but in fact you notice the error _before_
      instantiating your usual kind of Socket. The resulting Socket is
      usable for nothing except reading out the error string and closing it.
      
      [originally from svn r10065]
      a6139c1a
Loading