agent: Allow DBus calls without a proxy present

We allow DBus calls to arbitrary objects without a proxy in the
Object Managere.

Closes #523
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: Hold reference to CockpitPipe while emitting signals

While emitting CockpitPipe::read signal, hold a reference to
self, in case the signal handler unrefs the pipe, we can still
act in a coherent manner.

Caught by Travis and Valgrind.
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: Backport g_unix_fd_add() and friends

Backport the new g_unix_fd_add() and related functions which
define GSource's for unix fds. This prevents us from having to
define a custom GSource in CockpitPipe.

In addition we'd like to use these sources for the reauthorization
work.

Closes #529
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Suppress errors about unexpected TLS disconnects

Browsers seem to do this all the time. No use filling up the
server's logs.

Closes #531
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
Remove use of glib-mkenum and enum types

This is an (unfortunate) requirement of distributing code as a
library. However we're not distributing any of our GObject code
as libraries. So remove use of glib-mkenum and all the complexity
it entails.

Closes #532
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Make CockpitTransport an abstract base class

It doesn't need to be an interface. And as an abstract base
class we can have some implementation there.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: Add new CockpitTransport::control signal

This signal is fired when a control message is received by the
transport, and no recv signal handler has processed it. We use it
in the agent, to have multiple handlers for control messages,
but still avoiding parsing and validating them multiple times.

In the case of the web service, since we're mainly forwarding
messages, we don't use this new signal.

Closes #530
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Fix use of Secure https only cookies

We now have various criteria on whether HTTPS is in use, not just
just whether a certificate is present or not. So make the 'Secure'
flag of cookies track those criteria, and just check if the
connection in use is a TLS connection or not.

In addition fail safe, so and don't use G_IS_TLS_CONNECTION() but
rather the inverse, and rename things, add tests, so if things
change in our TLS implementation this will be caught.

Closes #533
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Fix invalid check for HTTP upgrade

Leave these checks to the WebSocket code. The code here was
invalid anyway, and checked whether both headers were missing.

Closes #534
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Don't use g_warning for WebSocket connection errors

g_warning() should be for local problems. g_message() is more
appropriate for warning about bad callers.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: Make cockpit test logic thread safe

In particular the expected messages stuff should be thread-safe

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
websocket: Clarify a couple TODO's that are really HACK's

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
websocket: Validate the Host and Origin headers properly

This prevents CSRF attacks.

Fixes #496
Closes #535
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
Signed-off-by: Marius Vollmer <marius.vollmer@redhat.com>
* Adapted one test to changes in master, where a warning is now a
  message.
ws: Create CockpitCreds closer to pam_authenticate()

Create the PAM creds closer to pam_authenticate(), so we can use
the real user that PAM canonicalized, as well as return additional
information into the creds (later).

Remove the noop authorization check. We want to be respecting
system authorization, not inventing our own.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Remove the cockpit_creds_take_password() function

It's not used, and not useful going forward.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: CockpitCreds with multi creds, remote host is a cred

As part of the build up to GSSAPI kerberos support we need to be
able to hold mulitple credentials in the aptly named CockpitCreds.

Move remote host credential to CockpitCreds. This is necessary
because we want to authenticate in cockpit-session and perform
that authentication from CockpitAuth

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Drop group privileges in cockpit-session

Correctly drop group privileges in cockpit session.

Fixes #492
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Use err() and warn() in cockpit-session

Since cockpit-session is written without GLib, we can't use the
standard GLib logging, but we can use these stdlib functions for
handling printing our errors.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Some minor cleanup in cockpit-session

Move global variables to top, and make some variables static rather
than global.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Don't lookup the user twice in cockpit-session

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>