common: Fix JSON string encoding for control characters

The implementation we got from json-glib is totally broken here
and escapes using octal sequences which are invalid in JSON.

Closes #582
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: use mkstemp() rather than mktemp()

Closes #588

Signed-off-by: Stef Walter <stefw@redhat.com>
 * Whitespace fix
daemon: Bail if storaged isn't running.

Fixes #586
Closes #587

Signed-off-by: Stef Walter <stefw@redhat.com>
 * Changed to a g_message()
daemon: Initialize accounts synchronously.

So that they are ready when cockpitd appears on the bus.

Fixes #592
Closes #593

Reviewed-by: Stef Walter <stefw@redhat.com>
ws: Remove some useless rhost stuff in CockpitWebService

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Only share sessions if channel uses normal user/key

If a channel requests a specific user or host key, then force a
new session/agent for that channel.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Test that a session without channel times out

This only happens after all channels have been closed. Refactor
things a bit to make testing easier.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: No need for tracking the connection in CockpitWebService

Not used for anything any longer. Removing this also fixes
a leak.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Make the authorize cookie a string

This lets us use the polkit agent cookie directly, and also lets
us have a simple implementation in CockpitWebService

Fixes a crasher in the previous commit.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Handle multiple WebSockets per CockpitWebService

Multiple web sockets can be served from a single CockpitWebService,
which allows tabs to share sessions, as well as coherent implementations
of /logout and resource handlers.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: CockpitAuth owns CockpitWebService instances

Each time a real login occurs, we instantiate a new CockpitWebService
and return that same instance when logging in with cookies.

When doing /logout we dispose that web service instance, and force
it to disconnect.

Fixes #495
Closes #565
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Run our own session DBus daemon for use by cockpit-agent

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
daemon: Run cockpitd as a session service not a system service

Fixes #494

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Put the self-signed cert in /etc/cockpit/ws-certs.d

Give it a name so it comes last in the ordering.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
daemon: The /var/lib/cockpit directory is wheel owned

This allows wheel users to add and remove machines from the
dashboard.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
daemon: Ignore SIGPIPE, it's not useful in daemons

systemd used to do this for us when spawning cockpitd, but
lets do this in our own daemon now.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: Remove useles CockpitLogLevel define

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Log cockpit-agent output to journal

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Kill the session dbus-daemon when cockpit-agent dies

This helps clean up after ourselves. All the various session DBus
services that were started will be exited cleanly.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Don't exit if dbus-daemon session bus we started exits

cockpit-agent is in control of the lifetime of the dbus session
bus for its session, not the other way around.

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