61 Commits

Author SHA1 Message Date
Simon McVittie
5964b13f1e Constify arrays of program arguments
These are passed to non-const-correct APIs which still need a cast, but
at least we can declare the array in a way that reduces mistakes.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-08-22 15:17:13 -03:00
Simon McVittie
7663b5137f session-helper: Don't leak the GOptionContext
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 11:06:30 +00:00
Hubert Figuière
6e3cc82af3 Fix memory leaks
Build with address sanitizer and run the tests

Signed-off-by: Hubert Figuière <hub@figuiere.net>
2024-02-13 08:20:57 -06:00
Simon McVittie
6e7eb1e19a portal, session-helper: Save original environment and use it for child
Otherwise, the child process will inherit GIO_USE_VFS=local, breaking
its ability to use GVfs and other GIO plugin interfaces.

Resolves: https://github.com/flatpak/flatpak/issues/5567
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-11-14 15:28:51 +00:00
Simon McVittie
c2c034733e common: Make flatpak_debug2() use the same domain as g_debug()
Now that we are logging `flatpak -v` messages with log level INFO,
and printing INFO messages in the same way as DEBUG, we can reserve
log level DEBUG for `flatpak -v -v` messages. This means we no longer
need a weird secondary debug domain.

There is a very small behaviour change here: G_MESSAGES_DEBUG=flatpak
is now similar to `flatpak -v -v` (previously `flatpak -v`), and
G_MESSAGES_DEBUG=flatpak2 no longer has any effect. This seems more in
line with what would be expected from a GLib-based application.

In flatpak(1) and the system helper, this does not change behaviour
other than that: the same messages are logged by `-v` and by `-v -v`
as before.

In daemons that do not implement `-v -v` (the OCI authenticator, portal
and session helper), it continues to be necessary to use
G_MESSAGES_DEBUG to see flatpak_debug2() messages.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
86c9d7d4c7 daemons, etc.: Use g_info() for messages that are enabled by -v
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
ea584acf20 daemons: Treat g_info() as equivalent to g_debug()
Same as the previous commit, but for anything that runs in the
background.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-14 20:02:35 +00:00
Alberto Garcia
c1f0370958 session-helper: Run default signal handler after handle_sigterm()
Exiting the process with a custom exit status (1) after systemctl stop
(SIGTERM) makes systemd treat the flatpak-session-helper service as if
it had failed.

Signed-off-by: Alberto Garcia <berto@igalia.com>
2022-10-06 13:48:31 +01:00
Phaedrus Leeds
600e18567c Add a vim modeline and .editorconfig
To make indentation work with less effort. The modeline was copied from
libostree with minor modification and the .editorconfig from GLib.

The advantage of having both a modeline and an editorconfig is we can
work out of the box on more editor setups, and the modeline allows us to
specify the style with a lot more fine grained control.
2022-08-22 19:48:10 -07:00
Simon McVittie
ccaa3ceacc session-helper: Move FlatpakHostCommandFlags to header file
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-11-01 15:14:44 +00:00
gasinvein
38c03dff32 session-helper: Monitor gai.conf 2021-09-23 09:58:27 +02:00
Simon McVittie
725efe7ae7 session-helper: Move D-Bus names and paths to a header file
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:05:16 +02:00
Simon McVittie
7eedd219e9 session-helper: Return G_DBUS_METHOD_INVOCATION_HANDLED where appropriate
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-12-09 08:34:19 +01:00
Phaedrus Leeds
08f692962e Avoid shadowing local variables
Avoid shadowing variables that are already declared in a previous scope,
and make such occurrences compile-time errors. These are not functional
changes.

In a few places do related code cleanup.

A similar ostree PR is here:
https://github.com/ostreedev/ostree/pull/2195
2020-09-15 08:58:49 +02:00
Philip Withnall
23e1928a19 session-helper: Correctly annotate use of Unix FDs in D-Bus API
This fixes compilation with GLib 2.63’s `gdbus-codegen`, which
automatically enables Unix FD support for D-Bus APIs which use the `h`
type, even if the `org.gtk.GDBus.C.UnixFD` annotation is missing.

By adding the annotation, the generated header whether using
`gdbus-codegen` 2.63 or < 2.63.

This is a slight API break in GLib, but it’s questionable about whether
flatpak should have always had the annotation.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-10 11:45:53 +01:00
Debarshi Ray
e82efa8603 Trim unused shared library linkages from the session helper
The org.freedesktop.Flatpak user D-Bus service isn't just used by
flatpak(1) or applications running as Flatpaks. It's also used by
toolbox(1) for similar reasons:
 * To keep various configuration files inside the container
   synchronized with the host
 * To let the container request certain commands to be run on the host

The org.freedesktop.Flatpak D-Bus service itself doesn't need much in
the way of dependencies, but inherits a lot of unused shared library
linkages through the libflatpak-common.la convenience library. Removing
these unused shared libraries reduces the footprint of toolbox(1) for
those who care about such things. eg., Fedora CoreOS.

This commit brings down the number of shared libraries to 19 from 62.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Debarshi Ray
61d4316043 common, session-helper: Make the session helper more self-contained
... by moving the definition of FlatpakHostCommandFlags from the
'common' sub-directory to 'session-helper'. It hasn't been used by
anything else ever since flatpak-builder was moved to a separate
repository in commit 52bd14656151fe63.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Debarshi Ray
bf96de941b session-helper: Relax directory permission for Toolbox containers
Toolbox [1] containers, like Flatpak containers, need to keep some
configuration files synchronized with the host. eg., /etc/localtime,
/etc/resolv.conf, etc.. The easiest way to keep them updated is to bind
mount the entire /etc from the host at some location inside the
container, and then replace the container's copy of the files with
symbolic links to the bind mounted copies.

However, this doesn't work when the host's copy of a configuration file
is itself a symbolic link to a location outside /etc. eg.,
/etc/localtime, which points somewhere inside /usr/share/zoneinfo. In
that case the host needs to be actively monitored via inotify(7) and
an updated copy of the file needs to maintained in a separate
directory, which can be bind mounted into the container.

This monitoring infrastructure is already present in Flatpak and it
makes sense to leverage it for Toolbox containers too.

However, Flatpak containers have only one user, the current one logged
into the host, whereas Toolbox containers have a longer list of users
like the host itself. Therefore, if the directory getting bind mounted
(ie., $XDG_RUNTIME_DIR/.flatpak-helper/monitor) isn't world readable,
then some users inside the container won't be able to read the
configuration file. eg., this will fail:
  $ sudo -u operator cat /run/host/monitor/localtime

Relaxing the directory permissions on the host shouldn't pose a
security risk. They are copies of originals that are world readable
anyway.

[1] https://github.com/debarshiray/toolbox

Closes: #2916
Approved by: alexlarsson
2019-05-28 07:37:13 +00:00
Rafael Fontenelle
95e692794b Fix misspellings
Closes: #2807
Approved by: matthiasclasen
2019-04-08 12:50:42 +00:00
Matthew Leeds
e8816b7663 Remove extra newlines in variable definiton blocks
Uncrustify has an option "nl_func_var_def_blk" which is supposed to
ensure there's a newline character between the block of variable
definitions and the rest of the function body, but it gets confused and
thinks that the first instance of "g_autoptr" or "g_auto" being used on
a variable is the start of the function body. So this commit removes
those extra newline characters and removes that option in uncrustify.cfg
so they don't get re-added the next time uncrustify is run.

Here's the command I used:

perl -0777 -i -pe 's/\n(\n\s*g_auto\()/\1/g' `git ls-tree --name-only
-r HEAD | grep \\\.[ch]$ | grep -v common/valgrind-private.h |
grep -v app/flatpak-polkit-agent-text-listener\\\.[ch]`

I ran it again with "g_autoptr" in place of "g_auto", and made a few
manual edits to add back the newline when the g_auto* was in the middle
of a function body rather than at the top.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthew Leeds
8d962a686f Run uncrustify
I had to make a few manual edits but other than those the changes look
reasonable.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthias Clasen
64e6764137 session-helper: Drop the unused RequestMonitor api
Nothing is using this now that we have RequestSession.
No need to carry this round.

Closes: #2533
Approved by: alexlarsson
2019-01-11 13:05:58 +00:00
Simon McVittie
4111dbadaf session-helper: Don't crash on NameOwnerChanged
There was a typo here: (gpointer *) pid_data should have been
(gpointer *) &pid_data, so that g_hash_table_iter_next() would make
pid_data a pointer to a PidData struct. Instead, the previous
implementation left pid_data set to NULL, leading to a NULL dereference
and segmentation fault whenever a name fell off the bus while a watched
client existed.

Instead of directly inserting the missing "&", I've used a pattern
that avoids needing the cast, in an attempt to make it more obviously
correct.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #2417
Approved by: matthiasclasen
2018-12-11 15:43:37 +00:00
Matthias Clasen
c516a22e4d session-helper: Improve HostCommand life-cycle handling
Add flag that instructs the session-helper to kill
the spawned command when the caller drops off the bus.

Closes: #2326

Closes: #2365
Approved by: alexlarsson
2018-12-06 13:10:51 +00:00
Matthias Clasen
972804f222 session-helper: Validate HostCommand arguments
This is not a portal, but we should still do some
due diligence.

Closes: #2365
Approved by: alexlarsson
2018-12-06 13:10:51 +00:00
Will Thompson
97983ba377 portal, session-helper: fix typo in TIOCSCTTY comment
Closes: #2382
Approved by: matthiasclasen
2018-12-04 13:41:29 +00:00
Matthias Clasen
4ef317c9ba session-helper: Properly report p11-kit exit status
Use the API that GLib offers for this.

Closes: #2252
Approved by: matthiasclasen
2018-10-23 20:10:37 +00:00
Alexander Larsson
0b6844f39e sandbox: Expose /etc/timezone
This exposes a /etc/timezone with the current timezone, as per the old
debian spec: https://wiki.debian.org/TimeZoneChanges

In case we're using the session-helper this will be extracted from
the host config and applied whenever that changes.

Normally timezone info is specified by /etc/localtime being a symlink
into the locale data, and you can look at the symlink value itself.
However, in the sandbox we can't update a symlink in /etc at runtime,
nor can we make it of the canonical form as that would point into the
runtime. This is why /etc/timezone is used.

This fixes https://github.com/flatpak/flatpak/issues/2190

Closes: #2214
Approved by: alexlarsson
2018-10-10 15:12:21 +00:00
Matthias Clasen
40f413836a Drop xdg-app migration support
It has been long enough. It is unlikely that we can still
find any xdg-app installations in the wild.
2018-10-10 12:20:27 +02:00
Alexander Larsson
3f4518b15c Run uncrustify
Closes: #1870
Approved by: alexlarsson
2018-07-08 10:05:37 +00:00
Alexander Larsson
11d9b5b0b6 session-helper: Disable p11-kit for older broken versions
p11-kit server version < 0.23.10 doesn't properly daemonize which
causes g_spawn_sync() to hang forever waiting for the pipe to
close.

We work around this by passing --sh, which is only available in the
working version, and fill fail the old ones.

https://github.com/flatpak/flatpak/issues/1768

Closes: #1782
Approved by: alexlarsson
2018-06-13 10:08:56 +00:00
Alexander Larsson
ab87617ac1 session-helper: break out the p11-kit code to a separate function
This makes it easier to read. Also, we convert some nested ifs
to early returns.

Closes: #1782
Approved by: alexlarsson
2018-06-13 10:08:56 +00:00
Alexander Larsson
66b2ff40f7 run: Support accessing host trusted certificates
If p11-kit server is installed on the host, we spawn a copy of this, forwarding the access to the
p11-kit trust module in a read-only way.

We then (if the above worked) bind mount the socket as /run/user/$UID/p11-kit/pkcs11 in the sandbox,
which is the default socket path for the p11-kit-client module.

We also add a configuration file in /etc/pkcs11/modules/p11-kit-trust.module that makes the trust
module actually load the client module instead. This means applications automatically switch
to using the host certs for trust if possible, and use the runtime ca-certificates otherwise.

Additionally we add a config file that always disables pkcs user
config merging, because pkcs11 modules on the host are unlikely to work in a random runtime.

Closes: #1757
Approved by: alexlarsson
2018-06-07 12:25:21 +00:00
Alexander Larsson
b4bb890516 session-helper: Add new more generic helper start method
This does the same as RequestMonitor, but returns the status via a
a{sv} so that its more extensible.

Closes: #1757
Approved by: alexlarsson
2018-06-07 12:25:21 +00:00
Alexander Larsson
c570e09ac9 common: Rename all generated files to *-dbus-generated.[ch]
Easier to spot them this way

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00
Alexander Larsson
960d20448c common: Rename all private headers to *-private.h
This is the start of the merging of lib/* into common/*

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00
Robert McQueen
6475f7663c session-helper: refactor creation and updating of real path monitors
I think this enhances readability significantly, reduces code duplication
and allows you to follow the rationale behind why monitors are being
added/removed a lot more clearly than the previous nested/ad-hoc logic in
file_changed. Also adds debug printouts in the case that file monitors
are not created successfully.

Closes: #1194
Approved by: pwithnall
2017-11-23 14:47:12 +00:00
Robert McQueen
46fa8492ac session-helper: avoid theoretical GFile leaks with g_autoptr
Closes: #1194
Approved by: pwithnall
2017-11-23 14:47:12 +00:00
Robert McQueen
bdf0f8c554 session-helper: add comment documenting rationale for two monitors
Closes: #1194
Approved by: pwithnall
2017-11-23 14:47:12 +00:00
Robert McQueen
2b516e5df1 session-helper: remove unused file_monitor_hash
The monitor data structures are never replaced in the hash table, so
it's not necessary. Keep MonitorData pointers in scope in main() and
set up g_autoptr instead.

Closes: #1194
Approved by: pwithnall
2017-11-23 14:47:12 +00:00
Robert McQueen
dc6a880238 session-helper: monitor canonical files for changes
Closes: #1190
Approved by: alexlarsson
2017-11-23 10:39:44 +00:00
Robert McQueen
c59f41a5f4 session-helper: store file monitor & source in a hash table
Closes: #1190
Approved by: alexlarsson
2017-11-23 10:39:44 +00:00
Robert McQueen
b31773b097 session-helper: remove un-needed file monitor actions on CREATED
CHANGES_DONE always fires after CREATED.

Closes: #1190
Approved by: alexlarsson
2017-11-23 10:39:44 +00:00
Alexander Larsson
4c91eeeada Change debug prefix from XA to F
We're not xdg-app anymore

Closes: #1173
Approved by: mwleeds
2017-11-16 08:15:15 +00:00
Philip Withnall
81301f0ef4 general: Remove trailing \n from GLib log messages
The GLib logging framework automatically appends a \n to messages, so it
doesn’t need to be added by callers.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2017-07-07 17:18:24 +01:00
Alexander Larsson
bda7575e79 Add version property to all dbus interfaces 2017-05-19 14:38:22 +02:00
Alexander Larsson
4d2d07d033 Expose host /etc/hosts and /etc/host.conf
These are local network configuration, very much similar to
resolv.conf, so should also be exposed.

Fixes https://github.com/alexlarsson/spotify-app/issues/42
2017-05-04 13:08:25 +02:00
Owen W. Taylor
5f12c9e328 flatpak-session-helper.c: Make failure of TIOCSCTTY a g_debug()
Just because stdout/stderr happen to be going to a terminal doesn't
necessarily mean that we want the command launched by HostCommand
to take ownership of the terminal - in the case where 'flatpak run'
is launched from a terminal, stderr will typically be left pointing
to the terminal for any command. In that case the terminal already
has a controlling process, and TIOCSCTTY will fail; avoid scary
messages by making the failure only a g_debug()
2017-01-27 10:47:13 +01:00
Alexander Larsson
cecae8295c Fix build due to missing include 2016-11-11 11:15:00 +01:00
Christian Hergert
b3489c3557 session-helper: use proper fd with ioctl() for tty setup
This was using the "from" fd from the fd_map, which will have already been
closed by time we reach this portion of the child setup.

Tracking the movement of FDs while resolving the remappings is rather
tedious and error prone, so just locate the final fd before calling
the ioctl() in child setup.
2016-09-15 21:38:06 -07:00