Find ToUnicodeEx() at run time, not load time.

This restores PuTTY's backward compatibility to versions of Windows
too old to have ToUnicodeEx in their system libraries, which was
accidentally broken in 0.63.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10061 cda61777-01e9-0310-a592-d414129be87e
Clean up the semantics of the ssh_rportfwd structure.

It's now indexed by source hostname as well as source port (so that
separate requests for the server to listen on addr1:1234 and
addr2:1234 can be disambiguated), and also its destination host name
is dynamically allocated rather than a fixed-size buffer.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10062 cda61777-01e9-0310-a592-d414129be87e
Move cipher settings into their own config panel.

This makes room in the main SSH panel for new options about connection
sharing, which I'm shortly going to add.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10063 cda61777-01e9-0310-a592-d414129be87e
Move SSH protocol enumerations out into ssh.h.

This permits packet type codes and other magic numbers to be accessed
from modules other than ssh.c.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10064 cda61777-01e9-0310-a592-d414129be87e
Add a Socket implementation which just holds an error message.

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.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10065 cda61777-01e9-0310-a592-d414129be87e
Factor out the HANDLE-to-Socket adapter from winproxy.c.

It's now kept in a separate module, where it can be reused
conveniently for other kinds of Windows HANDLE that I want to wrap in
the PuTTY Socket abstraction - for example, the named pipes that I
shortly plan to use for the Windows side of connection-sharing IPC.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10066 cda61777-01e9-0310-a592-d414129be87e
Implement freezing on Windows handle sockets.

That's been a FIXME in the code for ages, because it's difficult to
get winhandl.c to stop an already-started read from a handle (since
the read is a blocking system call running in a separate thread). But
I now realise it isn't absolutely necessary to do so - you can just
buffer one lot of data from winhandl and _then_ tell it to stop.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10067 cda61777-01e9-0310-a592-d414129be87e
Replace the hacky 'OSSocket' type with a closure.

The mechanism for constructing a new connection-type Socket when a
listening one receives an incoming connection previously worked by
passing a platform-specific 'OSSocket' type to the plug_accepting
function, which would then call sk_register to wrap it with a proper
Socket instance. This is less flexible than ideal, because it presumes
that only one kind of OS object might ever need to be turned into a
Socket. So I've replaced OSSocket throughout the code base with a pair
of parameters consisting of a function pointer and a context such that
passing the latter to the former returns the appropriate Socket; this
will permit different classes of listening Socket to pass different
function pointers.

In deference to the reality that OSSockets tend to be small integers
or pointer-sized OS handles, I've made the context parameter an
int/pointer union that can hold either of those directly, rather than
the usual approach of making it a plain 'void *' and requiring a
context structure to be dynamically allocated every time.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10068 cda61777-01e9-0310-a592-d414129be87e
Add support for Windows named pipes.

This commit adds two new support modules, winnpc.c and winnps.c, which
deal respectively with being a client and server of a Windows named
pipe (which, in spite of what Unix programmers will infer from that
name, is actually closer to Windows's analogue of a Unix-domain
socket). Each one provides a fully featured Socket wrapper around the
hairy Windows named pipe API, so that the rest of the code base should
be able to use these interchangeably with ordinary sockets and hardly
notice the difference.

As part of this work, I've introduced a mechanism in winhandl.c to
permit it to store handles of event objects on behalf of other Windows
support modules and deal with passing them to applications' main event
loops as necessary. (Perhaps it would have been cleaner to split
winhandl.c into an event-object tracking layer analogous to uxsel, and
the handle management which is winhandl.c's proper job, but this is
less disruptive for the present.)


git-svn-id: svn://svn.tartarus.org/sgt/putty@10069 cda61777-01e9-0310-a592-d414129be87e
Clean up the 'data' vs 'body' pointers in struct Packet.

There's always been some confusion over exactly what it all means. I
haven't cleaned it up to the point of complete sensibleness, but I've
got it to a point where I can at least understand and document the
remaining non-sensibleness.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10070 cda61777-01e9-0310-a592-d414129be87e
Complete rewrite of the packet log censoring code.

Because the upcoming connection sharing changes are going to involve
us emitting outgoing SSH packets into our log file that we didn't
construct ourselves, we can no longer rely on metadata inserted at
packet construction time to tell us which parts of which packets have
to be blanked or omitted in the SSH packet log. Instead, we now have
functions that deal with constructing the blanks array just before
passing all kinds of packet (both SSH-1 and SSH-2, incoming and
outgoing) to logging.c; the blanks/nblanks fields in struct Packet are
therefore no longer needed.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10071 cda61777-01e9-0310-a592-d414129be87e
Add support in uxnet.c for Unix-domain listening sockets.

There are two new functions: one to construct a SockAddr wrapping a
Unix socket pathname (which can also be used as the destination for
new_connection), and one to establish a new listening Unix-domain
socket.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10072 cda61777-01e9-0310-a592-d414129be87e
Reliably initialise uxnet's socket fd fields to -1.

This prevents embarrassing mess-ups involving getting back a Socket
which has mostly been memset to 0 but contains an error message,
sk_close()ing it to free the memory, and finding that standard input
has been closed as a side effect.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10073 cda61777-01e9-0310-a592-d414129be87e
Refactor ssh.c's APIs to x11fwd.c and portfwd.c.

The most important change is that, where previously ssh.c held the
Socket pointer for each X11 and port forwarding, and the support
modules would find their internal state structure by calling
sk_get_private_ptr on that Socket, it's now the other way round. ssh.c
now directly holds the internal state structure pointer for each
forwarding, and when the support module needs the Socket it looks it
up in a field of that. This will come in handy when I decouple socket
creation from logical forwarding setup, so that X forwardings can
delay actually opening a connection to an X server until they look at
the authentication data and see which server it has to be.

However, while I'm here, I've also taken the opportunity to clean up a
few other points, notably error message handling, and also the fact
that the same kind of state structure was used for both
connection-type and listening-type port forwardings. Now there are
separate PortForwarding and PortListener structure types, which seems
far more sensible.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10074 cda61777-01e9-0310-a592-d414129be87e
Remove sk_{get,set}_private_ptr completely!

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.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10075 cda61777-01e9-0310-a592-d414129be87e
Add a missing null pointer check in s_write.

I don't know that this can ever be triggered in the current state of
the code, but when I start mucking around with SSH session closing in
the near future, it may be handy to have it.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10076 cda61777-01e9-0310-a592-d414129be87e
Add missing 'const' in the des_*_xdmauth functions.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10077 cda61777-01e9-0310-a592-d414129be87e
Decouple X socket opening from x11_init().

Now we wait to open the socket to the X server until we've seen the
authorisation data. This prepares us to do something else with the
channel if we see different auth data, which will come up in
connection sharing.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10078 cda61777-01e9-0310-a592-d414129be87e
Prepare to have multiple X11 auth cookies valid at once.

Rather than the top-level component of X forwarding being an
X11Display structure which owns some auth data, it's now a collection
of X11FakeAuth structures, each of which owns a display. The idea is
that when we receive an X connection, we wait to see which of our
available auth cookies it matches, and then connect to whatever X
display that auth cookie identifies. At present the tree will only
have one thing in it; this is all groundwork for later changes.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10079 cda61777-01e9-0310-a592-d414129be87e
Refactor the construction of X protocol greetings.

I've moved it out into a separate function, preparatory to calling it
from somewhere completely different in changes to come. Also, we now
retain the peer address sent from the SSH server in string form,
rather than translating it immediately into a numeric IP address, so
that its original form will be available later to pass on elsewhere.


git-svn-id: svn://svn.tartarus.org/sgt/putty@10080 cda61777-01e9-0310-a592-d414129be87e