agent: Lookup introspect data asyncronously in CockpitDBusJson

We can't block the rest of the agent while talking out to other
DBus services.

This also removes the big leak of cached introspect data which
used to be global and never released until the agent went away.

Fixes #203
Closes #470
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Don't close sessions that receive for unknown channels

When a channel closes from the session side (eg: due to an error)
then cockpit-web can't possibly know it shouldn't send a message
to that channel until it receives the close message.

There's a race where a channel closes just before a message that
was already in transit gets delivered to it.

Currently we cause a failure in the transport due to a message
with an unknown channel. However this is inherently racy and breaks
the entire application (ie: logout).

We have to just ignore messages with bad channels in this situation.

Note that we still don't allow sessions to lie about which channels
they're sending messages from. This would be a security risk, and
is still handled strictly (by closing the session).

Closes #477
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
test: Don't ignore obsolete journal messages

They are not warnings anymore.

Reviewed-by: Stef Walter <stefw@redhat.com>
agent: Remove dead code in REST JSON processing

Dead code found by Coverity.
agent: Don't spin CPU in the loop in this test

This test would otherwise just spin fast, instead of waiting
for a result in poll() or another blocking call.

Found by Coverity.
common: Better handling of closing fds when execing

When spawning a new process double check that we can and have
closed all unnecessary file descriptors.

Issue found by coverity.
ws: Fix up mock-sshd to handle retrying non-blocking writes

There were corner cases in our testing where we would expect
all data to be written out. In reality not all data is expected
to be written during a write() or ssh_channel_write() so,
buffer it appropriately and only write when we are ready for it.
ws: Add --broken-auth argument to mock-sshd

This lets us start mock-sshd in a way that ssh authentication should
always fail. We don't have host-based auth or public key auth, so
use those as our way of forcing failure.
ws: Don't mix stderr and stdout in mock-sshd

In fact for testing purposes, just leave it connected to our normal
stderr so we can see failures.
ws: Send exit termination signals from children of mock-sshd

We'll want to test these cases, even though we don't currently
do that.
ws: Fix race closing down mock-sshd session/connection

Avoid printing an unnecessary warning in this case
common: Make cockpit_pipe_get_pid() more useful

It now returns TRUE if a pid was ever set or expected. The actual
pid is returned as an argument.

This lets us handle cases where callers want to behave differetnly
if a pipe was a process or not
ws: Add CockpitSshTransport which uses libssh

We'll migrate from our current sshpass + openssh client based
approach to libssh.

This doesn't use libgssh. libgssh unfortunately doesn't have a
pollable model (such as GPollableOutputStream and friends) which
is what we need to implement a CockpitTransport.

In addition the mechanism that it uses to do async work with
libssh (ie: eagain non-blocing based async) doesn't work well with
libssh 0.6.x upstream. Certain functions to make the corner cases
work are completely missing.

Lastly we need to authenticate in a thread, so we can support
kerberos (ie: GSSAPI). So implemented it this way in
CockpitSshTransport.

Part of fix for #69
ws: Use CockpitSshTransport for connecting to other hosts

Uses libssh instead of the openssh client for connecting to other
hosts.

We also remove some complexity from cockpit_pipe_transport_spawn()
which can no longer fail immedediately, but will close if failure.

Note that although the tests pass with this commit, running actual
webservice requires that you put known_hosts in the standard
format in the following file, for any hosts that you want to connect to:

  /var/lib/cockpit/known_hosts

This commit removes sshpass dependency.

Fixes #69
ws: Explicitly connect to 127.0.0.1 when testing

Some machines have 'localhost' in /etc/hosts that resolves to
an IPv6 address. While we support IPv6, our mock-sshd doesn't
support listening on both IPv4 and IPv6 localhost addresses. It
would be too complicated.
ws: Expose host key for CockpitSshTransport

This allows us to look at the host key that the server offered,
regardless of whether verification succeeded or failed. Via
cockpit_ssh_transport_get_host_key() and the 'host-key' property.

In addition we want to be able to tell CockpitSshTransport to
explicitly expect a certain key and ignore other host verification
via the known-hosts file. This happens via 'host-key' construct
property.
ws: Modernize how test-webservice uses test fixtures

Use a struct for the fixture so we can extend them. In addition use
TestCase for the test struct, so we can be less confused.
ws: Expose the host-key in the close channel message

If a channel closes with reason "unknown-hostkey" try to include
the host-key and host-fingerprint in the message so it can be
acted on by the caller.

I tried to come up with a better way to do this, such as allow
us to discover the host key for successfully opened channels. The
alternatives were complex and had all sorts of corner cases.

This solves the immediate need. The concept of having more
close fields is also used in the upcoming spawn-channel code
to relay exit codes and exit signals. So this bit is sound.
web: Expose channel close options in Channel.on("close")

Instead of having a reason argument to the event, there's now the
full options, so handlers can access any field of the close message.
This is symettrical with the Channel(@options) constructor.

In addition accept @options instead of a @reason in Channel.close()
ws: Add a channel open 'host-key' field for expecting a key

If we know which key to expect (such as after the user has
approved it) we can expect just that host-key when opening
a channel to a remote machine.