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>
agent: Return a proper error status if can't execute cockpit-agent

Fixes #498
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Set enviroment variables from PAM in cockpit-session

Don't let the cockpit-ws environment leak into cockpit-agent. Use
PAM to get the environment variable for the new process.

Fixes #497
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: Add 'problem' property to CockpitPipe

This can be used to retrieve the problem that the pipe closed
with, or NULL. But more importantly, it can be used to construct
a CockpitPipe for a failure.

Since CockpitPipe guarantees that it won't fire it's close
signals until the main loop, we follow that same guarantee
here with the "problem" property on construct.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Allow CockpitCreds to be used as hash table key

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Run PAM authentication in cockpit-session process

The PAM modules are not necessarily thread-safe. In addition we
really want to run the 'auth' and 'session' stacks in the same
process, so later work with reauthorizing the agent can kick in.

This means sharing a cockpit-session process between the CockpitAuth
code and webservice code.

cockpit-session now accepts a '-p FD' argument, which tells it to
read a password from that FD, authenticate, and return the results
back on the same FD.

In the future we'll also want cockpit-session to return any kerberos
TGT it got during opening the session back to cockpit-ws, so we can
use store that TGT in the user's credentials, and use it to connect
to other servers.

Unfortunately we cannot use CockpitPipe to start the process in
CockpitAuth because of the way that CockpitWebServer runs handlers in
different threads (for now). So implement a simple work around and
create the CockpitPipe once in the websocket thread.

Closes #509
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
Fix races in tests when running under valgrind or travis

Disable some code which currently races due to multi-threading,
and the expected order of messages. Should be re-enabled later
when we're no longer threaded in cockpit-ws.

Closes #544
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Inform client of byte order.

So that it can know what to do with numbers that are in "network byte
order", for example.

Reviewed-by: Stef Walter <stefw@redhat.com>
web: Fix 'interfaceAdded'

by passing the correct data to the DBusInterface constructor.

Reviewed-by: Stef Walter <stefw@redhat.com>
web: Add 'propertiesChanged' method to DBusInterface.

So that we can use other sources of change notifications, such as
explicit GetAll calls or custom PropertiesChanged signals.

Reviewed-by: Stef Walter <stefw@redhat.com>
web: Directly talk to NetworkManager.

Fixes #453

Reviewed-by: Stef Walter <stefw@redhat.com>